1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2016 The Khronos Group Inc.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief Synchronization tests utilities
22 *//*--------------------------------------------------------------------*/
24 #include "vktSynchronizationUtil.hpp"
25 #include "vkTypeUtil.hpp"
26 #include "deStringUtil.hpp"
30 namespace synchronization
34 VkBufferCreateInfo makeBufferCreateInfo (const VkDeviceSize bufferSize,
35 const VkBufferUsageFlags usage)
37 const VkBufferCreateInfo bufferCreateInfo =
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;
48 return bufferCreateInfo;
51 VkMemoryBarrier makeMemoryBarrier (const VkAccessFlags srcAccessMask,
52 const VkAccessFlags dstAccessMask)
54 const VkMemoryBarrier barrier =
56 VK_STRUCTURE_TYPE_MEMORY_BARRIER, // VkStructureType sType;
57 DE_NULL, // const void* pNext;
58 srcAccessMask, // VkAccessFlags srcAccessMask;
59 dstAccessMask, // VkAccessFlags dstAccessMask;
64 VkBufferMemoryBarrier makeBufferMemoryBarrier (const VkAccessFlags srcAccessMask,
65 const VkAccessFlags dstAccessMask,
66 const VkBuffer buffer,
67 const VkDeviceSize offset,
68 const VkDeviceSize bufferSizeBytes)
70 const VkBufferMemoryBarrier barrier =
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;
85 VkImageMemoryBarrier makeImageMemoryBarrier (const VkAccessFlags srcAccessMask,
86 const VkAccessFlags dstAccessMask,
87 const VkImageLayout oldLayout,
88 const VkImageLayout newLayout,
90 const VkImageSubresourceRange subresourceRange)
92 const VkImageMemoryBarrier barrier =
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;
108 Move<VkCommandPool> makeCommandPool (const DeviceInterface& vk, const VkDevice device, const deUint32 queueFamilyIndex)
110 const VkCommandPoolCreateInfo info =
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;
117 return createCommandPool(vk, device, &info);
120 Move<VkCommandBuffer> makeCommandBuffer (const DeviceInterface& vk, const VkDevice device, const VkCommandPool commandPool)
122 const VkCommandBufferAllocateInfo info =
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;
130 return allocateCommandBuffer(vk, device, &info);
133 Move<VkDescriptorSet> makeDescriptorSet (const DeviceInterface& vk,
134 const VkDevice device,
135 const VkDescriptorPool descriptorPool,
136 const VkDescriptorSetLayout setLayout)
138 const VkDescriptorSetAllocateInfo info =
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;
146 return allocateDescriptorSet(vk, device, &info);
149 Move<VkPipelineLayout> makePipelineLayout (const DeviceInterface& vk,
150 const VkDevice device,
151 const VkDescriptorSetLayout descriptorSetLayout)
153 const VkPipelineLayoutCreateInfo info =
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;
163 return createPipelineLayout(vk, device, &info);
166 Move<VkPipelineLayout> makePipelineLayoutWithoutDescriptors (const DeviceInterface& vk,
167 const VkDevice device)
169 const VkPipelineLayoutCreateInfo info =
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;
179 return createPipelineLayout(vk, device, &info);
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)
189 const VkPipelineShaderStageCreateInfo shaderStageInfo =
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;
199 const VkComputePipelineCreateInfo pipelineInfo =
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;
211 const vk::Unique<vk::VkPipelineCache> pipelineCache (pipelineCacheData.createPipelineCache(vk, device));
212 vk::Move<vk::VkPipeline> pipeline (createComputePipeline(vk, device, *pipelineCache, &pipelineInfo));
214 // Refresh data from cache
215 pipelineCacheData.setFromPipelineCache(vk, device, *pipelineCache);
221 VkImageCreateInfo makeImageCreateInfo (const VkImageType imageType, const VkExtent3D& extent, const VkFormat format, const VkImageUsageFlags usage)
223 const VkImageCreateInfo imageInfo =
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;
244 Move<VkImageView> makeImageView (const DeviceInterface& vk,
245 const VkDevice device,
247 const VkImageViewType viewType,
248 const VkFormat format,
249 const VkImageSubresourceRange subresourceRange)
251 const VkImageViewCreateInfo imageViewParams =
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;
262 return createImageView(vk, device, &imageViewParams);
265 VkBufferImageCopy makeBufferImageCopy (const VkImageSubresourceLayers subresourceLayers,
266 const VkExtent3D extent)
268 const VkBufferImageCopy copyParams =
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;
280 Move<VkEvent> makeEvent (const DeviceInterface& vk, const VkDevice device)
282 const VkEventCreateInfo eventParams =
284 VK_STRUCTURE_TYPE_EVENT_CREATE_INFO, // VkStructureType sType;
285 DE_NULL, // const void* pNext;
286 (VkEventCreateFlags)0, // VkEventCreateFlags flags;
288 return createEvent(vk, device, &eventParams);
291 void beginCommandBuffer (const DeviceInterface& vk, const VkCommandBuffer commandBuffer)
293 const VkCommandBufferBeginInfo info =
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;
300 VK_CHECK(vk.beginCommandBuffer(commandBuffer, &info));
303 void endCommandBuffer (const DeviceInterface& vk, const VkCommandBuffer commandBuffer)
305 VK_CHECK(vk.endCommandBuffer(commandBuffer));
308 void submitCommandsAndWait (const DeviceInterface& vk,
309 const VkDevice device,
311 const VkCommandBuffer commandBuffer)
313 const VkFenceCreateInfo fenceInfo =
315 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, // VkStructureType sType;
316 DE_NULL, // const void* pNext;
317 (VkFenceCreateFlags)0, // VkFenceCreateFlags flags;
319 const Unique<VkFence> fence(createFence(vk, device, &fenceInfo));
321 const VkSubmitInfo submitInfo =
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;
333 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
334 VK_CHECK(vk.waitForFences(device, 1u, &fence.get(), DE_TRUE, ~0ull));
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)
344 const VkClearValue clearValue = makeClearValueColor(clearColor);
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;
356 vk.cmdBeginRenderPass(commandBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
359 void beginRenderPassWithRasterizationDisabled (const DeviceInterface& vk,
360 const VkCommandBuffer commandBuffer,
361 const VkRenderPass renderPass,
362 const VkFramebuffer framebuffer)
364 const VkRect2D renderArea = {{ 0, 0 }, { 0, 0 }};
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;
376 vk.cmdBeginRenderPass(commandBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
379 void endRenderPass (const DeviceInterface& vk,
380 const VkCommandBuffer commandBuffer)
382 vk.cmdEndRenderPass(commandBuffer);
385 Move<VkRenderPass> makeRenderPass (const DeviceInterface& vk,
386 const VkDevice device,
387 const VkFormat colorFormat)
389 const VkAttachmentDescription colorAttachmentDescription =
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;
402 const VkAttachmentReference colorAttachmentReference =
404 0u, // deUint32 attachment;
405 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout layout;
408 const VkAttachmentReference depthAttachmentReference =
410 VK_ATTACHMENT_UNUSED, // deUint32 attachment;
411 VK_IMAGE_LAYOUT_UNDEFINED // VkImageLayout layout;
414 const VkSubpassDescription subpassDescription =
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;
428 const VkRenderPassCreateInfo renderPassInfo =
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;
441 return createRenderPass(vk, device, &renderPassInfo);
444 Move<VkRenderPass> makeRenderPassWithoutAttachments (const DeviceInterface& vk,
445 const VkDevice device)
447 const VkAttachmentReference unusedAttachment =
449 VK_ATTACHMENT_UNUSED, // deUint32 attachment;
450 VK_IMAGE_LAYOUT_UNDEFINED // VkImageLayout layout;
453 const VkSubpassDescription subpassDescription =
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;
467 const VkRenderPassCreateInfo renderPassInfo =
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;
480 return createRenderPass(vk, device, &renderPassInfo);
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)
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;
503 return createFramebuffer(vk, device, &framebufferInfo);
506 Move<VkFramebuffer> makeFramebufferWithoutAttachments (const DeviceInterface& vk,
507 const VkDevice device,
508 const VkRenderPass renderPass)
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;
522 return createFramebuffer(vk, device, &framebufferInfo);
525 GraphicsPipelineBuilder& GraphicsPipelineBuilder::setShader (const DeviceInterface& vk,
526 const VkDevice device,
527 const VkShaderStageFlagBits stage,
528 const ProgramBinary& binary,
529 const VkSpecializationInfo* specInfo)
531 VkShaderModule module;
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;
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;
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;
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;
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;
565 DE_FATAL("Invalid shader stage");
569 const VkPipelineShaderStageCreateInfo pipelineShaderStageInfo =
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;
580 m_shaderStageFlags |= stage;
581 m_shaderStages.push_back(pipelineShaderStageInfo);
586 GraphicsPipelineBuilder& GraphicsPipelineBuilder::setVertexInputSingleAttribute (const VkFormat vertexFormat, const deUint32 stride)
588 const VkVertexInputBindingDescription bindingDesc =
590 0u, // uint32_t binding;
591 stride, // uint32_t stride;
592 VK_VERTEX_INPUT_RATE_VERTEX, // VkVertexInputRate inputRate;
594 const VkVertexInputAttributeDescription attributeDesc =
596 0u, // uint32_t location;
597 0u, // uint32_t binding;
598 vertexFormat, // VkFormat format;
599 0u, // uint32_t offset;
602 m_vertexInputBindings.clear();
603 m_vertexInputBindings.push_back(bindingDesc);
605 m_vertexInputAttributes.clear();
606 m_vertexInputAttributes.push_back(attributeDesc);
612 inline const T* dataPointer (const std::vector<T>& vec)
614 return (vec.size() != 0 ? &vec[0] : DE_NULL);
617 Move<VkPipeline> GraphicsPipelineBuilder::build (const DeviceInterface& vk,
618 const VkDevice device,
619 const VkPipelineLayout pipelineLayout,
620 const VkRenderPass renderPass,
621 PipelineCacheData& pipelineCacheData)
623 const VkPipelineVertexInputStateCreateInfo vertexInputStateInfo =
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;
634 const VkPrimitiveTopology topology = (m_shaderStageFlags & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) ? VK_PRIMITIVE_TOPOLOGY_PATCH_LIST
635 : m_primitiveTopology;
636 const VkPipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateInfo =
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;
645 const VkPipelineTessellationStateCreateInfo pipelineTessellationStateInfo =
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;
653 const VkViewport viewport = makeViewport(
655 static_cast<float>(m_renderSize.x()), static_cast<float>(m_renderSize.y()),
658 const VkRect2D scissor = {
660 makeExtent2D(m_renderSize.x(), m_renderSize.y()),
663 const VkPipelineViewportStateCreateInfo pipelineViewportStateInfo =
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;
674 const bool isRasterizationDisabled = ((m_shaderStageFlags & VK_SHADER_STAGE_FRAGMENT_BIT) == 0);
675 const VkPipelineRasterizationStateCreateInfo pipelineRasterizationStateInfo =
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;
692 const VkPipelineMultisampleStateCreateInfo pipelineMultisampleStateInfo =
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;
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
714 const VkPipelineDepthStencilStateCreateInfo pipelineDepthStencilStateInfo =
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;
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 =
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;
743 const VkPipelineColorBlendStateCreateInfo pipelineColorBlendStateInfo =
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];
755 const VkGraphicsPipelineCreateInfo graphicsPipelineInfo =
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;
779 const vk::Unique<vk::VkPipelineCache> pipelineCache (pipelineCacheData.createPipelineCache(vk, device));
780 vk::Move<vk::VkPipeline> pipeline (createGraphicsPipeline(vk, device, *pipelineCache, &graphicsPipelineInfo));
782 // Refresh data from cache
783 pipelineCacheData.setFromPipelineCache(vk, device, *pipelineCache);
789 void requireFeatures (const InstanceInterface& vki, const VkPhysicalDevice physDevice, const FeatureFlags flags)
791 const VkPhysicalDeviceFeatures features = getPhysicalDeviceFeatures(vki, physDevice);
793 if (((flags & FEATURE_TESSELLATION_SHADER) != 0) && !features.tessellationShader)
794 throw tcu::NotSupportedError("Tessellation shader not supported");
796 if (((flags & FEATURE_GEOMETRY_SHADER) != 0) && !features.geometryShader)
797 throw tcu::NotSupportedError("Geometry shader not supported");
799 if (((flags & FEATURE_SHADER_FLOAT_64) != 0) && !features.shaderFloat64)
800 throw tcu::NotSupportedError("Double-precision floats not supported");
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");
805 if (((flags & FEATURE_FRAGMENT_STORES_AND_ATOMICS) != 0) && !features.fragmentStoresAndAtomics)
806 throw tcu::NotSupportedError("SSBO and image writes not supported in fragment shader");
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");
811 if (((flags & FEATURE_SHADER_STORAGE_IMAGE_EXTENDED_FORMATS) != 0) && !features.shaderStorageImageExtendedFormats)
812 throw tcu::NotSupportedError("Storage image extended formats not supported");
815 std::string getResourceName (const ResourceDescription& resource)
817 std::ostringstream str;
819 if (resource.type == RESOURCE_TYPE_BUFFER)
820 str << "buffer_" << resource.size.x();
821 else if (resource.type == RESOURCE_TYPE_IMAGE)
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);
828 else if (isIndirectBuffer(resource.type))
829 str << "indirect_buffer";
836 bool isIndirectBuffer (const ResourceType type)
840 case RESOURCE_TYPE_INDIRECT_BUFFER_DRAW:
841 case RESOURCE_TYPE_INDIRECT_BUFFER_DRAW_INDEXED:
842 case RESOURCE_TYPE_INDIRECT_BUFFER_DISPATCH:
850 PipelineCacheData::PipelineCacheData (void)
854 PipelineCacheData::~PipelineCacheData (void)
858 vk::Move<VkPipelineCache> PipelineCacheData::createPipelineCache (const vk::DeviceInterface& vk, const vk::VkDevice device) const
860 const de::ScopedLock dataLock (m_lock);
861 const struct vk::VkPipelineCacheCreateInfo params =
863 vk::VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO,
865 (vk::VkPipelineCacheCreateFlags)0,
866 (deUintptr)m_data.size(),
867 (m_data.empty() ? DE_NULL : &m_data[0])
870 return vk::createPipelineCache(vk, device, ¶ms);
873 void PipelineCacheData::setFromPipelineCache (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkPipelineCache pipelineCache)
875 const de::ScopedLock dataLock (m_lock);
876 deUintptr dataSize = 0;
878 VK_CHECK(vk.getPipelineCacheData(device, pipelineCache, &dataSize, DE_NULL));
880 m_data.resize(dataSize);
883 VK_CHECK(vk.getPipelineCacheData(device, pipelineCache, &dataSize, &m_data[0]));