Fix negative CompressedTexImage2D tests
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / synchronization / vktSynchronizationUtil.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 Synchronization tests utilities
22  *//*--------------------------------------------------------------------*/
23
24 #include "vktSynchronizationUtil.hpp"
25 #include "vkTypeUtil.hpp"
26 #include "deStringUtil.hpp"
27
28 namespace vkt
29 {
30 namespace synchronization
31 {
32 using namespace vk;
33
34 VkBufferCreateInfo makeBufferCreateInfo (const VkDeviceSize                     bufferSize,
35                                                                                  const VkBufferUsageFlags       usage)
36 {
37         const VkBufferCreateInfo bufferCreateInfo =
38         {
39                 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,   // VkStructureType              sType;
40                 DE_NULL,                                                                // const void*                  pNext;
41                 (VkBufferCreateFlags)0,                                 // VkBufferCreateFlags  flags;
42                 bufferSize,                                                             // VkDeviceSize                 size;
43                 usage,                                                                  // VkBufferUsageFlags   usage;
44                 VK_SHARING_MODE_EXCLUSIVE,                              // VkSharingMode                sharingMode;
45                 0u,                                                                             // deUint32                             queueFamilyIndexCount;
46                 DE_NULL,                                                                // const deUint32*              pQueueFamilyIndices;
47         };
48         return bufferCreateInfo;
49 }
50
51 VkMemoryBarrier makeMemoryBarrier (const VkAccessFlags  srcAccessMask,
52                                                                    const VkAccessFlags  dstAccessMask)
53 {
54         const VkMemoryBarrier barrier =
55         {
56                 VK_STRUCTURE_TYPE_MEMORY_BARRIER,       // VkStructureType    sType;
57                 DE_NULL,                                                        // const void*        pNext;
58                 srcAccessMask,                                          // VkAccessFlags      srcAccessMask;
59                 dstAccessMask,                                          // VkAccessFlags      dstAccessMask;
60         };
61         return barrier;
62 }
63
64 VkBufferMemoryBarrier makeBufferMemoryBarrier (const VkAccessFlags      srcAccessMask,
65                                                                                            const VkAccessFlags  dstAccessMask,
66                                                                                            const VkBuffer               buffer,
67                                                                                            const VkDeviceSize   offset,
68                                                                                            const VkDeviceSize   bufferSizeBytes)
69 {
70         const VkBufferMemoryBarrier barrier =
71         {
72                 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,        // VkStructureType      sType;
73                 DE_NULL,                                                                        // const void*          pNext;
74                 srcAccessMask,                                                          // VkAccessFlags        srcAccessMask;
75                 dstAccessMask,                                                          // VkAccessFlags        dstAccessMask;
76                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                     srcQueueFamilyIndex;
77                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                     destQueueFamilyIndex;
78                 buffer,                                                                         // VkBuffer                     buffer;
79                 offset,                                                                         // VkDeviceSize         offset;
80                 bufferSizeBytes,                                                        // VkDeviceSize         size;
81         };
82         return barrier;
83 }
84
85 VkImageMemoryBarrier makeImageMemoryBarrier     (const VkAccessFlags                    srcAccessMask,
86                                                                                          const VkAccessFlags                    dstAccessMask,
87                                                                                          const VkImageLayout                    oldLayout,
88                                                                                          const VkImageLayout                    newLayout,
89                                                                                          const VkImage                                  image,
90                                                                                          const VkImageSubresourceRange  subresourceRange)
91 {
92         const VkImageMemoryBarrier barrier =
93         {
94                 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,                 // VkStructureType                      sType;
95                 DE_NULL,                                                                                // const void*                          pNext;
96                 srcAccessMask,                                                                  // VkAccessFlags                        outputMask;
97                 dstAccessMask,                                                                  // VkAccessFlags                        inputMask;
98                 oldLayout,                                                                              // VkImageLayout                        oldLayout;
99                 newLayout,                                                                              // VkImageLayout                        newLayout;
100                 VK_QUEUE_FAMILY_IGNORED,                                                // deUint32                                     srcQueueFamilyIndex;
101                 VK_QUEUE_FAMILY_IGNORED,                                                // deUint32                                     destQueueFamilyIndex;
102                 image,                                                                                  // VkImage                                      image;
103                 subresourceRange,                                                               // VkImageSubresourceRange      subresourceRange;
104         };
105         return barrier;
106 }
107
108 Move<VkCommandPool> makeCommandPool (const DeviceInterface& vk, const VkDevice device, const deUint32 queueFamilyIndex)
109 {
110         const VkCommandPoolCreateInfo info =
111         {
112                 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,                     // VkStructureType                      sType;
113                 DE_NULL,                                                                                        // const void*                          pNext;
114                 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,        // VkCommandPoolCreateFlags     flags;
115                 queueFamilyIndex,                                                                       // deUint32                                     queueFamilyIndex;
116         };
117         return createCommandPool(vk, device, &info);
118 }
119
120 Move<VkCommandBuffer> makeCommandBuffer (const DeviceInterface& vk, const VkDevice device, const VkCommandPool commandPool)
121 {
122         const VkCommandBufferAllocateInfo info =
123         {
124                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,         // VkStructureType              sType;
125                 DE_NULL,                                                                                        // const void*                  pNext;
126                 commandPool,                                                                            // VkCommandPool                commandPool;
127                 VK_COMMAND_BUFFER_LEVEL_PRIMARY,                                        // VkCommandBufferLevel level;
128                 1u,                                                                                                     // deUint32                             commandBufferCount;
129         };
130         return allocateCommandBuffer(vk, device, &info);
131 }
132
133 Move<VkDescriptorSet> makeDescriptorSet (const DeviceInterface&                 vk,
134                                                                                  const VkDevice                                 device,
135                                                                                  const VkDescriptorPool                 descriptorPool,
136                                                                                  const VkDescriptorSetLayout    setLayout)
137 {
138         const VkDescriptorSetAllocateInfo info =
139         {
140                 VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,         // VkStructureType                              sType;
141                 DE_NULL,                                                                                        // const void*                                  pNext;
142                 descriptorPool,                                                                         // VkDescriptorPool                             descriptorPool;
143                 1u,                                                                                                     // deUint32                                             descriptorSetCount;
144                 &setLayout,                                                                                     // const VkDescriptorSetLayout* pSetLayouts;
145         };
146         return allocateDescriptorSet(vk, device, &info);
147 }
148
149 Move<VkPipelineLayout> makePipelineLayout (const DeviceInterface&               vk,
150                                                                                    const VkDevice                               device,
151                                                                                    const VkDescriptorSetLayout  descriptorSetLayout)
152 {
153         const VkPipelineLayoutCreateInfo info =
154         {
155                 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,          // VkStructureType                              sType;
156                 DE_NULL,                                                                                        // const void*                                  pNext;
157                 (VkPipelineLayoutCreateFlags)0,                                         // VkPipelineLayoutCreateFlags  flags;
158                 1u,                                                                                                     // deUint32                                             setLayoutCount;
159                 &descriptorSetLayout,                                                           // const VkDescriptorSetLayout* pSetLayouts;
160                 0u,                                                                                                     // deUint32                                             pushConstantRangeCount;
161                 DE_NULL,                                                                                        // const VkPushConstantRange*   pPushConstantRanges;
162         };
163         return createPipelineLayout(vk, device, &info);
164 }
165
166 Move<VkPipelineLayout> makePipelineLayoutWithoutDescriptors (const DeviceInterface&             vk,
167                                                                                                                          const VkDevice                         device)
168 {
169         const VkPipelineLayoutCreateInfo info =
170         {
171                 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,          // VkStructureType                              sType;
172                 DE_NULL,                                                                                        // const void*                                  pNext;
173                 (VkPipelineLayoutCreateFlags)0,                                         // VkPipelineLayoutCreateFlags  flags;
174                 0u,                                                                                                     // deUint32                                             setLayoutCount;
175                 DE_NULL,                                                                                        // const VkDescriptorSetLayout* pSetLayouts;
176                 0u,                                                                                                     // deUint32                                             pushConstantRangeCount;
177                 DE_NULL,                                                                                        // const VkPushConstantRange*   pPushConstantRanges;
178         };
179         return createPipelineLayout(vk, device, &info);
180 }
181
182 Move<VkPipeline> makeComputePipeline (const DeviceInterface&            vk,
183                                                                           const VkDevice                                device,
184                                                                           const VkPipelineLayout                pipelineLayout,
185                                                                           const VkShaderModule                  shaderModule,
186                                                                           const VkSpecializationInfo*   specInfo,
187                                                                           PipelineCacheData&                    pipelineCacheData)
188 {
189         const VkPipelineShaderStageCreateInfo shaderStageInfo =
190         {
191                 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,    // VkStructureType                                      sType;
192                 DE_NULL,                                                                                                // const void*                                          pNext;
193                 (VkPipelineShaderStageCreateFlags)0,                                    // VkPipelineShaderStageCreateFlags     flags;
194                 VK_SHADER_STAGE_COMPUTE_BIT,                                                    // VkShaderStageFlagBits                        stage;
195                 shaderModule,                                                                                   // VkShaderModule                                       module;
196                 "main",                                                                                                 // const char*                                          pName;
197                 specInfo,                                                                                               // const VkSpecializationInfo*          pSpecializationInfo;
198         };
199         const VkComputePipelineCreateInfo pipelineInfo =
200         {
201                 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,         // VkStructureType                                      sType;
202                 DE_NULL,                                                                                        // const void*                                          pNext;
203                 (VkPipelineCreateFlags)0,                                                       // VkPipelineCreateFlags                        flags;
204                 shaderStageInfo,                                                                        // VkPipelineShaderStageCreateInfo      stage;
205                 pipelineLayout,                                                                         // VkPipelineLayout                                     layout;
206                 DE_NULL,                                                                                        // VkPipeline                                           basePipelineHandle;
207                 0,                                                                                                      // deInt32                                                      basePipelineIndex;
208         };
209
210         {
211                 const vk::Unique<vk::VkPipelineCache>   pipelineCache   (pipelineCacheData.createPipelineCache(vk, device));
212                 vk::Move<vk::VkPipeline>                                pipeline                (createComputePipeline(vk, device, *pipelineCache, &pipelineInfo));
213
214                 // Refresh data from cache
215                 pipelineCacheData.setFromPipelineCache(vk, device, *pipelineCache);
216
217                 return pipeline;
218         }
219 }
220
221 VkImageCreateInfo makeImageCreateInfo (const VkImageType imageType, const VkExtent3D& extent, const VkFormat format, const VkImageUsageFlags usage)
222 {
223         const VkImageCreateInfo imageInfo =
224         {
225                 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,            // VkStructureType          sType;
226                 DE_NULL,                                                                        // const void*              pNext;
227                 (VkImageCreateFlags)0,                                          // VkImageCreateFlags       flags;
228                 imageType,                                                                      // VkImageType              imageType;
229                 format,                                                                         // VkFormat                 format;
230                 extent,                                                                         // VkExtent3D               extent;
231                 1u,                                                                                     // uint32_t                 mipLevels;
232                 1u,                                                                                     // uint32_t                 arrayLayers;
233                 VK_SAMPLE_COUNT_1_BIT,                                          // VkSampleCountFlagBits    samples;
234                 VK_IMAGE_TILING_OPTIMAL,                                        // VkImageTiling            tiling;
235                 usage,                                                                          // VkImageUsageFlags        usage;
236                 VK_SHARING_MODE_EXCLUSIVE,                                      // VkSharingMode            sharingMode;
237                 0u,                                                                                     // uint32_t                 queueFamilyIndexCount;
238                 DE_NULL,                                                                        // const uint32_t*          pQueueFamilyIndices;
239                 VK_IMAGE_LAYOUT_UNDEFINED,                                      // VkImageLayout            initialLayout;
240         };
241         return imageInfo;
242 }
243
244 Move<VkImageView> makeImageView (const DeviceInterface&                 vk,
245                                                                  const VkDevice                                 device,
246                                                                  const VkImage                                  image,
247                                                                  const VkImageViewType                  viewType,
248                                                                  const VkFormat                                 format,
249                                                                  const VkImageSubresourceRange  subresourceRange)
250 {
251         const VkImageViewCreateInfo imageViewParams =
252         {
253                 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,               // VkStructureType                      sType;
254                 DE_NULL,                                                                                // const void*                          pNext;
255                 (VkImageViewCreateFlags)0,                                              // VkImageViewCreateFlags       flags;
256                 image,                                                                                  // VkImage                                      image;
257                 viewType,                                                                               // VkImageViewType                      viewType;
258                 format,                                                                                 // VkFormat                                     format;
259                 makeComponentMappingRGBA(),                                             // VkComponentMapping           components;
260                 subresourceRange,                                                               // VkImageSubresourceRange      subresourceRange;
261         };
262         return createImageView(vk, device, &imageViewParams);
263 }
264
265 VkBufferImageCopy makeBufferImageCopy (const VkImageSubresourceLayers   subresourceLayers,
266                                                                            const VkExtent3D                                     extent)
267 {
268         const VkBufferImageCopy copyParams =
269         {
270                 0ull,                                                                           //      VkDeviceSize                            bufferOffset;
271                 0u,                                                                                     //      deUint32                                        bufferRowLength;
272                 0u,                                                                                     //      deUint32                                        bufferImageHeight;
273                 subresourceLayers,                                                      //      VkImageSubresourceLayers        imageSubresource;
274                 makeOffset3D(0, 0, 0),                                          //      VkOffset3D                                      imageOffset;
275                 extent,                                                                         //      VkExtent3D                                      imageExtent;
276         };
277         return copyParams;
278 }
279
280 Move<VkEvent> makeEvent (const DeviceInterface& vk, const VkDevice device)
281 {
282         const VkEventCreateInfo eventParams =
283         {
284                 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,    // VkStructureType       sType;
285                 DE_NULL,                                                                // const void*           pNext;
286                 (VkEventCreateFlags)0,                                  // VkEventCreateFlags    flags;
287         };
288         return createEvent(vk, device, &eventParams);
289 }
290
291 void beginCommandBuffer (const DeviceInterface& vk, const VkCommandBuffer commandBuffer)
292 {
293         const VkCommandBufferBeginInfo info =
294         {
295                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,    // VkStructureType                          sType;
296                 DE_NULL,                                                                                // const void*                              pNext;
297                 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,    // VkCommandBufferUsageFlags                flags;
298                 DE_NULL,                                                                                // const VkCommandBufferInheritanceInfo*    pInheritanceInfo;
299         };
300         VK_CHECK(vk.beginCommandBuffer(commandBuffer, &info));
301 }
302
303 void endCommandBuffer (const DeviceInterface& vk, const VkCommandBuffer commandBuffer)
304 {
305         VK_CHECK(vk.endCommandBuffer(commandBuffer));
306 }
307
308 void submitCommandsAndWait (const DeviceInterface&      vk,
309                                                         const VkDevice                  device,
310                                                         const VkQueue                   queue,
311                                                         const VkCommandBuffer   commandBuffer)
312 {
313         const VkFenceCreateInfo fenceInfo =
314         {
315                 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,    // VkStructureType              sType;
316                 DE_NULL,                                                                // const void*                  pNext;
317                 (VkFenceCreateFlags)0,                                  // VkFenceCreateFlags   flags;
318         };
319         const Unique<VkFence> fence(createFence(vk, device, &fenceInfo));
320
321         const VkSubmitInfo submitInfo =
322         {
323                 VK_STRUCTURE_TYPE_SUBMIT_INFO,          // VkStructureType                sType;
324                 DE_NULL,                                                        // const void*                    pNext;
325                 0u,                                                                     // uint32_t                       waitSemaphoreCount;
326                 DE_NULL,                                                        // const VkSemaphore*             pWaitSemaphores;
327                 DE_NULL,                                                        // const VkPipelineStageFlags*    pWaitDstStageMask;
328                 1u,                                                                     // uint32_t                       commandBufferCount;
329                 &commandBuffer,                                         // const VkCommandBuffer*         pCommandBuffers;
330                 0u,                                                                     // uint32_t                       signalSemaphoreCount;
331                 DE_NULL,                                                        // const VkSemaphore*             pSignalSemaphores;
332         };
333         VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
334         VK_CHECK(vk.waitForFences(device, 1u, &fence.get(), DE_TRUE, ~0ull));
335 }
336
337 void beginRenderPass (const DeviceInterface&    vk,
338                                           const VkCommandBuffer         commandBuffer,
339                                           const VkRenderPass            renderPass,
340                                           const VkFramebuffer           framebuffer,
341                                           const VkRect2D&                       renderArea,
342                                           const tcu::Vec4&                      clearColor)
343 {
344         const VkClearValue clearValue = makeClearValueColor(clearColor);
345
346         const VkRenderPassBeginInfo renderPassBeginInfo = {
347                 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,               // VkStructureType         sType;
348                 DE_NULL,                                                                                // const void*             pNext;
349                 renderPass,                                                                             // VkRenderPass            renderPass;
350                 framebuffer,                                                                    // VkFramebuffer           framebuffer;
351                 renderArea,                                                                             // VkRect2D                renderArea;
352                 1u,                                                                                             // uint32_t                clearValueCount;
353                 &clearValue,                                                                    // const VkClearValue*     pClearValues;
354         };
355
356         vk.cmdBeginRenderPass(commandBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
357 }
358
359 void beginRenderPassWithRasterizationDisabled (const DeviceInterface&   vk,
360                                                                                            const VkCommandBuffer        commandBuffer,
361                                                                                            const VkRenderPass           renderPass,
362                                                                                            const VkFramebuffer          framebuffer)
363 {
364         const VkRect2D renderArea = {{ 0, 0 }, { 0, 0 }};
365
366         const VkRenderPassBeginInfo renderPassBeginInfo = {
367                 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,               // VkStructureType         sType;
368                 DE_NULL,                                                                                // const void*             pNext;
369                 renderPass,                                                                             // VkRenderPass            renderPass;
370                 framebuffer,                                                                    // VkFramebuffer           framebuffer;
371                 renderArea,                                                                             // VkRect2D                renderArea;
372                 0u,                                                                                             // uint32_t                clearValueCount;
373                 DE_NULL,                                                                                // const VkClearValue*     pClearValues;
374         };
375
376         vk.cmdBeginRenderPass(commandBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
377 }
378
379 void endRenderPass (const DeviceInterface&      vk,
380                                         const VkCommandBuffer   commandBuffer)
381 {
382         vk.cmdEndRenderPass(commandBuffer);
383 }
384
385 Move<VkRenderPass> makeRenderPass (const DeviceInterface&       vk,
386                                                                    const VkDevice                       device,
387                                                                    const VkFormat                       colorFormat)
388 {
389         const VkAttachmentDescription colorAttachmentDescription =
390         {
391                 (VkAttachmentDescriptionFlags)0,                                        // VkAttachmentDescriptionFlags         flags;
392                 colorFormat,                                                                            // VkFormat                                                     format;
393                 VK_SAMPLE_COUNT_1_BIT,                                                          // VkSampleCountFlagBits                        samples;
394                 VK_ATTACHMENT_LOAD_OP_CLEAR,                                            // VkAttachmentLoadOp                           loadOp;
395                 VK_ATTACHMENT_STORE_OP_STORE,                                           // VkAttachmentStoreOp                          storeOp;
396                 VK_ATTACHMENT_LOAD_OP_DONT_CARE,                                        // VkAttachmentLoadOp                           stencilLoadOp;
397                 VK_ATTACHMENT_STORE_OP_DONT_CARE,                                       // VkAttachmentStoreOp                          stencilStoreOp;
398                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,                       // VkImageLayout                                        initialLayout;
399                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL                        // VkImageLayout                                        finalLayout;
400         };
401
402         const VkAttachmentReference colorAttachmentReference =
403         {
404                 0u,                                                                                                     // deUint32                     attachment;
405                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL                        // VkImageLayout        layout;
406         };
407
408         const VkAttachmentReference depthAttachmentReference =
409         {
410                 VK_ATTACHMENT_UNUSED,                                                           // deUint32                     attachment;
411                 VK_IMAGE_LAYOUT_UNDEFINED                                                       // VkImageLayout        layout;
412         };
413
414         const VkSubpassDescription subpassDescription =
415         {
416                 (VkSubpassDescriptionFlags)0,                                           // VkSubpassDescriptionFlags            flags;
417                 VK_PIPELINE_BIND_POINT_GRAPHICS,                                        // VkPipelineBindPoint                          pipelineBindPoint;
418                 0u,                                                                                                     // deUint32                                                     inputAttachmentCount;
419                 DE_NULL,                                                                                        // const VkAttachmentReference*         pInputAttachments;
420                 1u,                                                                                                     // deUint32                                                     colorAttachmentCount;
421                 &colorAttachmentReference,                                                      // const VkAttachmentReference*         pColorAttachments;
422                 DE_NULL,                                                                                        // const VkAttachmentReference*         pResolveAttachments;
423                 &depthAttachmentReference,                                                      // const VkAttachmentReference*         pDepthStencilAttachment;
424                 0u,                                                                                                     // deUint32                                                     preserveAttachmentCount;
425                 DE_NULL                                                                                         // const deUint32*                                      pPreserveAttachments;
426         };
427
428         const VkRenderPassCreateInfo renderPassInfo =
429         {
430                 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,                      // VkStructureType                                      sType;
431                 DE_NULL,                                                                                        // const void*                                          pNext;
432                 (VkRenderPassCreateFlags)0,                                                     // VkRenderPassCreateFlags                      flags;
433                 1u,                                                                                                     // deUint32                                                     attachmentCount;
434                 &colorAttachmentDescription,                                            // const VkAttachmentDescription*       pAttachments;
435                 1u,                                                                                                     // deUint32                                                     subpassCount;
436                 &subpassDescription,                                                            // const VkSubpassDescription*          pSubpasses;
437                 0u,                                                                                                     // deUint32                                                     dependencyCount;
438                 DE_NULL                                                                                         // const VkSubpassDependency*           pDependencies;
439         };
440
441         return createRenderPass(vk, device, &renderPassInfo);
442 }
443
444 Move<VkRenderPass> makeRenderPassWithoutAttachments (const DeviceInterface&     vk,
445                                                                                                          const VkDevice                 device)
446 {
447         const VkAttachmentReference unusedAttachment =
448         {
449                 VK_ATTACHMENT_UNUSED,                                                           // deUint32                     attachment;
450                 VK_IMAGE_LAYOUT_UNDEFINED                                                       // VkImageLayout        layout;
451         };
452
453         const VkSubpassDescription subpassDescription =
454         {
455                 (VkSubpassDescriptionFlags)0,                                           // VkSubpassDescriptionFlags            flags;
456                 VK_PIPELINE_BIND_POINT_GRAPHICS,                                        // VkPipelineBindPoint                          pipelineBindPoint;
457                 0u,                                                                                                     // deUint32                                                     inputAttachmentCount;
458                 DE_NULL,                                                                                        // const VkAttachmentReference*         pInputAttachments;
459                 0u,                                                                                                     // deUint32                                                     colorAttachmentCount;
460                 DE_NULL,                                                                                        // const VkAttachmentReference*         pColorAttachments;
461                 DE_NULL,                                                                                        // const VkAttachmentReference*         pResolveAttachments;
462                 &unusedAttachment,                                                                      // const VkAttachmentReference*         pDepthStencilAttachment;
463                 0u,                                                                                                     // deUint32                                                     preserveAttachmentCount;
464                 DE_NULL                                                                                         // const deUint32*                                      pPreserveAttachments;
465         };
466
467         const VkRenderPassCreateInfo renderPassInfo =
468         {
469                 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,                      // VkStructureType                                      sType;
470                 DE_NULL,                                                                                        // const void*                                          pNext;
471                 (VkRenderPassCreateFlags)0,                                                     // VkRenderPassCreateFlags                      flags;
472                 0u,                                                                                                     // deUint32                                                     attachmentCount;
473                 DE_NULL,                                                                                        // const VkAttachmentDescription*       pAttachments;
474                 1u,                                                                                                     // deUint32                                                     subpassCount;
475                 &subpassDescription,                                                            // const VkSubpassDescription*          pSubpasses;
476                 0u,                                                                                                     // deUint32                                                     dependencyCount;
477                 DE_NULL                                                                                         // const VkSubpassDependency*           pDependencies;
478         };
479
480         return createRenderPass(vk, device, &renderPassInfo);
481 }
482
483 Move<VkFramebuffer> makeFramebuffer (const DeviceInterface&             vk,
484                                                                          const VkDevice                         device,
485                                                                          const VkRenderPass                     renderPass,
486                                                                          const VkImageView                      colorAttachment,
487                                                                          const deUint32                         width,
488                                                                          const deUint32                         height,
489                                                                          const deUint32                         layers)
490 {
491         const VkFramebufferCreateInfo framebufferInfo = {
492                 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,              // VkStructureType                             sType;
493                 DE_NULL,                                                                                // const void*                                 pNext;
494                 (VkFramebufferCreateFlags)0,                                    // VkFramebufferCreateFlags                    flags;
495                 renderPass,                                                                             // VkRenderPass                                renderPass;
496                 1u,                                                                                             // uint32_t                                    attachmentCount;
497                 &colorAttachment,                                                               // const VkImageView*                          pAttachments;
498                 width,                                                                                  // uint32_t                                    width;
499                 height,                                                                                 // uint32_t                                    height;
500                 layers,                                                                                 // uint32_t                                    layers;
501         };
502
503         return createFramebuffer(vk, device, &framebufferInfo);
504 }
505
506 Move<VkFramebuffer> makeFramebufferWithoutAttachments (const DeviceInterface&           vk,
507                                                                                                            const VkDevice                               device,
508                                                                                                            const VkRenderPass                   renderPass)
509 {
510         const VkFramebufferCreateInfo framebufferInfo = {
511                 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,              // VkStructureType                             sType;
512                 DE_NULL,                                                                                // const void*                                 pNext;
513                 (VkFramebufferCreateFlags)0,                                    // VkFramebufferCreateFlags                    flags;
514                 renderPass,                                                                             // VkRenderPass                                renderPass;
515                 0u,                                                                                             // uint32_t                                    attachmentCount;
516                 DE_NULL,                                                                                // const VkImageView*                          pAttachments;
517                 0u,                                                                                             // uint32_t                                    width;
518                 0u,                                                                                             // uint32_t                                    height;
519                 0u,                                                                                             // uint32_t                                    layers;
520         };
521
522         return createFramebuffer(vk, device, &framebufferInfo);
523 }
524
525 GraphicsPipelineBuilder& GraphicsPipelineBuilder::setShader (const DeviceInterface&                     vk,
526                                                                                                                          const VkDevice                                 device,
527                                                                                                                          const VkShaderStageFlagBits    stage,
528                                                                                                                          const ProgramBinary&                   binary,
529                                                                                                                          const VkSpecializationInfo*    specInfo)
530 {
531         VkShaderModule module;
532         switch (stage)
533         {
534                 case (VK_SHADER_STAGE_VERTEX_BIT):
535                         DE_ASSERT(m_vertexShaderModule.get() == DE_NULL);
536                         m_vertexShaderModule = createShaderModule(vk, device, binary, (VkShaderModuleCreateFlags)0);
537                         module = *m_vertexShaderModule;
538                         break;
539
540                 case (VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT):
541                         DE_ASSERT(m_tessControlShaderModule.get() == DE_NULL);
542                         m_tessControlShaderModule = createShaderModule(vk, device, binary, (VkShaderModuleCreateFlags)0);
543                         module = *m_tessControlShaderModule;
544                         break;
545
546                 case (VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT):
547                         DE_ASSERT(m_tessEvaluationShaderModule.get() == DE_NULL);
548                         m_tessEvaluationShaderModule = createShaderModule(vk, device, binary, (VkShaderModuleCreateFlags)0);
549                         module = *m_tessEvaluationShaderModule;
550                         break;
551
552                 case (VK_SHADER_STAGE_GEOMETRY_BIT):
553                         DE_ASSERT(m_geometryShaderModule.get() == DE_NULL);
554                         m_geometryShaderModule = createShaderModule(vk, device, binary, (VkShaderModuleCreateFlags)0);
555                         module = *m_geometryShaderModule;
556                         break;
557
558                 case (VK_SHADER_STAGE_FRAGMENT_BIT):
559                         DE_ASSERT(m_fragmentShaderModule.get() == DE_NULL);
560                         m_fragmentShaderModule = createShaderModule(vk, device, binary, (VkShaderModuleCreateFlags)0);
561                         module = *m_fragmentShaderModule;
562                         break;
563
564                 default:
565                         DE_FATAL("Invalid shader stage");
566                         return *this;
567         }
568
569         const VkPipelineShaderStageCreateInfo pipelineShaderStageInfo =
570         {
571                 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,    // VkStructureType                                              sType;
572                 DE_NULL,                                                                                                // const void*                                                  pNext;
573                 (VkPipelineShaderStageCreateFlags)0,                                    // VkPipelineShaderStageCreateFlags             flags;
574                 stage,                                                                                                  // VkShaderStageFlagBits                                stage;
575                 module,                                                                                                 // VkShaderModule                                               module;
576                 "main",                                                                                                 // const char*                                                  pName;
577                 specInfo,                                                                                               // const VkSpecializationInfo*                  pSpecializationInfo;
578         };
579
580         m_shaderStageFlags |= stage;
581         m_shaderStages.push_back(pipelineShaderStageInfo);
582
583         return *this;
584 }
585
586 GraphicsPipelineBuilder& GraphicsPipelineBuilder::setVertexInputSingleAttribute (const VkFormat vertexFormat, const deUint32 stride)
587 {
588         const VkVertexInputBindingDescription bindingDesc =
589         {
590                 0u,                                                                     // uint32_t                             binding;
591                 stride,                                                         // uint32_t                             stride;
592                 VK_VERTEX_INPUT_RATE_VERTEX,            // VkVertexInputRate    inputRate;
593         };
594         const VkVertexInputAttributeDescription attributeDesc =
595         {
596                 0u,                                                                     // uint32_t                     location;
597                 0u,                                                                     // uint32_t                     binding;
598                 vertexFormat,                                           // VkFormat                     format;
599                 0u,                                                                     // uint32_t                     offset;
600         };
601
602         m_vertexInputBindings.clear();
603         m_vertexInputBindings.push_back(bindingDesc);
604
605         m_vertexInputAttributes.clear();
606         m_vertexInputAttributes.push_back(attributeDesc);
607
608         return *this;
609 }
610
611 template<typename T>
612 inline const T* dataPointer (const std::vector<T>& vec)
613 {
614         return (vec.size() != 0 ? &vec[0] : DE_NULL);
615 }
616
617 Move<VkPipeline> GraphicsPipelineBuilder::build (const DeviceInterface& vk,
618                                                                                                  const VkDevice                 device,
619                                                                                                  const VkPipelineLayout pipelineLayout,
620                                                                                                  const VkRenderPass             renderPass,
621                                                                                                  PipelineCacheData&             pipelineCacheData)
622 {
623         const VkPipelineVertexInputStateCreateInfo vertexInputStateInfo =
624         {
625                 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,              // VkStructureType                             sType;
626                 DE_NULL,                                                                                                                // const void*                                 pNext;
627                 (VkPipelineVertexInputStateCreateFlags)0,                                               // VkPipelineVertexInputStateCreateFlags       flags;
628                 static_cast<deUint32>(m_vertexInputBindings.size()),                    // uint32_t                                    vertexBindingDescriptionCount;
629                 dataPointer(m_vertexInputBindings),                                                             // const VkVertexInputBindingDescription*      pVertexBindingDescriptions;
630                 static_cast<deUint32>(m_vertexInputAttributes.size()),                  // uint32_t                                    vertexAttributeDescriptionCount;
631                 dataPointer(m_vertexInputAttributes),                                                   // const VkVertexInputAttributeDescription*    pVertexAttributeDescriptions;
632         };
633
634         const VkPrimitiveTopology topology = (m_shaderStageFlags & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) ? VK_PRIMITIVE_TOPOLOGY_PATCH_LIST
635                                                                                                                                                                                                                  : m_primitiveTopology;
636         const VkPipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateInfo =
637         {
638                 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,    // VkStructureType                             sType;
639                 DE_NULL,                                                                                                                // const void*                                 pNext;
640                 (VkPipelineInputAssemblyStateCreateFlags)0,                                             // VkPipelineInputAssemblyStateCreateFlags     flags;
641                 topology,                                                                                                               // VkPrimitiveTopology                         topology;
642                 VK_FALSE,                                                                                                               // VkBool32                                    primitiveRestartEnable;
643         };
644
645         const VkPipelineTessellationStateCreateInfo pipelineTessellationStateInfo =
646         {
647                 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,              // VkStructureType                             sType;
648                 DE_NULL,                                                                                                                // const void*                                 pNext;
649                 (VkPipelineTessellationStateCreateFlags)0,                                              // VkPipelineTessellationStateCreateFlags      flags;
650                 m_patchControlPoints,                                                                                   // uint32_t                                    patchControlPoints;
651         };
652
653         const VkViewport viewport = makeViewport(
654                 0.0f, 0.0f,
655                 static_cast<float>(m_renderSize.x()), static_cast<float>(m_renderSize.y()),
656                 0.0f, 1.0f);
657
658         const VkRect2D scissor = {
659                 makeOffset2D(0, 0),
660                 makeExtent2D(m_renderSize.x(), m_renderSize.y()),
661         };
662
663         const VkPipelineViewportStateCreateInfo pipelineViewportStateInfo =
664         {
665                 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,  // VkStructureType                             sType;
666                 DE_NULL,                                                                                                // const void*                                 pNext;
667                 (VkPipelineViewportStateCreateFlags)0,                                  // VkPipelineViewportStateCreateFlags          flags;
668                 1u,                                                                                                             // uint32_t                                    viewportCount;
669                 &viewport,                                                                                              // const VkViewport*                           pViewports;
670                 1u,                                                                                                             // uint32_t                                    scissorCount;
671                 &scissor,                                                                                               // const VkRect2D*                             pScissors;
672         };
673
674         const bool isRasterizationDisabled = ((m_shaderStageFlags & VK_SHADER_STAGE_FRAGMENT_BIT) == 0);
675         const VkPipelineRasterizationStateCreateInfo pipelineRasterizationStateInfo =
676         {
677                 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,             // VkStructureType                          sType;
678                 DE_NULL,                                                                                                                // const void*                              pNext;
679                 (VkPipelineRasterizationStateCreateFlags)0,                                             // VkPipelineRasterizationStateCreateFlags  flags;
680                 VK_FALSE,                                                                                                               // VkBool32                                 depthClampEnable;
681                 isRasterizationDisabled,                                                                                // VkBool32                                 rasterizerDiscardEnable;
682                 VK_POLYGON_MODE_FILL,                                                                                   // VkPolygonMode                                                        polygonMode;
683                 m_cullModeFlags,                                                                                                // VkCullModeFlags                                                      cullMode;
684                 m_frontFace,                                                                                                    // VkFrontFace                                                          frontFace;
685                 VK_FALSE,                                                                                                               // VkBool32                                                                     depthBiasEnable;
686                 0.0f,                                                                                                                   // float                                                                        depthBiasConstantFactor;
687                 0.0f,                                                                                                                   // float                                                                        depthBiasClamp;
688                 0.0f,                                                                                                                   // float                                                                        depthBiasSlopeFactor;
689                 1.0f,                                                                                                                   // float                                                                        lineWidth;
690         };
691
692         const VkPipelineMultisampleStateCreateInfo pipelineMultisampleStateInfo =
693         {
694                 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,       // VkStructureType                                                      sType;
695                 DE_NULL,                                                                                                        // const void*                                                          pNext;
696                 (VkPipelineMultisampleStateCreateFlags)0,                                       // VkPipelineMultisampleStateCreateFlags        flags;
697                 VK_SAMPLE_COUNT_1_BIT,                                                                          // VkSampleCountFlagBits                                        rasterizationSamples;
698                 VK_FALSE,                                                                                                       // VkBool32                                                                     sampleShadingEnable;
699                 0.0f,                                                                                                           // float                                                                        minSampleShading;
700                 DE_NULL,                                                                                                        // const VkSampleMask*                                          pSampleMask;
701                 VK_FALSE,                                                                                                       // VkBool32                                                                     alphaToCoverageEnable;
702                 VK_FALSE                                                                                                        // VkBool32                                                                     alphaToOneEnable;
703         };
704
705         const VkStencilOpState stencilOpState = makeStencilOpState(
706                 VK_STENCIL_OP_KEEP,             // stencil fail
707                 VK_STENCIL_OP_KEEP,             // depth & stencil pass
708                 VK_STENCIL_OP_KEEP,             // depth only fail
709                 VK_COMPARE_OP_NEVER,    // compare op
710                 0u,                                             // compare mask
711                 0u,                                             // write mask
712                 0u);                                    // reference
713
714         const VkPipelineDepthStencilStateCreateInfo pipelineDepthStencilStateInfo =
715         {
716                 VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,     // VkStructureType                                                      sType;
717                 DE_NULL,                                                                                                        // const void*                                                          pNext;
718                 (VkPipelineDepthStencilStateCreateFlags)0,                                      // VkPipelineDepthStencilStateCreateFlags       flags;
719                 VK_FALSE,                                                                                                       // VkBool32                                                                     depthTestEnable;
720                 VK_FALSE,                                                                                                       // VkBool32                                                                     depthWriteEnable;
721                 VK_COMPARE_OP_LESS,                                                                                     // VkCompareOp                                                          depthCompareOp;
722                 VK_FALSE,                                                                                                       // VkBool32                                                                     depthBoundsTestEnable;
723                 VK_FALSE,                                                                                                       // VkBool32                                                                     stencilTestEnable;
724                 stencilOpState,                                                                                         // VkStencilOpState                                                     front;
725                 stencilOpState,                                                                                         // VkStencilOpState                                                     back;
726                 0.0f,                                                                                                           // float                                                                        minDepthBounds;
727                 1.0f,                                                                                                           // float                                                                        maxDepthBounds;
728         };
729
730         const VkColorComponentFlags colorComponentsAll = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
731         const VkPipelineColorBlendAttachmentState pipelineColorBlendAttachmentState =
732         {
733                 m_blendEnable,                                          // VkBool32                                     blendEnable;
734                 VK_BLEND_FACTOR_SRC_ALPHA,                      // VkBlendFactor                        srcColorBlendFactor;
735                 VK_BLEND_FACTOR_ONE,                            // VkBlendFactor                        dstColorBlendFactor;
736                 VK_BLEND_OP_ADD,                                        // VkBlendOp                            colorBlendOp;
737                 VK_BLEND_FACTOR_SRC_ALPHA,                      // VkBlendFactor                        srcAlphaBlendFactor;
738                 VK_BLEND_FACTOR_ONE,                            // VkBlendFactor                        dstAlphaBlendFactor;
739                 VK_BLEND_OP_ADD,                                        // VkBlendOp                            alphaBlendOp;
740                 colorComponentsAll,                                     // VkColorComponentFlags        colorWriteMask;
741         };
742
743         const VkPipelineColorBlendStateCreateInfo pipelineColorBlendStateInfo =
744         {
745                 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,       // VkStructureType                                                              sType;
746                 DE_NULL,                                                                                                        // const void*                                                                  pNext;
747                 (VkPipelineColorBlendStateCreateFlags)0,                                        // VkPipelineColorBlendStateCreateFlags                 flags;
748                 VK_FALSE,                                                                                                       // VkBool32                                                                             logicOpEnable;
749                 VK_LOGIC_OP_COPY,                                                                                       // VkLogicOp                                                                    logicOp;
750                 1u,                                                                                                                     // deUint32                                                                             attachmentCount;
751                 &pipelineColorBlendAttachmentState,                                                     // const VkPipelineColorBlendAttachmentState*   pAttachments;
752                 { 0.0f, 0.0f, 0.0f, 0.0f },                                                                     // float                                                                                blendConstants[4];
753         };
754
755         const VkGraphicsPipelineCreateInfo graphicsPipelineInfo =
756         {
757                 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,                                                // VkStructureType                                                                      sType;
758                 DE_NULL,                                                                                                                                // const void*                                                                          pNext;
759                 (VkPipelineCreateFlags)0,                                                                                               // VkPipelineCreateFlags                                                        flags;
760                 static_cast<deUint32>(m_shaderStages.size()),                                                   // deUint32                                                                                     stageCount;
761                 &m_shaderStages[0],                                                                                                             // const VkPipelineShaderStageCreateInfo*                       pStages;
762                 &vertexInputStateInfo,                                                                                                  // const VkPipelineVertexInputStateCreateInfo*          pVertexInputState;
763                 &pipelineInputAssemblyStateInfo,                                                                                // const VkPipelineInputAssemblyStateCreateInfo*        pInputAssemblyState;
764                 (m_shaderStageFlags & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT ? &pipelineTessellationStateInfo : DE_NULL), // const VkPipelineTessellationStateCreateInfo*             pTessellationState;
765                 (isRasterizationDisabled ? DE_NULL : &pipelineViewportStateInfo),               // const VkPipelineViewportStateCreateInfo*                     pViewportState;
766                 &pipelineRasterizationStateInfo,                                                                                // const VkPipelineRasterizationStateCreateInfo*        pRasterizationState;
767                 (isRasterizationDisabled ? DE_NULL : &pipelineMultisampleStateInfo),    // const VkPipelineMultisampleStateCreateInfo*          pMultisampleState;
768                 (isRasterizationDisabled ? DE_NULL : &pipelineDepthStencilStateInfo),   // const VkPipelineDepthStencilStateCreateInfo*         pDepthStencilState;
769                 (isRasterizationDisabled ? DE_NULL : &pipelineColorBlendStateInfo),             // const VkPipelineColorBlendStateCreateInfo*           pColorBlendState;
770                 DE_NULL,                                                                                                                                // const VkPipelineDynamicStateCreateInfo*                      pDynamicState;
771                 pipelineLayout,                                                                                                                 // VkPipelineLayout                                                                     layout;
772                 renderPass,                                                                                                                             // VkRenderPass                                                                         renderPass;
773                 0u,                                                                                                                                             // deUint32                                                                                     subpass;
774                 DE_NULL,                                                                                                                                // VkPipeline                                                                           basePipelineHandle;
775                 0,                                                                                                                                              // deInt32                                                                                      basePipelineIndex;
776         };
777
778         {
779                 const vk::Unique<vk::VkPipelineCache>   pipelineCache   (pipelineCacheData.createPipelineCache(vk, device));
780                 vk::Move<vk::VkPipeline>                                pipeline                (createGraphicsPipeline(vk, device, *pipelineCache, &graphicsPipelineInfo));
781
782                 // Refresh data from cache
783                 pipelineCacheData.setFromPipelineCache(vk, device, *pipelineCache);
784
785                 return pipeline;
786         }
787 }
788
789 void requireFeatures (const InstanceInterface& vki, const VkPhysicalDevice physDevice, const FeatureFlags flags)
790 {
791         const VkPhysicalDeviceFeatures features = getPhysicalDeviceFeatures(vki, physDevice);
792
793         if (((flags & FEATURE_TESSELLATION_SHADER) != 0) && !features.tessellationShader)
794                 throw tcu::NotSupportedError("Tessellation shader not supported");
795
796         if (((flags & FEATURE_GEOMETRY_SHADER) != 0) && !features.geometryShader)
797                 throw tcu::NotSupportedError("Geometry shader not supported");
798
799         if (((flags & FEATURE_SHADER_FLOAT_64) != 0) && !features.shaderFloat64)
800                 throw tcu::NotSupportedError("Double-precision floats not supported");
801
802         if (((flags & FEATURE_VERTEX_PIPELINE_STORES_AND_ATOMICS) != 0) && !features.vertexPipelineStoresAndAtomics)
803                 throw tcu::NotSupportedError("SSBO and image writes not supported in vertex pipeline");
804
805         if (((flags & FEATURE_FRAGMENT_STORES_AND_ATOMICS) != 0) && !features.fragmentStoresAndAtomics)
806                 throw tcu::NotSupportedError("SSBO and image writes not supported in fragment shader");
807
808         if (((flags & FEATURE_SHADER_TESSELLATION_AND_GEOMETRY_POINT_SIZE) != 0) && !features.shaderTessellationAndGeometryPointSize)
809                 throw tcu::NotSupportedError("Tessellation and geometry shaders don't support PointSize built-in");
810
811         if (((flags & FEATURE_SHADER_STORAGE_IMAGE_EXTENDED_FORMATS) != 0) && !features.shaderStorageImageExtendedFormats)
812                 throw tcu::NotSupportedError("Storage image extended formats not supported");
813 }
814
815 std::string getResourceName (const ResourceDescription& resource)
816 {
817         std::ostringstream str;
818
819         if (resource.type == RESOURCE_TYPE_BUFFER)
820                 str << "buffer_" << resource.size.x();
821         else if (resource.type == RESOURCE_TYPE_IMAGE)
822         {
823                 str << "image_" << resource.size.x()
824                                                 << (resource.size.y() > 0 ? "x" + de::toString(resource.size.y()) : "")
825                                                 << (resource.size.z() > 0 ? "x" + de::toString(resource.size.z()) : "")
826                         << "_" << de::toLower(getFormatName(resource.imageFormat)).substr(10);
827         }
828         else if (isIndirectBuffer(resource.type))
829                 str << "indirect_buffer";
830         else
831                 DE_ASSERT(0);
832
833         return str.str();
834 }
835
836 bool isIndirectBuffer (const ResourceType type)
837 {
838         switch (type)
839         {
840                 case RESOURCE_TYPE_INDIRECT_BUFFER_DRAW:
841                 case RESOURCE_TYPE_INDIRECT_BUFFER_DRAW_INDEXED:
842                 case RESOURCE_TYPE_INDIRECT_BUFFER_DISPATCH:
843                         return true;
844
845                 default:
846                         return false;
847         }
848 }
849
850 PipelineCacheData::PipelineCacheData (void)
851 {
852 }
853
854 PipelineCacheData::~PipelineCacheData (void)
855 {
856 }
857
858 vk::Move<VkPipelineCache> PipelineCacheData::createPipelineCache (const vk::DeviceInterface& vk, const vk::VkDevice device) const
859 {
860         const de::ScopedLock                                            dataLock        (m_lock);
861         const struct vk::VkPipelineCacheCreateInfo      params  =
862         {
863                 vk::VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO,
864                 DE_NULL,
865                 (vk::VkPipelineCacheCreateFlags)0,
866                 (deUintptr)m_data.size(),
867                 (m_data.empty() ? DE_NULL : &m_data[0])
868         };
869
870         return vk::createPipelineCache(vk, device, &params);
871 }
872
873 void PipelineCacheData::setFromPipelineCache (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkPipelineCache pipelineCache)
874 {
875         const de::ScopedLock            dataLock                (m_lock);
876         deUintptr                                       dataSize                = 0;
877
878         VK_CHECK(vk.getPipelineCacheData(device, pipelineCache, &dataSize, DE_NULL));
879
880         m_data.resize(dataSize);
881
882         if (dataSize > 0)
883                 VK_CHECK(vk.getPipelineCacheData(device, pipelineCache, &dataSize, &m_data[0]));
884 }
885
886 } // synchronization
887 } // vkt