1 /*------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2016 The Khronos Group Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Image Tests Utility Classes
22  *//*--------------------------------------------------------------------*/
23 
24 #include "vktImageTestsUtil.hpp"
25 #include "vkQueryUtil.hpp"
26 #include "vkTypeUtil.hpp"
27 #include "vkCmdUtil.hpp"
28 #include "vkObjUtil.hpp"
29 #include "tcuTextureUtil.hpp"
30 
31 using namespace vk;
32 
33 namespace vkt
34 {
35 namespace image
36 {
37 
Buffer(const DeviceInterface & vk,const VkDevice device,Allocator & allocator,const VkBufferCreateInfo & bufferCreateInfo,const MemoryRequirement memoryRequirement)38 Buffer::Buffer (const DeviceInterface&		vk,
39 				const VkDevice				device,
40 				Allocator&					allocator,
41 				const VkBufferCreateInfo&	bufferCreateInfo,
42 				const MemoryRequirement		memoryRequirement)
43 {
44 	m_buffer = createBuffer(vk, device, &bufferCreateInfo);
45 	m_allocation = allocator.allocate(getBufferMemoryRequirements(vk, device, *m_buffer), memoryRequirement);
46 	VK_CHECK(vk.bindBufferMemory(device, *m_buffer, m_allocation->getMemory(), m_allocation->getOffset()));
47 }
48 
Image(const DeviceInterface & vk,const VkDevice device,Allocator & allocator,const VkImageCreateInfo & imageCreateInfo,const MemoryRequirement memoryRequirement)49 Image::Image (const DeviceInterface&	vk,
50 			  const VkDevice			device,
51 			  Allocator&				allocator,
52 			  const VkImageCreateInfo&	imageCreateInfo,
53 			  const MemoryRequirement	memoryRequirement)
54 {
55 	m_image = createImage(vk, device, &imageCreateInfo);
56 	m_allocation = allocator.allocate(getImageMemoryRequirements(vk, device, *m_image), memoryRequirement);
57 	VK_CHECK(vk.bindImageMemory(device, *m_image, m_allocation->getMemory(), m_allocation->getOffset()));
58 }
59 
getShaderGridSize(const ImageType imageType,const tcu::UVec3 & imageSize)60 tcu::UVec3 getShaderGridSize (const ImageType imageType, const tcu::UVec3& imageSize)
61 {
62 	switch (imageType)
63 	{
64 		case IMAGE_TYPE_1D:
65 		case IMAGE_TYPE_BUFFER:
66 			return tcu::UVec3(imageSize.x(), 1u, 1u);
67 
68 		case IMAGE_TYPE_1D_ARRAY:
69 			return tcu::UVec3(imageSize.x(), imageSize.z(), 1u);
70 
71 		case IMAGE_TYPE_2D:
72 			return tcu::UVec3(imageSize.x(), imageSize.y(), 1u);
73 
74 		case IMAGE_TYPE_2D_ARRAY:
75 		case IMAGE_TYPE_3D:
76 			return tcu::UVec3(imageSize.x(), imageSize.y(), imageSize.z());
77 
78 		case IMAGE_TYPE_CUBE:
79 			return tcu::UVec3(imageSize.x(), imageSize.y(), 6u);
80 
81 		case IMAGE_TYPE_CUBE_ARRAY:
82 			return tcu::UVec3(imageSize.x(), imageSize.y(), 6u * imageSize.z());
83 
84 		default:
85 			DE_FATAL("Unknown image type");
86 			return tcu::UVec3(1u, 1u, 1u);
87 	}
88 }
89 
getLayerSize(const ImageType imageType,const tcu::UVec3 & imageSize)90 tcu::UVec3 getLayerSize (const ImageType imageType, const tcu::UVec3& imageSize)
91 {
92 	switch (imageType)
93 	{
94 		case IMAGE_TYPE_1D:
95 		case IMAGE_TYPE_1D_ARRAY:
96 		case IMAGE_TYPE_BUFFER:
97 			return tcu::UVec3(imageSize.x(), 1u, 1u);
98 
99 		case IMAGE_TYPE_2D:
100 		case IMAGE_TYPE_2D_ARRAY:
101 		case IMAGE_TYPE_CUBE:
102 		case IMAGE_TYPE_CUBE_ARRAY:
103 			return tcu::UVec3(imageSize.x(), imageSize.y(), 1u);
104 
105 		case IMAGE_TYPE_3D:
106 			return tcu::UVec3(imageSize.x(), imageSize.y(), imageSize.z());
107 
108 		default:
109 			DE_FATAL("Unknown image type");
110 			return tcu::UVec3(1u, 1u, 1u);
111 	}
112 }
113 
getNumLayers(const ImageType imageType,const tcu::UVec3 & imageSize)114 deUint32 getNumLayers (const ImageType imageType, const tcu::UVec3& imageSize)
115 {
116 	switch (imageType)
117 	{
118 		case IMAGE_TYPE_1D:
119 		case IMAGE_TYPE_2D:
120 		case IMAGE_TYPE_3D:
121 		case IMAGE_TYPE_BUFFER:
122 			return 1u;
123 
124 		case IMAGE_TYPE_1D_ARRAY:
125 		case IMAGE_TYPE_2D_ARRAY:
126 			return imageSize.z();
127 
128 		case IMAGE_TYPE_CUBE:
129 			return 6u;
130 
131 		case IMAGE_TYPE_CUBE_ARRAY:
132 			return imageSize.z() * 6u;
133 
134 		default:
135 			DE_FATAL("Unknown image type");
136 			return 0u;
137 	}
138 }
139 
getNumPixels(const ImageType imageType,const tcu::UVec3 & imageSize)140 deUint32 getNumPixels (const ImageType imageType, const tcu::UVec3& imageSize)
141 {
142 	const tcu::UVec3 gridSize = getShaderGridSize(imageType, imageSize);
143 
144 	return gridSize.x() * gridSize.y() * gridSize.z();
145 }
146 
getDimensions(const ImageType imageType)147 deUint32 getDimensions (const ImageType imageType)
148 {
149 	switch (imageType)
150 	{
151 		case IMAGE_TYPE_1D:
152 		case IMAGE_TYPE_BUFFER:
153 			return 1u;
154 
155 		case IMAGE_TYPE_1D_ARRAY:
156 		case IMAGE_TYPE_2D:
157 			return 2u;
158 
159 		case IMAGE_TYPE_2D_ARRAY:
160 		case IMAGE_TYPE_CUBE:
161 		case IMAGE_TYPE_CUBE_ARRAY:
162 		case IMAGE_TYPE_3D:
163 			return 3u;
164 
165 		default:
166 			DE_FATAL("Unknown image type");
167 			return 0u;
168 	}
169 }
170 
getLayerDimensions(const ImageType imageType)171 deUint32 getLayerDimensions (const ImageType imageType)
172 {
173 	switch (imageType)
174 	{
175 		case IMAGE_TYPE_1D:
176 		case IMAGE_TYPE_BUFFER:
177 		case IMAGE_TYPE_1D_ARRAY:
178 			return 1u;
179 
180 		case IMAGE_TYPE_2D:
181 		case IMAGE_TYPE_2D_ARRAY:
182 		case IMAGE_TYPE_CUBE:
183 		case IMAGE_TYPE_CUBE_ARRAY:
184 			return 2u;
185 
186 		case IMAGE_TYPE_3D:
187 			return 3u;
188 
189 		default:
190 			DE_FATAL("Unknown image type");
191 			return 0u;
192 	}
193 }
194 
makeBufferCreateInfo(const VkDeviceSize bufferSize,const VkBufferUsageFlags usage)195 VkBufferCreateInfo makeBufferCreateInfo (const VkDeviceSize			bufferSize,
196 										 const VkBufferUsageFlags	usage)
197 {
198 	const VkBufferCreateInfo bufferCreateInfo =
199 	{
200 		VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,	// VkStructureType		sType;
201 		DE_NULL,								// const void*			pNext;
202 		0u,										// VkBufferCreateFlags	flags;
203 		bufferSize,								// VkDeviceSize			size;
204 		usage,									// VkBufferUsageFlags	usage;
205 		VK_SHARING_MODE_EXCLUSIVE,				// VkSharingMode		sharingMode;
206 		0u,										// deUint32				queueFamilyIndexCount;
207 		DE_NULL,								// const deUint32*		pQueueFamilyIndices;
208 	};
209 	return bufferCreateInfo;
210 }
211 
makeBufferImageCopy(const VkExtent3D extent,const deUint32 arraySize)212 VkBufferImageCopy makeBufferImageCopy (const VkExtent3D extent,
213 									   const deUint32	arraySize)
214 {
215 	const VkBufferImageCopy copyParams =
216 	{
217 		0ull,																		//	VkDeviceSize				bufferOffset;
218 		0u,																			//	deUint32					bufferRowLength;
219 		0u,																			//	deUint32					bufferImageHeight;
220 		makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, arraySize),	//	VkImageSubresourceLayers	imageSubresource;
221 		makeOffset3D(0, 0, 0),														//	VkOffset3D					imageOffset;
222 		extent,																		//	VkExtent3D					imageExtent;
223 	};
224 	return copyParams;
225 }
226 
makePipelineLayout(const DeviceInterface & vk,const VkDevice device,const VkDescriptorSetLayout descriptorSetLayout)227 Move<VkPipelineLayout> makePipelineLayout (const DeviceInterface&		vk,
228 										   const VkDevice				device,
229 										   const VkDescriptorSetLayout	descriptorSetLayout)
230 {
231 	const VkPipelineLayoutCreateInfo pipelineLayoutParams =
232 	{
233 		VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,		// VkStructureType					sType;
234 		DE_NULL,											// const void*						pNext;
235 		0u,													// VkPipelineLayoutCreateFlags		flags;
236 		1u,													// deUint32							setLayoutCount;
237 		&descriptorSetLayout,								// const VkDescriptorSetLayout*		pSetLayouts;
238 		0u,													// deUint32							pushConstantRangeCount;
239 		DE_NULL,											// const VkPushConstantRange*		pPushConstantRanges;
240 	};
241 	return createPipelineLayout(vk, device, &pipelineLayoutParams);
242 }
243 
makeComputePipeline(const DeviceInterface & vk,const VkDevice device,const VkPipelineLayout pipelineLayout,const VkShaderModule shaderModule)244 Move<VkPipeline> makeComputePipeline (const DeviceInterface&	vk,
245 									  const VkDevice			device,
246 									  const VkPipelineLayout	pipelineLayout,
247 									  const VkShaderModule		shaderModule)
248 {
249 	const VkPipelineShaderStageCreateInfo pipelineShaderStageParams =
250 	{
251 		VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,	// VkStructureType						sType;
252 		DE_NULL,												// const void*							pNext;
253 		0u,														// VkPipelineShaderStageCreateFlags		flags;
254 		VK_SHADER_STAGE_COMPUTE_BIT,							// VkShaderStageFlagBits				stage;
255 		shaderModule,											// VkShaderModule						module;
256 		"main",													// const char*							pName;
257 		DE_NULL,												// const VkSpecializationInfo*			pSpecializationInfo;
258 	};
259 	const VkComputePipelineCreateInfo pipelineCreateInfo =
260 	{
261 		VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,		// VkStructureType					sType;
262 		DE_NULL,											// const void*						pNext;
263 		0u,													// VkPipelineCreateFlags			flags;
264 		pipelineShaderStageParams,							// VkPipelineShaderStageCreateInfo	stage;
265 		pipelineLayout,										// VkPipelineLayout					layout;
266 		DE_NULL,											// VkPipeline						basePipelineHandle;
267 		0,													// deInt32							basePipelineIndex;
268 	};
269 	return createComputePipeline(vk, device, DE_NULL , &pipelineCreateInfo);
270 }
271 
makeGraphicsPipeline(const DeviceInterface & vk,const VkDevice device,const VkPipelineLayout pipelineLayout,const VkRenderPass renderPass,const VkShaderModule vertexModule,const VkShaderModule fragmentModule,const VkExtent2D renderSize,const deUint32 colorAttachmentCount,const bool dynamicSize)272 Move<VkPipeline> makeGraphicsPipeline (const DeviceInterface&	vk,
273 									   const VkDevice			device,
274 									   const VkPipelineLayout	pipelineLayout,
275 									   const VkRenderPass		renderPass,
276 									   const VkShaderModule		vertexModule,
277 									   const VkShaderModule		fragmentModule,
278 									   const VkExtent2D			renderSize,
279 									   const deUint32			colorAttachmentCount,
280 									   const bool				dynamicSize)
281 {
282 	std::vector<VkViewport>								viewports;
283 	std::vector<VkRect2D>								scissors;
284 
285 	const VkViewport									viewport						= makeViewport(renderSize);
286 	const VkRect2D										scissor							= makeRect2D(renderSize);
287 
288 	const VkFormat										vertexFormatPosition			= VK_FORMAT_R32G32B32A32_SFLOAT;
289 	const deUint32										vertexSizePosition				= tcu::getPixelSize(mapVkFormat(vertexFormatPosition));
290 	const deUint32										vertexBufferOffsetPosition		= 0u;
291 	const deUint32										vertexDataStride				= vertexSizePosition;
292 
293 	if (!dynamicSize)
294 	{
295 		viewports.push_back(viewport);
296 		scissors.push_back(scissor);
297 	}
298 
299 	const VkVertexInputBindingDescription				vertexInputBindingDescription	=
300 	{
301 		0u,							// deUint32             binding;
302 		vertexDataStride,			// deUint32             stride;
303 		VK_VERTEX_INPUT_RATE_VERTEX	// VkVertexInputRate    inputRate;
304 	};
305 
306 	const VkVertexInputAttributeDescription				vertexInputAttributeDescription	=
307 	{
308 		0u,							// deUint32    location;
309 		0u,							// deUint32    binding;
310 		vertexFormatPosition,		// VkFormat    format;
311 		vertexBufferOffsetPosition,	// deUint32    offset;
312 	};
313 
314 	const VkPipelineVertexInputStateCreateInfo			vertexInputStateCreateInfo		=
315 	{
316 		VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,	// VkStructureType                             sType;
317 		DE_NULL,													// const void*                                 pNext;
318 		(VkPipelineVertexInputStateCreateFlags)0,					// VkPipelineVertexInputStateCreateFlags       flags;
319 		1u,															// deUint32                                    vertexBindingDescriptionCount;
320 		&vertexInputBindingDescription,								// const VkVertexInputBindingDescription*      pVertexBindingDescriptions;
321 		1u,															// deUint32                                    vertexAttributeDescriptionCount;
322 		&vertexInputAttributeDescription							// const VkVertexInputAttributeDescription*    pVertexAttributeDescriptions;
323 	};
324 
325 	const VkColorComponentFlags							colorComponentsAll				= VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
326 	const VkPipelineColorBlendAttachmentState			colorBlendAttachmentState		=
327 	{
328 		VK_FALSE,				// VkBool32                 blendEnable;
329 		VK_BLEND_FACTOR_ONE,	// VkBlendFactor            srcColorBlendFactor;
330 		VK_BLEND_FACTOR_ZERO,	// VkBlendFactor            dstColorBlendFactor;
331 		VK_BLEND_OP_ADD,		// VkBlendOp                colorBlendOp;
332 		VK_BLEND_FACTOR_ONE,	// VkBlendFactor            srcAlphaBlendFactor;
333 		VK_BLEND_FACTOR_ZERO,	// VkBlendFactor            dstAlphaBlendFactor;
334 		VK_BLEND_OP_ADD,		// VkBlendOp                alphaBlendOp;
335 		colorComponentsAll		// VkColorComponentFlags    colorWriteMask;
336 	};
337 
338 	std::vector<VkPipelineColorBlendAttachmentState>	colorAttachments				(colorAttachmentCount, colorBlendAttachmentState);
339 
340 	const VkPipelineColorBlendStateCreateInfo			pipelineColorBlendStateInfo		=
341 	{
342 		VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,		// VkStructureType                              sType;
343 		DE_NULL,														// const void*                                  pNext;
344 		(VkPipelineColorBlendStateCreateFlags)0,						// VkPipelineColorBlendStateCreateFlags         flags;
345 		VK_FALSE,														// VkBool32                                     logicOpEnable;
346 		VK_LOGIC_OP_COPY,												// VkLogicOp                                    logicOp;
347 		(deUint32)colorAttachments.size(),								// deUint32                                     attachmentCount;
348 		colorAttachments.size() != 0 ? &colorAttachments[0] : DE_NULL,	// const VkPipelineColorBlendAttachmentState*   pAttachments;
349 		{ 0.0f, 0.0f, 0.0f, 0.0f }										// float                                        blendConstants[4];
350 	};
351 
352 	return vk::makeGraphicsPipeline(vk,										// const DeviceInterface&                        vk
353 									device,									// const VkDevice                                device
354 									pipelineLayout,							// const VkPipelineLayout                        pipelineLayout
355 									vertexModule,							// const VkShaderModule                          vertexShaderModule
356 									DE_NULL,								// const VkShaderModule                          tessellationControlModule
357 									DE_NULL,								// const VkShaderModule                          tessellationEvalModule
358 									DE_NULL,								// const VkShaderModule                          geometryShaderModule
359 									fragmentModule,							// const VkShaderModule                          fragmentShaderModule
360 									renderPass,								// const VkRenderPass                            renderPass
361 									viewports,								// const std::vector<VkViewport>&                viewports
362 									scissors,								// const std::vector<VkRect2D>&                  scissors
363 									VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,	// const VkPrimitiveTopology                     topology
364 									0u,										// const deUint32                                subpass
365 									0u,										// const deUint32                                patchControlPoints
366 									&vertexInputStateCreateInfo,			// const VkPipelineVertexInputStateCreateInfo*   vertexInputStateCreateInfo
367 									DE_NULL,								// const VkPipelineRasterizationStateCreateInfo* rasterizationStateCreateInfo
368 									DE_NULL,								// const VkPipelineMultisampleStateCreateInfo*   multisampleStateCreateInfo
369 									DE_NULL,								// const VkPipelineDepthStencilStateCreateInfo*  depthStencilStateCreateInfo
370 									&pipelineColorBlendStateInfo);			// const VkPipelineColorBlendStateCreateInfo*    colorBlendStateCreateInfo
371 }
372 
373 //! A single-subpass render pass.
makeRenderPass(const DeviceInterface & vk,const VkDevice device,const VkFormat inputFormat,const VkFormat colorFormat)374 Move<VkRenderPass> makeRenderPass (const DeviceInterface&	vk,
375 								   const VkDevice			device,
376 								   const VkFormat			inputFormat,
377 								   const VkFormat			colorFormat)
378 {
379 	const VkAttachmentReference		inputAttachmentRef			=
380 	{
381 		0u,															// deUint32			attachment;
382 		VK_IMAGE_LAYOUT_GENERAL										// VkImageLayout	layout;
383 	};
384 
385 	const VkAttachmentReference		colorAttachmentRef			=
386 	{
387 		1u,															// deUint32			attachment;
388 		VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL					// VkImageLayout	layout;
389 	};
390 
391 	const VkSubpassDescription		subpassDescription			=
392 	{
393 		(VkSubpassDescriptionFlags)0,								// VkSubpassDescriptionFlags		flags;
394 		VK_PIPELINE_BIND_POINT_GRAPHICS,							// VkPipelineBindPoint				pipelineBindPoint;
395 		1u,															// deUint32							inputAttachmentCount;
396 		&inputAttachmentRef,										// const VkAttachmentReference*		pInputAttachments;
397 		1u,															// deUint32							colorAttachmentCount;
398 		&colorAttachmentRef,										// const VkAttachmentReference*		pColorAttachments;
399 		DE_NULL,													// const VkAttachmentReference*		pResolveAttachments;
400 		DE_NULL,													// const VkAttachmentReference*		pDepthStencilAttachment;
401 		0u,															// deUint32							preserveAttachmentCount;
402 		DE_NULL														// const deUint32*					pPreserveAttachments;
403 	};
404 
405 	const VkAttachmentDescription	attachmentsDescriptions[]	=
406 	{
407 		//inputAttachmentDescription,
408 		{
409 			(VkAttachmentDescriptionFlags)0,						// VkAttachmentDescriptionFlags		flags;
410 			inputFormat,											// VkFormat							format;
411 			VK_SAMPLE_COUNT_1_BIT,									// VkSampleCountFlagBits			samples;
412 			VK_ATTACHMENT_LOAD_OP_LOAD,								// VkAttachmentLoadOp				loadOp;
413 			VK_ATTACHMENT_STORE_OP_DONT_CARE,						// VkAttachmentStoreOp				storeOp;
414 			VK_ATTACHMENT_LOAD_OP_DONT_CARE,						// VkAttachmentLoadOp				stencilLoadOp;
415 			VK_ATTACHMENT_STORE_OP_DONT_CARE,						// VkAttachmentStoreOp				stencilStoreOp;
416 			VK_IMAGE_LAYOUT_GENERAL,								// VkImageLayout					initialLayout;
417 			VK_IMAGE_LAYOUT_GENERAL,								// VkImageLayout					finalLayout;
418 		},
419 		//colorAttachmentDescription
420 		{
421 			(VkAttachmentDescriptionFlags)0,						// VkAttachmentDescriptionFlags		flags;
422 			colorFormat,											// VkFormat							format;
423 			VK_SAMPLE_COUNT_1_BIT,									// VkSampleCountFlagBits			samples;
424 			VK_ATTACHMENT_LOAD_OP_CLEAR,							// VkAttachmentLoadOp				loadOp;
425 			VK_ATTACHMENT_STORE_OP_STORE,							// VkAttachmentStoreOp				storeOp;
426 			VK_ATTACHMENT_LOAD_OP_DONT_CARE,						// VkAttachmentLoadOp				stencilLoadOp;
427 			VK_ATTACHMENT_STORE_OP_DONT_CARE,						// VkAttachmentStoreOp				stencilStoreOp;
428 			VK_IMAGE_LAYOUT_UNDEFINED,								// VkImageLayout					initialLayout;
429 			VK_IMAGE_LAYOUT_GENERAL,								// VkImageLayout					finalLayout;
430 		}
431 	};
432 
433 	const VkRenderPassCreateInfo	renderPassInfo				=
434 	{
435 		VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,					// VkStructureType					sType;
436 		DE_NULL,													// const void*						pNext;
437 		(VkRenderPassCreateFlags)0,									// VkRenderPassCreateFlags			flags;
438 		DE_LENGTH_OF_ARRAY(attachmentsDescriptions),				// deUint32							attachmentCount;
439 		attachmentsDescriptions,									// const VkAttachmentDescription*	pAttachments;
440 		1u,															// deUint32							subpassCount;
441 		&subpassDescription,										// const VkSubpassDescription*		pSubpasses;
442 		0u,															// deUint32							dependencyCount;
443 		DE_NULL														// const VkSubpassDependency*		pDependencies;
444 	};
445 
446 	return createRenderPass(vk, device, &renderPassInfo);
447 }
448 
449 //! A single-subpass render pass.
makeRenderPass(const DeviceInterface & vk,const VkDevice device)450 Move<VkRenderPass> makeRenderPass (const DeviceInterface&	vk,
451 								   const VkDevice			device)
452 {
453 	const VkSubpassDescription		subpassDescription			=
454 	{
455 		(VkSubpassDescriptionFlags)0,								// VkSubpassDescriptionFlags		flags;
456 		VK_PIPELINE_BIND_POINT_GRAPHICS,							// VkPipelineBindPoint				pipelineBindPoint;
457 		0u,															// deUint32							inputAttachmentCount;
458 		DE_NULL,													// const VkAttachmentReference*		pInputAttachments;
459 		0u,															// deUint32							colorAttachmentCount;
460 		DE_NULL,													// const VkAttachmentReference*		pColorAttachments;
461 		DE_NULL,													// const VkAttachmentReference*		pResolveAttachments;
462 		DE_NULL,													// const VkAttachmentReference*		pDepthStencilAttachment;
463 		0u,															// deUint32							preserveAttachmentCount;
464 		DE_NULL														// const deUint32*					pPreserveAttachments;
465 	};
466 
467 	const VkRenderPassCreateInfo	renderPassInfo				=
468 	{
469 		VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,					// VkStructureType					sType;
470 		DE_NULL,													// const void*						pNext;
471 		(VkRenderPassCreateFlags)0,									// VkRenderPassCreateFlags			flags;
472 		0,															// deUint32							attachmentCount;
473 		DE_NULL,													// const VkAttachmentDescription*	pAttachments;
474 		1u,															// deUint32							subpassCount;
475 		&subpassDescription,										// const VkSubpassDescription*		pSubpasses;
476 		0u,															// deUint32							dependencyCount;
477 		DE_NULL														// const VkSubpassDependency*		pDependencies;
478 	};
479 
480 	return createRenderPass(vk, device, &renderPassInfo);
481 }
482 
makeBufferView(const DeviceInterface & vk,const VkDevice vkDevice,const VkBuffer buffer,const VkFormat format,const VkDeviceSize offset,const VkDeviceSize size)483 Move<VkBufferView> makeBufferView (const DeviceInterface&	vk,
484 								   const VkDevice			vkDevice,
485 								   const VkBuffer			buffer,
486 								   const VkFormat			format,
487 								   const VkDeviceSize		offset,
488 								   const VkDeviceSize		size)
489 {
490 	const VkBufferViewCreateInfo bufferViewParams =
491 	{
492 		VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO,	// VkStructureType			sType;
493 		DE_NULL,									// const void*				pNext;
494 		0u,											// VkBufferViewCreateFlags	flags;
495 		buffer,										// VkBuffer					buffer;
496 		format,										// VkFormat					format;
497 		offset,										// VkDeviceSize				offset;
498 		size,										// VkDeviceSize				range;
499 	};
500 	return createBufferView(vk, vkDevice, &bufferViewParams);
501 }
502 
makeImageView(const DeviceInterface & vk,const VkDevice vkDevice,const VkImage image,const VkImageViewType imageViewType,const VkFormat format,const VkImageSubresourceRange subresourceRange,const VkImageViewUsageCreateInfo * ImageUsageCreateInfo)503 Move<VkImageView> makeImageView (const DeviceInterface&					vk,
504 								 const VkDevice							vkDevice,
505 								 const VkImage							image,
506 								 const VkImageViewType					imageViewType,
507 								 const VkFormat							format,
508 								 const VkImageSubresourceRange			subresourceRange,
509 								 const VkImageViewUsageCreateInfo*		ImageUsageCreateInfo)
510 {
511 	const VkImageViewCreateInfo imageViewParams =
512 	{
513 		VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,		// VkStructureType			sType;
514 		ImageUsageCreateInfo,							// const void*				pNext;
515 		0u,												// VkImageViewCreateFlags	flags;
516 		image,											// VkImage					image;
517 		imageViewType,									// VkImageViewType			viewType;
518 		format,											// VkFormat					format;
519 		makeComponentMappingRGBA(),						// VkComponentMapping		components;
520 		subresourceRange,								// VkImageSubresourceRange	subresourceRange;
521 	};
522 	return createImageView(vk, vkDevice, &imageViewParams);
523 }
524 
makeDescriptorSet(const DeviceInterface & vk,const VkDevice device,const VkDescriptorPool descriptorPool,const VkDescriptorSetLayout setLayout)525 Move<VkDescriptorSet> makeDescriptorSet (const DeviceInterface&			vk,
526 										 const VkDevice					device,
527 										 const VkDescriptorPool			descriptorPool,
528 										 const VkDescriptorSetLayout	setLayout)
529 {
530 	const VkDescriptorSetAllocateInfo allocateParams =
531 	{
532 		VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,		// VkStructureType				sType;
533 		DE_NULL,											// const void*					pNext;
534 		descriptorPool,										// VkDescriptorPool				descriptorPool;
535 		1u,													// deUint32						setLayoutCount;
536 		&setLayout,											// const VkDescriptorSetLayout*	pSetLayouts;
537 	};
538 	return allocateDescriptorSet(vk, device, &allocateParams);
539 }
540 
makeImageViewUsageCreateInfo(const VkImageUsageFlags imageUsageFlags)541 VkImageViewUsageCreateInfo makeImageViewUsageCreateInfo (const VkImageUsageFlags imageUsageFlags)
542 {
543 	VkImageViewUsageCreateInfo imageViewUsageCreateInfo =
544 	{
545 		VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO_KHR,	//VkStructureType		sType;
546 		DE_NULL,											//const void*			pNext;
547 		imageUsageFlags,									//VkImageUsageFlags		usage;
548 	};
549 
550 	return imageViewUsageCreateInfo;
551 }
552 
makeSamplerCreateInfo()553 VkSamplerCreateInfo makeSamplerCreateInfo ()
554 {
555 	const VkSamplerCreateInfo defaultSamplerParams =
556 	{
557 		VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,		// VkStructureType			sType;
558 		DE_NULL,									// const void*				pNext;
559 		0u,											// VkSamplerCreateFlags		flags;
560 		VK_FILTER_NEAREST,							// VkFilter					magFilter;
561 		VK_FILTER_NEAREST,							// VkFilter					minFilter;
562 		VK_SAMPLER_MIPMAP_MODE_NEAREST,				// VkSamplerMipmapMode		mipmapMode;
563 		VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,		// VkSamplerAddressMode		addressModeU;
564 		VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,		// VkSamplerAddressMode		addressModeV;
565 		VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,		// VkSamplerAddressMode		addressModeW;
566 		0.0f,										// float					mipLodBias;
567 		VK_FALSE,									// VkBool32					anisotropyEnable;
568 		1.0f,										// float					maxAnisotropy;
569 		VK_FALSE,									// VkBool32					compareEnable;
570 		VK_COMPARE_OP_NEVER,						// VkCompareOp				compareOp;
571 		0.0f,										// float					minLod;
572 		0.25f,										// float					maxLod;
573 		VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK,	// VkBorderColor			borderColor;
574 		VK_FALSE									// VkBool32					unnormalizedCoordinates;
575 	};
576 
577 	return defaultSamplerParams;
578 }
579 
getCompressedImageResolutionInBlocks(const vk::VkFormat format,const tcu::UVec3 & size)580 tcu::UVec3 getCompressedImageResolutionInBlocks (const vk::VkFormat format, const tcu::UVec3& size)
581 {
582 	deUint32	blockWidth	= getBlockWidth(format);
583 	deUint32	blockHeight	= getBlockHeight(format);
584 
585 	DE_ASSERT(size[2] == 1);
586 	DE_ASSERT(blockWidth != 0 && blockHeight != 0);
587 
588 	deUint32	widthInBlocks	= (size[0] + blockWidth - 1) / blockWidth;
589 	deUint32	heightInBlocks	= (size[1] + blockHeight - 1) / blockHeight;
590 
591 	return tcu::UVec3(widthInBlocks, heightInBlocks, 1);
592 }
593 
getCompressedImageResolutionBlockCeil(const vk::VkFormat format,const tcu::UVec3 & size)594 tcu::UVec3 getCompressedImageResolutionBlockCeil (const vk::VkFormat format, const tcu::UVec3& size)
595 {
596 	deUint32	blockWidth	= getBlockWidth(format);
597 	deUint32	blockHeight	= getBlockHeight(format);
598 
599 	DE_ASSERT(size[2] == 1);
600 	DE_ASSERT(blockWidth != 0 && blockHeight != 0);
601 
602 	deUint32	widthInBlocks	= (size[0] + blockWidth - 1) / blockWidth;
603 	deUint32	heightInBlocks	= (size[1] + blockHeight - 1) / blockHeight;
604 
605 	return tcu::UVec3(blockWidth * widthInBlocks, blockHeight * heightInBlocks, 1);
606 }
607 
getCompressedImageSizeInBytes(const vk::VkFormat format,const tcu::UVec3 & size)608 VkDeviceSize getCompressedImageSizeInBytes (const vk::VkFormat format, const tcu::UVec3& size)
609 {
610 	tcu::UVec3		sizeInBlocks	= getCompressedImageResolutionInBlocks(format, size);
611 	deUint32		blockBytes		= getBlockSizeInBytes(format);
612 	VkDeviceSize	sizeBytes		= sizeInBlocks[0] * sizeInBlocks[1] * sizeInBlocks[2] * blockBytes;
613 
614 	return sizeBytes;
615 }
616 
getUncompressedImageSizeInBytes(const vk::VkFormat format,const tcu::UVec3 & size)617 VkDeviceSize getUncompressedImageSizeInBytes (const vk::VkFormat format, const tcu::UVec3& size)
618 {
619 	const tcu::IVec3	sizeAsIVec3	= tcu::IVec3((int)size.x(), (int)size.y(), (int)size.z());
620 	const VkDeviceSize	sizeBytes	= getImageSizeBytes(sizeAsIVec3, format);
621 
622 	return sizeBytes;
623 }
624 
mapImageType(const ImageType imageType)625 VkImageType	mapImageType (const ImageType imageType)
626 {
627 	switch (imageType)
628 	{
629 		case IMAGE_TYPE_1D:
630 		case IMAGE_TYPE_1D_ARRAY:
631 		case IMAGE_TYPE_BUFFER:
632 			return VK_IMAGE_TYPE_1D;
633 
634 		case IMAGE_TYPE_2D:
635 		case IMAGE_TYPE_2D_ARRAY:
636 		case IMAGE_TYPE_CUBE:
637 		case IMAGE_TYPE_CUBE_ARRAY:
638 			return VK_IMAGE_TYPE_2D;
639 
640 		case IMAGE_TYPE_3D:
641 			return VK_IMAGE_TYPE_3D;
642 
643 		default:
644 			DE_ASSERT(false);
645 			return VK_IMAGE_TYPE_LAST;
646 	}
647 }
648 
mapImageViewType(const ImageType imageType)649 VkImageViewType	mapImageViewType (const ImageType imageType)
650 {
651 	switch (imageType)
652 	{
653 		case IMAGE_TYPE_1D:			return VK_IMAGE_VIEW_TYPE_1D;
654 		case IMAGE_TYPE_1D_ARRAY:	return VK_IMAGE_VIEW_TYPE_1D_ARRAY;
655 		case IMAGE_TYPE_2D:			return VK_IMAGE_VIEW_TYPE_2D;
656 		case IMAGE_TYPE_2D_ARRAY:	return VK_IMAGE_VIEW_TYPE_2D_ARRAY;
657 		case IMAGE_TYPE_3D:			return VK_IMAGE_VIEW_TYPE_3D;
658 		case IMAGE_TYPE_CUBE:		return VK_IMAGE_VIEW_TYPE_CUBE;
659 		case IMAGE_TYPE_CUBE_ARRAY:	return VK_IMAGE_VIEW_TYPE_CUBE_ARRAY;
660 
661 		default:
662 			DE_ASSERT(false);
663 			return VK_IMAGE_VIEW_TYPE_LAST;
664 	}
665 }
666 
getImageTypeName(const ImageType imageType)667 std::string getImageTypeName (const ImageType imageType)
668 {
669 	switch (imageType)
670 	{
671 		case IMAGE_TYPE_1D:			return "1d";
672 		case IMAGE_TYPE_1D_ARRAY:	return "1d_array";
673 		case IMAGE_TYPE_2D:			return "2d";
674 		case IMAGE_TYPE_2D_ARRAY:	return "2d_array";
675 		case IMAGE_TYPE_3D:			return "3d";
676 		case IMAGE_TYPE_CUBE:		return "cube";
677 		case IMAGE_TYPE_CUBE_ARRAY:	return "cube_array";
678 		case IMAGE_TYPE_BUFFER:		return "buffer";
679 
680 		default:
681 			DE_ASSERT(false);
682 			return "";
683 	}
684 }
685 
getShaderImageType(const tcu::TextureFormat & format,const ImageType imageType,const bool multisample)686 std::string getShaderImageType (const tcu::TextureFormat& format, const ImageType imageType, const bool multisample)
687 {
688 	std::string formatPart = tcu::getTextureChannelClass(format.type) == tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER ? "u" :
689 							 tcu::getTextureChannelClass(format.type) == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER   ? "i" : "";
690 
691 	std::string imageTypePart;
692 	if (multisample)
693 	{
694 		switch (imageType)
695 		{
696 			case IMAGE_TYPE_2D:			imageTypePart = "2DMS";			break;
697 			case IMAGE_TYPE_2D_ARRAY:	imageTypePart = "2DMSArray";	break;
698 
699 			default:
700 				DE_ASSERT(false);
701 		}
702 	}
703 	else
704 	{
705 		switch (imageType)
706 		{
707 			case IMAGE_TYPE_1D:			imageTypePart = "1D";			break;
708 			case IMAGE_TYPE_1D_ARRAY:	imageTypePart = "1DArray";		break;
709 			case IMAGE_TYPE_2D:			imageTypePart = "2D";			break;
710 			case IMAGE_TYPE_2D_ARRAY:	imageTypePart = "2DArray";		break;
711 			case IMAGE_TYPE_3D:			imageTypePart = "3D";			break;
712 			case IMAGE_TYPE_CUBE:		imageTypePart = "Cube";			break;
713 			case IMAGE_TYPE_CUBE_ARRAY:	imageTypePart = "CubeArray";	break;
714 			case IMAGE_TYPE_BUFFER:		imageTypePart = "Buffer";		break;
715 
716 			default:
717 				DE_ASSERT(false);
718 		}
719 	}
720 
721 	return formatPart + "image" + imageTypePart;
722 }
723 
getShaderImageFormatQualifier(const tcu::TextureFormat & format)724 std::string getShaderImageFormatQualifier (const tcu::TextureFormat& format)
725 {
726 	const char* orderPart;
727 	const char* typePart;
728 
729 	switch (format.order)
730 	{
731 		case tcu::TextureFormat::R:		orderPart = "r";	break;
732 		case tcu::TextureFormat::RG:	orderPart = "rg";	break;
733 		case tcu::TextureFormat::RGB:	orderPart = "rgb";	break;
734 		case tcu::TextureFormat::RGBA:	orderPart = "rgba";	break;
735 		case tcu::TextureFormat::sRGBA:	orderPart = "rgba";	break;
736 
737 		default:
738 			DE_ASSERT(false);
739 			orderPart = DE_NULL;
740 	}
741 
742 	switch (format.type)
743 	{
744 		case tcu::TextureFormat::FLOAT:				typePart = "32f";		break;
745 		case tcu::TextureFormat::HALF_FLOAT:		typePart = "16f";		break;
746 
747 		case tcu::TextureFormat::UNSIGNED_INT32:	typePart = "32ui";		break;
748 		case tcu::TextureFormat::UNSIGNED_INT16:	typePart = "16ui";		break;
749 		case tcu::TextureFormat::UNSIGNED_INT8:		typePart = "8ui";		break;
750 
751 		case tcu::TextureFormat::SIGNED_INT32:		typePart = "32i";		break;
752 		case tcu::TextureFormat::SIGNED_INT16:		typePart = "16i";		break;
753 		case tcu::TextureFormat::SIGNED_INT8:		typePart = "8i";		break;
754 
755 		case tcu::TextureFormat::UNORM_INT16:		typePart = "16";		break;
756 		case tcu::TextureFormat::UNORM_INT8:		typePart = "8";			break;
757 
758 		case tcu::TextureFormat::SNORM_INT16:		typePart = "16_snorm";	break;
759 		case tcu::TextureFormat::SNORM_INT8:		typePart = "8_snorm";	break;
760 
761 		default:
762 			DE_ASSERT(false);
763 			typePart = DE_NULL;
764 	}
765 
766 	return std::string() + orderPart + typePart;
767 }
768 
getGlslSamplerType(const tcu::TextureFormat & format,VkImageViewType type)769 std::string getGlslSamplerType (const tcu::TextureFormat& format, VkImageViewType type)
770 {
771 	const char* typePart	= DE_NULL;
772 	const char* formatPart	= tcu::getTextureChannelClass(format.type) == tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER ? "u" :
773 							  tcu::getTextureChannelClass(format.type) == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER   ? "i" : "";
774 
775 	switch (type)
776 	{
777 		case VK_IMAGE_VIEW_TYPE_1D:			typePart = "sampler1D";			break;
778 		case VK_IMAGE_VIEW_TYPE_1D_ARRAY:	typePart = "sampler1DArray";	break;
779 		case VK_IMAGE_VIEW_TYPE_2D:			typePart = "sampler2D";			break;
780 		case VK_IMAGE_VIEW_TYPE_2D_ARRAY:	typePart = "sampler2DArray";	break;
781 		case VK_IMAGE_VIEW_TYPE_3D:			typePart = "sampler3D";			break;
782 		case VK_IMAGE_VIEW_TYPE_CUBE:		typePart = "samplerCube";		break;
783 		case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:	typePart = "samplerCubeArray";	break;
784 
785 		default:
786 			DE_FATAL("Unknown image view type");
787 			break;
788 	}
789 
790 	return std::string(formatPart) + typePart;
791 }
792 
793 
getGlslInputFormatType(const vk::VkFormat format)794 const char* getGlslInputFormatType (const vk::VkFormat format)
795 {
796 	switch (format)
797 	{
798 		// 64-bit
799 		case VK_FORMAT_R16G16B16A16_UNORM:		return "subpassInput";
800 		case VK_FORMAT_R16G16B16A16_SNORM:		return "subpassInput";
801 		case VK_FORMAT_R16G16B16A16_USCALED:	return "subpassInput";
802 		case VK_FORMAT_R16G16B16A16_SSCALED:	return "subpassInput";
803 		case VK_FORMAT_R16G16B16A16_UINT:		return "usubpassInput";
804 		case VK_FORMAT_R16G16B16A16_SINT:		return "isubpassInput";
805 		case VK_FORMAT_R16G16B16A16_SFLOAT:		return "subpassInput";
806 		case VK_FORMAT_R32G32_UINT:				return "usubpassInput";
807 		case VK_FORMAT_R32G32_SINT:				return "isubpassInput";
808 		case VK_FORMAT_R32G32_SFLOAT:			return "subpassInput";
809 		// TODO: case VK_FORMAT_R64_UINT:		return "usubpassInput";
810 		// TODO: case VK_FORMAT_R64_SINT:		return "isubpassInput";
811 		// TODO: case VK_FORMAT_R64_SFLOAT:		return "subpassInput";
812 
813 		// 128-bit
814 		case VK_FORMAT_R32G32B32A32_UINT:		return "usubpassInput";
815 		case VK_FORMAT_R32G32B32A32_SINT:		return "isubpassInput";
816 		case VK_FORMAT_R32G32B32A32_SFLOAT:		return "subpassInput";
817 		// TODO: case VK_FORMAT_R64G64_UINT:	return "usubpassInput";
818 		// TODO: case VK_FORMAT_R64G64_SINT:	return "isubpassInput";
819 		// TODO: case VK_FORMAT_R64G64_SFLOAT:	return "subpassInput";
820 
821 		default:	TCU_THROW(InternalError, "Unknown format");
822 	}
823 }
824 
getGlslFormatType(const vk::VkFormat format)825 const char* getGlslFormatType (const vk::VkFormat format)
826 {
827 	switch (format)
828 	{
829 		// 64-bit
830 		case VK_FORMAT_R16G16B16A16_UNORM:		return "vec4";
831 		case VK_FORMAT_R16G16B16A16_SNORM:		return "vec4";
832 		case VK_FORMAT_R16G16B16A16_USCALED:	return "vec4";
833 		case VK_FORMAT_R16G16B16A16_SSCALED:	return "vec4";
834 		case VK_FORMAT_R16G16B16A16_UINT:		return "uvec4";
835 		case VK_FORMAT_R16G16B16A16_SINT:		return "ivec4";
836 		case VK_FORMAT_R16G16B16A16_SFLOAT:		return "vec4";
837 		case VK_FORMAT_R32G32_UINT:				return "uvec2";
838 		case VK_FORMAT_R32G32_SINT:				return "ivec2";
839 		case VK_FORMAT_R32G32_SFLOAT:			return "vec2";
840 		// TODO: case VK_FORMAT_R64_UINT:		return "uint64";
841 		// TODO: case VK_FORMAT_R64_SINT:		return "int64";
842 		// TODO: case VK_FORMAT_R64_SFLOAT:		return "double";
843 
844 		// 128-bit
845 		case VK_FORMAT_R32G32B32A32_UINT:		return "uvec4";
846 		case VK_FORMAT_R32G32B32A32_SINT:		return "ivec4";
847 		case VK_FORMAT_R32G32B32A32_SFLOAT:		return "vec4";
848 		// TODO: case VK_FORMAT_R64G64_UINT:	return "ulvec2";
849 		// TODO: case VK_FORMAT_R64G64_SINT:	return "ilvec2";
850 		// TODO: case VK_FORMAT_R64G64_SFLOAT:	return "dvec2";
851 
852 		default:	TCU_THROW(InternalError, "Unknown format");
853 	}
854 }
855 
getGlslAttachmentType(const vk::VkFormat format)856 const char* getGlslAttachmentType (const vk::VkFormat format)
857 {
858 	const tcu::TextureFormat		textureFormat	= mapVkFormat(format);
859 	const tcu::TextureChannelClass	channelClass	= tcu::getTextureChannelClass(textureFormat.type);
860 
861 	switch (channelClass)
862 	{
863 		case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
864 			return "ivec4";
865 
866 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
867 			return "uvec4";
868 
869 		case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
870 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
871 		case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
872 			return "vec4";
873 
874 		default:
875 			DE_FATAL("Unknown channel class");
876 			return "";
877 	}
878 }
879 
getGlslInputAttachmentType(const vk::VkFormat format)880 const char* getGlslInputAttachmentType (const vk::VkFormat format)
881 {
882 	const tcu::TextureFormat		textureFormat	= mapVkFormat(format);
883 	const tcu::TextureChannelClass	channelClass	= tcu::getTextureChannelClass(textureFormat.type);
884 
885 	switch (channelClass)
886 	{
887 		case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
888 			return "isubpassInput";
889 
890 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
891 			return "usubpassInput";
892 
893 		case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
894 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
895 		case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
896 			return "subpassInput";
897 
898 		default:
899 			DE_FATAL("Unknown channel class");
900 			return "";
901 	}
902 }
903 
isPackedType(const vk::VkFormat format)904 bool isPackedType (const vk::VkFormat format)
905 {
906 	const tcu::TextureFormat	textureFormat	= mapVkFormat(format);
907 
908 	DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELTYPE_LAST == 40);
909 
910 	switch (textureFormat.type)
911 	{
912 		case tcu::TextureFormat::UNORM_BYTE_44:
913 		case tcu::TextureFormat::UNORM_SHORT_565:
914 		case tcu::TextureFormat::UNORM_SHORT_555:
915 		case tcu::TextureFormat::UNORM_SHORT_4444:
916 		case tcu::TextureFormat::UNORM_SHORT_5551:
917 		case tcu::TextureFormat::UNORM_SHORT_1555:
918 		case tcu::TextureFormat::UNORM_INT_101010:
919 		case tcu::TextureFormat::SNORM_INT_1010102_REV:
920 		case tcu::TextureFormat::UNORM_INT_1010102_REV:
921 		case tcu::TextureFormat::UNSIGNED_BYTE_44:
922 		case tcu::TextureFormat::UNSIGNED_SHORT_565:
923 		case tcu::TextureFormat::UNSIGNED_SHORT_4444:
924 		case tcu::TextureFormat::UNSIGNED_SHORT_5551:
925 		case tcu::TextureFormat::SIGNED_INT_1010102_REV:
926 		case tcu::TextureFormat::UNSIGNED_INT_1010102_REV:
927 		case tcu::TextureFormat::UNSIGNED_INT_11F_11F_10F_REV:
928 		case tcu::TextureFormat::UNSIGNED_INT_999_E5_REV:
929 		case tcu::TextureFormat::UNSIGNED_INT_16_8_8:
930 		case tcu::TextureFormat::UNSIGNED_INT_24_8:
931 		case tcu::TextureFormat::UNSIGNED_INT_24_8_REV:
932 			return true;
933 
934 		default:
935 			return false;
936 	}
937 }
938 
isComponentSwizzled(const vk::VkFormat format)939 bool isComponentSwizzled (const vk::VkFormat format)
940 {
941 	const tcu::TextureFormat	textureFormat	= mapVkFormat(format);
942 
943 	DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELORDER_LAST == 21);
944 
945 	switch (textureFormat.order)
946 	{
947 		case tcu::TextureFormat::ARGB:
948 		case tcu::TextureFormat::BGR:
949 		case tcu::TextureFormat::BGRA:
950 		case tcu::TextureFormat::sBGR:
951 		case tcu::TextureFormat::sBGRA:
952 			return true;
953 
954 		default:
955 			return false;
956 	}
957 }
958 
getNumUsedChannels(const vk::VkFormat format)959 int getNumUsedChannels (const vk::VkFormat format)
960 {
961 	// make sure this function will be checked if type table is updated
962 	DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELORDER_LAST == 21);
963 
964 	const tcu::TextureFormat	textureFormat	= mapVkFormat(format);
965 
966 	return getNumUsedChannels(textureFormat.order);
967 }
968 
isFormatImageLoadStoreCapable(const vk::VkFormat format)969 bool isFormatImageLoadStoreCapable (const vk::VkFormat format)
970 {
971 	// These come from https://www.khronos.org/registry/vulkan/specs/1.1/html/vkspec.html#spirvenv-image-formats
972 	switch (format)
973 	{
974 		case VK_FORMAT_R32G32B32A32_SFLOAT:
975 		case VK_FORMAT_R16G16B16A16_SFLOAT:
976 		case VK_FORMAT_R32_SFLOAT:
977 		case VK_FORMAT_R8G8B8A8_UNORM:
978 		case VK_FORMAT_R8G8B8A8_SNORM:
979 		case VK_FORMAT_R32G32_SFLOAT:
980 		case VK_FORMAT_R16G16_SFLOAT:
981 		case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
982 		case VK_FORMAT_R16_SFLOAT:
983 		case VK_FORMAT_R16G16B16A16_UNORM:
984 		case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
985 		case VK_FORMAT_R16G16_UNORM:
986 		case VK_FORMAT_R8G8_UNORM:
987 		case VK_FORMAT_R16_UNORM:
988 		case VK_FORMAT_R8_UNORM:
989 		case VK_FORMAT_R16G16B16A16_SNORM:
990 		case VK_FORMAT_R16G16_SNORM:
991 		case VK_FORMAT_R8G8_SNORM:
992 		case VK_FORMAT_R16_SNORM:
993 		case VK_FORMAT_R8_SNORM:
994 		case VK_FORMAT_R32G32B32A32_SINT:
995 		case VK_FORMAT_R16G16B16A16_SINT:
996 		case VK_FORMAT_R8G8B8A8_SINT:
997 		case VK_FORMAT_R32_SINT:
998 		case VK_FORMAT_R32G32_SINT:
999 		case VK_FORMAT_R16G16_SINT:
1000 		case VK_FORMAT_R8G8_SINT:
1001 		case VK_FORMAT_R16_SINT:
1002 		case VK_FORMAT_R8_SINT:
1003 		case VK_FORMAT_R32G32B32A32_UINT:
1004 		case VK_FORMAT_R16G16B16A16_UINT:
1005 		case VK_FORMAT_R8G8B8A8_UINT:
1006 		case VK_FORMAT_R32_UINT:
1007 		case VK_FORMAT_A2B10G10R10_UINT_PACK32:
1008 		case VK_FORMAT_R32G32_UINT:
1009 		case VK_FORMAT_R16G16_UINT:
1010 		case VK_FORMAT_R8G8_UINT:
1011 		case VK_FORMAT_R16_UINT:
1012 		case VK_FORMAT_R8_UINT:
1013 			return true;
1014 
1015 		default:
1016 			return false;
1017 	}
1018 }
1019 
getFormatShortString(const VkFormat format)1020 std::string getFormatShortString (const VkFormat format)
1021 {
1022 	const std::string fullName = getFormatName(format);
1023 
1024 	DE_ASSERT(de::beginsWith(fullName, "VK_FORMAT_"));
1025 
1026 	return de::toLower(fullName.substr(10));
1027 }
1028 
createFullscreenQuad(void)1029 std::vector<tcu::Vec4> createFullscreenQuad (void)
1030 {
1031 	const tcu::Vec4 lowerLeftVertex		(-1.0f,	-1.0f,	0.0f,	1.0f);
1032 	const tcu::Vec4 upperLeftVertex		(-1.0f,	1.0f,	0.0f,	1.0f);
1033 	const tcu::Vec4 lowerRightVertex	(1.0f,	-1.0f,	0.0f,	1.0f);
1034 	const tcu::Vec4 upperRightVertex	(1.0f,	1.0f,	0.0f,	1.0f);
1035 
1036 	const tcu::Vec4 vertices[6] =
1037 	{
1038 		lowerLeftVertex,
1039 		lowerRightVertex,
1040 		upperLeftVertex,
1041 
1042 		upperLeftVertex,
1043 		lowerRightVertex,
1044 		upperRightVertex
1045 	};
1046 
1047 	return std::vector<tcu::Vec4>(vertices, vertices + DE_LENGTH_OF_ARRAY(vertices));
1048 }
1049 
makeBufferImageCopy(const deUint32 imageWidth,const deUint32 imageHeight,const deUint32 mipLevel,const deUint32 layer)1050 vk::VkBufferImageCopy makeBufferImageCopy (const deUint32 imageWidth, const deUint32 imageHeight, const deUint32 mipLevel, const deUint32 layer)
1051 {
1052 	const VkBufferImageCopy	copyParams	=
1053 	{
1054 		(VkDeviceSize)0u,						// bufferOffset
1055 		imageWidth,								// bufferRowLength
1056 		imageHeight,							// bufferImageHeight
1057 		{
1058 			VK_IMAGE_ASPECT_COLOR_BIT,				// aspectMask
1059 			mipLevel,								// mipLevel
1060 			layer,									// baseArrayLayer
1061 			1u,										// layerCount
1062 		},										// imageSubresource
1063 		{ 0u, 0u, 0u },							// imageOffset
1064 		{
1065 			imageWidth,
1066 			imageHeight,
1067 			1u
1068 		}										// imageExtent
1069 	};
1070 
1071 	return copyParams;
1072 }
1073 
makeBufferImageCopy(const deUint32 imageWidth,const deUint32 imageHeight,const deUint32 mipLevel,const deUint32 layer,const deUint32 bufferRowLength,const deUint32 bufferImageHeight)1074 vk::VkBufferImageCopy makeBufferImageCopy (const deUint32 imageWidth, const deUint32 imageHeight, const deUint32 mipLevel, const deUint32 layer, const deUint32 bufferRowLength, const deUint32 bufferImageHeight)
1075 {
1076 	const VkBufferImageCopy	copyParams	=
1077 	{
1078 		(VkDeviceSize)0u,						// bufferOffset
1079 		bufferRowLength,						// bufferRowLength
1080 		bufferImageHeight,						// bufferImageHeight
1081 		{
1082 			VK_IMAGE_ASPECT_COLOR_BIT,				// aspectMask
1083 			mipLevel,								// mipLevel
1084 			layer,									// baseArrayLayer
1085 			1u,										// layerCount
1086 		},										// imageSubresource
1087 		{ 0u, 0u, 0u },							// imageOffset
1088 		{
1089 			imageWidth,
1090 			imageHeight,
1091 			1u
1092 		}										// imageExtent
1093 	};
1094 
1095 	return copyParams;
1096 }
1097 
beginRenderPass(const DeviceInterface & vk,const VkCommandBuffer commandBuffer,const VkRenderPass renderPass,const VkFramebuffer framebuffer,const VkExtent2D & renderSize)1098 void beginRenderPass (const DeviceInterface&	vk,
1099 					  const VkCommandBuffer		commandBuffer,
1100 					  const VkRenderPass		renderPass,
1101 					  const VkFramebuffer		framebuffer,
1102 					  const VkExtent2D&			renderSize)
1103 {
1104 	const VkRect2D renderArea =
1105 	{
1106 		{0, 0},			// VkOffset2D				offset;
1107 		renderSize,		// VkExtent2D				extent;
1108 	};
1109 
1110 	beginRenderPass(vk, commandBuffer, renderPass, framebuffer, renderArea, tcu::Vec4(0.0f), 0.0f, 0u);
1111 }
1112 
makeFramebuffer(const DeviceInterface & vk,const VkDevice device,const VkRenderPass renderPass,const deUint32 attachmentCount,const VkImageView * pAttachments,const VkExtent2D & size,const deUint32 layersCount)1113 Move<VkFramebuffer> makeFramebuffer (const DeviceInterface&	vk,
1114 									 const VkDevice			device,
1115 									 const VkRenderPass		renderPass,
1116 									 const deUint32			attachmentCount,
1117 									 const VkImageView*		pAttachments,
1118 									 const VkExtent2D&		size,
1119 									 const deUint32			layersCount)
1120 {
1121 	const vk::VkFramebufferCreateInfo framebufferInfo =
1122 	{
1123 		VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,		// VkStructureType			sType;
1124 		DE_NULL,										// const void*				pNext;
1125 		(VkFramebufferCreateFlags)0,					// VkFramebufferCreateFlags	flags;
1126 		renderPass,										// VkRenderPass				renderPass;
1127 		attachmentCount,								// uint32_t					attachmentCount;
1128 		pAttachments,									// const VkImageView*		pAttachments;
1129 		static_cast<deUint32>(size.width),				// uint32_t					width;
1130 		static_cast<deUint32>(size.height),				// uint32_t					height;
1131 		layersCount,									// uint32_t					layers;
1132 	};
1133 
1134 	return createFramebuffer(vk, device, &framebufferInfo);
1135 }
1136 
1137 } // image
1138 } // vkt
1139