Merge vk-gl-cts/vulkan-cts-1.0.1 into vk-gl-cts/vulkan-cts-1.0.2
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / image / vktImageTestsUtil.cpp
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 "tcuTextureUtil.hpp"
28
29 using namespace vk;
30
31 namespace vkt
32 {
33 namespace image
34 {
35
36 Buffer::Buffer (const DeviceInterface&          vk,
37                                 const VkDevice                          device,
38                                 Allocator&                                      allocator,
39                                 const VkBufferCreateInfo&       bufferCreateInfo,
40                                 const MemoryRequirement         memoryRequirement)
41 {
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()));
45 }
46
47 Image::Image (const DeviceInterface&    vk,
48                           const VkDevice                        device,
49                           Allocator&                            allocator,
50                           const VkImageCreateInfo&      imageCreateInfo,
51                           const MemoryRequirement       memoryRequirement)
52 {
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()));
56 }
57
58 struct CompressedFormatParameters
59 {
60         VkFormat        format;
61         deUint32        blockBytes;
62         deUint32        blockWidth;
63         deUint32        blockHeight;
64 };
65
66 CompressedFormatParameters      compressedFormatParameters[VK_FORMAT_ASTC_12x12_SRGB_BLOCK - VK_FORMAT_BC1_RGB_UNORM_BLOCK + 1] =
67 {
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 },
122 };
123
124 deUint32 getBlockSizeInBytes(const VkFormat compressedFormat)
125 {
126         deUint32 formatNdx = static_cast<deUint32>(compressedFormat - VK_FORMAT_BC1_RGB_UNORM_BLOCK);
127
128         DE_ASSERT(deInRange32(formatNdx, 0, DE_LENGTH_OF_ARRAY(compressedFormatParameters)));
129         DE_ASSERT(compressedFormatParameters[formatNdx].format == compressedFormat);
130
131         return compressedFormatParameters[formatNdx].blockBytes;
132 }
133
134 deUint32 getBlockWidth(const VkFormat compressedFormat)
135 {
136         deUint32 formatNdx = static_cast<deUint32>(compressedFormat - VK_FORMAT_BC1_RGB_UNORM_BLOCK);
137
138         DE_ASSERT(deInRange32(formatNdx, 0, DE_LENGTH_OF_ARRAY(compressedFormatParameters)));
139         DE_ASSERT(compressedFormatParameters[formatNdx].format == compressedFormat);
140
141         return compressedFormatParameters[formatNdx].blockWidth;
142 }
143
144 deUint32 getBlockHeight(const VkFormat compressedFormat)
145 {
146         deUint32 formatNdx = static_cast<deUint32>(compressedFormat - VK_FORMAT_BC1_RGB_UNORM_BLOCK);
147
148         DE_ASSERT(deInRange32(formatNdx, 0, DE_LENGTH_OF_ARRAY(compressedFormatParameters)));
149         DE_ASSERT(compressedFormatParameters[formatNdx].format == compressedFormat);
150
151         return compressedFormatParameters[formatNdx].blockHeight;
152 }
153
154 tcu::UVec3 getShaderGridSize (const ImageType imageType, const tcu::UVec3& imageSize)
155 {
156         switch (imageType)
157         {
158                 case IMAGE_TYPE_1D:
159                 case IMAGE_TYPE_BUFFER:
160                         return tcu::UVec3(imageSize.x(), 1u, 1u);
161
162                 case IMAGE_TYPE_1D_ARRAY:
163                         return tcu::UVec3(imageSize.x(), imageSize.z(), 1u);
164
165                 case IMAGE_TYPE_2D:
166                         return tcu::UVec3(imageSize.x(), imageSize.y(), 1u);
167
168                 case IMAGE_TYPE_2D_ARRAY:
169                 case IMAGE_TYPE_3D:
170                         return tcu::UVec3(imageSize.x(), imageSize.y(), imageSize.z());
171
172                 case IMAGE_TYPE_CUBE:
173                         return tcu::UVec3(imageSize.x(), imageSize.y(), 6u);
174
175                 case IMAGE_TYPE_CUBE_ARRAY:
176                         return tcu::UVec3(imageSize.x(), imageSize.y(), 6u * imageSize.z());
177
178                 default:
179                         DE_FATAL("Unknown image type");
180                         return tcu::UVec3(1u, 1u, 1u);
181         }
182 }
183
184 tcu::UVec3 getLayerSize (const ImageType imageType, const tcu::UVec3& imageSize)
185 {
186         switch (imageType)
187         {
188                 case IMAGE_TYPE_1D:
189                 case IMAGE_TYPE_1D_ARRAY:
190                 case IMAGE_TYPE_BUFFER:
191                         return tcu::UVec3(imageSize.x(), 1u, 1u);
192
193                 case IMAGE_TYPE_2D:
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);
198
199                 case IMAGE_TYPE_3D:
200                         return tcu::UVec3(imageSize.x(), imageSize.y(), imageSize.z());
201
202                 default:
203                         DE_FATAL("Unknown image type");
204                         return tcu::UVec3(1u, 1u, 1u);
205         }
206 }
207
208 deUint32 getNumLayers (const ImageType imageType, const tcu::UVec3& imageSize)
209 {
210         switch (imageType)
211         {
212                 case IMAGE_TYPE_1D:
213                 case IMAGE_TYPE_2D:
214                 case IMAGE_TYPE_3D:
215                 case IMAGE_TYPE_BUFFER:
216                         return 1u;
217
218                 case IMAGE_TYPE_1D_ARRAY:
219                 case IMAGE_TYPE_2D_ARRAY:
220                         return imageSize.z();
221
222                 case IMAGE_TYPE_CUBE:
223                         return 6u;
224
225                 case IMAGE_TYPE_CUBE_ARRAY:
226                         return imageSize.z() * 6u;
227
228                 default:
229                         DE_FATAL("Unknown image type");
230                         return 0u;
231         }
232 }
233
234 deUint32 getNumPixels (const ImageType imageType, const tcu::UVec3& imageSize)
235 {
236         const tcu::UVec3 gridSize = getShaderGridSize(imageType, imageSize);
237
238         return gridSize.x() * gridSize.y() * gridSize.z();
239 }
240
241 deUint32 getDimensions (const ImageType imageType)
242 {
243         switch (imageType)
244         {
245                 case IMAGE_TYPE_1D:
246                 case IMAGE_TYPE_BUFFER:
247                         return 1u;
248
249                 case IMAGE_TYPE_1D_ARRAY:
250                 case IMAGE_TYPE_2D:
251                         return 2u;
252
253                 case IMAGE_TYPE_2D_ARRAY:
254                 case IMAGE_TYPE_CUBE:
255                 case IMAGE_TYPE_CUBE_ARRAY:
256                 case IMAGE_TYPE_3D:
257                         return 3u;
258
259                 default:
260                         DE_FATAL("Unknown image type");
261                         return 0u;
262         }
263 }
264
265 deUint32 getLayerDimensions (const ImageType imageType)
266 {
267         switch (imageType)
268         {
269                 case IMAGE_TYPE_1D:
270                 case IMAGE_TYPE_BUFFER:
271                 case IMAGE_TYPE_1D_ARRAY:
272                         return 1u;
273
274                 case IMAGE_TYPE_2D:
275                 case IMAGE_TYPE_2D_ARRAY:
276                 case IMAGE_TYPE_CUBE:
277                 case IMAGE_TYPE_CUBE_ARRAY:
278                         return 2u;
279
280                 case IMAGE_TYPE_3D:
281                         return 3u;
282
283                 default:
284                         DE_FATAL("Unknown image type");
285                         return 0u;
286         }
287 }
288
289 VkBufferCreateInfo makeBufferCreateInfo (const VkDeviceSize                     bufferSize,
290                                                                                  const VkBufferUsageFlags       usage)
291 {
292         const VkBufferCreateInfo bufferCreateInfo =
293         {
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;
302         };
303         return bufferCreateInfo;
304 }
305
306 VkBufferImageCopy makeBufferImageCopy (const VkExtent3D extent,
307                                                                            const deUint32       arraySize)
308 {
309         const VkBufferImageCopy copyParams =
310         {
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;
317         };
318         return copyParams;
319 }
320
321 Move<VkPipelineLayout> makePipelineLayout (const DeviceInterface&               vk,
322                                                                                    const VkDevice                               device,
323                                                                                    const VkDescriptorSetLayout  descriptorSetLayout)
324 {
325         const VkPipelineLayoutCreateInfo pipelineLayoutParams =
326         {
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;
334         };
335         return createPipelineLayout(vk, device, &pipelineLayoutParams);
336 }
337
338 Move<VkPipeline> makeComputePipeline (const DeviceInterface&    vk,
339                                                                           const VkDevice                        device,
340                                                                           const VkPipelineLayout        pipelineLayout,
341                                                                           const VkShaderModule          shaderModule)
342 {
343         const VkPipelineShaderStageCreateInfo pipelineShaderStageParams =
344         {
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;
352         };
353         const VkComputePipelineCreateInfo pipelineCreateInfo =
354         {
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;
362         };
363         return createComputePipeline(vk, device, DE_NULL , &pipelineCreateInfo);
364 }
365
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)
375 {
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;
380
381         const VkVertexInputBindingDescription vertexBinding =
382         {
383                 0u,                                                                                                                             // deUint32                                                                             binding;
384                 vertexDataStride,                                                                                               // deUint32                                                                             stride;
385                 VK_VERTEX_INPUT_RATE_VERTEX                                                                             // VkVertexInputRate                                                    inputRate;
386         };
387
388         const VkVertexInputAttributeDescription vertexInputAttributeDescriptions[] =
389         {
390                 // position
391                 {
392                         0u,                                                                                                                     // deUint32                                                                             location;
393                         0u,                                                                                                                     // deUint32                                                                             binding;
394                         vertexFormatPosition,                                                                           // VkFormat                                                                             format;
395                         vertexBufferOffsetPosition,                                                                     // deUint32                                                                             offset;
396                 },
397         };
398
399         const VkPipelineVertexInputStateCreateInfo vertexInputStateInfo =
400         {
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;
408         };
409
410         const VkPipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateInfo =
411         {
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;
417         };
418
419         const VkViewport viewport =
420         {
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;
427         };
428
429         const VkRect2D scissor =
430         {
431                 { 0u, 0u },                                                                                                             // VkOffset2D                                                                   offset;
432                 renderSize                                                                                                              // VkExtent2D                                                                   extent;
433         };
434
435         const VkPipelineViewportStateCreateInfo pipelineViewportStateInfo =
436         {
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;
444         };
445
446         const VkPipelineRasterizationStateCreateInfo pipelineRasterizationStateInfo =
447         {
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;
461         };
462
463         const VkPipelineMultisampleStateCreateInfo pipelineMultisampleStateInfo =
464         {
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;
474         };
475
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       =
478         {
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;
487         };
488         std::vector<VkPipelineColorBlendAttachmentState> colorAttachments(colorAttachmentCount, colorBlendAttachmentState);
489
490         const VkPipelineColorBlendStateCreateInfo pipelineColorBlendStateInfo =
491         {
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];
500         };
501
502         const VkPipelineShaderStageCreateInfo pShaderStages[] =
503         {
504                 {
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;
512                 },
513                 {
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;
521                 }
522         };
523         const deUint32 numActiveShaderStages = DE_LENGTH_OF_ARRAY(pShaderStages);
524
525         const VkDynamicState dynamicStates[] =
526         {
527                 VK_DYNAMIC_STATE_VIEWPORT,
528                 VK_DYNAMIC_STATE_SCISSOR,
529         };
530
531         const VkPipelineDynamicStateCreateInfo dynamicStateCreateInfo =
532         {
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;
538         };
539
540         const VkGraphicsPipelineCreateInfo graphicsPipelineInfo =
541         {
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;
561         };
562
563         return createGraphicsPipeline(vk, device, DE_NULL, &graphicsPipelineInfo);
564 }
565
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)
571 {
572         const VkAttachmentReference             inputAttachmentRef                      =
573         {
574                 0u,                                                                                                                     // deUint32                     attachment;
575                 VK_IMAGE_LAYOUT_GENERAL                                                                         // VkImageLayout        layout;
576         };
577
578         const VkAttachmentReference             colorAttachmentRef                      =
579         {
580                 1u,                                                                                                                     // deUint32                     attachment;
581                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL                                        // VkImageLayout        layout;
582         };
583
584         const VkSubpassDescription              subpassDescription                      =
585         {
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;
596         };
597
598         const VkAttachmentDescription   attachmentsDescriptions[]       =
599         {
600                 //inputAttachmentDescription,
601                 {
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;
611                 },
612                 //colorAttachmentDescription
613                 {
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;
623                 }
624         };
625
626         const VkRenderPassCreateInfo    renderPassInfo                          =
627         {
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;
637         };
638
639         return createRenderPass(vk, device, &renderPassInfo);
640 }
641
642 //! A single-subpass render pass.
643 Move<VkRenderPass> makeRenderPass (const DeviceInterface&       vk,
644                                                                    const VkDevice                       device)
645 {
646         const VkSubpassDescription              subpassDescription                      =
647         {
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;
658         };
659
660         const VkRenderPassCreateInfo    renderPassInfo                          =
661         {
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;
671         };
672
673         return createRenderPass(vk, device, &renderPassInfo);
674 }
675
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)
682 {
683         const VkBufferViewCreateInfo bufferViewParams =
684         {
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;
692         };
693         return createBufferView(vk, vkDevice, &bufferViewParams);
694 }
695
696 Move<VkImageView> makeImageView (const DeviceInterface&                                 vk,
697                                                                  const VkDevice                                                 vkDevice,
698                                                                  const VkImage                                                  image,
699                                                                  const VkImageViewType                                  imageViewType,
700                                                                  const VkFormat                                                 format,
701                                                                  const VkImageSubresourceRange                  subresourceRange,
702                                                                  const VkImageViewUsageCreateInfoKHR*   ImageUsageCreateInfoKHR)
703 {
704         const VkImageViewCreateInfo imageViewParams =
705         {
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;
714         };
715         return createImageView(vk, vkDevice, &imageViewParams);
716 }
717
718 Move<VkDescriptorSet> makeDescriptorSet (const DeviceInterface&                 vk,
719                                                                                  const VkDevice                                 device,
720                                                                                  const VkDescriptorPool                 descriptorPool,
721                                                                                  const VkDescriptorSetLayout    setLayout)
722 {
723         const VkDescriptorSetAllocateInfo allocateParams =
724         {
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;
730         };
731         return allocateDescriptorSet(vk, device, &allocateParams);
732 }
733
734 VkBufferMemoryBarrier makeBufferMemoryBarrier (const VkAccessFlags      srcAccessMask,
735                                                                                            const VkAccessFlags  dstAccessMask,
736                                                                                            const VkBuffer               buffer,
737                                                                                            const VkDeviceSize   offset,
738                                                                                            const VkDeviceSize   bufferSizeBytes)
739 {
740         const VkBufferMemoryBarrier barrier =
741         {
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;
751         };
752         return barrier;
753 }
754
755 VkImageMemoryBarrier makeImageMemoryBarrier     (const VkAccessFlags                    srcAccessMask,
756                                                                                          const VkAccessFlags                    dstAccessMask,
757                                                                                          const VkImageLayout                    oldLayout,
758                                                                                          const VkImageLayout                    newLayout,
759                                                                                          const VkImage                                  image,
760                                                                                          const VkImageSubresourceRange  subresourceRange)
761 {
762         const VkImageMemoryBarrier barrier =
763         {
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;
774         };
775         return barrier;
776 }
777
778 VkImageViewUsageCreateInfoKHR makeImageViewUsageCreateInfo (const VkImageUsageFlags imageUsageFlags)
779 {
780         VkImageViewUsageCreateInfoKHR imageViewUsageCreateInfoKHR =
781         {
782                 VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO_KHR,     //VkStructureType               sType;
783                 DE_NULL,                                                                                        //const void*                   pNext;
784                 imageUsageFlags,                                                                        //VkImageUsageFlags             usage;
785         };
786
787         return imageViewUsageCreateInfoKHR;
788 }
789
790 VkSamplerCreateInfo makeSamplerCreateInfo ()
791 {
792         const VkSamplerCreateInfo defaultSamplerParams =
793         {
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;
812         };
813
814         return defaultSamplerParams;
815 }
816
817 void beginCommandBuffer (const DeviceInterface& vk, const VkCommandBuffer commandBuffer)
818 {
819         const VkCommandBufferBeginInfo commandBufBeginParams =
820         {
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,
825         };
826         VK_CHECK(vk.beginCommandBuffer(commandBuffer, &commandBufBeginParams));
827 }
828 void endCommandBuffer (const DeviceInterface& vk, const VkCommandBuffer commandBuffer)
829 {
830         VK_CHECK(vk.endCommandBuffer(commandBuffer));
831 }
832
833 void submitCommandsAndWait (const DeviceInterface&      vk,
834                                                         const VkDevice                  device,
835                                                         const VkQueue                   queue,
836                                                         const VkCommandBuffer   commandBuffer)
837 {
838         const Unique<VkFence> fence(createFence(vk, device));
839
840         const VkSubmitInfo submitInfo =
841         {
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;
851         };
852
853         VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
854         VK_CHECK(vk.waitForFences(device, 1u, &fence.get(), DE_TRUE, ~0ull));
855 }
856
857 tcu::UVec3 getCompressedImageResolutionInBlocks (const vk::VkFormat format, const tcu::UVec3& size)
858 {
859         deUint32        blockWidth      = getBlockWidth(format);
860         deUint32        blockHeight     = getBlockHeight(format);
861
862         DE_ASSERT(size[2] == 1);
863         DE_ASSERT(blockWidth != 0 && blockHeight != 0);
864
865         deUint32        widthInBlocks   = (size[0] + blockWidth - 1) / blockWidth;
866         deUint32        heightInBlocks  = (size[1] + blockHeight - 1) / blockHeight;
867
868         return tcu::UVec3(widthInBlocks, heightInBlocks, 1);
869 }
870
871 tcu::UVec3 getCompressedImageResolutionBlockCeil (const vk::VkFormat format, const tcu::UVec3& size)
872 {
873         deUint32        blockWidth      = getBlockWidth(format);
874         deUint32        blockHeight     = getBlockHeight(format);
875
876         DE_ASSERT(size[2] == 1);
877         DE_ASSERT(blockWidth != 0 && blockHeight != 0);
878
879         deUint32        widthInBlocks   = (size[0] + blockWidth - 1) / blockWidth;
880         deUint32        heightInBlocks  = (size[1] + blockHeight - 1) / blockHeight;
881
882         return tcu::UVec3(blockWidth * widthInBlocks, blockHeight * heightInBlocks, 1);
883 }
884
885 VkDeviceSize getCompressedImageSizeInBytes (const vk::VkFormat format, const tcu::UVec3& size)
886 {
887         tcu::UVec3              sizeInBlocks    = getCompressedImageResolutionInBlocks(format, size);
888         deUint32                blockBytes              = getBlockSizeInBytes(format);
889         VkDeviceSize    sizeBytes               = sizeInBlocks[0] * sizeInBlocks[1] * sizeInBlocks[2] * blockBytes;
890
891         return sizeBytes;
892 }
893
894 VkDeviceSize getUncompressedImageSizeInBytes (const vk::VkFormat format, const tcu::UVec3& size)
895 {
896         const tcu::IVec3        sizeAsIVec3     = tcu::IVec3((int)size.x(), (int)size.y(), (int)size.z());
897         const VkDeviceSize      sizeBytes       = getImageSizeBytes(sizeAsIVec3, format);
898
899         return sizeBytes;
900 }
901
902 VkImageType     mapImageType (const ImageType imageType)
903 {
904         switch (imageType)
905         {
906                 case IMAGE_TYPE_1D:
907                 case IMAGE_TYPE_1D_ARRAY:
908                 case IMAGE_TYPE_BUFFER:
909                         return VK_IMAGE_TYPE_1D;
910
911                 case IMAGE_TYPE_2D:
912                 case IMAGE_TYPE_2D_ARRAY:
913                 case IMAGE_TYPE_CUBE:
914                 case IMAGE_TYPE_CUBE_ARRAY:
915                         return VK_IMAGE_TYPE_2D;
916
917                 case IMAGE_TYPE_3D:
918                         return VK_IMAGE_TYPE_3D;
919
920                 default:
921                         DE_ASSERT(false);
922                         return VK_IMAGE_TYPE_LAST;
923         }
924 }
925
926 VkImageViewType mapImageViewType (const ImageType imageType)
927 {
928         switch (imageType)
929         {
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;
937
938                 default:
939                         DE_ASSERT(false);
940                         return VK_IMAGE_VIEW_TYPE_LAST;
941         }
942 }
943
944 std::string getImageTypeName (const ImageType imageType)
945 {
946         switch (imageType)
947         {
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";
956
957                 default:
958                         DE_ASSERT(false);
959                         return "";
960         }
961 }
962
963 std::string getShaderImageType (const tcu::TextureFormat& format, const ImageType imageType, const bool multisample)
964 {
965         std::string formatPart = tcu::getTextureChannelClass(format.type) == tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER ? "u" :
966                                                          tcu::getTextureChannelClass(format.type) == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER   ? "i" : "";
967
968         std::string imageTypePart;
969         if (multisample)
970         {
971                 switch (imageType)
972                 {
973                         case IMAGE_TYPE_2D:                     imageTypePart = "2DMS";                 break;
974                         case IMAGE_TYPE_2D_ARRAY:       imageTypePart = "2DMSArray";    break;
975
976                         default:
977                                 DE_ASSERT(false);
978                 }
979         }
980         else
981         {
982                 switch (imageType)
983                 {
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;
992
993                         default:
994                                 DE_ASSERT(false);
995                 }
996         }
997
998         return formatPart + "image" + imageTypePart;
999 }
1000
1001 std::string getShaderImageFormatQualifier (const tcu::TextureFormat& format)
1002 {
1003         const char* orderPart;
1004         const char* typePart;
1005
1006         switch (format.order)
1007         {
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;
1012
1013                 default:
1014                         DE_ASSERT(false);
1015                         orderPart = DE_NULL;
1016         }
1017
1018         switch (format.type)
1019         {
1020                 case tcu::TextureFormat::FLOAT:                         typePart = "32f";               break;
1021                 case tcu::TextureFormat::HALF_FLOAT:            typePart = "16f";               break;
1022
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;
1026
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;
1030
1031                 case tcu::TextureFormat::UNORM_INT16:           typePart = "16";                break;
1032                 case tcu::TextureFormat::UNORM_INT8:            typePart = "8";                 break;
1033
1034                 case tcu::TextureFormat::SNORM_INT16:           typePart = "16_snorm";  break;
1035                 case tcu::TextureFormat::SNORM_INT8:            typePart = "8_snorm";   break;
1036
1037                 default:
1038                         DE_ASSERT(false);
1039                         typePart = DE_NULL;
1040         }
1041
1042         return std::string() + orderPart + typePart;
1043 }
1044
1045 std::string getGlslSamplerType (const tcu::TextureFormat& format, VkImageViewType type)
1046 {
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" : "";
1050
1051         switch (type)
1052         {
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;
1060
1061                 default:
1062                         DE_FATAL("Unknown image view type");
1063                         break;
1064         }
1065
1066         return std::string(formatPart) + typePart;
1067 }
1068
1069
1070 const char* getGlslInputFormatType (const vk::VkFormat format)
1071 {
1072         switch (format)
1073         {
1074                 // 64-bit
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";
1088
1089                 // 128-bit
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";
1096
1097                 default:        TCU_THROW(InternalError, "Unknown format");
1098         }
1099 }
1100
1101 const char* getGlslFormatType (const vk::VkFormat format)
1102 {
1103         switch (format)
1104         {
1105                 // 64-bit
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";
1119
1120                 // 128-bit
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";
1127
1128                 default:        TCU_THROW(InternalError, "Unknown format");
1129         }
1130 }
1131
1132 const char* getGlslAttachmentType (const vk::VkFormat format)
1133 {
1134         const tcu::TextureFormat                textureFormat   = mapVkFormat(format);
1135         const tcu::TextureChannelClass  channelClass    = tcu::getTextureChannelClass(textureFormat.type);
1136
1137         switch (channelClass)
1138         {
1139                 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
1140                         return "ivec4";
1141
1142                 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1143                         return "uvec4";
1144
1145                 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1146                 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1147                 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
1148                         return "vec4";
1149
1150                 default:
1151                         DE_FATAL("Unknown channel class");
1152                         return "";
1153         }
1154 }
1155
1156 const char* getGlslInputAttachmentType (const vk::VkFormat format)
1157 {
1158         const tcu::TextureFormat                textureFormat   = mapVkFormat(format);
1159         const tcu::TextureChannelClass  channelClass    = tcu::getTextureChannelClass(textureFormat.type);
1160
1161         switch (channelClass)
1162         {
1163                 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
1164                         return "isubpassInput";
1165
1166                 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1167                         return "usubpassInput";
1168
1169                 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1170                 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1171                 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
1172                         return "subpassInput";
1173
1174                 default:
1175                         DE_FATAL("Unknown channel class");
1176                         return "";
1177         }
1178 }
1179
1180 bool isPackedType (const vk::VkFormat format)
1181 {
1182         const tcu::TextureFormat        textureFormat   = mapVkFormat(format);
1183
1184         DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELTYPE_LAST == 40);
1185
1186         switch (textureFormat.type)
1187         {
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:
1208                         return true;
1209
1210                 default:
1211                         return false;
1212         }
1213 }
1214
1215 bool isComponentSwizzled (const vk::VkFormat format)
1216 {
1217         const tcu::TextureFormat        textureFormat   = mapVkFormat(format);
1218
1219         DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELORDER_LAST == 21);
1220
1221         switch (textureFormat.order)
1222         {
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:
1228                         return true;
1229
1230                 default:
1231                         return false;
1232         }
1233 }
1234
1235 int getNumUsedChannels (const vk::VkFormat format)
1236 {
1237         // make sure this function will be checked if type table is updated
1238         DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELORDER_LAST == 21);
1239
1240         const tcu::TextureFormat        textureFormat   = mapVkFormat(format);
1241
1242         return getNumUsedChannels(textureFormat.order);
1243 }
1244
1245 std::string getFormatShortString (const VkFormat format)
1246 {
1247         const std::string fullName = getFormatName(format);
1248
1249         DE_ASSERT(de::beginsWith(fullName, "VK_FORMAT_"));
1250
1251         return de::toLower(fullName.substr(10));
1252 }
1253
1254 std::vector<tcu::Vec4> createFullscreenQuad (void)
1255 {
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);
1260
1261         const tcu::Vec4 vertices[6] =
1262         {
1263                 lowerLeftVertex,
1264                 lowerRightVertex,
1265                 upperLeftVertex,
1266
1267                 upperLeftVertex,
1268                 lowerRightVertex,
1269                 upperRightVertex
1270         };
1271
1272         return std::vector<tcu::Vec4>(vertices, vertices + DE_LENGTH_OF_ARRAY(vertices));
1273 }
1274
1275 vk::VkBufferImageCopy makeBufferImageCopy (const deUint32 imageWidth, const deUint32 imageHeight, const deUint32 mipLevel, const deUint32 layer)
1276 {
1277         const VkBufferImageCopy copyParams      =
1278         {
1279                 (VkDeviceSize)0u,                                               // bufferOffset
1280                 imageWidth,                                                             // bufferRowLength
1281                 imageHeight,                                                    // bufferImageHeight
1282                 {
1283                         VK_IMAGE_ASPECT_COLOR_BIT,                              // aspectMask
1284                         mipLevel,                                                               // mipLevel
1285                         layer,                                                                  // baseArrayLayer
1286                         1u,                                                                             // layerCount
1287                 },                                                                              // imageSubresource
1288                 { 0u, 0u, 0u },                                                 // imageOffset
1289                 {
1290                         imageWidth,
1291                         imageHeight,
1292                         1u
1293                 }                                                                               // imageExtent
1294         };
1295
1296         return copyParams;
1297 }
1298
1299 vk::VkBufferImageCopy makeBufferImageCopy (const deUint32 imageWidth, const deUint32 imageHeight, const deUint32 mipLevel, const deUint32 layer, const deUint32 bufferRowLength, const deUint32 bufferImageHeight)
1300 {
1301         const VkBufferImageCopy copyParams      =
1302         {
1303                 (VkDeviceSize)0u,                                               // bufferOffset
1304                 bufferRowLength,                                                // bufferRowLength
1305                 bufferImageHeight,                                              // bufferImageHeight
1306                 {
1307                         VK_IMAGE_ASPECT_COLOR_BIT,                              // aspectMask
1308                         mipLevel,                                                               // mipLevel
1309                         layer,                                                                  // baseArrayLayer
1310                         1u,                                                                             // layerCount
1311                 },                                                                              // imageSubresource
1312                 { 0u, 0u, 0u },                                                 // imageOffset
1313                 {
1314                         imageWidth,
1315                         imageHeight,
1316                         1u
1317                 }                                                                               // imageExtent
1318         };
1319
1320         return copyParams;
1321 }
1322
1323 void beginRenderPass (const DeviceInterface&    vk,
1324                                           const VkCommandBuffer         commandBuffer,
1325                                           const VkRenderPass            renderPass,
1326                                           const VkFramebuffer           framebuffer,
1327                                           const VkExtent2D&                     renderSize)
1328 {
1329         const VkClearValue                      clearValues[]           =
1330         {
1331                 makeClearValueColorF32(0.0, 0.0, 0.0, 0.0),
1332                 makeClearValueColorF32(0.0, 0.0, 0.0, 0.0),
1333         };
1334         const VkRect2D                          renderArea                      =
1335         {
1336                 {0, 0},                                                                                 // VkOffset2D                           offset;
1337                 renderSize,                                                                             // VkExtent2D                           extent;
1338         };
1339         const VkRenderPassBeginInfo     renderPassBeginInfo =
1340         {
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;
1348         };
1349
1350         vk.cmdBeginRenderPass(commandBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
1351 }
1352
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)
1360 {
1361         const vk::VkFramebufferCreateInfo framebufferInfo =
1362         {
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;
1372         };
1373
1374         return createFramebuffer(vk, device, &framebufferInfo);
1375 }
1376
1377 VkRect2D makeScissor (const deUint32    width,
1378                                           const deUint32        height)
1379 {
1380         const VkRect2D scissor =
1381         {
1382                 { 0u, 0u },                     // VkOffset2D   offset;
1383                 { width, height }       // VkExtent2D   extent;
1384         };
1385
1386         return scissor;
1387 }
1388
1389 } // image
1390 } // vkt