1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2016 The Khronos Group Inc.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief Image Tests Utility Classes
22 *//*--------------------------------------------------------------------*/
24 #include "vktImageTestsUtil.hpp"
25 #include "vkQueryUtil.hpp"
26 #include "vkTypeUtil.hpp"
27 #include "tcuTextureUtil.hpp"
36 Buffer::Buffer (const DeviceInterface& vk,
37 const VkDevice device,
39 const VkBufferCreateInfo& bufferCreateInfo,
40 const MemoryRequirement memoryRequirement)
42 m_buffer = createBuffer(vk, device, &bufferCreateInfo);
43 m_allocation = allocator.allocate(getBufferMemoryRequirements(vk, device, *m_buffer), memoryRequirement);
44 VK_CHECK(vk.bindBufferMemory(device, *m_buffer, m_allocation->getMemory(), m_allocation->getOffset()));
47 Image::Image (const DeviceInterface& vk,
48 const VkDevice device,
50 const VkImageCreateInfo& imageCreateInfo,
51 const MemoryRequirement memoryRequirement)
53 m_image = createImage(vk, device, &imageCreateInfo);
54 m_allocation = allocator.allocate(getImageMemoryRequirements(vk, device, *m_image), memoryRequirement);
55 VK_CHECK(vk.bindImageMemory(device, *m_image, m_allocation->getMemory(), m_allocation->getOffset()));
58 struct CompressedFormatParameters
66 CompressedFormatParameters compressedFormatParameters[VK_FORMAT_ASTC_12x12_SRGB_BLOCK - VK_FORMAT_BC1_RGB_UNORM_BLOCK + 1] =
68 { VK_FORMAT_BC1_RGB_UNORM_BLOCK, 8, 4, 4 },
69 { VK_FORMAT_BC1_RGB_SRGB_BLOCK, 8, 4, 4 },
70 { VK_FORMAT_BC1_RGBA_UNORM_BLOCK, 8, 4, 4 },
71 { VK_FORMAT_BC1_RGBA_SRGB_BLOCK, 8, 4, 4 },
72 { VK_FORMAT_BC2_UNORM_BLOCK, 16, 4, 4 },
73 { VK_FORMAT_BC2_SRGB_BLOCK, 16, 4, 4 },
74 { VK_FORMAT_BC3_UNORM_BLOCK, 16, 4, 4 },
75 { VK_FORMAT_BC3_SRGB_BLOCK, 16, 4, 4 },
76 { VK_FORMAT_BC4_UNORM_BLOCK, 8, 4, 4 },
77 { VK_FORMAT_BC4_SNORM_BLOCK, 8, 4, 4 },
78 { VK_FORMAT_BC5_UNORM_BLOCK, 16, 4, 4 },
79 { VK_FORMAT_BC5_SNORM_BLOCK, 16, 4, 4 },
80 { VK_FORMAT_BC6H_UFLOAT_BLOCK, 16, 4, 4 },
81 { VK_FORMAT_BC6H_SFLOAT_BLOCK, 16, 4, 4 },
82 { VK_FORMAT_BC7_UNORM_BLOCK, 16, 4, 4 },
83 { VK_FORMAT_BC7_SRGB_BLOCK, 16, 4, 4 },
84 { VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK, 8, 4, 4 },
85 { VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK, 8, 4, 4 },
86 { VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK, 8, 4, 4 },
87 { VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK, 8, 4, 4 },
88 { VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, 16, 4, 4 },
89 { VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK, 16, 4, 4 },
90 { VK_FORMAT_EAC_R11_UNORM_BLOCK, 8, 4, 4 },
91 { VK_FORMAT_EAC_R11_SNORM_BLOCK, 8, 4, 4 },
92 { VK_FORMAT_EAC_R11G11_UNORM_BLOCK, 16, 4, 4 },
93 { VK_FORMAT_EAC_R11G11_SNORM_BLOCK, 16, 4, 4 },
94 { VK_FORMAT_ASTC_4x4_UNORM_BLOCK, 16, 4, 4 },
95 { VK_FORMAT_ASTC_4x4_SRGB_BLOCK, 16, 4, 4 },
96 { VK_FORMAT_ASTC_5x4_UNORM_BLOCK, 16, 5, 4 },
97 { VK_FORMAT_ASTC_5x4_SRGB_BLOCK, 16, 5, 4 },
98 { VK_FORMAT_ASTC_5x5_UNORM_BLOCK, 16, 5, 5 },
99 { VK_FORMAT_ASTC_5x5_SRGB_BLOCK, 16, 5, 5 },
100 { VK_FORMAT_ASTC_6x5_UNORM_BLOCK, 16, 6, 5 },
101 { VK_FORMAT_ASTC_6x5_SRGB_BLOCK, 16, 6, 5 },
102 { VK_FORMAT_ASTC_6x6_UNORM_BLOCK, 16, 6, 6 },
103 { VK_FORMAT_ASTC_6x6_SRGB_BLOCK, 16, 6, 6 },
104 { VK_FORMAT_ASTC_8x5_UNORM_BLOCK, 16, 8, 5 },
105 { VK_FORMAT_ASTC_8x5_SRGB_BLOCK, 16, 8, 5 },
106 { VK_FORMAT_ASTC_8x6_UNORM_BLOCK, 16, 8, 6 },
107 { VK_FORMAT_ASTC_8x6_SRGB_BLOCK, 16, 8, 6 },
108 { VK_FORMAT_ASTC_8x8_UNORM_BLOCK, 16, 8, 8 },
109 { VK_FORMAT_ASTC_8x8_SRGB_BLOCK, 16, 8, 8 },
110 { VK_FORMAT_ASTC_10x5_UNORM_BLOCK, 16, 10, 5 },
111 { VK_FORMAT_ASTC_10x5_SRGB_BLOCK, 16, 10, 5 },
112 { VK_FORMAT_ASTC_10x6_UNORM_BLOCK, 16, 10, 6 },
113 { VK_FORMAT_ASTC_10x6_SRGB_BLOCK, 16, 10, 6 },
114 { VK_FORMAT_ASTC_10x8_UNORM_BLOCK, 16, 10, 8 },
115 { VK_FORMAT_ASTC_10x8_SRGB_BLOCK, 16, 10, 8 },
116 { VK_FORMAT_ASTC_10x10_UNORM_BLOCK, 16, 10, 10 },
117 { VK_FORMAT_ASTC_10x10_SRGB_BLOCK, 16, 10, 10 },
118 { VK_FORMAT_ASTC_12x10_UNORM_BLOCK, 16, 12, 10 },
119 { VK_FORMAT_ASTC_12x10_SRGB_BLOCK, 16, 12, 10 },
120 { VK_FORMAT_ASTC_12x12_UNORM_BLOCK, 16, 12, 12 },
121 { VK_FORMAT_ASTC_12x12_SRGB_BLOCK, 16, 12, 12 },
124 deUint32 getBlockSizeInBytes(const VkFormat compressedFormat)
126 deUint32 formatNdx = static_cast<deUint32>(compressedFormat - VK_FORMAT_BC1_RGB_UNORM_BLOCK);
128 DE_ASSERT(deInRange32(formatNdx, 0, DE_LENGTH_OF_ARRAY(compressedFormatParameters)));
129 DE_ASSERT(compressedFormatParameters[formatNdx].format == compressedFormat);
131 return compressedFormatParameters[formatNdx].blockBytes;
134 deUint32 getBlockWidth(const VkFormat compressedFormat)
136 deUint32 formatNdx = static_cast<deUint32>(compressedFormat - VK_FORMAT_BC1_RGB_UNORM_BLOCK);
138 DE_ASSERT(deInRange32(formatNdx, 0, DE_LENGTH_OF_ARRAY(compressedFormatParameters)));
139 DE_ASSERT(compressedFormatParameters[formatNdx].format == compressedFormat);
141 return compressedFormatParameters[formatNdx].blockWidth;
144 deUint32 getBlockHeight(const VkFormat compressedFormat)
146 deUint32 formatNdx = static_cast<deUint32>(compressedFormat - VK_FORMAT_BC1_RGB_UNORM_BLOCK);
148 DE_ASSERT(deInRange32(formatNdx, 0, DE_LENGTH_OF_ARRAY(compressedFormatParameters)));
149 DE_ASSERT(compressedFormatParameters[formatNdx].format == compressedFormat);
151 return compressedFormatParameters[formatNdx].blockHeight;
154 tcu::UVec3 getShaderGridSize (const ImageType imageType, const tcu::UVec3& imageSize)
159 case IMAGE_TYPE_BUFFER:
160 return tcu::UVec3(imageSize.x(), 1u, 1u);
162 case IMAGE_TYPE_1D_ARRAY:
163 return tcu::UVec3(imageSize.x(), imageSize.z(), 1u);
166 return tcu::UVec3(imageSize.x(), imageSize.y(), 1u);
168 case IMAGE_TYPE_2D_ARRAY:
170 return tcu::UVec3(imageSize.x(), imageSize.y(), imageSize.z());
172 case IMAGE_TYPE_CUBE:
173 return tcu::UVec3(imageSize.x(), imageSize.y(), 6u);
175 case IMAGE_TYPE_CUBE_ARRAY:
176 return tcu::UVec3(imageSize.x(), imageSize.y(), 6u * imageSize.z());
179 DE_FATAL("Unknown image type");
180 return tcu::UVec3(1u, 1u, 1u);
184 tcu::UVec3 getLayerSize (const ImageType imageType, const tcu::UVec3& imageSize)
189 case IMAGE_TYPE_1D_ARRAY:
190 case IMAGE_TYPE_BUFFER:
191 return tcu::UVec3(imageSize.x(), 1u, 1u);
194 case IMAGE_TYPE_2D_ARRAY:
195 case IMAGE_TYPE_CUBE:
196 case IMAGE_TYPE_CUBE_ARRAY:
197 return tcu::UVec3(imageSize.x(), imageSize.y(), 1u);
200 return tcu::UVec3(imageSize.x(), imageSize.y(), imageSize.z());
203 DE_FATAL("Unknown image type");
204 return tcu::UVec3(1u, 1u, 1u);
208 deUint32 getNumLayers (const ImageType imageType, const tcu::UVec3& imageSize)
215 case IMAGE_TYPE_BUFFER:
218 case IMAGE_TYPE_1D_ARRAY:
219 case IMAGE_TYPE_2D_ARRAY:
220 return imageSize.z();
222 case IMAGE_TYPE_CUBE:
225 case IMAGE_TYPE_CUBE_ARRAY:
226 return imageSize.z() * 6u;
229 DE_FATAL("Unknown image type");
234 deUint32 getNumPixels (const ImageType imageType, const tcu::UVec3& imageSize)
236 const tcu::UVec3 gridSize = getShaderGridSize(imageType, imageSize);
238 return gridSize.x() * gridSize.y() * gridSize.z();
241 deUint32 getDimensions (const ImageType imageType)
246 case IMAGE_TYPE_BUFFER:
249 case IMAGE_TYPE_1D_ARRAY:
253 case IMAGE_TYPE_2D_ARRAY:
254 case IMAGE_TYPE_CUBE:
255 case IMAGE_TYPE_CUBE_ARRAY:
260 DE_FATAL("Unknown image type");
265 deUint32 getLayerDimensions (const ImageType imageType)
270 case IMAGE_TYPE_BUFFER:
271 case IMAGE_TYPE_1D_ARRAY:
275 case IMAGE_TYPE_2D_ARRAY:
276 case IMAGE_TYPE_CUBE:
277 case IMAGE_TYPE_CUBE_ARRAY:
284 DE_FATAL("Unknown image type");
289 VkBufferCreateInfo makeBufferCreateInfo (const VkDeviceSize bufferSize,
290 const VkBufferUsageFlags usage)
292 const VkBufferCreateInfo bufferCreateInfo =
294 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
295 DE_NULL, // const void* pNext;
296 0u, // VkBufferCreateFlags flags;
297 bufferSize, // VkDeviceSize size;
298 usage, // VkBufferUsageFlags usage;
299 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
300 0u, // deUint32 queueFamilyIndexCount;
301 DE_NULL, // const deUint32* pQueueFamilyIndices;
303 return bufferCreateInfo;
306 VkBufferImageCopy makeBufferImageCopy (const VkExtent3D extent,
307 const deUint32 arraySize)
309 const VkBufferImageCopy copyParams =
311 0ull, // VkDeviceSize bufferOffset;
312 0u, // deUint32 bufferRowLength;
313 0u, // deUint32 bufferImageHeight;
314 makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, arraySize), // VkImageSubresourceLayers imageSubresource;
315 makeOffset3D(0, 0, 0), // VkOffset3D imageOffset;
316 extent, // VkExtent3D imageExtent;
321 Move<VkPipelineLayout> makePipelineLayout (const DeviceInterface& vk,
322 const VkDevice device,
323 const VkDescriptorSetLayout descriptorSetLayout)
325 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
327 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
328 DE_NULL, // const void* pNext;
329 0u, // VkPipelineLayoutCreateFlags flags;
330 1u, // deUint32 setLayoutCount;
331 &descriptorSetLayout, // const VkDescriptorSetLayout* pSetLayouts;
332 0u, // deUint32 pushConstantRangeCount;
333 DE_NULL, // const VkPushConstantRange* pPushConstantRanges;
335 return createPipelineLayout(vk, device, &pipelineLayoutParams);
338 Move<VkPipeline> makeComputePipeline (const DeviceInterface& vk,
339 const VkDevice device,
340 const VkPipelineLayout pipelineLayout,
341 const VkShaderModule shaderModule)
343 const VkPipelineShaderStageCreateInfo pipelineShaderStageParams =
345 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
346 DE_NULL, // const void* pNext;
347 0u, // VkPipelineShaderStageCreateFlags flags;
348 VK_SHADER_STAGE_COMPUTE_BIT, // VkShaderStageFlagBits stage;
349 shaderModule, // VkShaderModule module;
350 "main", // const char* pName;
351 DE_NULL, // const VkSpecializationInfo* pSpecializationInfo;
353 const VkComputePipelineCreateInfo pipelineCreateInfo =
355 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, // VkStructureType sType;
356 DE_NULL, // const void* pNext;
357 0u, // VkPipelineCreateFlags flags;
358 pipelineShaderStageParams, // VkPipelineShaderStageCreateInfo stage;
359 pipelineLayout, // VkPipelineLayout layout;
360 DE_NULL, // VkPipeline basePipelineHandle;
361 0, // deInt32 basePipelineIndex;
363 return createComputePipeline(vk, device, DE_NULL , &pipelineCreateInfo);
366 Move<VkPipeline> makeGraphicsPipeline (const DeviceInterface& vk,
367 const VkDevice device,
368 const VkPipelineLayout pipelineLayout,
369 const VkRenderPass renderPass,
370 const VkShaderModule vertexModule,
371 const VkShaderModule fragmentModule,
372 const VkExtent2D renderSize,
373 const deUint32 colorAttachmentCount,
374 const bool dynamicSize)
376 const VkFormat vertexFormatPosition = VK_FORMAT_R32G32B32A32_SFLOAT;
377 const deUint32 vertexSizePosition = tcu::getPixelSize(mapVkFormat(vertexFormatPosition));
378 const deUint32 vertexBufferOffsetPosition = 0u;
379 const deUint32 vertexDataStride = vertexSizePosition;
381 const VkVertexInputBindingDescription vertexBinding =
383 0u, // deUint32 binding;
384 vertexDataStride, // deUint32 stride;
385 VK_VERTEX_INPUT_RATE_VERTEX // VkVertexInputRate inputRate;
388 const VkVertexInputAttributeDescription vertexInputAttributeDescriptions[] =
392 0u, // deUint32 location;
393 0u, // deUint32 binding;
394 vertexFormatPosition, // VkFormat format;
395 vertexBufferOffsetPosition, // deUint32 offset;
399 const VkPipelineVertexInputStateCreateInfo vertexInputStateInfo =
401 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, // VkStructureType sType;
402 DE_NULL, // const void* pNext;
403 (VkPipelineVertexInputStateCreateFlags)0, // VkPipelineVertexInputStateCreateFlags flags;
404 1u, // uint32_t vertexBindingDescriptionCount;
405 &vertexBinding, // const VkVertexInputBindingDescription* pVertexBindingDescriptions;
406 DE_LENGTH_OF_ARRAY(vertexInputAttributeDescriptions), // uint32_t vertexAttributeDescriptionCount;
407 vertexInputAttributeDescriptions, // const VkVertexInputAttributeDescription* pVertexAttributeDescriptions;
410 const VkPipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateInfo =
412 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, // VkStructureType sType;
413 DE_NULL, // const void* pNext;
414 (VkPipelineInputAssemblyStateCreateFlags)0, // VkPipelineInputAssemblyStateCreateFlags flags;
415 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, // VkPrimitiveTopology topology;
416 VK_FALSE, // VkBool32 primitiveRestartEnable;
419 const VkViewport viewport =
421 0.0f, // float originX;
422 0.0f, // float originY;
423 (float)renderSize.width, // float width;
424 (float)renderSize.height, // float height;
425 0.0f, // float minDepth;
426 1.0f // float maxDepth;
429 const VkRect2D scissor =
431 { 0u, 0u }, // VkOffset2D offset;
432 renderSize // VkExtent2D extent;
435 const VkPipelineViewportStateCreateInfo pipelineViewportStateInfo =
437 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, // VkStructureType sType;
438 DE_NULL, // const void* pNext;
439 (VkPipelineViewportStateCreateFlags)0, // VkPipelineViewportStateCreateFlags flags;
440 1u, // uint32_t viewportCount;
441 &viewport, // dynamic state // const VkViewport* pViewports;
442 1u, // uint32_t scissorCount;
443 &scissor, // dynamic state // const VkRect2D* pScissors;
446 const VkPipelineRasterizationStateCreateInfo pipelineRasterizationStateInfo =
448 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, // VkStructureType sType;
449 DE_NULL, // const void* pNext;
450 (VkPipelineRasterizationStateCreateFlags)0, // VkPipelineRasterizationStateCreateFlags flags;
451 VK_FALSE, // VkBool32 depthClampEnable;
452 VK_FALSE, // VkBool32 rasterizerDiscardEnable;
453 VK_POLYGON_MODE_FILL, // VkPolygonMode polygonMode;
454 VK_CULL_MODE_NONE, // VkCullModeFlags cullMode;
455 VK_FRONT_FACE_COUNTER_CLOCKWISE, // VkFrontFace frontFace;
456 VK_FALSE, // VkBool32 depthBiasEnable;
457 0.0f, // float depthBiasConstantFactor;
458 0.0f, // float depthBiasClamp;
459 0.0f, // float depthBiasSlopeFactor;
460 1.0f, // float lineWidth;
463 const VkPipelineMultisampleStateCreateInfo pipelineMultisampleStateInfo =
465 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType;
466 DE_NULL, // const void* pNext;
467 (VkPipelineMultisampleStateCreateFlags)0, // VkPipelineMultisampleStateCreateFlags flags;
468 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits rasterizationSamples;
469 VK_FALSE, // VkBool32 sampleShadingEnable;
470 0.0f, // float minSampleShading;
471 DE_NULL, // const VkSampleMask* pSampleMask;
472 VK_FALSE, // VkBool32 alphaToCoverageEnable;
473 VK_FALSE // VkBool32 alphaToOneEnable;
476 const VkColorComponentFlags colorComponentsAll = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
477 const VkPipelineColorBlendAttachmentState colorBlendAttachmentState =
479 VK_FALSE, // VkBool32 blendEnable;
480 VK_BLEND_FACTOR_ONE, // VkBlendFactor srcColorBlendFactor;
481 VK_BLEND_FACTOR_ZERO, // VkBlendFactor dstColorBlendFactor;
482 VK_BLEND_OP_ADD, // VkBlendOp colorBlendOp;
483 VK_BLEND_FACTOR_ONE, // VkBlendFactor srcAlphaBlendFactor;
484 VK_BLEND_FACTOR_ZERO, // VkBlendFactor dstAlphaBlendFactor;
485 VK_BLEND_OP_ADD, // VkBlendOp alphaBlendOp;
486 colorComponentsAll, // VkColorComponentFlags colorWriteMask;
488 std::vector<VkPipelineColorBlendAttachmentState> colorAttachments(colorAttachmentCount, colorBlendAttachmentState);
490 const VkPipelineColorBlendStateCreateInfo pipelineColorBlendStateInfo =
492 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, // VkStructureType sType;
493 DE_NULL, // const void* pNext;
494 (VkPipelineColorBlendStateCreateFlags)0, // VkPipelineColorBlendStateCreateFlags flags;
495 VK_FALSE, // VkBool32 logicOpEnable;
496 VK_LOGIC_OP_COPY, // VkLogicOp logicOp;
497 (deUint32)colorAttachments.size(), // deUint32 attachmentCount;
498 colorAttachments.size() != 0 ? &colorAttachments[0] : DE_NULL, // const VkPipelineColorBlendAttachmentState* pAttachments;
499 { 0.0f, 0.0f, 0.0f, 0.0f }, // float blendConstants[4];
502 const VkPipelineShaderStageCreateInfo pShaderStages[] =
505 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
506 DE_NULL, // const void* pNext;
507 (VkPipelineShaderStageCreateFlags)0, // VkPipelineShaderStageCreateFlags flags;
508 VK_SHADER_STAGE_VERTEX_BIT, // VkShaderStageFlagBits stage;
509 vertexModule, // VkShaderModule module;
510 "main", // const char* pName;
511 DE_NULL, // const VkSpecializationInfo* pSpecializationInfo;
514 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
515 DE_NULL, // const void* pNext;
516 (VkPipelineShaderStageCreateFlags)0, // VkPipelineShaderStageCreateFlags flags;
517 VK_SHADER_STAGE_FRAGMENT_BIT, // VkShaderStageFlagBits stage;
518 fragmentModule, // VkShaderModule module;
519 "main", // const char* pName;
520 DE_NULL, // const VkSpecializationInfo* pSpecializationInfo;
523 const deUint32 numActiveShaderStages = DE_LENGTH_OF_ARRAY(pShaderStages);
525 const VkDynamicState dynamicStates[] =
527 VK_DYNAMIC_STATE_VIEWPORT,
528 VK_DYNAMIC_STATE_SCISSOR,
531 const VkPipelineDynamicStateCreateInfo dynamicStateCreateInfo =
533 VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, // VkStructureType sType;
534 DE_NULL, // const void* pNext;
535 (VkPipelineDynamicStateCreateFlags)0, // VkPipelineDynamicStateCreateFlags flags;
536 DE_LENGTH_OF_ARRAY(dynamicStates), // deUint32 dynamicStateCount;
537 dynamicStates, // const VkDynamicState* pDynamicStates;
540 const VkGraphicsPipelineCreateInfo graphicsPipelineInfo =
542 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, // VkStructureType sType;
543 DE_NULL, // const void* pNext;
544 (VkPipelineCreateFlags)0, // VkPipelineCreateFlags flags;
545 numActiveShaderStages, // deUint32 stageCount;
546 pShaderStages, // const VkPipelineShaderStageCreateInfo* pStages;
547 &vertexInputStateInfo, // const VkPipelineVertexInputStateCreateInfo* pVertexInputState;
548 &pipelineInputAssemblyStateInfo, // const VkPipelineInputAssemblyStateCreateInfo* pInputAssemblyState;
549 DE_NULL, // const VkPipelineTessellationStateCreateInfo* pTessellationState;
550 &pipelineViewportStateInfo, // const VkPipelineViewportStateCreateInfo* pViewportState;
551 &pipelineRasterizationStateInfo, // const VkPipelineRasterizationStateCreateInfo* pRasterizationState;
552 &pipelineMultisampleStateInfo, // const VkPipelineMultisampleStateCreateInfo* pMultisampleState;
553 DE_NULL, // const VkPipelineDepthStencilStateCreateInfo* pDepthStencilState;
554 &pipelineColorBlendStateInfo, // const VkPipelineColorBlendStateCreateInfo* pColorBlendState;
555 dynamicSize ? &dynamicStateCreateInfo : DE_NULL, // const VkPipelineDynamicStateCreateInfo* pDynamicState;
556 pipelineLayout, // VkPipelineLayout layout;
557 renderPass, // VkRenderPass renderPass;
558 0u, // deUint32 subpass;
559 DE_NULL, // VkPipeline basePipelineHandle;
560 0, // deInt32 basePipelineIndex;
563 return createGraphicsPipeline(vk, device, DE_NULL, &graphicsPipelineInfo);
566 //! A single-subpass render pass.
567 Move<VkRenderPass> makeRenderPass (const DeviceInterface& vk,
568 const VkDevice device,
569 const VkFormat inputFormat,
570 const VkFormat colorFormat)
572 const VkAttachmentReference inputAttachmentRef =
574 0u, // deUint32 attachment;
575 VK_IMAGE_LAYOUT_GENERAL // VkImageLayout layout;
578 const VkAttachmentReference colorAttachmentRef =
580 1u, // deUint32 attachment;
581 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout layout;
584 const VkSubpassDescription subpassDescription =
586 (VkSubpassDescriptionFlags)0, // VkSubpassDescriptionFlags flags;
587 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint;
588 1u, // deUint32 inputAttachmentCount;
589 &inputAttachmentRef, // const VkAttachmentReference* pInputAttachments;
590 1u, // deUint32 colorAttachmentCount;
591 &colorAttachmentRef, // const VkAttachmentReference* pColorAttachments;
592 DE_NULL, // const VkAttachmentReference* pResolveAttachments;
593 DE_NULL, // const VkAttachmentReference* pDepthStencilAttachment;
594 0u, // deUint32 preserveAttachmentCount;
595 DE_NULL // const deUint32* pPreserveAttachments;
598 const VkAttachmentDescription attachmentsDescriptions[] =
600 //inputAttachmentDescription,
602 (VkAttachmentDescriptionFlags)0, // VkAttachmentDescriptionFlags flags;
603 inputFormat, // VkFormat format;
604 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
605 VK_ATTACHMENT_LOAD_OP_LOAD, // VkAttachmentLoadOp loadOp;
606 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp storeOp;
607 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp;
608 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp;
609 VK_IMAGE_LAYOUT_GENERAL, // VkImageLayout initialLayout;
610 VK_IMAGE_LAYOUT_GENERAL, // VkImageLayout finalLayout;
612 //colorAttachmentDescription
614 (VkAttachmentDescriptionFlags)0, // VkAttachmentDescriptionFlags flags;
615 colorFormat, // VkFormat format;
616 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
617 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp;
618 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
619 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp;
620 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp;
621 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
622 VK_IMAGE_LAYOUT_GENERAL, // VkImageLayout finalLayout;
626 const VkRenderPassCreateInfo renderPassInfo =
628 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, // VkStructureType sType;
629 DE_NULL, // const void* pNext;
630 (VkRenderPassCreateFlags)0, // VkRenderPassCreateFlags flags;
631 DE_LENGTH_OF_ARRAY(attachmentsDescriptions), // deUint32 attachmentCount;
632 attachmentsDescriptions, // const VkAttachmentDescription* pAttachments;
633 1u, // deUint32 subpassCount;
634 &subpassDescription, // const VkSubpassDescription* pSubpasses;
635 0u, // deUint32 dependencyCount;
636 DE_NULL // const VkSubpassDependency* pDependencies;
639 return createRenderPass(vk, device, &renderPassInfo);
642 //! A single-subpass render pass.
643 Move<VkRenderPass> makeRenderPass (const DeviceInterface& vk,
644 const VkDevice device)
646 const VkSubpassDescription subpassDescription =
648 (VkSubpassDescriptionFlags)0, // VkSubpassDescriptionFlags flags;
649 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint;
650 0u, // deUint32 inputAttachmentCount;
651 DE_NULL, // const VkAttachmentReference* pInputAttachments;
652 0u, // deUint32 colorAttachmentCount;
653 DE_NULL, // const VkAttachmentReference* pColorAttachments;
654 DE_NULL, // const VkAttachmentReference* pResolveAttachments;
655 DE_NULL, // const VkAttachmentReference* pDepthStencilAttachment;
656 0u, // deUint32 preserveAttachmentCount;
657 DE_NULL // const deUint32* pPreserveAttachments;
660 const VkRenderPassCreateInfo renderPassInfo =
662 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, // VkStructureType sType;
663 DE_NULL, // const void* pNext;
664 (VkRenderPassCreateFlags)0, // VkRenderPassCreateFlags flags;
665 0, // deUint32 attachmentCount;
666 DE_NULL, // const VkAttachmentDescription* pAttachments;
667 1u, // deUint32 subpassCount;
668 &subpassDescription, // const VkSubpassDescription* pSubpasses;
669 0u, // deUint32 dependencyCount;
670 DE_NULL // const VkSubpassDependency* pDependencies;
673 return createRenderPass(vk, device, &renderPassInfo);
676 Move<VkBufferView> makeBufferView (const DeviceInterface& vk,
677 const VkDevice vkDevice,
678 const VkBuffer buffer,
679 const VkFormat format,
680 const VkDeviceSize offset,
681 const VkDeviceSize size)
683 const VkBufferViewCreateInfo bufferViewParams =
685 VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO, // VkStructureType sType;
686 DE_NULL, // const void* pNext;
687 0u, // VkBufferViewCreateFlags flags;
688 buffer, // VkBuffer buffer;
689 format, // VkFormat format;
690 offset, // VkDeviceSize offset;
691 size, // VkDeviceSize range;
693 return createBufferView(vk, vkDevice, &bufferViewParams);
696 Move<VkImageView> makeImageView (const DeviceInterface& vk,
697 const VkDevice vkDevice,
699 const VkImageViewType imageViewType,
700 const VkFormat format,
701 const VkImageSubresourceRange subresourceRange,
702 const VkImageViewUsageCreateInfoKHR* ImageUsageCreateInfoKHR)
704 const VkImageViewCreateInfo imageViewParams =
706 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
707 ImageUsageCreateInfoKHR, // const void* pNext;
708 0u, // VkImageViewCreateFlags flags;
709 image, // VkImage image;
710 imageViewType, // VkImageViewType viewType;
711 format, // VkFormat format;
712 makeComponentMappingRGBA(), // VkComponentMapping components;
713 subresourceRange, // VkImageSubresourceRange subresourceRange;
715 return createImageView(vk, vkDevice, &imageViewParams);
718 Move<VkDescriptorSet> makeDescriptorSet (const DeviceInterface& vk,
719 const VkDevice device,
720 const VkDescriptorPool descriptorPool,
721 const VkDescriptorSetLayout setLayout)
723 const VkDescriptorSetAllocateInfo allocateParams =
725 VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, // VkStructureType sType;
726 DE_NULL, // const void* pNext;
727 descriptorPool, // VkDescriptorPool descriptorPool;
728 1u, // deUint32 setLayoutCount;
729 &setLayout, // const VkDescriptorSetLayout* pSetLayouts;
731 return allocateDescriptorSet(vk, device, &allocateParams);
734 VkBufferMemoryBarrier makeBufferMemoryBarrier (const VkAccessFlags srcAccessMask,
735 const VkAccessFlags dstAccessMask,
736 const VkBuffer buffer,
737 const VkDeviceSize offset,
738 const VkDeviceSize bufferSizeBytes)
740 const VkBufferMemoryBarrier barrier =
742 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // VkStructureType sType;
743 DE_NULL, // const void* pNext;
744 srcAccessMask, // VkAccessFlags srcAccessMask;
745 dstAccessMask, // VkAccessFlags dstAccessMask;
746 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
747 VK_QUEUE_FAMILY_IGNORED, // deUint32 destQueueFamilyIndex;
748 buffer, // VkBuffer buffer;
749 offset, // VkDeviceSize offset;
750 bufferSizeBytes, // VkDeviceSize size;
755 VkImageMemoryBarrier makeImageMemoryBarrier (const VkAccessFlags srcAccessMask,
756 const VkAccessFlags dstAccessMask,
757 const VkImageLayout oldLayout,
758 const VkImageLayout newLayout,
760 const VkImageSubresourceRange subresourceRange)
762 const VkImageMemoryBarrier barrier =
764 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
765 DE_NULL, // const void* pNext;
766 srcAccessMask, // VkAccessFlags outputMask;
767 dstAccessMask, // VkAccessFlags inputMask;
768 oldLayout, // VkImageLayout oldLayout;
769 newLayout, // VkImageLayout newLayout;
770 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
771 VK_QUEUE_FAMILY_IGNORED, // deUint32 destQueueFamilyIndex;
772 image, // VkImage image;
773 subresourceRange, // VkImageSubresourceRange subresourceRange;
778 VkImageViewUsageCreateInfoKHR makeImageViewUsageCreateInfo (const VkImageUsageFlags imageUsageFlags)
780 VkImageViewUsageCreateInfoKHR imageViewUsageCreateInfoKHR =
782 VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO_KHR, //VkStructureType sType;
783 DE_NULL, //const void* pNext;
784 imageUsageFlags, //VkImageUsageFlags usage;
787 return imageViewUsageCreateInfoKHR;
790 VkSamplerCreateInfo makeSamplerCreateInfo ()
792 const VkSamplerCreateInfo defaultSamplerParams =
794 VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, // VkStructureType sType;
795 DE_NULL, // const void* pNext;
796 0u, // VkSamplerCreateFlags flags;
797 VK_FILTER_NEAREST, // VkFilter magFilter;
798 VK_FILTER_NEAREST, // VkFilter minFilter;
799 VK_SAMPLER_MIPMAP_MODE_NEAREST, // VkSamplerMipmapMode mipmapMode;
800 VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, // VkSamplerAddressMode addressModeU;
801 VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, // VkSamplerAddressMode addressModeV;
802 VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, // VkSamplerAddressMode addressModeW;
803 0.0f, // float mipLodBias;
804 VK_FALSE, // VkBool32 anisotropyEnable;
805 1.0f, // float maxAnisotropy;
806 VK_FALSE, // VkBool32 compareEnable;
807 VK_COMPARE_OP_NEVER, // VkCompareOp compareOp;
808 0.0f, // float minLod;
809 0.25f, // float maxLod;
810 VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK, // VkBorderColor borderColor;
811 VK_FALSE // VkBool32 unnormalizedCoordinates;
814 return defaultSamplerParams;
817 void beginCommandBuffer (const DeviceInterface& vk, const VkCommandBuffer commandBuffer)
819 const VkCommandBufferBeginInfo commandBufBeginParams =
821 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
822 DE_NULL, // const void* pNext;
823 0u, // VkCommandBufferUsageFlags flags;
824 (const VkCommandBufferInheritanceInfo*)DE_NULL,
826 VK_CHECK(vk.beginCommandBuffer(commandBuffer, &commandBufBeginParams));
828 void endCommandBuffer (const DeviceInterface& vk, const VkCommandBuffer commandBuffer)
830 VK_CHECK(vk.endCommandBuffer(commandBuffer));
833 void submitCommandsAndWait (const DeviceInterface& vk,
834 const VkDevice device,
836 const VkCommandBuffer commandBuffer)
838 const Unique<VkFence> fence(createFence(vk, device));
840 const VkSubmitInfo submitInfo =
842 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
843 DE_NULL, // const void* pNext;
844 0u, // deUint32 waitSemaphoreCount;
845 DE_NULL, // const VkSemaphore* pWaitSemaphores;
846 (const VkPipelineStageFlags*)DE_NULL, // const VkPipelineStageFlags* pWaitDstStageMask;
847 1u, // deUint32 commandBufferCount;
848 &commandBuffer, // const VkCommandBuffer* pCommandBuffers;
849 0u, // deUint32 signalSemaphoreCount;
850 DE_NULL, // const VkSemaphore* pSignalSemaphores;
853 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
854 VK_CHECK(vk.waitForFences(device, 1u, &fence.get(), DE_TRUE, ~0ull));
857 tcu::UVec3 getCompressedImageResolutionInBlocks (const vk::VkFormat format, const tcu::UVec3& size)
859 deUint32 blockWidth = getBlockWidth(format);
860 deUint32 blockHeight = getBlockHeight(format);
862 DE_ASSERT(size[2] == 1);
863 DE_ASSERT(blockWidth != 0 && blockHeight != 0);
865 deUint32 widthInBlocks = (size[0] + blockWidth - 1) / blockWidth;
866 deUint32 heightInBlocks = (size[1] + blockHeight - 1) / blockHeight;
868 return tcu::UVec3(widthInBlocks, heightInBlocks, 1);
871 tcu::UVec3 getCompressedImageResolutionBlockCeil (const vk::VkFormat format, const tcu::UVec3& size)
873 deUint32 blockWidth = getBlockWidth(format);
874 deUint32 blockHeight = getBlockHeight(format);
876 DE_ASSERT(size[2] == 1);
877 DE_ASSERT(blockWidth != 0 && blockHeight != 0);
879 deUint32 widthInBlocks = (size[0] + blockWidth - 1) / blockWidth;
880 deUint32 heightInBlocks = (size[1] + blockHeight - 1) / blockHeight;
882 return tcu::UVec3(blockWidth * widthInBlocks, blockHeight * heightInBlocks, 1);
885 VkDeviceSize getCompressedImageSizeInBytes (const vk::VkFormat format, const tcu::UVec3& size)
887 tcu::UVec3 sizeInBlocks = getCompressedImageResolutionInBlocks(format, size);
888 deUint32 blockBytes = getBlockSizeInBytes(format);
889 VkDeviceSize sizeBytes = sizeInBlocks[0] * sizeInBlocks[1] * sizeInBlocks[2] * blockBytes;
894 VkDeviceSize getUncompressedImageSizeInBytes (const vk::VkFormat format, const tcu::UVec3& size)
896 const tcu::IVec3 sizeAsIVec3 = tcu::IVec3((int)size.x(), (int)size.y(), (int)size.z());
897 const VkDeviceSize sizeBytes = getImageSizeBytes(sizeAsIVec3, format);
902 VkImageType mapImageType (const ImageType imageType)
907 case IMAGE_TYPE_1D_ARRAY:
908 case IMAGE_TYPE_BUFFER:
909 return VK_IMAGE_TYPE_1D;
912 case IMAGE_TYPE_2D_ARRAY:
913 case IMAGE_TYPE_CUBE:
914 case IMAGE_TYPE_CUBE_ARRAY:
915 return VK_IMAGE_TYPE_2D;
918 return VK_IMAGE_TYPE_3D;
922 return VK_IMAGE_TYPE_LAST;
926 VkImageViewType mapImageViewType (const ImageType imageType)
930 case IMAGE_TYPE_1D: return VK_IMAGE_VIEW_TYPE_1D;
931 case IMAGE_TYPE_1D_ARRAY: return VK_IMAGE_VIEW_TYPE_1D_ARRAY;
932 case IMAGE_TYPE_2D: return VK_IMAGE_VIEW_TYPE_2D;
933 case IMAGE_TYPE_2D_ARRAY: return VK_IMAGE_VIEW_TYPE_2D_ARRAY;
934 case IMAGE_TYPE_3D: return VK_IMAGE_VIEW_TYPE_3D;
935 case IMAGE_TYPE_CUBE: return VK_IMAGE_VIEW_TYPE_CUBE;
936 case IMAGE_TYPE_CUBE_ARRAY: return VK_IMAGE_VIEW_TYPE_CUBE_ARRAY;
940 return VK_IMAGE_VIEW_TYPE_LAST;
944 std::string getImageTypeName (const ImageType imageType)
948 case IMAGE_TYPE_1D: return "1d";
949 case IMAGE_TYPE_1D_ARRAY: return "1d_array";
950 case IMAGE_TYPE_2D: return "2d";
951 case IMAGE_TYPE_2D_ARRAY: return "2d_array";
952 case IMAGE_TYPE_3D: return "3d";
953 case IMAGE_TYPE_CUBE: return "cube";
954 case IMAGE_TYPE_CUBE_ARRAY: return "cube_array";
955 case IMAGE_TYPE_BUFFER: return "buffer";
963 std::string getShaderImageType (const tcu::TextureFormat& format, const ImageType imageType, const bool multisample)
965 std::string formatPart = tcu::getTextureChannelClass(format.type) == tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER ? "u" :
966 tcu::getTextureChannelClass(format.type) == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER ? "i" : "";
968 std::string imageTypePart;
973 case IMAGE_TYPE_2D: imageTypePart = "2DMS"; break;
974 case IMAGE_TYPE_2D_ARRAY: imageTypePart = "2DMSArray"; break;
984 case IMAGE_TYPE_1D: imageTypePart = "1D"; break;
985 case IMAGE_TYPE_1D_ARRAY: imageTypePart = "1DArray"; break;
986 case IMAGE_TYPE_2D: imageTypePart = "2D"; break;
987 case IMAGE_TYPE_2D_ARRAY: imageTypePart = "2DArray"; break;
988 case IMAGE_TYPE_3D: imageTypePart = "3D"; break;
989 case IMAGE_TYPE_CUBE: imageTypePart = "Cube"; break;
990 case IMAGE_TYPE_CUBE_ARRAY: imageTypePart = "CubeArray"; break;
991 case IMAGE_TYPE_BUFFER: imageTypePart = "Buffer"; break;
998 return formatPart + "image" + imageTypePart;
1001 std::string getShaderImageFormatQualifier (const tcu::TextureFormat& format)
1003 const char* orderPart;
1004 const char* typePart;
1006 switch (format.order)
1008 case tcu::TextureFormat::R: orderPart = "r"; break;
1009 case tcu::TextureFormat::RG: orderPart = "rg"; break;
1010 case tcu::TextureFormat::RGB: orderPart = "rgb"; break;
1011 case tcu::TextureFormat::RGBA: orderPart = "rgba"; break;
1015 orderPart = DE_NULL;
1018 switch (format.type)
1020 case tcu::TextureFormat::FLOAT: typePart = "32f"; break;
1021 case tcu::TextureFormat::HALF_FLOAT: typePart = "16f"; break;
1023 case tcu::TextureFormat::UNSIGNED_INT32: typePart = "32ui"; break;
1024 case tcu::TextureFormat::UNSIGNED_INT16: typePart = "16ui"; break;
1025 case tcu::TextureFormat::UNSIGNED_INT8: typePart = "8ui"; break;
1027 case tcu::TextureFormat::SIGNED_INT32: typePart = "32i"; break;
1028 case tcu::TextureFormat::SIGNED_INT16: typePart = "16i"; break;
1029 case tcu::TextureFormat::SIGNED_INT8: typePart = "8i"; break;
1031 case tcu::TextureFormat::UNORM_INT16: typePart = "16"; break;
1032 case tcu::TextureFormat::UNORM_INT8: typePart = "8"; break;
1034 case tcu::TextureFormat::SNORM_INT16: typePart = "16_snorm"; break;
1035 case tcu::TextureFormat::SNORM_INT8: typePart = "8_snorm"; break;
1042 return std::string() + orderPart + typePart;
1045 std::string getGlslSamplerType (const tcu::TextureFormat& format, VkImageViewType type)
1047 const char* typePart = DE_NULL;
1048 const char* formatPart = tcu::getTextureChannelClass(format.type) == tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER ? "u" :
1049 tcu::getTextureChannelClass(format.type) == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER ? "i" : "";
1053 case VK_IMAGE_VIEW_TYPE_1D: typePart = "sampler1D"; break;
1054 case VK_IMAGE_VIEW_TYPE_1D_ARRAY: typePart = "sampler1DArray"; break;
1055 case VK_IMAGE_VIEW_TYPE_2D: typePart = "sampler2D"; break;
1056 case VK_IMAGE_VIEW_TYPE_2D_ARRAY: typePart = "sampler2DArray"; break;
1057 case VK_IMAGE_VIEW_TYPE_3D: typePart = "sampler3D"; break;
1058 case VK_IMAGE_VIEW_TYPE_CUBE: typePart = "samplerCube"; break;
1059 case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY: typePart = "samplerCubeArray"; break;
1062 DE_FATAL("Unknown image view type");
1066 return std::string(formatPart) + typePart;
1070 const char* getGlslInputFormatType (const vk::VkFormat format)
1075 case VK_FORMAT_R16G16B16A16_UNORM: return "subpassInput";
1076 case VK_FORMAT_R16G16B16A16_SNORM: return "subpassInput";
1077 case VK_FORMAT_R16G16B16A16_USCALED: return "subpassInput";
1078 case VK_FORMAT_R16G16B16A16_SSCALED: return "subpassInput";
1079 case VK_FORMAT_R16G16B16A16_UINT: return "usubpassInput";
1080 case VK_FORMAT_R16G16B16A16_SINT: return "isubpassInput";
1081 case VK_FORMAT_R16G16B16A16_SFLOAT: return "subpassInput";
1082 case VK_FORMAT_R32G32_UINT: return "usubpassInput";
1083 case VK_FORMAT_R32G32_SINT: return "isubpassInput";
1084 case VK_FORMAT_R32G32_SFLOAT: return "subpassInput";
1085 // TODO: case VK_FORMAT_R64_UINT: return "usubpassInput";
1086 // TODO: case VK_FORMAT_R64_SINT: return "isubpassInput";
1087 // TODO: case VK_FORMAT_R64_SFLOAT: return "subpassInput";
1090 case VK_FORMAT_R32G32B32A32_UINT: return "usubpassInput";
1091 case VK_FORMAT_R32G32B32A32_SINT: return "isubpassInput";
1092 case VK_FORMAT_R32G32B32A32_SFLOAT: return "subpassInput";
1093 // TODO: case VK_FORMAT_R64G64_UINT: return "usubpassInput";
1094 // TODO: case VK_FORMAT_R64G64_SINT: return "isubpassInput";
1095 // TODO: case VK_FORMAT_R64G64_SFLOAT: return "subpassInput";
1097 default: TCU_THROW(InternalError, "Unknown format");
1101 const char* getGlslFormatType (const vk::VkFormat format)
1106 case VK_FORMAT_R16G16B16A16_UNORM: return "vec4";
1107 case VK_FORMAT_R16G16B16A16_SNORM: return "vec4";
1108 case VK_FORMAT_R16G16B16A16_USCALED: return "vec4";
1109 case VK_FORMAT_R16G16B16A16_SSCALED: return "vec4";
1110 case VK_FORMAT_R16G16B16A16_UINT: return "uvec4";
1111 case VK_FORMAT_R16G16B16A16_SINT: return "ivec4";
1112 case VK_FORMAT_R16G16B16A16_SFLOAT: return "vec4";
1113 case VK_FORMAT_R32G32_UINT: return "uvec2";
1114 case VK_FORMAT_R32G32_SINT: return "ivec2";
1115 case VK_FORMAT_R32G32_SFLOAT: return "vec2";
1116 // TODO: case VK_FORMAT_R64_UINT: return "uint64";
1117 // TODO: case VK_FORMAT_R64_SINT: return "int64";
1118 // TODO: case VK_FORMAT_R64_SFLOAT: return "double";
1121 case VK_FORMAT_R32G32B32A32_UINT: return "uvec4";
1122 case VK_FORMAT_R32G32B32A32_SINT: return "ivec4";
1123 case VK_FORMAT_R32G32B32A32_SFLOAT: return "vec4";
1124 // TODO: case VK_FORMAT_R64G64_UINT: return "ulvec2";
1125 // TODO: case VK_FORMAT_R64G64_SINT: return "ilvec2";
1126 // TODO: case VK_FORMAT_R64G64_SFLOAT: return "dvec2";
1128 default: TCU_THROW(InternalError, "Unknown format");
1132 const char* getGlslAttachmentType (const vk::VkFormat format)
1134 const tcu::TextureFormat textureFormat = mapVkFormat(format);
1135 const tcu::TextureChannelClass channelClass = tcu::getTextureChannelClass(textureFormat.type);
1137 switch (channelClass)
1139 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
1142 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1145 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1146 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1147 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
1151 DE_FATAL("Unknown channel class");
1156 const char* getGlslInputAttachmentType (const vk::VkFormat format)
1158 const tcu::TextureFormat textureFormat = mapVkFormat(format);
1159 const tcu::TextureChannelClass channelClass = tcu::getTextureChannelClass(textureFormat.type);
1161 switch (channelClass)
1163 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
1164 return "isubpassInput";
1166 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1167 return "usubpassInput";
1169 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1170 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1171 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
1172 return "subpassInput";
1175 DE_FATAL("Unknown channel class");
1180 bool isPackedType (const vk::VkFormat format)
1182 const tcu::TextureFormat textureFormat = mapVkFormat(format);
1184 DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELTYPE_LAST == 40);
1186 switch (textureFormat.type)
1188 case tcu::TextureFormat::UNORM_BYTE_44:
1189 case tcu::TextureFormat::UNORM_SHORT_565:
1190 case tcu::TextureFormat::UNORM_SHORT_555:
1191 case tcu::TextureFormat::UNORM_SHORT_4444:
1192 case tcu::TextureFormat::UNORM_SHORT_5551:
1193 case tcu::TextureFormat::UNORM_SHORT_1555:
1194 case tcu::TextureFormat::UNORM_INT_101010:
1195 case tcu::TextureFormat::SNORM_INT_1010102_REV:
1196 case tcu::TextureFormat::UNORM_INT_1010102_REV:
1197 case tcu::TextureFormat::UNSIGNED_BYTE_44:
1198 case tcu::TextureFormat::UNSIGNED_SHORT_565:
1199 case tcu::TextureFormat::UNSIGNED_SHORT_4444:
1200 case tcu::TextureFormat::UNSIGNED_SHORT_5551:
1201 case tcu::TextureFormat::SIGNED_INT_1010102_REV:
1202 case tcu::TextureFormat::UNSIGNED_INT_1010102_REV:
1203 case tcu::TextureFormat::UNSIGNED_INT_11F_11F_10F_REV:
1204 case tcu::TextureFormat::UNSIGNED_INT_999_E5_REV:
1205 case tcu::TextureFormat::UNSIGNED_INT_16_8_8:
1206 case tcu::TextureFormat::UNSIGNED_INT_24_8:
1207 case tcu::TextureFormat::UNSIGNED_INT_24_8_REV:
1215 bool isComponentSwizzled (const vk::VkFormat format)
1217 const tcu::TextureFormat textureFormat = mapVkFormat(format);
1219 DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELORDER_LAST == 21);
1221 switch (textureFormat.order)
1223 case tcu::TextureFormat::ARGB:
1224 case tcu::TextureFormat::BGR:
1225 case tcu::TextureFormat::BGRA:
1226 case tcu::TextureFormat::sBGR:
1227 case tcu::TextureFormat::sBGRA:
1235 int getNumUsedChannels (const vk::VkFormat format)
1237 // make sure this function will be checked if type table is updated
1238 DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELORDER_LAST == 21);
1240 const tcu::TextureFormat textureFormat = mapVkFormat(format);
1242 return getNumUsedChannels(textureFormat.order);
1245 std::string getFormatShortString (const VkFormat format)
1247 const std::string fullName = getFormatName(format);
1249 DE_ASSERT(de::beginsWith(fullName, "VK_FORMAT_"));
1251 return de::toLower(fullName.substr(10));
1254 std::vector<tcu::Vec4> createFullscreenQuad (void)
1256 const tcu::Vec4 lowerLeftVertex (-1.0f, -1.0f, 0.0f, 1.0f);
1257 const tcu::Vec4 upperLeftVertex (-1.0f, 1.0f, 0.0f, 1.0f);
1258 const tcu::Vec4 lowerRightVertex (1.0f, -1.0f, 0.0f, 1.0f);
1259 const tcu::Vec4 upperRightVertex (1.0f, 1.0f, 0.0f, 1.0f);
1261 const tcu::Vec4 vertices[6] =
1272 return std::vector<tcu::Vec4>(vertices, vertices + DE_LENGTH_OF_ARRAY(vertices));
1275 vk::VkBufferImageCopy makeBufferImageCopy (const deUint32 imageWidth, const deUint32 imageHeight, const deUint32 mipLevel, const deUint32 layer)
1277 const VkBufferImageCopy copyParams =
1279 (VkDeviceSize)0u, // bufferOffset
1280 imageWidth, // bufferRowLength
1281 imageHeight, // bufferImageHeight
1283 VK_IMAGE_ASPECT_COLOR_BIT, // aspectMask
1284 mipLevel, // mipLevel
1285 layer, // baseArrayLayer
1287 }, // imageSubresource
1288 { 0u, 0u, 0u }, // imageOffset
1299 vk::VkBufferImageCopy makeBufferImageCopy (const deUint32 imageWidth, const deUint32 imageHeight, const deUint32 mipLevel, const deUint32 layer, const deUint32 bufferRowLength, const deUint32 bufferImageHeight)
1301 const VkBufferImageCopy copyParams =
1303 (VkDeviceSize)0u, // bufferOffset
1304 bufferRowLength, // bufferRowLength
1305 bufferImageHeight, // bufferImageHeight
1307 VK_IMAGE_ASPECT_COLOR_BIT, // aspectMask
1308 mipLevel, // mipLevel
1309 layer, // baseArrayLayer
1311 }, // imageSubresource
1312 { 0u, 0u, 0u }, // imageOffset
1323 void beginRenderPass (const DeviceInterface& vk,
1324 const VkCommandBuffer commandBuffer,
1325 const VkRenderPass renderPass,
1326 const VkFramebuffer framebuffer,
1327 const VkExtent2D& renderSize)
1329 const VkClearValue clearValues[] =
1331 makeClearValueColorF32(0.0, 0.0, 0.0, 0.0),
1332 makeClearValueColorF32(0.0, 0.0, 0.0, 0.0),
1334 const VkRect2D renderArea =
1336 {0, 0}, // VkOffset2D offset;
1337 renderSize, // VkExtent2D extent;
1339 const VkRenderPassBeginInfo renderPassBeginInfo =
1341 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, // VkStructureType sType;
1342 DE_NULL, // const void* pNext;
1343 renderPass, // VkRenderPass renderPass;
1344 framebuffer, // VkFramebuffer framebuffer;
1345 renderArea, // VkRect2D renderArea;
1346 DE_LENGTH_OF_ARRAY(clearValues), // uint32_t clearValueCount;
1347 clearValues, // const VkClearValue* pClearValues;
1350 vk.cmdBeginRenderPass(commandBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
1353 Move<VkFramebuffer> makeFramebuffer (const DeviceInterface& vk,
1354 const VkDevice device,
1355 const VkRenderPass renderPass,
1356 const deUint32 attachmentCount,
1357 const VkImageView* pAttachments,
1358 const VkExtent2D& size,
1359 const deUint32 layersCount)
1361 const vk::VkFramebufferCreateInfo framebufferInfo =
1363 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // VkStructureType sType;
1364 DE_NULL, // const void* pNext;
1365 (VkFramebufferCreateFlags)0, // VkFramebufferCreateFlags flags;
1366 renderPass, // VkRenderPass renderPass;
1367 attachmentCount, // uint32_t attachmentCount;
1368 pAttachments, // const VkImageView* pAttachments;
1369 static_cast<deUint32>(size.width), // uint32_t width;
1370 static_cast<deUint32>(size.height), // uint32_t height;
1371 layersCount, // uint32_t layers;
1374 return createFramebuffer(vk, device, &framebufferInfo);
1377 VkRect2D makeScissor (const deUint32 width,
1378 const deUint32 height)
1380 const VkRect2D scissor =
1382 { 0u, 0u }, // VkOffset2D offset;
1383 { width, height } // VkExtent2D extent;