1 /*-------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015 Google 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 RenderPass tests
22 *//*--------------------------------------------------------------------*/
24 #include "vktRenderPassTests.hpp"
25 #include "vktRenderPassTestsUtil.hpp"
26 #include "vktRenderPassGroupParams.hpp"
27 #include "vktRenderPassMultisampleTests.hpp"
28 #include "vktRenderPassMultisampleResolveTests.hpp"
29 #include "vktRenderPassSampleReadTests.hpp"
30 #ifndef CTS_USES_VULKANSC
31 #include "vktRenderPassSparseRenderTargetTests.hpp"
32 #endif // CTS_USES_VULKANSC
33 #include "vktRenderPassSubpassDependencyTests.hpp"
34 #include "vktRenderPassUnusedAttachmentTests.hpp"
35 #include "vktRenderPassUnusedClearAttachmentTests.hpp"
36 #include "vktRenderPassDepthStencilResolveTests.hpp"
37 #include "vktRenderPassUnusedAttachmentSparseFillingTests.hpp"
38 #include "vktRenderPassFragmentDensityMapTests.hpp"
39 #include "vktRenderPassMultipleSubpassesMultipleCommandBuffersTests.hpp"
40 #ifndef CTS_USES_VULKANSC
41 #include "vktRenderPassLoadStoreOpNoneTests.hpp"
42 #include "vktDynamicRenderingTests.hpp"
43 #endif // CTS_USES_VULKANSC
44 #include "vktRenderPassDepthStencilWriteConditionsTests.hpp"
45 #include "vktRenderPassSubpassMergeFeedbackTests.hpp"
46 #include "vktDynamicRenderingRandomTests.hpp"
48 #include "vktTestCaseUtil.hpp"
49 #include "vktTestGroupUtil.hpp"
52 #include "vkDeviceUtil.hpp"
53 #include "vkImageUtil.hpp"
54 #include "vkMemUtil.hpp"
55 #include "vkPlatform.hpp"
56 #include "vkPrograms.hpp"
57 #include "vkQueryUtil.hpp"
59 #include "vkRefUtil.hpp"
60 #include "vkStrUtil.hpp"
61 #include "vkTypeUtil.hpp"
62 #include "vkCmdUtil.hpp"
63 #include "vkObjUtil.hpp"
65 #include "tcuFloat.hpp"
66 #include "tcuFormatUtil.hpp"
67 #include "tcuMaybe.hpp"
68 #include "tcuResultCollector.hpp"
69 #include "tcuTestLog.hpp"
70 #include "tcuTextureUtil.hpp"
71 #include "tcuVectorUtil.hpp"
73 #include "deRandom.hpp"
74 #include "deSTLUtil.hpp"
75 #include "deSharedPtr.hpp"
76 #include "deStringUtil.hpp"
77 #include "deUniquePtr.hpp"
98 using tcu::ConstPixelBufferAccess;
99 using tcu::PixelBufferAccess;
114 using namespace renderpass;
116 typedef vector<deUint8> DepthValuesArray;
118 static const deUint8 DEPTH_VALUES[] = { 0u, 255u, 1u };
122 ALLOCATION_KIND_SUBALLOCATED,
123 ALLOCATION_KIND_DEDICATED,
126 struct TestConfigExternal
128 TestConfigExternal (AllocationKind allocationKind_,
129 const SharedGroupParams groupParams_)
130 : allocationKind (allocationKind_)
131 , groupParams (groupParams_)
135 AllocationKind allocationKind;
136 const SharedGroupParams groupParams;
139 de::MovePtr<Allocation> allocateBuffer (const InstanceInterface& vki,
140 const DeviceInterface& vkd,
141 const VkPhysicalDevice& physDevice,
142 const VkDevice device,
143 const VkBuffer& buffer,
144 const MemoryRequirement requirement,
145 Allocator& allocator,
146 AllocationKind allocationKind)
148 switch (allocationKind)
150 case ALLOCATION_KIND_SUBALLOCATED:
152 const VkMemoryRequirements memoryRequirements = getBufferMemoryRequirements(vkd, device, buffer);
154 return allocator.allocate(memoryRequirements, requirement);
157 case ALLOCATION_KIND_DEDICATED:
159 return allocateDedicated(vki, vkd, physDevice, device, buffer, requirement);
164 TCU_THROW(InternalError, "Invalid allocation kind");
169 de::MovePtr<Allocation> allocateImage (const InstanceInterface& vki,
170 const DeviceInterface& vkd,
171 const VkPhysicalDevice& physDevice,
172 const VkDevice device,
173 const VkImage& image,
174 const MemoryRequirement requirement,
175 Allocator& allocator,
176 AllocationKind allocationKind)
178 switch (allocationKind)
180 case ALLOCATION_KIND_SUBALLOCATED:
182 const VkMemoryRequirements memoryRequirements = getImageMemoryRequirements(vkd, device, image);
184 return allocator.allocate(memoryRequirements, requirement);
187 case ALLOCATION_KIND_DEDICATED:
189 return allocateDedicated(vki, vkd, physDevice, device, image, requirement);
194 TCU_THROW(InternalError, "Invalid allocation kind");
207 const char* boolOpToString (BoolOp op)
224 DE_FATAL("Unknown boolean operation.");
229 bool performBoolOp (BoolOp op, bool a, bool b)
246 DE_FATAL("Unknown boolean operation.");
251 BoolOp boolOpFromIndex (size_t index)
261 return ops[index % DE_LENGTH_OF_ARRAY(ops)];
264 static float requiredDepthEpsilon(VkFormat format)
266 // Possible precision loss in the unorm depth pipeline means that we need to check depths
267 // that go in and back out of the depth buffer with an epsilon rather than an exact match
268 deUint32 unormBits = 0;
272 case VK_FORMAT_D16_UNORM:
275 case VK_FORMAT_X8_D24_UNORM_PACK32:
276 case VK_FORMAT_D24_UNORM_S8_UINT:
279 case VK_FORMAT_D32_SFLOAT:
280 case VK_FORMAT_D32_SFLOAT_S8_UINT:
287 return 1.0f / (float)((1 << unormBits) - 1);
289 return 0.0f; // Require exact match
292 static bool depthsEqual(float a, float b, float epsilon)
294 return fabs(a - b) <= epsilon;
297 Move<VkFramebuffer> createFramebuffer (const DeviceInterface& vk,
299 VkFramebufferCreateFlags pCreateInfo_flags,
300 VkRenderPass pCreateInfo_renderPass,
301 deUint32 pCreateInfo_attachmentCount,
302 const VkImageView* pCreateInfo_pAttachments,
303 deUint32 pCreateInfo_width,
304 deUint32 pCreateInfo_height,
305 deUint32 pCreateInfo_layers)
307 const VkFramebufferCreateInfo pCreateInfo =
309 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
312 pCreateInfo_renderPass,
313 pCreateInfo_attachmentCount,
314 pCreateInfo_pAttachments,
319 return createFramebuffer(vk, device, &pCreateInfo);
322 Move<VkImage> createImage (const DeviceInterface& vk,
324 VkImageCreateFlags pCreateInfo_flags,
325 VkImageType pCreateInfo_imageType,
326 VkFormat pCreateInfo_format,
327 VkExtent3D pCreateInfo_extent,
328 deUint32 pCreateInfo_mipLevels,
329 deUint32 pCreateInfo_arrayLayers,
330 VkSampleCountFlagBits pCreateInfo_samples,
331 VkImageTiling pCreateInfo_tiling,
332 VkImageUsageFlags pCreateInfo_usage,
333 VkSharingMode pCreateInfo_sharingMode,
334 deUint32 pCreateInfo_queueFamilyCount,
335 const deUint32* pCreateInfo_pQueueFamilyIndices,
336 VkImageLayout pCreateInfo_initialLayout)
338 const VkImageCreateInfo pCreateInfo =
340 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
343 pCreateInfo_imageType,
346 pCreateInfo_mipLevels,
347 pCreateInfo_arrayLayers,
351 pCreateInfo_sharingMode,
352 pCreateInfo_queueFamilyCount,
353 pCreateInfo_pQueueFamilyIndices,
354 pCreateInfo_initialLayout
356 return createImage(vk, device, &pCreateInfo);
359 void bindBufferMemory (const DeviceInterface& vk, VkDevice device, VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memOffset)
361 VK_CHECK(vk.bindBufferMemory(device, buffer, mem, memOffset));
364 void bindImageMemory (const DeviceInterface& vk, VkDevice device, VkImage image, VkDeviceMemory mem, VkDeviceSize memOffset)
366 VK_CHECK(vk.bindImageMemory(device, image, mem, memOffset));
369 Move<VkImageView> createImageView (const DeviceInterface& vk,
371 VkImageViewCreateFlags pCreateInfo_flags,
372 VkImage pCreateInfo_image,
373 VkImageViewType pCreateInfo_viewType,
374 VkFormat pCreateInfo_format,
375 VkComponentMapping pCreateInfo_components,
376 VkImageSubresourceRange pCreateInfo_subresourceRange)
378 const VkImageViewCreateInfo pCreateInfo =
380 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
384 pCreateInfo_viewType,
386 pCreateInfo_components,
387 pCreateInfo_subresourceRange,
389 return createImageView(vk, device, &pCreateInfo);
392 Move<VkBuffer> createBuffer (const DeviceInterface& vk,
394 VkBufferCreateFlags pCreateInfo_flags,
395 VkDeviceSize pCreateInfo_size,
396 VkBufferUsageFlags pCreateInfo_usage,
397 VkSharingMode pCreateInfo_sharingMode,
398 deUint32 pCreateInfo_queueFamilyCount,
399 const deUint32* pCreateInfo_pQueueFamilyIndices)
401 const VkBufferCreateInfo pCreateInfo =
403 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
408 pCreateInfo_sharingMode,
409 pCreateInfo_queueFamilyCount,
410 pCreateInfo_pQueueFamilyIndices,
412 return createBuffer(vk, device, &pCreateInfo);
415 VkRenderPassBeginInfo createRenderPassBeginInfo (VkRenderPass pRenderPassBegin_renderPass,
416 VkFramebuffer pRenderPassBegin_framebuffer,
417 VkRect2D pRenderPassBegin_renderArea,
418 deUint32 pRenderPassBegin_clearValueCount,
419 const VkClearValue* pRenderPassBegin_pAttachmentClearValues)
421 const VkRenderPassBeginInfo renderPassBeginInfo =
423 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
425 pRenderPassBegin_renderPass,
426 pRenderPassBegin_framebuffer,
427 pRenderPassBegin_renderArea,
428 pRenderPassBegin_clearValueCount,
429 pRenderPassBegin_pAttachmentClearValues,
432 return renderPassBeginInfo;
435 void queueSubmit (const DeviceInterface& vk, VkQueue queue, deUint32 cmdBufferCount, const VkCommandBuffer* pCmdBuffers, VkFence fence)
437 const VkSubmitInfo submitInfo =
439 VK_STRUCTURE_TYPE_SUBMIT_INFO,
441 0u, // waitSemaphoreCount
442 (const VkSemaphore*)DE_NULL, // pWaitSemaphores
443 (const VkPipelineStageFlags*)DE_NULL,
444 cmdBufferCount, // commandBufferCount
446 0u, // signalSemaphoreCount
447 (const VkSemaphore*)DE_NULL, // pSignalSemaphores
449 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, fence));
452 void waitForFences (const DeviceInterface& vk, VkDevice device, deUint32 fenceCount, const VkFence* pFences, VkBool32 waitAll, deUint64 timeout)
454 VK_CHECK(vk.waitForFences(device, fenceCount, pFences, waitAll, timeout));
457 VkImageAspectFlags getImageAspectFlags (VkFormat vkFormat)
459 const tcu::TextureFormat format = mapVkFormat(vkFormat);
461 DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELORDER_LAST == 22);
463 switch (format.order)
465 case tcu::TextureFormat::DS:
466 return VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
468 case tcu::TextureFormat::D:
469 return VK_IMAGE_ASPECT_DEPTH_BIT;
471 case tcu::TextureFormat::S:
472 return VK_IMAGE_ASPECT_STENCIL_BIT;
475 return VK_IMAGE_ASPECT_COLOR_BIT;
479 VkAccessFlags getAllMemoryReadFlags (void)
481 return VK_ACCESS_TRANSFER_READ_BIT
482 | VK_ACCESS_UNIFORM_READ_BIT
483 | VK_ACCESS_HOST_READ_BIT
484 | VK_ACCESS_INDEX_READ_BIT
485 | VK_ACCESS_SHADER_READ_BIT
486 | VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT
487 | VK_ACCESS_INDIRECT_COMMAND_READ_BIT
488 | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT
489 | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT
490 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
493 VkAccessFlags getAllMemoryWriteFlags (void)
495 return VK_ACCESS_TRANSFER_WRITE_BIT
496 | VK_ACCESS_HOST_WRITE_BIT
497 | VK_ACCESS_SHADER_WRITE_BIT
498 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT
499 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
502 VkAccessFlags getMemoryFlagsForLayout (const VkImageLayout layout)
506 case VK_IMAGE_LAYOUT_GENERAL: return getAllMemoryReadFlags() | getAllMemoryWriteFlags();
507 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: return VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
508 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: return VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
509 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: return VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
510 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: return VK_ACCESS_SHADER_READ_BIT;
511 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: return VK_ACCESS_TRANSFER_READ_BIT;
512 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: return VK_ACCESS_TRANSFER_WRITE_BIT;
513 case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL: return VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | VK_ACCESS_SHADER_READ_BIT;
514 case VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL: return VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | VK_ACCESS_SHADER_READ_BIT;
516 return (VkAccessFlags)0;
520 VkPipelineStageFlags getAllPipelineStageFlags (void)
522 /* All relevant flags for a pipeline containing VS+PS. */
523 return VK_PIPELINE_STAGE_TRANSFER_BIT
524 | VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT
525 | VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT
526 | VK_PIPELINE_STAGE_VERTEX_INPUT_BIT
527 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT
528 | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
529 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
530 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT
531 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
532 | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT
533 | VK_PIPELINE_STAGE_HOST_BIT;
536 class AttachmentReference
539 AttachmentReference (deUint32 attachment,
540 VkImageLayout layout,
541 VkImageAspectFlags aspectMask = static_cast<VkImageAspectFlags>(0u))
542 : m_attachment (attachment)
544 , m_aspectMask (aspectMask)
548 deUint32 getAttachment (void) const { return m_attachment; }
549 VkImageLayout getImageLayout (void) const { return m_layout; }
550 VkImageAspectFlags getAspectMask (void) const { return m_aspectMask; }
551 void setImageLayout (VkImageLayout layout) { m_layout = layout; }
554 deUint32 m_attachment;
555 VkImageLayout m_layout;
556 VkImageAspectFlags m_aspectMask;
562 Subpass (VkPipelineBindPoint pipelineBindPoint,
563 VkSubpassDescriptionFlags flags,
564 const vector<AttachmentReference>& inputAttachments,
565 const vector<AttachmentReference>& colorAttachments,
566 const vector<AttachmentReference>& resolveAttachments,
567 AttachmentReference depthStencilAttachment,
568 const vector<deUint32>& preserveAttachments,
569 bool omitBlendState = false)
570 : m_pipelineBindPoint (pipelineBindPoint)
572 , m_inputAttachments (inputAttachments)
573 , m_colorAttachments (colorAttachments)
574 , m_resolveAttachments (resolveAttachments)
575 , m_depthStencilAttachment (depthStencilAttachment)
576 , m_preserveAttachments (preserveAttachments)
577 , m_omitBlendState (omitBlendState)
581 VkPipelineBindPoint getPipelineBindPoint (void) const { return m_pipelineBindPoint; }
582 VkSubpassDescriptionFlags getFlags (void) const { return m_flags; }
583 const vector<AttachmentReference>& getInputAttachments (void) const { return m_inputAttachments; }
584 const vector<AttachmentReference>& getColorAttachments (void) const { return m_colorAttachments; }
585 const vector<AttachmentReference>& getResolveAttachments (void) const { return m_resolveAttachments; }
586 const AttachmentReference& getDepthStencilAttachment (void) const { return m_depthStencilAttachment; }
587 const vector<deUint32>& getPreserveAttachments (void) const { return m_preserveAttachments; }
588 bool getOmitBlendState (void) const { return m_omitBlendState; }
591 VkPipelineBindPoint m_pipelineBindPoint;
592 VkSubpassDescriptionFlags m_flags;
594 vector<AttachmentReference> m_inputAttachments;
595 vector<AttachmentReference> m_colorAttachments;
596 vector<AttachmentReference> m_resolveAttachments;
597 AttachmentReference m_depthStencilAttachment;
599 vector<deUint32> m_preserveAttachments;
600 bool m_omitBlendState;
603 class SubpassDependency
606 SubpassDependency (deUint32 srcPass,
609 VkPipelineStageFlags srcStageMask,
610 VkPipelineStageFlags dstStageMask,
612 VkAccessFlags srcAccessMask,
613 VkAccessFlags dstAccessMask,
615 VkDependencyFlags flags)
616 : m_srcPass (srcPass)
617 , m_dstPass (dstPass)
619 , m_srcStageMask (srcStageMask)
620 , m_dstStageMask (dstStageMask)
622 , m_srcAccessMask (srcAccessMask)
623 , m_dstAccessMask (dstAccessMask)
628 deUint32 getSrcPass (void) const { return m_srcPass; }
629 deUint32 getDstPass (void) const { return m_dstPass; }
631 VkPipelineStageFlags getSrcStageMask (void) const { return m_srcStageMask; }
632 VkPipelineStageFlags getDstStageMask (void) const { return m_dstStageMask; }
634 VkAccessFlags getSrcAccessMask (void) const { return m_srcAccessMask; }
635 VkAccessFlags getDstAccessMask (void) const { return m_dstAccessMask; }
637 VkDependencyFlags getFlags (void) const { return m_flags; }
639 void setSrcAccessMask (const VkAccessFlags& flags) { m_srcAccessMask = flags; }
640 void setDstAccessMask (const VkAccessFlags& flags) { m_dstAccessMask = flags; }
646 VkPipelineStageFlags m_srcStageMask;
647 VkPipelineStageFlags m_dstStageMask;
649 VkAccessFlags m_srcAccessMask;
650 VkAccessFlags m_dstAccessMask;
651 VkDependencyFlags m_flags;
657 Attachment (VkFormat format,
658 VkSampleCountFlagBits samples,
660 VkAttachmentLoadOp loadOp,
661 VkAttachmentStoreOp storeOp,
663 VkAttachmentLoadOp stencilLoadOp,
664 VkAttachmentStoreOp stencilStoreOp,
666 VkImageLayout initialLayout,
667 VkImageLayout finalLayout)
669 , m_samples (samples)
672 , m_storeOp (storeOp)
674 , m_stencilLoadOp (stencilLoadOp)
675 , m_stencilStoreOp (stencilStoreOp)
677 , m_initialLayout (initialLayout)
678 , m_finalLayout (finalLayout)
682 VkFormat getFormat (void) const { return m_format; }
683 VkSampleCountFlagBits getSamples (void) const { return m_samples; }
685 VkAttachmentLoadOp getLoadOp (void) const { return m_loadOp; }
686 VkAttachmentStoreOp getStoreOp (void) const { return m_storeOp; }
689 VkAttachmentLoadOp getStencilLoadOp (void) const { return m_stencilLoadOp; }
690 VkAttachmentStoreOp getStencilStoreOp (void) const { return m_stencilStoreOp; }
692 VkImageLayout getInitialLayout (void) const { return m_initialLayout; }
693 VkImageLayout getFinalLayout (void) const { return m_finalLayout; }
697 VkSampleCountFlagBits m_samples;
699 VkAttachmentLoadOp m_loadOp;
700 VkAttachmentStoreOp m_storeOp;
702 VkAttachmentLoadOp m_stencilLoadOp;
703 VkAttachmentStoreOp m_stencilStoreOp;
705 VkImageLayout m_initialLayout;
706 VkImageLayout m_finalLayout;
712 RenderPass (const vector<Attachment>& attachments,
713 const vector<Subpass>& subpasses,
714 const vector<SubpassDependency>& dependencies,
715 const vector<VkInputAttachmentAspectReference> inputAspects = vector<VkInputAttachmentAspectReference>())
716 : m_attachments (attachments)
717 , m_subpasses (subpasses)
718 , m_dependencies (dependencies)
719 , m_inputAspects (inputAspects)
723 const vector<Attachment>& getAttachments (void) const { return m_attachments; }
724 const vector<Subpass>& getSubpasses (void) const { return m_subpasses; }
725 const vector<SubpassDependency>& getDependencies (void) const { return m_dependencies; }
726 const vector<VkInputAttachmentAspectReference>& getInputAspects (void) const { return m_inputAspects; }
729 const vector<Attachment> m_attachments;
730 const vector<Subpass> m_subpasses;
731 const vector<SubpassDependency> m_dependencies;
732 const vector<VkInputAttachmentAspectReference> m_inputAspects;
739 RENDERTYPES_NONE = 0,
740 RENDERTYPES_CLEAR = (1<<1),
741 RENDERTYPES_DRAW = (1<<2)
744 enum CommandBufferTypes
746 COMMANDBUFFERTYPES_INLINE = (1<<0),
747 COMMANDBUFFERTYPES_SECONDARY = (1<<1)
752 IMAGEMEMORY_STRICT = (1<<0),
753 IMAGEMEMORY_LAZY = (1<<1)
756 TestConfig (const RenderPass& renderPass_,
757 RenderTypes renderTypes_,
758 CommandBufferTypes commandBufferTypes_,
759 ImageMemory imageMemory_,
760 const UVec2& targetSize_,
761 const UVec2& renderPos_,
762 const UVec2& renderSize_,
763 deBool useFormatCompCount_,
765 deUint32 drawStartNdx_,
766 AllocationKind allocationKind_,
767 SharedGroupParams groupParams_,
768 vector<DeviceCoreFeature> requiredFeatures_ = vector<DeviceCoreFeature>())
769 : renderPass (renderPass_)
770 , renderTypes (renderTypes_)
771 , commandBufferTypes (commandBufferTypes_)
772 , imageMemory (imageMemory_)
773 , targetSize (targetSize_)
774 , renderPos (renderPos_)
775 , renderSize (renderSize_)
776 , useFormatCompCount (useFormatCompCount_)
778 , drawStartNdx (drawStartNdx_)
779 , allocationKind (allocationKind_)
780 , groupParams (groupParams_)
781 , requiredFeatures (requiredFeatures_)
783 DepthValuesArray shuffledDepthValues (&DEPTH_VALUES[0], &DEPTH_VALUES[DE_LENGTH_OF_ARRAY(DEPTH_VALUES)]);
784 de::Random rng (seed + 1);
786 rng.shuffle(shuffledDepthValues.begin(), shuffledDepthValues.end());
788 depthValues.push_back(shuffledDepthValues[0]);
789 depthValues.push_back(shuffledDepthValues[1]);
792 RenderPass renderPass;
793 RenderTypes renderTypes;
794 CommandBufferTypes commandBufferTypes;
795 ImageMemory imageMemory;
799 deBool useFormatCompCount;
801 deUint32 drawStartNdx;
802 AllocationKind allocationKind;
803 SharedGroupParams groupParams;
804 vector<DeviceCoreFeature> requiredFeatures;
805 DepthValuesArray depthValues;
808 TestConfig::RenderTypes operator| (TestConfig::RenderTypes a, TestConfig::RenderTypes b)
810 return (TestConfig::RenderTypes)(((deUint32)a) | ((deUint32)b));
813 TestConfig::CommandBufferTypes operator| (TestConfig::CommandBufferTypes a, TestConfig::CommandBufferTypes b)
815 return (TestConfig::CommandBufferTypes)(((deUint32)a) | ((deUint32)b));
818 TestConfig::ImageMemory operator| (TestConfig::ImageMemory a, TestConfig::ImageMemory b)
820 return (TestConfig::ImageMemory)(((deUint32)a) | ((deUint32)b));
823 void checkSupport (Context& context, TestConfig config)
825 for (size_t featureNdx = 0; featureNdx < config.requiredFeatures.size(); featureNdx++)
826 context.requireDeviceCoreFeature(config.requiredFeatures[featureNdx]);
829 void logRenderPassInfo (TestLog& log,
830 const RenderPass& renderPass)
832 const bool useExternalInputAspect = !renderPass.getInputAspects().empty();
833 const tcu::ScopedLogSection section (log, "RenderPass", "RenderPass");
836 const tcu::ScopedLogSection attachmentsSection (log, "Attachments", "Attachments");
837 const vector<Attachment>& attachments = renderPass.getAttachments();
839 for (size_t attachmentNdx = 0; attachmentNdx < attachments.size(); attachmentNdx++)
841 const tcu::ScopedLogSection attachmentSection (log, "Attachment" + de::toString(attachmentNdx), "Attachment " + de::toString(attachmentNdx));
842 const Attachment& attachment = attachments[attachmentNdx];
844 log << TestLog::Message << "Format: " << attachment.getFormat() << TestLog::EndMessage;
845 log << TestLog::Message << "Samples: " << attachment.getSamples() << TestLog::EndMessage;
847 log << TestLog::Message << "LoadOp: " << attachment.getLoadOp() << TestLog::EndMessage;
848 log << TestLog::Message << "StoreOp: " << attachment.getStoreOp() << TestLog::EndMessage;
850 log << TestLog::Message << "StencilLoadOp: " << attachment.getStencilLoadOp() << TestLog::EndMessage;
851 log << TestLog::Message << "StencilStoreOp: " << attachment.getStencilStoreOp() << TestLog::EndMessage;
853 log << TestLog::Message << "InitialLayout: " << attachment.getInitialLayout() << TestLog::EndMessage;
854 log << TestLog::Message << "FinalLayout: " << attachment.getFinalLayout() << TestLog::EndMessage;
858 if (useExternalInputAspect)
860 const tcu::ScopedLogSection inputAspectSection (log, "InputAspects", "InputAspects");
862 for (size_t aspectNdx = 0; aspectNdx < renderPass.getInputAspects().size(); aspectNdx++)
864 const VkInputAttachmentAspectReference& inputAspect (renderPass.getInputAspects()[aspectNdx]);
866 log << TestLog::Message << "Subpass: " << inputAspect.subpass << TestLog::EndMessage;
867 log << TestLog::Message << "InputAttachmentIndex: " << inputAspect.inputAttachmentIndex << TestLog::EndMessage;
868 log << TestLog::Message << "AspectFlags: " << getImageAspectFlagsStr(inputAspect.aspectMask) << TestLog::EndMessage;
873 const tcu::ScopedLogSection subpassesSection (log, "Subpasses", "Subpasses");
874 const vector<Subpass>& subpasses = renderPass.getSubpasses();
876 for (size_t subpassNdx = 0; subpassNdx < subpasses.size(); subpassNdx++)
878 const tcu::ScopedLogSection subpassSection (log, "Subpass" + de::toString(subpassNdx), "Subpass " + de::toString(subpassNdx));
879 const Subpass& subpass = subpasses[subpassNdx];
881 const vector<AttachmentReference>& inputAttachments = subpass.getInputAttachments();
882 const vector<AttachmentReference>& colorAttachments = subpass.getColorAttachments();
883 const vector<AttachmentReference>& resolveAttachments = subpass.getResolveAttachments();
884 const vector<deUint32>& preserveAttachments = subpass.getPreserveAttachments();
886 if (!inputAttachments.empty())
888 const tcu::ScopedLogSection inputAttachmentsSection (log, "Inputs", "Inputs");
890 for (size_t inputNdx = 0; inputNdx < inputAttachments.size(); inputNdx++)
892 const tcu::ScopedLogSection inputAttachmentSection (log, "Input" + de::toString(inputNdx), "Input " + de::toString(inputNdx));
893 const AttachmentReference& inputAttachment = inputAttachments[inputNdx];
895 log << TestLog::Message << "Attachment: " << inputAttachment.getAttachment() << TestLog::EndMessage;
896 log << TestLog::Message << "Layout: " << inputAttachment.getImageLayout() << TestLog::EndMessage;
897 if (!useExternalInputAspect)
898 log << TestLog::Message << "AspectMask: " << inputAttachment.getAspectMask() << TestLog::EndMessage;
902 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED)
904 const tcu::ScopedLogSection depthStencilAttachmentSection (log, "DepthStencil", "DepthStencil");
905 const AttachmentReference& depthStencilAttachment = subpass.getDepthStencilAttachment();
907 log << TestLog::Message << "Attachment: " << depthStencilAttachment.getAttachment() << TestLog::EndMessage;
908 log << TestLog::Message << "Layout: " << depthStencilAttachment.getImageLayout() << TestLog::EndMessage;
911 if (!colorAttachments.empty())
913 const tcu::ScopedLogSection colorAttachmentsSection (log, "Colors", "Colors");
915 for (size_t colorNdx = 0; colorNdx < colorAttachments.size(); colorNdx++)
917 const tcu::ScopedLogSection colorAttachmentSection (log, "Color" + de::toString(colorNdx), "Color " + de::toString(colorNdx));
918 const AttachmentReference& colorAttachment = colorAttachments[colorNdx];
920 log << TestLog::Message << "Attachment: " << colorAttachment.getAttachment() << TestLog::EndMessage;
921 log << TestLog::Message << "Layout: " << colorAttachment.getImageLayout() << TestLog::EndMessage;
925 if (!resolveAttachments.empty())
927 const tcu::ScopedLogSection resolveAttachmentsSection (log, "Resolves", "Resolves");
929 for (size_t resolveNdx = 0; resolveNdx < resolveAttachments.size(); resolveNdx++)
931 const tcu::ScopedLogSection resolveAttachmentSection (log, "Resolve" + de::toString(resolveNdx), "Resolve " + de::toString(resolveNdx));
932 const AttachmentReference& resolveAttachment = resolveAttachments[resolveNdx];
934 log << TestLog::Message << "Attachment: " << resolveAttachment.getAttachment() << TestLog::EndMessage;
935 log << TestLog::Message << "Layout: " << resolveAttachment.getImageLayout() << TestLog::EndMessage;
939 if (!preserveAttachments.empty())
941 const tcu::ScopedLogSection preserveAttachmentsSection (log, "Preserves", "Preserves");
943 for (size_t preserveNdx = 0; preserveNdx < preserveAttachments.size(); preserveNdx++)
945 const tcu::ScopedLogSection preserveAttachmentSection (log, "Preserve" + de::toString(preserveNdx), "Preserve " + de::toString(preserveNdx));
946 const deUint32 preserveAttachment = preserveAttachments[preserveNdx];
948 log << TestLog::Message << "Attachment: " << preserveAttachment << TestLog::EndMessage;
955 if (!renderPass.getDependencies().empty())
957 const tcu::ScopedLogSection dependenciesSection (log, "Dependencies", "Dependencies");
959 for (size_t depNdx = 0; depNdx < renderPass.getDependencies().size(); depNdx++)
961 const tcu::ScopedLogSection dependencySection (log, "Dependency" + de::toString(depNdx), "Dependency " + de::toString(depNdx));
962 const SubpassDependency& dep = renderPass.getDependencies()[depNdx];
964 log << TestLog::Message << "Source: " << dep.getSrcPass() << TestLog::EndMessage;
965 log << TestLog::Message << "Destination: " << dep.getDstPass() << TestLog::EndMessage;
967 log << TestLog::Message << "Source Stage Mask: " << dep.getSrcStageMask() << TestLog::EndMessage;
968 log << TestLog::Message << "Destination Stage Mask: " << dep.getDstStageMask() << TestLog::EndMessage;
970 log << TestLog::Message << "Input Mask: " << dep.getDstAccessMask() << TestLog::EndMessage;
971 log << TestLog::Message << "Output Mask: " << dep.getSrcAccessMask() << TestLog::EndMessage;
972 log << TestLog::Message << "Dependency Flags: " << getDependencyFlagsStr(dep.getFlags()) << TestLog::EndMessage;
977 std::string clearColorToString (VkFormat vkFormat, VkClearColorValue value, deBool useFormatCompCount)
979 const tcu::TextureFormat format = mapVkFormat(vkFormat);
980 const tcu::TextureChannelClass channelClass = tcu::getTextureChannelClass(format.type);
981 const tcu::BVec4 channelMask = tcu::getTextureFormatChannelMask(format);
982 const deUint32 componentCount = (useFormatCompCount ? (deUint32)tcu::getNumUsedChannels(format.order) : 4);
984 std::ostringstream stream;
988 switch (channelClass)
990 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
991 for (deUint32 i = 0; i < componentCount; i++)
997 stream << value.int32[i];
1003 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1004 for (deUint32 i = 0; i < componentCount; i++)
1010 stream << value.uint32[i];
1016 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1017 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1018 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
1019 for (deUint32 i = 0; i < componentCount; i++)
1025 stream << value.float32[i];
1032 DE_FATAL("Unknown channel class");
1037 return stream.str();
1040 std::string clearValueToString (VkFormat vkFormat, VkClearValue value, deBool useFormatCompCount)
1042 const tcu::TextureFormat format = mapVkFormat(vkFormat);
1044 if (tcu::hasStencilComponent(format.order) || tcu::hasDepthComponent(format.order))
1046 std::ostringstream stream;
1050 if (tcu::hasStencilComponent(format.order))
1051 stream << "stencil: " << value.depthStencil.stencil;
1053 if (tcu::hasStencilComponent(format.order) && tcu::hasDepthComponent(format.order))
1056 if (tcu::hasDepthComponent(format.order))
1057 stream << "depth: " << value.depthStencil.depth;
1061 return stream.str();
1064 return clearColorToString(vkFormat, value.color, useFormatCompCount);
1067 VkClearColorValue randomColorClearValue (const Attachment& attachment, de::Random& rng, deBool useFormatCompCount)
1069 const float clearNan = tcu::Float32::nan().asFloat();
1070 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
1071 const tcu::TextureChannelClass channelClass = tcu::getTextureChannelClass(format.type);
1072 const tcu::BVec4 channelMask = tcu::getTextureFormatChannelMask(format);
1073 const deUint32 componentCount = (useFormatCompCount ? (deUint32)tcu::getNumUsedChannels(format.order) : 4);
1074 VkClearColorValue clearColor;
1076 switch (channelClass)
1078 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
1080 for (deUint32 ndx = 0; ndx < componentCount; ndx++)
1082 if (!channelMask[ndx])
1083 clearColor.int32[ndx] = std::numeric_limits<deInt32>::min();
1085 clearColor.uint32[ndx] = rng.getBool() ? 1u : 0u;
1090 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1092 for (deUint32 ndx = 0; ndx < componentCount; ndx++)
1094 if (!channelMask[ndx])
1095 clearColor.uint32[ndx] = std::numeric_limits<deUint32>::max();
1097 clearColor.uint32[ndx] = rng.getBool() ? 1u : 0u;
1102 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1103 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1104 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
1106 for (deUint32 ndx = 0; ndx < componentCount; ndx++)
1108 if (!channelMask[ndx])
1109 clearColor.float32[ndx] = clearNan;
1111 clearColor.float32[ndx] = rng.getBool() ? 1.0f : 0.0f;
1117 DE_FATAL("Unknown channel class");
1123 template <typename AttachmentDesc>
1124 AttachmentDesc createAttachmentDescription (const Attachment& attachment)
1126 const AttachmentDesc attachmentDescription // VkAttachmentDescription || VkAttachmentDescription2KHR
1128 // || VkStructureType sType;
1129 DE_NULL, // || const void* pNext;
1130 0u, // VkAttachmentDescriptionFlags flags; || VkAttachmentDescriptionFlags flags;
1131 attachment.getFormat(), // VkFormat format; || VkFormat format;
1132 attachment.getSamples(), // VkSampleCountFlagBits samples; || VkSampleCountFlagBits samples;
1133 attachment.getLoadOp(), // VkAttachmentLoadOp loadOp; || VkAttachmentLoadOp loadOp;
1134 attachment.getStoreOp(), // VkAttachmentStoreOp storeOp; || VkAttachmentStoreOp storeOp;
1135 attachment.getStencilLoadOp(), // VkAttachmentLoadOp stencilLoadOp; || VkAttachmentLoadOp stencilLoadOp;
1136 attachment.getStencilStoreOp(), // VkAttachmentStoreOp stencilStoreOp; || VkAttachmentStoreOp stencilStoreOp;
1137 attachment.getInitialLayout(), // VkImageLayout initialLayout; || VkImageLayout initialLayout;
1138 attachment.getFinalLayout() // VkImageLayout finalLayout; || VkImageLayout finalLayout;
1141 return attachmentDescription;
1144 template <typename AttachmentRef>
1145 AttachmentRef createAttachmentReference (const AttachmentReference& referenceInfo)
1147 const AttachmentRef reference // VkAttachmentReference || VkAttachmentReference2KHR
1149 // || VkStructureType sType;
1150 DE_NULL, // || const void* pNext;
1151 referenceInfo.getAttachment(), // deUint32 attachment; || deUint32 attachment;
1152 referenceInfo.getImageLayout(), // VkImageLayout layout; || VkImageLayout layout;
1153 referenceInfo.getAspectMask() // || VkImageAspectFlags aspectMask;
1159 template <typename SubpassDesc, typename AttachmentRef>
1160 SubpassDesc createSubpassDescription (const Subpass& subpass,
1161 vector<AttachmentRef>* attachmentReferenceLists,
1162 vector<deUint32>* preserveAttachmentReferences)
1164 vector<AttachmentRef>& inputAttachmentReferences = attachmentReferenceLists[0];
1165 vector<AttachmentRef>& colorAttachmentReferences = attachmentReferenceLists[1];
1166 vector<AttachmentRef>& resolveAttachmentReferences = attachmentReferenceLists[2];
1167 vector<AttachmentRef>& depthStencilAttachmentReferences = attachmentReferenceLists[3];
1169 for (size_t attachmentNdx = 0; attachmentNdx < subpass.getColorAttachments().size(); attachmentNdx++)
1170 colorAttachmentReferences.push_back(createAttachmentReference<AttachmentRef>(subpass.getColorAttachments()[attachmentNdx]));
1172 for (size_t attachmentNdx = 0; attachmentNdx < subpass.getInputAttachments().size(); attachmentNdx++)
1173 inputAttachmentReferences.push_back(createAttachmentReference<AttachmentRef>(subpass.getInputAttachments()[attachmentNdx]));
1175 for (size_t attachmentNdx = 0; attachmentNdx < subpass.getResolveAttachments().size(); attachmentNdx++)
1176 resolveAttachmentReferences.push_back(createAttachmentReference<AttachmentRef>(subpass.getResolveAttachments()[attachmentNdx]));
1178 depthStencilAttachmentReferences.push_back(createAttachmentReference<AttachmentRef>(subpass.getDepthStencilAttachment()));
1180 for (size_t attachmentNdx = 0; attachmentNdx < subpass.getPreserveAttachments().size(); attachmentNdx++)
1181 preserveAttachmentReferences->push_back(subpass.getPreserveAttachments()[attachmentNdx]);
1183 DE_ASSERT(resolveAttachmentReferences.empty() || colorAttachmentReferences.size() == resolveAttachmentReferences.size());
1186 const SubpassDesc subpassDescription // VkSubpassDescription || VkSubpassDescription2KHR
1188 // || VkStructureType sType;
1189 DE_NULL, // || const void* pNext;
1190 subpass.getFlags(), // VkSubpassDescriptionFlags flags; || VkSubpassDescriptionFlags flags;
1191 subpass.getPipelineBindPoint(), // VkPipelineBindPoint pipelineBindPoint; || VkPipelineBindPoint pipelineBindPoint;
1192 0u, // || deUint32 viewMask;
1193 (deUint32)inputAttachmentReferences.size(), // deUint32 inputAttachmentCount; || deUint32 inputAttachmentCount;
1194 inputAttachmentReferences.empty() ? DE_NULL : &inputAttachmentReferences[0], // const VkAttachmentReference* pInputAttachments; || const VkAttachmentReference2KHR* pInputAttachments;
1195 (deUint32)colorAttachmentReferences.size(), // deUint32 colorAttachmentCount; || deUint32 colorAttachmentCount;
1196 colorAttachmentReferences.empty() ? DE_NULL : &colorAttachmentReferences[0], // const VkAttachmentReference* pColorAttachments; || const VkAttachmentReference2KHR* pColorAttachments;
1197 resolveAttachmentReferences.empty() ? DE_NULL : &resolveAttachmentReferences[0], // const VkAttachmentReference* pResolveAttachments; || const VkAttachmentReference2KHR* pResolveAttachments;
1198 &depthStencilAttachmentReferences[0], // const VkAttachmentReference* pDepthStencilAttachment; || const VkAttachmentReference2KHR* pDepthStencilAttachment;
1199 (deUint32)preserveAttachmentReferences->size(), // deUint32 preserveAttachmentCount; || deUint32 preserveAttachmentCount;
1200 preserveAttachmentReferences->empty() ? DE_NULL : &(*preserveAttachmentReferences)[0] // const deUint32* pPreserveAttachments; || const deUint32* pPreserveAttachments;
1203 return subpassDescription;
1207 template <typename SubpassDep>
1208 SubpassDep createSubpassDependency (const SubpassDependency& dependencyInfo)
1210 const SubpassDep dependency // VkSubpassDependency || VkSubpassDependency2KHR
1212 // || VkStructureType sType;
1213 DE_NULL, // || const void* pNext;
1214 dependencyInfo.getSrcPass(), // deUint32 srcSubpass; || deUint32 srcSubpass;
1215 dependencyInfo.getDstPass(), // deUint32 dstSubpass; || deUint32 dstSubpass;
1216 dependencyInfo.getSrcStageMask(), // VkPipelineStageFlags srcStageMask; || VkPipelineStageFlags srcStageMask;
1217 dependencyInfo.getDstStageMask(), // VkPipelineStageFlags dstStageMask; || VkPipelineStageFlags dstStageMask;
1218 dependencyInfo.getSrcAccessMask(), // VkAccessFlags srcAccessMask; || VkAccessFlags srcAccessMask;
1219 dependencyInfo.getDstAccessMask(), // VkAccessFlags dstAccessMask; || VkAccessFlags dstAccessMask;
1220 dependencyInfo.getFlags(), // VkDependencyFlags dependencyFlags; || VkDependencyFlags dependencyFlags;
1221 0u // || deInt32 viewOffset;
1227 de::MovePtr<VkRenderPassInputAttachmentAspectCreateInfo> createRenderPassInputAttachmentAspectCreateInfo(const RenderPass& renderPassInfo)
1229 de::MovePtr<VkRenderPassInputAttachmentAspectCreateInfo> result (DE_NULL);
1231 if (!renderPassInfo.getInputAspects().empty())
1233 const VkRenderPassInputAttachmentAspectCreateInfo inputAspectCreateInfo =
1235 VK_STRUCTURE_TYPE_RENDER_PASS_INPUT_ATTACHMENT_ASPECT_CREATE_INFO,
1238 (deUint32)renderPassInfo.getInputAspects().size(),
1239 renderPassInfo.getInputAspects().data(),
1242 result = de::MovePtr<VkRenderPassInputAttachmentAspectCreateInfo>(new VkRenderPassInputAttachmentAspectCreateInfo(inputAspectCreateInfo));
1248 template<typename AttachmentDesc, typename AttachmentRef, typename SubpassDesc, typename SubpassDep, typename RenderPassCreateInfo>
1249 Move<VkRenderPass> createRenderPass (const DeviceInterface& vk,
1251 const RenderPass& renderPassInfo)
1253 const size_t perSubpassAttachmentReferenceLists = 4;
1254 vector<AttachmentDesc> attachments;
1255 vector<SubpassDesc> subpasses;
1256 vector<SubpassDep> dependencies;
1257 vector<vector<AttachmentRef> > attachmentReferenceLists(renderPassInfo.getSubpasses().size() * perSubpassAttachmentReferenceLists);
1258 vector<vector<deUint32> > preserveAttachments(renderPassInfo.getSubpasses().size());
1259 de::MovePtr<VkRenderPassInputAttachmentAspectCreateInfo> inputAspectCreateInfo(createRenderPassInputAttachmentAspectCreateInfo(renderPassInfo));
1261 for (size_t attachmentNdx = 0; attachmentNdx < renderPassInfo.getAttachments().size(); attachmentNdx++)
1262 attachments.push_back(createAttachmentDescription<AttachmentDesc>(renderPassInfo.getAttachments()[attachmentNdx]));
1264 for (size_t subpassNdx = 0; subpassNdx < renderPassInfo.getSubpasses().size(); subpassNdx++)
1265 subpasses.push_back(createSubpassDescription<SubpassDesc>(renderPassInfo.getSubpasses()[subpassNdx], &(attachmentReferenceLists[subpassNdx * perSubpassAttachmentReferenceLists]), &preserveAttachments[subpassNdx]));
1267 for (size_t depNdx = 0; depNdx < renderPassInfo.getDependencies().size(); depNdx++)
1268 dependencies.push_back(createSubpassDependency<SubpassDep>(renderPassInfo.getDependencies()[depNdx]));
1270 const RenderPassCreateInfo renderPassCreator // VkRenderPassCreateInfo || VkRenderPassCreateInfo2KHR
1272 // VkStructureType sType; || VkStructureType sType;
1273 inputAspectCreateInfo.get(), // const void* pNext; || const void* pNext;
1274 (VkRenderPassCreateFlags)0u, // VkRenderPassCreateFlags flags; || VkRenderPassCreateFlags flags;
1275 (deUint32)attachments.size(), // deUint32 attachmentCount; || deUint32 attachmentCount;
1276 (attachments.empty() ? DE_NULL : &attachments[0]), // const VkAttachmentDescription* pAttachments; || const VkAttachmentDescription2KHR* pAttachments;
1277 (deUint32)subpasses.size(), // deUint32 subpassCount; || deUint32 subpassCount;
1278 (subpasses.empty() ? DE_NULL : &subpasses[0]), // const VkSubpassDescription* pSubpasses; || const VkSubpassDescription2KHR* pSubpasses;
1279 (deUint32)dependencies.size(), // deUint32 dependencyCount; || deUint32 dependencyCount;
1280 (dependencies.empty() ? DE_NULL : &dependencies[0]), // const VkSubpassDependency* pDependencies; || const VkSubpassDependency2KHR* pDependencies;
1281 0u, // || deUint32 correlatedViewMaskCount;
1282 DE_NULL // || const deUint32* pCorrelatedViewMasks;
1285 return renderPassCreator.createRenderPass(vk, device);
1288 Move<VkRenderPass> createRenderPass (const DeviceInterface& vk,
1290 const RenderPass& renderPassInfo,
1291 const RenderingType renderPassType)
1293 switch (renderPassType)
1295 case RENDERING_TYPE_RENDERPASS_LEGACY:
1296 return createRenderPass<AttachmentDescription1, AttachmentReference1, SubpassDescription1, SubpassDependency1, RenderPassCreateInfo1>(vk, device, renderPassInfo);
1297 case RENDERING_TYPE_RENDERPASS2:
1298 return createRenderPass<AttachmentDescription2, AttachmentReference2, SubpassDescription2, SubpassDependency2, RenderPassCreateInfo2>(vk, device, renderPassInfo);
1300 TCU_THROW(InternalError, "Impossible");
1304 Move<VkFramebuffer> createFramebuffer (const DeviceInterface& vk,
1306 VkRenderPass renderPass,
1308 const vector<VkImageView>& attachments)
1310 return createFramebuffer(vk, device, 0u, renderPass, (deUint32)attachments.size(), attachments.empty() ? DE_NULL : &attachments[0], size.x(), size.y(), 1u);
1313 Move<VkImage> createAttachmentImage (const DeviceInterface& vk,
1315 deUint32 queueIndex,
1318 VkSampleCountFlagBits samples,
1319 VkImageUsageFlags usageFlags,
1320 VkImageLayout layout)
1322 VkImageUsageFlags targetUsageFlags = 0;
1323 const tcu::TextureFormat textureFormat = mapVkFormat(format);
1325 DE_ASSERT(!(tcu::hasDepthComponent(vk::mapVkFormat(format).order) || tcu::hasStencilComponent(vk::mapVkFormat(format).order))
1326 || ((usageFlags & vk::VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) == 0));
1328 DE_ASSERT((tcu::hasDepthComponent(vk::mapVkFormat(format).order) || tcu::hasStencilComponent(vk::mapVkFormat(format).order))
1329 || ((usageFlags & vk::VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0));
1331 if (tcu::hasDepthComponent(textureFormat.order) || tcu::hasStencilComponent(textureFormat.order))
1332 targetUsageFlags |= vk::VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
1334 targetUsageFlags |= vk::VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
1336 return createImage(vk, device,
1337 (VkImageCreateFlags)0,
1340 vk::makeExtent3D(size.x(), size.y(), 1u),
1344 VK_IMAGE_TILING_OPTIMAL,
1345 usageFlags | targetUsageFlags,
1346 VK_SHARING_MODE_EXCLUSIVE,
1352 de::MovePtr<Allocation> createImageMemory (const InstanceInterface& vki,
1353 const VkPhysicalDevice& vkd,
1354 const DeviceInterface& vk,
1356 Allocator& allocator,
1359 AllocationKind allocationKind)
1361 const MemoryRequirement memoryRequirement = lazy ? MemoryRequirement::LazilyAllocated : MemoryRequirement::Any;
1362 de::MovePtr<Allocation> allocation = allocateImage(vki, vk, vkd, device, image, memoryRequirement, allocator, allocationKind);
1364 bindImageMemory(vk, device, image, allocation->getMemory(), allocation->getOffset());
1369 Move<VkImageView> createImageAttachmentView (const DeviceInterface& vk,
1373 VkImageAspectFlags aspect)
1375 const VkImageSubresourceRange range =
1384 return createImageView(vk, device, 0u, image, VK_IMAGE_VIEW_TYPE_2D, format, makeComponentMappingRGBA(), range);
1387 VkClearValue randomClearValue (const Attachment& attachment, de::Random& rng, deBool useFormatCompCount, const DepthValuesArray& depthValues)
1389 const float clearNan = tcu::Float32::nan().asFloat();
1390 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
1392 if (tcu::hasStencilComponent(format.order) || tcu::hasDepthComponent(format.order))
1394 VkClearValue clearValue;
1396 clearValue.depthStencil.depth = clearNan;
1397 clearValue.depthStencil.stencil = 0xCDu;
1399 if (tcu::hasStencilComponent(format.order))
1400 clearValue.depthStencil.stencil = rng.getBool()
1404 if (tcu::hasDepthComponent(format.order))
1405 clearValue.depthStencil.depth = float(depthValues[rng.getBool() ? 1 : 0]) / 255.0f;
1411 VkClearValue clearValue;
1413 clearValue.color = randomColorClearValue(attachment, rng, useFormatCompCount);
1419 class AttachmentResources
1422 AttachmentResources (const InstanceInterface& vki,
1423 const VkPhysicalDevice& physDevice,
1424 const DeviceInterface& vk,
1426 Allocator& allocator,
1427 deUint32 queueIndex,
1429 const Attachment& attachmentInfo,
1430 VkImageUsageFlags usageFlags,
1431 const AllocationKind allocationKind)
1432 : m_image (createAttachmentImage(vk, device, queueIndex, size, attachmentInfo.getFormat(), attachmentInfo.getSamples(), usageFlags, VK_IMAGE_LAYOUT_UNDEFINED))
1433 , m_imageMemory (createImageMemory(vki, physDevice, vk, device, allocator, *m_image, ((usageFlags & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) != 0), allocationKind))
1434 , m_attachmentView (createImageAttachmentView(vk, device, *m_image, attachmentInfo.getFormat(), getImageAspectFlags(attachmentInfo.getFormat())))
1436 const tcu::TextureFormat format = mapVkFormat(attachmentInfo.getFormat());
1437 const bool isDepthFormat = tcu::hasDepthComponent(format.order);
1438 const bool isStencilFormat = tcu::hasStencilComponent(format.order);
1440 if (isDepthFormat && isStencilFormat)
1442 m_depthInputAttachmentView = createImageAttachmentView(vk, device, *m_image, attachmentInfo.getFormat(), VK_IMAGE_ASPECT_DEPTH_BIT);
1443 m_stencilInputAttachmentView = createImageAttachmentView(vk, device, *m_image, attachmentInfo.getFormat(), VK_IMAGE_ASPECT_STENCIL_BIT);
1445 m_inputAttachmentViews = std::make_pair(*m_depthInputAttachmentView, *m_stencilInputAttachmentView);
1448 m_inputAttachmentViews = std::make_pair(*m_attachmentView, (vk::VkImageView)0u);
1450 if ((usageFlags & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) == 0)
1452 if (tcu::hasDepthComponent(format.order) && tcu::hasStencilComponent(format.order))
1454 const tcu::TextureFormat depthFormat = getDepthCopyFormat(attachmentInfo.getFormat());
1455 const tcu::TextureFormat stencilFormat = getStencilCopyFormat(attachmentInfo.getFormat());
1457 m_bufferSize = size.x() * size.y() * depthFormat.getPixelSize();
1458 m_secondaryBufferSize = size.x() * size.y() * stencilFormat.getPixelSize();
1460 m_buffer = createBuffer(vk, device, 0, m_bufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_SHARING_MODE_EXCLUSIVE, 1, &queueIndex);
1461 m_bufferMemory = allocateBuffer(vki, vk, physDevice, device, *m_buffer, MemoryRequirement::HostVisible, allocator, allocationKind);
1463 bindBufferMemory(vk, device, *m_buffer, m_bufferMemory->getMemory(), m_bufferMemory->getOffset());
1465 m_secondaryBuffer = createBuffer(vk, device, 0, m_secondaryBufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_SHARING_MODE_EXCLUSIVE, 1, &queueIndex);
1466 m_secondaryBufferMemory = allocateBuffer(vki, vk, physDevice, device, *m_secondaryBuffer, MemoryRequirement::HostVisible, allocator, allocationKind);
1468 bindBufferMemory(vk, device, *m_secondaryBuffer, m_secondaryBufferMemory->getMemory(), m_secondaryBufferMemory->getOffset());
1472 m_bufferSize = size.x() * size.y() * format.getPixelSize();
1474 m_buffer = createBuffer(vk, device, 0, m_bufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_SHARING_MODE_EXCLUSIVE, 1, &queueIndex);
1475 m_bufferMemory = allocateBuffer(vki, vk, physDevice, device, *m_buffer, MemoryRequirement::HostVisible, allocator, allocationKind);
1477 bindBufferMemory(vk, device, *m_buffer, m_bufferMemory->getMemory(), m_bufferMemory->getOffset());
1482 const pair<VkImageView, VkImageView>& getInputAttachmentViews (void) const
1484 return m_inputAttachmentViews;
1487 ~AttachmentResources (void)
1491 VkImageView getAttachmentView (void) const
1493 return *m_attachmentView;
1496 VkImage getImage (void) const
1501 VkBuffer getBuffer (void) const
1503 DE_ASSERT(*m_buffer != DE_NULL);
1507 VkDeviceSize getBufferSize (void) const
1509 DE_ASSERT(*m_buffer != DE_NULL);
1510 return m_bufferSize;
1513 const Allocation& getResultMemory (void) const
1515 DE_ASSERT(m_bufferMemory);
1516 return *m_bufferMemory;
1519 VkBuffer getSecondaryBuffer (void) const
1521 DE_ASSERT(*m_secondaryBuffer != DE_NULL);
1522 return *m_secondaryBuffer;
1525 VkDeviceSize getSecondaryBufferSize (void) const
1527 DE_ASSERT(*m_secondaryBuffer != DE_NULL);
1528 return m_secondaryBufferSize;
1531 const Allocation& getSecondaryResultMemory (void) const
1533 DE_ASSERT(m_secondaryBufferMemory);
1534 return *m_secondaryBufferMemory;
1538 const Unique<VkImage> m_image;
1539 const UniquePtr<Allocation> m_imageMemory;
1540 const Unique<VkImageView> m_attachmentView;
1542 Move<VkImageView> m_depthInputAttachmentView;
1543 Move<VkImageView> m_stencilInputAttachmentView;
1544 pair<VkImageView, VkImageView> m_inputAttachmentViews;
1546 Move<VkBuffer> m_buffer;
1547 VkDeviceSize m_bufferSize;
1548 de::MovePtr<Allocation> m_bufferMemory;
1550 Move<VkBuffer> m_secondaryBuffer;
1551 VkDeviceSize m_secondaryBufferSize;
1552 de::MovePtr<Allocation> m_secondaryBufferMemory;
1555 void uploadBufferData (const DeviceInterface& vk,
1557 const Allocation& memory,
1560 VkDeviceSize nonCoherentAtomSize)
1562 // Expand the range to flush to account for the nonCoherentAtomSize
1563 const VkDeviceSize roundedOffset = de::roundDown(memory.getOffset(), nonCoherentAtomSize);
1564 const VkDeviceSize roundedSize = de::roundUp(memory.getOffset() - roundedOffset + static_cast<VkDeviceSize>(size), nonCoherentAtomSize);
1566 const VkMappedMemoryRange range =
1568 VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, // sType;
1570 memory.getMemory(), // mem;
1571 roundedOffset, // offset;
1572 roundedSize, // size;
1574 void* const ptr = memory.getHostPtr();
1576 deMemcpy(ptr, data, size);
1577 VK_CHECK(vk.flushMappedMemoryRanges(device, 1, &range));
1580 VkImageAspectFlagBits getPrimaryImageAspect (tcu::TextureFormat::ChannelOrder order)
1582 DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELORDER_LAST == 22);
1586 case tcu::TextureFormat::D:
1587 case tcu::TextureFormat::DS:
1588 return VK_IMAGE_ASPECT_DEPTH_BIT;
1590 case tcu::TextureFormat::S:
1591 return VK_IMAGE_ASPECT_STENCIL_BIT;
1594 return VK_IMAGE_ASPECT_COLOR_BIT;
1598 deUint32 getAttachmentNdx (const vector<AttachmentReference>& colorAttachments, size_t ndx)
1600 return (colorAttachments[ndx].getAttachment() == VK_ATTACHMENT_UNUSED) ? (deUint32)ndx : colorAttachments[ndx].getAttachment();
1606 RenderQuad (const Vec2& posA, const Vec2& posB)
1609 m_vertices[0] = posA;
1610 m_vertices[1] = Vec2(posA[0], posB[1]);
1611 m_vertices[2] = posB;
1613 m_vertices[3] = posB;
1614 m_vertices[4] = Vec2(posB[0], posA[1]);
1615 m_vertices[5] = posA;
1618 const Vec2& getCornerA (void) const
1620 return m_vertices[0];
1623 const Vec2& getCornerB (void) const
1625 return m_vertices[2];
1628 const void* getVertexPointer (void) const
1630 return &m_vertices[0];
1633 size_t getVertexDataSize (void) const
1635 return sizeof(Vec2) * m_vertices.size();
1639 vector<Vec2> m_vertices;
1645 ColorClear (const UVec2& offset,
1647 const VkClearColorValue& color)
1654 const UVec2& getOffset (void) const { return m_offset; }
1655 const UVec2& getSize (void) const { return m_size; }
1656 const VkClearColorValue& getColor (void) const { return m_color; }
1661 VkClearColorValue m_color;
1664 class DepthStencilClear
1667 DepthStencilClear (const UVec2& offset,
1674 , m_stencil (stencil)
1678 const UVec2& getOffset (void) const { return m_offset; }
1679 const UVec2& getSize (void) const { return m_size; }
1680 float getDepth (void) const { return m_depth; }
1681 deUint32 getStencil (void) const { return m_stencil; }
1684 const UVec2 m_offset;
1687 const float m_depth;
1688 const deUint32 m_stencil;
1691 class SubpassRenderInfo
1694 SubpassRenderInfo (const RenderPass& renderPass,
1695 deUint32 subpassIndex,
1696 deUint32 drawStartNdx,
1699 bool omitBlendState_,
1701 const UVec2& viewportOffset,
1702 const UVec2& viewportSize,
1704 const Maybe<RenderQuad>& renderQuad,
1705 const vector<ColorClear>& colorClears,
1706 const Maybe<DepthStencilClear>& depthStencilClear)
1707 : m_viewportOffset (viewportOffset)
1708 , m_viewportSize (viewportSize)
1709 , m_subpassIndex (subpassIndex)
1710 , m_drawStartNdx (drawStartNdx)
1711 , m_isSecondary (isSecondary_)
1712 , m_omitBlendState (omitBlendState_)
1713 , m_flags (renderPass.getSubpasses()[subpassIndex].getFlags())
1714 , m_renderQuad (renderQuad)
1715 , m_colorClears (colorClears)
1716 , m_depthStencilClear (depthStencilClear)
1717 , m_colorAttachments (renderPass.getSubpasses()[subpassIndex].getColorAttachments())
1718 , m_inputAttachments (renderPass.getSubpasses()[subpassIndex].getInputAttachments())
1720 for (deUint32 attachmentNdx = 0; attachmentNdx < (deUint32)m_colorAttachments.size(); attachmentNdx++)
1721 m_colorAttachmentInfo.push_back(renderPass.getAttachments()[getAttachmentNdx(m_colorAttachments, attachmentNdx)]);
1723 if (renderPass.getSubpasses()[subpassIndex].getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED)
1725 m_depthStencilAttachment = tcu::just(renderPass.getSubpasses()[subpassIndex].getDepthStencilAttachment());
1726 m_depthStencilAttachmentInfo = tcu::just(renderPass.getAttachments()[renderPass.getSubpasses()[subpassIndex].getDepthStencilAttachment().getAttachment()]);
1730 const UVec2& getViewportOffset (void) const { return m_viewportOffset; }
1731 const UVec2& getViewportSize (void) const { return m_viewportSize; }
1733 deUint32 getSubpassIndex (void) const { return m_subpassIndex; }
1734 deUint32 getDrawStartNdx (void) const { return m_drawStartNdx; }
1735 bool isSecondary (void) const { return m_isSecondary; }
1736 bool getOmitBlendState (void) const { return m_omitBlendState; }
1738 const Maybe<RenderQuad>& getRenderQuad (void) const { return m_renderQuad; }
1739 const vector<ColorClear>& getColorClears (void) const { return m_colorClears; }
1740 const Maybe<DepthStencilClear>& getDepthStencilClear (void) const { return m_depthStencilClear; }
1742 deUint32 getInputAttachmentCount (void) const { return (deUint32)m_inputAttachments.size(); }
1743 deUint32 getInputAttachmentIndex (deUint32 attachmentNdx) const { return m_inputAttachments[attachmentNdx].getAttachment(); }
1744 VkImageLayout getInputAttachmentLayout (deUint32 attachmentNdx) const { return m_inputAttachments[attachmentNdx].getImageLayout(); }
1746 deUint32 getColorAttachmentCount (void) const { return (deUint32)m_colorAttachments.size(); }
1747 VkImageLayout getColorAttachmentLayout (deUint32 attachmentNdx) const { return m_colorAttachments[attachmentNdx].getImageLayout(); }
1748 deUint32 getColorAttachmentIndex (deUint32 attachmentNdx) const { return m_colorAttachments[attachmentNdx].getAttachment(); }
1749 const Attachment& getColorAttachment (deUint32 attachmentNdx) const { return m_colorAttachmentInfo[attachmentNdx]; }
1750 Maybe<VkImageLayout> getDepthStencilAttachmentLayout (void) const { return m_depthStencilAttachment ? tcu::just(m_depthStencilAttachment->getImageLayout()) : tcu::Nothing; }
1751 Maybe<deUint32> getDepthStencilAttachmentIndex (void) const { return m_depthStencilAttachment ? tcu::just(m_depthStencilAttachment->getAttachment()) : tcu::Nothing; }
1752 const Maybe<Attachment>& getDepthStencilAttachment (void) const { return m_depthStencilAttachmentInfo; }
1753 VkSubpassDescriptionFlags getSubpassFlags (void) const { return m_flags; }
1756 UVec2 m_viewportOffset;
1757 UVec2 m_viewportSize;
1759 deUint32 m_subpassIndex;
1760 deUint32 m_drawStartNdx;
1762 bool m_omitBlendState;
1763 VkSubpassDescriptionFlags m_flags;
1765 Maybe<RenderQuad> m_renderQuad;
1766 vector<ColorClear> m_colorClears;
1767 Maybe<DepthStencilClear> m_depthStencilClear;
1769 vector<AttachmentReference> m_colorAttachments;
1770 vector<Attachment> m_colorAttachmentInfo;
1772 Maybe<AttachmentReference> m_depthStencilAttachment;
1773 Maybe<Attachment> m_depthStencilAttachmentInfo;
1775 vector<AttachmentReference> m_inputAttachments;
1778 void beginCommandBuffer (const DeviceInterface& vk,
1779 VkCommandBuffer cmdBuffer,
1780 VkRenderPass pInheritanceInfo_renderPass,
1781 deUint32 pInheritanceInfo_subpass,
1782 VkFramebuffer pInheritanceInfo_framebuffer,
1783 VkBool32 pInheritanceInfo_occlusionQueryEnable,
1784 VkQueryControlFlags pInheritanceInfo_queryFlags,
1785 VkQueryPipelineStatisticFlags pInheritanceInfo_pipelineStatistics,
1786 const SubpassRenderInfo* pRenderInfo = 0,
1787 bool dynamicRenderPass = false,
1788 bool secondaryCmdBufferCompletelyContainsRenderpass = false)
1790 VkCommandBufferUsageFlags usageFlags = (VkCommandBufferUsageFlags)0;
1791 VkCommandBufferInheritanceInfo pInheritanceInfo
1793 VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO,
1795 pInheritanceInfo_renderPass,
1796 pInheritanceInfo_subpass,
1797 pInheritanceInfo_framebuffer,
1798 pInheritanceInfo_occlusionQueryEnable,
1799 pInheritanceInfo_queryFlags,
1800 pInheritanceInfo_pipelineStatistics,
1803 #ifndef CTS_USES_VULKANSC
1805 std::vector<vk::VkFormat> colorAttachmentFormats;
1806 VkCommandBufferInheritanceRenderingInfoKHR inheritanceRenderingInfo = initVulkanStructure();
1808 if (dynamicRenderPass && pRenderInfo)
1810 if (secondaryCmdBufferCompletelyContainsRenderpass)
1811 inheritanceRenderingInfo.flags = VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT;
1813 usageFlags |= VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
1815 for (deUint32 i = 0; i < pRenderInfo->getColorAttachmentCount(); ++i)
1816 colorAttachmentFormats.push_back(pRenderInfo->getColorAttachment(i).getFormat());
1818 inheritanceRenderingInfo.colorAttachmentCount = static_cast<deUint32>(colorAttachmentFormats.size());
1819 inheritanceRenderingInfo.pColorAttachmentFormats = colorAttachmentFormats.data();
1820 if (pRenderInfo->getDepthStencilAttachment())
1822 const VkFormat dsFormat = pRenderInfo->getDepthStencilAttachment()->getFormat();
1823 inheritanceRenderingInfo.depthAttachmentFormat = tcu::hasDepthComponent(mapVkFormat(dsFormat).order) ? dsFormat : VK_FORMAT_UNDEFINED;
1824 inheritanceRenderingInfo.stencilAttachmentFormat = tcu::hasStencilComponent(mapVkFormat(dsFormat).order) ? dsFormat : VK_FORMAT_UNDEFINED;
1827 if (pRenderInfo->getColorAttachmentCount())
1828 inheritanceRenderingInfo.rasterizationSamples = pRenderInfo->getColorAttachment(0).getSamples();
1829 else if (pRenderInfo->getDepthStencilAttachment())
1830 inheritanceRenderingInfo.rasterizationSamples = pRenderInfo->getDepthStencilAttachment()->getSamples();
1832 inheritanceRenderingInfo.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
1834 pInheritanceInfo.pNext = &inheritanceRenderingInfo;
1836 else if (!secondaryCmdBufferCompletelyContainsRenderpass)
1837 usageFlags = VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
1840 DE_UNREF(pRenderInfo);
1841 DE_UNREF(dynamicRenderPass);
1842 DE_UNREF(secondaryCmdBufferCompletelyContainsRenderpass);
1844 usageFlags = VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
1846 #endif // CTS_USES_VULKANSC
1848 const VkCommandBufferBeginInfo pBeginInfo
1850 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
1855 VK_CHECK(vk.beginCommandBuffer(cmdBuffer, &pBeginInfo));
1858 Move<VkPipeline> createSubpassPipeline (const DeviceInterface& vk,
1860 VkRenderPass renderPass,
1861 VkShaderModule vertexShaderModule,
1862 VkShaderModule fragmentShaderModule,
1863 VkPipelineLayout pipelineLayout,
1864 const SubpassRenderInfo& renderInfo)
1866 Maybe<VkSampleCountFlagBits> rasterSamples;
1867 vector<VkPipelineColorBlendAttachmentState> attachmentBlendStates;
1869 for (deUint32 attachmentNdx = 0; attachmentNdx < renderInfo.getColorAttachmentCount(); attachmentNdx++)
1871 const Attachment& attachment = renderInfo.getColorAttachment(attachmentNdx);
1873 DE_ASSERT(!rasterSamples || *rasterSamples == attachment.getSamples());
1875 rasterSamples = attachment.getSamples();
1878 const VkPipelineColorBlendAttachmentState attachmentBlendState =
1880 VK_FALSE, // blendEnable
1881 VK_BLEND_FACTOR_SRC_ALPHA, // srcBlendColor
1882 VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, // destBlendColor
1883 VK_BLEND_OP_ADD, // blendOpColor
1884 VK_BLEND_FACTOR_ONE, // srcBlendAlpha
1885 VK_BLEND_FACTOR_ONE, // destBlendAlpha
1886 VK_BLEND_OP_ADD, // blendOpAlpha
1887 (attachmentNdx < renderInfo.getDrawStartNdx() ? (deUint32)0 :
1888 VK_COLOR_COMPONENT_R_BIT|VK_COLOR_COMPONENT_G_BIT|VK_COLOR_COMPONENT_B_BIT|VK_COLOR_COMPONENT_A_BIT) // channelWriteMask
1891 attachmentBlendStates.push_back(attachmentBlendState);
1895 if (renderInfo.getDepthStencilAttachment())
1897 const Attachment& attachment = *renderInfo.getDepthStencilAttachment();
1899 DE_ASSERT(!rasterSamples || *rasterSamples == attachment.getSamples());
1900 rasterSamples = attachment.getSamples();
1903 // If there are no attachment use single sample
1905 rasterSamples = VK_SAMPLE_COUNT_1_BIT;
1907 const VkVertexInputBindingDescription vertexBinding =
1910 (deUint32)sizeof(tcu::Vec2), // strideInBytes
1911 VK_VERTEX_INPUT_RATE_VERTEX, // stepRate
1914 const VkVertexInputAttributeDescription vertexAttrib =
1918 VK_FORMAT_R32G32_SFLOAT, // format
1919 0u, // offsetInBytes
1922 const VkPipelineVertexInputStateCreateInfo vertexInputState =
1924 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, // sType
1926 (VkPipelineVertexInputStateCreateFlags)0u,
1928 &vertexBinding, // pVertexBindingDescriptions
1929 1u, // attributeCount
1930 &vertexAttrib, // pVertexAttributeDescriptions
1933 const VkPipelineInputAssemblyStateCreateInfo inputAssemblyState =
1935 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, // VkStructureType sType
1936 DE_NULL, // const void* pNext
1937 0u, // VkPipelineInputAssemblyStateCreateFlags flags
1938 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, // VkPrimitiveTopology topology
1939 VK_FALSE // VkBool32 primitiveRestartEnable
1942 const VkViewport viewport =
1944 (float)renderInfo.getViewportOffset().x(), (float)renderInfo.getViewportOffset().y(),
1945 (float)renderInfo.getViewportSize().x(), (float)renderInfo.getViewportSize().y(),
1949 const VkRect2D scissor =
1951 { (deInt32)renderInfo.getViewportOffset().x(), (deInt32)renderInfo.getViewportOffset().y() },
1952 { renderInfo.getViewportSize().x(), renderInfo.getViewportSize().y() }
1955 const VkPipelineViewportStateCreateInfo viewportState =
1957 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, // VkStructureType sType
1958 DE_NULL, // const void* pNext
1959 (VkPipelineViewportStateCreateFlags)0, // VkPipelineViewportStateCreateFlags flags
1960 1u, // deUint32 viewportCount
1961 &viewport, // const VkViewport* pViewports
1962 1u, // deUint32 scissorCount
1963 &scissor // const VkRect2D* pScissors
1966 const VkPipelineRasterizationStateCreateInfo rasterizationState =
1968 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, // VkStructureType sType
1969 DE_NULL, // const void* pNext
1970 0u, // VkPipelineRasterizationStateCreateFlags flags
1971 VK_FALSE, // VkBool32 depthClampEnable
1972 VK_FALSE, // VkBool32 rasterizerDiscardEnable
1973 VK_POLYGON_MODE_FILL, // VkPolygonMode polygonMode
1974 VK_CULL_MODE_NONE, // VkCullModeFlags cullMode
1975 VK_FRONT_FACE_COUNTER_CLOCKWISE, // VkFrontFace frontFace
1976 VK_FALSE, // VkBool32 depthBiasEnable
1977 0.0f, // float depthBiasConstantFactor
1978 0.0f, // float depthBiasClamp
1979 0.0f, // float depthBiasSlopeFactor
1980 1.0f // float lineWidth
1983 const VkPipelineMultisampleStateCreateInfo multisampleState =
1985 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // sType
1987 (VkPipelineMultisampleStateCreateFlags)0u,
1988 *rasterSamples, // rasterSamples
1989 VK_FALSE, // sampleShadingEnable
1990 0.0f, // minSampleShading
1991 DE_NULL, // pSampleMask
1992 VK_FALSE, // alphaToCoverageEnable
1993 VK_FALSE, // alphaToOneEnable
1995 const size_t stencilIndex = renderInfo.getSubpassIndex();
1997 const VkBool32 writeDepth = renderInfo.getDepthStencilAttachmentLayout()
1998 && *renderInfo.getDepthStencilAttachmentLayout() != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
1999 && *renderInfo.getDepthStencilAttachmentLayout() != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL
2003 const VkBool32 writeStencil = renderInfo.getDepthStencilAttachmentLayout()
2004 && *renderInfo.getDepthStencilAttachmentLayout() != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
2005 && *renderInfo.getDepthStencilAttachmentLayout() != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL
2009 const VkPipelineDepthStencilStateCreateInfo depthStencilState =
2011 VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, // sType
2013 (VkPipelineDepthStencilStateCreateFlags)0u,
2014 writeDepth, // depthTestEnable
2015 writeDepth, // depthWriteEnable
2016 VK_COMPARE_OP_ALWAYS, // depthCompareOp
2017 VK_FALSE, // depthBoundsEnable
2018 writeStencil, // stencilTestEnable
2020 VK_STENCIL_OP_REPLACE, // stencilFailOp
2021 VK_STENCIL_OP_REPLACE, // stencilPassOp
2022 VK_STENCIL_OP_REPLACE, // stencilDepthFailOp
2023 VK_COMPARE_OP_ALWAYS, // stencilCompareOp
2024 ~0u, // stencilCompareMask
2025 ~0u, // stencilWriteMask
2026 ((stencilIndex % 2) == 0) ? ~0x0u : 0x0u // stencilReference
2029 VK_STENCIL_OP_REPLACE, // stencilFailOp
2030 VK_STENCIL_OP_REPLACE, // stencilPassOp
2031 VK_STENCIL_OP_REPLACE, // stencilDepthFailOp
2032 VK_COMPARE_OP_ALWAYS, // stencilCompareOp
2033 ~0u, // stencilCompareMask
2034 ~0u, // stencilWriteMask
2035 ((stencilIndex % 2) == 0) ? ~0x0u : 0x0u // stencilReference
2038 0.0f, // minDepthBounds;
2039 1.0f // maxDepthBounds;
2042 const VkPipelineColorBlendStateCreateInfo blendState =
2044 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, // sType
2046 (VkPipelineColorBlendStateCreateFlags)0u,
2047 VK_FALSE, // logicOpEnable
2048 VK_LOGIC_OP_COPY, // logicOp
2049 (deUint32)attachmentBlendStates.size(), // attachmentCount
2050 attachmentBlendStates.empty() ? DE_NULL : &attachmentBlendStates[0],// pAttachments
2051 { 0.0f, 0.0f, 0.0f, 0.0f } // blendConst
2054 #ifndef CTS_USES_VULKANSC
2055 std::vector<vk::VkFormat> colorAttachmentFormats;
2056 for (deUint32 i = 0; i < renderInfo.getColorAttachmentCount(); ++i)
2057 colorAttachmentFormats.push_back(renderInfo.getColorAttachment(i).getFormat());
2059 vk::VkFormat depthFormat = VK_FORMAT_UNDEFINED;
2060 vk::VkFormat stencilFormat = VK_FORMAT_UNDEFINED;
2061 if (renderInfo.getDepthStencilAttachment())
2063 const Attachment& attachment = *renderInfo.getDepthStencilAttachment();
2064 vk::VkFormat depthStencilFormat = attachment.getFormat();
2065 if (depthStencilFormat != VK_FORMAT_UNDEFINED)
2067 if (tcu::hasDepthComponent(mapVkFormat(depthStencilFormat).order))
2069 depthFormat = depthStencilFormat;
2071 if (tcu::hasStencilComponent(mapVkFormat(depthStencilFormat).order))
2073 stencilFormat = depthStencilFormat;
2079 VkPipelineRenderingCreateInfoKHR renderingCreateInfo
2081 VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR,
2084 static_cast<deUint32>(colorAttachmentFormats.size()),
2085 colorAttachmentFormats.data(),
2089 #endif // CTS_USES_VULKANSC
2091 return makeGraphicsPipeline(vk, // const DeviceInterface& vk
2092 device, // const VkDevice device
2093 pipelineLayout, // const VkPipelineLayout pipelineLayout
2094 vertexShaderModule, // const VkShaderModule vertexShaderModule
2095 DE_NULL, // const VkShaderModule tessellationControlShaderModule
2096 DE_NULL, // const VkShaderModule tessellationEvalShaderModule
2097 DE_NULL, // const VkShaderModule geometryShaderModule
2098 fragmentShaderModule, // const VkShaderModule fragmentShaderModule
2099 renderPass, // const VkRenderPass renderPass
2100 renderInfo.getSubpassIndex(), // const deUint32 subpass
2101 &vertexInputState, // const VkPipelineVertexInputStateCreateInfo* vertexInputStateCreateInfo
2102 &inputAssemblyState, // const VkPipelineInputAssemblyStateCreateInfo* pInputAssemblyState;
2103 DE_NULL, // const VkPipelineRasterizationStateCreateInfo* rasterizationStateCreateInfo
2104 &viewportState, // const VkPipelineViewportStateCreateInfo* pViewportStat;
2105 &rasterizationState, // const VkPipelineRasterizationStateCreateInfo* pRasterizationState
2106 &multisampleState, // const VkPipelineMultisampleStateCreateInfo* multisampleStateCreateInfo
2107 &depthStencilState, // const VkPipelineDepthStencilStateCreateInfo* depthStencilStateCreateInfo
2108 renderInfo.getOmitBlendState()
2109 ? DE_NULL : &blendState, // const VkPipelineColorBlendStateCreateInfo* colorBlendStateCreateInfo
2110 DE_NULL, // const VkPipelineDynamicStateCreateInfo* dynamicStateCreateInfo
2111 #ifndef CTS_USES_VULKANSC
2112 (renderPass == DE_NULL)
2113 ? &renderingCreateInfo : DE_NULL); // const void* pNext)
2115 DE_NULL); // const void* pNext)
2116 #endif // CTS_USES_VULKANSC
2119 #ifndef CTS_USES_VULKANSC
2120 void beginDynamicRendering(const DeviceInterface& vk,
2121 VkCommandBuffer commandBuffer,
2122 const RenderPass& renderPassInfo,
2123 const vector<de::SharedPtr<AttachmentResources> >& attachmentResources,
2124 const VkRect2D& renderArea,
2125 const vector<Maybe<VkClearValue> >& renderPassClearValues,
2126 const VkRenderingFlagsKHR renderingFlags = 0u)
2128 const float clearNan = tcu::Float32::nan().asFloat();
2129 const VkClearValue clearValueNan = makeClearValueColorF32(clearNan, clearNan, clearNan, clearNan);
2131 // translate structures that were prepared to construct renderpass to structures needed for dynamic rendering
2133 std::vector<vk::VkRenderingAttachmentInfoKHR> colorAttachmentVect;
2134 const Subpass& subpassInfo = renderPassInfo.getSubpasses()[0];
2135 const vector<AttachmentReference>& colorAttachmentsInfo = subpassInfo.getColorAttachments();
2136 const vector<AttachmentReference>& resolveAttachmentsInfo = subpassInfo.getResolveAttachments();
2138 for (deUint32 i = 0; i < colorAttachmentsInfo.size(); ++i)
2140 const AttachmentReference& colorAttachmentReference = colorAttachmentsInfo[i];
2141 const deUint32 colorAttachmentIndex = colorAttachmentReference.getAttachment();
2142 const Attachment& colorAttachmentInfo = renderPassInfo.getAttachments()[colorAttachmentIndex];
2144 VkResolveModeFlagBits resolveMode = VK_RESOLVE_MODE_NONE;
2145 VkImageView resolveImageView = DE_NULL;
2146 VkImageLayout resolveImageLayout = VK_IMAGE_LAYOUT_UNDEFINED;
2148 // handle resolve attachments if they were specified
2149 if (!resolveAttachmentsInfo.empty())
2151 const AttachmentReference& resolveAttachmentReference = resolveAttachmentsInfo[i];
2152 const deUint32 resolveAttachmentIndex = resolveAttachmentReference.getAttachment();
2153 const Attachment& resolveAttachmentInfo = renderPassInfo.getAttachments()[resolveAttachmentIndex];
2155 resolveMode = VK_RESOLVE_MODE_AVERAGE_BIT;
2156 resolveImageView = attachmentResources[resolveAttachmentIndex]->getAttachmentView();
2157 resolveImageLayout = resolveAttachmentInfo.getInitialLayout();
2160 colorAttachmentVect.push_back({
2161 vk::VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR, // VkStructureType sType
2162 DE_NULL, // const void* pNext
2163 attachmentResources[colorAttachmentIndex]->getAttachmentView(), // VkImageView imageView
2164 colorAttachmentReference.getImageLayout(), // VkImageLayout imageLayout
2165 resolveMode, // VkResolveModeFlagBits resolveMode
2166 resolveImageView, // VkImageView resolveImageView
2167 resolveImageLayout, // VkImageLayout resolveImageLayout
2168 colorAttachmentInfo.getLoadOp(), // VkAttachmentLoadOp loadOp
2169 colorAttachmentInfo.getStoreOp(), // VkAttachmentStoreOp storeOp
2170 (renderPassClearValues[colorAttachmentIndex] ?
2171 *renderPassClearValues[colorAttachmentIndex] :
2172 clearValueNan) // VkClearValue clearValue
2176 VkRenderingAttachmentInfoKHR* pDepthAttachment = DE_NULL;
2177 VkRenderingAttachmentInfoKHR* pStencilAttachment = DE_NULL;
2178 VkRenderingAttachmentInfoKHR depthAttachment
2180 vk::VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR, // VkStructureType sType;
2181 DE_NULL, // const void* pNext;
2182 DE_NULL, // VkImageView imageView;
2183 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout imageLayout;
2184 VK_RESOLVE_MODE_NONE, // VkResolveModeFlagBits resolveMode;
2185 DE_NULL, // VkImageView resolveImageView;
2186 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout resolveImageLayout;
2187 VK_ATTACHMENT_LOAD_OP_LOAD, // VkAttachmentLoadOp loadOp;
2188 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
2189 clearValueNan // VkClearValue clearValue;
2191 VkRenderingAttachmentInfoKHR stencilAttachment = depthAttachment;
2192 const AttachmentReference& depthStencilAttachmentReference = subpassInfo.getDepthStencilAttachment();
2193 const deUint32 dsAttachmentIndex = depthStencilAttachmentReference.getAttachment();
2195 if (dsAttachmentIndex != VK_ATTACHMENT_UNUSED)
2197 const Attachment& dsAttachmentInfo = renderPassInfo.getAttachments()[dsAttachmentIndex];
2198 const tcu::TextureFormat format = mapVkFormat(dsAttachmentInfo.getFormat());
2200 if (tcu::hasDepthComponent(format.order))
2202 depthAttachment.imageView = attachmentResources[dsAttachmentIndex]->getAttachmentView();
2203 depthAttachment.imageLayout = depthStencilAttachmentReference.getImageLayout();
2204 depthAttachment.loadOp = dsAttachmentInfo.getLoadOp();
2205 depthAttachment.storeOp = dsAttachmentInfo.getStoreOp();
2207 if (renderPassClearValues[dsAttachmentIndex])
2208 depthAttachment.clearValue = *renderPassClearValues[dsAttachmentIndex];
2210 pDepthAttachment = &depthAttachment;
2213 if (tcu::hasStencilComponent(format.order))
2215 stencilAttachment.imageView = attachmentResources[dsAttachmentIndex]->getAttachmentView();
2216 stencilAttachment.imageLayout = depthStencilAttachmentReference.getImageLayout();
2217 stencilAttachment.loadOp = dsAttachmentInfo.getStencilLoadOp();
2218 stencilAttachment.storeOp = dsAttachmentInfo.getStencilStoreOp();
2220 if (renderPassClearValues[dsAttachmentIndex])
2221 stencilAttachment.clearValue = *renderPassClearValues[dsAttachmentIndex];
2223 pStencilAttachment = &stencilAttachment;
2227 vk::VkRenderingInfoKHR renderingInfo
2229 vk::VK_STRUCTURE_TYPE_RENDERING_INFO_KHR,
2231 renderingFlags, // VkRenderingFlagsKHR flags;
2232 renderArea, // VkRect2D renderArea;
2233 1u, // deUint32 layerCount;
2234 0u, // deUint32 viewMask;
2235 static_cast<deUint32>(colorAttachmentVect.size()), // deUint32 colorAttachmentCount;
2236 colorAttachmentVect.empty() ? DE_NULL : &colorAttachmentVect[0], // const VkRenderingAttachmentInfoKHR* pColorAttachments;
2237 pDepthAttachment, // const VkRenderingAttachmentInfoKHR* pDepthAttachment;
2238 pStencilAttachment // const VkRenderingAttachmentInfoKHR* pStencilAttachment;
2241 vk.cmdBeginRendering(commandBuffer, &renderingInfo);
2244 void endDynamicRendering(const DeviceInterface& vk, VkCommandBuffer commandBuffer)
2246 vk.cmdEndRendering(commandBuffer);
2248 #endif // CTS_USES_VULKANSC
2250 class SubpassRenderer
2253 SubpassRenderer (Context& context,
2254 const DeviceInterface& vk,
2256 Allocator& allocator,
2257 const RenderPass& renderPassInfo,
2258 const vector<de::SharedPtr<AttachmentResources> >& attachmentResources,
2259 const VkRect2D& renderArea,
2260 const vector<Maybe<VkClearValue> >& renderPassClearValues,
2261 VkRenderPass renderPass,
2262 VkFramebuffer framebuffer,
2263 VkCommandPool commandBufferPool,
2264 deUint32 queueFamilyIndex,
2265 const vector<VkImage>& attachmentImages,
2266 const vector<pair<VkImageView, VkImageView> >& attachmentViews,
2267 const SubpassRenderInfo& renderInfo,
2268 const AllocationKind allocationKind,
2269 const bool dynamicRendering,
2270 const bool secondaryCmdBufferCompletelyContainsDynamicRenderpass)
2271 : m_renderInfo (renderInfo)
2273 // unreference values not used by Vulkan SC, no need to pu this under ifdef
2274 DE_UNREF(attachmentResources);
2275 DE_UNREF(renderArea);
2276 DE_UNREF(renderPassClearValues);
2278 const InstanceInterface& vki = context.getInstanceInterface();
2279 const VkPhysicalDevice& physDevice = context.getPhysicalDevice();
2280 const vector<Attachment>& attachmentInfos = renderPassInfo.getAttachments();
2281 const deUint32 subpassIndex = renderInfo.getSubpassIndex();
2282 vector<VkDescriptorSetLayoutBinding> bindings;
2284 for (deUint32 colorAttachmentNdx = 0; colorAttachmentNdx < renderInfo.getColorAttachmentCount(); colorAttachmentNdx++)
2286 const deUint32 attachmentNdx = (renderInfo.getColorAttachmentIndex(colorAttachmentNdx) == VK_ATTACHMENT_UNUSED) ? colorAttachmentNdx
2287 : renderInfo.getColorAttachmentIndex(colorAttachmentNdx);
2289 m_colorAttachmentImages.push_back(attachmentImages[attachmentNdx]);
2292 if (renderInfo.getDepthStencilAttachmentIndex())
2293 m_depthStencilAttachmentImage = attachmentImages[*renderInfo.getDepthStencilAttachmentIndex()];
2295 if (renderInfo.getRenderQuad())
2297 const RenderQuad& renderQuad = *renderInfo.getRenderQuad();
2299 if (renderInfo.getInputAttachmentCount() > 0)
2301 deUint32 bindingIndex = 0;
2303 for (deUint32 inputAttachmentNdx = 0; inputAttachmentNdx < renderInfo.getInputAttachmentCount(); inputAttachmentNdx++)
2305 const Attachment attachmentInfo = attachmentInfos[renderInfo.getInputAttachmentIndex(inputAttachmentNdx)];
2306 const VkImageLayout layout = renderInfo.getInputAttachmentLayout(inputAttachmentNdx);
2307 const tcu::TextureFormat format = mapVkFormat(attachmentInfo.getFormat());
2308 const bool isDepthFormat = tcu::hasDepthComponent(format.order);
2309 const bool isStencilFormat = tcu::hasStencilComponent(format.order);
2310 const deUint32 bindingCount = (isDepthFormat && layout != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
2311 && (isStencilFormat && layout != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL)
2315 for (deUint32 bindingNdx = 0; bindingNdx < bindingCount; bindingNdx++)
2317 const VkDescriptorSetLayoutBinding binding =
2320 vk::VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
2322 vk::VK_SHADER_STAGE_FRAGMENT_BIT,
2326 bindings.push_back(binding);
2331 const VkDescriptorSetLayoutCreateInfo createInfo =
2333 vk::VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
2337 (deUint32)bindings.size(),
2341 m_descriptorSetLayout = vk::createDescriptorSetLayout(vk, device, &createInfo);
2344 const VkDescriptorSetLayout descriptorSetLayout = *m_descriptorSetLayout;
2345 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
2347 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // sType;
2349 (vk::VkPipelineLayoutCreateFlags)0,
2350 m_descriptorSetLayout ? 1u :0u , // setLayoutCount;
2351 m_descriptorSetLayout ? &descriptorSetLayout : DE_NULL, // pSetLayouts;
2352 0u, // pushConstantRangeCount;
2353 DE_NULL, // pPushConstantRanges;
2356 m_vertexShaderModule = createShaderModule(vk, device, context.getBinaryCollection().get(de::toString(subpassIndex) + "-vert"), 0u);
2357 m_fragmentShaderModule = createShaderModule(vk, device, context.getBinaryCollection().get(de::toString(subpassIndex) + "-frag"), 0u);
2358 m_pipelineLayout = createPipelineLayout(vk, device, &pipelineLayoutParams);
2359 m_pipeline = createSubpassPipeline(vk, device, renderPass, *m_vertexShaderModule, *m_fragmentShaderModule, *m_pipelineLayout, m_renderInfo);
2361 // Round up the vertex buffer size to honor nonCoherentAtomSize.
2362 const auto properties = vk::getPhysicalDeviceProperties(context.getInstanceInterface(), context.getPhysicalDevice());
2363 const auto vertexBufferSize = de::roundUp(static_cast<VkDeviceSize>(renderQuad.getVertexDataSize()), properties.limits.nonCoherentAtomSize);
2365 m_vertexBuffer = createBuffer(vk, device, 0u, vertexBufferSize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_SHARING_MODE_EXCLUSIVE, 1u, &queueFamilyIndex);
2366 m_vertexBufferMemory = allocateBuffer(vki, vk, physDevice, device, *m_vertexBuffer, MemoryRequirement::HostVisible, allocator, allocationKind);
2368 bindBufferMemory(vk, device, *m_vertexBuffer, m_vertexBufferMemory->getMemory(), m_vertexBufferMemory->getOffset());
2370 uploadBufferData(vk, device, *m_vertexBufferMemory, renderQuad.getVertexDataSize(), renderQuad.getVertexPointer(), properties.limits.nonCoherentAtomSize);
2372 if (renderInfo.getInputAttachmentCount() > 0)
2375 const VkDescriptorPoolSize poolSize =
2377 vk::VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
2378 // \note Reserve 2 per input attachment since depthStencil attachments require 2.
2379 renderInfo.getInputAttachmentCount() * 2u
2381 const VkDescriptorPoolCreateInfo createInfo =
2383 vk::VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
2385 VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT,
2387 // \note Reserve 2 per input attachment since depthStencil attachments require 2.
2388 renderInfo.getInputAttachmentCount() * 2u,
2393 m_descriptorPool = vk::createDescriptorPool(vk, device, &createInfo);
2396 const VkDescriptorSetAllocateInfo allocateInfo =
2398 vk::VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
2403 &descriptorSetLayout
2406 m_descriptorSet = vk::allocateDescriptorSet(vk, device, &allocateInfo);
2409 vector<VkWriteDescriptorSet> writes (bindings.size());
2410 vector<VkDescriptorImageInfo> imageInfos (bindings.size());
2411 deUint32 bindingIndex = 0;
2413 for (deUint32 inputAttachmentNdx = 0; inputAttachmentNdx < renderInfo.getInputAttachmentCount(); inputAttachmentNdx++)
2415 const Attachment attachmentInfo = attachmentInfos[renderInfo.getInputAttachmentIndex(inputAttachmentNdx)];
2416 const tcu::TextureFormat format = mapVkFormat(attachmentInfo.getFormat());
2417 const bool isDepthFormat = tcu::hasDepthComponent(format.order);
2418 const bool isStencilFormat = tcu::hasStencilComponent(format.order);
2419 const VkImageLayout inputAttachmentLayout = renderInfo.getInputAttachmentLayout(inputAttachmentNdx);
2422 if (isDepthFormat && isStencilFormat)
2424 if (inputAttachmentLayout != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL)
2426 const VkDescriptorImageInfo imageInfo =
2429 attachmentViews[renderInfo.getInputAttachmentIndex(inputAttachmentNdx)].first,
2430 inputAttachmentLayout
2432 imageInfos[bindingIndex] = imageInfo;
2435 const VkWriteDescriptorSet write =
2437 VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
2444 VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
2445 &imageInfos[bindingIndex],
2449 writes[bindingIndex] = write;
2455 if (inputAttachmentLayout != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
2457 const VkDescriptorImageInfo imageInfo =
2460 attachmentViews[renderInfo.getInputAttachmentIndex(inputAttachmentNdx)].second,
2461 inputAttachmentLayout
2463 imageInfos[bindingIndex] = imageInfo;
2466 const VkWriteDescriptorSet write =
2468 VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
2475 VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
2476 &imageInfos[bindingIndex],
2480 writes[bindingIndex] = write;
2488 const VkDescriptorImageInfo imageInfo =
2491 attachmentViews[renderInfo.getInputAttachmentIndex(inputAttachmentNdx)].first,
2492 inputAttachmentLayout
2494 imageInfos[bindingIndex] = imageInfo;
2497 const VkWriteDescriptorSet write =
2499 VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
2506 VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
2507 &imageInfos[bindingIndex],
2511 writes[bindingIndex] = write;
2518 vk.updateDescriptorSets(device, (deUint32)writes.size(), &writes[0], 0u, DE_NULL);
2523 if (renderInfo.isSecondary())
2525 m_commandBuffer = allocateCommandBuffer(vk, device, commandBufferPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
2527 beginCommandBuffer(vk, *m_commandBuffer, renderPass, subpassIndex, framebuffer, VK_FALSE, (VkQueryControlFlags)0,
2528 (VkQueryPipelineStatisticFlags)0, &renderInfo, dynamicRendering, secondaryCmdBufferCompletelyContainsDynamicRenderpass);
2530 if (dynamicRendering && secondaryCmdBufferCompletelyContainsDynamicRenderpass)
2532 #ifndef CTS_USES_VULKANSC
2533 beginDynamicRendering(vk, *m_commandBuffer, renderPassInfo, attachmentResources, renderArea, renderPassClearValues);
2534 pushRenderCommands(vk, *m_commandBuffer);
2535 endDynamicRendering(vk, *m_commandBuffer);
2536 #endif // CTS_USES_VULKANSC
2539 pushRenderCommands(vk, *m_commandBuffer);
2541 endCommandBuffer(vk, *m_commandBuffer);
2545 bool isSecondary (void) const
2547 return !!m_commandBuffer;
2550 VkCommandBuffer getCommandBuffer (void) const
2552 DE_ASSERT(isSecondary());
2553 return *m_commandBuffer;
2556 void pushRenderCommands (const DeviceInterface& vk,
2557 VkCommandBuffer commandBuffer)
2559 if (!m_renderInfo.getColorClears().empty())
2561 const vector<ColorClear>& colorClears (m_renderInfo.getColorClears());
2563 for (deUint32 attachmentNdx = 0; attachmentNdx < m_renderInfo.getColorAttachmentCount(); attachmentNdx++)
2565 const ColorClear& colorClear = colorClears[attachmentNdx];
2566 const VkClearAttachment attachment =
2568 VK_IMAGE_ASPECT_COLOR_BIT,
2570 makeClearValue(colorClear.getColor()),
2572 const VkClearRect rect =
2575 { (deInt32)colorClear.getOffset().x(), (deInt32)colorClear.getOffset().y() },
2576 { colorClear.getSize().x(), colorClear.getSize().y() }
2578 0u, // baseArrayLayer
2582 vk.cmdClearAttachments(commandBuffer, 1u, &attachment, 1u, &rect);
2586 if (m_renderInfo.getDepthStencilClear())
2588 const DepthStencilClear& depthStencilClear = *m_renderInfo.getDepthStencilClear();
2589 const deUint32 attachmentNdx = m_renderInfo.getColorAttachmentCount();
2590 tcu::TextureFormat format = mapVkFormat(m_renderInfo.getDepthStencilAttachment()->getFormat());
2591 const VkImageLayout layout = *m_renderInfo.getDepthStencilAttachmentLayout();
2592 const VkClearAttachment attachment =
2594 (VkImageAspectFlags)((hasDepthComponent(format.order) && layout != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL ? VK_IMAGE_ASPECT_DEPTH_BIT : 0)
2595 | (hasStencilComponent(format.order) && layout != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL ? VK_IMAGE_ASPECT_STENCIL_BIT : 0)),
2597 makeClearValueDepthStencil(depthStencilClear.getDepth(), depthStencilClear.getStencil())
2599 const VkClearRect rect =
2602 { (deInt32)depthStencilClear.getOffset().x(), (deInt32)depthStencilClear.getOffset().y() },
2603 { depthStencilClear.getSize().x(), depthStencilClear.getSize().y() }
2605 0u, // baseArrayLayer
2609 if ((tcu::hasDepthComponent(format.order) && layout != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
2610 || (tcu::hasStencilComponent(format.order) && layout != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL))
2612 vk.cmdClearAttachments(commandBuffer, 1u, &attachment, 1u, &rect);
2616 vector<VkImageMemoryBarrier> selfDeps;
2617 VkPipelineStageFlags srcStages = 0;
2618 VkPipelineStageFlags dstStages = 0;
2620 for (deUint32 inputAttachmentNdx = 0; inputAttachmentNdx < m_renderInfo.getInputAttachmentCount(); inputAttachmentNdx++)
2622 for (deUint32 colorAttachmentNdx = 0; colorAttachmentNdx < m_renderInfo.getColorAttachmentCount(); colorAttachmentNdx++)
2624 if (m_renderInfo.getInputAttachmentIndex(inputAttachmentNdx) == m_renderInfo.getColorAttachmentIndex(colorAttachmentNdx))
2626 const VkImageMemoryBarrier barrier =
2628 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
2631 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // srcAccessMask
2632 VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, // dstAccessMask
2634 VK_IMAGE_LAYOUT_GENERAL, // oldLayout
2635 VK_IMAGE_LAYOUT_GENERAL, // newLayout
2637 VK_QUEUE_FAMILY_IGNORED, // srcQueueFamilyIndex
2638 VK_QUEUE_FAMILY_IGNORED, // destQueueFamilyIndex
2640 m_colorAttachmentImages[colorAttachmentNdx], // image
2641 { // subresourceRange
2642 VK_IMAGE_ASPECT_COLOR_BIT, // aspect
2645 0, // baseArraySlice
2650 srcStages |= VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
2651 dstStages |= VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
2653 selfDeps.push_back(barrier);
2657 if (m_renderInfo.getDepthStencilAttachmentIndex() && (m_renderInfo.getInputAttachmentIndex(inputAttachmentNdx) == *m_renderInfo.getDepthStencilAttachmentIndex()))
2659 const tcu::TextureFormat format = mapVkFormat(m_renderInfo.getDepthStencilAttachment()->getFormat());
2660 const bool hasDepth = hasDepthComponent(format.order);
2661 const bool hasStencil = hasStencilComponent(format.order);
2662 const VkImageMemoryBarrier barrier =
2664 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType;
2667 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, // srcAccessMask
2668 VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, // dstAccessMask
2670 m_renderInfo.getInputAttachmentLayout(inputAttachmentNdx), // oldLayout
2671 m_renderInfo.getInputAttachmentLayout(inputAttachmentNdx), // newLayout;
2673 VK_QUEUE_FAMILY_IGNORED, // srcQueueFamilyIndex;
2674 VK_QUEUE_FAMILY_IGNORED, // destQueueFamilyIndex;
2676 m_depthStencilAttachmentImage, // image;
2677 { // subresourceRange;
2678 (hasDepth ? (VkImageAspectFlags)VK_IMAGE_ASPECT_DEPTH_BIT : 0u)
2679 | (hasStencil ? (VkImageAspectFlags)VK_IMAGE_ASPECT_STENCIL_BIT : 0u), // aspect;
2682 0, // baseArraySlice;
2687 srcStages |= VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT;
2688 dstStages |= VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
2690 selfDeps.push_back(barrier);
2694 if (!selfDeps.empty())
2696 DE_ASSERT(srcStages != 0);
2697 DE_ASSERT(dstStages != 0);
2698 vk.cmdPipelineBarrier(commandBuffer, srcStages, dstStages, VK_DEPENDENCY_BY_REGION_BIT, 0, DE_NULL, 0, DE_NULL, (deUint32)selfDeps.size(), &selfDeps[0]);
2701 if (m_renderInfo.getRenderQuad())
2703 const VkDeviceSize offset = 0;
2704 const VkBuffer vertexBuffer = *m_vertexBuffer;
2706 vk.cmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
2708 if (m_descriptorSet)
2710 const VkDescriptorSet descriptorSet = *m_descriptorSet;
2711 vk.cmdBindDescriptorSets(commandBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipelineLayout, 0u, 1u, &descriptorSet, 0u, NULL);
2714 vk.cmdBindVertexBuffers(commandBuffer, 0u, 1u, &vertexBuffer, &offset);
2715 vk.cmdDraw(commandBuffer, 6u, 1u, 0u, 0u);
2720 const SubpassRenderInfo m_renderInfo;
2721 Move<VkCommandBuffer> m_commandBuffer;
2722 Move<VkPipeline> m_pipeline;
2723 Move<VkDescriptorSetLayout> m_descriptorSetLayout;
2724 Move<VkPipelineLayout> m_pipelineLayout;
2726 Move<VkShaderModule> m_vertexShaderModule;
2727 Move<VkShaderModule> m_fragmentShaderModule;
2729 Move<VkDescriptorPool> m_descriptorPool;
2730 Move<VkDescriptorSet> m_descriptorSet;
2731 Move<VkBuffer> m_vertexBuffer;
2732 de::MovePtr<Allocation> m_vertexBufferMemory;
2733 vector<VkImage> m_colorAttachmentImages;
2734 VkImage m_depthStencilAttachmentImage;
2737 void pushImageInitializationCommands (const DeviceInterface& vk,
2738 VkCommandBuffer commandBuffer,
2739 const vector<Attachment>& attachmentInfo,
2740 const vector<de::SharedPtr<AttachmentResources> >& attachmentResources,
2741 deUint32 queueIndex,
2742 const vector<Maybe<VkClearValue> >& clearValues)
2745 vector<VkImageMemoryBarrier> initializeLayouts;
2747 for (size_t attachmentNdx = 0; attachmentNdx < attachmentInfo.size(); attachmentNdx++)
2749 if (!clearValues[attachmentNdx])
2752 const VkImageMemoryBarrier barrier =
2754 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType;
2757 (VkAccessFlags)0, // srcAccessMask
2758 getAllMemoryReadFlags() | VK_ACCESS_TRANSFER_WRITE_BIT, // dstAccessMask
2760 VK_IMAGE_LAYOUT_UNDEFINED, // oldLayout
2761 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // newLayout;
2763 queueIndex, // srcQueueFamilyIndex;
2764 queueIndex, // destQueueFamilyIndex;
2766 attachmentResources[attachmentNdx]->getImage(), // image;
2767 { // subresourceRange;
2768 getImageAspectFlags(attachmentInfo[attachmentNdx].getFormat()), // aspect;
2771 0, // baseArraySlice;
2776 initializeLayouts.push_back(barrier);
2779 if (!initializeLayouts.empty())
2780 vk.cmdPipelineBarrier(commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT,
2781 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, (VkDependencyFlags)0,
2782 0, (const VkMemoryBarrier*)DE_NULL,
2783 0, (const VkBufferMemoryBarrier*)DE_NULL,
2784 (deUint32)initializeLayouts.size(), &initializeLayouts[0]);
2787 for (size_t attachmentNdx = 0; attachmentNdx < attachmentInfo.size(); attachmentNdx++)
2789 if (!clearValues[attachmentNdx])
2792 const tcu::TextureFormat format = mapVkFormat(attachmentInfo[attachmentNdx].getFormat());
2794 if (hasStencilComponent(format.order) || hasDepthComponent(format.order))
2796 const float clearNan = tcu::Float32::nan().asFloat();
2797 const float clearDepth = hasDepthComponent(format.order) ? clearValues[attachmentNdx]->depthStencil.depth : clearNan;
2798 const deUint32 clearStencil = hasStencilComponent(format.order) ? clearValues[attachmentNdx]->depthStencil.stencil : 0xDEu;
2799 const VkClearDepthStencilValue depthStencil =
2804 const VkImageSubresourceRange range =
2806 (VkImageAspectFlags)((hasDepthComponent(format.order) ? VK_IMAGE_ASPECT_DEPTH_BIT : 0)
2807 | (hasStencilComponent(format.order) ? VK_IMAGE_ASPECT_STENCIL_BIT : 0)),
2814 vk.cmdClearDepthStencilImage(commandBuffer, attachmentResources[attachmentNdx]->getImage(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &depthStencil, 1, &range);
2818 const VkImageSubresourceRange range =
2820 VK_IMAGE_ASPECT_COLOR_BIT, // aspectMask;
2823 0, // baseArrayLayer;
2826 const VkClearColorValue clearColor = clearValues[attachmentNdx]->color;
2828 vk.cmdClearColorImage(commandBuffer, attachmentResources[attachmentNdx]->getImage(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clearColor, 1, &range);
2833 vector<VkImageMemoryBarrier> renderPassLayouts;
2835 for (size_t attachmentNdx = 0; attachmentNdx < attachmentInfo.size(); attachmentNdx++)
2837 const VkImageLayout oldLayout = clearValues[attachmentNdx] ? VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL : VK_IMAGE_LAYOUT_UNDEFINED;
2838 const VkImageMemoryBarrier barrier =
2840 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType;
2843 getMemoryFlagsForLayout(oldLayout), // srcAccessMask
2844 getAllMemoryReadFlags() | getMemoryFlagsForLayout(attachmentInfo[attachmentNdx].getInitialLayout()), // dstAccessMask
2846 oldLayout, // oldLayout
2847 attachmentInfo[attachmentNdx].getInitialLayout(), // newLayout;
2849 queueIndex, // srcQueueFamilyIndex;
2850 queueIndex, // destQueueFamilyIndex;
2852 attachmentResources[attachmentNdx]->getImage(), // image;
2853 { // subresourceRange;
2854 getImageAspectFlags(attachmentInfo[attachmentNdx].getFormat()), // aspect;
2857 0, // baseArraySlice;
2862 renderPassLayouts.push_back(barrier);
2865 if (!renderPassLayouts.empty())
2866 vk.cmdPipelineBarrier(commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT,
2867 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, (VkDependencyFlags)0,
2868 0, (const VkMemoryBarrier*)DE_NULL,
2869 0, (const VkBufferMemoryBarrier*)DE_NULL,
2870 (deUint32)renderPassLayouts.size(), &renderPassLayouts[0]);
2874 template<typename RenderpassSubpass>
2875 void pushRenderPassCommands (const DeviceInterface& vk,
2876 VkCommandBuffer commandBuffer,
2877 VkRenderPass renderPass,
2878 VkFramebuffer framebuffer,
2879 const vector<de::SharedPtr<SubpassRenderer> >& subpassRenderers,
2880 const VkRect2D& renderArea,
2881 const vector<Maybe<VkClearValue> >& renderPassClearValues,
2882 TestConfig::RenderTypes render)
2884 const float clearNan = tcu::Float32::nan().asFloat();
2885 vector<VkClearValue> attachmentClearValues;
2886 const typename RenderpassSubpass::SubpassEndInfo subpassEndInfo (DE_NULL);
2888 for (size_t attachmentNdx = 0; attachmentNdx < renderPassClearValues.size(); attachmentNdx++)
2890 if (renderPassClearValues[attachmentNdx])
2891 attachmentClearValues.push_back(*renderPassClearValues[attachmentNdx]);
2893 attachmentClearValues.push_back(makeClearValueColorF32(clearNan, clearNan, clearNan, clearNan));
2897 for (size_t subpassNdx = 0; subpassNdx < subpassRenderers.size(); subpassNdx++)
2899 const VkSubpassContents contents = subpassRenderers[subpassNdx]->isSecondary() ? VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS : VK_SUBPASS_CONTENTS_INLINE;
2900 const typename RenderpassSubpass::SubpassBeginInfo subpassBeginInfo (DE_NULL, contents);
2901 const VkRenderPassBeginInfo renderPassBeginInfo = createRenderPassBeginInfo(renderPass,
2904 (deUint32)attachmentClearValues.size(),
2905 attachmentClearValues.empty() ? DE_NULL : &attachmentClearValues[0]);
2907 if (subpassNdx == 0)
2908 RenderpassSubpass::cmdBeginRenderPass(vk, commandBuffer, &renderPassBeginInfo, &subpassBeginInfo);
2910 RenderpassSubpass::cmdNextSubpass(vk, commandBuffer, &subpassBeginInfo, &subpassEndInfo);
2914 if (contents == VK_SUBPASS_CONTENTS_INLINE)
2916 subpassRenderers[subpassNdx]->pushRenderCommands(vk, commandBuffer);
2918 else if (contents == VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS)
2920 const VkCommandBuffer cmd = subpassRenderers[subpassNdx]->getCommandBuffer();
2921 vk.cmdExecuteCommands(commandBuffer, 1, &cmd);
2924 DE_FATAL("Invalid contents");
2928 RenderpassSubpass::cmdEndRenderPass(vk, commandBuffer, &subpassEndInfo);
2932 #ifndef CTS_USES_VULKANSC
2933 void pushDynamicRenderingCommands (const DeviceInterface& vk,
2934 VkCommandBuffer commandBuffer,
2935 const RenderPass& renderPassInfo,
2936 const vector<de::SharedPtr<AttachmentResources> >& attachmentResources,
2937 const vector<de::SharedPtr<SubpassRenderer> >& subpassRenderers,
2938 const VkRect2D& renderArea,
2939 const vector<Maybe<VkClearValue> >& renderPassClearValues,
2940 deUint32 queueIndex,
2941 TestConfig::RenderTypes renderType,
2942 bool secondaryCmdBufferCompletelyContainsDynamicRenderpass)
2944 DE_ASSERT(subpassRenderers.size() == 1);
2946 vector<VkImageMemoryBarrier> imageBarriersBeforeRendering;
2947 vector<VkImageMemoryBarrier> imageBarriersAfterRendering;
2949 const Subpass& subpassInfo = renderPassInfo.getSubpasses()[0];
2950 const vector<AttachmentReference>& colorAttachmentsInfo = subpassInfo.getColorAttachments();
2952 for (deUint32 i = 0 ; i < colorAttachmentsInfo.size() ; ++i)
2954 const AttachmentReference& colorAttachmentReference = colorAttachmentsInfo[i];
2955 const deUint32 colorAttachmentIndex = colorAttachmentReference.getAttachment();
2956 const Attachment& colorAttachmentInfo = renderPassInfo.getAttachments()[colorAttachmentIndex];
2958 const VkImageLayout initialLayout = colorAttachmentInfo.getInitialLayout();
2959 const VkImageLayout renderingLayout = colorAttachmentReference.getImageLayout();
2960 const VkImageLayout finalLayout = colorAttachmentInfo.getFinalLayout();
2962 const VkImageMemoryBarrier barrierBeforeRendering
2964 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
2967 getAllMemoryWriteFlags() | getMemoryFlagsForLayout(initialLayout), // srcAccessMask
2968 getMemoryFlagsForLayout(renderingLayout), // dstAccessMask
2970 initialLayout, // oldLayout
2971 renderingLayout, // newLayout
2973 queueIndex, // srcQueueFamilyIndex
2974 queueIndex, // destQueueFamilyIndex
2976 attachmentResources[colorAttachmentIndex]->getImage(), // image
2977 { // subresourceRange
2978 getImageAspectFlags(colorAttachmentInfo.getFormat()), // aspect;
2981 0, // baseArraySlice
2985 imageBarriersBeforeRendering.push_back(barrierBeforeRendering);
2987 const VkImageMemoryBarrier barrierAfterRendering
2989 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
2992 getMemoryFlagsForLayout(renderingLayout), // srcAccessMask
2993 getAllMemoryReadFlags() | getMemoryFlagsForLayout(finalLayout), // dstAccessMask
2995 renderingLayout, // oldLayout
2996 finalLayout, // newLayout
2998 queueIndex, // srcQueueFamilyIndex
2999 queueIndex, // destQueueFamilyIndex
3001 attachmentResources[colorAttachmentIndex]->getImage(), // image
3002 { // subresourceRange
3003 getImageAspectFlags(colorAttachmentInfo.getFormat()), // aspect;
3006 0, // baseArraySlice
3010 imageBarriersAfterRendering.push_back(barrierAfterRendering);
3013 const AttachmentReference& depthStencilAttachmentReference = subpassInfo.getDepthStencilAttachment();
3014 const deUint32 dsAttachmentIndex = depthStencilAttachmentReference.getAttachment();
3016 if (dsAttachmentIndex != VK_ATTACHMENT_UNUSED)
3018 const Attachment& dsAttachmentInfo = renderPassInfo.getAttachments()[dsAttachmentIndex];
3020 const VkImageLayout initialLayout = dsAttachmentInfo.getInitialLayout();
3021 const VkImageLayout renderingLayout = depthStencilAttachmentReference.getImageLayout();
3022 const VkImageLayout finalLayout = dsAttachmentInfo.getFinalLayout();
3024 const VkImageMemoryBarrier barrierBeforeRendering
3026 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
3029 getAllMemoryWriteFlags() | getMemoryFlagsForLayout(initialLayout), // srcAccessMask
3030 getMemoryFlagsForLayout(renderingLayout), // dstAccessMask
3032 initialLayout, // oldLayout
3033 renderingLayout, // newLayout
3035 queueIndex, // srcQueueFamilyIndex
3036 queueIndex, // destQueueFamilyIndex
3038 attachmentResources[dsAttachmentIndex]->getImage(), // image
3039 { // subresourceRange
3040 getImageAspectFlags(dsAttachmentInfo.getFormat()), // aspect;
3043 0, // baseArraySlice
3047 imageBarriersBeforeRendering.push_back(barrierBeforeRendering);
3049 const VkImageMemoryBarrier barrierAfterRendering
3051 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
3054 getMemoryFlagsForLayout(renderingLayout), // srcAccessMask
3055 getAllMemoryReadFlags() | getMemoryFlagsForLayout(finalLayout), // dstAccessMask
3057 renderingLayout, // oldLayout
3058 finalLayout, // newLayout
3060 queueIndex, // srcQueueFamilyIndex
3061 queueIndex, // destQueueFamilyIndex
3063 attachmentResources[dsAttachmentIndex]->getImage(), // image
3064 { // subresourceRange
3065 getImageAspectFlags(dsAttachmentInfo.getFormat()), // aspect;
3068 0, // baseArraySlice
3072 imageBarriersAfterRendering.push_back(barrierAfterRendering);
3075 if (!imageBarriersBeforeRendering.empty())
3076 vk.cmdPipelineBarrier(commandBuffer,
3077 getAllPipelineStageFlags(),
3078 getAllPipelineStageFlags(),
3079 (VkDependencyFlags)0,
3080 0, (const VkMemoryBarrier*)DE_NULL,
3081 0, (const VkBufferMemoryBarrier*)DE_NULL,
3082 (deUint32)imageBarriersBeforeRendering.size(),
3083 &imageBarriersBeforeRendering[0]);
3085 bool executeRenderCommands = (renderType != TestConfig::RENDERTYPES_NONE);
3087 if (secondaryCmdBufferCompletelyContainsDynamicRenderpass)
3089 // when secondary command buffer completely contains dynamic renderpass
3090 // then we need to execute it even when render type is none
3091 executeRenderCommands = true;
3095 VkRenderingFlagsKHR renderingFlags = 0u;
3096 if (subpassRenderers[0]->isSecondary())
3097 renderingFlags = VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR;
3099 beginDynamicRendering(vk, commandBuffer, renderPassInfo, attachmentResources, renderArea, renderPassClearValues, renderingFlags);
3102 if (executeRenderCommands)
3104 if (subpassRenderers[0]->isSecondary())
3106 const VkCommandBuffer cmd = subpassRenderers[0]->getCommandBuffer();
3107 vk.cmdExecuteCommands(commandBuffer, 1, &cmd);
3110 subpassRenderers[0]->pushRenderCommands(vk, commandBuffer);
3113 if (!secondaryCmdBufferCompletelyContainsDynamicRenderpass)
3114 endDynamicRendering(vk, commandBuffer);
3116 if (!imageBarriersAfterRendering.empty())
3117 vk.cmdPipelineBarrier(commandBuffer,
3118 getAllPipelineStageFlags(),
3119 getAllPipelineStageFlags(),
3120 (VkDependencyFlags)0,
3121 0, (const VkMemoryBarrier*)DE_NULL,
3122 0, (const VkBufferMemoryBarrier*)DE_NULL,
3123 (deUint32)imageBarriersAfterRendering.size(),
3124 &imageBarriersAfterRendering[0]);
3126 #endif // CTS_USES_VULKANSC
3128 void pushRenderPassCommands (const DeviceInterface& vk,
3129 VkCommandBuffer commandBuffer,
3130 VkRenderPass renderPass,
3131 const RenderPass& renderPassInfo,
3132 const vector<de::SharedPtr<AttachmentResources> >& attachmentResources,
3133 VkFramebuffer framebuffer,
3134 const vector<de::SharedPtr<SubpassRenderer> >& subpassRenderers,
3135 const VkRect2D& renderArea,
3136 const vector<Maybe<VkClearValue> >& renderPassClearValues,
3137 deUint32 queueIndex,
3138 TestConfig::RenderTypes render,
3139 RenderingType renderingType,
3140 bool secondaryCmdBufferCompletelyContainsDynamicRenderpass)
3142 // unreference arguments not used by Vulkan SC, no need to put them under ifdef
3143 DE_UNREF(renderPassInfo);
3144 DE_UNREF(attachmentResources);
3145 DE_UNREF(queueIndex);
3146 DE_UNREF(secondaryCmdBufferCompletelyContainsDynamicRenderpass);
3148 switch (renderingType)
3150 case RENDERING_TYPE_RENDERPASS_LEGACY:
3151 return pushRenderPassCommands<RenderpassSubpass1>(vk, commandBuffer, renderPass, framebuffer, subpassRenderers, renderArea, renderPassClearValues, render);
3152 case RENDERING_TYPE_RENDERPASS2:
3153 return pushRenderPassCommands<RenderpassSubpass2>(vk, commandBuffer, renderPass, framebuffer, subpassRenderers, renderArea, renderPassClearValues, render);
3155 #ifndef CTS_USES_VULKANSC
3156 case RENDERING_TYPE_DYNAMIC_RENDERING:
3157 return pushDynamicRenderingCommands(vk, commandBuffer, renderPassInfo, attachmentResources, subpassRenderers, renderArea, renderPassClearValues, queueIndex, render, secondaryCmdBufferCompletelyContainsDynamicRenderpass);
3158 #endif // CTS_USES_VULKANSC
3161 TCU_THROW(InternalError, "Impossible");
3165 void pushReadImagesToBuffers (const DeviceInterface& vk,
3166 VkCommandBuffer commandBuffer,
3167 deUint32 queueIndex,
3169 const vector<de::SharedPtr<AttachmentResources> >& attachmentResources,
3170 const vector<Attachment>& attachmentInfo,
3171 const vector<bool>& isLazy,
3173 const UVec2& targetSize)
3176 vector<VkImageMemoryBarrier> imageBarriers;
3178 for (size_t attachmentNdx = 0; attachmentNdx < attachmentInfo.size(); attachmentNdx++)
3180 if (isLazy[attachmentNdx])
3183 const VkImageLayout oldLayout = attachmentInfo[attachmentNdx].getFinalLayout();
3184 const VkImageMemoryBarrier barrier =
3186 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
3189 getAllMemoryWriteFlags() | getMemoryFlagsForLayout(oldLayout), // srcAccessMask
3190 getAllMemoryReadFlags(), // dstAccessMask
3192 oldLayout, // oldLayout
3193 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // newLayout
3195 queueIndex, // srcQueueFamilyIndex
3196 queueIndex, // destQueueFamilyIndex
3198 attachmentResources[attachmentNdx]->getImage(), // image
3199 { // subresourceRange
3200 getImageAspectFlags(attachmentInfo[attachmentNdx].getFormat()), // aspect;
3203 0, // baseArraySlice
3208 imageBarriers.push_back(barrier);
3211 if (!imageBarriers.empty())
3212 vk.cmdPipelineBarrier(commandBuffer,
3213 getAllPipelineStageFlags(),
3214 getAllPipelineStageFlags(),
3215 (VkDependencyFlags)0,
3216 0, (const VkMemoryBarrier*)DE_NULL,
3217 0, (const VkBufferMemoryBarrier*)DE_NULL,
3218 (deUint32)imageBarriers.size(), &imageBarriers[0]);
3221 for (size_t attachmentNdx = 0; attachmentNdx < attachmentInfo.size(); attachmentNdx++)
3223 if (isLazy[attachmentNdx])
3226 const tcu::TextureFormat::ChannelOrder order = mapVkFormat(attachmentInfo[attachmentNdx].getFormat()).order;
3227 const VkBufferImageCopy rect =
3230 0, // bufferRowLength
3231 0, // bufferImageHeight
3232 { // imageSubresource
3233 (vk::VkImageAspectFlags)getPrimaryImageAspect(mapVkFormat(attachmentInfo[attachmentNdx].getFormat()).order), // aspect
3238 { 0, 0, 0 }, // imageOffset
3239 { targetSize.x(), targetSize.y(), 1u } // imageExtent
3242 vk.cmdCopyImageToBuffer(commandBuffer, attachmentResources[attachmentNdx]->getImage(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, attachmentResources[attachmentNdx]->getBuffer(), 1, &rect);
3244 if (tcu::TextureFormat::DS == order)
3246 const VkBufferImageCopy stencilRect =
3249 0, // bufferRowLength
3250 0, // bufferImageHeight
3251 { // imageSubresource
3252 VK_IMAGE_ASPECT_STENCIL_BIT, // aspect
3257 { 0, 0, 0 }, // imageOffset
3258 { targetSize.x(), targetSize.y(), 1u } // imageExtent
3261 vk.cmdCopyImageToBuffer(commandBuffer, attachmentResources[attachmentNdx]->getImage(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, attachmentResources[attachmentNdx]->getSecondaryBuffer(), 1, &stencilRect);
3266 vector<VkBufferMemoryBarrier> bufferBarriers;
3268 for (size_t attachmentNdx = 0; attachmentNdx < attachmentInfo.size(); attachmentNdx++)
3270 if (isLazy[attachmentNdx])
3273 const tcu::TextureFormat::ChannelOrder order = mapVkFormat(attachmentInfo[attachmentNdx].getFormat()).order;
3274 const VkBufferMemoryBarrier bufferBarrier =
3276 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
3279 getAllMemoryWriteFlags(),
3280 getAllMemoryReadFlags(),
3285 attachmentResources[attachmentNdx]->getBuffer(),
3287 attachmentResources[attachmentNdx]->getBufferSize()
3290 bufferBarriers.push_back(bufferBarrier);
3292 if (tcu::TextureFormat::DS == order)
3294 const VkBufferMemoryBarrier secondaryBufferBarrier =
3296 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
3299 getAllMemoryWriteFlags(),
3300 getAllMemoryReadFlags(),
3305 attachmentResources[attachmentNdx]->getSecondaryBuffer(),
3307 attachmentResources[attachmentNdx]->getSecondaryBufferSize()
3310 bufferBarriers.push_back(secondaryBufferBarrier);
3314 if (!bufferBarriers.empty())
3315 vk.cmdPipelineBarrier(commandBuffer,
3316 getAllPipelineStageFlags(),
3317 getAllPipelineStageFlags(),
3318 (VkDependencyFlags)0,
3319 0, (const VkMemoryBarrier*)DE_NULL,
3320 (deUint32)bufferBarriers.size(), &bufferBarriers[0],
3321 0, (const VkImageMemoryBarrier*)DE_NULL);
3328 PixelValue (const Maybe<bool>& x = tcu::Nothing,
3329 const Maybe<bool>& y = tcu::Nothing,
3330 const Maybe<bool>& z = tcu::Nothing,
3331 const Maybe<bool>& w = tcu::Nothing);
3333 void setUndefined (size_t ndx);
3334 void setValue (size_t ndx, bool value);
3335 Maybe<bool> getValue (size_t ndx) const;
3341 PixelValue::PixelValue (const Maybe<bool>& x,
3342 const Maybe<bool>& y,
3343 const Maybe<bool>& z,
3344 const Maybe<bool>& w)
3347 const Maybe<bool> values[] =
3352 for (size_t ndx = 0; ndx < DE_LENGTH_OF_ARRAY(values); ndx++)
3355 setValue(ndx, *values[ndx]);
3360 DE_ASSERT(m_status <= 0xFFu);
3363 void PixelValue::setUndefined (size_t ndx)
3366 DE_ASSERT(m_status <= 0xFFu);
3368 m_status &= (deUint16)~(0x1u << (deUint16)(ndx * 2));
3369 DE_ASSERT(m_status <= 0xFFu);
3372 void PixelValue::setValue (size_t ndx, bool value)
3375 DE_ASSERT(m_status <= 0xFFu);
3377 m_status = (deUint16)(m_status | (deUint16)(0x1u << (ndx * 2)));
3380 m_status = (deUint16)(m_status | (deUint16)(0x1u << (ndx * 2 + 1)));
3382 m_status &= (deUint16)~(0x1u << (deUint16)(ndx * 2 + 1));
3384 DE_ASSERT(m_status <= 0xFFu);
3387 Maybe<bool> PixelValue::getValue (size_t ndx) const
3390 DE_ASSERT(m_status <= 0xFFu);
3392 if ((m_status & (0x1u << (deUint16)(ndx * 2))) != 0)
3394 return just((m_status & (0x1u << (deUint32)(ndx * 2 + 1))) != 0);
3397 return tcu::Nothing;
3400 void clearReferenceValues (vector<PixelValue>& values,
3401 const UVec2& targetSize,
3402 const UVec2& offset,
3405 const PixelValue& value)
3407 DE_ASSERT(targetSize.x() * targetSize.y() == (deUint32)values.size());
3408 DE_ASSERT(offset.x() + size.x() <= targetSize.x());
3409 DE_ASSERT(offset.y() + size.y() <= targetSize.y());
3411 for (deUint32 y = offset.y(); y < offset.y() + size.y(); y++)
3412 for (deUint32 x = offset.x(); x < offset.x() + size.x(); x++)
3414 for (int compNdx = 0; compNdx < 4; compNdx++)
3418 if (value.getValue(compNdx))
3419 values[x + y * targetSize.x()].setValue(compNdx, *value.getValue(compNdx));
3421 values[x + y * targetSize.x()].setUndefined(compNdx);
3427 void markUndefined (vector<PixelValue>& values,
3429 const UVec2& targetSize,
3430 const UVec2& offset,
3433 DE_ASSERT(targetSize.x() * targetSize.y() == (deUint32)values.size());
3435 for (deUint32 y = offset.y(); y < offset.y() + size.y(); y++)
3436 for (deUint32 x = offset.x(); x < offset.x() + size.x(); x++)
3438 for (int compNdx = 0; compNdx < 4; compNdx++)
3441 values[x + y * targetSize.x()].setUndefined(compNdx);
3446 PixelValue clearValueToPixelValue (const VkClearValue& value,
3447 const tcu::TextureFormat& format,
3448 const DepthValuesArray& depthValues)
3450 const bool isDepthAttachment = hasDepthComponent(format.order);
3451 const bool isStencilAttachment = hasStencilComponent(format.order);
3452 const bool isDepthOrStencilAttachment = isDepthAttachment || isStencilAttachment;
3453 PixelValue pixelValue;
3455 if (isDepthOrStencilAttachment)
3457 if (isDepthAttachment)
3459 if (value.depthStencil.depth == float(depthValues[1]) / 255.0f)
3460 pixelValue.setValue(0, true);
3461 else if (value.depthStencil.depth == float(depthValues[0]) / 255.0f)
3462 pixelValue.setValue(0, false);
3464 DE_FATAL("Unknown depth value");
3467 if (isStencilAttachment)
3469 if (value.depthStencil.stencil == 0xFFu)
3470 pixelValue.setValue(1, true);
3471 else if (value.depthStencil.stencil == 0x0u)
3472 pixelValue.setValue(1, false);
3474 DE_FATAL("Unknown stencil value");
3479 const tcu::TextureChannelClass channelClass = tcu::getTextureChannelClass(format.type);
3480 const tcu::BVec4 channelMask = tcu::getTextureFormatChannelMask(format);
3482 switch (channelClass)
3484 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
3485 for (int i = 0; i < 4; i++)
3489 if (value.color.int32[i] == 1)
3490 pixelValue.setValue(i, true);
3491 else if (value.color.int32[i] == 0)
3492 pixelValue.setValue(i, false);
3494 DE_FATAL("Unknown clear color value");
3499 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
3500 for (int i = 0; i < 4; i++)
3504 if (value.color.uint32[i] == 1u)
3505 pixelValue.setValue(i, true);
3506 else if (value.color.uint32[i] == 0u)
3507 pixelValue.setValue(i, false);
3509 DE_FATAL("Unknown clear color value");
3514 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
3515 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
3516 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
3517 for (int i = 0; i < 4; i++)
3521 if (value.color.float32[i] == 1.0f)
3522 pixelValue.setValue(i, true);
3523 else if (value.color.float32[i] == 0.0f)
3524 pixelValue.setValue(i, false);
3526 DE_FATAL("Unknown clear color value");
3532 DE_FATAL("Unknown channel class");
3539 void renderReferenceValues (vector<vector<PixelValue> >& referenceAttachments,
3540 const RenderPass& renderPassInfo,
3541 const UVec2& targetSize,
3542 const vector<Maybe<VkClearValue> >& imageClearValues,
3543 const vector<Maybe<VkClearValue> >& renderPassClearValues,
3544 const vector<SubpassRenderInfo>& subpassRenderInfo,
3545 const UVec2& renderPos,
3546 const UVec2& renderSize,
3547 const deUint32 drawStartNdx,
3548 const DepthValuesArray& depthValues)
3550 const vector<Subpass>& subpasses = renderPassInfo.getSubpasses();
3551 vector<bool> attachmentUsed (renderPassInfo.getAttachments().size(), false);
3553 referenceAttachments.resize(renderPassInfo.getAttachments().size());
3555 for (size_t attachmentNdx = 0; attachmentNdx < renderPassInfo.getAttachments().size(); attachmentNdx++)
3557 const Attachment attachment = renderPassInfo.getAttachments()[attachmentNdx];
3558 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3559 vector<PixelValue>& reference = referenceAttachments[attachmentNdx];
3561 reference.resize(targetSize.x() * targetSize.y());
3563 if (imageClearValues[attachmentNdx])
3564 clearReferenceValues(reference, targetSize, UVec2(0, 0), targetSize, BVec4(true), clearValueToPixelValue(*imageClearValues[attachmentNdx], format, depthValues));
3567 for (size_t subpassNdx = 0; subpassNdx < subpasses.size(); subpassNdx++)
3569 const Subpass& subpass = subpasses[subpassNdx];
3570 const SubpassRenderInfo& renderInfo = subpassRenderInfo[subpassNdx];
3571 const vector<AttachmentReference>& colorAttachments = subpass.getColorAttachments();
3573 // Apply load op if attachment was used for the first time
3574 for (size_t attachmentNdx = 0; attachmentNdx < colorAttachments.size(); attachmentNdx++)
3576 const deUint32 attachmentIndex = getAttachmentNdx(colorAttachments, attachmentNdx);
3578 if (!attachmentUsed[attachmentIndex] && colorAttachments[attachmentNdx].getAttachment() != VK_ATTACHMENT_UNUSED)
3580 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3581 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3582 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3584 DE_ASSERT(!tcu::hasDepthComponent(format.order));
3585 DE_ASSERT(!tcu::hasStencilComponent(format.order));
3587 if (attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_CLEAR)
3588 clearReferenceValues(reference, targetSize, renderPos, renderSize, BVec4(true), clearValueToPixelValue(*renderPassClearValues[attachmentIndex], format, depthValues));
3589 else if (attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE)
3590 markUndefined(reference, BVec4(true), targetSize, renderPos, renderSize);
3592 attachmentUsed[attachmentIndex] = true;
3596 // Apply load op to depth/stencil attachment if it was used for the first time
3597 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED)
3599 const deUint32 attachmentIndex = subpass.getDepthStencilAttachment().getAttachment();
3601 // Apply load op if attachment was used for the first time
3602 if (!attachmentUsed[attachmentIndex])
3604 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3605 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3606 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3608 if (tcu::hasDepthComponent(format.order))
3610 if (attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_CLEAR)
3611 clearReferenceValues(reference, targetSize, renderPos, renderSize, BVec4(true, false, false, false), clearValueToPixelValue(*renderPassClearValues[attachmentIndex], format, depthValues));
3612 else if (attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE)
3613 markUndefined(reference, BVec4(true, false, false, false), targetSize, renderPos, renderSize);
3616 if (tcu::hasStencilComponent(format.order))
3618 if (attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_CLEAR)
3619 clearReferenceValues(reference, targetSize, renderPos, renderSize, BVec4(false, true, false, false), clearValueToPixelValue(*renderPassClearValues[attachmentIndex], format, depthValues));
3620 else if (attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE)
3621 markUndefined(reference, BVec4(false, true, false, false), targetSize, renderPos, renderSize);
3624 attachmentUsed[attachmentIndex] = true;
3628 for (size_t colorClearNdx = 0; colorClearNdx < renderInfo.getColorClears().size(); colorClearNdx++)
3630 const ColorClear& colorClear = renderInfo.getColorClears()[colorClearNdx];
3631 const UVec2 offset = colorClear.getOffset();
3632 const UVec2 size = colorClear.getSize();
3633 const deUint32 attachmentIndex = subpass.getColorAttachments()[colorClearNdx].getAttachment();
3634 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3635 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3636 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3639 value.color = colorClear.getColor();
3641 clearReferenceValues(reference, targetSize, offset, size, BVec4(true), clearValueToPixelValue(value, format, depthValues));
3644 if (renderInfo.getDepthStencilClear())
3646 const DepthStencilClear& dsClear = *renderInfo.getDepthStencilClear();
3647 const UVec2 offset = dsClear.getOffset();
3648 const UVec2 size = dsClear.getSize();
3649 const deUint32 attachmentIndex = subpass.getDepthStencilAttachment().getAttachment();
3650 const VkImageLayout layout = subpass.getDepthStencilAttachment().getImageLayout();
3651 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3652 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3653 const bool hasStencil = tcu::hasStencilComponent(format.order)
3654 && layout != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL;
3655 const bool hasDepth = tcu::hasDepthComponent(format.order)
3656 && layout != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL;
3657 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3660 value.depthStencil.depth = dsClear.getDepth();
3661 value.depthStencil.stencil = dsClear.getStencil();
3663 clearReferenceValues(reference, targetSize, offset, size, BVec4(hasDepth, hasStencil, false, false), clearValueToPixelValue(value, format, depthValues));
3666 if (renderInfo.getRenderQuad())
3668 const RenderQuad& renderQuad = *renderInfo.getRenderQuad();
3669 const Vec2 posA = renderQuad.getCornerA();
3670 const Vec2 posB = renderQuad.getCornerB();
3671 const Vec2 origin = Vec2((float)renderInfo.getViewportOffset().x(), (float)renderInfo.getViewportOffset().y()) + Vec2((float)renderInfo.getViewportSize().x(), (float)renderInfo.getViewportSize().y()) / Vec2(2.0f);
3672 const Vec2 p = Vec2((float)renderInfo.getViewportSize().x(), (float)renderInfo.getViewportSize().y()) / Vec2(2.0f);
3673 const IVec2 posAI (deRoundFloatToInt32(origin.x() + (p.x() * posA.x())),
3674 deRoundFloatToInt32(origin.y() + (p.y() * posA.y())));
3675 const IVec2 posBI (deRoundFloatToInt32(origin.x() + (p.x() * posB.x())),
3676 deRoundFloatToInt32(origin.y() + (p.y() * posB.y())));
3678 DE_ASSERT(posAI.x() < posBI.x());
3679 DE_ASSERT(posAI.y() < posBI.y());
3681 if (subpass.getInputAttachments().empty())
3683 for (size_t attachmentRefNdx = drawStartNdx; attachmentRefNdx < subpass.getColorAttachments().size(); attachmentRefNdx++)
3685 const deUint32 attachmentIndex = subpass.getColorAttachments()[attachmentRefNdx].getAttachment();
3687 if (attachmentIndex == VK_ATTACHMENT_UNUSED)
3690 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3691 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3692 const tcu::BVec4 channelMask = tcu::getTextureFormatChannelMask(format);
3693 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3695 for (int y = posAI.y(); y < (int)posBI.y(); y++)
3696 for (int x = posAI.x(); x < (int)posBI.x(); x++)
3698 for (int compNdx = 0; compNdx < 4; compNdx++)
3700 const size_t index = subpassNdx + attachmentIndex + compNdx;
3701 const BoolOp op = boolOpFromIndex(index);
3702 const bool boolX = x % 2 == (int)(index % 2);
3703 const bool boolY = y % 2 == (int)((index / 2) % 2);
3705 if (channelMask[compNdx])
3706 reference[x + y * targetSize.x()].setValue(compNdx, performBoolOp(op, boolX, boolY));
3711 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED)
3713 const deUint32 attachmentIndex = subpass.getDepthStencilAttachment().getAttachment();
3714 const VkImageLayout layout = subpass.getDepthStencilAttachment().getImageLayout();
3715 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3716 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3717 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3719 for (int y = posAI.y(); y < (int)posBI.y(); y++)
3720 for (int x = posAI.x(); x < (int)posBI.x(); x++)
3722 if (tcu::hasDepthComponent(format.order)
3723 && layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
3724 && layout != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
3726 const size_t index = subpassNdx + 1;
3727 const BoolOp op = boolOpFromIndex(index);
3728 const bool boolX = x % 2 == (int)(index % 2);
3729 const bool boolY = y % 2 == (int)((index / 2) % 2);
3731 reference[x + y * targetSize.x()].setValue(0, performBoolOp(op, boolX, boolY));
3734 if (tcu::hasStencilComponent(format.order)
3735 && layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
3736 && layout != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL)
3738 const size_t index = subpassNdx;
3739 reference[x + y * targetSize.x()].setValue(1, (index % 2) == 0);
3746 size_t outputComponentCount = 0;
3747 vector<Maybe<bool> > inputs;
3749 DE_ASSERT(posAI.x() < posBI.x());
3750 DE_ASSERT(posAI.y() < posBI.y());
3752 for (size_t attachmentRefNdx = 0; attachmentRefNdx < subpass.getColorAttachments().size(); attachmentRefNdx++)
3754 const deUint32 attachmentIndex = subpass.getColorAttachments()[attachmentRefNdx].getAttachment();
3755 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3756 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3757 const int componentCount = tcu::getNumUsedChannels(format.order);
3759 outputComponentCount += (size_t)componentCount;
3762 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED
3763 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
3764 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
3766 const Attachment& attachment (renderPassInfo.getAttachments()[subpass.getDepthStencilAttachment().getAttachment()]);
3767 const tcu::TextureFormat format (mapVkFormat(attachment.getFormat()));
3769 if (tcu::hasDepthComponent(format.order))
3770 outputComponentCount++;
3773 if (outputComponentCount > 0)
3775 for (int y = posAI.y(); y < (int)posBI.y(); y++)
3776 for (int x = posAI.x(); x < (int)posBI.x(); x++)
3778 for (size_t inputAttachmentNdx = 0; inputAttachmentNdx < subpass.getInputAttachments().size(); inputAttachmentNdx++)
3780 const deUint32 attachmentIndex = subpass.getInputAttachments()[inputAttachmentNdx].getAttachment();
3781 const VkImageLayout layout = subpass.getInputAttachments()[inputAttachmentNdx].getImageLayout();
3782 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3783 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3784 const int componentCount = tcu::getNumUsedChannels(format.order);
3786 for (int compNdx = 0; compNdx < componentCount; compNdx++)
3788 if ((compNdx != 0 || layout != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL)
3789 && (compNdx != 1 || layout != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL))
3791 inputs.push_back(referenceAttachments[attachmentIndex][x + y * targetSize.x()].getValue(compNdx));
3796 const size_t inputsPerOutput = inputs.size() >= outputComponentCount
3797 ? ((inputs.size() / outputComponentCount)
3798 + ((inputs.size() % outputComponentCount) != 0 ? 1 : 0))
3801 size_t outputValueNdx = 0;
3803 for (size_t attachmentRefNdx = 0; attachmentRefNdx < subpass.getColorAttachments().size(); attachmentRefNdx++)
3805 const deUint32 attachmentIndex = subpass.getColorAttachments()[attachmentRefNdx].getAttachment();
3806 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3807 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3808 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3809 const int componentCount = tcu::getNumUsedChannels(format.order);
3811 for (int compNdx = 0; compNdx < componentCount; compNdx++)
3813 const size_t index = subpassNdx + attachmentIndex + outputValueNdx;
3814 const BoolOp op = boolOpFromIndex(index);
3815 const bool boolX = x % 2 == (int)(index % 2);
3816 const bool boolY = y % 2 == (int)((index / 2) % 2);
3817 Maybe<bool> output = tcu::just(performBoolOp(op, boolX, boolY));
3819 for (size_t i = 0; i < inputsPerOutput; i++)
3823 else if (!inputs[((outputValueNdx + compNdx) * inputsPerOutput + i) % inputs.size()])
3824 output = tcu::Nothing;
3826 output = (*output) == (*inputs[((outputValueNdx + compNdx) * inputsPerOutput + i) % inputs.size()]);
3830 reference[x + y * targetSize.x()].setValue(compNdx, *output);
3832 reference[x + y * targetSize.x()].setUndefined(compNdx);
3835 outputValueNdx += componentCount;
3838 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED
3839 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
3840 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
3842 const deUint32 attachmentIndex = subpass.getDepthStencilAttachment().getAttachment();
3843 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3844 const size_t index = subpassNdx + attachmentIndex;
3845 const BoolOp op = boolOpFromIndex(index);
3846 const bool boolX = x % 2 == (int)(index % 2);
3847 const bool boolY = y % 2 == (int)((index / 2) % 2);
3848 Maybe<bool> output = tcu::just(performBoolOp(op, boolX, boolY));
3850 for (size_t i = 0; i < inputsPerOutput; i++)
3854 else if (inputs[(outputValueNdx * inputsPerOutput + i) % inputs.size()])
3855 output = (*output) == (*inputs[(outputValueNdx * inputsPerOutput + i) % inputs.size()]);
3857 output = tcu::Nothing;
3861 reference[x + y * targetSize.x()].setValue(0, *output);
3863 reference[x + y * targetSize.x()].setUndefined(0);
3870 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED
3871 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
3872 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL)
3874 const deUint32 attachmentIndex = subpass.getDepthStencilAttachment().getAttachment();
3875 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3876 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3877 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3879 if (tcu::hasStencilComponent(format.order))
3881 for (int y = posAI.y(); y < (int)posBI.y(); y++)
3882 for (int x = posAI.x(); x < (int)posBI.x(); x++)
3884 const size_t index = subpassNdx;
3885 reference[x + y * targetSize.x()].setValue(1, (index % 2) == 0);
3893 // Mark all attachments that were used but not stored as undefined
3894 for (size_t attachmentIndex = 0; attachmentIndex < renderPassInfo.getAttachments().size(); attachmentIndex++)
3896 const Attachment attachment = renderPassInfo.getAttachments()[attachmentIndex];
3897 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3898 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3899 const bool isStencilAttachment = hasStencilComponent(format.order);
3900 const bool isDepthOrStencilAttachment = hasDepthComponent(format.order) || isStencilAttachment;
3902 if (attachmentUsed[attachmentIndex] && renderPassInfo.getAttachments()[attachmentIndex].getStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE)
3904 if (isDepthOrStencilAttachment)
3905 markUndefined(reference, BVec4(true, false, false, false), targetSize, renderPos, renderSize);
3907 markUndefined(reference, BVec4(true), targetSize, renderPos, renderSize);
3910 if (attachmentUsed[attachmentIndex] && isStencilAttachment && renderPassInfo.getAttachments()[attachmentIndex].getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE)
3911 markUndefined(reference, BVec4(false, true, false, false), targetSize, renderPos, renderSize);
3915 void renderReferenceImagesFromValues (vector<tcu::TextureLevel>& referenceImages,
3916 const vector<vector<PixelValue> >& referenceValues,
3917 const UVec2& targetSize,
3918 const RenderPass& renderPassInfo,
3919 const DepthValuesArray& depthValues)
3921 referenceImages.resize(referenceValues.size());
3923 for (size_t attachmentNdx = 0; attachmentNdx < renderPassInfo.getAttachments().size(); attachmentNdx++)
3925 const Attachment attachment = renderPassInfo.getAttachments()[attachmentNdx];
3926 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3927 const vector<PixelValue>& reference = referenceValues[attachmentNdx];
3928 const bool hasDepth = tcu::hasDepthComponent(format.order);
3929 const bool hasStencil = tcu::hasStencilComponent(format.order);
3930 const bool hasDepthOrStencil = hasDepth || hasStencil;
3931 tcu::TextureLevel& referenceImage = referenceImages[attachmentNdx];
3933 referenceImage.setStorage(format, targetSize.x(), targetSize.y());
3935 if (hasDepthOrStencil)
3939 const PixelBufferAccess depthAccess (tcu::getEffectiveDepthStencilAccess(referenceImage.getAccess(), tcu::Sampler::MODE_DEPTH));
3941 for (deUint32 y = 0; y < targetSize.y(); y++)
3942 for (deUint32 x = 0; x < targetSize.x(); x++)
3944 if (reference[x + y * targetSize.x()].getValue(0))
3946 if (*reference[x + y * targetSize.x()].getValue(0))
3947 depthAccess.setPixDepth(float(depthValues[1]) / 255.0f, x, y);
3949 depthAccess.setPixDepth(float(depthValues[0]) / 255.0f, x, y);
3951 else // Fill with 3x3 grid
3952 depthAccess.setPixDepth(((x / 3) % 2) == ((y / 3) % 2) ? 0.33f : 0.66f, x, y);
3958 const PixelBufferAccess stencilAccess (tcu::getEffectiveDepthStencilAccess(referenceImage.getAccess(), tcu::Sampler::MODE_STENCIL));
3960 for (deUint32 y = 0; y < targetSize.y(); y++)
3961 for (deUint32 x = 0; x < targetSize.x(); x++)
3963 if (reference[x + y * targetSize.x()].getValue(1))
3965 if (*reference[x + y * targetSize.x()].getValue(1))
3966 stencilAccess.setPixStencil(0xFFu, x, y);
3968 stencilAccess.setPixStencil(0x0u, x, y);
3970 else // Fill with 3x3 grid
3971 stencilAccess.setPixStencil(((x / 3) % 2) == ((y / 3) % 2) ? 85 : 170, x, y);
3977 for (deUint32 y = 0; y < targetSize.y(); y++)
3978 for (deUint32 x = 0; x < targetSize.x(); x++)
3982 for (int compNdx = 0; compNdx < 4; compNdx++)
3984 if (reference[x + y * targetSize.x()].getValue(compNdx))
3986 if (*reference[x + y * targetSize.x()].getValue(compNdx))
3987 color[compNdx] = 1.0f;
3989 color[compNdx] = 0.0f;
3991 else // Fill with 3x3 grid
3992 color[compNdx] = ((compNdx + (x / 3)) % 2) == ((y / 3) % 2) ? 0.33f : 0.66f;
3995 referenceImage.getAccess().setPixel(color, x, y);
4001 bool verifyColorAttachment (const vector<PixelValue>& reference,
4002 const ConstPixelBufferAccess& result,
4003 const PixelBufferAccess& errorImage,
4004 const deBool useFormatCompCount)
4006 const Vec4 red (1.0f, 0.0f, 0.0f, 1.0f);
4007 const Vec4 green (0.0f, 1.0f, 0.0f, 1.0f);
4010 DE_ASSERT(result.getWidth() * result.getHeight() == (int)reference.size());
4011 DE_ASSERT(result.getWidth() == errorImage.getWidth());
4012 DE_ASSERT(result.getHeight() == errorImage.getHeight());
4014 for (int y = 0; y < result.getHeight(); y++)
4015 for (int x = 0; x < result.getWidth(); x++)
4017 const Vec4 resultColor = result.getPixel(x, y);
4018 const PixelValue& referenceValue = reference[x + y * result.getWidth()];
4019 bool pixelOk = true;
4020 const deUint32 componentCount = useFormatCompCount ? (deUint32)tcu::getNumUsedChannels(result.getFormat().order) : 4;
4022 for (deUint32 compNdx = 0; compNdx < componentCount; compNdx++)
4024 const Maybe<bool> maybeValue = referenceValue.getValue(compNdx);
4028 const bool value = *maybeValue;
4030 if ((value && (resultColor[compNdx] != 1.0f))
4031 || (!value && resultColor[compNdx] != 0.0f))
4038 errorImage.setPixel(red, x, y);
4042 errorImage.setPixel(green, x, y);
4048 // Setting the alpha value to 1.0f by default helps visualization when the alpha channel is not used.
4049 const tcu::Vec4 kDefaultColorForLog {0.0f, 0.0f, 0.0f, 1.0f};
4050 const float kTrueComponent = 1.0f;
4051 const float kFalseComponent = 0.5f;
4052 const float kUnsetComponentLow = 0.0f;
4053 const float kUnsetComponentHigh = 0.25f;
4055 std::unique_ptr<tcu::TextureLevel> renderColorImageForLog (const ConstPixelBufferAccess& image, int numChannels)
4057 // Same channel order, but using UNORM_INT8 for the color format.
4058 const auto order = image.getFormat().order;
4059 const tcu::TextureFormat loggableFormat {order, tcu::TextureFormat::UNORM_INT8};
4060 const int width = image.getWidth();
4061 const int height = image.getHeight();
4062 std::unique_ptr<tcu::TextureLevel> result {new tcu::TextureLevel{loggableFormat, width, height}};
4063 auto access = result->getAccess();
4064 tcu::Vec4 outColor = kDefaultColorForLog;
4066 for (int x = 0; x < width; ++x)
4067 for (int y = 0; y < height; ++y)
4069 const auto value = image.getPixel(x, y);
4070 for (int c = 0; c < numChannels; ++c)
4072 if (value[c] == 0.0f)
4073 outColor[c] = kFalseComponent;
4074 else if (value[c] == 1.0f)
4075 outColor[c] = kTrueComponent;
4079 access.setPixel(outColor, x, y);
4085 std::unique_ptr<tcu::TextureLevel> renderColorImageForLog (const vector<PixelValue>& reference, const UVec2& targetSize, int numChannels)
4087 const tcu::TextureFormat loggableFormat {tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8};
4088 const int width = static_cast<int>(targetSize.x());
4089 const int height = static_cast<int>(targetSize.y());
4090 std::unique_ptr<tcu::TextureLevel> result {new tcu::TextureLevel{loggableFormat, width, height}};
4091 auto access = result->getAccess();
4092 tcu::Vec4 outColor = kDefaultColorForLog;
4094 for (int x = 0; x < width; ++x)
4095 for (int y = 0; y < height; ++y)
4097 const int index = x + y * width;
4098 for (int c = 0; c < numChannels; ++c)
4100 const auto maybeValue = reference[index].getValue(c);
4102 outColor[c] = ((*maybeValue) ? kTrueComponent : kFalseComponent);
4104 outColor[c] = ((((x / 3) % 2) == ((y / 3) % 2)) ? kUnsetComponentLow : kUnsetComponentHigh);
4106 access.setPixel(outColor, x, y);
4112 bool verifyDepthAttachment (const vector<PixelValue>& reference,
4113 const ConstPixelBufferAccess& result,
4114 const PixelBufferAccess& errorImage,
4115 const DepthValuesArray& depthValues,
4118 const Vec4 red (1.0f, 0.0f, 0.0f, 1.0f);
4119 const Vec4 green (0.0f, 1.0f, 0.0f, 1.0f);
4122 DE_ASSERT(result.getWidth() * result.getHeight() == (int)reference.size());
4123 DE_ASSERT(result.getWidth() == errorImage.getWidth());
4124 DE_ASSERT(result.getHeight() == errorImage.getHeight());
4126 for (int y = 0; y < result.getHeight(); y++)
4127 for (int x = 0; x < result.getWidth(); x++)
4129 bool pixelOk = true;
4131 const float resultDepth = result.getPixDepth(x, y);
4132 const PixelValue& referenceValue = reference[x + y * result.getWidth()];
4133 const Maybe<bool> maybeValue = referenceValue.getValue(0);
4137 const bool value = *maybeValue;
4139 if ((value && !depthsEqual(resultDepth, float(depthValues[1]) / 255.0f, epsilon))
4140 || (!value && !depthsEqual(resultDepth, float(depthValues[0]) / 255.0f, epsilon)))
4146 errorImage.setPixel(red, x, y);
4150 errorImage.setPixel(green, x, y);
4156 bool verifyStencilAttachment (const vector<PixelValue>& reference,
4157 const ConstPixelBufferAccess& result,
4158 const PixelBufferAccess& errorImage)
4160 const Vec4 red (1.0f, 0.0f, 0.0f, 1.0f);
4161 const Vec4 green (0.0f, 1.0f, 0.0f, 1.0f);
4164 DE_ASSERT(result.getWidth() * result.getHeight() == (int)reference.size());
4165 DE_ASSERT(result.getWidth() == errorImage.getWidth());
4166 DE_ASSERT(result.getHeight() == errorImage.getHeight());
4168 for (int y = 0; y < result.getHeight(); y++)
4169 for (int x = 0; x < result.getWidth(); x++)
4171 bool pixelOk = true;
4173 const deUint32 resultStencil = result.getPixStencil(x, y);
4174 const PixelValue& referenceValue = reference[x + y * result.getWidth()];
4175 const Maybe<bool> maybeValue = referenceValue.getValue(1);
4179 const bool value = *maybeValue;
4181 if ((value && (resultStencil != 0xFFu))
4182 || (!value && resultStencil != 0x0u))
4188 errorImage.setPixel(red, x, y);
4192 errorImage.setPixel(green, x, y);
4198 bool logAndVerifyImages (TestLog& log,
4199 const DeviceInterface& vk,
4201 const vector<de::SharedPtr<AttachmentResources> >& attachmentResources,
4202 const vector<bool>& attachmentIsLazy,
4203 const RenderPass& renderPassInfo,
4204 const vector<Maybe<VkClearValue> >& renderPassClearValues,
4205 const vector<Maybe<VkClearValue> >& imageClearValues,
4206 const vector<SubpassRenderInfo>& subpassRenderInfo,
4207 const UVec2& targetSize,
4208 const TestConfig& config)
4210 vector<vector<PixelValue> > referenceValues;
4211 vector<tcu::TextureLevel> referenceAttachments;
4214 log << TestLog::Message << "Reference images fill undefined pixels with 3x3 grid pattern." << TestLog::EndMessage;
4216 renderReferenceValues(referenceValues, renderPassInfo, targetSize, imageClearValues, renderPassClearValues, subpassRenderInfo, config.renderPos, config.renderSize, config.drawStartNdx, config.depthValues);
4217 renderReferenceImagesFromValues(referenceAttachments, referenceValues, targetSize, renderPassInfo, config.depthValues);
4219 for (size_t attachmentNdx = 0; attachmentNdx < renderPassInfo.getAttachments().size(); attachmentNdx++)
4221 if (!attachmentIsLazy[attachmentNdx])
4223 bool attachmentOK = true;
4224 const Attachment attachment = renderPassInfo.getAttachments()[attachmentNdx];
4225 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
4227 if (tcu::hasDepthComponent(format.order) && tcu::hasStencilComponent(format.order))
4229 const tcu::TextureFormat depthFormat = getDepthCopyFormat(attachment.getFormat());
4230 void* const depthPtr = attachmentResources[attachmentNdx]->getResultMemory().getHostPtr();
4232 const tcu::TextureFormat stencilFormat = getStencilCopyFormat(attachment.getFormat());
4233 void* const stencilPtr = attachmentResources[attachmentNdx]->getSecondaryResultMemory().getHostPtr();
4235 invalidateAlloc(vk, device, attachmentResources[attachmentNdx]->getResultMemory());
4236 invalidateAlloc(vk, device, attachmentResources[attachmentNdx]->getSecondaryResultMemory());
4239 bool depthOK = true;
4240 bool stencilOK = true;
4241 const ConstPixelBufferAccess depthAccess (depthFormat, targetSize.x(), targetSize.y(), 1, depthPtr);
4242 const ConstPixelBufferAccess stencilAccess (stencilFormat, targetSize.x(), targetSize.y(), 1, stencilPtr);
4243 tcu::TextureLevel depthErrorImage (tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), targetSize.x(), targetSize.y());
4244 tcu::TextureLevel stencilErrorImage (tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), targetSize.x(), targetSize.y());
4246 if (renderPassInfo.getAttachments()[attachmentNdx].getStoreOp() == VK_ATTACHMENT_STORE_OP_STORE
4247 && !verifyDepthAttachment(referenceValues[attachmentNdx], depthAccess, depthErrorImage.getAccess(), config.depthValues, requiredDepthEpsilon(attachment.getFormat())))
4252 if (renderPassInfo.getAttachments()[attachmentNdx].getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_STORE
4253 && !verifyStencilAttachment(referenceValues[attachmentNdx], stencilAccess, stencilErrorImage.getAccess()))
4258 if (!depthOK || !stencilOK)
4260 const auto attachmentNdxStr = de::toString(attachmentNdx);
4263 log << TestLog::ImageSet("OutputAttachments" + attachmentNdxStr, "Output depth and stencil attachments " + attachmentNdxStr);
4264 log << TestLog::Image("Attachment" + attachmentNdxStr + "Depth", "Attachment " + attachmentNdxStr + " Depth", depthAccess);
4265 log << TestLog::Image("Attachment" + attachmentNdxStr + "Stencil", "Attachment " + attachmentNdxStr + " Stencil", stencilAccess);
4266 log << TestLog::EndImageSet;
4268 // Reference images. These will be logged as image sets due to having depth and stencil aspects.
4269 log << TestLog::Image("AttachmentReferences" + attachmentNdxStr, "Reference images " + attachmentNdxStr, referenceAttachments[attachmentNdx].getAccess());
4272 log << TestLog::ImageSet("ErrorMasks" + attachmentNdxStr, "Error masks " + attachmentNdxStr);
4274 log << TestLog::Image("DepthAttachmentError" + attachmentNdxStr, "Depth Attachment Error " + attachmentNdxStr, depthErrorImage.getAccess());
4276 log << TestLog::Image("StencilAttachmentError" + attachmentNdxStr, "Stencil Attachment Error " + attachmentNdxStr, stencilErrorImage.getAccess());
4277 log << TestLog::EndImageSet;
4279 attachmentOK = false;
4285 void* const ptr = attachmentResources[attachmentNdx]->getResultMemory().getHostPtr();
4287 invalidateAlloc(vk, device, attachmentResources[attachmentNdx]->getResultMemory());
4289 bool depthOK = true;
4290 bool stencilOK = true;
4291 bool colorOK = true;
4292 const ConstPixelBufferAccess access (format, targetSize.x(), targetSize.y(), 1, ptr);
4293 tcu::TextureLevel errorImage (tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), targetSize.x(), targetSize.y());
4295 if (tcu::hasDepthComponent(format.order))
4297 if ((renderPassInfo.getAttachments()[attachmentNdx].getStoreOp() == VK_ATTACHMENT_STORE_OP_STORE || renderPassInfo.getAttachments()[attachmentNdx].getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_STORE)
4298 && !verifyDepthAttachment(referenceValues[attachmentNdx], access, errorImage.getAccess(), config.depthValues, requiredDepthEpsilon(attachment.getFormat())))
4303 else if (tcu::hasStencilComponent(format.order))
4305 if ((renderPassInfo.getAttachments()[attachmentNdx].getStoreOp() == VK_ATTACHMENT_STORE_OP_STORE || renderPassInfo.getAttachments()[attachmentNdx].getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_STORE)
4306 && !verifyStencilAttachment(referenceValues[attachmentNdx], access, errorImage.getAccess()))
4313 if ((renderPassInfo.getAttachments()[attachmentNdx].getStoreOp() == VK_ATTACHMENT_STORE_OP_STORE || renderPassInfo.getAttachments()[attachmentNdx].getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_STORE)
4314 && !verifyColorAttachment(referenceValues[attachmentNdx], access, errorImage.getAccess(), config.useFormatCompCount))
4320 if (!depthOK || !stencilOK || !colorOK)
4322 log << TestLog::ImageSet("TestImages", "Output attachment, reference image and error mask");
4323 if (!depthOK || !stencilOK)
4325 // Log without conversions.
4326 log << TestLog::Image("Attachment" + de::toString(attachmentNdx), "Attachment " + de::toString(attachmentNdx), access);
4327 log << TestLog::Image("AttachmentReference" + de::toString(attachmentNdx), "Attachment reference " + de::toString(attachmentNdx), referenceAttachments[attachmentNdx].getAccess());
4331 // Convert color images to better reflect test status and output in any format.
4332 const auto numChannels = tcu::getNumUsedChannels(access.getFormat().order);
4333 const auto attachmentForLog = renderColorImageForLog(access, numChannels);
4334 const auto referenceForLog = renderColorImageForLog(referenceValues[attachmentNdx], targetSize, numChannels);
4336 log << TestLog::Message << "Check the attachment formats and test data to verify which components affect the test result." << TestLog::EndMessage;
4337 log << TestLog::Message << "In the reference image, unset pixel components are marked with a 3x3 grid storing values 0.0 and 0.25, pixel components set to false are stored as 0.5 and pixel components set to true are stored as 1.0." << TestLog::EndMessage;
4338 log << TestLog::Message << "Output attachment pixel components are always set to 0.5 or 1.0 but may not be taken into account if not set in the reference image." << TestLog::EndMessage;
4340 log << TestLog::Image("Attachment" + de::toString(attachmentNdx), "Attachment " + de::toString(attachmentNdx), attachmentForLog->getAccess());
4341 log << TestLog::Image("AttachmentReference" + de::toString(attachmentNdx), "Attachment reference " + de::toString(attachmentNdx), referenceForLog->getAccess());
4343 log << TestLog::Image("AttachmentError" + de::toString(attachmentNdx), "Attachment Error " + de::toString(attachmentNdx), errorImage.getAccess());
4344 log << TestLog::EndImageSet;
4346 attachmentOK = false;
4358 std::string getInputAttachmentType (VkFormat vkFormat)
4360 const tcu::TextureFormat format = mapVkFormat(vkFormat);
4361 const tcu::TextureChannelClass channelClass = tcu::getTextureChannelClass(format.type);
4363 switch (channelClass)
4365 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
4366 return "isubpassInput";
4368 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
4369 return "usubpassInput";
4371 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
4372 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
4373 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
4374 return "subpassInput";
4377 DE_FATAL("Unknown channel class");
4382 std::string getAttachmentType (VkFormat vkFormat, deBool useFormatCompCount)
4384 const tcu::TextureFormat format = mapVkFormat(vkFormat);
4385 const tcu::TextureChannelClass channelClass = tcu::getTextureChannelClass(format.type);
4386 const size_t componentCount = (size_t)tcu::getNumUsedChannels(format.order);
4388 switch (channelClass)
4390 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
4391 if (useFormatCompCount)
4392 return (componentCount == 1 ? "int" : "ivec" + de::toString(componentCount));
4396 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
4397 if (useFormatCompCount)
4398 return (componentCount == 1 ? "uint" : "uvec" + de::toString(componentCount));
4402 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
4403 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
4404 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
4405 if (useFormatCompCount)
4406 return (componentCount == 1 ? "float" : "vec" + de::toString(componentCount));
4411 DE_FATAL("Unknown channel class");
4416 void createTestShaders (SourceCollections& dst, TestConfig config)
4418 if (config.renderTypes & TestConfig::RENDERTYPES_DRAW)
4420 const vector<Subpass>& subpasses = config.renderPass.getSubpasses();
4422 for (size_t subpassNdx = 0; subpassNdx < subpasses.size(); subpassNdx++)
4424 const Subpass& subpass = subpasses[subpassNdx];
4425 deUint32 inputAttachmentBinding = 0;
4426 std::ostringstream vertexShader;
4427 std::ostringstream fragmentShader;
4429 vertexShader << "#version 310 es\n"
4430 << "layout(location = 0) in highp vec2 a_position;\n"
4431 << "void main (void) {\n"
4432 << "\tgl_Position = vec4(a_position, 1.0, 1.0);\n"
4435 fragmentShader << "#version 310 es\n"
4436 << "precision highp float;\n";
4438 bool hasAnyDepthFormats = false;
4440 for (size_t attachmentNdx = config.drawStartNdx; attachmentNdx < subpass.getInputAttachments().size(); attachmentNdx++)
4442 const deUint32 attachmentIndex = subpass.getInputAttachments()[attachmentNdx].getAttachment();
4443 const VkImageLayout layout = subpass.getInputAttachments()[attachmentNdx].getImageLayout();
4444 const Attachment attachment = config.renderPass.getAttachments()[attachmentIndex];
4445 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
4446 const bool isDepthFormat = tcu::hasDepthComponent(format.order);
4447 const bool isStencilFormat = tcu::hasStencilComponent(format.order);
4449 if (isDepthFormat || isStencilFormat)
4451 if (isDepthFormat && layout != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL)
4453 hasAnyDepthFormats = true;
4454 fragmentShader << "layout(input_attachment_index = " << attachmentNdx << ", set=0, binding=" << inputAttachmentBinding << ") uniform highp subpassInput i_depth" << attachmentNdx << ";\n";
4455 inputAttachmentBinding++;
4458 if (isStencilFormat && layout != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
4460 fragmentShader << "layout(input_attachment_index = " << attachmentNdx << ", set=0, binding=" << inputAttachmentBinding << ") uniform highp usubpassInput i_stencil" << attachmentNdx << ";\n";
4461 inputAttachmentBinding++;
4466 const std::string attachmentType = getInputAttachmentType(attachment.getFormat());
4468 fragmentShader << "layout(input_attachment_index = " << attachmentNdx << ", set=0, binding=" << inputAttachmentBinding << ") uniform highp " << attachmentType << " i_color" << attachmentNdx << ";\n";
4469 inputAttachmentBinding++;
4473 for (size_t attachmentNdx = config.drawStartNdx; attachmentNdx < subpass.getColorAttachments().size(); attachmentNdx++)
4475 const std::string attachmentType = getAttachmentType(config.renderPass.getAttachments()[getAttachmentNdx(subpass.getColorAttachments(), attachmentNdx)].getFormat(), config.useFormatCompCount);
4476 fragmentShader << "layout(location = " << attachmentNdx << ") out highp " << attachmentType << " o_color" << attachmentNdx << ";\n";
4479 if (hasAnyDepthFormats)
4480 fragmentShader << "\nbool depthsEqual(float a, float b, float epsilon) {\n"
4481 << "\treturn abs(a - b) <= epsilon;\n}\n\n";
4483 fragmentShader << "void main (void) {\n";
4485 if (subpass.getInputAttachments().empty())
4487 for (size_t attachmentNdx = config.drawStartNdx; attachmentNdx < subpass.getColorAttachments().size(); attachmentNdx++)
4489 const deUint32 attachmentIndex = subpass.getColorAttachments()[attachmentNdx].getAttachment();
4491 if (attachmentIndex == VK_ATTACHMENT_UNUSED)
4494 const Attachment attachment = config.renderPass.getAttachments()[attachmentIndex];
4495 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
4496 const size_t componentCount = config.useFormatCompCount ? (size_t)tcu::getNumUsedChannels(format.order) : 4;
4497 const std::string attachmentType = getAttachmentType(attachment.getFormat(), config.useFormatCompCount);
4499 fragmentShader << "\to_color" << attachmentNdx << " = " << attachmentType << "(" << attachmentType + "(";
4501 for (size_t compNdx = 0; compNdx < componentCount; compNdx++)
4503 const size_t index = subpassNdx + attachmentIndex + compNdx;
4504 const BoolOp op = boolOpFromIndex(index);
4507 fragmentShader << ",\n\t\t";
4509 fragmentShader << "((int(gl_FragCoord.x) % 2 == " << (index % 2)
4510 << ") " << boolOpToString(op) << " ("
4511 << "int(gl_FragCoord.y) % 2 == " << ((index / 2) % 2)
4512 << ") ? 1.0 : 0.0)";
4515 fragmentShader << "));\n";
4518 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED
4519 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
4520 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
4522 const size_t index = subpassNdx + 1;
4523 const BoolOp op = boolOpFromIndex(index);
4525 fragmentShader << "\tgl_FragDepth = ((int(gl_FragCoord.x) % 2 == " << (index % 2)
4526 << ") " << boolOpToString(op) << " ("
4527 << "int(gl_FragCoord.y) % 2 == " << ((index / 2) % 2)
4528 << ") ? " << deUint32(config.depthValues[1]) << ".0f/255.0f : " << deUint32(config.depthValues[0]) << ".0f/255.0f);\n";
4533 size_t inputComponentCount = 0;
4534 size_t outputComponentCount = 0;
4536 for (size_t attachmentNdx = config.drawStartNdx; attachmentNdx < subpass.getInputAttachments().size(); attachmentNdx++)
4538 const deUint32 attachmentIndex = subpass.getInputAttachments()[attachmentNdx].getAttachment();
4539 const VkImageLayout layout = subpass.getInputAttachments()[attachmentNdx].getImageLayout();
4540 const Attachment attachment = config.renderPass.getAttachments()[attachmentIndex];
4541 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
4542 const size_t componentCount = (size_t)tcu::getNumUsedChannels(format.order);
4544 if (layout == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
4545 inputComponentCount += 1;
4546 else if (layout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL)
4547 inputComponentCount += 1;
4549 inputComponentCount += componentCount;
4552 for (size_t attachmentNdx = config.drawStartNdx; attachmentNdx < subpass.getColorAttachments().size(); attachmentNdx++)
4554 const deUint32 attachmentIndex = subpass.getColorAttachments()[attachmentNdx].getAttachment();
4555 const Attachment attachment = config.renderPass.getAttachments()[attachmentIndex];
4556 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
4557 const size_t componentCount = (size_t)tcu::getNumUsedChannels(format.order);
4559 outputComponentCount += componentCount;
4562 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED
4563 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
4564 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
4566 outputComponentCount++;
4569 if (outputComponentCount > 0)
4571 const size_t inputsPerOutput = inputComponentCount >= outputComponentCount
4572 ? ((inputComponentCount / outputComponentCount)
4573 + ((inputComponentCount % outputComponentCount) != 0 ? 1 : 0))
4576 fragmentShader << "\tbool inputs[" << inputComponentCount << "];\n";
4578 if (outputComponentCount > 0)
4579 fragmentShader << "\tbool outputs[" << outputComponentCount << "];\n";
4581 size_t inputValueNdx = 0;
4583 for (size_t attachmentNdx = config.drawStartNdx; attachmentNdx < subpass.getInputAttachments().size(); attachmentNdx++)
4585 const char* const components[] =
4589 const deUint32 attachmentIndex = subpass.getInputAttachments()[attachmentNdx].getAttachment();
4590 const VkImageLayout layout = subpass.getInputAttachments()[attachmentNdx].getImageLayout();
4591 const Attachment attachment = config.renderPass.getAttachments()[attachmentIndex];
4592 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
4593 const size_t componentCount = (size_t)tcu::getNumUsedChannels(format.order);
4594 const bool isDepthFormat = tcu::hasDepthComponent(format.order);
4595 const bool isStencilFormat = tcu::hasStencilComponent(format.order);
4597 if (isDepthFormat || isStencilFormat)
4599 if (isDepthFormat && layout != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL)
4601 fragmentShader << "\tinputs[" << inputValueNdx << "] = depthsEqual(" << deUint32(config.depthValues[1]) <<
4602 ".0f/255.0f, float(subpassLoad(i_depth" << attachmentNdx << ").x), " <<
4603 std::fixed << std::setprecision(12) << requiredDepthEpsilon(attachment.getFormat()) << ");\n";
4607 if (isStencilFormat && layout != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
4609 fragmentShader << "\tinputs[" << inputValueNdx << "] = 255u == subpassLoad(i_stencil" << attachmentNdx << ").x;\n";
4615 for (size_t compNdx = 0; compNdx < componentCount; compNdx++)
4617 fragmentShader << "\tinputs[" << inputValueNdx << "] = 1.0 == float(subpassLoad(i_color" << attachmentNdx << ")." << components[compNdx] << ");\n";
4623 size_t outputValueNdx = 0;
4625 for (size_t attachmentNdx = config.drawStartNdx; attachmentNdx < subpass.getColorAttachments().size(); attachmentNdx++)
4627 const deUint32 attachmentIndex = subpass.getColorAttachments()[attachmentNdx].getAttachment();
4628 const Attachment attachment = config.renderPass.getAttachments()[attachmentIndex];
4629 const std::string attachmentType = getAttachmentType(config.renderPass.getAttachments()[attachmentIndex].getFormat(), config.useFormatCompCount);
4630 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
4631 const size_t componentCount = (size_t)tcu::getNumUsedChannels(format.order);
4633 for (size_t compNdx = 0; compNdx < componentCount; compNdx++)
4635 const size_t index = subpassNdx + attachmentIndex + outputValueNdx;
4636 const BoolOp op = boolOpFromIndex(index);
4638 fragmentShader << "\toutputs[" << outputValueNdx + compNdx << "] = "
4639 << "(int(gl_FragCoord.x) % 2 == " << (index % 2)
4640 << ") " << boolOpToString(op) << " ("
4641 << "int(gl_FragCoord.y) % 2 == " << ((index / 2) % 2)
4644 for (size_t i = 0; i < inputsPerOutput; i++)
4645 fragmentShader << "\toutputs[" << outputValueNdx + compNdx << "] = outputs[" << outputValueNdx + compNdx << "] == inputs[" << ((outputValueNdx + compNdx) * inputsPerOutput + i) % inputComponentCount << "];\n";
4648 fragmentShader << "\to_color" << attachmentNdx << " = " << attachmentType << "(";
4650 for (size_t compNdx = 0; compNdx < (config.useFormatCompCount ? componentCount : 4); compNdx++)
4653 fragmentShader << ", ";
4655 if (compNdx < componentCount)
4656 fragmentShader << "outputs[" << outputValueNdx + compNdx << "]";
4658 fragmentShader << "0";
4661 outputValueNdx += componentCount;
4663 fragmentShader << ");\n";
4666 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED
4667 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
4668 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
4670 const deUint32 attachmentIndex = subpass.getDepthStencilAttachment().getAttachment();
4671 const size_t index = subpassNdx + attachmentIndex;
4672 const BoolOp op = boolOpFromIndex(index);
4674 fragmentShader << "\toutputs[" << outputValueNdx << "] = "
4675 << "(int(gl_FragCoord.x) % 2 == " << (index % 2)
4676 << ") " << boolOpToString(op) << " ("
4677 << "int(gl_FragCoord.y) % 2 == " << ((index / 2) % 2)
4680 for (size_t i = 0; i < inputsPerOutput; i++)
4681 fragmentShader << "\toutputs[" << outputValueNdx << "] = outputs[" << outputValueNdx << "] == inputs[" << (outputValueNdx * inputsPerOutput + i) % inputComponentCount << "];\n";
4683 fragmentShader << "\tgl_FragDepth = outputs[" << outputValueNdx << "] ? " << deUint32(config.depthValues[1]) << ".0f/255.0f : " << deUint32(config.depthValues[0]) << ".0f/255.0f;\n";
4688 fragmentShader << "}\n";
4690 dst.glslSources.add(de::toString(subpassNdx) + "-vert") << glu::VertexSource(vertexShader.str());
4691 dst.glslSources.add(de::toString(subpassNdx) + "-frag") << glu::FragmentSource(fragmentShader.str());
4696 void initializeAttachmentIsLazy (vector<bool>& attachmentIsLazy, const vector<Attachment>& attachments, TestConfig::ImageMemory imageMemory)
4698 bool lastAttachmentWasLazy = false;
4700 for (size_t attachmentNdx = 0; attachmentNdx < attachments.size(); attachmentNdx++)
4702 if (attachments[attachmentNdx].getLoadOp() != VK_ATTACHMENT_LOAD_OP_LOAD
4703 && attachments[attachmentNdx].getStoreOp() != VK_ATTACHMENT_STORE_OP_STORE
4704 && attachments[attachmentNdx].getStencilLoadOp() != VK_ATTACHMENT_LOAD_OP_LOAD
4705 && attachments[attachmentNdx].getStencilStoreOp() != VK_ATTACHMENT_STORE_OP_STORE)
4707 if (imageMemory == TestConfig::IMAGEMEMORY_LAZY || (imageMemory & TestConfig::IMAGEMEMORY_LAZY && !lastAttachmentWasLazy))
4709 attachmentIsLazy.push_back(true);
4711 lastAttachmentWasLazy = true;
4713 else if (imageMemory & TestConfig::IMAGEMEMORY_STRICT)
4715 attachmentIsLazy.push_back(false);
4716 lastAttachmentWasLazy = false;
4719 DE_FATAL("Unknown imageMemory");
4722 attachmentIsLazy.push_back(false);
4726 enum AttachmentRefType
4728 ATTACHMENTREFTYPE_COLOR,
4729 ATTACHMENTREFTYPE_DEPTH_STENCIL,
4730 ATTACHMENTREFTYPE_INPUT,
4731 ATTACHMENTREFTYPE_RESOLVE,
4734 VkImageUsageFlags getImageUsageFromLayout (VkImageLayout layout)
4738 case VK_IMAGE_LAYOUT_GENERAL:
4739 case VK_IMAGE_LAYOUT_PREINITIALIZED:
4742 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
4743 return VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
4745 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
4746 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
4747 return VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
4749 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
4750 return VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
4752 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL:
4753 return VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
4755 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL:
4756 return VK_IMAGE_USAGE_TRANSFER_DST_BIT;
4759 DE_FATAL("Unexpected image layout");
4764 void getImageUsageFromAttachmentReferences(vector<VkImageUsageFlags>& attachmentImageUsage, AttachmentRefType refType, size_t count, const AttachmentReference* references)
4766 for (size_t referenceNdx = 0; referenceNdx < count; ++referenceNdx)
4768 const deUint32 attachment = references[referenceNdx].getAttachment();
4770 if (attachment != VK_ATTACHMENT_UNUSED)
4772 VkImageUsageFlags usage;
4776 case ATTACHMENTREFTYPE_COLOR:
4777 case ATTACHMENTREFTYPE_RESOLVE:
4778 usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
4781 case ATTACHMENTREFTYPE_DEPTH_STENCIL:
4782 usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
4785 case ATTACHMENTREFTYPE_INPUT:
4786 usage = VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
4790 DE_FATAL("Unexpected attachment reference type");
4795 attachmentImageUsage[attachment] |= usage;
4800 void getImageUsageFromAttachmentReferences(vector<VkImageUsageFlags>& attachmentImageUsage, AttachmentRefType refType, const vector<AttachmentReference>& references)
4802 if (!references.empty())
4804 getImageUsageFromAttachmentReferences(attachmentImageUsage, refType, references.size(), &references[0]);
4808 void initializeAttachmentImageUsage (Context &context, vector<VkImageUsageFlags>& attachmentImageUsage, const RenderPass& renderPassInfo, const vector<bool>& attachmentIsLazy, const vector<Maybe<VkClearValue> >& clearValues)
4810 attachmentImageUsage.resize(renderPassInfo.getAttachments().size(), VkImageUsageFlags(0));
4812 for (size_t subpassNdx = 0; subpassNdx < renderPassInfo.getSubpasses().size(); ++subpassNdx)
4814 const Subpass& subpass = renderPassInfo.getSubpasses()[subpassNdx];
4816 getImageUsageFromAttachmentReferences(attachmentImageUsage, ATTACHMENTREFTYPE_COLOR, subpass.getColorAttachments());
4817 getImageUsageFromAttachmentReferences(attachmentImageUsage, ATTACHMENTREFTYPE_DEPTH_STENCIL, 1, &subpass.getDepthStencilAttachment());
4818 getImageUsageFromAttachmentReferences(attachmentImageUsage, ATTACHMENTREFTYPE_INPUT, subpass.getInputAttachments());
4819 getImageUsageFromAttachmentReferences(attachmentImageUsage, ATTACHMENTREFTYPE_RESOLVE, subpass.getResolveAttachments());
4822 for (size_t attachmentNdx = 0; attachmentNdx < renderPassInfo.getAttachments().size(); attachmentNdx++)
4824 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentNdx];
4825 const VkFormatProperties formatProperties = getPhysicalDeviceFormatProperties(context.getInstanceInterface(), context.getPhysicalDevice(), attachment.getFormat());
4826 const VkFormatFeatureFlags supportedFeatures = formatProperties.optimalTilingFeatures;
4828 if ((supportedFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) != 0)
4829 attachmentImageUsage[attachmentNdx] |= VK_IMAGE_USAGE_SAMPLED_BIT;
4831 if ((supportedFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) != 0)
4832 attachmentImageUsage[attachmentNdx] |= VK_IMAGE_USAGE_STORAGE_BIT;
4834 attachmentImageUsage[attachmentNdx] |= getImageUsageFromLayout(attachment.getInitialLayout());
4835 attachmentImageUsage[attachmentNdx] |= getImageUsageFromLayout(attachment.getFinalLayout());
4837 if (!attachmentIsLazy[attachmentNdx])
4839 if (clearValues[attachmentNdx])
4840 attachmentImageUsage[attachmentNdx] |= VK_IMAGE_USAGE_TRANSFER_DST_BIT;
4842 attachmentImageUsage[attachmentNdx] |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
4846 const VkImageUsageFlags allowedTransientBits = static_cast<VkImageUsageFlags>(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT);
4848 attachmentImageUsage[attachmentNdx] &= allowedTransientBits;
4849 attachmentImageUsage[attachmentNdx] |= VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT;
4854 void initializeSubpassIsSecondary (vector<bool>& subpassIsSecondary, const vector<Subpass>& subpasses, TestConfig::CommandBufferTypes commandBuffer)
4856 bool lastSubpassWasSecondary = false;
4858 for (size_t subpassNdx = 0; subpassNdx < subpasses.size(); subpassNdx++)
4860 if (commandBuffer == TestConfig::COMMANDBUFFERTYPES_SECONDARY || (commandBuffer & TestConfig::COMMANDBUFFERTYPES_SECONDARY && !lastSubpassWasSecondary))
4862 subpassIsSecondary.push_back(true);
4863 lastSubpassWasSecondary = true;
4865 else if (commandBuffer & TestConfig::COMMANDBUFFERTYPES_INLINE)
4867 subpassIsSecondary.push_back(false);
4868 lastSubpassWasSecondary = false;
4871 DE_FATAL("Unknown commandBuffer");
4875 void initializeImageClearValues (de::Random& rng, vector<Maybe<VkClearValue> >& clearValues, const vector<Attachment>& attachments, const vector<bool>& isLazy, deBool useFormatCompCount, const DepthValuesArray& depthValues)
4877 for (size_t attachmentNdx = 0; attachmentNdx < attachments.size(); attachmentNdx++)
4879 if (!isLazy[attachmentNdx])
4880 clearValues.push_back(just(randomClearValue(attachments[attachmentNdx], rng, useFormatCompCount, depthValues)));
4882 clearValues.push_back(tcu::Nothing);
4886 void initializeRenderPassClearValues (de::Random& rng, vector<Maybe<VkClearValue> >& clearValues, const vector<Attachment>& attachments, deBool useFormatCompCount, const DepthValuesArray& depthValues)
4888 for (size_t attachmentNdx = 0; attachmentNdx < attachments.size(); attachmentNdx++)
4890 if (attachments[attachmentNdx].getLoadOp() == VK_ATTACHMENT_LOAD_OP_CLEAR
4891 || attachments[attachmentNdx].getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_CLEAR)
4893 clearValues.push_back(just(randomClearValue(attachments[attachmentNdx], rng, useFormatCompCount, depthValues)));
4896 clearValues.push_back(tcu::Nothing);
4900 void logSubpassRenderInfo (TestLog& log, const SubpassRenderInfo& info, TestConfig config)
4902 log << TestLog::Message << "Viewport, offset: " << info.getViewportOffset() << ", size: " << info.getViewportSize() << TestLog::EndMessage;
4904 if (info.isSecondary())
4905 log << TestLog::Message << "Subpass uses secondary command buffers" << TestLog::EndMessage;
4907 log << TestLog::Message << "Subpass uses inlined commands" << TestLog::EndMessage;
4909 for (deUint32 attachmentNdx = 0; attachmentNdx < info.getColorClears().size(); attachmentNdx++)
4911 const ColorClear& colorClear = info.getColorClears()[attachmentNdx];
4913 log << TestLog::Message << "Clearing color attachment " << attachmentNdx
4914 << ". Offset: " << colorClear.getOffset()
4915 << ", Size: " << colorClear.getSize()
4916 << ", Color: " << clearColorToString(info.getColorAttachment(attachmentNdx).getFormat(), colorClear.getColor(), config.useFormatCompCount) << TestLog::EndMessage;
4919 if (info.getDepthStencilClear())
4921 const DepthStencilClear& depthStencilClear = *info.getDepthStencilClear();
4923 log << TestLog::Message << "Clearing depth stencil attachment"
4924 << ". Offset: " << depthStencilClear.getOffset()
4925 << ", Size: " << depthStencilClear.getSize()
4926 << ", Depth: " << depthStencilClear.getDepth()
4927 << ", Stencil: " << depthStencilClear.getStencil() << TestLog::EndMessage;
4930 if (info.getRenderQuad())
4932 const RenderQuad& renderQuad = *info.getRenderQuad();
4934 log << TestLog::Message << "Rendering grid quad to " << renderQuad.getCornerA() << " -> " << renderQuad.getCornerB() << TestLog::EndMessage;
4938 void logTestCaseInfo (TestLog& log,
4939 const TestConfig& config,
4940 const vector<bool>& attachmentIsLazy,
4941 const vector<Maybe<VkClearValue> >& imageClearValues,
4942 const vector<Maybe<VkClearValue> >& renderPassClearValues,
4943 const vector<SubpassRenderInfo>& subpassRenderInfo)
4945 const RenderPass& renderPass = config.renderPass;
4947 logRenderPassInfo(log, renderPass);
4949 DE_ASSERT(attachmentIsLazy.size() == renderPass.getAttachments().size());
4950 DE_ASSERT(imageClearValues.size() == renderPass.getAttachments().size());
4951 DE_ASSERT(renderPassClearValues.size() == renderPass.getAttachments().size());
4953 log << TestLog::Message << "TargetSize: " << config.targetSize << TestLog::EndMessage;
4954 log << TestLog::Message << "Render area, Offset: " << config.renderPos << ", Size: " << config.renderSize << TestLog::EndMessage;
4956 for (size_t attachmentNdx = 0; attachmentNdx < attachmentIsLazy.size(); attachmentNdx++)
4958 const tcu::ScopedLogSection section (log, "Attachment" + de::toString(attachmentNdx), "Attachment " + de::toString(attachmentNdx));
4960 if (attachmentIsLazy[attachmentNdx])
4961 log << TestLog::Message << "Is lazy." << TestLog::EndMessage;
4963 if (imageClearValues[attachmentNdx])
4964 log << TestLog::Message << "Image is cleared to " << clearValueToString(renderPass.getAttachments()[attachmentNdx].getFormat(),
4965 *imageClearValues[attachmentNdx], config.useFormatCompCount) << " before rendering." << TestLog::EndMessage;
4967 if (renderPass.getAttachments()[attachmentNdx].getLoadOp() == VK_ATTACHMENT_LOAD_OP_CLEAR && renderPassClearValues[attachmentNdx])
4968 log << TestLog::Message << "Attachment is cleared to " << clearValueToString(renderPass.getAttachments()[attachmentNdx].getFormat(),
4969 *renderPassClearValues[attachmentNdx], config.useFormatCompCount) << " in the beginning of the render pass." << TestLog::EndMessage;
4972 for (size_t subpassNdx = 0; subpassNdx < renderPass.getSubpasses().size(); subpassNdx++)
4974 const tcu::ScopedLogSection section (log, "Subpass" + de::toString(subpassNdx), "Subpass " + de::toString(subpassNdx));
4976 logSubpassRenderInfo(log, subpassRenderInfo[subpassNdx], config);
4980 float roundToViewport (float x, deUint32 offset, deUint32 size)
4982 const float origin = (float)(offset) + ((float(size) / 2.0f));
4983 const float p = (float)(size) / 2.0f;
4984 const deInt32 xi = deRoundFloatToInt32(origin + (p * x));
4986 return (((float)xi) - origin) / p;
4989 void initializeSubpassRenderInfo (vector<SubpassRenderInfo>& renderInfos, de::Random& rng, const RenderPass& renderPass, const TestConfig& config)
4991 const TestConfig::CommandBufferTypes commandBuffer = config.commandBufferTypes;
4992 const vector<Subpass>& subpasses = renderPass.getSubpasses();
4993 bool lastSubpassWasSecondary = false;
4995 for (deUint32 subpassNdx = 0; subpassNdx < (deUint32)subpasses.size(); subpassNdx++)
4997 const Subpass& subpass = subpasses[subpassNdx];
4998 const bool subpassIsSecondary = commandBuffer == TestConfig::COMMANDBUFFERTYPES_SECONDARY
4999 || (commandBuffer & TestConfig::COMMANDBUFFERTYPES_SECONDARY && !lastSubpassWasSecondary) ? true : false;
5000 const bool omitBlendState = subpass.getOmitBlendState();
5001 const UVec2 viewportSize ((config.renderSize * UVec2(2)) / UVec2(3));
5002 const UVec2 viewportOffset (config.renderPos.x() + (subpassNdx % 2) * (config.renderSize.x() / 3),
5003 config.renderPos.y() + ((subpassNdx / 2) % 2) * (config.renderSize.y() / 3));
5005 vector<ColorClear> colorClears;
5006 Maybe<DepthStencilClear> depthStencilClear;
5007 Maybe<RenderQuad> renderQuad;
5009 lastSubpassWasSecondary = subpassIsSecondary;
5011 if (config.renderTypes & TestConfig::RENDERTYPES_CLEAR)
5013 const vector<AttachmentReference>& colorAttachments = subpass.getColorAttachments();
5015 for (size_t attachmentRefNdx = 0; attachmentRefNdx < colorAttachments.size(); attachmentRefNdx++)
5017 const AttachmentReference& attachmentRef = colorAttachments[attachmentRefNdx];
5018 const Attachment& attachment = renderPass.getAttachments()[attachmentRef.getAttachment()];
5019 const UVec2 size ((viewportSize * UVec2(2)) / UVec2(3));
5020 const UVec2 offset (viewportOffset.x() + ((deUint32)attachmentRefNdx % 2u) * (viewportSize.x() / 3u),
5021 viewportOffset.y() + (((deUint32)attachmentRefNdx / 2u) % 2u) * (viewportSize.y() / 3u));
5022 const VkClearColorValue color = randomColorClearValue(attachment, rng, config.useFormatCompCount);
5024 colorClears.push_back(ColorClear(offset, size, color));
5027 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED)
5029 const Attachment& attachment = renderPass.getAttachments()[subpass.getDepthStencilAttachment().getAttachment()];
5030 const UVec2 size ((viewportSize * UVec2(2)) / UVec2(3));
5031 const UVec2 offset (viewportOffset.x() + ((deUint32)colorAttachments.size() % 2u) * (viewportSize.x() / 3u),
5032 viewportOffset.y() + (((deUint32)colorAttachments.size() / 2u) % 2u) * (viewportSize.y() / 3u));
5033 const VkClearValue value = randomClearValue(attachment, rng, config.useFormatCompCount, config.depthValues);
5035 depthStencilClear = tcu::just(DepthStencilClear(offset, size, value.depthStencil.depth, value.depthStencil.stencil));
5039 if (config.renderTypes & TestConfig::RENDERTYPES_DRAW)
5041 const float w = (subpassNdx % 2) == 0 ? 1.0f : 1.25f;
5042 const float h = (subpassNdx % 2) == 0 ? 1.25f : 1.0f;
5044 const float x0 = roundToViewport((subpassNdx % 2) == 0 ? 1.0f - w : -1.0f, viewportOffset.x(), viewportSize.x());
5045 const float x1 = roundToViewport((subpassNdx % 2) == 0 ? 1.0f : -1.0f + w, viewportOffset.x(), viewportSize.x());
5047 const float y0 = roundToViewport(((subpassNdx / 2) % 2) == 0 ? 1.0f - h : -1.0f, viewportOffset.y(), viewportSize.y());
5048 const float y1 = roundToViewport(((subpassNdx / 2) % 2) == 0 ? 1.0f : -1.0f + h, viewportOffset.y(), viewportSize.y());
5050 renderQuad = tcu::just(RenderQuad(tcu::Vec2(x0, y0), tcu::Vec2(x1, y1)));
5053 renderInfos.push_back(SubpassRenderInfo(renderPass, subpassNdx, config.drawStartNdx, subpassIsSecondary, omitBlendState, viewportOffset, viewportSize, renderQuad, colorClears, depthStencilClear));
5057 void checkTextureFormatSupport (TestLog& log,
5058 const InstanceInterface& vk,
5059 VkPhysicalDevice device,
5060 const vector<Attachment>& attachments)
5062 bool supported = true;
5064 for (size_t attachmentNdx = 0; attachmentNdx < attachments.size(); attachmentNdx++)
5066 const Attachment& attachment = attachments[attachmentNdx];
5067 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
5068 const bool isDepthOrStencilAttachment = hasDepthComponent(format.order) || hasStencilComponent(format.order);
5069 const VkFormatFeatureFlags flags = isDepthOrStencilAttachment? VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT : VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT;
5070 VkFormatProperties properties;
5072 vk.getPhysicalDeviceFormatProperties(device, attachment.getFormat(), &properties);
5074 if ((properties.optimalTilingFeatures & flags) != flags)
5077 log << TestLog::Message << "Format: " << attachment.getFormat() << " not supported as " << (isDepthOrStencilAttachment ? "depth stencil attachment" : "color attachment") << TestLog::EndMessage;
5082 TCU_THROW(NotSupportedError, "Format not supported");
5085 tcu::TestStatus renderPassTest (Context& context, TestConfig config)
5087 const UVec2 targetSize = config.targetSize;
5088 const UVec2 renderPos = config.renderPos;
5089 const UVec2 renderSize = config.renderSize;
5090 const RenderPass& renderPassInfo = config.renderPass;
5092 TestLog& log = context.getTestContext().getLog();
5093 de::Random rng (config.seed);
5095 vector<bool> attachmentIsLazy;
5096 vector<VkImageUsageFlags> attachmentImageUsage;
5097 vector<Maybe<VkClearValue> > imageClearValues;
5098 vector<Maybe<VkClearValue> > renderPassClearValues;
5100 vector<bool> subpassIsSecondary;
5101 vector<SubpassRenderInfo> subpassRenderInfo;
5103 if (config.groupParams->renderingType == RENDERING_TYPE_RENDERPASS2)
5104 context.requireDeviceFunctionality("VK_KHR_create_renderpass2");
5106 if (config.groupParams->renderingType == RENDERING_TYPE_DYNAMIC_RENDERING)
5107 context.requireDeviceFunctionality("VK_KHR_dynamic_rendering");
5109 if (config.allocationKind == ALLOCATION_KIND_DEDICATED)
5111 if (!context.isDeviceFunctionalitySupported("VK_KHR_dedicated_allocation"))
5112 TCU_THROW(NotSupportedError, "VK_KHR_dedicated_allocation is not supported");
5115 if (!renderPassInfo.getInputAspects().empty())
5117 if (!context.isDeviceFunctionalitySupported("VK_KHR_maintenance2"))
5118 TCU_THROW(NotSupportedError, "Extension VK_KHR_maintenance2 not supported.");
5122 bool requireDepthStencilLayout = false;
5124 for (size_t attachmentNdx = 0; attachmentNdx < renderPassInfo.getAttachments().size(); attachmentNdx++)
5126 if (renderPassInfo.getAttachments()[attachmentNdx].getInitialLayout() == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL
5127 || renderPassInfo.getAttachments()[attachmentNdx].getInitialLayout() == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL
5128 || renderPassInfo.getAttachments()[attachmentNdx].getFinalLayout() == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL
5129 || renderPassInfo.getAttachments()[attachmentNdx].getFinalLayout() == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
5131 requireDepthStencilLayout = true;
5136 for (size_t subpassNdx = 0; subpassNdx < renderPassInfo.getSubpasses().size() && !requireDepthStencilLayout; subpassNdx++)
5138 const Subpass& subpass (renderPassInfo.getSubpasses()[subpassNdx]);
5140 for (size_t attachmentNdx = 0; attachmentNdx < subpass.getColorAttachments().size(); attachmentNdx++)
5142 if (subpass.getColorAttachments()[attachmentNdx].getImageLayout() == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL
5143 || subpass.getColorAttachments()[attachmentNdx].getImageLayout() == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
5145 requireDepthStencilLayout = true;
5150 for (size_t attachmentNdx = 0; !requireDepthStencilLayout && attachmentNdx < subpass.getInputAttachments().size(); attachmentNdx++)
5152 if (subpass.getInputAttachments()[attachmentNdx].getImageLayout() == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL
5153 || subpass.getInputAttachments()[attachmentNdx].getImageLayout() == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
5155 requireDepthStencilLayout = true;
5160 for (size_t attachmentNdx = 0; !requireDepthStencilLayout && attachmentNdx < subpass.getResolveAttachments().size(); attachmentNdx++)
5162 if (subpass.getResolveAttachments()[attachmentNdx].getImageLayout() == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL
5163 || subpass.getResolveAttachments()[attachmentNdx].getImageLayout() == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
5165 requireDepthStencilLayout = true;
5170 if (subpass.getDepthStencilAttachment().getImageLayout() == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL
5171 || subpass.getDepthStencilAttachment().getImageLayout() == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
5173 requireDepthStencilLayout = true;
5178 if (requireDepthStencilLayout && !context.isDeviceFunctionalitySupported("VK_KHR_maintenance2"))
5179 TCU_THROW(NotSupportedError, "VK_KHR_maintenance2 is not supported");
5182 initializeAttachmentIsLazy(attachmentIsLazy, renderPassInfo.getAttachments(), config.imageMemory);
5183 initializeImageClearValues(rng, imageClearValues, renderPassInfo.getAttachments(), attachmentIsLazy, config.useFormatCompCount, config.depthValues);
5184 initializeAttachmentImageUsage(context, attachmentImageUsage, renderPassInfo, attachmentIsLazy, imageClearValues);
5185 initializeRenderPassClearValues(rng, renderPassClearValues, renderPassInfo.getAttachments(), config.useFormatCompCount, config.depthValues);
5187 initializeSubpassIsSecondary(subpassIsSecondary, renderPassInfo.getSubpasses(), config.commandBufferTypes);
5188 initializeSubpassRenderInfo(subpassRenderInfo, rng, renderPassInfo, config);
5190 logTestCaseInfo(log, config, attachmentIsLazy, imageClearValues, renderPassClearValues, subpassRenderInfo);
5192 checkTextureFormatSupport(log, context.getInstanceInterface(), context.getPhysicalDevice(), config.renderPass.getAttachments());
5195 const vk::VkPhysicalDeviceProperties properties = vk::getPhysicalDeviceProperties(context.getInstanceInterface(), context.getPhysicalDevice());
5197 log << TestLog::Message << "Max color attachments: " << properties.limits.maxColorAttachments << TestLog::EndMessage;
5199 for (size_t subpassNdx = 0; subpassNdx < renderPassInfo.getSubpasses().size(); subpassNdx++)
5201 if (renderPassInfo.getSubpasses()[subpassNdx].getColorAttachments().size() > (size_t)properties.limits.maxColorAttachments)
5202 TCU_THROW(NotSupportedError, "Subpass uses more than maxColorAttachments.");
5207 const InstanceInterface& vki = context.getInstanceInterface();
5208 const VkPhysicalDevice& physDevice = context.getPhysicalDevice();
5209 const VkDevice device = context.getDevice();
5210 const DeviceInterface& vk = context.getDeviceInterface();
5211 const VkQueue queue = context.getUniversalQueue();
5212 const deUint32 queueIndex = context.getUniversalQueueFamilyIndex();
5213 Allocator& allocator = context.getDefaultAllocator();
5215 const Unique<VkCommandPool> commandBufferPool (createCommandPool(vk, device, 0, queueIndex));
5216 const Unique<VkCommandBuffer> initializeImagesCommandBuffer (allocateCommandBuffer(vk, device, *commandBufferPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
5217 const Unique<VkCommandBuffer> renderCommandBuffer (allocateCommandBuffer(vk, device, *commandBufferPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
5218 const Unique<VkCommandBuffer> readImagesToBuffersCommandBuffer (allocateCommandBuffer(vk, device, *commandBufferPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
5220 vector<de::SharedPtr<AttachmentResources> > attachmentResources;
5221 vector<de::SharedPtr<SubpassRenderer> > subpassRenderers;
5222 vector<VkImage> attachmentImages;
5223 vector<VkImageView> attachmentViews;
5224 vector<pair<VkImageView, VkImageView> > inputAttachmentViews;
5226 Move<VkRenderPass> renderPass;
5227 if (config.groupParams->renderingType != RENDERING_TYPE_DYNAMIC_RENDERING)
5228 renderPass = createRenderPass(vk, device, renderPassInfo, config.groupParams->renderingType);
5230 for (size_t attachmentNdx = 0; attachmentNdx < renderPassInfo.getAttachments().size(); attachmentNdx++)
5232 const Attachment& attachmentInfo = renderPassInfo.getAttachments()[attachmentNdx];
5234 attachmentResources.push_back(de::SharedPtr<AttachmentResources>(new AttachmentResources(vki, physDevice, vk, device, allocator, queueIndex, targetSize, attachmentInfo, attachmentImageUsage[attachmentNdx], config.allocationKind)));
5235 attachmentViews.push_back(attachmentResources[attachmentNdx]->getAttachmentView());
5236 attachmentImages.push_back(attachmentResources[attachmentNdx]->getImage());
5238 inputAttachmentViews.push_back(attachmentResources[attachmentNdx]->getInputAttachmentViews());
5241 beginCommandBuffer(vk, *initializeImagesCommandBuffer, DE_NULL, 0, DE_NULL, VK_FALSE, (VkQueryControlFlags)0, (VkQueryPipelineStatisticFlags)0);
5242 pushImageInitializationCommands(vk, *initializeImagesCommandBuffer, renderPassInfo.getAttachments(), attachmentResources, queueIndex, imageClearValues);
5243 endCommandBuffer(vk, *initializeImagesCommandBuffer);
5246 Move<VkFramebuffer> framebuffer;
5247 if (config.groupParams->renderingType != RENDERING_TYPE_DYNAMIC_RENDERING)
5248 framebuffer = createFramebuffer(vk, device, *renderPass, targetSize, attachmentViews);
5250 const VkRect2D renderArea
5252 { (deInt32)renderPos.x(), (deInt32)renderPos.y() },
5253 { renderSize.x(), renderSize.y() }
5255 const bool dynamicRendering = (config.groupParams->renderingType == RENDERING_TYPE_DYNAMIC_RENDERING);
5256 const bool secondaryCmdBufferCompletelyContainsDynamicRenderpass = (config.commandBufferTypes == TestConfig::COMMANDBUFFERTYPES_SECONDARY) &&
5257 config.groupParams->secondaryCmdBufferCompletelyContainsDynamicRenderpass;
5259 for (size_t subpassNdx = 0; subpassNdx < renderPassInfo.getSubpasses().size(); subpassNdx++)
5261 subpassRenderers.push_back(de::SharedPtr<SubpassRenderer>(new SubpassRenderer(context, vk, device, allocator, renderPassInfo, attachmentResources,
5262 renderArea, renderPassClearValues, *renderPass, *framebuffer,
5263 *commandBufferPool, queueIndex, attachmentImages, inputAttachmentViews,
5264 subpassRenderInfo[subpassNdx], config.allocationKind, dynamicRendering,
5265 secondaryCmdBufferCompletelyContainsDynamicRenderpass)));
5268 beginCommandBuffer(vk, *renderCommandBuffer, DE_NULL, 0, DE_NULL, VK_FALSE, (VkQueryControlFlags)0, (VkQueryPipelineStatisticFlags)0);
5269 pushRenderPassCommands(vk, *renderCommandBuffer, *renderPass, renderPassInfo, attachmentResources, *framebuffer, subpassRenderers, renderArea,
5270 renderPassClearValues, queueIndex, config.renderTypes, config.groupParams->renderingType, secondaryCmdBufferCompletelyContainsDynamicRenderpass);
5271 endCommandBuffer(vk, *renderCommandBuffer);
5273 beginCommandBuffer(vk, *readImagesToBuffersCommandBuffer, DE_NULL, 0, DE_NULL, VK_FALSE, (VkQueryControlFlags)0, (VkQueryPipelineStatisticFlags)0);
5274 pushReadImagesToBuffers(vk, *readImagesToBuffersCommandBuffer, queueIndex, attachmentResources, renderPassInfo.getAttachments(), attachmentIsLazy, targetSize);
5275 endCommandBuffer(vk, *readImagesToBuffersCommandBuffer);
5277 const VkCommandBuffer commandBuffers[] =
5279 *initializeImagesCommandBuffer,
5280 *renderCommandBuffer,
5281 *readImagesToBuffersCommandBuffer
5283 const Unique<VkFence> fence (createFence(vk, device, 0u));
5285 queueSubmit(vk, queue, DE_LENGTH_OF_ARRAY(commandBuffers), commandBuffers, *fence);
5286 waitForFences(vk, device, 1, &fence.get(), VK_TRUE, ~0ull);
5289 #ifdef CTS_USES_VULKANSC
5290 if (!context.getTestContext().getCommandLine().isSubProcess())
5291 return tcu::TestStatus::pass("Pass");
5293 if (logAndVerifyImages(log, vk, device, attachmentResources, attachmentIsLazy, renderPassInfo, renderPassClearValues, imageClearValues, subpassRenderInfo, targetSize, config))
5294 return tcu::TestStatus::pass("Pass");
5296 return tcu::TestStatus::fail("Result verification failed");
5300 static const VkFormat s_coreColorFormats[] =
5302 VK_FORMAT_R5G6B5_UNORM_PACK16,
5307 VK_FORMAT_R8G8_UNORM,
5308 VK_FORMAT_R8G8_SNORM,
5309 VK_FORMAT_R8G8_UINT,
5310 VK_FORMAT_R8G8_SINT,
5311 VK_FORMAT_R8G8B8A8_UNORM,
5312 VK_FORMAT_R8G8B8A8_SNORM,
5313 VK_FORMAT_R8G8B8A8_UINT,
5314 VK_FORMAT_R8G8B8A8_SINT,
5315 VK_FORMAT_R8G8B8A8_SRGB,
5316 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
5317 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
5318 VK_FORMAT_A8B8G8R8_UINT_PACK32,
5319 VK_FORMAT_A8B8G8R8_SINT_PACK32,
5320 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
5321 VK_FORMAT_B8G8R8A8_UNORM,
5322 VK_FORMAT_B8G8R8A8_SRGB,
5323 VK_FORMAT_A2R10G10B10_UNORM_PACK32,
5324 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
5325 VK_FORMAT_A2B10G10R10_UINT_PACK32,
5326 VK_FORMAT_R16_UNORM,
5327 VK_FORMAT_R16_SNORM,
5330 VK_FORMAT_R16_SFLOAT,
5331 VK_FORMAT_R16G16_UNORM,
5332 VK_FORMAT_R16G16_SNORM,
5333 VK_FORMAT_R16G16_UINT,
5334 VK_FORMAT_R16G16_SINT,
5335 VK_FORMAT_R16G16_SFLOAT,
5336 VK_FORMAT_R16G16B16A16_UNORM,
5337 VK_FORMAT_R16G16B16A16_SNORM,
5338 VK_FORMAT_R16G16B16A16_UINT,
5339 VK_FORMAT_R16G16B16A16_SINT,
5340 VK_FORMAT_R16G16B16A16_SFLOAT,
5343 VK_FORMAT_R32_SFLOAT,
5344 VK_FORMAT_R32G32_UINT,
5345 VK_FORMAT_R32G32_SINT,
5346 VK_FORMAT_R32G32_SFLOAT,
5347 VK_FORMAT_R32G32B32A32_UINT,
5348 VK_FORMAT_R32G32B32A32_SINT,
5349 VK_FORMAT_R32G32B32A32_SFLOAT
5352 static const VkFormat s_coreDepthStencilFormats[] =
5354 VK_FORMAT_D16_UNORM,
5356 VK_FORMAT_X8_D24_UNORM_PACK32,
5357 VK_FORMAT_D32_SFLOAT,
5359 VK_FORMAT_D24_UNORM_S8_UINT,
5360 VK_FORMAT_D32_SFLOAT_S8_UINT
5363 void addAttachmentTests (tcu::TestCaseGroup* group, const TestConfigExternal testConfigExternal)
5365 const deUint32 attachmentCounts[] = { 1, 3, 4, 8 };
5366 const VkAttachmentLoadOp loadOps[] =
5368 VK_ATTACHMENT_LOAD_OP_LOAD,
5369 VK_ATTACHMENT_LOAD_OP_CLEAR,
5370 VK_ATTACHMENT_LOAD_OP_DONT_CARE
5373 const VkAttachmentStoreOp storeOps[] =
5375 VK_ATTACHMENT_STORE_OP_STORE,
5376 VK_ATTACHMENT_STORE_OP_DONT_CARE
5379 const VkImageLayout initialAndFinalColorLayouts[] =
5381 VK_IMAGE_LAYOUT_GENERAL,
5382 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
5383 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
5384 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
5385 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
5388 const VkImageLayout initialAndFinalColorLayoutsLazy[] =
5390 VK_IMAGE_LAYOUT_GENERAL,
5391 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
5392 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
5395 const VkImageLayout initialAndFinalDepthStencilLayouts[] =
5397 VK_IMAGE_LAYOUT_GENERAL,
5398 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
5399 VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL,
5400 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
5401 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
5402 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
5405 const VkImageLayout initialAndFinalDepthStencilLayoutsLazy[] =
5407 VK_IMAGE_LAYOUT_GENERAL,
5408 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
5409 VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL,
5410 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
5413 const VkImageLayout subpassLayouts[] =
5415 VK_IMAGE_LAYOUT_GENERAL,
5416 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
5419 const VkImageLayout depthStencilLayouts[] =
5421 VK_IMAGE_LAYOUT_GENERAL,
5422 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL
5425 const TestConfig::RenderTypes renderCommands[] =
5427 TestConfig::RENDERTYPES_NONE,
5428 TestConfig::RENDERTYPES_CLEAR,
5429 TestConfig::RENDERTYPES_DRAW,
5430 TestConfig::RENDERTYPES_CLEAR|TestConfig::RENDERTYPES_DRAW,
5433 const TestConfig::CommandBufferTypes commandBuffers[] =
5435 TestConfig::COMMANDBUFFERTYPES_INLINE,
5436 TestConfig::COMMANDBUFFERTYPES_SECONDARY,
5437 TestConfig::COMMANDBUFFERTYPES_INLINE|TestConfig::COMMANDBUFFERTYPES_SECONDARY
5440 const TestConfig::ImageMemory imageMemories[] =
5442 TestConfig::IMAGEMEMORY_STRICT,
5443 TestConfig::IMAGEMEMORY_LAZY,
5444 TestConfig::IMAGEMEMORY_STRICT|TestConfig::IMAGEMEMORY_LAZY
5447 const UVec2 targetSizes[] =
5453 const UVec2 renderPositions[] =
5459 const UVec2 renderSizes[] =
5465 tcu::TestContext& testCtx (group->getTestContext());
5466 bool useDynamicRendering (testConfigExternal.groupParams->renderingType == RENDERING_TYPE_DYNAMIC_RENDERING);
5467 de::Random rng (1433774382u);
5469 for (size_t attachmentCountNdx = 0; attachmentCountNdx < DE_LENGTH_OF_ARRAY(attachmentCounts); attachmentCountNdx++)
5471 const deUint32 attachmentCount = attachmentCounts[attachmentCountNdx];
5472 const deUint32 testCaseCount = (attachmentCount == 1 ? 100 : 200);
5473 de::MovePtr<tcu::TestCaseGroup> attachmentCountGroup (new tcu::TestCaseGroup(testCtx, de::toString(attachmentCount).c_str(), de::toString(attachmentCount).c_str()));
5475 for (size_t testCaseNdx = 0; testCaseNdx < testCaseCount; testCaseNdx++)
5477 const bool useDepthStencil = rng.getBool();
5478 const TestConfig::ImageMemory imageMemory = rng.choose<TestConfig::ImageMemory>(DE_ARRAY_BEGIN(imageMemories), DE_ARRAY_END(imageMemories));
5479 VkImageLayout depthStencilLayout = VK_IMAGE_LAYOUT_GENERAL;
5480 vector<Attachment> attachments;
5481 vector<AttachmentReference> colorAttachmentReferences;
5483 // we want to make sure that dynamic rendering test cases have corresponding renderpass
5484 // cases as this will allow drivers to easily compare GPU batches; since configurations
5485 // for those tests are generated we need to generate configurations for all cases
5486 // even when we know earlier that for dynamic rendering we will skip it
5487 bool executeForDynamicRendering = true;
5489 for (size_t attachmentNdx = 0; attachmentNdx < attachmentCount; attachmentNdx++)
5491 const VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_1_BIT;
5492 const VkFormat format = rng.choose<VkFormat>(DE_ARRAY_BEGIN(s_coreColorFormats), DE_ARRAY_END(s_coreColorFormats));
5493 const VkAttachmentLoadOp loadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
5494 const VkAttachmentStoreOp storeOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
5496 const VkImageLayout initialLayout = (imageMemory == TestConfig::IMAGEMEMORY_STRICT)
5497 ? rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalColorLayouts), DE_ARRAY_END(initialAndFinalColorLayouts))
5498 : rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalColorLayoutsLazy), DE_ARRAY_END(initialAndFinalColorLayoutsLazy));
5499 VkImageLayout finalizeLayout = (imageMemory == TestConfig::IMAGEMEMORY_STRICT)
5500 ? rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalColorLayouts), DE_ARRAY_END(initialAndFinalColorLayouts))
5501 : rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalColorLayoutsLazy), DE_ARRAY_END(initialAndFinalColorLayoutsLazy));
5502 const VkImageLayout subpassLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayouts), DE_ARRAY_END(subpassLayouts));
5504 const VkAttachmentLoadOp stencilLoadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
5505 const VkAttachmentStoreOp stencilStoreOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
5507 if (useDynamicRendering)
5509 // with renderpass we can have automatic layout transitions; to do the same with dynamic rendering cases
5510 // we would need to add addtional barries but since those tests won't add coverage we are skipping them
5511 if ((initialLayout == VK_IMAGE_LAYOUT_GENERAL) ||
5512 (initialLayout == VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL))
5513 finalizeLayout = initialLayout;
5515 executeForDynamicRendering = false;
5518 attachments.push_back(Attachment(format, sampleCount, loadOp, storeOp, stencilLoadOp, stencilStoreOp, initialLayout, finalizeLayout));
5519 colorAttachmentReferences.push_back(AttachmentReference((deUint32)attachmentNdx, subpassLayout));
5522 if (useDepthStencil)
5524 const VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_1_BIT;
5525 const VkFormat format = rng.choose<VkFormat>(DE_ARRAY_BEGIN(s_coreDepthStencilFormats), DE_ARRAY_END(s_coreDepthStencilFormats));
5526 const VkAttachmentLoadOp loadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
5527 const VkAttachmentStoreOp storeOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
5529 const VkImageLayout initialLayout = (imageMemory == TestConfig::IMAGEMEMORY_STRICT)
5530 ? rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalDepthStencilLayouts), DE_ARRAY_END(initialAndFinalDepthStencilLayouts))
5531 : rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalDepthStencilLayoutsLazy), DE_ARRAY_END(initialAndFinalDepthStencilLayoutsLazy));
5532 VkImageLayout finalizeLayout = (imageMemory == TestConfig::IMAGEMEMORY_STRICT)
5533 ? rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalDepthStencilLayouts), DE_ARRAY_END(initialAndFinalDepthStencilLayouts))
5534 : rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalDepthStencilLayoutsLazy), DE_ARRAY_END(initialAndFinalDepthStencilLayoutsLazy));
5536 const VkAttachmentLoadOp stencilLoadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
5537 const VkAttachmentStoreOp stencilStoreOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
5539 if (useDynamicRendering)
5541 if ((initialLayout == VK_IMAGE_LAYOUT_GENERAL) ||
5542 (initialLayout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) ||
5543 (initialLayout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL))
5544 finalizeLayout = initialLayout;
5546 executeForDynamicRendering = false;
5549 depthStencilLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(depthStencilLayouts), DE_ARRAY_END(depthStencilLayouts));
5550 attachments.push_back(Attachment(format, sampleCount, loadOp, storeOp, stencilLoadOp, stencilStoreOp, initialLayout, finalizeLayout));
5554 const TestConfig::RenderTypes render = rng.choose<TestConfig::RenderTypes>(DE_ARRAY_BEGIN(renderCommands), DE_ARRAY_END(renderCommands));
5555 const TestConfig::CommandBufferTypes commandBuffer = rng.choose<TestConfig::CommandBufferTypes>(DE_ARRAY_BEGIN(commandBuffers), DE_ARRAY_END(commandBuffers));
5556 const vector<Subpass> subpasses (1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u, vector<AttachmentReference>(), colorAttachmentReferences, vector<AttachmentReference>(), AttachmentReference((useDepthStencil ? (deUint32)(attachments.size() - 1) : VK_ATTACHMENT_UNUSED), depthStencilLayout), vector<deUint32>()));
5557 const vector<SubpassDependency> deps;
5558 const string testCaseName = de::toString(attachmentCountNdx * testCaseCount + testCaseNdx);
5559 const RenderPass renderPass (attachments, subpasses, deps);
5560 const UVec2 targetSize = rng.choose<UVec2>(DE_ARRAY_BEGIN(targetSizes), DE_ARRAY_END(targetSizes));
5561 const UVec2 renderPos = rng.choose<UVec2>(DE_ARRAY_BEGIN(renderPositions), DE_ARRAY_END(renderPositions));
5562 const UVec2 renderSize = rng.choose<UVec2>(DE_ARRAY_BEGIN(renderSizes), DE_ARRAY_END(renderSizes));
5564 if (useDynamicRendering)
5566 // skip dynamic rendering cases (that don't add coverage) this can be done not earlier than after grabbing all
5567 // random numbers as we need to make sure that those tests that will be created for dynamic rendering have
5568 // corresponding renderpass tests with the same name
5569 if (!executeForDynamicRendering)
5572 // dont repeat non secondary buffer cases when testing secondaryCmdBufferCompletelyContainsDynamicRenderpass flag
5573 if (testConfigExternal.groupParams->secondaryCmdBufferCompletelyContainsDynamicRenderpass &&
5574 (commandBuffer != TestConfig::COMMANDBUFFERTYPES_SECONDARY))
5580 const TestConfig testConfig (renderPass,
5590 testConfigExternal.allocationKind,
5591 testConfigExternal.groupParams);
5593 addFunctionCaseWithPrograms<TestConfig>(attachmentCountGroup.get(), testCaseName.c_str(), testCaseName.c_str(), createTestShaders, renderPassTest, testConfig);
5597 group->addChild(attachmentCountGroup.release());
5601 void addAttachmentWriteMaskTests (tcu::TestCaseGroup* group, const TestConfigExternal testConfigExternal)
5603 const deUint32 attachmentCounts[] = { 1, 2, 3, 4, 8 };
5605 const VkFormat attachmentFormats[] =
5607 VK_FORMAT_R8G8B8A8_UINT,
5608 VK_FORMAT_R8G8B8A8_UNORM,
5609 VK_FORMAT_R5G6B5_UNORM_PACK16,
5610 VK_FORMAT_R8G8_UNORM
5613 tcu::TestContext& testCtx = group->getTestContext();
5615 for (deUint32 attachmentCountNdx = 0; attachmentCountNdx < DE_LENGTH_OF_ARRAY(attachmentCounts); attachmentCountNdx++)
5617 const deUint32 attachmentCount = attachmentCounts[attachmentCountNdx];
5618 const string groupName = "attachment_count_" + de::toString(attachmentCount);
5620 de::MovePtr<tcu::TestCaseGroup> attachmentCountGroup(new tcu::TestCaseGroup(testCtx, groupName.c_str(), de::toString(attachmentCount).c_str()));
5622 for (deUint32 drawStartNdx = 0; drawStartNdx < (attachmentCount); drawStartNdx++)
5624 deUint32 formatNdx = 0;
5625 vector<Attachment> attachments;
5626 vector<AttachmentReference> colorAttachmentReferences;
5628 for (deUint32 attachmentNdx = 0; attachmentNdx < attachmentCount; attachmentNdx++)
5630 const VkFormat format = attachmentFormats[formatNdx];
5631 const VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_1_BIT;
5632 const VkAttachmentLoadOp loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
5633 const VkAttachmentStoreOp storeOp = VK_ATTACHMENT_STORE_OP_STORE;
5634 const VkAttachmentLoadOp stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
5635 const VkAttachmentStoreOp stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
5636 const VkImageLayout initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
5637 const VkImageLayout finalizeLayout = (testConfigExternal.groupParams->renderingType == RENDERING_TYPE_DYNAMIC_RENDERING)
5638 ? initialLayout : VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
5639 const VkImageLayout subpassLayout = VK_IMAGE_LAYOUT_GENERAL;
5641 attachments.push_back(Attachment(format, sampleCount, loadOp, storeOp, stencilLoadOp, stencilStoreOp, initialLayout, finalizeLayout));
5642 colorAttachmentReferences.push_back(AttachmentReference((deUint32)attachmentNdx, subpassLayout));
5644 if (++formatNdx == DE_LENGTH_OF_ARRAY(attachmentFormats))
5649 const VkImageLayout depthStencilLayout = VK_IMAGE_LAYOUT_GENERAL;
5650 const vector<Subpass> subpass (1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u, vector<AttachmentReference>(), colorAttachmentReferences, vector<AttachmentReference>(), AttachmentReference(VK_ATTACHMENT_UNUSED, depthStencilLayout), vector<deUint32>()));
5651 const vector<SubpassDependency> deps;
5653 const string testCaseName = "start_index_" + de::toString(drawStartNdx);
5654 const RenderPass renderPass (attachments, subpass, deps);
5656 const TestConfig::RenderTypes render = TestConfig::RENDERTYPES_DRAW;
5657 const TestConfig::CommandBufferTypes commandBuffer = TestConfig::COMMANDBUFFERTYPES_INLINE;
5658 const TestConfig::ImageMemory imageMemory = TestConfig::IMAGEMEMORY_LAZY;
5659 const UVec2 targetSize = UVec2(64, 64);
5660 const UVec2 renderPos = UVec2(0, 0);
5661 const UVec2 renderSize = UVec2(64, 64);
5662 const deBool useFormatCompCount = DE_TRUE;
5663 const vector<DeviceCoreFeature> requiredFeatures = {DEVICE_CORE_FEATURE_INDEPENDENT_BLEND};
5664 const TestConfig testConfig (renderPass,
5674 testConfigExternal.allocationKind,
5675 testConfigExternal.groupParams,
5678 addFunctionCaseWithPrograms<TestConfig>(attachmentCountGroup.get(), testCaseName.c_str(), testCaseName.c_str(), checkSupport, createTestShaders, renderPassTest, testConfig);
5682 group->addChild(attachmentCountGroup.release());
5686 template<typename T>
5687 T chooseRandom (de::Random& rng, const set<T>& values)
5689 size_t ndx = ((size_t)rng.getUint32()) % values.size();
5690 typename set<T>::const_iterator iter = values.begin();
5692 for (; ndx > 0; ndx--)
5698 void addAttachmentAllocationTests (tcu::TestCaseGroup* group, const TestConfigExternal testConfigExternal)
5700 const deUint32 attachmentCounts[] = { 4, 8 };
5701 const VkAttachmentLoadOp loadOps[] =
5703 VK_ATTACHMENT_LOAD_OP_LOAD,
5704 VK_ATTACHMENT_LOAD_OP_CLEAR,
5705 VK_ATTACHMENT_LOAD_OP_DONT_CARE
5708 const VkAttachmentStoreOp storeOps[] =
5710 VK_ATTACHMENT_STORE_OP_STORE,
5711 VK_ATTACHMENT_STORE_OP_DONT_CARE
5714 const VkImageLayout initialAndFinalColorLayouts[] =
5716 VK_IMAGE_LAYOUT_GENERAL,
5717 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
5718 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
5719 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
5720 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
5723 const VkImageLayout initialAndFinalDepthStencilLayouts[] =
5725 VK_IMAGE_LAYOUT_GENERAL,
5726 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
5727 VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL,
5728 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
5729 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
5730 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
5733 const VkImageLayout subpassLayoutsColor[] =
5735 VK_IMAGE_LAYOUT_GENERAL,
5736 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
5739 const VkImageLayout subpassLayoutsDepthStencil[] =
5741 VK_IMAGE_LAYOUT_GENERAL,
5742 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL
5745 const VkImageLayout subpassLayoutsInput[] =
5747 VK_IMAGE_LAYOUT_GENERAL,
5748 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
5753 // Each pass uses one more attachmen than previous one
5754 ALLOCATIONTYPE_GROW,
5755 // Each pass uses one less attachment than previous one
5756 ALLOCATIONTYPE_SHRINK,
5757 // Each pass drops one attachment and picks up new one
5758 ALLOCATIONTYPE_ROLL,
5759 // Start by growing and end by shrinking
5760 ALLOCATIONTYPE_GROW_SHRINK,
5761 // Each subpass has single input and single output attachment
5762 ALLOCATIONTYPE_IO_CHAIN,
5763 // Each subpass has multiple inputs and multiple outputs attachment
5764 ALLOCATIONTYPE_IO_GENERIC
5767 const AllocationType allocationTypes[] =
5769 ALLOCATIONTYPE_GROW,
5770 ALLOCATIONTYPE_SHRINK,
5771 ALLOCATIONTYPE_ROLL,
5772 ALLOCATIONTYPE_GROW_SHRINK,
5773 ALLOCATIONTYPE_IO_CHAIN,
5774 ALLOCATIONTYPE_IO_GENERIC
5777 const char* const allocationTypeStr[] =
5783 "input_output_chain",
5787 const TestConfig::RenderTypes renderCommands[] =
5789 TestConfig::RENDERTYPES_NONE,
5790 TestConfig::RENDERTYPES_CLEAR,
5791 TestConfig::RENDERTYPES_DRAW,
5792 TestConfig::RENDERTYPES_CLEAR|TestConfig::RENDERTYPES_DRAW,
5795 const TestConfig::CommandBufferTypes commandBuffers[] =
5797 TestConfig::COMMANDBUFFERTYPES_INLINE,
5798 TestConfig::COMMANDBUFFERTYPES_SECONDARY,
5799 TestConfig::COMMANDBUFFERTYPES_INLINE|TestConfig::COMMANDBUFFERTYPES_SECONDARY
5802 const TestConfig::ImageMemory imageMemories[] =
5804 TestConfig::IMAGEMEMORY_STRICT,
5805 TestConfig::IMAGEMEMORY_LAZY,
5806 TestConfig::IMAGEMEMORY_STRICT|TestConfig::IMAGEMEMORY_LAZY
5809 const UVec2 targetSizes[] =
5815 const UVec2 renderPositions[] =
5821 const UVec2 renderSizes[] =
5827 tcu::TestContext& testCtx = group->getTestContext();
5828 de::Random rng (3700649827u);
5830 for (size_t allocationTypeNdx = 0; allocationTypeNdx < DE_LENGTH_OF_ARRAY(allocationTypes); allocationTypeNdx++)
5832 const AllocationType allocationType = allocationTypes[allocationTypeNdx];
5833 const size_t testCaseCount = 100;
5834 de::MovePtr<tcu::TestCaseGroup> allocationTypeGroup (new tcu::TestCaseGroup(testCtx, allocationTypeStr[allocationTypeNdx], allocationTypeStr[allocationTypeNdx]));
5836 for (size_t testCaseNdx = 0; testCaseNdx < testCaseCount; testCaseNdx++)
5838 if (allocationType == ALLOCATIONTYPE_IO_GENERIC)
5840 const deUint32 attachmentCount = 4u + rng.getUint32() % 31u;
5841 const deUint32 subpassCount = 4u + rng.getUint32() % 31u;
5842 vector<Attachment> attachments;
5844 set<deUint32> definedAttachments;
5846 vector<Subpass> subpasses;
5847 set<deUint32> colorAttachments;
5848 set<deUint32> depthStencilAttachments;
5850 for (deUint32 attachmentIndex = 0; attachmentIndex < attachmentCount; attachmentIndex++)
5852 const bool isDepthStencilAttachment = rng.getFloat() < 0.01f;
5853 const VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_1_BIT;
5854 const VkAttachmentLoadOp loadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
5855 const VkAttachmentStoreOp storeOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
5857 const VkImageLayout initialLayout = isDepthStencilAttachment
5858 ? rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalDepthStencilLayouts), DE_ARRAY_END(initialAndFinalDepthStencilLayouts))
5859 : rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalColorLayouts), DE_ARRAY_END(initialAndFinalColorLayouts));
5860 const VkImageLayout finalizeLayout = isDepthStencilAttachment
5861 ? rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalDepthStencilLayouts), DE_ARRAY_END(initialAndFinalDepthStencilLayouts))
5862 : rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalColorLayouts), DE_ARRAY_END(initialAndFinalColorLayouts));
5864 const VkAttachmentLoadOp stencilLoadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
5865 const VkAttachmentStoreOp stencilStoreOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
5867 if (isDepthStencilAttachment)
5869 const VkFormat format = rng.choose<VkFormat>(DE_ARRAY_BEGIN(s_coreDepthStencilFormats), DE_ARRAY_END(s_coreDepthStencilFormats));
5871 if (loadOp == VK_ATTACHMENT_LOAD_OP_LOAD || loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR
5872 || stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD || stencilLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR)
5873 definedAttachments.insert(attachmentIndex);
5875 depthStencilAttachments.insert(attachmentIndex);
5877 attachments.push_back(Attachment(format, sampleCount, loadOp, storeOp, stencilLoadOp, stencilStoreOp, initialLayout, finalizeLayout));
5881 const VkFormat format = rng.choose<VkFormat>(DE_ARRAY_BEGIN(s_coreColorFormats), DE_ARRAY_END(s_coreColorFormats));
5883 if (loadOp == VK_ATTACHMENT_LOAD_OP_LOAD || loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR)
5884 definedAttachments.insert(attachmentIndex);
5886 colorAttachments.insert(attachmentIndex);
5888 attachments.push_back(Attachment(format, sampleCount, loadOp, storeOp, stencilLoadOp, stencilStoreOp, initialLayout, finalizeLayout));
5891 vector<Maybe<deUint32> > lastUseOfAttachment (attachments.size(), tcu::Nothing);
5892 vector<SubpassDependency> deps;
5894 for (deUint32 subpassIndex = 0; subpassIndex < subpassCount; subpassIndex++)
5896 const deUint32 colorAttachmentCount = depthStencilAttachments.empty()
5897 ? 1 + rng.getUint32() % de::min(4u, (deUint32)colorAttachments.size())
5898 : rng.getUint32() % (de::min(4u, (deUint32)colorAttachments.size()) + 1u);
5899 const deUint32 inputAttachmentCount = rng.getUint32() % (deUint32)(de::min<size_t>(4, definedAttachments.size()) + 1);
5900 const bool useDepthStencilAttachment = !depthStencilAttachments.empty() && (colorAttachmentCount == 0 || rng.getBool());
5901 std::vector<deUint32> subpassColorAttachments (colorAttachmentCount);
5902 std::vector<deUint32> subpassInputAttachments (inputAttachmentCount);
5903 Maybe<deUint32> depthStencilAttachment (useDepthStencilAttachment
5904 ? just(chooseRandom(rng, depthStencilAttachments))
5906 std::vector<deUint32> subpassPreserveAttachments;
5908 rng.choose(colorAttachments.begin(), colorAttachments.end(), subpassColorAttachments.begin(), colorAttachmentCount);
5909 rng.choose(definedAttachments.begin(), definedAttachments.end(), subpassInputAttachments.begin(), inputAttachmentCount);
5911 for (size_t colorAttachmentNdx = 0; colorAttachmentNdx < subpassColorAttachments.size(); colorAttachmentNdx++)
5912 definedAttachments.insert(subpassColorAttachments[colorAttachmentNdx]);
5914 if (depthStencilAttachment)
5915 definedAttachments.insert(*depthStencilAttachment);
5918 std::vector<AttachmentReference> inputAttachmentReferences;
5919 std::vector<AttachmentReference> colorAttachmentReferences;
5920 AttachmentReference depthStencilAttachmentReference (VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL);
5922 for (size_t colorAttachmentNdx = 0; colorAttachmentNdx < subpassColorAttachments.size(); colorAttachmentNdx++)
5924 const deUint32 colorAttachmentIndex = subpassColorAttachments[colorAttachmentNdx];
5926 if (lastUseOfAttachment[colorAttachmentIndex])
5928 deBool foundDuplicate = false;
5930 const deUint32 srcPass = *lastUseOfAttachment[colorAttachmentIndex];
5931 const deUint32 dstPass = subpassIndex;
5932 const VkDependencyFlags dependencyFlags = rng.getBool() ? (VkDependencyFlags) VK_DEPENDENCY_BY_REGION_BIT : 0u;
5934 const SubpassDependency newDependency(srcPass, dstPass,
5935 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
5936 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
5937 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
5938 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
5940 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
5941 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
5942 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
5943 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
5945 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
5946 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT,
5950 for (SubpassDependency& dependency : deps)
5952 if (dependency.getSrcPass() == srcPass && dependency.getDstPass() == dstPass)
5954 const VkAccessFlags newDstFlags = dependency.getDstAccessMask() | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT;
5955 dependency.setDstAccessMask(newDstFlags);
5956 foundDuplicate = true;
5961 if (!foundDuplicate)
5963 deps.push_back(newDependency);
5967 lastUseOfAttachment[colorAttachmentIndex] = just(subpassIndex);
5969 colorAttachmentReferences.push_back(AttachmentReference((deUint32)subpassColorAttachments[colorAttachmentNdx], VK_IMAGE_LAYOUT_GENERAL));
5972 for (size_t inputAttachmentNdx = 0; inputAttachmentNdx < subpassInputAttachments.size(); inputAttachmentNdx++)
5974 const deUint32 inputAttachmentIndex = subpassInputAttachments[inputAttachmentNdx];
5976 if(lastUseOfAttachment[inputAttachmentIndex])
5978 deBool foundDuplicate = false;
5980 const deUint32 srcPass = *lastUseOfAttachment[inputAttachmentIndex];
5981 const deUint32 dstPass = subpassIndex;
5982 const VkDependencyFlags dependencyFlags = ((srcPass == subpassIndex) || rng.getBool()) ? (VkDependencyFlags)VK_DEPENDENCY_BY_REGION_BIT : 0u;
5984 const SubpassDependency newDependency(srcPass, dstPass,
5985 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
5986 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
5987 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
5988 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
5990 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
5991 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
5992 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
5993 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
5995 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
5996 VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
5999 for (SubpassDependency& dependency : deps)
6001 if (dependency.getSrcPass() == srcPass && dependency.getDstPass() == dstPass)
6003 const VkAccessFlags newSrcFlags = dependency.getSrcAccessMask() | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
6004 const VkAccessFlags newDstFlags = dependency.getDstAccessMask() | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT;
6005 dependency.setDstAccessMask(newSrcFlags);
6006 dependency.setDstAccessMask(newDstFlags);
6007 foundDuplicate = true;
6012 if (!foundDuplicate)
6014 deps.push_back(newDependency);
6017 lastUseOfAttachment[inputAttachmentIndex] = just(subpassIndex);
6019 VkImageAspectFlags aspect = 0u;
6020 if (testConfigExternal.groupParams->renderingType == RENDERING_TYPE_RENDERPASS2)
6022 bool col = colorAttachments.find(inputAttachmentIndex) != colorAttachments.end();
6023 aspect = col ? VK_IMAGE_ASPECT_COLOR_BIT : VK_IMAGE_ASPECT_DEPTH_BIT;
6025 inputAttachmentReferences.push_back(AttachmentReference((deUint32)subpassInputAttachments[inputAttachmentNdx], VK_IMAGE_LAYOUT_GENERAL, aspect));
6029 if (depthStencilAttachment)
6031 if (lastUseOfAttachment[*depthStencilAttachment])
6033 deBool foundDuplicate = false;
6035 const deUint32 srcPass = *lastUseOfAttachment[*depthStencilAttachment];
6036 const deUint32 dstPass = subpassIndex;
6037 const VkDependencyFlags dependencyFlags = ((srcPass == subpassIndex) || rng.getBool()) ? (VkDependencyFlags)VK_DEPENDENCY_BY_REGION_BIT : 0u;
6039 const SubpassDependency newDependency(srcPass, dstPass,
6040 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
6041 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
6042 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
6043 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
6045 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
6046 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
6047 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
6048 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
6050 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
6051 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT
6052 | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
6055 for (SubpassDependency& dependency : deps)
6057 if (dependency.getSrcPass() == srcPass && dependency.getDstPass() == dstPass)
6059 const VkAccessFlags newSrcFlags = dependency.getSrcAccessMask() | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
6060 const VkAccessFlags newDstFlags = dependency.getDstAccessMask() | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT;
6061 dependency.setDstAccessMask(newSrcFlags);
6062 dependency.setDstAccessMask(newDstFlags);
6063 foundDuplicate = true;
6068 if (!foundDuplicate)
6070 deps.push_back(newDependency);
6074 lastUseOfAttachment[*depthStencilAttachment] = just(subpassIndex);
6076 depthStencilAttachmentReference = AttachmentReference(*depthStencilAttachment, VK_IMAGE_LAYOUT_GENERAL);
6079 depthStencilAttachmentReference = AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL);
6081 vector<deUint32> preserveAttachments;
6082 for (deUint32 attachmentIndex = 0; attachmentIndex < (deUint32)attachments.size(); attachmentIndex++)
6084 if (lastUseOfAttachment[attachmentIndex] && (*lastUseOfAttachment[attachmentIndex]) != subpassIndex)
6085 preserveAttachments.push_back(attachmentIndex);
6088 // Use random image layout when possible
6089 for (size_t colorRefIdx = 0; colorRefIdx < colorAttachmentReferences.size(); ++colorRefIdx)
6091 bool usedAsInput = false;
6092 for (size_t inputRefIdx = 0; inputRefIdx < inputAttachmentReferences.size(); ++inputRefIdx)
6093 if (colorAttachmentReferences[colorRefIdx].getAttachment() == inputAttachmentReferences[inputRefIdx].getAttachment())
6097 colorAttachmentReferences[colorRefIdx].setImageLayout(rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayoutsColor), DE_ARRAY_END(subpassLayoutsColor)));
6099 for (size_t inputRefIdx = 0; inputRefIdx < inputAttachmentReferences.size(); ++inputRefIdx)
6101 bool usedAsDepthStencil = inputAttachmentReferences[inputRefIdx].getAttachment() == depthStencilAttachmentReference.getAttachment();
6102 bool usedAsColor = false;
6103 for (size_t colorRefIdx = 0; colorRefIdx < colorAttachmentReferences.size(); ++colorRefIdx)
6104 if (inputAttachmentReferences[inputRefIdx].getAttachment() == colorAttachmentReferences[colorRefIdx].getAttachment())
6107 if (!usedAsColor && !usedAsDepthStencil)
6108 inputAttachmentReferences[inputRefIdx].setImageLayout(rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayoutsInput), DE_ARRAY_END(subpassLayoutsInput)));
6111 bool usedAsInput = false;
6112 for (size_t inputRefIdx = 0; inputRefIdx < inputAttachmentReferences.size(); ++inputRefIdx)
6113 if (depthStencilAttachmentReference.getAttachment() == inputAttachmentReferences[inputRefIdx].getAttachment())
6117 depthStencilAttachmentReference.setImageLayout(rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayoutsDepthStencil), DE_ARRAY_END(subpassLayoutsDepthStencil)));
6120 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
6121 inputAttachmentReferences,
6122 colorAttachmentReferences,
6123 vector<AttachmentReference>(),
6124 depthStencilAttachmentReference,
6125 preserveAttachments));
6129 const TestConfig::RenderTypes render = rng.choose<TestConfig::RenderTypes>(DE_ARRAY_BEGIN(renderCommands), DE_ARRAY_END(renderCommands));
6130 const TestConfig::CommandBufferTypes commandBuffer = rng.choose<TestConfig::CommandBufferTypes>(DE_ARRAY_BEGIN(commandBuffers), DE_ARRAY_END(commandBuffers));
6131 const TestConfig::ImageMemory imageMemory = rng.choose<TestConfig::ImageMemory>(DE_ARRAY_BEGIN(imageMemories), DE_ARRAY_END(imageMemories));
6133 const string testCaseName = de::toString(testCaseNdx);
6134 const UVec2 targetSize = rng.choose<UVec2>(DE_ARRAY_BEGIN(targetSizes), DE_ARRAY_END(targetSizes));
6135 const UVec2 renderPos = rng.choose<UVec2>(DE_ARRAY_BEGIN(renderPositions), DE_ARRAY_END(renderPositions));
6136 const UVec2 renderSize = rng.choose<UVec2>(DE_ARRAY_BEGIN(renderSizes), DE_ARRAY_END(renderSizes));
6138 const RenderPass renderPass (attachments, subpasses, deps);
6139 const TestConfig testConfig (renderPass,
6149 testConfigExternal.allocationKind,
6150 testConfigExternal.groupParams);
6152 addFunctionCaseWithPrograms<TestConfig>(allocationTypeGroup.get(), testCaseName.c_str(), testCaseName.c_str(), createTestShaders, renderPassTest, testConfig);
6157 const deUint32 attachmentCount = rng.choose<deUint32>(DE_ARRAY_BEGIN(attachmentCounts), DE_ARRAY_END(attachmentCounts));
6158 vector<Attachment> attachments;
6159 vector<Subpass> subpasses;
6161 for (size_t attachmentNdx = 0; attachmentNdx < attachmentCount; attachmentNdx++)
6163 const VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_1_BIT;
6164 const VkFormat format = rng.choose<VkFormat>(DE_ARRAY_BEGIN(s_coreColorFormats), DE_ARRAY_END(s_coreColorFormats));
6165 const VkAttachmentLoadOp loadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
6166 const VkAttachmentStoreOp storeOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
6168 const VkImageLayout initialLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalColorLayouts), DE_ARRAY_END(initialAndFinalColorLayouts));
6169 const VkImageLayout finalizeLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalColorLayouts), DE_ARRAY_END(initialAndFinalColorLayouts));
6171 const VkAttachmentLoadOp stencilLoadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
6172 const VkAttachmentStoreOp stencilStoreOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
6174 attachments.push_back(Attachment(format, sampleCount, loadOp, storeOp, stencilLoadOp, stencilStoreOp, initialLayout, finalizeLayout));
6177 if (allocationType == ALLOCATIONTYPE_GROW)
6179 for (size_t subpassNdx = 0; subpassNdx < attachmentCount; subpassNdx++)
6181 vector<AttachmentReference> colorAttachmentReferences;
6183 for (size_t attachmentNdx = 0; attachmentNdx < subpassNdx + 1; attachmentNdx++)
6185 const VkImageLayout subpassLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayoutsColor), DE_ARRAY_END(subpassLayoutsColor));
6187 colorAttachmentReferences.push_back(AttachmentReference((deUint32)attachmentNdx, subpassLayout));
6190 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
6191 vector<AttachmentReference>(),
6192 colorAttachmentReferences,
6193 vector<AttachmentReference>(),
6194 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6195 vector<deUint32>()));
6198 else if (allocationType == ALLOCATIONTYPE_SHRINK)
6200 for (size_t subpassNdx = 0; subpassNdx < attachmentCount; subpassNdx++)
6202 vector<AttachmentReference> colorAttachmentReferences;
6204 for (size_t attachmentNdx = 0; attachmentNdx < (attachmentCount - subpassNdx); attachmentNdx++)
6206 const VkImageLayout subpassLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayoutsColor), DE_ARRAY_END(subpassLayoutsColor));
6208 colorAttachmentReferences.push_back(AttachmentReference((deUint32)attachmentNdx, subpassLayout));
6211 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
6212 vector<AttachmentReference>(),
6213 colorAttachmentReferences,
6214 vector<AttachmentReference>(),
6215 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6216 vector<deUint32>()));
6219 else if (allocationType == ALLOCATIONTYPE_ROLL)
6221 for (size_t subpassNdx = 0; subpassNdx < attachmentCount / 2; subpassNdx++)
6223 vector<AttachmentReference> colorAttachmentReferences;
6225 for (size_t attachmentNdx = 0; attachmentNdx < attachmentCount / 2; attachmentNdx++)
6227 const VkImageLayout subpassLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayoutsColor), DE_ARRAY_END(subpassLayoutsColor));
6229 colorAttachmentReferences.push_back(AttachmentReference((deUint32)(subpassNdx + attachmentNdx), subpassLayout));
6232 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
6233 vector<AttachmentReference>(),
6234 colorAttachmentReferences,
6235 vector<AttachmentReference>(),
6236 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6237 vector<deUint32>()));
6240 else if (allocationType == ALLOCATIONTYPE_GROW_SHRINK)
6242 for (size_t subpassNdx = 0; subpassNdx < attachmentCount; subpassNdx++)
6244 vector<AttachmentReference> colorAttachmentReferences;
6246 for (size_t attachmentNdx = 0; attachmentNdx < subpassNdx + 1; attachmentNdx++)
6248 const VkImageLayout subpassLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayoutsColor), DE_ARRAY_END(subpassLayoutsColor));
6250 colorAttachmentReferences.push_back(AttachmentReference((deUint32)attachmentNdx, subpassLayout));
6253 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
6254 vector<AttachmentReference>(),
6255 colorAttachmentReferences,
6256 vector<AttachmentReference>(),
6257 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6258 vector<deUint32>()));
6260 for (size_t subpassNdx = 0; subpassNdx < attachmentCount; subpassNdx++)
6262 vector<AttachmentReference> colorAttachmentReferences;
6264 for (size_t attachmentNdx = 0; attachmentNdx < (attachmentCount - subpassNdx); attachmentNdx++)
6266 const VkImageLayout subpassLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayoutsColor), DE_ARRAY_END(subpassLayoutsColor));
6268 colorAttachmentReferences.push_back(AttachmentReference((deUint32)attachmentNdx, subpassLayout));
6271 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
6272 vector<AttachmentReference>(),
6273 colorAttachmentReferences,
6274 vector<AttachmentReference>(),
6275 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6276 vector<deUint32>()));
6279 else if (allocationType == ALLOCATIONTYPE_IO_CHAIN)
6281 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
6282 vector<AttachmentReference>(),
6283 vector<AttachmentReference>(1, AttachmentReference(0, rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayoutsColor), DE_ARRAY_END(subpassLayoutsColor)))),
6284 vector<AttachmentReference>(),
6285 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6286 vector<deUint32>()));
6288 for (size_t subpassNdx = 1; subpassNdx < attachmentCount; subpassNdx++)
6290 const VkImageAspectFlags inputAttachmentAspectMask = (testConfigExternal.groupParams->renderingType == RENDERING_TYPE_RENDERPASS2) ? VK_IMAGE_ASPECT_COLOR_BIT : static_cast<VkImageAspectFlagBits>(0);
6291 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
6292 vector<AttachmentReference>(1, AttachmentReference((deUint32)(subpassNdx - 1), VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, inputAttachmentAspectMask)),
6293 vector<AttachmentReference>(1, AttachmentReference((deUint32)(subpassNdx), rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayoutsColor), DE_ARRAY_END(subpassLayoutsColor)))),
6294 vector<AttachmentReference>(),
6295 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6296 vector<deUint32>()));
6300 DE_FATAL("Unknown allocation type");
6303 const TestConfig::RenderTypes render = rng.choose<TestConfig::RenderTypes>(DE_ARRAY_BEGIN(renderCommands), DE_ARRAY_END(renderCommands));
6304 const TestConfig::CommandBufferTypes commandBuffer = rng.choose<TestConfig::CommandBufferTypes>(DE_ARRAY_BEGIN(commandBuffers), DE_ARRAY_END(commandBuffers));
6305 const TestConfig::ImageMemory imageMemory = rng.choose<TestConfig::ImageMemory>(DE_ARRAY_BEGIN(imageMemories), DE_ARRAY_END(imageMemories));
6307 const string testCaseName = de::toString(testCaseNdx);
6308 const UVec2 targetSize = rng.choose<UVec2>(DE_ARRAY_BEGIN(targetSizes), DE_ARRAY_END(targetSizes));
6309 const UVec2 renderPos = rng.choose<UVec2>(DE_ARRAY_BEGIN(renderPositions), DE_ARRAY_END(renderPositions));
6310 const UVec2 renderSize = rng.choose<UVec2>(DE_ARRAY_BEGIN(renderSizes), DE_ARRAY_END(renderSizes));
6312 vector<SubpassDependency> deps;
6314 for (size_t subpassNdx = 0; subpassNdx < subpasses.size() - 1; subpassNdx++)
6316 const bool byRegion = rng.getBool();
6317 deps.push_back(SubpassDependency((deUint32)subpassNdx, (deUint32)subpassNdx + 1,
6318 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
6319 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
6320 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
6321 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
6323 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
6324 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
6325 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
6326 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
6328 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
6329 (VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT),
6331 byRegion ? (VkDependencyFlags)VK_DEPENDENCY_BY_REGION_BIT : 0u));
6334 const RenderPass renderPass (attachments, subpasses, deps);
6335 const TestConfig testConfig (renderPass,
6345 testConfigExternal.allocationKind,
6346 testConfigExternal.groupParams);
6348 addFunctionCaseWithPrograms<TestConfig>(allocationTypeGroup.get(), testCaseName.c_str(), testCaseName.c_str(), createTestShaders, renderPassTest, testConfig);
6352 group->addChild(allocationTypeGroup.release());
6356 void addSimpleTests (tcu::TestCaseGroup* group, const TestConfigExternal testConfigExternal)
6358 const UVec2 targetSize (64, 64);
6359 const UVec2 renderPos (0, 0);
6360 const UVec2 renderSize (64, 64);
6364 const RenderPass renderPass (vector<Attachment>(1, Attachment(VK_FORMAT_R8G8B8A8_UNORM,
6365 VK_SAMPLE_COUNT_1_BIT,
6366 VK_ATTACHMENT_LOAD_OP_CLEAR,
6367 VK_ATTACHMENT_STORE_OP_STORE,
6368 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6369 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6370 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
6371 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6372 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6374 vector<AttachmentReference>(),
6375 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6376 vector<AttachmentReference>(),
6377 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6378 vector<deUint32>())),
6379 vector<SubpassDependency>());
6380 const TestConfig testConfig (renderPass,
6381 TestConfig::RENDERTYPES_DRAW,
6382 TestConfig::COMMANDBUFFERTYPES_INLINE,
6383 TestConfig::IMAGEMEMORY_STRICT,
6390 testConfigExternal.allocationKind,
6391 testConfigExternal.groupParams);
6393 addFunctionCaseWithPrograms<TestConfig>(group, "color", "Single color attachment case.", createTestShaders, renderPassTest, testConfig);
6398 const RenderPass renderPass (vector<Attachment>(1, Attachment(VK_FORMAT_X8_D24_UNORM_PACK32,
6399 VK_SAMPLE_COUNT_1_BIT,
6400 VK_ATTACHMENT_LOAD_OP_CLEAR,
6401 VK_ATTACHMENT_STORE_OP_STORE,
6402 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6403 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6404 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
6405 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)),
6406 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6408 vector<AttachmentReference>(),
6409 vector<AttachmentReference>(),
6410 vector<AttachmentReference>(),
6411 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
6412 vector<deUint32>())),
6413 vector<SubpassDependency>());
6414 const TestConfig testConfig (renderPass,
6415 TestConfig::RENDERTYPES_DRAW,
6416 TestConfig::COMMANDBUFFERTYPES_INLINE,
6417 TestConfig::IMAGEMEMORY_STRICT,
6424 testConfigExternal.allocationKind,
6425 testConfigExternal.groupParams);
6427 addFunctionCaseWithPrograms<TestConfig>(group, "depth", "Single depth attachment case.", createTestShaders, renderPassTest, testConfig);
6432 const RenderPass renderPass (vector<Attachment>(1, Attachment(VK_FORMAT_S8_UINT,
6433 VK_SAMPLE_COUNT_1_BIT,
6434 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6435 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6436 VK_ATTACHMENT_LOAD_OP_CLEAR,
6437 VK_ATTACHMENT_STORE_OP_STORE,
6438 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
6439 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)),
6440 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6442 vector<AttachmentReference>(),
6443 vector<AttachmentReference>(),
6444 vector<AttachmentReference>(),
6445 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
6446 vector<deUint32>())),
6447 vector<SubpassDependency>());
6448 const TestConfig testConfig (renderPass,
6449 TestConfig::RENDERTYPES_DRAW,
6450 TestConfig::COMMANDBUFFERTYPES_INLINE,
6451 TestConfig::IMAGEMEMORY_STRICT,
6458 testConfigExternal.allocationKind,
6459 testConfigExternal.groupParams);
6461 addFunctionCaseWithPrograms<TestConfig>(group, "stencil", "Single stencil attachment case.", createTestShaders, renderPassTest, testConfig);
6466 const RenderPass renderPass (vector<Attachment>(1, Attachment(VK_FORMAT_D24_UNORM_S8_UINT,
6467 VK_SAMPLE_COUNT_1_BIT,
6468 VK_ATTACHMENT_LOAD_OP_CLEAR,
6469 VK_ATTACHMENT_STORE_OP_STORE,
6470 VK_ATTACHMENT_LOAD_OP_CLEAR,
6471 VK_ATTACHMENT_STORE_OP_STORE,
6472 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
6473 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)),
6474 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6476 vector<AttachmentReference>(),
6477 vector<AttachmentReference>(),
6478 vector<AttachmentReference>(),
6479 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
6480 vector<deUint32>())),
6481 vector<SubpassDependency>());
6482 const TestConfig testConfig (renderPass,
6483 TestConfig::RENDERTYPES_DRAW,
6484 TestConfig::COMMANDBUFFERTYPES_INLINE,
6485 TestConfig::IMAGEMEMORY_STRICT,
6492 testConfigExternal.allocationKind,
6493 testConfigExternal.groupParams);
6495 addFunctionCaseWithPrograms<TestConfig>(group, "depth_stencil", "Single depth stencil attachment case.", createTestShaders, renderPassTest, testConfig);
6500 const Attachment attachments[] =
6502 Attachment(VK_FORMAT_R8G8B8A8_UNORM,
6503 VK_SAMPLE_COUNT_1_BIT,
6504 VK_ATTACHMENT_LOAD_OP_CLEAR,
6505 VK_ATTACHMENT_STORE_OP_STORE,
6506 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6507 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6508 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
6509 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL),
6510 Attachment(VK_FORMAT_X8_D24_UNORM_PACK32,
6511 VK_SAMPLE_COUNT_1_BIT,
6512 VK_ATTACHMENT_LOAD_OP_CLEAR,
6513 VK_ATTACHMENT_STORE_OP_STORE,
6514 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6515 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6516 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
6517 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
6520 const RenderPass renderPass (vector<Attachment>(DE_ARRAY_BEGIN(attachments), DE_ARRAY_END(attachments)),
6521 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6523 vector<AttachmentReference>(),
6524 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6525 vector<AttachmentReference>(),
6526 AttachmentReference(1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
6527 vector<deUint32>())),
6528 vector<SubpassDependency>());
6529 const TestConfig testConfig (renderPass,
6530 TestConfig::RENDERTYPES_DRAW,
6531 TestConfig::COMMANDBUFFERTYPES_INLINE,
6532 TestConfig::IMAGEMEMORY_STRICT,
6539 testConfigExternal.allocationKind,
6540 testConfigExternal.groupParams);
6542 addFunctionCaseWithPrograms<TestConfig>(group, "color_depth", "Color and depth attachment case.", createTestShaders, renderPassTest, testConfig);
6547 const Attachment attachments[] =
6549 Attachment(VK_FORMAT_R8G8B8A8_UNORM,
6550 VK_SAMPLE_COUNT_1_BIT,
6551 VK_ATTACHMENT_LOAD_OP_CLEAR,
6552 VK_ATTACHMENT_STORE_OP_STORE,
6553 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6554 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6555 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
6556 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL),
6557 Attachment(VK_FORMAT_S8_UINT,
6558 VK_SAMPLE_COUNT_1_BIT,
6559 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6560 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6561 VK_ATTACHMENT_LOAD_OP_CLEAR,
6562 VK_ATTACHMENT_STORE_OP_STORE,
6563 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
6564 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
6567 const RenderPass renderPass (vector<Attachment>(DE_ARRAY_BEGIN(attachments), DE_ARRAY_END(attachments)),
6568 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6570 vector<AttachmentReference>(),
6571 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6572 vector<AttachmentReference>(),
6573 AttachmentReference(1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
6574 vector<deUint32>())),
6575 vector<SubpassDependency>());
6576 const TestConfig testConfig (renderPass,
6577 TestConfig::RENDERTYPES_DRAW,
6578 TestConfig::COMMANDBUFFERTYPES_INLINE,
6579 TestConfig::IMAGEMEMORY_STRICT,
6586 testConfigExternal.allocationKind,
6587 testConfigExternal.groupParams);
6589 addFunctionCaseWithPrograms<TestConfig>(group, "color_stencil", "Color and stencil attachment case.", createTestShaders, renderPassTest, testConfig);
6592 // color_depth_stencil
6594 const Attachment attachments[] =
6596 Attachment(VK_FORMAT_R8G8B8A8_UNORM,
6597 VK_SAMPLE_COUNT_1_BIT,
6598 VK_ATTACHMENT_LOAD_OP_CLEAR,
6599 VK_ATTACHMENT_STORE_OP_STORE,
6600 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6601 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6602 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
6603 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL),
6604 Attachment(VK_FORMAT_D24_UNORM_S8_UINT,
6605 VK_SAMPLE_COUNT_1_BIT,
6606 VK_ATTACHMENT_LOAD_OP_CLEAR,
6607 VK_ATTACHMENT_STORE_OP_STORE,
6608 VK_ATTACHMENT_LOAD_OP_CLEAR,
6609 VK_ATTACHMENT_STORE_OP_STORE,
6610 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
6611 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
6614 const RenderPass renderPass (vector<Attachment>(DE_ARRAY_BEGIN(attachments), DE_ARRAY_END(attachments)),
6615 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6617 vector<AttachmentReference>(),
6618 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6619 vector<AttachmentReference>(),
6620 AttachmentReference(1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
6621 vector<deUint32>())),
6622 vector<SubpassDependency>());
6623 const TestConfig testConfig (renderPass,
6624 TestConfig::RENDERTYPES_DRAW,
6625 TestConfig::COMMANDBUFFERTYPES_INLINE,
6626 TestConfig::IMAGEMEMORY_STRICT,
6633 testConfigExternal.allocationKind,
6634 testConfigExternal.groupParams);
6636 addFunctionCaseWithPrograms<TestConfig>(group, "color_depth_stencil", "Color, depth and stencil attachment case.", createTestShaders, renderPassTest, testConfig);
6641 const RenderPass renderPass (vector<Attachment>(),
6642 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6644 vector<AttachmentReference>(),
6645 vector<AttachmentReference>(),
6646 vector<AttachmentReference>(),
6647 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6648 vector<deUint32>())),
6649 vector<SubpassDependency>());
6650 const TestConfig testConfig (renderPass,
6651 TestConfig::RENDERTYPES_DRAW,
6652 TestConfig::COMMANDBUFFERTYPES_INLINE,
6653 TestConfig::IMAGEMEMORY_STRICT,
6660 testConfigExternal.allocationKind,
6661 testConfigExternal.groupParams);
6663 addFunctionCaseWithPrograms<TestConfig>(group, "no_attachments", "No attachments case.", createTestShaders, renderPassTest, testConfig);
6666 // color_unused_omit_blend_state
6667 if (testConfigExternal.groupParams->renderingType != RENDERING_TYPE_DYNAMIC_RENDERING)
6669 vector<Subpass> subpasses;
6671 // First subpass: use color attachment, create pipeline with color blend state
6672 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6674 vector<AttachmentReference>(),
6675 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6676 vector<AttachmentReference>(),
6677 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6681 // Second subpass: don't use color attachment, create pipeline without color blend state
6682 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6684 vector<AttachmentReference>(),
6685 vector<AttachmentReference>(1, AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6686 vector<AttachmentReference>(),
6687 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6691 const RenderPass renderPass (vector<Attachment>(1, Attachment(VK_FORMAT_R8G8B8A8_UNORM,
6692 VK_SAMPLE_COUNT_1_BIT,
6693 VK_ATTACHMENT_LOAD_OP_CLEAR,
6694 VK_ATTACHMENT_STORE_OP_STORE,
6695 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6696 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6697 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
6698 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6700 vector<SubpassDependency>());
6702 const TestConfig testConfig (renderPass,
6703 TestConfig::RENDERTYPES_DRAW,
6704 TestConfig::COMMANDBUFFERTYPES_INLINE,
6705 TestConfig::IMAGEMEMORY_STRICT,
6712 testConfigExternal.allocationKind,
6713 testConfigExternal.groupParams);
6714 addFunctionCaseWithPrograms<TestConfig>(group, "color_unused_omit_blend_state", "Two unused color attachment case without blend state", createTestShaders, renderPassTest, testConfig);
6718 std::string formatToName (VkFormat format)
6720 const std::string formatStr = de::toString(format);
6721 const std::string prefix = "VK_FORMAT_";
6723 DE_ASSERT(formatStr.substr(0, prefix.length()) == prefix);
6725 return de::toLower(formatStr.substr(prefix.length()));
6728 void addFormatTests (tcu::TestCaseGroup* group, const TestConfigExternal testConfigExternal)
6730 tcu::TestContext& testCtx = group->getTestContext();
6732 const UVec2 targetSize (64, 64);
6733 const UVec2 renderPos (0, 0);
6734 const UVec2 renderSize (64, 64);
6738 const char* const str;
6739 const VkAttachmentStoreOp op;
6742 { "store", VK_ATTACHMENT_STORE_OP_STORE },
6743 { "dont_care", VK_ATTACHMENT_STORE_OP_DONT_CARE }
6748 const char* const str;
6749 const VkAttachmentLoadOp op;
6752 { "clear", VK_ATTACHMENT_LOAD_OP_CLEAR },
6753 { "load", VK_ATTACHMENT_LOAD_OP_LOAD },
6754 { "dont_care", VK_ATTACHMENT_LOAD_OP_DONT_CARE }
6759 const char* const str;
6760 const TestConfig::RenderTypes types;
6763 { "clear", TestConfig::RENDERTYPES_CLEAR },
6764 { "draw", TestConfig::RENDERTYPES_DRAW },
6765 { "clear_draw", TestConfig::RENDERTYPES_CLEAR|TestConfig::RENDERTYPES_DRAW }
6769 for (size_t formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(s_coreColorFormats); formatNdx++)
6771 const VkFormat format = s_coreColorFormats[formatNdx];
6772 de::MovePtr<tcu::TestCaseGroup> formatGroup (new tcu::TestCaseGroup(testCtx, formatToName(format).c_str(), de::toString(format).c_str()));
6774 for (size_t loadOpNdx = 0; loadOpNdx < DE_LENGTH_OF_ARRAY(loadOps); loadOpNdx++)
6776 const VkAttachmentLoadOp loadOp = loadOps[loadOpNdx].op;
6777 de::MovePtr<tcu::TestCaseGroup> loadOpGroup (new tcu::TestCaseGroup(testCtx, loadOps[loadOpNdx].str, loadOps[loadOpNdx].str));
6779 for (size_t renderTypeNdx = 0; renderTypeNdx < DE_LENGTH_OF_ARRAY(renderTypes); renderTypeNdx++)
6781 const RenderPass renderPass (vector<Attachment>(1, Attachment(format,
6782 VK_SAMPLE_COUNT_1_BIT,
6784 VK_ATTACHMENT_STORE_OP_STORE,
6785 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6786 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6787 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
6788 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6789 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6791 vector<AttachmentReference>(),
6792 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6793 vector<AttachmentReference>(),
6794 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6795 vector<deUint32>())),
6796 vector<SubpassDependency>());
6797 const TestConfig testConfig (renderPass,
6798 renderTypes[renderTypeNdx].types,
6799 TestConfig::COMMANDBUFFERTYPES_INLINE,
6800 TestConfig::IMAGEMEMORY_STRICT,
6807 testConfigExternal.allocationKind,
6808 testConfigExternal.groupParams);
6810 addFunctionCaseWithPrograms<TestConfig>(loadOpGroup.get(), renderTypes[renderTypeNdx].str, renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
6813 formatGroup->addChild(loadOpGroup.release());
6816 if (testConfigExternal.groupParams->renderingType != RENDERING_TYPE_DYNAMIC_RENDERING)
6818 de::MovePtr<tcu::TestCaseGroup> inputGroup (new tcu::TestCaseGroup(testCtx, "input", "Test attachment format as input"));
6820 for (size_t loadOpNdx = 0; loadOpNdx < DE_LENGTH_OF_ARRAY(loadOps); loadOpNdx++)
6822 const VkAttachmentLoadOp loadOp = loadOps[loadOpNdx].op;
6823 de::MovePtr<tcu::TestCaseGroup> loadOpGroup (new tcu::TestCaseGroup(testCtx, loadOps[loadOpNdx].str, loadOps[loadOpNdx].str));
6825 for (size_t storeOpNdx = 0; storeOpNdx < DE_LENGTH_OF_ARRAY(storeOps); storeOpNdx++)
6827 const VkImageAspectFlags inputAttachmentAspectMask = (testConfigExternal.groupParams->renderingType == RENDERING_TYPE_RENDERPASS2)
6828 ? static_cast<VkImageAspectFlags>(VK_IMAGE_ASPECT_COLOR_BIT)
6829 : static_cast<VkImageAspectFlags>(0);
6830 const VkAttachmentStoreOp storeOp = storeOps[storeOpNdx].op;
6831 de::MovePtr<tcu::TestCaseGroup> storeOpGroup (new tcu::TestCaseGroup(testCtx, storeOps[storeOpNdx].str, storeOps[storeOpNdx].str));
6833 for (size_t useInputAspectNdx = 0; useInputAspectNdx < 2; useInputAspectNdx++)
6835 const bool useInputAspect = useInputAspectNdx != 0;
6837 if (testConfigExternal.groupParams->renderingType == RENDERING_TYPE_RENDERPASS2 && useInputAspect)
6840 for (size_t renderTypeNdx = 0; renderTypeNdx < DE_LENGTH_OF_ARRAY(renderTypes); renderTypeNdx++)
6843 vector<Attachment> attachments;
6844 vector<Subpass> subpasses;
6845 vector<SubpassDependency> deps;
6846 vector<VkInputAttachmentAspectReference> inputAspects;
6848 attachments.push_back(Attachment(format,
6849 VK_SAMPLE_COUNT_1_BIT,
6852 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6853 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6854 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
6855 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
6857 attachments.push_back(Attachment(vk::VK_FORMAT_R8G8B8A8_UNORM,
6858 VK_SAMPLE_COUNT_1_BIT,
6859 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6860 VK_ATTACHMENT_STORE_OP_STORE,
6861 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6862 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6863 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
6864 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
6866 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6868 vector<AttachmentReference>(),
6869 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6870 vector<AttachmentReference>(),
6871 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6872 vector<deUint32>()));
6873 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6875 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, inputAttachmentAspectMask)),
6876 vector<AttachmentReference>(1, AttachmentReference(1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6877 vector<AttachmentReference>(),
6878 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6879 vector<deUint32>()));
6881 deps.push_back(SubpassDependency(0, 1,
6883 vk::VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
6884 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
6886 vk::VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
6887 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
6888 vk::VK_DEPENDENCY_BY_REGION_BIT));
6892 const VkInputAttachmentAspectReference inputAspect =
6896 VK_IMAGE_ASPECT_COLOR_BIT
6899 inputAspects.push_back(inputAspect);
6903 const RenderPass renderPass (attachments, subpasses, deps, inputAspects);
6904 const TestConfig testConfig (renderPass,
6905 renderTypes[renderTypeNdx].types,
6906 TestConfig::COMMANDBUFFERTYPES_INLINE,
6907 TestConfig::IMAGEMEMORY_STRICT,
6914 testConfigExternal.allocationKind,
6915 testConfigExternal.groupParams);
6916 const string testName (renderTypes[renderTypeNdx].str + string(useInputAspect ? "_use_input_aspect" : ""));
6918 addFunctionCaseWithPrograms<TestConfig>(storeOpGroup.get(), testName, renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
6922 vector<Attachment> attachments;
6923 vector<Subpass> subpasses;
6924 vector<SubpassDependency> deps;
6925 vector<VkInputAttachmentAspectReference> inputAspects;
6927 attachments.push_back(Attachment(format,
6928 VK_SAMPLE_COUNT_1_BIT,
6931 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6932 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6933 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
6934 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
6936 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6938 vector<AttachmentReference>(),
6939 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6940 vector<AttachmentReference>(),
6941 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6942 vector<deUint32>()));
6943 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6945 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_GENERAL, inputAttachmentAspectMask)),
6946 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_GENERAL)),
6947 vector<AttachmentReference>(),
6948 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6949 vector<deUint32>()));
6951 deps.push_back(SubpassDependency(0, 1,
6952 vk::VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
6953 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
6955 vk::VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
6956 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
6957 vk::VK_DEPENDENCY_BY_REGION_BIT));
6959 deps.push_back(SubpassDependency(1, 1,
6960 vk::VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
6961 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
6963 vk::VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
6964 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
6965 vk::VK_DEPENDENCY_BY_REGION_BIT));
6969 const VkInputAttachmentAspectReference inputAspect =
6973 VK_IMAGE_ASPECT_COLOR_BIT
6976 inputAspects.push_back(inputAspect);
6980 const RenderPass renderPass (attachments, subpasses, deps, inputAspects);
6981 const TestConfig testConfig (renderPass,
6982 renderTypes[renderTypeNdx].types,
6983 TestConfig::COMMANDBUFFERTYPES_INLINE,
6984 TestConfig::IMAGEMEMORY_STRICT,
6991 testConfigExternal.allocationKind,
6992 testConfigExternal.groupParams);
6993 const string testName (string("self_dep_") + renderTypes[renderTypeNdx].str + (useInputAspect ? "_use_input_aspect" : ""));
6995 addFunctionCaseWithPrograms<TestConfig>(storeOpGroup.get(), testName, string("self_dep_") + renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
7001 loadOpGroup->addChild(storeOpGroup.release());
7004 inputGroup->addChild(loadOpGroup.release());
7007 formatGroup->addChild(inputGroup.release());
7010 group->addChild(formatGroup.release());
7013 // Depth stencil formats
7014 for (size_t formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(s_coreDepthStencilFormats); formatNdx++)
7016 const VkFormat vkFormat = s_coreDepthStencilFormats[formatNdx];
7017 const tcu::TextureFormat format = mapVkFormat(vkFormat);
7018 const bool isStencilAttachment = hasStencilComponent(format.order);
7019 const bool isDepthAttachment = hasDepthComponent(format.order);
7020 const VkImageAspectFlags formatAspectFlags = (isDepthAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_DEPTH_BIT : 0u)
7021 | (isStencilAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_STENCIL_BIT : 0u);
7022 de::MovePtr<tcu::TestCaseGroup> formatGroup (new tcu::TestCaseGroup(testCtx, formatToName(vkFormat).c_str(), de::toString(vkFormat).c_str()));
7024 for (size_t loadOpNdx = 0; loadOpNdx < DE_LENGTH_OF_ARRAY(loadOps); loadOpNdx++)
7026 const VkAttachmentLoadOp loadOp = loadOps[loadOpNdx].op;
7027 de::MovePtr<tcu::TestCaseGroup> loadOpGroup (new tcu::TestCaseGroup(testCtx, loadOps[loadOpNdx].str, loadOps[loadOpNdx].str));
7029 for (size_t renderTypeNdx = 0; renderTypeNdx < DE_LENGTH_OF_ARRAY(renderTypes); renderTypeNdx++)
7032 const RenderPass renderPass (vector<Attachment>(1, Attachment(vkFormat,
7033 VK_SAMPLE_COUNT_1_BIT,
7034 isDepthAttachment ? loadOp : VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7035 isDepthAttachment ? VK_ATTACHMENT_STORE_OP_STORE :VK_ATTACHMENT_STORE_OP_DONT_CARE,
7036 isStencilAttachment ? loadOp : VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7037 isStencilAttachment ? VK_ATTACHMENT_STORE_OP_STORE :VK_ATTACHMENT_STORE_OP_DONT_CARE,
7038 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
7039 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)),
7040 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7042 vector<AttachmentReference>(),
7043 vector<AttachmentReference>(),
7044 vector<AttachmentReference>(),
7045 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
7046 vector<deUint32>())),
7047 vector<SubpassDependency>());
7048 const TestConfig testConfig (renderPass,
7049 renderTypes[renderTypeNdx].types,
7050 TestConfig::COMMANDBUFFERTYPES_INLINE,
7051 TestConfig::IMAGEMEMORY_STRICT,
7058 testConfigExternal.allocationKind,
7059 testConfigExternal.groupParams);
7061 addFunctionCaseWithPrograms<TestConfig>(loadOpGroup.get(), renderTypes[renderTypeNdx].str, renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
7064 if (isStencilAttachment && isDepthAttachment && loadOp != VK_ATTACHMENT_LOAD_OP_CLEAR)
7067 const RenderPass renderPass (vector<Attachment>(1, Attachment(vkFormat,
7068 VK_SAMPLE_COUNT_1_BIT,
7069 isDepthAttachment ? loadOp : VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7070 isDepthAttachment ? VK_ATTACHMENT_STORE_OP_STORE :VK_ATTACHMENT_STORE_OP_DONT_CARE,
7071 isStencilAttachment ? loadOp : VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7072 isStencilAttachment ? VK_ATTACHMENT_STORE_OP_STORE :VK_ATTACHMENT_STORE_OP_DONT_CARE,
7073 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
7074 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)),
7075 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7077 vector<AttachmentReference>(),
7078 vector<AttachmentReference>(),
7079 vector<AttachmentReference>(),
7080 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL),
7081 vector<deUint32>())),
7082 vector<SubpassDependency>());
7083 const TestConfig testConfig (renderPass,
7084 renderTypes[renderTypeNdx].types,
7085 TestConfig::COMMANDBUFFERTYPES_INLINE,
7086 TestConfig::IMAGEMEMORY_STRICT,
7093 testConfigExternal.allocationKind,
7094 testConfigExternal.groupParams);
7095 const string testName (string(renderTypes[renderTypeNdx].str) + "_depth_read_only");
7097 addFunctionCaseWithPrograms<TestConfig>(loadOpGroup.get(), testName, renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
7101 const RenderPass renderPass (vector<Attachment>(1, Attachment(vkFormat,
7102 VK_SAMPLE_COUNT_1_BIT,
7103 isDepthAttachment ? loadOp : VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7104 isDepthAttachment ? VK_ATTACHMENT_STORE_OP_STORE :VK_ATTACHMENT_STORE_OP_DONT_CARE,
7105 isStencilAttachment ? loadOp : VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7106 isStencilAttachment ? VK_ATTACHMENT_STORE_OP_STORE :VK_ATTACHMENT_STORE_OP_DONT_CARE,
7107 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
7108 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)),
7109 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7111 vector<AttachmentReference>(),
7112 vector<AttachmentReference>(),
7113 vector<AttachmentReference>(),
7114 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL),
7115 vector<deUint32>())),
7116 vector<SubpassDependency>());
7117 const TestConfig testConfig (renderPass,
7118 renderTypes[renderTypeNdx].types,
7119 TestConfig::COMMANDBUFFERTYPES_INLINE,
7120 TestConfig::IMAGEMEMORY_STRICT,
7127 testConfigExternal.allocationKind,
7128 testConfigExternal.groupParams);
7129 const string testName (string(renderTypes[renderTypeNdx].str) + "_stencil_read_only");
7131 addFunctionCaseWithPrograms<TestConfig>(loadOpGroup.get(), testName, renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
7136 formatGroup->addChild(loadOpGroup.release());
7139 if (testConfigExternal.groupParams->renderingType != RENDERING_TYPE_DYNAMIC_RENDERING)
7141 de::MovePtr<tcu::TestCaseGroup> inputGroup (new tcu::TestCaseGroup(testCtx, "input", "Test attachment format as input"));
7143 for (size_t loadOpNdx = 0; loadOpNdx < DE_LENGTH_OF_ARRAY(loadOps); loadOpNdx++)
7145 const VkAttachmentLoadOp loadOp = loadOps[loadOpNdx].op;
7146 de::MovePtr<tcu::TestCaseGroup> loadOpGroup (new tcu::TestCaseGroup(testCtx, loadOps[loadOpNdx].str, loadOps[loadOpNdx].str));
7148 for (size_t storeOpNdx = 0; storeOpNdx < DE_LENGTH_OF_ARRAY(storeOps); storeOpNdx++)
7150 const VkImageAspectFlags inputAttachmentAspectMask = (testConfigExternal.groupParams->renderingType == RENDERING_TYPE_RENDERPASS2)
7152 : static_cast<VkImageAspectFlags>(0);
7153 const VkAttachmentStoreOp storeOp = storeOps[storeOpNdx].op;
7154 de::MovePtr<tcu::TestCaseGroup> storeOpGroup (new tcu::TestCaseGroup(testCtx, storeOps[storeOpNdx].str, storeOps[storeOpNdx].str));
7156 for (size_t useInputAspectNdx = 0; useInputAspectNdx < 2; useInputAspectNdx++)
7158 const bool useInputAspect = useInputAspectNdx != 0;
7160 if (testConfigExternal.groupParams->renderingType == RENDERING_TYPE_RENDERPASS2 && useInputAspect)
7163 for (size_t renderTypeNdx = 0; renderTypeNdx < DE_LENGTH_OF_ARRAY(renderTypes); renderTypeNdx++)
7166 vector<Attachment> attachments;
7167 vector<Subpass> subpasses;
7168 vector<SubpassDependency> deps;
7169 vector<VkInputAttachmentAspectReference> inputAspects;
7171 attachments.push_back(Attachment(vkFormat,
7172 VK_SAMPLE_COUNT_1_BIT,
7177 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
7178 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL));
7180 attachments.push_back(Attachment(vk::VK_FORMAT_R8G8B8A8_UNORM,
7181 VK_SAMPLE_COUNT_1_BIT,
7182 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7183 VK_ATTACHMENT_STORE_OP_STORE,
7184 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7185 VK_ATTACHMENT_STORE_OP_DONT_CARE,
7186 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
7187 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
7189 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7191 vector<AttachmentReference>(),
7192 vector<AttachmentReference>(),
7193 vector<AttachmentReference>(),
7194 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
7195 vector<deUint32>()));
7196 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7198 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, inputAttachmentAspectMask)),
7199 vector<AttachmentReference>(1, AttachmentReference(1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
7200 vector<AttachmentReference>(),
7201 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
7202 vector<deUint32>()));
7204 deps.push_back(SubpassDependency(0, 1,
7205 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
7206 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
7208 vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
7209 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
7214 const VkInputAttachmentAspectReference inputAspect =
7218 (isDepthAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_DEPTH_BIT : 0u)
7219 | (isStencilAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_STENCIL_BIT : 0u)
7222 inputAspects.push_back(inputAspect);
7226 const RenderPass renderPass (attachments, subpasses, deps, inputAspects);
7227 const TestConfig testConfig (renderPass,
7228 renderTypes[renderTypeNdx].types,
7229 TestConfig::COMMANDBUFFERTYPES_INLINE,
7230 TestConfig::IMAGEMEMORY_STRICT,
7237 testConfigExternal.allocationKind,
7238 testConfigExternal.groupParams);
7239 const string testName (renderTypes[renderTypeNdx].str + string(useInputAspect ? "_use_input_aspect" : ""));
7241 addFunctionCaseWithPrograms<TestConfig>(storeOpGroup.get(), testName, renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
7245 vector<Attachment> attachments;
7246 vector<Subpass> subpasses;
7247 vector<SubpassDependency> deps;
7248 vector<VkInputAttachmentAspectReference> inputAspects;
7250 attachments.push_back(Attachment(vkFormat,
7251 VK_SAMPLE_COUNT_1_BIT,
7254 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7255 VK_ATTACHMENT_STORE_OP_DONT_CARE,
7256 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
7257 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL));
7259 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7261 vector<AttachmentReference>(),
7262 vector<AttachmentReference>(),
7263 vector<AttachmentReference>(),
7264 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
7265 vector<deUint32>()));
7266 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7268 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_GENERAL, inputAttachmentAspectMask)),
7269 vector<AttachmentReference>(),
7270 vector<AttachmentReference>(),
7271 AttachmentReference(0, VK_IMAGE_LAYOUT_GENERAL),
7272 vector<deUint32>()));
7274 deps.push_back(SubpassDependency(0, 1,
7275 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
7276 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
7278 vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
7279 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
7280 vk::VK_DEPENDENCY_BY_REGION_BIT));
7282 deps.push_back(SubpassDependency(1, 1,
7283 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
7284 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
7285 vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
7286 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
7287 vk::VK_DEPENDENCY_BY_REGION_BIT));
7292 const VkInputAttachmentAspectReference inputAspect =
7297 (isDepthAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_DEPTH_BIT : 0u)
7298 | (isStencilAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_STENCIL_BIT : 0u)
7301 inputAspects.push_back(inputAspect);
7305 const RenderPass renderPass (attachments, subpasses, deps, inputAspects);
7306 const TestConfig testConfig (renderPass,
7307 renderTypes[renderTypeNdx].types,
7308 TestConfig::COMMANDBUFFERTYPES_INLINE,
7309 TestConfig::IMAGEMEMORY_STRICT,
7316 testConfigExternal.allocationKind,
7317 testConfigExternal.groupParams);
7318 const string testName (string("self_dep_") + renderTypes[renderTypeNdx].str + (useInputAspect ? "_use_input_aspect" : ""));
7320 addFunctionCaseWithPrograms<TestConfig>(storeOpGroup.get(), testName, string("self_dep_") + renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
7324 if (isStencilAttachment && isDepthAttachment)
7328 vector<Attachment> attachments;
7329 vector<Subpass> subpasses;
7330 vector<SubpassDependency> deps;
7331 vector<VkInputAttachmentAspectReference> inputAspects;
7333 attachments.push_back(Attachment(vkFormat,
7334 VK_SAMPLE_COUNT_1_BIT,
7339 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
7340 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL));
7342 attachments.push_back(Attachment(vk::VK_FORMAT_R8G8B8A8_UNORM,
7343 VK_SAMPLE_COUNT_1_BIT,
7344 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7345 VK_ATTACHMENT_STORE_OP_STORE,
7346 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7347 VK_ATTACHMENT_STORE_OP_DONT_CARE,
7348 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
7349 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
7351 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7353 vector<AttachmentReference>(),
7354 vector<AttachmentReference>(),
7355 vector<AttachmentReference>(),
7356 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
7357 vector<deUint32>()));
7358 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7360 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL, inputAttachmentAspectMask)),
7361 vector<AttachmentReference>(1, AttachmentReference(1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
7362 vector<AttachmentReference>(),
7363 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
7364 vector<deUint32>()));
7366 deps.push_back(SubpassDependency(0, 1,
7367 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
7368 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
7370 vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
7371 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
7376 const VkInputAttachmentAspectReference inputAspect =
7381 (isDepthAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_DEPTH_BIT : 0u)
7382 | (isStencilAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_STENCIL_BIT : 0u)
7385 inputAspects.push_back(inputAspect);
7389 const RenderPass renderPass (attachments, subpasses, deps, inputAspects);
7390 const TestConfig testConfig (renderPass,
7391 renderTypes[renderTypeNdx].types,
7392 TestConfig::COMMANDBUFFERTYPES_INLINE,
7393 TestConfig::IMAGEMEMORY_STRICT,
7400 testConfigExternal.allocationKind,
7401 testConfigExternal.groupParams);
7402 const string testName (renderTypes[renderTypeNdx].str + string(useInputAspect ? "_use_input_aspect" : "") + "_depth_read_only");
7404 addFunctionCaseWithPrograms<TestConfig>(storeOpGroup.get(), testName, renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
7408 vector<Attachment> attachments;
7409 vector<Subpass> subpasses;
7410 vector<SubpassDependency> deps;
7411 vector<VkInputAttachmentAspectReference> inputAspects;
7413 attachments.push_back(Attachment(vkFormat,
7414 VK_SAMPLE_COUNT_1_BIT,
7419 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
7420 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL));
7422 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7424 vector<AttachmentReference>(),
7425 vector<AttachmentReference>(),
7426 vector<AttachmentReference>(),
7427 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
7428 vector<deUint32>()));
7429 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7431 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL, inputAttachmentAspectMask)),
7432 vector<AttachmentReference>(),
7433 vector<AttachmentReference>(),
7434 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL),
7435 vector<deUint32>()));
7437 deps.push_back(SubpassDependency(0, 1,
7438 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
7439 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
7441 vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
7442 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
7443 vk::VK_DEPENDENCY_BY_REGION_BIT));
7445 deps.push_back(SubpassDependency(1, 1,
7446 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
7447 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
7449 vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
7450 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
7451 vk::VK_DEPENDENCY_BY_REGION_BIT));
7455 const VkInputAttachmentAspectReference inputAspect =
7460 (isDepthAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_DEPTH_BIT : 0u)
7461 | (isStencilAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_STENCIL_BIT : 0u)
7464 inputAspects.push_back(inputAspect);
7468 const RenderPass renderPass (attachments, subpasses, deps, inputAspects);
7469 const TestConfig testConfig (renderPass,
7470 renderTypes[renderTypeNdx].types,
7471 TestConfig::COMMANDBUFFERTYPES_INLINE,
7472 TestConfig::IMAGEMEMORY_STRICT,
7479 testConfigExternal.allocationKind,
7480 testConfigExternal.groupParams);
7481 const string testName (string("self_dep_") + renderTypes[renderTypeNdx].str + (useInputAspect ? "_use_input_aspect" : "") + "_depth_read_only");
7483 addFunctionCaseWithPrograms<TestConfig>(storeOpGroup.get(), testName, string("self_dep_") + renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
7486 // Stencil read only
7488 vector<Attachment> attachments;
7489 vector<Subpass> subpasses;
7490 vector<SubpassDependency> deps;
7491 vector<VkInputAttachmentAspectReference> inputAspects;
7493 attachments.push_back(Attachment(vkFormat,
7494 VK_SAMPLE_COUNT_1_BIT,
7499 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
7500 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL));
7502 attachments.push_back(Attachment(vk::VK_FORMAT_R8G8B8A8_UNORM,
7503 VK_SAMPLE_COUNT_1_BIT,
7504 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7505 VK_ATTACHMENT_STORE_OP_STORE,
7506 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7507 VK_ATTACHMENT_STORE_OP_DONT_CARE,
7508 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
7509 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
7511 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7513 vector<AttachmentReference>(),
7514 vector<AttachmentReference>(),
7515 vector<AttachmentReference>(),
7516 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
7517 vector<deUint32>()));
7518 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7520 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL, inputAttachmentAspectMask)),
7521 vector<AttachmentReference>(1, AttachmentReference(1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
7522 vector<AttachmentReference>(),
7523 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
7524 vector<deUint32>()));
7526 deps.push_back(SubpassDependency(0, 1,
7527 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
7528 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
7530 vk::VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
7531 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
7536 const VkInputAttachmentAspectReference inputAspect =
7541 (isDepthAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_DEPTH_BIT : 0u)
7542 | (isStencilAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_STENCIL_BIT : 0u)
7545 inputAspects.push_back(inputAspect);
7549 const RenderPass renderPass (attachments, subpasses, deps, inputAspects);
7550 const TestConfig testConfig (renderPass,
7551 renderTypes[renderTypeNdx].types,
7552 TestConfig::COMMANDBUFFERTYPES_INLINE,
7553 TestConfig::IMAGEMEMORY_STRICT,
7560 testConfigExternal.allocationKind,
7561 testConfigExternal.groupParams);
7562 const string testName (renderTypes[renderTypeNdx].str + string(useInputAspect ? "_use_input_aspect" : "") + "_stencil_read_only");
7564 addFunctionCaseWithPrograms<TestConfig>(storeOpGroup.get(), testName, renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
7568 vector<Attachment> attachments;
7569 vector<Subpass> subpasses;
7570 vector<SubpassDependency> deps;
7571 vector<VkInputAttachmentAspectReference> inputAspects;
7573 attachments.push_back(Attachment(vkFormat,
7574 VK_SAMPLE_COUNT_1_BIT,
7579 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
7580 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL));
7582 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7584 vector<AttachmentReference>(),
7585 vector<AttachmentReference>(),
7586 vector<AttachmentReference>(),
7587 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
7588 vector<deUint32>()));
7589 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7591 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL, inputAttachmentAspectMask)),
7592 vector<AttachmentReference>(),
7593 vector<AttachmentReference>(),
7594 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL),
7595 vector<deUint32>()));
7597 deps.push_back(SubpassDependency(0, 1,
7598 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
7599 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
7601 vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
7602 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
7603 vk::VK_DEPENDENCY_BY_REGION_BIT));
7605 deps.push_back(SubpassDependency(1, 1,
7606 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
7607 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
7609 vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
7610 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
7611 vk::VK_DEPENDENCY_BY_REGION_BIT));
7616 const VkInputAttachmentAspectReference inputAspect =
7621 (isDepthAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_DEPTH_BIT : 0u)
7622 | (isStencilAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_STENCIL_BIT : 0u)
7625 inputAspects.push_back(inputAspect);
7629 const RenderPass renderPass (attachments, subpasses, deps, inputAspects);
7630 const TestConfig testConfig (renderPass,
7631 renderTypes[renderTypeNdx].types,
7632 TestConfig::COMMANDBUFFERTYPES_INLINE,
7633 TestConfig::IMAGEMEMORY_STRICT,
7640 testConfigExternal.allocationKind,
7641 testConfigExternal.groupParams);
7642 const string testName (string("self_dep_") + renderTypes[renderTypeNdx].str + (useInputAspect ? "_use_input_aspect" : "") + "_stencil_read_only");
7644 addFunctionCaseWithPrograms<TestConfig>(storeOpGroup.get(), testName, string("self_dep_") + renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
7651 loadOpGroup->addChild(storeOpGroup.release());
7654 inputGroup->addChild(loadOpGroup.release());
7657 formatGroup->addChild(inputGroup.release());
7660 group->addChild(formatGroup.release());
7664 void addRenderPassTests (tcu::TestCaseGroup* group, const AllocationKind allocationKind, const SharedGroupParams groupParams)
7666 // tests added by this function have both primary and secondary cases and there is no need to repeat them for useSecondaryCmdBuffer flag;
7667 // but cases defined in other files that are later added to those groups in createRenderPassTestsInternal had to be adjusted and run
7668 // for useSecondaryCmdBuffer flag
7669 if (groupParams->useSecondaryCmdBuffer && !groupParams->secondaryCmdBufferCompletelyContainsDynamicRenderpass)
7672 const TestConfigExternal testConfigExternal (allocationKind, groupParams);
7674 // don't repeat cases that don't use CommandBufferTypes::COMMANDBUFFERTYPES_SECONDARY
7675 if (!groupParams->secondaryCmdBufferCompletelyContainsDynamicRenderpass)
7677 addTestGroup(group, "simple", "Simple basic render pass tests", addSimpleTests, testConfigExternal);
7678 addTestGroup(group, "formats", "Tests for different image formats.", addFormatTests, testConfigExternal);
7681 addTestGroup(group, "attachment", "Attachment format and count tests with load and store ops and image layouts", addAttachmentTests, testConfigExternal);
7683 // don't repeat cases that don't use CommandBufferTypes::COMMANDBUFFERTYPES_SECONDARY
7684 if (!groupParams->secondaryCmdBufferCompletelyContainsDynamicRenderpass)
7685 addTestGroup(group, "attachment_write_mask", "Attachment write mask tests", addAttachmentWriteMaskTests, testConfigExternal);
7687 if (groupParams->renderingType != RENDERING_TYPE_DYNAMIC_RENDERING)
7688 addTestGroup(group, "attachment_allocation", "Attachment allocation tests", addAttachmentAllocationTests, testConfigExternal);
7691 de::MovePtr<tcu::TestCaseGroup> createSuballocationTests(tcu::TestContext& testCtx, const SharedGroupParams groupParams)
7693 de::MovePtr<tcu::TestCaseGroup> suballocationTestsGroup(new tcu::TestCaseGroup(testCtx, "suballocation", "Suballocation RenderPass Tests"));
7695 addRenderPassTests(suballocationTestsGroup.get(), ALLOCATION_KIND_SUBALLOCATED, groupParams);
7697 return suballocationTestsGroup;
7700 de::MovePtr<tcu::TestCaseGroup> createDedicatedAllocationTests(tcu::TestContext& testCtx, const SharedGroupParams groupParams)
7702 de::MovePtr<tcu::TestCaseGroup> dedicatedAllocationTestsGroup(new tcu::TestCaseGroup(testCtx, "dedicated_allocation", "RenderPass Tests For Dedicated Allocation"));
7704 addRenderPassTests(dedicatedAllocationTestsGroup.get(), ALLOCATION_KIND_DEDICATED, groupParams);
7706 return dedicatedAllocationTestsGroup;
7709 tcu::TestCaseGroup* createRenderPassTestsInternal (tcu::TestContext& testCtx, const char* groupName, const SharedGroupParams groupParams)
7711 de::MovePtr<tcu::TestCaseGroup> renderingTests (new tcu::TestCaseGroup(testCtx, groupName, ""));
7712 de::MovePtr<tcu::TestCaseGroup> suballocationTestGroup = createSuballocationTests(testCtx, groupParams);
7713 de::MovePtr<tcu::TestCaseGroup> dedicatedAllocationTestGroup = createDedicatedAllocationTests(testCtx, groupParams);
7715 const RenderingType renderingType = groupParams->renderingType;
7717 switch (renderingType)
7719 case RENDERING_TYPE_RENDERPASS_LEGACY:
7720 suballocationTestGroup->addChild(createRenderPassMultisampleTests(testCtx));
7721 suballocationTestGroup->addChild(createRenderPassMultisampleResolveTests(testCtx, groupParams));
7722 suballocationTestGroup->addChild(createRenderPassSubpassDependencyTests(testCtx));
7723 suballocationTestGroup->addChild(createRenderPassSampleReadTests(testCtx));
7725 #ifndef CTS_USES_VULKANSC
7726 suballocationTestGroup->addChild(createRenderPassSparseRenderTargetTests(testCtx, groupParams));
7727 renderingTests->addChild(createDepthStencilWriteConditionsTests(testCtx));
7728 #endif // CTS_USES_VULKANSC
7730 renderingTests->addChild(createRenderPassMultipleSubpassesMultipleCommandBuffersTests(testCtx));
7734 case RENDERING_TYPE_RENDERPASS2:
7735 suballocationTestGroup->addChild(createRenderPass2MultisampleTests(testCtx));
7736 suballocationTestGroup->addChild(createRenderPass2MultisampleResolveTests(testCtx, groupParams));
7737 suballocationTestGroup->addChild(createRenderPass2SubpassDependencyTests(testCtx));
7738 suballocationTestGroup->addChild(createRenderPass2SampleReadTests(testCtx));
7740 #ifndef CTS_USES_VULKANSC
7741 suballocationTestGroup->addChild(createRenderPass2SparseRenderTargetTests(testCtx, groupParams));
7742 #endif // CTS_USES_VULKANSC
7744 renderingTests->addChild(createRenderPass2DepthStencilResolveTests(testCtx));
7747 #ifndef CTS_USES_VULKANSC
7748 case RENDERING_TYPE_DYNAMIC_RENDERING:
7749 suballocationTestGroup->addChild(createDynamicRenderingMultisampleResolveTests(testCtx, groupParams));
7750 suballocationTestGroup->addChild(createDynamicRenderingSparseRenderTargetTests(testCtx, groupParams));
7752 if (groupParams->useSecondaryCmdBuffer == false)
7754 renderingTests->addChild(createDynamicRenderingRandomTests(testCtx));
7755 renderingTests->addChild(createDynamicRenderingBasicTests(testCtx));
7758 #endif // CTS_USES_VULKANSC
7764 if (renderingType != RENDERING_TYPE_DYNAMIC_RENDERING)
7766 suballocationTestGroup->addChild(createRenderPassUnusedAttachmentTests(testCtx, renderingType));
7767 suballocationTestGroup->addChild(createRenderPassUnusedAttachmentSparseFillingTests(testCtx, renderingType));
7770 suballocationTestGroup->addChild(createRenderPassUnusedClearAttachmentTests(testCtx, groupParams));
7772 #ifndef CTS_USES_VULKANSC
7773 suballocationTestGroup->addChild(createRenderPassLoadStoreOpNoneTests(testCtx, groupParams));
7775 if (renderingType == RENDERING_TYPE_RENDERPASS2)
7777 suballocationTestGroup->addChild(createRenderPassSubpassMergeFeedbackTests(testCtx, renderingType));
7780 renderingTests->addChild(createFragmentDensityMapTests(testCtx, groupParams));
7781 #endif // CTS_USES_VULKANSC
7783 renderingTests->addChild(suballocationTestGroup.release());
7784 renderingTests->addChild(dedicatedAllocationTestGroup.release());
7786 return renderingTests.release();
7791 tcu::TestCaseGroup* createRenderPassTests (tcu::TestContext& testCtx)
7793 SharedGroupParams groupParams(
7796 RENDERING_TYPE_RENDERPASS_LEGACY, // RenderingType renderingType;
7797 false, // bool useSecondaryCmdBuffer;
7798 false, // bool secondaryCmdBufferCompletelyContainsDynamicRenderpass;
7800 return createRenderPassTestsInternal(testCtx, "renderpass", groupParams);
7803 tcu::TestCaseGroup* createRenderPass2Tests (tcu::TestContext& testCtx)
7805 SharedGroupParams groupParams(
7808 RENDERING_TYPE_RENDERPASS2, // RenderingType renderingType;
7809 false, // bool useSecondaryCmdBuffer;
7810 false, // bool secondaryCmdBufferCompletelyContainsDynamicRenderpass;
7812 return createRenderPassTestsInternal(testCtx, "renderpass2", groupParams);
7815 tcu::TestCaseGroup* createDynamicRenderingTests(tcu::TestContext& testCtx)
7817 de::MovePtr<tcu::TestCaseGroup> dynamicRenderingGroup(new tcu::TestCaseGroup(testCtx, "dynamic_rendering", "Draw using VK_KHR_dynamic_rendering"));
7819 dynamicRenderingGroup->addChild(createRenderPassTestsInternal(testCtx, "primary_cmd_buff", SharedGroupParams(
7822 RENDERING_TYPE_DYNAMIC_RENDERING, // RenderingType renderingType;
7823 false, // bool useSecondaryCmdBuffer;
7824 false, // bool secondaryCmdBufferCompletelyContainsDynamicRenderpass;
7826 dynamicRenderingGroup->addChild(createRenderPassTestsInternal(testCtx, "partial_secondary_cmd_buff", SharedGroupParams(
7829 RENDERING_TYPE_DYNAMIC_RENDERING, // RenderingType renderingType;
7830 true, // bool useSecondaryCmdBuffer;
7831 false, // bool secondaryCmdBufferCompletelyContainsDynamicRenderpass;
7833 dynamicRenderingGroup->addChild(createRenderPassTestsInternal(testCtx, "complete_secondary_cmd_buff", SharedGroupParams(
7836 RENDERING_TYPE_DYNAMIC_RENDERING, // RenderingType renderingType;
7837 true, // bool useSecondaryCmdBuffer;
7838 true, // bool secondaryCmdBufferCompletelyContainsDynamicRenderpass;
7841 return dynamicRenderingGroup.release();