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 VkStencilOp stencilOp = writeStencil ? VK_STENCIL_OP_REPLACE : VK_STENCIL_OP_KEEP;
2011 const VkPipelineDepthStencilStateCreateInfo depthStencilState =
2013 VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, // sType
2015 (VkPipelineDepthStencilStateCreateFlags)0u,
2016 writeDepth, // depthTestEnable
2017 writeDepth, // depthWriteEnable
2018 VK_COMPARE_OP_ALWAYS, // depthCompareOp
2019 VK_FALSE, // depthBoundsEnable
2020 writeStencil, // stencilTestEnable
2022 stencilOp, // stencilFailOp
2023 stencilOp, // stencilPassOp
2024 stencilOp, // stencilDepthFailOp
2025 VK_COMPARE_OP_ALWAYS, // stencilCompareOp
2026 ~0u, // stencilCompareMask
2027 ~0u, // stencilWriteMask
2028 ((stencilIndex % 2) == 0) ? ~0x0u : 0x0u // stencilReference
2031 stencilOp, // stencilFailOp
2032 stencilOp, // stencilPassOp
2033 stencilOp, // stencilDepthFailOp
2034 VK_COMPARE_OP_ALWAYS, // stencilCompareOp
2035 ~0u, // stencilCompareMask
2036 ~0u, // stencilWriteMask
2037 ((stencilIndex % 2) == 0) ? ~0x0u : 0x0u // stencilReference
2040 0.0f, // minDepthBounds;
2041 1.0f // maxDepthBounds;
2044 const VkPipelineColorBlendStateCreateInfo blendState =
2046 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, // sType
2048 (VkPipelineColorBlendStateCreateFlags)0u,
2049 VK_FALSE, // logicOpEnable
2050 VK_LOGIC_OP_COPY, // logicOp
2051 (deUint32)attachmentBlendStates.size(), // attachmentCount
2052 attachmentBlendStates.empty() ? DE_NULL : &attachmentBlendStates[0],// pAttachments
2053 { 0.0f, 0.0f, 0.0f, 0.0f } // blendConst
2056 #ifndef CTS_USES_VULKANSC
2057 std::vector<vk::VkFormat> colorAttachmentFormats;
2058 for (deUint32 i = 0; i < renderInfo.getColorAttachmentCount(); ++i)
2059 colorAttachmentFormats.push_back(renderInfo.getColorAttachment(i).getFormat());
2061 vk::VkFormat depthFormat = VK_FORMAT_UNDEFINED;
2062 vk::VkFormat stencilFormat = VK_FORMAT_UNDEFINED;
2063 if (renderInfo.getDepthStencilAttachment())
2065 const Attachment& attachment = *renderInfo.getDepthStencilAttachment();
2066 vk::VkFormat depthStencilFormat = attachment.getFormat();
2067 if (depthStencilFormat != VK_FORMAT_UNDEFINED)
2069 if (tcu::hasDepthComponent(mapVkFormat(depthStencilFormat).order))
2071 depthFormat = depthStencilFormat;
2073 if (tcu::hasStencilComponent(mapVkFormat(depthStencilFormat).order))
2075 stencilFormat = depthStencilFormat;
2081 VkPipelineRenderingCreateInfoKHR renderingCreateInfo
2083 VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR,
2086 static_cast<deUint32>(colorAttachmentFormats.size()),
2087 colorAttachmentFormats.data(),
2091 #endif // CTS_USES_VULKANSC
2093 return makeGraphicsPipeline(vk, // const DeviceInterface& vk
2094 device, // const VkDevice device
2095 pipelineLayout, // const VkPipelineLayout pipelineLayout
2096 vertexShaderModule, // const VkShaderModule vertexShaderModule
2097 DE_NULL, // const VkShaderModule tessellationControlShaderModule
2098 DE_NULL, // const VkShaderModule tessellationEvalShaderModule
2099 DE_NULL, // const VkShaderModule geometryShaderModule
2100 fragmentShaderModule, // const VkShaderModule fragmentShaderModule
2101 renderPass, // const VkRenderPass renderPass
2102 renderInfo.getSubpassIndex(), // const deUint32 subpass
2103 &vertexInputState, // const VkPipelineVertexInputStateCreateInfo* vertexInputStateCreateInfo
2104 &inputAssemblyState, // const VkPipelineInputAssemblyStateCreateInfo* pInputAssemblyState;
2105 DE_NULL, // const VkPipelineRasterizationStateCreateInfo* rasterizationStateCreateInfo
2106 &viewportState, // const VkPipelineViewportStateCreateInfo* pViewportStat;
2107 &rasterizationState, // const VkPipelineRasterizationStateCreateInfo* pRasterizationState
2108 &multisampleState, // const VkPipelineMultisampleStateCreateInfo* multisampleStateCreateInfo
2109 &depthStencilState, // const VkPipelineDepthStencilStateCreateInfo* depthStencilStateCreateInfo
2110 renderInfo.getOmitBlendState()
2111 ? DE_NULL : &blendState, // const VkPipelineColorBlendStateCreateInfo* colorBlendStateCreateInfo
2112 DE_NULL, // const VkPipelineDynamicStateCreateInfo* dynamicStateCreateInfo
2113 #ifndef CTS_USES_VULKANSC
2114 (renderPass == DE_NULL)
2115 ? &renderingCreateInfo : DE_NULL); // const void* pNext)
2117 DE_NULL); // const void* pNext)
2118 #endif // CTS_USES_VULKANSC
2121 #ifndef CTS_USES_VULKANSC
2122 void beginDynamicRendering(const DeviceInterface& vk,
2123 VkCommandBuffer commandBuffer,
2124 const RenderPass& renderPassInfo,
2125 const vector<de::SharedPtr<AttachmentResources> >& attachmentResources,
2126 const VkRect2D& renderArea,
2127 const vector<Maybe<VkClearValue> >& renderPassClearValues,
2128 const VkRenderingFlagsKHR renderingFlags = 0u)
2130 const float clearNan = tcu::Float32::nan().asFloat();
2131 const VkClearValue clearValueNan = makeClearValueColorF32(clearNan, clearNan, clearNan, clearNan);
2133 // translate structures that were prepared to construct renderpass to structures needed for dynamic rendering
2135 std::vector<vk::VkRenderingAttachmentInfoKHR> colorAttachmentVect;
2136 const Subpass& subpassInfo = renderPassInfo.getSubpasses()[0];
2137 const vector<AttachmentReference>& colorAttachmentsInfo = subpassInfo.getColorAttachments();
2138 const vector<AttachmentReference>& resolveAttachmentsInfo = subpassInfo.getResolveAttachments();
2140 for (deUint32 i = 0; i < colorAttachmentsInfo.size(); ++i)
2142 const AttachmentReference& colorAttachmentReference = colorAttachmentsInfo[i];
2143 const deUint32 colorAttachmentIndex = colorAttachmentReference.getAttachment();
2144 const Attachment& colorAttachmentInfo = renderPassInfo.getAttachments()[colorAttachmentIndex];
2146 VkResolveModeFlagBits resolveMode = VK_RESOLVE_MODE_NONE;
2147 VkImageView resolveImageView = DE_NULL;
2148 VkImageLayout resolveImageLayout = VK_IMAGE_LAYOUT_UNDEFINED;
2150 // handle resolve attachments if they were specified
2151 if (!resolveAttachmentsInfo.empty())
2153 const AttachmentReference& resolveAttachmentReference = resolveAttachmentsInfo[i];
2154 const deUint32 resolveAttachmentIndex = resolveAttachmentReference.getAttachment();
2155 const Attachment& resolveAttachmentInfo = renderPassInfo.getAttachments()[resolveAttachmentIndex];
2157 resolveMode = VK_RESOLVE_MODE_AVERAGE_BIT;
2158 resolveImageView = attachmentResources[resolveAttachmentIndex]->getAttachmentView();
2159 resolveImageLayout = resolveAttachmentInfo.getInitialLayout();
2162 colorAttachmentVect.push_back({
2163 vk::VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR, // VkStructureType sType
2164 DE_NULL, // const void* pNext
2165 attachmentResources[colorAttachmentIndex]->getAttachmentView(), // VkImageView imageView
2166 colorAttachmentReference.getImageLayout(), // VkImageLayout imageLayout
2167 resolveMode, // VkResolveModeFlagBits resolveMode
2168 resolveImageView, // VkImageView resolveImageView
2169 resolveImageLayout, // VkImageLayout resolveImageLayout
2170 colorAttachmentInfo.getLoadOp(), // VkAttachmentLoadOp loadOp
2171 colorAttachmentInfo.getStoreOp(), // VkAttachmentStoreOp storeOp
2172 (renderPassClearValues[colorAttachmentIndex] ?
2173 *renderPassClearValues[colorAttachmentIndex] :
2174 clearValueNan) // VkClearValue clearValue
2178 VkRenderingAttachmentInfoKHR* pDepthAttachment = DE_NULL;
2179 VkRenderingAttachmentInfoKHR* pStencilAttachment = DE_NULL;
2180 VkRenderingAttachmentInfoKHR depthAttachment
2182 vk::VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR, // VkStructureType sType;
2183 DE_NULL, // const void* pNext;
2184 DE_NULL, // VkImageView imageView;
2185 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout imageLayout;
2186 VK_RESOLVE_MODE_NONE, // VkResolveModeFlagBits resolveMode;
2187 DE_NULL, // VkImageView resolveImageView;
2188 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout resolveImageLayout;
2189 VK_ATTACHMENT_LOAD_OP_LOAD, // VkAttachmentLoadOp loadOp;
2190 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
2191 clearValueNan // VkClearValue clearValue;
2193 VkRenderingAttachmentInfoKHR stencilAttachment = depthAttachment;
2194 const AttachmentReference& depthStencilAttachmentReference = subpassInfo.getDepthStencilAttachment();
2195 const deUint32 dsAttachmentIndex = depthStencilAttachmentReference.getAttachment();
2197 if (dsAttachmentIndex != VK_ATTACHMENT_UNUSED)
2199 const Attachment& dsAttachmentInfo = renderPassInfo.getAttachments()[dsAttachmentIndex];
2200 const tcu::TextureFormat format = mapVkFormat(dsAttachmentInfo.getFormat());
2202 if (tcu::hasDepthComponent(format.order))
2204 depthAttachment.imageView = attachmentResources[dsAttachmentIndex]->getAttachmentView();
2205 depthAttachment.imageLayout = depthStencilAttachmentReference.getImageLayout();
2206 depthAttachment.loadOp = dsAttachmentInfo.getLoadOp();
2207 depthAttachment.storeOp = dsAttachmentInfo.getStoreOp();
2209 if (renderPassClearValues[dsAttachmentIndex])
2210 depthAttachment.clearValue = *renderPassClearValues[dsAttachmentIndex];
2212 pDepthAttachment = &depthAttachment;
2215 if (tcu::hasStencilComponent(format.order))
2217 stencilAttachment.imageView = attachmentResources[dsAttachmentIndex]->getAttachmentView();
2218 stencilAttachment.imageLayout = depthStencilAttachmentReference.getImageLayout();
2219 stencilAttachment.loadOp = dsAttachmentInfo.getStencilLoadOp();
2220 stencilAttachment.storeOp = dsAttachmentInfo.getStencilStoreOp();
2222 if (renderPassClearValues[dsAttachmentIndex])
2223 stencilAttachment.clearValue = *renderPassClearValues[dsAttachmentIndex];
2225 pStencilAttachment = &stencilAttachment;
2229 vk::VkRenderingInfoKHR renderingInfo
2231 vk::VK_STRUCTURE_TYPE_RENDERING_INFO_KHR,
2233 renderingFlags, // VkRenderingFlagsKHR flags;
2234 renderArea, // VkRect2D renderArea;
2235 1u, // deUint32 layerCount;
2236 0u, // deUint32 viewMask;
2237 static_cast<deUint32>(colorAttachmentVect.size()), // deUint32 colorAttachmentCount;
2238 colorAttachmentVect.empty() ? DE_NULL : &colorAttachmentVect[0], // const VkRenderingAttachmentInfoKHR* pColorAttachments;
2239 pDepthAttachment, // const VkRenderingAttachmentInfoKHR* pDepthAttachment;
2240 pStencilAttachment // const VkRenderingAttachmentInfoKHR* pStencilAttachment;
2243 vk.cmdBeginRendering(commandBuffer, &renderingInfo);
2246 void endDynamicRendering(const DeviceInterface& vk, VkCommandBuffer commandBuffer)
2248 vk.cmdEndRendering(commandBuffer);
2250 #endif // CTS_USES_VULKANSC
2252 class SubpassRenderer
2255 SubpassRenderer (Context& context,
2256 const DeviceInterface& vk,
2258 Allocator& allocator,
2259 const RenderPass& renderPassInfo,
2260 const vector<de::SharedPtr<AttachmentResources> >& attachmentResources,
2261 const VkRect2D& renderArea,
2262 const vector<Maybe<VkClearValue> >& renderPassClearValues,
2263 VkRenderPass renderPass,
2264 VkFramebuffer framebuffer,
2265 VkCommandPool commandBufferPool,
2266 deUint32 queueFamilyIndex,
2267 const vector<VkImage>& attachmentImages,
2268 const vector<pair<VkImageView, VkImageView> >& attachmentViews,
2269 const SubpassRenderInfo& renderInfo,
2270 const AllocationKind allocationKind,
2271 const bool dynamicRendering,
2272 const bool secondaryCmdBufferCompletelyContainsDynamicRenderpass)
2273 : m_renderInfo (renderInfo)
2275 // unreference values not used by Vulkan SC, no need to pu this under ifdef
2276 DE_UNREF(attachmentResources);
2277 DE_UNREF(renderArea);
2278 DE_UNREF(renderPassClearValues);
2280 const InstanceInterface& vki = context.getInstanceInterface();
2281 const VkPhysicalDevice& physDevice = context.getPhysicalDevice();
2282 const vector<Attachment>& attachmentInfos = renderPassInfo.getAttachments();
2283 const deUint32 subpassIndex = renderInfo.getSubpassIndex();
2284 vector<VkDescriptorSetLayoutBinding> bindings;
2286 for (deUint32 colorAttachmentNdx = 0; colorAttachmentNdx < renderInfo.getColorAttachmentCount(); colorAttachmentNdx++)
2288 const deUint32 attachmentNdx = (renderInfo.getColorAttachmentIndex(colorAttachmentNdx) == VK_ATTACHMENT_UNUSED) ? colorAttachmentNdx
2289 : renderInfo.getColorAttachmentIndex(colorAttachmentNdx);
2291 m_colorAttachmentImages.push_back(attachmentImages[attachmentNdx]);
2294 if (renderInfo.getDepthStencilAttachmentIndex())
2295 m_depthStencilAttachmentImage = attachmentImages[*renderInfo.getDepthStencilAttachmentIndex()];
2297 if (renderInfo.getRenderQuad())
2299 const RenderQuad& renderQuad = *renderInfo.getRenderQuad();
2301 if (renderInfo.getInputAttachmentCount() > 0)
2303 deUint32 bindingIndex = 0;
2305 for (deUint32 inputAttachmentNdx = 0; inputAttachmentNdx < renderInfo.getInputAttachmentCount(); inputAttachmentNdx++)
2307 const Attachment attachmentInfo = attachmentInfos[renderInfo.getInputAttachmentIndex(inputAttachmentNdx)];
2308 const VkImageLayout layout = renderInfo.getInputAttachmentLayout(inputAttachmentNdx);
2309 const tcu::TextureFormat format = mapVkFormat(attachmentInfo.getFormat());
2310 const bool isDepthFormat = tcu::hasDepthComponent(format.order);
2311 const bool isStencilFormat = tcu::hasStencilComponent(format.order);
2312 const deUint32 bindingCount = (isDepthFormat && layout != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
2313 && (isStencilFormat && layout != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL)
2317 for (deUint32 bindingNdx = 0; bindingNdx < bindingCount; bindingNdx++)
2319 const VkDescriptorSetLayoutBinding binding =
2322 vk::VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
2324 vk::VK_SHADER_STAGE_FRAGMENT_BIT,
2328 bindings.push_back(binding);
2333 const VkDescriptorSetLayoutCreateInfo createInfo =
2335 vk::VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
2339 (deUint32)bindings.size(),
2343 m_descriptorSetLayout = vk::createDescriptorSetLayout(vk, device, &createInfo);
2346 const VkDescriptorSetLayout descriptorSetLayout = *m_descriptorSetLayout;
2347 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
2349 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // sType;
2351 (vk::VkPipelineLayoutCreateFlags)0,
2352 m_descriptorSetLayout ? 1u :0u , // setLayoutCount;
2353 m_descriptorSetLayout ? &descriptorSetLayout : DE_NULL, // pSetLayouts;
2354 0u, // pushConstantRangeCount;
2355 DE_NULL, // pPushConstantRanges;
2358 m_vertexShaderModule = createShaderModule(vk, device, context.getBinaryCollection().get(de::toString(subpassIndex) + "-vert"), 0u);
2359 m_fragmentShaderModule = createShaderModule(vk, device, context.getBinaryCollection().get(de::toString(subpassIndex) + "-frag"), 0u);
2360 m_pipelineLayout = createPipelineLayout(vk, device, &pipelineLayoutParams);
2361 m_pipeline = createSubpassPipeline(vk, device, renderPass, *m_vertexShaderModule, *m_fragmentShaderModule, *m_pipelineLayout, m_renderInfo);
2363 // Round up the vertex buffer size to honor nonCoherentAtomSize.
2364 const auto properties = vk::getPhysicalDeviceProperties(context.getInstanceInterface(), context.getPhysicalDevice());
2365 const auto vertexBufferSize = de::roundUp(static_cast<VkDeviceSize>(renderQuad.getVertexDataSize()), properties.limits.nonCoherentAtomSize);
2367 m_vertexBuffer = createBuffer(vk, device, 0u, vertexBufferSize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_SHARING_MODE_EXCLUSIVE, 1u, &queueFamilyIndex);
2368 m_vertexBufferMemory = allocateBuffer(vki, vk, physDevice, device, *m_vertexBuffer, MemoryRequirement::HostVisible, allocator, allocationKind);
2370 bindBufferMemory(vk, device, *m_vertexBuffer, m_vertexBufferMemory->getMemory(), m_vertexBufferMemory->getOffset());
2372 uploadBufferData(vk, device, *m_vertexBufferMemory, renderQuad.getVertexDataSize(), renderQuad.getVertexPointer(), properties.limits.nonCoherentAtomSize);
2374 if (renderInfo.getInputAttachmentCount() > 0)
2377 const VkDescriptorPoolSize poolSize =
2379 vk::VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
2380 // \note Reserve 2 per input attachment since depthStencil attachments require 2.
2381 renderInfo.getInputAttachmentCount() * 2u
2383 const VkDescriptorPoolCreateInfo createInfo =
2385 vk::VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
2387 VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT,
2389 // \note Reserve 2 per input attachment since depthStencil attachments require 2.
2390 renderInfo.getInputAttachmentCount() * 2u,
2395 m_descriptorPool = vk::createDescriptorPool(vk, device, &createInfo);
2398 const VkDescriptorSetAllocateInfo allocateInfo =
2400 vk::VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
2405 &descriptorSetLayout
2408 m_descriptorSet = vk::allocateDescriptorSet(vk, device, &allocateInfo);
2411 vector<VkWriteDescriptorSet> writes (bindings.size());
2412 vector<VkDescriptorImageInfo> imageInfos (bindings.size());
2413 deUint32 bindingIndex = 0;
2415 for (deUint32 inputAttachmentNdx = 0; inputAttachmentNdx < renderInfo.getInputAttachmentCount(); inputAttachmentNdx++)
2417 const Attachment attachmentInfo = attachmentInfos[renderInfo.getInputAttachmentIndex(inputAttachmentNdx)];
2418 const tcu::TextureFormat format = mapVkFormat(attachmentInfo.getFormat());
2419 const bool isDepthFormat = tcu::hasDepthComponent(format.order);
2420 const bool isStencilFormat = tcu::hasStencilComponent(format.order);
2421 const VkImageLayout inputAttachmentLayout = renderInfo.getInputAttachmentLayout(inputAttachmentNdx);
2424 if (isDepthFormat && isStencilFormat)
2426 if (inputAttachmentLayout != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL)
2428 const VkDescriptorImageInfo imageInfo =
2431 attachmentViews[renderInfo.getInputAttachmentIndex(inputAttachmentNdx)].first,
2432 inputAttachmentLayout
2434 imageInfos[bindingIndex] = imageInfo;
2437 const VkWriteDescriptorSet write =
2439 VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
2446 VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
2447 &imageInfos[bindingIndex],
2451 writes[bindingIndex] = write;
2457 if (inputAttachmentLayout != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
2459 const VkDescriptorImageInfo imageInfo =
2462 attachmentViews[renderInfo.getInputAttachmentIndex(inputAttachmentNdx)].second,
2463 inputAttachmentLayout
2465 imageInfos[bindingIndex] = imageInfo;
2468 const VkWriteDescriptorSet write =
2470 VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
2477 VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
2478 &imageInfos[bindingIndex],
2482 writes[bindingIndex] = write;
2490 const VkDescriptorImageInfo imageInfo =
2493 attachmentViews[renderInfo.getInputAttachmentIndex(inputAttachmentNdx)].first,
2494 inputAttachmentLayout
2496 imageInfos[bindingIndex] = imageInfo;
2499 const VkWriteDescriptorSet write =
2501 VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
2508 VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
2509 &imageInfos[bindingIndex],
2513 writes[bindingIndex] = write;
2520 vk.updateDescriptorSets(device, (deUint32)writes.size(), &writes[0], 0u, DE_NULL);
2525 if (renderInfo.isSecondary())
2527 m_commandBuffer = allocateCommandBuffer(vk, device, commandBufferPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
2529 beginCommandBuffer(vk, *m_commandBuffer, renderPass, subpassIndex, framebuffer, VK_FALSE, (VkQueryControlFlags)0,
2530 (VkQueryPipelineStatisticFlags)0, &renderInfo, dynamicRendering, secondaryCmdBufferCompletelyContainsDynamicRenderpass);
2532 if (dynamicRendering && secondaryCmdBufferCompletelyContainsDynamicRenderpass)
2534 #ifndef CTS_USES_VULKANSC
2535 beginDynamicRendering(vk, *m_commandBuffer, renderPassInfo, attachmentResources, renderArea, renderPassClearValues);
2536 pushRenderCommands(vk, *m_commandBuffer);
2537 endDynamicRendering(vk, *m_commandBuffer);
2538 #endif // CTS_USES_VULKANSC
2541 pushRenderCommands(vk, *m_commandBuffer);
2543 endCommandBuffer(vk, *m_commandBuffer);
2547 bool isSecondary (void) const
2549 return !!m_commandBuffer;
2552 VkCommandBuffer getCommandBuffer (void) const
2554 DE_ASSERT(isSecondary());
2555 return *m_commandBuffer;
2558 void pushRenderCommands (const DeviceInterface& vk,
2559 VkCommandBuffer commandBuffer)
2561 if (!m_renderInfo.getColorClears().empty())
2563 const vector<ColorClear>& colorClears (m_renderInfo.getColorClears());
2565 for (deUint32 attachmentNdx = 0; attachmentNdx < m_renderInfo.getColorAttachmentCount(); attachmentNdx++)
2567 const ColorClear& colorClear = colorClears[attachmentNdx];
2568 const VkClearAttachment attachment =
2570 VK_IMAGE_ASPECT_COLOR_BIT,
2572 makeClearValue(colorClear.getColor()),
2574 const VkClearRect rect =
2577 { (deInt32)colorClear.getOffset().x(), (deInt32)colorClear.getOffset().y() },
2578 { colorClear.getSize().x(), colorClear.getSize().y() }
2580 0u, // baseArrayLayer
2584 vk.cmdClearAttachments(commandBuffer, 1u, &attachment, 1u, &rect);
2588 if (m_renderInfo.getDepthStencilClear())
2590 const DepthStencilClear& depthStencilClear = *m_renderInfo.getDepthStencilClear();
2591 const deUint32 attachmentNdx = m_renderInfo.getColorAttachmentCount();
2592 tcu::TextureFormat format = mapVkFormat(m_renderInfo.getDepthStencilAttachment()->getFormat());
2593 const VkImageLayout layout = *m_renderInfo.getDepthStencilAttachmentLayout();
2594 const VkClearAttachment attachment =
2596 (VkImageAspectFlags)((hasDepthComponent(format.order) && layout != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL ? VK_IMAGE_ASPECT_DEPTH_BIT : 0)
2597 | (hasStencilComponent(format.order) && layout != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL ? VK_IMAGE_ASPECT_STENCIL_BIT : 0)),
2599 makeClearValueDepthStencil(depthStencilClear.getDepth(), depthStencilClear.getStencil())
2601 const VkClearRect rect =
2604 { (deInt32)depthStencilClear.getOffset().x(), (deInt32)depthStencilClear.getOffset().y() },
2605 { depthStencilClear.getSize().x(), depthStencilClear.getSize().y() }
2607 0u, // baseArrayLayer
2611 if ((tcu::hasDepthComponent(format.order) && layout != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
2612 || (tcu::hasStencilComponent(format.order) && layout != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL))
2614 vk.cmdClearAttachments(commandBuffer, 1u, &attachment, 1u, &rect);
2618 vector<VkImageMemoryBarrier> selfDeps;
2619 VkPipelineStageFlags srcStages = 0;
2620 VkPipelineStageFlags dstStages = 0;
2622 for (deUint32 inputAttachmentNdx = 0; inputAttachmentNdx < m_renderInfo.getInputAttachmentCount(); inputAttachmentNdx++)
2624 for (deUint32 colorAttachmentNdx = 0; colorAttachmentNdx < m_renderInfo.getColorAttachmentCount(); colorAttachmentNdx++)
2626 if (m_renderInfo.getInputAttachmentIndex(inputAttachmentNdx) == m_renderInfo.getColorAttachmentIndex(colorAttachmentNdx))
2628 const VkImageMemoryBarrier barrier =
2630 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
2633 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // srcAccessMask
2634 VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, // dstAccessMask
2636 VK_IMAGE_LAYOUT_GENERAL, // oldLayout
2637 VK_IMAGE_LAYOUT_GENERAL, // newLayout
2639 VK_QUEUE_FAMILY_IGNORED, // srcQueueFamilyIndex
2640 VK_QUEUE_FAMILY_IGNORED, // destQueueFamilyIndex
2642 m_colorAttachmentImages[colorAttachmentNdx], // image
2643 { // subresourceRange
2644 VK_IMAGE_ASPECT_COLOR_BIT, // aspect
2647 0, // baseArraySlice
2652 srcStages |= VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
2653 dstStages |= VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
2655 selfDeps.push_back(barrier);
2659 if (m_renderInfo.getDepthStencilAttachmentIndex() && (m_renderInfo.getInputAttachmentIndex(inputAttachmentNdx) == *m_renderInfo.getDepthStencilAttachmentIndex()))
2661 const tcu::TextureFormat format = mapVkFormat(m_renderInfo.getDepthStencilAttachment()->getFormat());
2662 const bool hasDepth = hasDepthComponent(format.order);
2663 const bool hasStencil = hasStencilComponent(format.order);
2664 const VkImageMemoryBarrier barrier =
2666 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType;
2669 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, // srcAccessMask
2670 VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, // dstAccessMask
2672 m_renderInfo.getInputAttachmentLayout(inputAttachmentNdx), // oldLayout
2673 m_renderInfo.getInputAttachmentLayout(inputAttachmentNdx), // newLayout;
2675 VK_QUEUE_FAMILY_IGNORED, // srcQueueFamilyIndex;
2676 VK_QUEUE_FAMILY_IGNORED, // destQueueFamilyIndex;
2678 m_depthStencilAttachmentImage, // image;
2679 { // subresourceRange;
2680 (hasDepth ? (VkImageAspectFlags)VK_IMAGE_ASPECT_DEPTH_BIT : 0u)
2681 | (hasStencil ? (VkImageAspectFlags)VK_IMAGE_ASPECT_STENCIL_BIT : 0u), // aspect;
2684 0, // baseArraySlice;
2689 srcStages |= VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT;
2690 dstStages |= VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
2692 selfDeps.push_back(barrier);
2696 if (!selfDeps.empty())
2698 DE_ASSERT(srcStages != 0);
2699 DE_ASSERT(dstStages != 0);
2700 vk.cmdPipelineBarrier(commandBuffer, srcStages, dstStages, VK_DEPENDENCY_BY_REGION_BIT, 0, DE_NULL, 0, DE_NULL, (deUint32)selfDeps.size(), &selfDeps[0]);
2703 if (m_renderInfo.getRenderQuad())
2705 const VkDeviceSize offset = 0;
2706 const VkBuffer vertexBuffer = *m_vertexBuffer;
2708 vk.cmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
2710 if (m_descriptorSet)
2712 const VkDescriptorSet descriptorSet = *m_descriptorSet;
2713 vk.cmdBindDescriptorSets(commandBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipelineLayout, 0u, 1u, &descriptorSet, 0u, NULL);
2716 vk.cmdBindVertexBuffers(commandBuffer, 0u, 1u, &vertexBuffer, &offset);
2717 vk.cmdDraw(commandBuffer, 6u, 1u, 0u, 0u);
2722 const SubpassRenderInfo m_renderInfo;
2723 Move<VkCommandBuffer> m_commandBuffer;
2724 Move<VkPipeline> m_pipeline;
2725 Move<VkDescriptorSetLayout> m_descriptorSetLayout;
2726 Move<VkPipelineLayout> m_pipelineLayout;
2728 Move<VkShaderModule> m_vertexShaderModule;
2729 Move<VkShaderModule> m_fragmentShaderModule;
2731 Move<VkDescriptorPool> m_descriptorPool;
2732 Move<VkDescriptorSet> m_descriptorSet;
2733 Move<VkBuffer> m_vertexBuffer;
2734 de::MovePtr<Allocation> m_vertexBufferMemory;
2735 vector<VkImage> m_colorAttachmentImages;
2736 VkImage m_depthStencilAttachmentImage;
2739 void pushImageInitializationCommands (const DeviceInterface& vk,
2740 VkCommandBuffer commandBuffer,
2741 const vector<Attachment>& attachmentInfo,
2742 const vector<de::SharedPtr<AttachmentResources> >& attachmentResources,
2743 deUint32 queueIndex,
2744 const vector<Maybe<VkClearValue> >& clearValues)
2747 vector<VkImageMemoryBarrier> initializeLayouts;
2749 for (size_t attachmentNdx = 0; attachmentNdx < attachmentInfo.size(); attachmentNdx++)
2751 if (!clearValues[attachmentNdx])
2754 const VkImageMemoryBarrier barrier =
2756 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType;
2759 (VkAccessFlags)0, // srcAccessMask
2760 getAllMemoryReadFlags() | VK_ACCESS_TRANSFER_WRITE_BIT, // dstAccessMask
2762 VK_IMAGE_LAYOUT_UNDEFINED, // oldLayout
2763 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // newLayout;
2765 queueIndex, // srcQueueFamilyIndex;
2766 queueIndex, // destQueueFamilyIndex;
2768 attachmentResources[attachmentNdx]->getImage(), // image;
2769 { // subresourceRange;
2770 getImageAspectFlags(attachmentInfo[attachmentNdx].getFormat()), // aspect;
2773 0, // baseArraySlice;
2778 initializeLayouts.push_back(barrier);
2781 if (!initializeLayouts.empty())
2782 vk.cmdPipelineBarrier(commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT,
2783 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, (VkDependencyFlags)0,
2784 0, (const VkMemoryBarrier*)DE_NULL,
2785 0, (const VkBufferMemoryBarrier*)DE_NULL,
2786 (deUint32)initializeLayouts.size(), &initializeLayouts[0]);
2789 for (size_t attachmentNdx = 0; attachmentNdx < attachmentInfo.size(); attachmentNdx++)
2791 if (!clearValues[attachmentNdx])
2794 const tcu::TextureFormat format = mapVkFormat(attachmentInfo[attachmentNdx].getFormat());
2796 if (hasStencilComponent(format.order) || hasDepthComponent(format.order))
2798 const float clearNan = tcu::Float32::nan().asFloat();
2799 const float clearDepth = hasDepthComponent(format.order) ? clearValues[attachmentNdx]->depthStencil.depth : clearNan;
2800 const deUint32 clearStencil = hasStencilComponent(format.order) ? clearValues[attachmentNdx]->depthStencil.stencil : 0xDEu;
2801 const VkClearDepthStencilValue depthStencil =
2806 const VkImageSubresourceRange range =
2808 (VkImageAspectFlags)((hasDepthComponent(format.order) ? VK_IMAGE_ASPECT_DEPTH_BIT : 0)
2809 | (hasStencilComponent(format.order) ? VK_IMAGE_ASPECT_STENCIL_BIT : 0)),
2816 vk.cmdClearDepthStencilImage(commandBuffer, attachmentResources[attachmentNdx]->getImage(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &depthStencil, 1, &range);
2820 const VkImageSubresourceRange range =
2822 VK_IMAGE_ASPECT_COLOR_BIT, // aspectMask;
2825 0, // baseArrayLayer;
2828 const VkClearColorValue clearColor = clearValues[attachmentNdx]->color;
2830 vk.cmdClearColorImage(commandBuffer, attachmentResources[attachmentNdx]->getImage(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clearColor, 1, &range);
2835 vector<VkImageMemoryBarrier> renderPassLayouts;
2837 for (size_t attachmentNdx = 0; attachmentNdx < attachmentInfo.size(); attachmentNdx++)
2839 const VkImageLayout oldLayout = clearValues[attachmentNdx] ? VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL : VK_IMAGE_LAYOUT_UNDEFINED;
2840 const VkImageMemoryBarrier barrier =
2842 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType;
2845 getMemoryFlagsForLayout(oldLayout), // srcAccessMask
2846 getAllMemoryReadFlags() | getMemoryFlagsForLayout(attachmentInfo[attachmentNdx].getInitialLayout()), // dstAccessMask
2848 oldLayout, // oldLayout
2849 attachmentInfo[attachmentNdx].getInitialLayout(), // newLayout;
2851 queueIndex, // srcQueueFamilyIndex;
2852 queueIndex, // destQueueFamilyIndex;
2854 attachmentResources[attachmentNdx]->getImage(), // image;
2855 { // subresourceRange;
2856 getImageAspectFlags(attachmentInfo[attachmentNdx].getFormat()), // aspect;
2859 0, // baseArraySlice;
2864 renderPassLayouts.push_back(barrier);
2867 if (!renderPassLayouts.empty())
2868 vk.cmdPipelineBarrier(commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT,
2869 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, (VkDependencyFlags)0,
2870 0, (const VkMemoryBarrier*)DE_NULL,
2871 0, (const VkBufferMemoryBarrier*)DE_NULL,
2872 (deUint32)renderPassLayouts.size(), &renderPassLayouts[0]);
2876 template<typename RenderpassSubpass>
2877 void pushRenderPassCommands (const DeviceInterface& vk,
2878 VkCommandBuffer commandBuffer,
2879 VkRenderPass renderPass,
2880 VkFramebuffer framebuffer,
2881 const vector<de::SharedPtr<SubpassRenderer> >& subpassRenderers,
2882 const VkRect2D& renderArea,
2883 const vector<Maybe<VkClearValue> >& renderPassClearValues,
2884 TestConfig::RenderTypes render)
2886 const float clearNan = tcu::Float32::nan().asFloat();
2887 vector<VkClearValue> attachmentClearValues;
2888 const typename RenderpassSubpass::SubpassEndInfo subpassEndInfo (DE_NULL);
2890 for (size_t attachmentNdx = 0; attachmentNdx < renderPassClearValues.size(); attachmentNdx++)
2892 if (renderPassClearValues[attachmentNdx])
2893 attachmentClearValues.push_back(*renderPassClearValues[attachmentNdx]);
2895 attachmentClearValues.push_back(makeClearValueColorF32(clearNan, clearNan, clearNan, clearNan));
2899 for (size_t subpassNdx = 0; subpassNdx < subpassRenderers.size(); subpassNdx++)
2901 const VkSubpassContents contents = subpassRenderers[subpassNdx]->isSecondary() ? VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS : VK_SUBPASS_CONTENTS_INLINE;
2902 const typename RenderpassSubpass::SubpassBeginInfo subpassBeginInfo (DE_NULL, contents);
2903 const VkRenderPassBeginInfo renderPassBeginInfo = createRenderPassBeginInfo(renderPass,
2906 (deUint32)attachmentClearValues.size(),
2907 attachmentClearValues.empty() ? DE_NULL : &attachmentClearValues[0]);
2909 if (subpassNdx == 0)
2910 RenderpassSubpass::cmdBeginRenderPass(vk, commandBuffer, &renderPassBeginInfo, &subpassBeginInfo);
2912 RenderpassSubpass::cmdNextSubpass(vk, commandBuffer, &subpassBeginInfo, &subpassEndInfo);
2916 if (contents == VK_SUBPASS_CONTENTS_INLINE)
2918 subpassRenderers[subpassNdx]->pushRenderCommands(vk, commandBuffer);
2920 else if (contents == VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS)
2922 const VkCommandBuffer cmd = subpassRenderers[subpassNdx]->getCommandBuffer();
2923 vk.cmdExecuteCommands(commandBuffer, 1, &cmd);
2926 DE_FATAL("Invalid contents");
2930 RenderpassSubpass::cmdEndRenderPass(vk, commandBuffer, &subpassEndInfo);
2934 #ifndef CTS_USES_VULKANSC
2935 void pushDynamicRenderingCommands (const DeviceInterface& vk,
2936 VkCommandBuffer commandBuffer,
2937 const RenderPass& renderPassInfo,
2938 const vector<de::SharedPtr<AttachmentResources> >& attachmentResources,
2939 const vector<de::SharedPtr<SubpassRenderer> >& subpassRenderers,
2940 const VkRect2D& renderArea,
2941 const vector<Maybe<VkClearValue> >& renderPassClearValues,
2942 deUint32 queueIndex,
2943 TestConfig::RenderTypes renderType,
2944 bool secondaryCmdBufferCompletelyContainsDynamicRenderpass)
2946 DE_ASSERT(subpassRenderers.size() == 1);
2948 vector<VkImageMemoryBarrier> imageBarriersBeforeRendering;
2949 vector<VkImageMemoryBarrier> imageBarriersAfterRendering;
2951 const Subpass& subpassInfo = renderPassInfo.getSubpasses()[0];
2952 const vector<AttachmentReference>& colorAttachmentsInfo = subpassInfo.getColorAttachments();
2954 for (deUint32 i = 0 ; i < colorAttachmentsInfo.size() ; ++i)
2956 const AttachmentReference& colorAttachmentReference = colorAttachmentsInfo[i];
2957 const deUint32 colorAttachmentIndex = colorAttachmentReference.getAttachment();
2958 const Attachment& colorAttachmentInfo = renderPassInfo.getAttachments()[colorAttachmentIndex];
2960 const VkImageLayout initialLayout = colorAttachmentInfo.getInitialLayout();
2961 const VkImageLayout renderingLayout = colorAttachmentReference.getImageLayout();
2962 const VkImageLayout finalLayout = colorAttachmentInfo.getFinalLayout();
2964 const VkImageMemoryBarrier barrierBeforeRendering
2966 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
2969 getAllMemoryWriteFlags() | getMemoryFlagsForLayout(initialLayout), // srcAccessMask
2970 getMemoryFlagsForLayout(renderingLayout), // dstAccessMask
2972 initialLayout, // oldLayout
2973 renderingLayout, // newLayout
2975 queueIndex, // srcQueueFamilyIndex
2976 queueIndex, // destQueueFamilyIndex
2978 attachmentResources[colorAttachmentIndex]->getImage(), // image
2979 { // subresourceRange
2980 getImageAspectFlags(colorAttachmentInfo.getFormat()), // aspect;
2983 0, // baseArraySlice
2987 imageBarriersBeforeRendering.push_back(barrierBeforeRendering);
2989 const VkImageMemoryBarrier barrierAfterRendering
2991 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
2994 getMemoryFlagsForLayout(renderingLayout), // srcAccessMask
2995 getAllMemoryReadFlags() | getMemoryFlagsForLayout(finalLayout), // dstAccessMask
2997 renderingLayout, // oldLayout
2998 finalLayout, // newLayout
3000 queueIndex, // srcQueueFamilyIndex
3001 queueIndex, // destQueueFamilyIndex
3003 attachmentResources[colorAttachmentIndex]->getImage(), // image
3004 { // subresourceRange
3005 getImageAspectFlags(colorAttachmentInfo.getFormat()), // aspect;
3008 0, // baseArraySlice
3012 imageBarriersAfterRendering.push_back(barrierAfterRendering);
3015 const AttachmentReference& depthStencilAttachmentReference = subpassInfo.getDepthStencilAttachment();
3016 const deUint32 dsAttachmentIndex = depthStencilAttachmentReference.getAttachment();
3018 if (dsAttachmentIndex != VK_ATTACHMENT_UNUSED)
3020 const Attachment& dsAttachmentInfo = renderPassInfo.getAttachments()[dsAttachmentIndex];
3022 const VkImageLayout initialLayout = dsAttachmentInfo.getInitialLayout();
3023 const VkImageLayout renderingLayout = depthStencilAttachmentReference.getImageLayout();
3024 const VkImageLayout finalLayout = dsAttachmentInfo.getFinalLayout();
3026 const VkImageMemoryBarrier barrierBeforeRendering
3028 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
3031 getAllMemoryWriteFlags() | getMemoryFlagsForLayout(initialLayout), // srcAccessMask
3032 getMemoryFlagsForLayout(renderingLayout), // dstAccessMask
3034 initialLayout, // oldLayout
3035 renderingLayout, // newLayout
3037 queueIndex, // srcQueueFamilyIndex
3038 queueIndex, // destQueueFamilyIndex
3040 attachmentResources[dsAttachmentIndex]->getImage(), // image
3041 { // subresourceRange
3042 getImageAspectFlags(dsAttachmentInfo.getFormat()), // aspect;
3045 0, // baseArraySlice
3049 imageBarriersBeforeRendering.push_back(barrierBeforeRendering);
3051 const VkImageMemoryBarrier barrierAfterRendering
3053 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
3056 getMemoryFlagsForLayout(renderingLayout), // srcAccessMask
3057 getAllMemoryReadFlags() | getMemoryFlagsForLayout(finalLayout), // dstAccessMask
3059 renderingLayout, // oldLayout
3060 finalLayout, // newLayout
3062 queueIndex, // srcQueueFamilyIndex
3063 queueIndex, // destQueueFamilyIndex
3065 attachmentResources[dsAttachmentIndex]->getImage(), // image
3066 { // subresourceRange
3067 getImageAspectFlags(dsAttachmentInfo.getFormat()), // aspect;
3070 0, // baseArraySlice
3074 imageBarriersAfterRendering.push_back(barrierAfterRendering);
3077 if (!imageBarriersBeforeRendering.empty())
3078 vk.cmdPipelineBarrier(commandBuffer,
3079 getAllPipelineStageFlags(),
3080 getAllPipelineStageFlags(),
3081 (VkDependencyFlags)0,
3082 0, (const VkMemoryBarrier*)DE_NULL,
3083 0, (const VkBufferMemoryBarrier*)DE_NULL,
3084 (deUint32)imageBarriersBeforeRendering.size(),
3085 &imageBarriersBeforeRendering[0]);
3087 bool executeRenderCommands = (renderType != TestConfig::RENDERTYPES_NONE);
3089 if (secondaryCmdBufferCompletelyContainsDynamicRenderpass)
3091 // when secondary command buffer completely contains dynamic renderpass
3092 // then we need to execute it even when render type is none
3093 executeRenderCommands = true;
3097 VkRenderingFlagsKHR renderingFlags = 0u;
3098 if (subpassRenderers[0]->isSecondary())
3099 renderingFlags = VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR;
3101 beginDynamicRendering(vk, commandBuffer, renderPassInfo, attachmentResources, renderArea, renderPassClearValues, renderingFlags);
3104 if (executeRenderCommands)
3106 if (subpassRenderers[0]->isSecondary())
3108 const VkCommandBuffer cmd = subpassRenderers[0]->getCommandBuffer();
3109 vk.cmdExecuteCommands(commandBuffer, 1, &cmd);
3112 subpassRenderers[0]->pushRenderCommands(vk, commandBuffer);
3115 if (!secondaryCmdBufferCompletelyContainsDynamicRenderpass)
3116 endDynamicRendering(vk, commandBuffer);
3118 if (!imageBarriersAfterRendering.empty())
3119 vk.cmdPipelineBarrier(commandBuffer,
3120 getAllPipelineStageFlags(),
3121 getAllPipelineStageFlags(),
3122 (VkDependencyFlags)0,
3123 0, (const VkMemoryBarrier*)DE_NULL,
3124 0, (const VkBufferMemoryBarrier*)DE_NULL,
3125 (deUint32)imageBarriersAfterRendering.size(),
3126 &imageBarriersAfterRendering[0]);
3128 #endif // CTS_USES_VULKANSC
3130 void pushRenderPassCommands (const DeviceInterface& vk,
3131 VkCommandBuffer commandBuffer,
3132 VkRenderPass renderPass,
3133 const RenderPass& renderPassInfo,
3134 const vector<de::SharedPtr<AttachmentResources> >& attachmentResources,
3135 VkFramebuffer framebuffer,
3136 const vector<de::SharedPtr<SubpassRenderer> >& subpassRenderers,
3137 const VkRect2D& renderArea,
3138 const vector<Maybe<VkClearValue> >& renderPassClearValues,
3139 deUint32 queueIndex,
3140 TestConfig::RenderTypes render,
3141 RenderingType renderingType,
3142 bool secondaryCmdBufferCompletelyContainsDynamicRenderpass)
3144 // unreference arguments not used by Vulkan SC, no need to put them under ifdef
3145 DE_UNREF(renderPassInfo);
3146 DE_UNREF(attachmentResources);
3147 DE_UNREF(queueIndex);
3148 DE_UNREF(secondaryCmdBufferCompletelyContainsDynamicRenderpass);
3150 switch (renderingType)
3152 case RENDERING_TYPE_RENDERPASS_LEGACY:
3153 return pushRenderPassCommands<RenderpassSubpass1>(vk, commandBuffer, renderPass, framebuffer, subpassRenderers, renderArea, renderPassClearValues, render);
3154 case RENDERING_TYPE_RENDERPASS2:
3155 return pushRenderPassCommands<RenderpassSubpass2>(vk, commandBuffer, renderPass, framebuffer, subpassRenderers, renderArea, renderPassClearValues, render);
3157 #ifndef CTS_USES_VULKANSC
3158 case RENDERING_TYPE_DYNAMIC_RENDERING:
3159 return pushDynamicRenderingCommands(vk, commandBuffer, renderPassInfo, attachmentResources, subpassRenderers, renderArea, renderPassClearValues, queueIndex, render, secondaryCmdBufferCompletelyContainsDynamicRenderpass);
3160 #endif // CTS_USES_VULKANSC
3163 TCU_THROW(InternalError, "Impossible");
3167 void pushReadImagesToBuffers (const DeviceInterface& vk,
3168 VkCommandBuffer commandBuffer,
3169 deUint32 queueIndex,
3171 const vector<de::SharedPtr<AttachmentResources> >& attachmentResources,
3172 const vector<Attachment>& attachmentInfo,
3173 const vector<bool>& isLazy,
3175 const UVec2& targetSize)
3178 vector<VkImageMemoryBarrier> imageBarriers;
3180 for (size_t attachmentNdx = 0; attachmentNdx < attachmentInfo.size(); attachmentNdx++)
3182 if (isLazy[attachmentNdx])
3185 const VkImageLayout oldLayout = attachmentInfo[attachmentNdx].getFinalLayout();
3186 const VkImageMemoryBarrier barrier =
3188 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
3191 getAllMemoryWriteFlags() | getMemoryFlagsForLayout(oldLayout), // srcAccessMask
3192 getAllMemoryReadFlags(), // dstAccessMask
3194 oldLayout, // oldLayout
3195 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // newLayout
3197 queueIndex, // srcQueueFamilyIndex
3198 queueIndex, // destQueueFamilyIndex
3200 attachmentResources[attachmentNdx]->getImage(), // image
3201 { // subresourceRange
3202 getImageAspectFlags(attachmentInfo[attachmentNdx].getFormat()), // aspect;
3205 0, // baseArraySlice
3210 imageBarriers.push_back(barrier);
3213 if (!imageBarriers.empty())
3214 vk.cmdPipelineBarrier(commandBuffer,
3215 getAllPipelineStageFlags(),
3216 getAllPipelineStageFlags(),
3217 (VkDependencyFlags)0,
3218 0, (const VkMemoryBarrier*)DE_NULL,
3219 0, (const VkBufferMemoryBarrier*)DE_NULL,
3220 (deUint32)imageBarriers.size(), &imageBarriers[0]);
3223 for (size_t attachmentNdx = 0; attachmentNdx < attachmentInfo.size(); attachmentNdx++)
3225 if (isLazy[attachmentNdx])
3228 const tcu::TextureFormat::ChannelOrder order = mapVkFormat(attachmentInfo[attachmentNdx].getFormat()).order;
3229 const VkBufferImageCopy rect =
3232 0, // bufferRowLength
3233 0, // bufferImageHeight
3234 { // imageSubresource
3235 (vk::VkImageAspectFlags)getPrimaryImageAspect(mapVkFormat(attachmentInfo[attachmentNdx].getFormat()).order), // aspect
3240 { 0, 0, 0 }, // imageOffset
3241 { targetSize.x(), targetSize.y(), 1u } // imageExtent
3244 vk.cmdCopyImageToBuffer(commandBuffer, attachmentResources[attachmentNdx]->getImage(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, attachmentResources[attachmentNdx]->getBuffer(), 1, &rect);
3246 if (tcu::TextureFormat::DS == order)
3248 const VkBufferImageCopy stencilRect =
3251 0, // bufferRowLength
3252 0, // bufferImageHeight
3253 { // imageSubresource
3254 VK_IMAGE_ASPECT_STENCIL_BIT, // aspect
3259 { 0, 0, 0 }, // imageOffset
3260 { targetSize.x(), targetSize.y(), 1u } // imageExtent
3263 vk.cmdCopyImageToBuffer(commandBuffer, attachmentResources[attachmentNdx]->getImage(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, attachmentResources[attachmentNdx]->getSecondaryBuffer(), 1, &stencilRect);
3268 vector<VkBufferMemoryBarrier> bufferBarriers;
3270 for (size_t attachmentNdx = 0; attachmentNdx < attachmentInfo.size(); attachmentNdx++)
3272 if (isLazy[attachmentNdx])
3275 const tcu::TextureFormat::ChannelOrder order = mapVkFormat(attachmentInfo[attachmentNdx].getFormat()).order;
3276 const VkBufferMemoryBarrier bufferBarrier =
3278 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
3281 getAllMemoryWriteFlags(),
3282 getAllMemoryReadFlags(),
3287 attachmentResources[attachmentNdx]->getBuffer(),
3289 attachmentResources[attachmentNdx]->getBufferSize()
3292 bufferBarriers.push_back(bufferBarrier);
3294 if (tcu::TextureFormat::DS == order)
3296 const VkBufferMemoryBarrier secondaryBufferBarrier =
3298 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
3301 getAllMemoryWriteFlags(),
3302 getAllMemoryReadFlags(),
3307 attachmentResources[attachmentNdx]->getSecondaryBuffer(),
3309 attachmentResources[attachmentNdx]->getSecondaryBufferSize()
3312 bufferBarriers.push_back(secondaryBufferBarrier);
3316 if (!bufferBarriers.empty())
3317 vk.cmdPipelineBarrier(commandBuffer,
3318 getAllPipelineStageFlags(),
3319 getAllPipelineStageFlags(),
3320 (VkDependencyFlags)0,
3321 0, (const VkMemoryBarrier*)DE_NULL,
3322 (deUint32)bufferBarriers.size(), &bufferBarriers[0],
3323 0, (const VkImageMemoryBarrier*)DE_NULL);
3330 PixelValue (const Maybe<bool>& x = tcu::Nothing,
3331 const Maybe<bool>& y = tcu::Nothing,
3332 const Maybe<bool>& z = tcu::Nothing,
3333 const Maybe<bool>& w = tcu::Nothing);
3335 void setUndefined (size_t ndx);
3336 void setValue (size_t ndx, bool value);
3337 Maybe<bool> getValue (size_t ndx) const;
3343 PixelValue::PixelValue (const Maybe<bool>& x,
3344 const Maybe<bool>& y,
3345 const Maybe<bool>& z,
3346 const Maybe<bool>& w)
3349 const Maybe<bool> values[] =
3354 for (size_t ndx = 0; ndx < DE_LENGTH_OF_ARRAY(values); ndx++)
3357 setValue(ndx, *values[ndx]);
3362 DE_ASSERT(m_status <= 0xFFu);
3365 void PixelValue::setUndefined (size_t ndx)
3368 DE_ASSERT(m_status <= 0xFFu);
3370 m_status &= (deUint16)~(0x1u << (deUint16)(ndx * 2));
3371 DE_ASSERT(m_status <= 0xFFu);
3374 void PixelValue::setValue (size_t ndx, bool value)
3377 DE_ASSERT(m_status <= 0xFFu);
3379 m_status = (deUint16)(m_status | (deUint16)(0x1u << (ndx * 2)));
3382 m_status = (deUint16)(m_status | (deUint16)(0x1u << (ndx * 2 + 1)));
3384 m_status &= (deUint16)~(0x1u << (deUint16)(ndx * 2 + 1));
3386 DE_ASSERT(m_status <= 0xFFu);
3389 Maybe<bool> PixelValue::getValue (size_t ndx) const
3392 DE_ASSERT(m_status <= 0xFFu);
3394 if ((m_status & (0x1u << (deUint16)(ndx * 2))) != 0)
3396 return just((m_status & (0x1u << (deUint32)(ndx * 2 + 1))) != 0);
3399 return tcu::Nothing;
3402 void clearReferenceValues (vector<PixelValue>& values,
3403 const UVec2& targetSize,
3404 const UVec2& offset,
3407 const PixelValue& value)
3409 DE_ASSERT(targetSize.x() * targetSize.y() == (deUint32)values.size());
3410 DE_ASSERT(offset.x() + size.x() <= targetSize.x());
3411 DE_ASSERT(offset.y() + size.y() <= targetSize.y());
3413 for (deUint32 y = offset.y(); y < offset.y() + size.y(); y++)
3414 for (deUint32 x = offset.x(); x < offset.x() + size.x(); x++)
3416 for (int compNdx = 0; compNdx < 4; compNdx++)
3420 if (value.getValue(compNdx))
3421 values[x + y * targetSize.x()].setValue(compNdx, *value.getValue(compNdx));
3423 values[x + y * targetSize.x()].setUndefined(compNdx);
3429 void markUndefined (vector<PixelValue>& values,
3431 const UVec2& targetSize,
3432 const UVec2& offset,
3435 DE_ASSERT(targetSize.x() * targetSize.y() == (deUint32)values.size());
3437 for (deUint32 y = offset.y(); y < offset.y() + size.y(); y++)
3438 for (deUint32 x = offset.x(); x < offset.x() + size.x(); x++)
3440 for (int compNdx = 0; compNdx < 4; compNdx++)
3443 values[x + y * targetSize.x()].setUndefined(compNdx);
3448 PixelValue clearValueToPixelValue (const VkClearValue& value,
3449 const tcu::TextureFormat& format,
3450 const DepthValuesArray& depthValues)
3452 const bool isDepthAttachment = hasDepthComponent(format.order);
3453 const bool isStencilAttachment = hasStencilComponent(format.order);
3454 const bool isDepthOrStencilAttachment = isDepthAttachment || isStencilAttachment;
3455 PixelValue pixelValue;
3457 if (isDepthOrStencilAttachment)
3459 if (isDepthAttachment)
3461 if (value.depthStencil.depth == float(depthValues[1]) / 255.0f)
3462 pixelValue.setValue(0, true);
3463 else if (value.depthStencil.depth == float(depthValues[0]) / 255.0f)
3464 pixelValue.setValue(0, false);
3466 DE_FATAL("Unknown depth value");
3469 if (isStencilAttachment)
3471 if (value.depthStencil.stencil == 0xFFu)
3472 pixelValue.setValue(1, true);
3473 else if (value.depthStencil.stencil == 0x0u)
3474 pixelValue.setValue(1, false);
3476 DE_FATAL("Unknown stencil value");
3481 const tcu::TextureChannelClass channelClass = tcu::getTextureChannelClass(format.type);
3482 const tcu::BVec4 channelMask = tcu::getTextureFormatChannelMask(format);
3484 switch (channelClass)
3486 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
3487 for (int i = 0; i < 4; i++)
3491 if (value.color.int32[i] == 1)
3492 pixelValue.setValue(i, true);
3493 else if (value.color.int32[i] == 0)
3494 pixelValue.setValue(i, false);
3496 DE_FATAL("Unknown clear color value");
3501 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
3502 for (int i = 0; i < 4; i++)
3506 if (value.color.uint32[i] == 1u)
3507 pixelValue.setValue(i, true);
3508 else if (value.color.uint32[i] == 0u)
3509 pixelValue.setValue(i, false);
3511 DE_FATAL("Unknown clear color value");
3516 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
3517 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
3518 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
3519 for (int i = 0; i < 4; i++)
3523 if (value.color.float32[i] == 1.0f)
3524 pixelValue.setValue(i, true);
3525 else if (value.color.float32[i] == 0.0f)
3526 pixelValue.setValue(i, false);
3528 DE_FATAL("Unknown clear color value");
3534 DE_FATAL("Unknown channel class");
3541 void renderReferenceValues (vector<vector<PixelValue> >& referenceAttachments,
3542 const RenderPass& renderPassInfo,
3543 const UVec2& targetSize,
3544 const vector<Maybe<VkClearValue> >& imageClearValues,
3545 const vector<Maybe<VkClearValue> >& renderPassClearValues,
3546 const vector<SubpassRenderInfo>& subpassRenderInfo,
3547 const UVec2& renderPos,
3548 const UVec2& renderSize,
3549 const deUint32 drawStartNdx,
3550 const DepthValuesArray& depthValues)
3552 const vector<Subpass>& subpasses = renderPassInfo.getSubpasses();
3553 vector<bool> attachmentUsed (renderPassInfo.getAttachments().size(), false);
3555 referenceAttachments.resize(renderPassInfo.getAttachments().size());
3557 for (size_t attachmentNdx = 0; attachmentNdx < renderPassInfo.getAttachments().size(); attachmentNdx++)
3559 const Attachment attachment = renderPassInfo.getAttachments()[attachmentNdx];
3560 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3561 vector<PixelValue>& reference = referenceAttachments[attachmentNdx];
3563 reference.resize(targetSize.x() * targetSize.y());
3565 if (imageClearValues[attachmentNdx])
3566 clearReferenceValues(reference, targetSize, UVec2(0, 0), targetSize, BVec4(true), clearValueToPixelValue(*imageClearValues[attachmentNdx], format, depthValues));
3569 for (size_t subpassNdx = 0; subpassNdx < subpasses.size(); subpassNdx++)
3571 const Subpass& subpass = subpasses[subpassNdx];
3572 const SubpassRenderInfo& renderInfo = subpassRenderInfo[subpassNdx];
3573 const vector<AttachmentReference>& colorAttachments = subpass.getColorAttachments();
3575 // Apply load op if attachment was used for the first time
3576 for (size_t attachmentNdx = 0; attachmentNdx < colorAttachments.size(); attachmentNdx++)
3578 const deUint32 attachmentIndex = getAttachmentNdx(colorAttachments, attachmentNdx);
3580 if (!attachmentUsed[attachmentIndex] && colorAttachments[attachmentNdx].getAttachment() != VK_ATTACHMENT_UNUSED)
3582 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3583 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3584 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3586 DE_ASSERT(!tcu::hasDepthComponent(format.order));
3587 DE_ASSERT(!tcu::hasStencilComponent(format.order));
3589 if (attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_CLEAR)
3590 clearReferenceValues(reference, targetSize, renderPos, renderSize, BVec4(true), clearValueToPixelValue(*renderPassClearValues[attachmentIndex], format, depthValues));
3591 else if (attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE)
3592 markUndefined(reference, BVec4(true), targetSize, renderPos, renderSize);
3594 attachmentUsed[attachmentIndex] = true;
3598 // Apply load op to depth/stencil attachment if it was used for the first time
3599 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED)
3601 const deUint32 attachmentIndex = subpass.getDepthStencilAttachment().getAttachment();
3603 // Apply load op if attachment was used for the first time
3604 if (!attachmentUsed[attachmentIndex])
3606 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3607 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3608 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3610 if (tcu::hasDepthComponent(format.order))
3612 if (attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_CLEAR)
3613 clearReferenceValues(reference, targetSize, renderPos, renderSize, BVec4(true, false, false, false), clearValueToPixelValue(*renderPassClearValues[attachmentIndex], format, depthValues));
3614 else if (attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE)
3615 markUndefined(reference, BVec4(true, false, false, false), targetSize, renderPos, renderSize);
3618 if (tcu::hasStencilComponent(format.order))
3620 if (attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_CLEAR)
3621 clearReferenceValues(reference, targetSize, renderPos, renderSize, BVec4(false, true, false, false), clearValueToPixelValue(*renderPassClearValues[attachmentIndex], format, depthValues));
3622 else if (attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE)
3623 markUndefined(reference, BVec4(false, true, false, false), targetSize, renderPos, renderSize);
3626 attachmentUsed[attachmentIndex] = true;
3630 for (size_t colorClearNdx = 0; colorClearNdx < renderInfo.getColorClears().size(); colorClearNdx++)
3632 const ColorClear& colorClear = renderInfo.getColorClears()[colorClearNdx];
3633 const UVec2 offset = colorClear.getOffset();
3634 const UVec2 size = colorClear.getSize();
3635 const deUint32 attachmentIndex = subpass.getColorAttachments()[colorClearNdx].getAttachment();
3636 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3637 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3638 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3641 value.color = colorClear.getColor();
3643 clearReferenceValues(reference, targetSize, offset, size, BVec4(true), clearValueToPixelValue(value, format, depthValues));
3646 if (renderInfo.getDepthStencilClear())
3648 const DepthStencilClear& dsClear = *renderInfo.getDepthStencilClear();
3649 const UVec2 offset = dsClear.getOffset();
3650 const UVec2 size = dsClear.getSize();
3651 const deUint32 attachmentIndex = subpass.getDepthStencilAttachment().getAttachment();
3652 const VkImageLayout layout = subpass.getDepthStencilAttachment().getImageLayout();
3653 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3654 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3655 const bool hasStencil = tcu::hasStencilComponent(format.order)
3656 && layout != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL;
3657 const bool hasDepth = tcu::hasDepthComponent(format.order)
3658 && layout != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL;
3659 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3662 value.depthStencil.depth = dsClear.getDepth();
3663 value.depthStencil.stencil = dsClear.getStencil();
3665 clearReferenceValues(reference, targetSize, offset, size, BVec4(hasDepth, hasStencil, false, false), clearValueToPixelValue(value, format, depthValues));
3668 if (renderInfo.getRenderQuad())
3670 const RenderQuad& renderQuad = *renderInfo.getRenderQuad();
3671 const Vec2 posA = renderQuad.getCornerA();
3672 const Vec2 posB = renderQuad.getCornerB();
3673 const Vec2 origin = Vec2((float)renderInfo.getViewportOffset().x(), (float)renderInfo.getViewportOffset().y()) + Vec2((float)renderInfo.getViewportSize().x(), (float)renderInfo.getViewportSize().y()) / Vec2(2.0f);
3674 const Vec2 p = Vec2((float)renderInfo.getViewportSize().x(), (float)renderInfo.getViewportSize().y()) / Vec2(2.0f);
3675 const IVec2 posAI (deRoundFloatToInt32(origin.x() + (p.x() * posA.x())),
3676 deRoundFloatToInt32(origin.y() + (p.y() * posA.y())));
3677 const IVec2 posBI (deRoundFloatToInt32(origin.x() + (p.x() * posB.x())),
3678 deRoundFloatToInt32(origin.y() + (p.y() * posB.y())));
3680 DE_ASSERT(posAI.x() < posBI.x());
3681 DE_ASSERT(posAI.y() < posBI.y());
3683 if (subpass.getInputAttachments().empty())
3685 for (size_t attachmentRefNdx = drawStartNdx; attachmentRefNdx < subpass.getColorAttachments().size(); attachmentRefNdx++)
3687 const deUint32 attachmentIndex = subpass.getColorAttachments()[attachmentRefNdx].getAttachment();
3689 if (attachmentIndex == VK_ATTACHMENT_UNUSED)
3692 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3693 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3694 const tcu::BVec4 channelMask = tcu::getTextureFormatChannelMask(format);
3695 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3697 for (int y = posAI.y(); y < (int)posBI.y(); y++)
3698 for (int x = posAI.x(); x < (int)posBI.x(); x++)
3700 for (int compNdx = 0; compNdx < 4; compNdx++)
3702 const size_t index = subpassNdx + attachmentIndex + compNdx;
3703 const BoolOp op = boolOpFromIndex(index);
3704 const bool boolX = x % 2 == (int)(index % 2);
3705 const bool boolY = y % 2 == (int)((index / 2) % 2);
3707 if (channelMask[compNdx])
3708 reference[x + y * targetSize.x()].setValue(compNdx, performBoolOp(op, boolX, boolY));
3713 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED)
3715 const deUint32 attachmentIndex = subpass.getDepthStencilAttachment().getAttachment();
3716 const VkImageLayout layout = subpass.getDepthStencilAttachment().getImageLayout();
3717 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3718 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3719 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3721 for (int y = posAI.y(); y < (int)posBI.y(); y++)
3722 for (int x = posAI.x(); x < (int)posBI.x(); x++)
3724 if (tcu::hasDepthComponent(format.order)
3725 && layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
3726 && layout != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
3728 const size_t index = subpassNdx + 1;
3729 const BoolOp op = boolOpFromIndex(index);
3730 const bool boolX = x % 2 == (int)(index % 2);
3731 const bool boolY = y % 2 == (int)((index / 2) % 2);
3733 reference[x + y * targetSize.x()].setValue(0, performBoolOp(op, boolX, boolY));
3736 if (tcu::hasStencilComponent(format.order)
3737 && layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
3738 && layout != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL)
3740 const size_t index = subpassNdx;
3741 reference[x + y * targetSize.x()].setValue(1, (index % 2) == 0);
3748 size_t outputComponentCount = 0;
3749 vector<Maybe<bool> > inputs;
3751 DE_ASSERT(posAI.x() < posBI.x());
3752 DE_ASSERT(posAI.y() < posBI.y());
3754 for (size_t attachmentRefNdx = 0; attachmentRefNdx < subpass.getColorAttachments().size(); attachmentRefNdx++)
3756 const deUint32 attachmentIndex = subpass.getColorAttachments()[attachmentRefNdx].getAttachment();
3757 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3758 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3759 const int componentCount = tcu::getNumUsedChannels(format.order);
3761 outputComponentCount += (size_t)componentCount;
3764 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED
3765 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
3766 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
3768 const Attachment& attachment (renderPassInfo.getAttachments()[subpass.getDepthStencilAttachment().getAttachment()]);
3769 const tcu::TextureFormat format (mapVkFormat(attachment.getFormat()));
3771 if (tcu::hasDepthComponent(format.order))
3772 outputComponentCount++;
3775 if (outputComponentCount > 0)
3777 for (int y = posAI.y(); y < (int)posBI.y(); y++)
3778 for (int x = posAI.x(); x < (int)posBI.x(); x++)
3780 for (size_t inputAttachmentNdx = 0; inputAttachmentNdx < subpass.getInputAttachments().size(); inputAttachmentNdx++)
3782 const deUint32 attachmentIndex = subpass.getInputAttachments()[inputAttachmentNdx].getAttachment();
3783 const VkImageLayout layout = subpass.getInputAttachments()[inputAttachmentNdx].getImageLayout();
3784 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3785 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3786 const int componentCount = tcu::getNumUsedChannels(format.order);
3788 for (int compNdx = 0; compNdx < componentCount; compNdx++)
3790 if ((compNdx != 0 || layout != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL)
3791 && (compNdx != 1 || layout != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL))
3793 inputs.push_back(referenceAttachments[attachmentIndex][x + y * targetSize.x()].getValue(compNdx));
3798 const size_t inputsPerOutput = inputs.size() >= outputComponentCount
3799 ? ((inputs.size() / outputComponentCount)
3800 + ((inputs.size() % outputComponentCount) != 0 ? 1 : 0))
3803 size_t outputValueNdx = 0;
3805 for (size_t attachmentRefNdx = 0; attachmentRefNdx < subpass.getColorAttachments().size(); attachmentRefNdx++)
3807 const deUint32 attachmentIndex = subpass.getColorAttachments()[attachmentRefNdx].getAttachment();
3808 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3809 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3810 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3811 const int componentCount = tcu::getNumUsedChannels(format.order);
3813 for (int compNdx = 0; compNdx < componentCount; compNdx++)
3815 const size_t index = subpassNdx + attachmentIndex + outputValueNdx;
3816 const BoolOp op = boolOpFromIndex(index);
3817 const bool boolX = x % 2 == (int)(index % 2);
3818 const bool boolY = y % 2 == (int)((index / 2) % 2);
3819 Maybe<bool> output = tcu::just(performBoolOp(op, boolX, boolY));
3821 for (size_t i = 0; i < inputsPerOutput; i++)
3825 else if (!inputs[((outputValueNdx + compNdx) * inputsPerOutput + i) % inputs.size()])
3826 output = tcu::Nothing;
3828 output = (*output) == (*inputs[((outputValueNdx + compNdx) * inputsPerOutput + i) % inputs.size()]);
3832 reference[x + y * targetSize.x()].setValue(compNdx, *output);
3834 reference[x + y * targetSize.x()].setUndefined(compNdx);
3837 outputValueNdx += componentCount;
3840 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED
3841 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
3842 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
3844 const deUint32 attachmentIndex = subpass.getDepthStencilAttachment().getAttachment();
3845 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3846 const size_t index = subpassNdx + attachmentIndex;
3847 const BoolOp op = boolOpFromIndex(index);
3848 const bool boolX = x % 2 == (int)(index % 2);
3849 const bool boolY = y % 2 == (int)((index / 2) % 2);
3850 Maybe<bool> output = tcu::just(performBoolOp(op, boolX, boolY));
3852 for (size_t i = 0; i < inputsPerOutput; i++)
3856 else if (inputs[(outputValueNdx * inputsPerOutput + i) % inputs.size()])
3857 output = (*output) == (*inputs[(outputValueNdx * inputsPerOutput + i) % inputs.size()]);
3859 output = tcu::Nothing;
3863 reference[x + y * targetSize.x()].setValue(0, *output);
3865 reference[x + y * targetSize.x()].setUndefined(0);
3872 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED
3873 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
3874 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL)
3876 const deUint32 attachmentIndex = subpass.getDepthStencilAttachment().getAttachment();
3877 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3878 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3879 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3881 if (tcu::hasStencilComponent(format.order))
3883 for (int y = posAI.y(); y < (int)posBI.y(); y++)
3884 for (int x = posAI.x(); x < (int)posBI.x(); x++)
3886 const size_t index = subpassNdx;
3887 reference[x + y * targetSize.x()].setValue(1, (index % 2) == 0);
3895 // Mark all attachments that were used but not stored as undefined
3896 for (size_t attachmentIndex = 0; attachmentIndex < renderPassInfo.getAttachments().size(); attachmentIndex++)
3898 const Attachment attachment = renderPassInfo.getAttachments()[attachmentIndex];
3899 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3900 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3901 const bool isStencilAttachment = hasStencilComponent(format.order);
3902 const bool isDepthOrStencilAttachment = hasDepthComponent(format.order) || isStencilAttachment;
3904 if (attachmentUsed[attachmentIndex] && renderPassInfo.getAttachments()[attachmentIndex].getStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE)
3906 if (isDepthOrStencilAttachment)
3907 markUndefined(reference, BVec4(true, false, false, false), targetSize, renderPos, renderSize);
3909 markUndefined(reference, BVec4(true), targetSize, renderPos, renderSize);
3912 if (attachmentUsed[attachmentIndex] && isStencilAttachment && renderPassInfo.getAttachments()[attachmentIndex].getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE)
3913 markUndefined(reference, BVec4(false, true, false, false), targetSize, renderPos, renderSize);
3917 void renderReferenceImagesFromValues (vector<tcu::TextureLevel>& referenceImages,
3918 const vector<vector<PixelValue> >& referenceValues,
3919 const UVec2& targetSize,
3920 const RenderPass& renderPassInfo,
3921 const DepthValuesArray& depthValues)
3923 referenceImages.resize(referenceValues.size());
3925 for (size_t attachmentNdx = 0; attachmentNdx < renderPassInfo.getAttachments().size(); attachmentNdx++)
3927 const Attachment attachment = renderPassInfo.getAttachments()[attachmentNdx];
3928 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3929 const vector<PixelValue>& reference = referenceValues[attachmentNdx];
3930 const bool hasDepth = tcu::hasDepthComponent(format.order);
3931 const bool hasStencil = tcu::hasStencilComponent(format.order);
3932 const bool hasDepthOrStencil = hasDepth || hasStencil;
3933 tcu::TextureLevel& referenceImage = referenceImages[attachmentNdx];
3935 referenceImage.setStorage(format, targetSize.x(), targetSize.y());
3937 if (hasDepthOrStencil)
3941 const PixelBufferAccess depthAccess (tcu::getEffectiveDepthStencilAccess(referenceImage.getAccess(), tcu::Sampler::MODE_DEPTH));
3943 for (deUint32 y = 0; y < targetSize.y(); y++)
3944 for (deUint32 x = 0; x < targetSize.x(); x++)
3946 if (reference[x + y * targetSize.x()].getValue(0))
3948 if (*reference[x + y * targetSize.x()].getValue(0))
3949 depthAccess.setPixDepth(float(depthValues[1]) / 255.0f, x, y);
3951 depthAccess.setPixDepth(float(depthValues[0]) / 255.0f, x, y);
3953 else // Fill with 3x3 grid
3954 depthAccess.setPixDepth(((x / 3) % 2) == ((y / 3) % 2) ? 0.33f : 0.66f, x, y);
3960 const PixelBufferAccess stencilAccess (tcu::getEffectiveDepthStencilAccess(referenceImage.getAccess(), tcu::Sampler::MODE_STENCIL));
3962 for (deUint32 y = 0; y < targetSize.y(); y++)
3963 for (deUint32 x = 0; x < targetSize.x(); x++)
3965 if (reference[x + y * targetSize.x()].getValue(1))
3967 if (*reference[x + y * targetSize.x()].getValue(1))
3968 stencilAccess.setPixStencil(0xFFu, x, y);
3970 stencilAccess.setPixStencil(0x0u, x, y);
3972 else // Fill with 3x3 grid
3973 stencilAccess.setPixStencil(((x / 3) % 2) == ((y / 3) % 2) ? 85 : 170, x, y);
3979 for (deUint32 y = 0; y < targetSize.y(); y++)
3980 for (deUint32 x = 0; x < targetSize.x(); x++)
3984 for (int compNdx = 0; compNdx < 4; compNdx++)
3986 if (reference[x + y * targetSize.x()].getValue(compNdx))
3988 if (*reference[x + y * targetSize.x()].getValue(compNdx))
3989 color[compNdx] = 1.0f;
3991 color[compNdx] = 0.0f;
3993 else // Fill with 3x3 grid
3994 color[compNdx] = ((compNdx + (x / 3)) % 2) == ((y / 3) % 2) ? 0.33f : 0.66f;
3997 referenceImage.getAccess().setPixel(color, x, y);
4003 bool verifyColorAttachment (const vector<PixelValue>& reference,
4004 const ConstPixelBufferAccess& result,
4005 const PixelBufferAccess& errorImage,
4006 const deBool useFormatCompCount)
4008 const Vec4 red (1.0f, 0.0f, 0.0f, 1.0f);
4009 const Vec4 green (0.0f, 1.0f, 0.0f, 1.0f);
4012 DE_ASSERT(result.getWidth() * result.getHeight() == (int)reference.size());
4013 DE_ASSERT(result.getWidth() == errorImage.getWidth());
4014 DE_ASSERT(result.getHeight() == errorImage.getHeight());
4016 for (int y = 0; y < result.getHeight(); y++)
4017 for (int x = 0; x < result.getWidth(); x++)
4019 const Vec4 resultColor = result.getPixel(x, y);
4020 const PixelValue& referenceValue = reference[x + y * result.getWidth()];
4021 bool pixelOk = true;
4022 const deUint32 componentCount = useFormatCompCount ? (deUint32)tcu::getNumUsedChannels(result.getFormat().order) : 4;
4024 for (deUint32 compNdx = 0; compNdx < componentCount; compNdx++)
4026 const Maybe<bool> maybeValue = referenceValue.getValue(compNdx);
4030 const bool value = *maybeValue;
4032 if ((value && (resultColor[compNdx] != 1.0f))
4033 || (!value && resultColor[compNdx] != 0.0f))
4040 errorImage.setPixel(red, x, y);
4044 errorImage.setPixel(green, x, y);
4050 // Setting the alpha value to 1.0f by default helps visualization when the alpha channel is not used.
4051 const tcu::Vec4 kDefaultColorForLog {0.0f, 0.0f, 0.0f, 1.0f};
4052 const float kTrueComponent = 1.0f;
4053 const float kFalseComponent = 0.5f;
4054 const float kUnsetComponentLow = 0.0f;
4055 const float kUnsetComponentHigh = 0.25f;
4057 std::unique_ptr<tcu::TextureLevel> renderColorImageForLog (const ConstPixelBufferAccess& image, int numChannels)
4059 // Same channel order, but using UNORM_INT8 for the color format.
4060 const auto order = image.getFormat().order;
4061 const tcu::TextureFormat loggableFormat {order, tcu::TextureFormat::UNORM_INT8};
4062 const int width = image.getWidth();
4063 const int height = image.getHeight();
4064 std::unique_ptr<tcu::TextureLevel> result {new tcu::TextureLevel{loggableFormat, width, height}};
4065 auto access = result->getAccess();
4066 tcu::Vec4 outColor = kDefaultColorForLog;
4068 for (int x = 0; x < width; ++x)
4069 for (int y = 0; y < height; ++y)
4071 const auto value = image.getPixel(x, y);
4072 for (int c = 0; c < numChannels; ++c)
4074 if (value[c] == 0.0f)
4075 outColor[c] = kFalseComponent;
4076 else if (value[c] == 1.0f)
4077 outColor[c] = kTrueComponent;
4081 access.setPixel(outColor, x, y);
4087 std::unique_ptr<tcu::TextureLevel> renderColorImageForLog (const vector<PixelValue>& reference, const UVec2& targetSize, int numChannels)
4089 const tcu::TextureFormat loggableFormat {tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8};
4090 const int width = static_cast<int>(targetSize.x());
4091 const int height = static_cast<int>(targetSize.y());
4092 std::unique_ptr<tcu::TextureLevel> result {new tcu::TextureLevel{loggableFormat, width, height}};
4093 auto access = result->getAccess();
4094 tcu::Vec4 outColor = kDefaultColorForLog;
4096 for (int x = 0; x < width; ++x)
4097 for (int y = 0; y < height; ++y)
4099 const int index = x + y * width;
4100 for (int c = 0; c < numChannels; ++c)
4102 const auto maybeValue = reference[index].getValue(c);
4104 outColor[c] = ((*maybeValue) ? kTrueComponent : kFalseComponent);
4106 outColor[c] = ((((x / 3) % 2) == ((y / 3) % 2)) ? kUnsetComponentLow : kUnsetComponentHigh);
4108 access.setPixel(outColor, x, y);
4114 bool verifyDepthAttachment (const vector<PixelValue>& reference,
4115 const ConstPixelBufferAccess& result,
4116 const PixelBufferAccess& errorImage,
4117 const DepthValuesArray& depthValues,
4120 const Vec4 red (1.0f, 0.0f, 0.0f, 1.0f);
4121 const Vec4 green (0.0f, 1.0f, 0.0f, 1.0f);
4124 DE_ASSERT(result.getWidth() * result.getHeight() == (int)reference.size());
4125 DE_ASSERT(result.getWidth() == errorImage.getWidth());
4126 DE_ASSERT(result.getHeight() == errorImage.getHeight());
4128 for (int y = 0; y < result.getHeight(); y++)
4129 for (int x = 0; x < result.getWidth(); x++)
4131 bool pixelOk = true;
4133 const float resultDepth = result.getPixDepth(x, y);
4134 const PixelValue& referenceValue = reference[x + y * result.getWidth()];
4135 const Maybe<bool> maybeValue = referenceValue.getValue(0);
4139 const bool value = *maybeValue;
4141 if ((value && !depthsEqual(resultDepth, float(depthValues[1]) / 255.0f, epsilon))
4142 || (!value && !depthsEqual(resultDepth, float(depthValues[0]) / 255.0f, epsilon)))
4148 errorImage.setPixel(red, x, y);
4152 errorImage.setPixel(green, x, y);
4158 bool verifyStencilAttachment (const vector<PixelValue>& reference,
4159 const ConstPixelBufferAccess& result,
4160 const PixelBufferAccess& errorImage)
4162 const Vec4 red (1.0f, 0.0f, 0.0f, 1.0f);
4163 const Vec4 green (0.0f, 1.0f, 0.0f, 1.0f);
4166 DE_ASSERT(result.getWidth() * result.getHeight() == (int)reference.size());
4167 DE_ASSERT(result.getWidth() == errorImage.getWidth());
4168 DE_ASSERT(result.getHeight() == errorImage.getHeight());
4170 for (int y = 0; y < result.getHeight(); y++)
4171 for (int x = 0; x < result.getWidth(); x++)
4173 bool pixelOk = true;
4175 const deUint32 resultStencil = result.getPixStencil(x, y);
4176 const PixelValue& referenceValue = reference[x + y * result.getWidth()];
4177 const Maybe<bool> maybeValue = referenceValue.getValue(1);
4181 const bool value = *maybeValue;
4183 if ((value && (resultStencil != 0xFFu))
4184 || (!value && resultStencil != 0x0u))
4190 errorImage.setPixel(red, x, y);
4194 errorImage.setPixel(green, x, y);
4200 bool logAndVerifyImages (TestLog& log,
4201 const DeviceInterface& vk,
4203 const vector<de::SharedPtr<AttachmentResources> >& attachmentResources,
4204 const vector<bool>& attachmentIsLazy,
4205 const RenderPass& renderPassInfo,
4206 const vector<Maybe<VkClearValue> >& renderPassClearValues,
4207 const vector<Maybe<VkClearValue> >& imageClearValues,
4208 const vector<SubpassRenderInfo>& subpassRenderInfo,
4209 const UVec2& targetSize,
4210 const TestConfig& config)
4212 vector<vector<PixelValue> > referenceValues;
4213 vector<tcu::TextureLevel> referenceAttachments;
4216 log << TestLog::Message << "Reference images fill undefined pixels with 3x3 grid pattern." << TestLog::EndMessage;
4218 renderReferenceValues(referenceValues, renderPassInfo, targetSize, imageClearValues, renderPassClearValues, subpassRenderInfo, config.renderPos, config.renderSize, config.drawStartNdx, config.depthValues);
4219 renderReferenceImagesFromValues(referenceAttachments, referenceValues, targetSize, renderPassInfo, config.depthValues);
4221 for (size_t attachmentNdx = 0; attachmentNdx < renderPassInfo.getAttachments().size(); attachmentNdx++)
4223 if (!attachmentIsLazy[attachmentNdx])
4225 bool attachmentOK = true;
4226 const Attachment attachment = renderPassInfo.getAttachments()[attachmentNdx];
4227 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
4229 if (tcu::hasDepthComponent(format.order) && tcu::hasStencilComponent(format.order))
4231 const tcu::TextureFormat depthFormat = getDepthCopyFormat(attachment.getFormat());
4232 void* const depthPtr = attachmentResources[attachmentNdx]->getResultMemory().getHostPtr();
4234 const tcu::TextureFormat stencilFormat = getStencilCopyFormat(attachment.getFormat());
4235 void* const stencilPtr = attachmentResources[attachmentNdx]->getSecondaryResultMemory().getHostPtr();
4237 invalidateAlloc(vk, device, attachmentResources[attachmentNdx]->getResultMemory());
4238 invalidateAlloc(vk, device, attachmentResources[attachmentNdx]->getSecondaryResultMemory());
4241 bool depthOK = true;
4242 bool stencilOK = true;
4243 const ConstPixelBufferAccess depthAccess (depthFormat, targetSize.x(), targetSize.y(), 1, depthPtr);
4244 const ConstPixelBufferAccess stencilAccess (stencilFormat, targetSize.x(), targetSize.y(), 1, stencilPtr);
4245 tcu::TextureLevel depthErrorImage (tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), targetSize.x(), targetSize.y());
4246 tcu::TextureLevel stencilErrorImage (tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), targetSize.x(), targetSize.y());
4248 if (renderPassInfo.getAttachments()[attachmentNdx].getStoreOp() == VK_ATTACHMENT_STORE_OP_STORE
4249 && !verifyDepthAttachment(referenceValues[attachmentNdx], depthAccess, depthErrorImage.getAccess(), config.depthValues, requiredDepthEpsilon(attachment.getFormat())))
4254 if (renderPassInfo.getAttachments()[attachmentNdx].getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_STORE
4255 && !verifyStencilAttachment(referenceValues[attachmentNdx], stencilAccess, stencilErrorImage.getAccess()))
4260 if (!depthOK || !stencilOK)
4262 const auto attachmentNdxStr = de::toString(attachmentNdx);
4265 log << TestLog::ImageSet("OutputAttachments" + attachmentNdxStr, "Output depth and stencil attachments " + attachmentNdxStr);
4266 log << TestLog::Image("Attachment" + attachmentNdxStr + "Depth", "Attachment " + attachmentNdxStr + " Depth", depthAccess);
4267 log << TestLog::Image("Attachment" + attachmentNdxStr + "Stencil", "Attachment " + attachmentNdxStr + " Stencil", stencilAccess);
4268 log << TestLog::EndImageSet;
4270 // Reference images. These will be logged as image sets due to having depth and stencil aspects.
4271 log << TestLog::Image("AttachmentReferences" + attachmentNdxStr, "Reference images " + attachmentNdxStr, referenceAttachments[attachmentNdx].getAccess());
4274 log << TestLog::ImageSet("ErrorMasks" + attachmentNdxStr, "Error masks " + attachmentNdxStr);
4276 log << TestLog::Image("DepthAttachmentError" + attachmentNdxStr, "Depth Attachment Error " + attachmentNdxStr, depthErrorImage.getAccess());
4278 log << TestLog::Image("StencilAttachmentError" + attachmentNdxStr, "Stencil Attachment Error " + attachmentNdxStr, stencilErrorImage.getAccess());
4279 log << TestLog::EndImageSet;
4281 attachmentOK = false;
4287 void* const ptr = attachmentResources[attachmentNdx]->getResultMemory().getHostPtr();
4289 invalidateAlloc(vk, device, attachmentResources[attachmentNdx]->getResultMemory());
4291 bool depthOK = true;
4292 bool stencilOK = true;
4293 bool colorOK = true;
4294 const ConstPixelBufferAccess access (format, targetSize.x(), targetSize.y(), 1, ptr);
4295 tcu::TextureLevel errorImage (tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), targetSize.x(), targetSize.y());
4297 if (tcu::hasDepthComponent(format.order))
4299 if ((renderPassInfo.getAttachments()[attachmentNdx].getStoreOp() == VK_ATTACHMENT_STORE_OP_STORE || renderPassInfo.getAttachments()[attachmentNdx].getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_STORE)
4300 && !verifyDepthAttachment(referenceValues[attachmentNdx], access, errorImage.getAccess(), config.depthValues, requiredDepthEpsilon(attachment.getFormat())))
4305 else if (tcu::hasStencilComponent(format.order))
4307 if ((renderPassInfo.getAttachments()[attachmentNdx].getStoreOp() == VK_ATTACHMENT_STORE_OP_STORE || renderPassInfo.getAttachments()[attachmentNdx].getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_STORE)
4308 && !verifyStencilAttachment(referenceValues[attachmentNdx], access, errorImage.getAccess()))
4315 if ((renderPassInfo.getAttachments()[attachmentNdx].getStoreOp() == VK_ATTACHMENT_STORE_OP_STORE || renderPassInfo.getAttachments()[attachmentNdx].getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_STORE)
4316 && !verifyColorAttachment(referenceValues[attachmentNdx], access, errorImage.getAccess(), config.useFormatCompCount))
4322 if (!depthOK || !stencilOK || !colorOK)
4324 log << TestLog::ImageSet("TestImages", "Output attachment, reference image and error mask");
4325 if (!depthOK || !stencilOK)
4327 // Log without conversions.
4328 log << TestLog::Image("Attachment" + de::toString(attachmentNdx), "Attachment " + de::toString(attachmentNdx), access);
4329 log << TestLog::Image("AttachmentReference" + de::toString(attachmentNdx), "Attachment reference " + de::toString(attachmentNdx), referenceAttachments[attachmentNdx].getAccess());
4333 // Convert color images to better reflect test status and output in any format.
4334 const auto numChannels = tcu::getNumUsedChannels(access.getFormat().order);
4335 const auto attachmentForLog = renderColorImageForLog(access, numChannels);
4336 const auto referenceForLog = renderColorImageForLog(referenceValues[attachmentNdx], targetSize, numChannels);
4338 log << TestLog::Message << "Check the attachment formats and test data to verify which components affect the test result." << TestLog::EndMessage;
4339 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;
4340 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;
4342 log << TestLog::Image("Attachment" + de::toString(attachmentNdx), "Attachment " + de::toString(attachmentNdx), attachmentForLog->getAccess());
4343 log << TestLog::Image("AttachmentReference" + de::toString(attachmentNdx), "Attachment reference " + de::toString(attachmentNdx), referenceForLog->getAccess());
4345 log << TestLog::Image("AttachmentError" + de::toString(attachmentNdx), "Attachment Error " + de::toString(attachmentNdx), errorImage.getAccess());
4346 log << TestLog::EndImageSet;
4348 attachmentOK = false;
4360 std::string getInputAttachmentType (VkFormat vkFormat)
4362 const tcu::TextureFormat format = mapVkFormat(vkFormat);
4363 const tcu::TextureChannelClass channelClass = tcu::getTextureChannelClass(format.type);
4365 switch (channelClass)
4367 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
4368 return "isubpassInput";
4370 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
4371 return "usubpassInput";
4373 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
4374 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
4375 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
4376 return "subpassInput";
4379 DE_FATAL("Unknown channel class");
4384 std::string getAttachmentType (VkFormat vkFormat, deBool useFormatCompCount)
4386 const tcu::TextureFormat format = mapVkFormat(vkFormat);
4387 const tcu::TextureChannelClass channelClass = tcu::getTextureChannelClass(format.type);
4388 const size_t componentCount = (size_t)tcu::getNumUsedChannels(format.order);
4390 switch (channelClass)
4392 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
4393 if (useFormatCompCount)
4394 return (componentCount == 1 ? "int" : "ivec" + de::toString(componentCount));
4398 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
4399 if (useFormatCompCount)
4400 return (componentCount == 1 ? "uint" : "uvec" + de::toString(componentCount));
4404 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
4405 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
4406 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
4407 if (useFormatCompCount)
4408 return (componentCount == 1 ? "float" : "vec" + de::toString(componentCount));
4413 DE_FATAL("Unknown channel class");
4418 void createTestShaders (SourceCollections& dst, TestConfig config)
4420 if (config.renderTypes & TestConfig::RENDERTYPES_DRAW)
4422 const vector<Subpass>& subpasses = config.renderPass.getSubpasses();
4424 for (size_t subpassNdx = 0; subpassNdx < subpasses.size(); subpassNdx++)
4426 const Subpass& subpass = subpasses[subpassNdx];
4427 deUint32 inputAttachmentBinding = 0;
4428 std::ostringstream vertexShader;
4429 std::ostringstream fragmentShader;
4431 vertexShader << "#version 310 es\n"
4432 << "layout(location = 0) in highp vec2 a_position;\n"
4433 << "void main (void) {\n"
4434 << "\tgl_Position = vec4(a_position, 1.0, 1.0);\n"
4437 fragmentShader << "#version 310 es\n"
4438 << "precision highp float;\n";
4440 bool hasAnyDepthFormats = false;
4442 for (size_t attachmentNdx = config.drawStartNdx; attachmentNdx < subpass.getInputAttachments().size(); attachmentNdx++)
4444 const deUint32 attachmentIndex = subpass.getInputAttachments()[attachmentNdx].getAttachment();
4445 const VkImageLayout layout = subpass.getInputAttachments()[attachmentNdx].getImageLayout();
4446 const Attachment attachment = config.renderPass.getAttachments()[attachmentIndex];
4447 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
4448 const bool isDepthFormat = tcu::hasDepthComponent(format.order);
4449 const bool isStencilFormat = tcu::hasStencilComponent(format.order);
4451 if (isDepthFormat || isStencilFormat)
4453 if (isDepthFormat && layout != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL)
4455 hasAnyDepthFormats = true;
4456 fragmentShader << "layout(input_attachment_index = " << attachmentNdx << ", set=0, binding=" << inputAttachmentBinding << ") uniform highp subpassInput i_depth" << attachmentNdx << ";\n";
4457 inputAttachmentBinding++;
4460 if (isStencilFormat && layout != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
4462 fragmentShader << "layout(input_attachment_index = " << attachmentNdx << ", set=0, binding=" << inputAttachmentBinding << ") uniform highp usubpassInput i_stencil" << attachmentNdx << ";\n";
4463 inputAttachmentBinding++;
4468 const std::string attachmentType = getInputAttachmentType(attachment.getFormat());
4470 fragmentShader << "layout(input_attachment_index = " << attachmentNdx << ", set=0, binding=" << inputAttachmentBinding << ") uniform highp " << attachmentType << " i_color" << attachmentNdx << ";\n";
4471 inputAttachmentBinding++;
4475 for (size_t attachmentNdx = config.drawStartNdx; attachmentNdx < subpass.getColorAttachments().size(); attachmentNdx++)
4477 const std::string attachmentType = getAttachmentType(config.renderPass.getAttachments()[getAttachmentNdx(subpass.getColorAttachments(), attachmentNdx)].getFormat(), config.useFormatCompCount);
4478 fragmentShader << "layout(location = " << attachmentNdx << ") out highp " << attachmentType << " o_color" << attachmentNdx << ";\n";
4481 if (hasAnyDepthFormats)
4482 fragmentShader << "\nbool depthsEqual(float a, float b, float epsilon) {\n"
4483 << "\treturn abs(a - b) <= epsilon;\n}\n\n";
4485 fragmentShader << "void main (void) {\n";
4487 if (subpass.getInputAttachments().empty())
4489 for (size_t attachmentNdx = config.drawStartNdx; attachmentNdx < subpass.getColorAttachments().size(); attachmentNdx++)
4491 const deUint32 attachmentIndex = subpass.getColorAttachments()[attachmentNdx].getAttachment();
4493 if (attachmentIndex == VK_ATTACHMENT_UNUSED)
4496 const Attachment attachment = config.renderPass.getAttachments()[attachmentIndex];
4497 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
4498 const size_t componentCount = config.useFormatCompCount ? (size_t)tcu::getNumUsedChannels(format.order) : 4;
4499 const std::string attachmentType = getAttachmentType(attachment.getFormat(), config.useFormatCompCount);
4501 fragmentShader << "\to_color" << attachmentNdx << " = " << attachmentType << "(" << attachmentType + "(";
4503 for (size_t compNdx = 0; compNdx < componentCount; compNdx++)
4505 const size_t index = subpassNdx + attachmentIndex + compNdx;
4506 const BoolOp op = boolOpFromIndex(index);
4509 fragmentShader << ",\n\t\t";
4511 fragmentShader << "((int(gl_FragCoord.x) % 2 == " << (index % 2)
4512 << ") " << boolOpToString(op) << " ("
4513 << "int(gl_FragCoord.y) % 2 == " << ((index / 2) % 2)
4514 << ") ? 1.0 : 0.0)";
4517 fragmentShader << "));\n";
4520 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED
4521 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
4522 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
4524 const size_t index = subpassNdx + 1;
4525 const BoolOp op = boolOpFromIndex(index);
4527 fragmentShader << "\tgl_FragDepth = ((int(gl_FragCoord.x) % 2 == " << (index % 2)
4528 << ") " << boolOpToString(op) << " ("
4529 << "int(gl_FragCoord.y) % 2 == " << ((index / 2) % 2)
4530 << ") ? " << deUint32(config.depthValues[1]) << ".0f/255.0f : " << deUint32(config.depthValues[0]) << ".0f/255.0f);\n";
4535 size_t inputComponentCount = 0;
4536 size_t outputComponentCount = 0;
4538 for (size_t attachmentNdx = config.drawStartNdx; attachmentNdx < subpass.getInputAttachments().size(); attachmentNdx++)
4540 const deUint32 attachmentIndex = subpass.getInputAttachments()[attachmentNdx].getAttachment();
4541 const VkImageLayout layout = subpass.getInputAttachments()[attachmentNdx].getImageLayout();
4542 const Attachment attachment = config.renderPass.getAttachments()[attachmentIndex];
4543 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
4544 const size_t componentCount = (size_t)tcu::getNumUsedChannels(format.order);
4546 if (layout == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
4547 inputComponentCount += 1;
4548 else if (layout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL)
4549 inputComponentCount += 1;
4551 inputComponentCount += componentCount;
4554 for (size_t attachmentNdx = config.drawStartNdx; attachmentNdx < subpass.getColorAttachments().size(); attachmentNdx++)
4556 const deUint32 attachmentIndex = subpass.getColorAttachments()[attachmentNdx].getAttachment();
4557 const Attachment attachment = config.renderPass.getAttachments()[attachmentIndex];
4558 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
4559 const size_t componentCount = (size_t)tcu::getNumUsedChannels(format.order);
4561 outputComponentCount += componentCount;
4564 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED
4565 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
4566 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
4568 outputComponentCount++;
4571 if (outputComponentCount > 0)
4573 const size_t inputsPerOutput = inputComponentCount >= outputComponentCount
4574 ? ((inputComponentCount / outputComponentCount)
4575 + ((inputComponentCount % outputComponentCount) != 0 ? 1 : 0))
4578 fragmentShader << "\tbool inputs[" << inputComponentCount << "];\n";
4580 if (outputComponentCount > 0)
4581 fragmentShader << "\tbool outputs[" << outputComponentCount << "];\n";
4583 size_t inputValueNdx = 0;
4585 for (size_t attachmentNdx = config.drawStartNdx; attachmentNdx < subpass.getInputAttachments().size(); attachmentNdx++)
4587 const char* const components[] =
4591 const deUint32 attachmentIndex = subpass.getInputAttachments()[attachmentNdx].getAttachment();
4592 const VkImageLayout layout = subpass.getInputAttachments()[attachmentNdx].getImageLayout();
4593 const Attachment attachment = config.renderPass.getAttachments()[attachmentIndex];
4594 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
4595 const size_t componentCount = (size_t)tcu::getNumUsedChannels(format.order);
4596 const bool isDepthFormat = tcu::hasDepthComponent(format.order);
4597 const bool isStencilFormat = tcu::hasStencilComponent(format.order);
4599 if (isDepthFormat || isStencilFormat)
4601 if (isDepthFormat && layout != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL)
4603 fragmentShader << "\tinputs[" << inputValueNdx << "] = depthsEqual(" << deUint32(config.depthValues[1]) <<
4604 ".0f/255.0f, float(subpassLoad(i_depth" << attachmentNdx << ").x), " <<
4605 std::fixed << std::setprecision(12) << requiredDepthEpsilon(attachment.getFormat()) << ");\n";
4609 if (isStencilFormat && layout != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
4611 fragmentShader << "\tinputs[" << inputValueNdx << "] = 255u == subpassLoad(i_stencil" << attachmentNdx << ").x;\n";
4617 for (size_t compNdx = 0; compNdx < componentCount; compNdx++)
4619 fragmentShader << "\tinputs[" << inputValueNdx << "] = 1.0 == float(subpassLoad(i_color" << attachmentNdx << ")." << components[compNdx] << ");\n";
4625 size_t outputValueNdx = 0;
4627 for (size_t attachmentNdx = config.drawStartNdx; attachmentNdx < subpass.getColorAttachments().size(); attachmentNdx++)
4629 const deUint32 attachmentIndex = subpass.getColorAttachments()[attachmentNdx].getAttachment();
4630 const Attachment attachment = config.renderPass.getAttachments()[attachmentIndex];
4631 const std::string attachmentType = getAttachmentType(config.renderPass.getAttachments()[attachmentIndex].getFormat(), config.useFormatCompCount);
4632 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
4633 const size_t componentCount = (size_t)tcu::getNumUsedChannels(format.order);
4635 for (size_t compNdx = 0; compNdx < componentCount; compNdx++)
4637 const size_t index = subpassNdx + attachmentIndex + outputValueNdx;
4638 const BoolOp op = boolOpFromIndex(index);
4640 fragmentShader << "\toutputs[" << outputValueNdx + compNdx << "] = "
4641 << "(int(gl_FragCoord.x) % 2 == " << (index % 2)
4642 << ") " << boolOpToString(op) << " ("
4643 << "int(gl_FragCoord.y) % 2 == " << ((index / 2) % 2)
4646 for (size_t i = 0; i < inputsPerOutput; i++)
4647 fragmentShader << "\toutputs[" << outputValueNdx + compNdx << "] = outputs[" << outputValueNdx + compNdx << "] == inputs[" << ((outputValueNdx + compNdx) * inputsPerOutput + i) % inputComponentCount << "];\n";
4650 fragmentShader << "\to_color" << attachmentNdx << " = " << attachmentType << "(";
4652 for (size_t compNdx = 0; compNdx < (config.useFormatCompCount ? componentCount : 4); compNdx++)
4655 fragmentShader << ", ";
4657 if (compNdx < componentCount)
4658 fragmentShader << "outputs[" << outputValueNdx + compNdx << "]";
4660 fragmentShader << "0";
4663 outputValueNdx += componentCount;
4665 fragmentShader << ");\n";
4668 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED
4669 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
4670 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
4672 const deUint32 attachmentIndex = subpass.getDepthStencilAttachment().getAttachment();
4673 const size_t index = subpassNdx + attachmentIndex;
4674 const BoolOp op = boolOpFromIndex(index);
4676 fragmentShader << "\toutputs[" << outputValueNdx << "] = "
4677 << "(int(gl_FragCoord.x) % 2 == " << (index % 2)
4678 << ") " << boolOpToString(op) << " ("
4679 << "int(gl_FragCoord.y) % 2 == " << ((index / 2) % 2)
4682 for (size_t i = 0; i < inputsPerOutput; i++)
4683 fragmentShader << "\toutputs[" << outputValueNdx << "] = outputs[" << outputValueNdx << "] == inputs[" << (outputValueNdx * inputsPerOutput + i) % inputComponentCount << "];\n";
4685 fragmentShader << "\tgl_FragDepth = outputs[" << outputValueNdx << "] ? " << deUint32(config.depthValues[1]) << ".0f/255.0f : " << deUint32(config.depthValues[0]) << ".0f/255.0f;\n";
4690 fragmentShader << "}\n";
4692 dst.glslSources.add(de::toString(subpassNdx) + "-vert") << glu::VertexSource(vertexShader.str());
4693 dst.glslSources.add(de::toString(subpassNdx) + "-frag") << glu::FragmentSource(fragmentShader.str());
4698 void initializeAttachmentIsLazy (vector<bool>& attachmentIsLazy, const vector<Attachment>& attachments, TestConfig::ImageMemory imageMemory)
4700 bool lastAttachmentWasLazy = false;
4702 for (size_t attachmentNdx = 0; attachmentNdx < attachments.size(); attachmentNdx++)
4704 if (attachments[attachmentNdx].getLoadOp() != VK_ATTACHMENT_LOAD_OP_LOAD
4705 && attachments[attachmentNdx].getStoreOp() != VK_ATTACHMENT_STORE_OP_STORE
4706 && attachments[attachmentNdx].getStencilLoadOp() != VK_ATTACHMENT_LOAD_OP_LOAD
4707 && attachments[attachmentNdx].getStencilStoreOp() != VK_ATTACHMENT_STORE_OP_STORE)
4709 if (imageMemory == TestConfig::IMAGEMEMORY_LAZY || (imageMemory & TestConfig::IMAGEMEMORY_LAZY && !lastAttachmentWasLazy))
4711 attachmentIsLazy.push_back(true);
4713 lastAttachmentWasLazy = true;
4715 else if (imageMemory & TestConfig::IMAGEMEMORY_STRICT)
4717 attachmentIsLazy.push_back(false);
4718 lastAttachmentWasLazy = false;
4721 DE_FATAL("Unknown imageMemory");
4724 attachmentIsLazy.push_back(false);
4728 enum AttachmentRefType
4730 ATTACHMENTREFTYPE_COLOR,
4731 ATTACHMENTREFTYPE_DEPTH_STENCIL,
4732 ATTACHMENTREFTYPE_INPUT,
4733 ATTACHMENTREFTYPE_RESOLVE,
4736 VkImageUsageFlags getImageUsageFromLayout (VkImageLayout layout)
4740 case VK_IMAGE_LAYOUT_GENERAL:
4741 case VK_IMAGE_LAYOUT_PREINITIALIZED:
4744 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
4745 return VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
4747 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
4748 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
4749 return VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
4751 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
4752 return VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
4754 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL:
4755 return VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
4757 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL:
4758 return VK_IMAGE_USAGE_TRANSFER_DST_BIT;
4761 DE_FATAL("Unexpected image layout");
4766 void getImageUsageFromAttachmentReferences(vector<VkImageUsageFlags>& attachmentImageUsage, AttachmentRefType refType, size_t count, const AttachmentReference* references)
4768 for (size_t referenceNdx = 0; referenceNdx < count; ++referenceNdx)
4770 const deUint32 attachment = references[referenceNdx].getAttachment();
4772 if (attachment != VK_ATTACHMENT_UNUSED)
4774 VkImageUsageFlags usage;
4778 case ATTACHMENTREFTYPE_COLOR:
4779 case ATTACHMENTREFTYPE_RESOLVE:
4780 usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
4783 case ATTACHMENTREFTYPE_DEPTH_STENCIL:
4784 usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
4787 case ATTACHMENTREFTYPE_INPUT:
4788 usage = VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
4792 DE_FATAL("Unexpected attachment reference type");
4797 attachmentImageUsage[attachment] |= usage;
4802 void getImageUsageFromAttachmentReferences(vector<VkImageUsageFlags>& attachmentImageUsage, AttachmentRefType refType, const vector<AttachmentReference>& references)
4804 if (!references.empty())
4806 getImageUsageFromAttachmentReferences(attachmentImageUsage, refType, references.size(), &references[0]);
4810 void initializeAttachmentImageUsage (Context &context, vector<VkImageUsageFlags>& attachmentImageUsage, const RenderPass& renderPassInfo, const vector<bool>& attachmentIsLazy, const vector<Maybe<VkClearValue> >& clearValues)
4812 attachmentImageUsage.resize(renderPassInfo.getAttachments().size(), VkImageUsageFlags(0));
4814 for (size_t subpassNdx = 0; subpassNdx < renderPassInfo.getSubpasses().size(); ++subpassNdx)
4816 const Subpass& subpass = renderPassInfo.getSubpasses()[subpassNdx];
4818 getImageUsageFromAttachmentReferences(attachmentImageUsage, ATTACHMENTREFTYPE_COLOR, subpass.getColorAttachments());
4819 getImageUsageFromAttachmentReferences(attachmentImageUsage, ATTACHMENTREFTYPE_DEPTH_STENCIL, 1, &subpass.getDepthStencilAttachment());
4820 getImageUsageFromAttachmentReferences(attachmentImageUsage, ATTACHMENTREFTYPE_INPUT, subpass.getInputAttachments());
4821 getImageUsageFromAttachmentReferences(attachmentImageUsage, ATTACHMENTREFTYPE_RESOLVE, subpass.getResolveAttachments());
4824 for (size_t attachmentNdx = 0; attachmentNdx < renderPassInfo.getAttachments().size(); attachmentNdx++)
4826 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentNdx];
4827 const VkFormatProperties formatProperties = getPhysicalDeviceFormatProperties(context.getInstanceInterface(), context.getPhysicalDevice(), attachment.getFormat());
4828 const VkFormatFeatureFlags supportedFeatures = formatProperties.optimalTilingFeatures;
4830 if ((supportedFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) != 0)
4831 attachmentImageUsage[attachmentNdx] |= VK_IMAGE_USAGE_SAMPLED_BIT;
4833 if ((supportedFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) != 0)
4834 attachmentImageUsage[attachmentNdx] |= VK_IMAGE_USAGE_STORAGE_BIT;
4836 attachmentImageUsage[attachmentNdx] |= getImageUsageFromLayout(attachment.getInitialLayout());
4837 attachmentImageUsage[attachmentNdx] |= getImageUsageFromLayout(attachment.getFinalLayout());
4839 if (!attachmentIsLazy[attachmentNdx])
4841 if (clearValues[attachmentNdx])
4842 attachmentImageUsage[attachmentNdx] |= VK_IMAGE_USAGE_TRANSFER_DST_BIT;
4844 attachmentImageUsage[attachmentNdx] |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
4848 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);
4850 attachmentImageUsage[attachmentNdx] &= allowedTransientBits;
4851 attachmentImageUsage[attachmentNdx] |= VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT;
4856 void initializeSubpassIsSecondary (vector<bool>& subpassIsSecondary, const vector<Subpass>& subpasses, TestConfig::CommandBufferTypes commandBuffer)
4858 bool lastSubpassWasSecondary = false;
4860 for (size_t subpassNdx = 0; subpassNdx < subpasses.size(); subpassNdx++)
4862 if (commandBuffer == TestConfig::COMMANDBUFFERTYPES_SECONDARY || (commandBuffer & TestConfig::COMMANDBUFFERTYPES_SECONDARY && !lastSubpassWasSecondary))
4864 subpassIsSecondary.push_back(true);
4865 lastSubpassWasSecondary = true;
4867 else if (commandBuffer & TestConfig::COMMANDBUFFERTYPES_INLINE)
4869 subpassIsSecondary.push_back(false);
4870 lastSubpassWasSecondary = false;
4873 DE_FATAL("Unknown commandBuffer");
4877 void initializeImageClearValues (de::Random& rng, vector<Maybe<VkClearValue> >& clearValues, const vector<Attachment>& attachments, const vector<bool>& isLazy, deBool useFormatCompCount, const DepthValuesArray& depthValues)
4879 for (size_t attachmentNdx = 0; attachmentNdx < attachments.size(); attachmentNdx++)
4881 if (!isLazy[attachmentNdx])
4882 clearValues.push_back(just(randomClearValue(attachments[attachmentNdx], rng, useFormatCompCount, depthValues)));
4884 clearValues.push_back(tcu::Nothing);
4888 void initializeRenderPassClearValues (de::Random& rng, vector<Maybe<VkClearValue> >& clearValues, const vector<Attachment>& attachments, deBool useFormatCompCount, const DepthValuesArray& depthValues)
4890 for (size_t attachmentNdx = 0; attachmentNdx < attachments.size(); attachmentNdx++)
4892 if (attachments[attachmentNdx].getLoadOp() == VK_ATTACHMENT_LOAD_OP_CLEAR
4893 || attachments[attachmentNdx].getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_CLEAR)
4895 clearValues.push_back(just(randomClearValue(attachments[attachmentNdx], rng, useFormatCompCount, depthValues)));
4898 clearValues.push_back(tcu::Nothing);
4902 void logSubpassRenderInfo (TestLog& log, const SubpassRenderInfo& info, TestConfig config)
4904 log << TestLog::Message << "Viewport, offset: " << info.getViewportOffset() << ", size: " << info.getViewportSize() << TestLog::EndMessage;
4906 if (info.isSecondary())
4907 log << TestLog::Message << "Subpass uses secondary command buffers" << TestLog::EndMessage;
4909 log << TestLog::Message << "Subpass uses inlined commands" << TestLog::EndMessage;
4911 for (deUint32 attachmentNdx = 0; attachmentNdx < info.getColorClears().size(); attachmentNdx++)
4913 const ColorClear& colorClear = info.getColorClears()[attachmentNdx];
4915 log << TestLog::Message << "Clearing color attachment " << attachmentNdx
4916 << ". Offset: " << colorClear.getOffset()
4917 << ", Size: " << colorClear.getSize()
4918 << ", Color: " << clearColorToString(info.getColorAttachment(attachmentNdx).getFormat(), colorClear.getColor(), config.useFormatCompCount) << TestLog::EndMessage;
4921 if (info.getDepthStencilClear())
4923 const DepthStencilClear& depthStencilClear = *info.getDepthStencilClear();
4925 log << TestLog::Message << "Clearing depth stencil attachment"
4926 << ". Offset: " << depthStencilClear.getOffset()
4927 << ", Size: " << depthStencilClear.getSize()
4928 << ", Depth: " << depthStencilClear.getDepth()
4929 << ", Stencil: " << depthStencilClear.getStencil() << TestLog::EndMessage;
4932 if (info.getRenderQuad())
4934 const RenderQuad& renderQuad = *info.getRenderQuad();
4936 log << TestLog::Message << "Rendering grid quad to " << renderQuad.getCornerA() << " -> " << renderQuad.getCornerB() << TestLog::EndMessage;
4940 void logTestCaseInfo (TestLog& log,
4941 const TestConfig& config,
4942 const vector<bool>& attachmentIsLazy,
4943 const vector<Maybe<VkClearValue> >& imageClearValues,
4944 const vector<Maybe<VkClearValue> >& renderPassClearValues,
4945 const vector<SubpassRenderInfo>& subpassRenderInfo)
4947 const RenderPass& renderPass = config.renderPass;
4949 logRenderPassInfo(log, renderPass);
4951 DE_ASSERT(attachmentIsLazy.size() == renderPass.getAttachments().size());
4952 DE_ASSERT(imageClearValues.size() == renderPass.getAttachments().size());
4953 DE_ASSERT(renderPassClearValues.size() == renderPass.getAttachments().size());
4955 log << TestLog::Message << "TargetSize: " << config.targetSize << TestLog::EndMessage;
4956 log << TestLog::Message << "Render area, Offset: " << config.renderPos << ", Size: " << config.renderSize << TestLog::EndMessage;
4958 for (size_t attachmentNdx = 0; attachmentNdx < attachmentIsLazy.size(); attachmentNdx++)
4960 const tcu::ScopedLogSection section (log, "Attachment" + de::toString(attachmentNdx), "Attachment " + de::toString(attachmentNdx));
4962 if (attachmentIsLazy[attachmentNdx])
4963 log << TestLog::Message << "Is lazy." << TestLog::EndMessage;
4965 if (imageClearValues[attachmentNdx])
4966 log << TestLog::Message << "Image is cleared to " << clearValueToString(renderPass.getAttachments()[attachmentNdx].getFormat(),
4967 *imageClearValues[attachmentNdx], config.useFormatCompCount) << " before rendering." << TestLog::EndMessage;
4969 if (renderPass.getAttachments()[attachmentNdx].getLoadOp() == VK_ATTACHMENT_LOAD_OP_CLEAR && renderPassClearValues[attachmentNdx])
4970 log << TestLog::Message << "Attachment is cleared to " << clearValueToString(renderPass.getAttachments()[attachmentNdx].getFormat(),
4971 *renderPassClearValues[attachmentNdx], config.useFormatCompCount) << " in the beginning of the render pass." << TestLog::EndMessage;
4974 for (size_t subpassNdx = 0; subpassNdx < renderPass.getSubpasses().size(); subpassNdx++)
4976 const tcu::ScopedLogSection section (log, "Subpass" + de::toString(subpassNdx), "Subpass " + de::toString(subpassNdx));
4978 logSubpassRenderInfo(log, subpassRenderInfo[subpassNdx], config);
4982 float roundToViewport (float x, deUint32 offset, deUint32 size)
4984 const float origin = (float)(offset) + ((float(size) / 2.0f));
4985 const float p = (float)(size) / 2.0f;
4986 const deInt32 xi = deRoundFloatToInt32(origin + (p * x));
4988 return (((float)xi) - origin) / p;
4991 void initializeSubpassRenderInfo (vector<SubpassRenderInfo>& renderInfos, de::Random& rng, const RenderPass& renderPass, const TestConfig& config)
4993 const TestConfig::CommandBufferTypes commandBuffer = config.commandBufferTypes;
4994 const vector<Subpass>& subpasses = renderPass.getSubpasses();
4995 bool lastSubpassWasSecondary = false;
4997 for (deUint32 subpassNdx = 0; subpassNdx < (deUint32)subpasses.size(); subpassNdx++)
4999 const Subpass& subpass = subpasses[subpassNdx];
5000 const bool subpassIsSecondary = commandBuffer == TestConfig::COMMANDBUFFERTYPES_SECONDARY
5001 || (commandBuffer & TestConfig::COMMANDBUFFERTYPES_SECONDARY && !lastSubpassWasSecondary) ? true : false;
5002 const bool omitBlendState = subpass.getOmitBlendState();
5003 const UVec2 viewportSize ((config.renderSize * UVec2(2)) / UVec2(3));
5004 const UVec2 viewportOffset (config.renderPos.x() + (subpassNdx % 2) * (config.renderSize.x() / 3),
5005 config.renderPos.y() + ((subpassNdx / 2) % 2) * (config.renderSize.y() / 3));
5007 vector<ColorClear> colorClears;
5008 Maybe<DepthStencilClear> depthStencilClear;
5009 Maybe<RenderQuad> renderQuad;
5011 lastSubpassWasSecondary = subpassIsSecondary;
5013 if (config.renderTypes & TestConfig::RENDERTYPES_CLEAR)
5015 const vector<AttachmentReference>& colorAttachments = subpass.getColorAttachments();
5017 for (size_t attachmentRefNdx = 0; attachmentRefNdx < colorAttachments.size(); attachmentRefNdx++)
5019 const AttachmentReference& attachmentRef = colorAttachments[attachmentRefNdx];
5020 const Attachment& attachment = renderPass.getAttachments()[attachmentRef.getAttachment()];
5021 const UVec2 size ((viewportSize * UVec2(2)) / UVec2(3));
5022 const UVec2 offset (viewportOffset.x() + ((deUint32)attachmentRefNdx % 2u) * (viewportSize.x() / 3u),
5023 viewportOffset.y() + (((deUint32)attachmentRefNdx / 2u) % 2u) * (viewportSize.y() / 3u));
5024 const VkClearColorValue color = randomColorClearValue(attachment, rng, config.useFormatCompCount);
5026 colorClears.push_back(ColorClear(offset, size, color));
5029 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED)
5031 const Attachment& attachment = renderPass.getAttachments()[subpass.getDepthStencilAttachment().getAttachment()];
5032 const UVec2 size ((viewportSize * UVec2(2)) / UVec2(3));
5033 const UVec2 offset (viewportOffset.x() + ((deUint32)colorAttachments.size() % 2u) * (viewportSize.x() / 3u),
5034 viewportOffset.y() + (((deUint32)colorAttachments.size() / 2u) % 2u) * (viewportSize.y() / 3u));
5035 const VkClearValue value = randomClearValue(attachment, rng, config.useFormatCompCount, config.depthValues);
5037 depthStencilClear = tcu::just(DepthStencilClear(offset, size, value.depthStencil.depth, value.depthStencil.stencil));
5041 if (config.renderTypes & TestConfig::RENDERTYPES_DRAW)
5043 const float w = (subpassNdx % 2) == 0 ? 1.0f : 1.25f;
5044 const float h = (subpassNdx % 2) == 0 ? 1.25f : 1.0f;
5046 const float x0 = roundToViewport((subpassNdx % 2) == 0 ? 1.0f - w : -1.0f, viewportOffset.x(), viewportSize.x());
5047 const float x1 = roundToViewport((subpassNdx % 2) == 0 ? 1.0f : -1.0f + w, viewportOffset.x(), viewportSize.x());
5049 const float y0 = roundToViewport(((subpassNdx / 2) % 2) == 0 ? 1.0f - h : -1.0f, viewportOffset.y(), viewportSize.y());
5050 const float y1 = roundToViewport(((subpassNdx / 2) % 2) == 0 ? 1.0f : -1.0f + h, viewportOffset.y(), viewportSize.y());
5052 renderQuad = tcu::just(RenderQuad(tcu::Vec2(x0, y0), tcu::Vec2(x1, y1)));
5055 renderInfos.push_back(SubpassRenderInfo(renderPass, subpassNdx, config.drawStartNdx, subpassIsSecondary, omitBlendState, viewportOffset, viewportSize, renderQuad, colorClears, depthStencilClear));
5059 void checkTextureFormatSupport (TestLog& log,
5060 const InstanceInterface& vk,
5061 VkPhysicalDevice device,
5062 const vector<Attachment>& attachments)
5064 bool supported = true;
5066 for (size_t attachmentNdx = 0; attachmentNdx < attachments.size(); attachmentNdx++)
5068 const Attachment& attachment = attachments[attachmentNdx];
5069 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
5070 const bool isDepthOrStencilAttachment = hasDepthComponent(format.order) || hasStencilComponent(format.order);
5071 const VkFormatFeatureFlags flags = isDepthOrStencilAttachment? VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT : VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT;
5072 VkFormatProperties properties;
5074 vk.getPhysicalDeviceFormatProperties(device, attachment.getFormat(), &properties);
5076 if ((properties.optimalTilingFeatures & flags) != flags)
5079 log << TestLog::Message << "Format: " << attachment.getFormat() << " not supported as " << (isDepthOrStencilAttachment ? "depth stencil attachment" : "color attachment") << TestLog::EndMessage;
5084 TCU_THROW(NotSupportedError, "Format not supported");
5087 tcu::TestStatus renderPassTest (Context& context, TestConfig config)
5089 const UVec2 targetSize = config.targetSize;
5090 const UVec2 renderPos = config.renderPos;
5091 const UVec2 renderSize = config.renderSize;
5092 const RenderPass& renderPassInfo = config.renderPass;
5094 TestLog& log = context.getTestContext().getLog();
5095 de::Random rng (config.seed);
5097 vector<bool> attachmentIsLazy;
5098 vector<VkImageUsageFlags> attachmentImageUsage;
5099 vector<Maybe<VkClearValue> > imageClearValues;
5100 vector<Maybe<VkClearValue> > renderPassClearValues;
5102 vector<bool> subpassIsSecondary;
5103 vector<SubpassRenderInfo> subpassRenderInfo;
5105 if (config.groupParams->renderingType == RENDERING_TYPE_RENDERPASS2)
5106 context.requireDeviceFunctionality("VK_KHR_create_renderpass2");
5108 if (config.groupParams->renderingType == RENDERING_TYPE_DYNAMIC_RENDERING)
5109 context.requireDeviceFunctionality("VK_KHR_dynamic_rendering");
5111 if (config.allocationKind == ALLOCATION_KIND_DEDICATED)
5113 if (!context.isDeviceFunctionalitySupported("VK_KHR_dedicated_allocation"))
5114 TCU_THROW(NotSupportedError, "VK_KHR_dedicated_allocation is not supported");
5117 if (!renderPassInfo.getInputAspects().empty())
5119 if (!context.isDeviceFunctionalitySupported("VK_KHR_maintenance2"))
5120 TCU_THROW(NotSupportedError, "Extension VK_KHR_maintenance2 not supported.");
5124 bool requireDepthStencilLayout = false;
5126 for (size_t attachmentNdx = 0; attachmentNdx < renderPassInfo.getAttachments().size(); attachmentNdx++)
5128 if (renderPassInfo.getAttachments()[attachmentNdx].getInitialLayout() == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL
5129 || renderPassInfo.getAttachments()[attachmentNdx].getInitialLayout() == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL
5130 || renderPassInfo.getAttachments()[attachmentNdx].getFinalLayout() == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL
5131 || renderPassInfo.getAttachments()[attachmentNdx].getFinalLayout() == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
5133 requireDepthStencilLayout = true;
5138 for (size_t subpassNdx = 0; subpassNdx < renderPassInfo.getSubpasses().size() && !requireDepthStencilLayout; subpassNdx++)
5140 const Subpass& subpass (renderPassInfo.getSubpasses()[subpassNdx]);
5142 for (size_t attachmentNdx = 0; attachmentNdx < subpass.getColorAttachments().size(); attachmentNdx++)
5144 if (subpass.getColorAttachments()[attachmentNdx].getImageLayout() == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL
5145 || subpass.getColorAttachments()[attachmentNdx].getImageLayout() == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
5147 requireDepthStencilLayout = true;
5152 for (size_t attachmentNdx = 0; !requireDepthStencilLayout && attachmentNdx < subpass.getInputAttachments().size(); attachmentNdx++)
5154 if (subpass.getInputAttachments()[attachmentNdx].getImageLayout() == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL
5155 || subpass.getInputAttachments()[attachmentNdx].getImageLayout() == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
5157 requireDepthStencilLayout = true;
5162 for (size_t attachmentNdx = 0; !requireDepthStencilLayout && attachmentNdx < subpass.getResolveAttachments().size(); attachmentNdx++)
5164 if (subpass.getResolveAttachments()[attachmentNdx].getImageLayout() == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL
5165 || subpass.getResolveAttachments()[attachmentNdx].getImageLayout() == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
5167 requireDepthStencilLayout = true;
5172 if (subpass.getDepthStencilAttachment().getImageLayout() == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL
5173 || subpass.getDepthStencilAttachment().getImageLayout() == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
5175 requireDepthStencilLayout = true;
5180 if (requireDepthStencilLayout && !context.isDeviceFunctionalitySupported("VK_KHR_maintenance2"))
5181 TCU_THROW(NotSupportedError, "VK_KHR_maintenance2 is not supported");
5184 initializeAttachmentIsLazy(attachmentIsLazy, renderPassInfo.getAttachments(), config.imageMemory);
5185 initializeImageClearValues(rng, imageClearValues, renderPassInfo.getAttachments(), attachmentIsLazy, config.useFormatCompCount, config.depthValues);
5186 initializeAttachmentImageUsage(context, attachmentImageUsage, renderPassInfo, attachmentIsLazy, imageClearValues);
5187 initializeRenderPassClearValues(rng, renderPassClearValues, renderPassInfo.getAttachments(), config.useFormatCompCount, config.depthValues);
5189 initializeSubpassIsSecondary(subpassIsSecondary, renderPassInfo.getSubpasses(), config.commandBufferTypes);
5190 initializeSubpassRenderInfo(subpassRenderInfo, rng, renderPassInfo, config);
5192 logTestCaseInfo(log, config, attachmentIsLazy, imageClearValues, renderPassClearValues, subpassRenderInfo);
5194 checkTextureFormatSupport(log, context.getInstanceInterface(), context.getPhysicalDevice(), config.renderPass.getAttachments());
5197 const vk::VkPhysicalDeviceProperties properties = vk::getPhysicalDeviceProperties(context.getInstanceInterface(), context.getPhysicalDevice());
5199 log << TestLog::Message << "Max color attachments: " << properties.limits.maxColorAttachments << TestLog::EndMessage;
5201 for (size_t subpassNdx = 0; subpassNdx < renderPassInfo.getSubpasses().size(); subpassNdx++)
5203 if (renderPassInfo.getSubpasses()[subpassNdx].getColorAttachments().size() > (size_t)properties.limits.maxColorAttachments)
5204 TCU_THROW(NotSupportedError, "Subpass uses more than maxColorAttachments.");
5209 const InstanceInterface& vki = context.getInstanceInterface();
5210 const VkPhysicalDevice& physDevice = context.getPhysicalDevice();
5211 const VkDevice device = context.getDevice();
5212 const DeviceInterface& vk = context.getDeviceInterface();
5213 const VkQueue queue = context.getUniversalQueue();
5214 const deUint32 queueIndex = context.getUniversalQueueFamilyIndex();
5215 Allocator& allocator = context.getDefaultAllocator();
5217 const Unique<VkCommandPool> commandBufferPool (createCommandPool(vk, device, 0, queueIndex));
5218 const Unique<VkCommandBuffer> initializeImagesCommandBuffer (allocateCommandBuffer(vk, device, *commandBufferPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
5219 const Unique<VkCommandBuffer> renderCommandBuffer (allocateCommandBuffer(vk, device, *commandBufferPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
5220 const Unique<VkCommandBuffer> readImagesToBuffersCommandBuffer (allocateCommandBuffer(vk, device, *commandBufferPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
5222 vector<de::SharedPtr<AttachmentResources> > attachmentResources;
5223 vector<de::SharedPtr<SubpassRenderer> > subpassRenderers;
5224 vector<VkImage> attachmentImages;
5225 vector<VkImageView> attachmentViews;
5226 vector<pair<VkImageView, VkImageView> > inputAttachmentViews;
5228 Move<VkRenderPass> renderPass;
5229 if (config.groupParams->renderingType != RENDERING_TYPE_DYNAMIC_RENDERING)
5230 renderPass = createRenderPass(vk, device, renderPassInfo, config.groupParams->renderingType);
5232 for (size_t attachmentNdx = 0; attachmentNdx < renderPassInfo.getAttachments().size(); attachmentNdx++)
5234 const Attachment& attachmentInfo = renderPassInfo.getAttachments()[attachmentNdx];
5236 attachmentResources.push_back(de::SharedPtr<AttachmentResources>(new AttachmentResources(vki, physDevice, vk, device, allocator, queueIndex, targetSize, attachmentInfo, attachmentImageUsage[attachmentNdx], config.allocationKind)));
5237 attachmentViews.push_back(attachmentResources[attachmentNdx]->getAttachmentView());
5238 attachmentImages.push_back(attachmentResources[attachmentNdx]->getImage());
5240 inputAttachmentViews.push_back(attachmentResources[attachmentNdx]->getInputAttachmentViews());
5243 beginCommandBuffer(vk, *initializeImagesCommandBuffer, DE_NULL, 0, DE_NULL, VK_FALSE, (VkQueryControlFlags)0, (VkQueryPipelineStatisticFlags)0);
5244 pushImageInitializationCommands(vk, *initializeImagesCommandBuffer, renderPassInfo.getAttachments(), attachmentResources, queueIndex, imageClearValues);
5245 endCommandBuffer(vk, *initializeImagesCommandBuffer);
5248 Move<VkFramebuffer> framebuffer;
5249 if (config.groupParams->renderingType != RENDERING_TYPE_DYNAMIC_RENDERING)
5250 framebuffer = createFramebuffer(vk, device, *renderPass, targetSize, attachmentViews);
5252 const VkRect2D renderArea
5254 { (deInt32)renderPos.x(), (deInt32)renderPos.y() },
5255 { renderSize.x(), renderSize.y() }
5257 const bool dynamicRendering = (config.groupParams->renderingType == RENDERING_TYPE_DYNAMIC_RENDERING);
5258 const bool secondaryCmdBufferCompletelyContainsDynamicRenderpass = (config.commandBufferTypes == TestConfig::COMMANDBUFFERTYPES_SECONDARY) &&
5259 config.groupParams->secondaryCmdBufferCompletelyContainsDynamicRenderpass;
5261 for (size_t subpassNdx = 0; subpassNdx < renderPassInfo.getSubpasses().size(); subpassNdx++)
5263 subpassRenderers.push_back(de::SharedPtr<SubpassRenderer>(new SubpassRenderer(context, vk, device, allocator, renderPassInfo, attachmentResources,
5264 renderArea, renderPassClearValues, *renderPass, *framebuffer,
5265 *commandBufferPool, queueIndex, attachmentImages, inputAttachmentViews,
5266 subpassRenderInfo[subpassNdx], config.allocationKind, dynamicRendering,
5267 secondaryCmdBufferCompletelyContainsDynamicRenderpass)));
5270 beginCommandBuffer(vk, *renderCommandBuffer, DE_NULL, 0, DE_NULL, VK_FALSE, (VkQueryControlFlags)0, (VkQueryPipelineStatisticFlags)0);
5271 pushRenderPassCommands(vk, *renderCommandBuffer, *renderPass, renderPassInfo, attachmentResources, *framebuffer, subpassRenderers, renderArea,
5272 renderPassClearValues, queueIndex, config.renderTypes, config.groupParams->renderingType, secondaryCmdBufferCompletelyContainsDynamicRenderpass);
5273 endCommandBuffer(vk, *renderCommandBuffer);
5275 beginCommandBuffer(vk, *readImagesToBuffersCommandBuffer, DE_NULL, 0, DE_NULL, VK_FALSE, (VkQueryControlFlags)0, (VkQueryPipelineStatisticFlags)0);
5276 pushReadImagesToBuffers(vk, *readImagesToBuffersCommandBuffer, queueIndex, attachmentResources, renderPassInfo.getAttachments(), attachmentIsLazy, targetSize);
5277 endCommandBuffer(vk, *readImagesToBuffersCommandBuffer);
5279 const VkCommandBuffer commandBuffers[] =
5281 *initializeImagesCommandBuffer,
5282 *renderCommandBuffer,
5283 *readImagesToBuffersCommandBuffer
5285 const Unique<VkFence> fence (createFence(vk, device, 0u));
5287 queueSubmit(vk, queue, DE_LENGTH_OF_ARRAY(commandBuffers), commandBuffers, *fence);
5288 waitForFences(vk, device, 1, &fence.get(), VK_TRUE, ~0ull);
5291 #ifdef CTS_USES_VULKANSC
5292 if (!context.getTestContext().getCommandLine().isSubProcess())
5293 return tcu::TestStatus::pass("Pass");
5295 if (logAndVerifyImages(log, vk, device, attachmentResources, attachmentIsLazy, renderPassInfo, renderPassClearValues, imageClearValues, subpassRenderInfo, targetSize, config))
5296 return tcu::TestStatus::pass("Pass");
5298 return tcu::TestStatus::fail("Result verification failed");
5302 static const VkFormat s_coreColorFormats[] =
5304 VK_FORMAT_R5G6B5_UNORM_PACK16,
5309 VK_FORMAT_R8G8_UNORM,
5310 VK_FORMAT_R8G8_SNORM,
5311 VK_FORMAT_R8G8_UINT,
5312 VK_FORMAT_R8G8_SINT,
5313 VK_FORMAT_R8G8B8A8_UNORM,
5314 VK_FORMAT_R8G8B8A8_SNORM,
5315 VK_FORMAT_R8G8B8A8_UINT,
5316 VK_FORMAT_R8G8B8A8_SINT,
5317 VK_FORMAT_R8G8B8A8_SRGB,
5318 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
5319 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
5320 VK_FORMAT_A8B8G8R8_UINT_PACK32,
5321 VK_FORMAT_A8B8G8R8_SINT_PACK32,
5322 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
5323 VK_FORMAT_B8G8R8A8_UNORM,
5324 VK_FORMAT_B8G8R8A8_SRGB,
5325 VK_FORMAT_A2R10G10B10_UNORM_PACK32,
5326 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
5327 VK_FORMAT_A2B10G10R10_UINT_PACK32,
5328 VK_FORMAT_R16_UNORM,
5329 VK_FORMAT_R16_SNORM,
5332 VK_FORMAT_R16_SFLOAT,
5333 VK_FORMAT_R16G16_UNORM,
5334 VK_FORMAT_R16G16_SNORM,
5335 VK_FORMAT_R16G16_UINT,
5336 VK_FORMAT_R16G16_SINT,
5337 VK_FORMAT_R16G16_SFLOAT,
5338 VK_FORMAT_R16G16B16A16_UNORM,
5339 VK_FORMAT_R16G16B16A16_SNORM,
5340 VK_FORMAT_R16G16B16A16_UINT,
5341 VK_FORMAT_R16G16B16A16_SINT,
5342 VK_FORMAT_R16G16B16A16_SFLOAT,
5345 VK_FORMAT_R32_SFLOAT,
5346 VK_FORMAT_R32G32_UINT,
5347 VK_FORMAT_R32G32_SINT,
5348 VK_FORMAT_R32G32_SFLOAT,
5349 VK_FORMAT_R32G32B32A32_UINT,
5350 VK_FORMAT_R32G32B32A32_SINT,
5351 VK_FORMAT_R32G32B32A32_SFLOAT
5354 static const VkFormat s_coreDepthStencilFormats[] =
5356 VK_FORMAT_D16_UNORM,
5358 VK_FORMAT_X8_D24_UNORM_PACK32,
5359 VK_FORMAT_D32_SFLOAT,
5361 VK_FORMAT_D24_UNORM_S8_UINT,
5362 VK_FORMAT_D32_SFLOAT_S8_UINT
5365 void addAttachmentTests (tcu::TestCaseGroup* group, const TestConfigExternal testConfigExternal)
5367 const deUint32 attachmentCounts[] = { 1, 3, 4, 8 };
5368 const VkAttachmentLoadOp loadOps[] =
5370 VK_ATTACHMENT_LOAD_OP_LOAD,
5371 VK_ATTACHMENT_LOAD_OP_CLEAR,
5372 VK_ATTACHMENT_LOAD_OP_DONT_CARE
5375 const VkAttachmentStoreOp storeOps[] =
5377 VK_ATTACHMENT_STORE_OP_STORE,
5378 VK_ATTACHMENT_STORE_OP_DONT_CARE
5381 const VkImageLayout initialAndFinalColorLayouts[] =
5383 VK_IMAGE_LAYOUT_GENERAL,
5384 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
5385 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
5386 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
5387 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
5390 const VkImageLayout initialAndFinalColorLayoutsLazy[] =
5392 VK_IMAGE_LAYOUT_GENERAL,
5393 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
5394 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
5397 const VkImageLayout initialAndFinalDepthStencilLayouts[] =
5399 VK_IMAGE_LAYOUT_GENERAL,
5400 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
5401 VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL,
5402 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
5403 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
5404 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
5407 const VkImageLayout initialAndFinalDepthStencilLayoutsLazy[] =
5409 VK_IMAGE_LAYOUT_GENERAL,
5410 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
5411 VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL,
5412 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
5415 const VkImageLayout subpassLayouts[] =
5417 VK_IMAGE_LAYOUT_GENERAL,
5418 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
5421 const VkImageLayout depthStencilLayouts[] =
5423 VK_IMAGE_LAYOUT_GENERAL,
5424 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL
5427 const TestConfig::RenderTypes renderCommands[] =
5429 TestConfig::RENDERTYPES_NONE,
5430 TestConfig::RENDERTYPES_CLEAR,
5431 TestConfig::RENDERTYPES_DRAW,
5432 TestConfig::RENDERTYPES_CLEAR|TestConfig::RENDERTYPES_DRAW,
5435 const TestConfig::CommandBufferTypes commandBuffers[] =
5437 TestConfig::COMMANDBUFFERTYPES_INLINE,
5438 TestConfig::COMMANDBUFFERTYPES_SECONDARY,
5439 TestConfig::COMMANDBUFFERTYPES_INLINE|TestConfig::COMMANDBUFFERTYPES_SECONDARY
5442 const TestConfig::ImageMemory imageMemories[] =
5444 TestConfig::IMAGEMEMORY_STRICT,
5445 TestConfig::IMAGEMEMORY_LAZY,
5446 TestConfig::IMAGEMEMORY_STRICT|TestConfig::IMAGEMEMORY_LAZY
5449 const UVec2 targetSizes[] =
5455 const UVec2 renderPositions[] =
5461 const UVec2 renderSizes[] =
5467 tcu::TestContext& testCtx (group->getTestContext());
5468 bool useDynamicRendering (testConfigExternal.groupParams->renderingType == RENDERING_TYPE_DYNAMIC_RENDERING);
5469 de::Random rng (1433774382u);
5471 for (size_t attachmentCountNdx = 0; attachmentCountNdx < DE_LENGTH_OF_ARRAY(attachmentCounts); attachmentCountNdx++)
5473 const deUint32 attachmentCount = attachmentCounts[attachmentCountNdx];
5474 const deUint32 testCaseCount = (attachmentCount == 1 ? 100 : 200);
5475 de::MovePtr<tcu::TestCaseGroup> attachmentCountGroup (new tcu::TestCaseGroup(testCtx, de::toString(attachmentCount).c_str(), de::toString(attachmentCount).c_str()));
5477 for (size_t testCaseNdx = 0; testCaseNdx < testCaseCount; testCaseNdx++)
5479 const bool useDepthStencil = rng.getBool();
5480 const TestConfig::ImageMemory imageMemory = rng.choose<TestConfig::ImageMemory>(DE_ARRAY_BEGIN(imageMemories), DE_ARRAY_END(imageMemories));
5481 VkImageLayout depthStencilLayout = VK_IMAGE_LAYOUT_GENERAL;
5482 vector<Attachment> attachments;
5483 vector<AttachmentReference> colorAttachmentReferences;
5485 // we want to make sure that dynamic rendering test cases have corresponding renderpass
5486 // cases as this will allow drivers to easily compare GPU batches; since configurations
5487 // for those tests are generated we need to generate configurations for all cases
5488 // even when we know earlier that for dynamic rendering we will skip it
5489 bool executeForDynamicRendering = true;
5491 for (size_t attachmentNdx = 0; attachmentNdx < attachmentCount; attachmentNdx++)
5493 const VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_1_BIT;
5494 const VkFormat format = rng.choose<VkFormat>(DE_ARRAY_BEGIN(s_coreColorFormats), DE_ARRAY_END(s_coreColorFormats));
5495 const VkAttachmentLoadOp loadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
5496 const VkAttachmentStoreOp storeOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
5498 const VkImageLayout initialLayout = (imageMemory == TestConfig::IMAGEMEMORY_STRICT)
5499 ? rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalColorLayouts), DE_ARRAY_END(initialAndFinalColorLayouts))
5500 : rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalColorLayoutsLazy), DE_ARRAY_END(initialAndFinalColorLayoutsLazy));
5501 VkImageLayout finalizeLayout = (imageMemory == TestConfig::IMAGEMEMORY_STRICT)
5502 ? rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalColorLayouts), DE_ARRAY_END(initialAndFinalColorLayouts))
5503 : rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalColorLayoutsLazy), DE_ARRAY_END(initialAndFinalColorLayoutsLazy));
5504 const VkImageLayout subpassLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayouts), DE_ARRAY_END(subpassLayouts));
5506 const VkAttachmentLoadOp stencilLoadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
5507 const VkAttachmentStoreOp stencilStoreOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
5509 if (useDynamicRendering)
5511 // with renderpass we can have automatic layout transitions; to do the same with dynamic rendering cases
5512 // we would need to add addtional barries but since those tests won't add coverage we are skipping them
5513 if ((initialLayout == VK_IMAGE_LAYOUT_GENERAL) ||
5514 (initialLayout == VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL))
5515 finalizeLayout = initialLayout;
5517 executeForDynamicRendering = false;
5520 attachments.push_back(Attachment(format, sampleCount, loadOp, storeOp, stencilLoadOp, stencilStoreOp, initialLayout, finalizeLayout));
5521 colorAttachmentReferences.push_back(AttachmentReference((deUint32)attachmentNdx, subpassLayout));
5524 if (useDepthStencil)
5526 const VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_1_BIT;
5527 const VkFormat format = rng.choose<VkFormat>(DE_ARRAY_BEGIN(s_coreDepthStencilFormats), DE_ARRAY_END(s_coreDepthStencilFormats));
5528 const VkAttachmentLoadOp loadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
5529 const VkAttachmentStoreOp storeOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
5531 const VkImageLayout initialLayout = (imageMemory == TestConfig::IMAGEMEMORY_STRICT)
5532 ? rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalDepthStencilLayouts), DE_ARRAY_END(initialAndFinalDepthStencilLayouts))
5533 : rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalDepthStencilLayoutsLazy), DE_ARRAY_END(initialAndFinalDepthStencilLayoutsLazy));
5534 VkImageLayout finalizeLayout = (imageMemory == TestConfig::IMAGEMEMORY_STRICT)
5535 ? rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalDepthStencilLayouts), DE_ARRAY_END(initialAndFinalDepthStencilLayouts))
5536 : rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalDepthStencilLayoutsLazy), DE_ARRAY_END(initialAndFinalDepthStencilLayoutsLazy));
5538 const VkAttachmentLoadOp stencilLoadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
5539 const VkAttachmentStoreOp stencilStoreOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
5541 if (useDynamicRendering)
5543 if ((initialLayout == VK_IMAGE_LAYOUT_GENERAL) ||
5544 (initialLayout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) ||
5545 (initialLayout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL))
5546 finalizeLayout = initialLayout;
5548 executeForDynamicRendering = false;
5551 depthStencilLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(depthStencilLayouts), DE_ARRAY_END(depthStencilLayouts));
5552 attachments.push_back(Attachment(format, sampleCount, loadOp, storeOp, stencilLoadOp, stencilStoreOp, initialLayout, finalizeLayout));
5556 const TestConfig::RenderTypes render = rng.choose<TestConfig::RenderTypes>(DE_ARRAY_BEGIN(renderCommands), DE_ARRAY_END(renderCommands));
5557 const TestConfig::CommandBufferTypes commandBuffer = rng.choose<TestConfig::CommandBufferTypes>(DE_ARRAY_BEGIN(commandBuffers), DE_ARRAY_END(commandBuffers));
5558 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>()));
5559 const vector<SubpassDependency> deps;
5560 const string testCaseName = de::toString(attachmentCountNdx * testCaseCount + testCaseNdx);
5561 const RenderPass renderPass (attachments, subpasses, deps);
5562 const UVec2 targetSize = rng.choose<UVec2>(DE_ARRAY_BEGIN(targetSizes), DE_ARRAY_END(targetSizes));
5563 const UVec2 renderPos = rng.choose<UVec2>(DE_ARRAY_BEGIN(renderPositions), DE_ARRAY_END(renderPositions));
5564 const UVec2 renderSize = rng.choose<UVec2>(DE_ARRAY_BEGIN(renderSizes), DE_ARRAY_END(renderSizes));
5566 if (useDynamicRendering)
5568 // skip dynamic rendering cases (that don't add coverage) this can be done not earlier than after grabbing all
5569 // random numbers as we need to make sure that those tests that will be created for dynamic rendering have
5570 // corresponding renderpass tests with the same name
5571 if (!executeForDynamicRendering)
5574 // dont repeat non secondary buffer cases when testing secondaryCmdBufferCompletelyContainsDynamicRenderpass flag
5575 if (testConfigExternal.groupParams->secondaryCmdBufferCompletelyContainsDynamicRenderpass &&
5576 (commandBuffer != TestConfig::COMMANDBUFFERTYPES_SECONDARY))
5582 const TestConfig testConfig (renderPass,
5592 testConfigExternal.allocationKind,
5593 testConfigExternal.groupParams);
5595 addFunctionCaseWithPrograms<TestConfig>(attachmentCountGroup.get(), testCaseName.c_str(), testCaseName.c_str(), createTestShaders, renderPassTest, testConfig);
5599 group->addChild(attachmentCountGroup.release());
5603 void addAttachmentWriteMaskTests (tcu::TestCaseGroup* group, const TestConfigExternal testConfigExternal)
5605 const deUint32 attachmentCounts[] = { 1, 2, 3, 4, 8 };
5607 const VkFormat attachmentFormats[] =
5609 VK_FORMAT_R8G8B8A8_UINT,
5610 VK_FORMAT_R8G8B8A8_UNORM,
5611 VK_FORMAT_R5G6B5_UNORM_PACK16,
5612 VK_FORMAT_R8G8_UNORM
5615 tcu::TestContext& testCtx = group->getTestContext();
5617 for (deUint32 attachmentCountNdx = 0; attachmentCountNdx < DE_LENGTH_OF_ARRAY(attachmentCounts); attachmentCountNdx++)
5619 const deUint32 attachmentCount = attachmentCounts[attachmentCountNdx];
5620 const string groupName = "attachment_count_" + de::toString(attachmentCount);
5622 de::MovePtr<tcu::TestCaseGroup> attachmentCountGroup(new tcu::TestCaseGroup(testCtx, groupName.c_str(), de::toString(attachmentCount).c_str()));
5624 for (deUint32 drawStartNdx = 0; drawStartNdx < (attachmentCount); drawStartNdx++)
5626 deUint32 formatNdx = 0;
5627 vector<Attachment> attachments;
5628 vector<AttachmentReference> colorAttachmentReferences;
5630 for (deUint32 attachmentNdx = 0; attachmentNdx < attachmentCount; attachmentNdx++)
5632 const VkFormat format = attachmentFormats[formatNdx];
5633 const VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_1_BIT;
5634 const VkAttachmentLoadOp loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
5635 const VkAttachmentStoreOp storeOp = VK_ATTACHMENT_STORE_OP_STORE;
5636 const VkAttachmentLoadOp stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
5637 const VkAttachmentStoreOp stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
5638 const VkImageLayout initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
5639 const VkImageLayout finalizeLayout = (testConfigExternal.groupParams->renderingType == RENDERING_TYPE_DYNAMIC_RENDERING)
5640 ? initialLayout : VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
5641 const VkImageLayout subpassLayout = VK_IMAGE_LAYOUT_GENERAL;
5643 attachments.push_back(Attachment(format, sampleCount, loadOp, storeOp, stencilLoadOp, stencilStoreOp, initialLayout, finalizeLayout));
5644 colorAttachmentReferences.push_back(AttachmentReference((deUint32)attachmentNdx, subpassLayout));
5646 if (++formatNdx == DE_LENGTH_OF_ARRAY(attachmentFormats))
5651 const VkImageLayout depthStencilLayout = VK_IMAGE_LAYOUT_GENERAL;
5652 const vector<Subpass> subpass (1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u, vector<AttachmentReference>(), colorAttachmentReferences, vector<AttachmentReference>(), AttachmentReference(VK_ATTACHMENT_UNUSED, depthStencilLayout), vector<deUint32>()));
5653 const vector<SubpassDependency> deps;
5655 const string testCaseName = "start_index_" + de::toString(drawStartNdx);
5656 const RenderPass renderPass (attachments, subpass, deps);
5658 const TestConfig::RenderTypes render = TestConfig::RENDERTYPES_DRAW;
5659 const TestConfig::CommandBufferTypes commandBuffer = TestConfig::COMMANDBUFFERTYPES_INLINE;
5660 const TestConfig::ImageMemory imageMemory = TestConfig::IMAGEMEMORY_LAZY;
5661 const UVec2 targetSize = UVec2(64, 64);
5662 const UVec2 renderPos = UVec2(0, 0);
5663 const UVec2 renderSize = UVec2(64, 64);
5664 const deBool useFormatCompCount = DE_TRUE;
5665 const vector<DeviceCoreFeature> requiredFeatures = {DEVICE_CORE_FEATURE_INDEPENDENT_BLEND};
5666 const TestConfig testConfig (renderPass,
5676 testConfigExternal.allocationKind,
5677 testConfigExternal.groupParams,
5680 addFunctionCaseWithPrograms<TestConfig>(attachmentCountGroup.get(), testCaseName.c_str(), testCaseName.c_str(), checkSupport, createTestShaders, renderPassTest, testConfig);
5684 group->addChild(attachmentCountGroup.release());
5688 template<typename T>
5689 T chooseRandom (de::Random& rng, const set<T>& values)
5691 size_t ndx = ((size_t)rng.getUint32()) % values.size();
5692 typename set<T>::const_iterator iter = values.begin();
5694 for (; ndx > 0; ndx--)
5700 void addAttachmentAllocationTests (tcu::TestCaseGroup* group, const TestConfigExternal testConfigExternal)
5702 const deUint32 attachmentCounts[] = { 4, 8 };
5703 const VkAttachmentLoadOp loadOps[] =
5705 VK_ATTACHMENT_LOAD_OP_LOAD,
5706 VK_ATTACHMENT_LOAD_OP_CLEAR,
5707 VK_ATTACHMENT_LOAD_OP_DONT_CARE
5710 const VkAttachmentStoreOp storeOps[] =
5712 VK_ATTACHMENT_STORE_OP_STORE,
5713 VK_ATTACHMENT_STORE_OP_DONT_CARE
5716 const VkImageLayout initialAndFinalColorLayouts[] =
5718 VK_IMAGE_LAYOUT_GENERAL,
5719 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
5720 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
5721 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
5722 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
5725 const VkImageLayout initialAndFinalDepthStencilLayouts[] =
5727 VK_IMAGE_LAYOUT_GENERAL,
5728 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
5729 VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL,
5730 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
5731 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
5732 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
5735 const VkImageLayout subpassLayoutsColor[] =
5737 VK_IMAGE_LAYOUT_GENERAL,
5738 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
5741 const VkImageLayout subpassLayoutsDepthStencil[] =
5743 VK_IMAGE_LAYOUT_GENERAL,
5744 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL
5747 const VkImageLayout subpassLayoutsInput[] =
5749 VK_IMAGE_LAYOUT_GENERAL,
5750 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
5755 // Each pass uses one more attachmen than previous one
5756 ALLOCATIONTYPE_GROW,
5757 // Each pass uses one less attachment than previous one
5758 ALLOCATIONTYPE_SHRINK,
5759 // Each pass drops one attachment and picks up new one
5760 ALLOCATIONTYPE_ROLL,
5761 // Start by growing and end by shrinking
5762 ALLOCATIONTYPE_GROW_SHRINK,
5763 // Each subpass has single input and single output attachment
5764 ALLOCATIONTYPE_IO_CHAIN,
5765 // Each subpass has multiple inputs and multiple outputs attachment
5766 ALLOCATIONTYPE_IO_GENERIC
5769 const AllocationType allocationTypes[] =
5771 ALLOCATIONTYPE_GROW,
5772 ALLOCATIONTYPE_SHRINK,
5773 ALLOCATIONTYPE_ROLL,
5774 ALLOCATIONTYPE_GROW_SHRINK,
5775 ALLOCATIONTYPE_IO_CHAIN,
5776 ALLOCATIONTYPE_IO_GENERIC
5779 const char* const allocationTypeStr[] =
5785 "input_output_chain",
5789 const TestConfig::RenderTypes renderCommands[] =
5791 TestConfig::RENDERTYPES_NONE,
5792 TestConfig::RENDERTYPES_CLEAR,
5793 TestConfig::RENDERTYPES_DRAW,
5794 TestConfig::RENDERTYPES_CLEAR|TestConfig::RENDERTYPES_DRAW,
5797 const TestConfig::CommandBufferTypes commandBuffers[] =
5799 TestConfig::COMMANDBUFFERTYPES_INLINE,
5800 TestConfig::COMMANDBUFFERTYPES_SECONDARY,
5801 TestConfig::COMMANDBUFFERTYPES_INLINE|TestConfig::COMMANDBUFFERTYPES_SECONDARY
5804 const TestConfig::ImageMemory imageMemories[] =
5806 TestConfig::IMAGEMEMORY_STRICT,
5807 TestConfig::IMAGEMEMORY_LAZY,
5808 TestConfig::IMAGEMEMORY_STRICT|TestConfig::IMAGEMEMORY_LAZY
5811 const UVec2 targetSizes[] =
5817 const UVec2 renderPositions[] =
5823 const UVec2 renderSizes[] =
5829 tcu::TestContext& testCtx = group->getTestContext();
5830 de::Random rng (3700649827u);
5832 for (size_t allocationTypeNdx = 0; allocationTypeNdx < DE_LENGTH_OF_ARRAY(allocationTypes); allocationTypeNdx++)
5834 const AllocationType allocationType = allocationTypes[allocationTypeNdx];
5835 const size_t testCaseCount = 100;
5836 de::MovePtr<tcu::TestCaseGroup> allocationTypeGroup (new tcu::TestCaseGroup(testCtx, allocationTypeStr[allocationTypeNdx], allocationTypeStr[allocationTypeNdx]));
5838 for (size_t testCaseNdx = 0; testCaseNdx < testCaseCount; testCaseNdx++)
5840 if (allocationType == ALLOCATIONTYPE_IO_GENERIC)
5842 const deUint32 attachmentCount = 4u + rng.getUint32() % 31u;
5843 const deUint32 subpassCount = 4u + rng.getUint32() % 31u;
5844 vector<Attachment> attachments;
5846 set<deUint32> definedAttachments;
5848 vector<Subpass> subpasses;
5849 set<deUint32> colorAttachments;
5850 set<deUint32> depthStencilAttachments;
5852 for (deUint32 attachmentIndex = 0; attachmentIndex < attachmentCount; attachmentIndex++)
5854 const bool isDepthStencilAttachment = rng.getFloat() < 0.01f;
5855 const VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_1_BIT;
5856 const VkAttachmentLoadOp loadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
5857 const VkAttachmentStoreOp storeOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
5859 const VkImageLayout initialLayout = isDepthStencilAttachment
5860 ? rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalDepthStencilLayouts), DE_ARRAY_END(initialAndFinalDepthStencilLayouts))
5861 : rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalColorLayouts), DE_ARRAY_END(initialAndFinalColorLayouts));
5862 const VkImageLayout finalizeLayout = isDepthStencilAttachment
5863 ? rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalDepthStencilLayouts), DE_ARRAY_END(initialAndFinalDepthStencilLayouts))
5864 : rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalColorLayouts), DE_ARRAY_END(initialAndFinalColorLayouts));
5866 const VkAttachmentLoadOp stencilLoadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
5867 const VkAttachmentStoreOp stencilStoreOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
5869 if (isDepthStencilAttachment)
5871 const VkFormat format = rng.choose<VkFormat>(DE_ARRAY_BEGIN(s_coreDepthStencilFormats), DE_ARRAY_END(s_coreDepthStencilFormats));
5873 if (loadOp == VK_ATTACHMENT_LOAD_OP_LOAD || loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR
5874 || stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD || stencilLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR)
5875 definedAttachments.insert(attachmentIndex);
5877 depthStencilAttachments.insert(attachmentIndex);
5879 attachments.push_back(Attachment(format, sampleCount, loadOp, storeOp, stencilLoadOp, stencilStoreOp, initialLayout, finalizeLayout));
5883 const VkFormat format = rng.choose<VkFormat>(DE_ARRAY_BEGIN(s_coreColorFormats), DE_ARRAY_END(s_coreColorFormats));
5885 if (loadOp == VK_ATTACHMENT_LOAD_OP_LOAD || loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR)
5886 definedAttachments.insert(attachmentIndex);
5888 colorAttachments.insert(attachmentIndex);
5890 attachments.push_back(Attachment(format, sampleCount, loadOp, storeOp, stencilLoadOp, stencilStoreOp, initialLayout, finalizeLayout));
5893 vector<Maybe<deUint32> > lastUseOfAttachment (attachments.size(), tcu::Nothing);
5894 vector<SubpassDependency> deps;
5896 for (deUint32 subpassIndex = 0; subpassIndex < subpassCount; subpassIndex++)
5898 const deUint32 colorAttachmentCount = depthStencilAttachments.empty()
5899 ? 1 + rng.getUint32() % de::min(4u, (deUint32)colorAttachments.size())
5900 : rng.getUint32() % (de::min(4u, (deUint32)colorAttachments.size()) + 1u);
5901 const deUint32 inputAttachmentCount = rng.getUint32() % (deUint32)(de::min<size_t>(4, definedAttachments.size()) + 1);
5902 const bool useDepthStencilAttachment = !depthStencilAttachments.empty() && (colorAttachmentCount == 0 || rng.getBool());
5903 std::vector<deUint32> subpassColorAttachments (colorAttachmentCount);
5904 std::vector<deUint32> subpassInputAttachments (inputAttachmentCount);
5905 Maybe<deUint32> depthStencilAttachment (useDepthStencilAttachment
5906 ? just(chooseRandom(rng, depthStencilAttachments))
5908 std::vector<deUint32> subpassPreserveAttachments;
5910 rng.choose(colorAttachments.begin(), colorAttachments.end(), subpassColorAttachments.begin(), colorAttachmentCount);
5911 rng.choose(definedAttachments.begin(), definedAttachments.end(), subpassInputAttachments.begin(), inputAttachmentCount);
5913 for (size_t colorAttachmentNdx = 0; colorAttachmentNdx < subpassColorAttachments.size(); colorAttachmentNdx++)
5914 definedAttachments.insert(subpassColorAttachments[colorAttachmentNdx]);
5916 if (depthStencilAttachment)
5917 definedAttachments.insert(*depthStencilAttachment);
5920 std::vector<AttachmentReference> inputAttachmentReferences;
5921 std::vector<AttachmentReference> colorAttachmentReferences;
5922 AttachmentReference depthStencilAttachmentReference (VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL);
5924 for (size_t colorAttachmentNdx = 0; colorAttachmentNdx < subpassColorAttachments.size(); colorAttachmentNdx++)
5926 const deUint32 colorAttachmentIndex = subpassColorAttachments[colorAttachmentNdx];
5928 if (lastUseOfAttachment[colorAttachmentIndex])
5930 deBool foundDuplicate = false;
5932 const deUint32 srcPass = *lastUseOfAttachment[colorAttachmentIndex];
5933 const deUint32 dstPass = subpassIndex;
5934 const VkDependencyFlags dependencyFlags = rng.getBool() ? (VkDependencyFlags) VK_DEPENDENCY_BY_REGION_BIT : 0u;
5936 const SubpassDependency newDependency(srcPass, dstPass,
5937 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
5938 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
5939 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
5940 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
5942 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
5943 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
5944 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
5945 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
5947 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
5948 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT,
5952 for (SubpassDependency& dependency : deps)
5954 if (dependency.getSrcPass() == srcPass && dependency.getDstPass() == dstPass)
5956 const VkAccessFlags newDstFlags = dependency.getDstAccessMask() | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT;
5957 dependency.setDstAccessMask(newDstFlags);
5958 foundDuplicate = true;
5963 if (!foundDuplicate)
5965 deps.push_back(newDependency);
5969 lastUseOfAttachment[colorAttachmentIndex] = just(subpassIndex);
5971 colorAttachmentReferences.push_back(AttachmentReference((deUint32)subpassColorAttachments[colorAttachmentNdx], VK_IMAGE_LAYOUT_GENERAL));
5974 for (size_t inputAttachmentNdx = 0; inputAttachmentNdx < subpassInputAttachments.size(); inputAttachmentNdx++)
5976 const deUint32 inputAttachmentIndex = subpassInputAttachments[inputAttachmentNdx];
5978 if(lastUseOfAttachment[inputAttachmentIndex])
5980 deBool foundDuplicate = false;
5982 const deUint32 srcPass = *lastUseOfAttachment[inputAttachmentIndex];
5983 const deUint32 dstPass = subpassIndex;
5984 const VkDependencyFlags dependencyFlags = ((srcPass == subpassIndex) || rng.getBool()) ? (VkDependencyFlags)VK_DEPENDENCY_BY_REGION_BIT : 0u;
5986 const SubpassDependency newDependency(srcPass, dstPass,
5987 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
5988 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
5989 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
5990 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
5992 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
5993 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
5994 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
5995 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
5997 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
5998 VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
6001 for (SubpassDependency& dependency : deps)
6003 if (dependency.getSrcPass() == srcPass && dependency.getDstPass() == dstPass)
6005 const VkAccessFlags newSrcFlags = dependency.getSrcAccessMask() | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
6006 const VkAccessFlags newDstFlags = dependency.getDstAccessMask() | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT;
6007 dependency.setDstAccessMask(newSrcFlags);
6008 dependency.setDstAccessMask(newDstFlags);
6009 foundDuplicate = true;
6014 if (!foundDuplicate)
6016 deps.push_back(newDependency);
6019 lastUseOfAttachment[inputAttachmentIndex] = just(subpassIndex);
6021 VkImageAspectFlags aspect = 0u;
6022 if (testConfigExternal.groupParams->renderingType == RENDERING_TYPE_RENDERPASS2)
6024 bool col = colorAttachments.find(inputAttachmentIndex) != colorAttachments.end();
6025 aspect = col ? VK_IMAGE_ASPECT_COLOR_BIT : VK_IMAGE_ASPECT_DEPTH_BIT;
6027 inputAttachmentReferences.push_back(AttachmentReference((deUint32)subpassInputAttachments[inputAttachmentNdx], VK_IMAGE_LAYOUT_GENERAL, aspect));
6031 if (depthStencilAttachment)
6033 if (lastUseOfAttachment[*depthStencilAttachment])
6035 deBool foundDuplicate = false;
6037 const deUint32 srcPass = *lastUseOfAttachment[*depthStencilAttachment];
6038 const deUint32 dstPass = subpassIndex;
6039 const VkDependencyFlags dependencyFlags = ((srcPass == subpassIndex) || rng.getBool()) ? (VkDependencyFlags)VK_DEPENDENCY_BY_REGION_BIT : 0u;
6041 const SubpassDependency newDependency(srcPass, dstPass,
6042 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
6043 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
6044 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
6045 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
6047 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
6048 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
6049 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
6050 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
6052 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
6053 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT
6054 | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
6057 for (SubpassDependency& dependency : deps)
6059 if (dependency.getSrcPass() == srcPass && dependency.getDstPass() == dstPass)
6061 const VkAccessFlags newSrcFlags = dependency.getSrcAccessMask() | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
6062 const VkAccessFlags newDstFlags = dependency.getDstAccessMask() | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT;
6063 dependency.setDstAccessMask(newSrcFlags);
6064 dependency.setDstAccessMask(newDstFlags);
6065 foundDuplicate = true;
6070 if (!foundDuplicate)
6072 deps.push_back(newDependency);
6076 lastUseOfAttachment[*depthStencilAttachment] = just(subpassIndex);
6078 depthStencilAttachmentReference = AttachmentReference(*depthStencilAttachment, VK_IMAGE_LAYOUT_GENERAL);
6081 depthStencilAttachmentReference = AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL);
6083 vector<deUint32> preserveAttachments;
6084 for (deUint32 attachmentIndex = 0; attachmentIndex < (deUint32)attachments.size(); attachmentIndex++)
6086 if (lastUseOfAttachment[attachmentIndex] && (*lastUseOfAttachment[attachmentIndex]) != subpassIndex)
6087 preserveAttachments.push_back(attachmentIndex);
6090 // Use random image layout when possible
6091 for (size_t colorRefIdx = 0; colorRefIdx < colorAttachmentReferences.size(); ++colorRefIdx)
6093 bool usedAsInput = false;
6094 for (size_t inputRefIdx = 0; inputRefIdx < inputAttachmentReferences.size(); ++inputRefIdx)
6095 if (colorAttachmentReferences[colorRefIdx].getAttachment() == inputAttachmentReferences[inputRefIdx].getAttachment())
6099 colorAttachmentReferences[colorRefIdx].setImageLayout(rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayoutsColor), DE_ARRAY_END(subpassLayoutsColor)));
6101 for (size_t inputRefIdx = 0; inputRefIdx < inputAttachmentReferences.size(); ++inputRefIdx)
6103 bool usedAsDepthStencil = inputAttachmentReferences[inputRefIdx].getAttachment() == depthStencilAttachmentReference.getAttachment();
6104 bool usedAsColor = false;
6105 for (size_t colorRefIdx = 0; colorRefIdx < colorAttachmentReferences.size(); ++colorRefIdx)
6106 if (inputAttachmentReferences[inputRefIdx].getAttachment() == colorAttachmentReferences[colorRefIdx].getAttachment())
6109 if (!usedAsColor && !usedAsDepthStencil)
6110 inputAttachmentReferences[inputRefIdx].setImageLayout(rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayoutsInput), DE_ARRAY_END(subpassLayoutsInput)));
6113 bool usedAsInput = false;
6114 for (size_t inputRefIdx = 0; inputRefIdx < inputAttachmentReferences.size(); ++inputRefIdx)
6115 if (depthStencilAttachmentReference.getAttachment() == inputAttachmentReferences[inputRefIdx].getAttachment())
6119 depthStencilAttachmentReference.setImageLayout(rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayoutsDepthStencil), DE_ARRAY_END(subpassLayoutsDepthStencil)));
6122 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
6123 inputAttachmentReferences,
6124 colorAttachmentReferences,
6125 vector<AttachmentReference>(),
6126 depthStencilAttachmentReference,
6127 preserveAttachments));
6131 const TestConfig::RenderTypes render = rng.choose<TestConfig::RenderTypes>(DE_ARRAY_BEGIN(renderCommands), DE_ARRAY_END(renderCommands));
6132 const TestConfig::CommandBufferTypes commandBuffer = rng.choose<TestConfig::CommandBufferTypes>(DE_ARRAY_BEGIN(commandBuffers), DE_ARRAY_END(commandBuffers));
6133 const TestConfig::ImageMemory imageMemory = rng.choose<TestConfig::ImageMemory>(DE_ARRAY_BEGIN(imageMemories), DE_ARRAY_END(imageMemories));
6135 const string testCaseName = de::toString(testCaseNdx);
6136 const UVec2 targetSize = rng.choose<UVec2>(DE_ARRAY_BEGIN(targetSizes), DE_ARRAY_END(targetSizes));
6137 const UVec2 renderPos = rng.choose<UVec2>(DE_ARRAY_BEGIN(renderPositions), DE_ARRAY_END(renderPositions));
6138 const UVec2 renderSize = rng.choose<UVec2>(DE_ARRAY_BEGIN(renderSizes), DE_ARRAY_END(renderSizes));
6140 const RenderPass renderPass (attachments, subpasses, deps);
6141 const TestConfig testConfig (renderPass,
6151 testConfigExternal.allocationKind,
6152 testConfigExternal.groupParams);
6154 addFunctionCaseWithPrograms<TestConfig>(allocationTypeGroup.get(), testCaseName.c_str(), testCaseName.c_str(), createTestShaders, renderPassTest, testConfig);
6159 const deUint32 attachmentCount = rng.choose<deUint32>(DE_ARRAY_BEGIN(attachmentCounts), DE_ARRAY_END(attachmentCounts));
6160 vector<Attachment> attachments;
6161 vector<Subpass> subpasses;
6163 for (size_t attachmentNdx = 0; attachmentNdx < attachmentCount; attachmentNdx++)
6165 const VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_1_BIT;
6166 const VkFormat format = rng.choose<VkFormat>(DE_ARRAY_BEGIN(s_coreColorFormats), DE_ARRAY_END(s_coreColorFormats));
6167 const VkAttachmentLoadOp loadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
6168 const VkAttachmentStoreOp storeOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
6170 const VkImageLayout initialLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalColorLayouts), DE_ARRAY_END(initialAndFinalColorLayouts));
6171 const VkImageLayout finalizeLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalColorLayouts), DE_ARRAY_END(initialAndFinalColorLayouts));
6173 const VkAttachmentLoadOp stencilLoadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
6174 const VkAttachmentStoreOp stencilStoreOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
6176 attachments.push_back(Attachment(format, sampleCount, loadOp, storeOp, stencilLoadOp, stencilStoreOp, initialLayout, finalizeLayout));
6179 if (allocationType == ALLOCATIONTYPE_GROW)
6181 for (size_t subpassNdx = 0; subpassNdx < attachmentCount; subpassNdx++)
6183 vector<AttachmentReference> colorAttachmentReferences;
6185 for (size_t attachmentNdx = 0; attachmentNdx < subpassNdx + 1; attachmentNdx++)
6187 const VkImageLayout subpassLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayoutsColor), DE_ARRAY_END(subpassLayoutsColor));
6189 colorAttachmentReferences.push_back(AttachmentReference((deUint32)attachmentNdx, subpassLayout));
6192 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
6193 vector<AttachmentReference>(),
6194 colorAttachmentReferences,
6195 vector<AttachmentReference>(),
6196 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6197 vector<deUint32>()));
6200 else if (allocationType == ALLOCATIONTYPE_SHRINK)
6202 for (size_t subpassNdx = 0; subpassNdx < attachmentCount; subpassNdx++)
6204 vector<AttachmentReference> colorAttachmentReferences;
6206 for (size_t attachmentNdx = 0; attachmentNdx < (attachmentCount - subpassNdx); attachmentNdx++)
6208 const VkImageLayout subpassLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayoutsColor), DE_ARRAY_END(subpassLayoutsColor));
6210 colorAttachmentReferences.push_back(AttachmentReference((deUint32)attachmentNdx, subpassLayout));
6213 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
6214 vector<AttachmentReference>(),
6215 colorAttachmentReferences,
6216 vector<AttachmentReference>(),
6217 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6218 vector<deUint32>()));
6221 else if (allocationType == ALLOCATIONTYPE_ROLL)
6223 for (size_t subpassNdx = 0; subpassNdx < attachmentCount / 2; subpassNdx++)
6225 vector<AttachmentReference> colorAttachmentReferences;
6227 for (size_t attachmentNdx = 0; attachmentNdx < attachmentCount / 2; attachmentNdx++)
6229 const VkImageLayout subpassLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayoutsColor), DE_ARRAY_END(subpassLayoutsColor));
6231 colorAttachmentReferences.push_back(AttachmentReference((deUint32)(subpassNdx + attachmentNdx), subpassLayout));
6234 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
6235 vector<AttachmentReference>(),
6236 colorAttachmentReferences,
6237 vector<AttachmentReference>(),
6238 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6239 vector<deUint32>()));
6242 else if (allocationType == ALLOCATIONTYPE_GROW_SHRINK)
6244 for (size_t subpassNdx = 0; subpassNdx < attachmentCount; subpassNdx++)
6246 vector<AttachmentReference> colorAttachmentReferences;
6248 for (size_t attachmentNdx = 0; attachmentNdx < subpassNdx + 1; attachmentNdx++)
6250 const VkImageLayout subpassLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayoutsColor), DE_ARRAY_END(subpassLayoutsColor));
6252 colorAttachmentReferences.push_back(AttachmentReference((deUint32)attachmentNdx, subpassLayout));
6255 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
6256 vector<AttachmentReference>(),
6257 colorAttachmentReferences,
6258 vector<AttachmentReference>(),
6259 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6260 vector<deUint32>()));
6262 for (size_t subpassNdx = 0; subpassNdx < attachmentCount; subpassNdx++)
6264 vector<AttachmentReference> colorAttachmentReferences;
6266 for (size_t attachmentNdx = 0; attachmentNdx < (attachmentCount - subpassNdx); attachmentNdx++)
6268 const VkImageLayout subpassLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayoutsColor), DE_ARRAY_END(subpassLayoutsColor));
6270 colorAttachmentReferences.push_back(AttachmentReference((deUint32)attachmentNdx, subpassLayout));
6273 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
6274 vector<AttachmentReference>(),
6275 colorAttachmentReferences,
6276 vector<AttachmentReference>(),
6277 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6278 vector<deUint32>()));
6281 else if (allocationType == ALLOCATIONTYPE_IO_CHAIN)
6283 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
6284 vector<AttachmentReference>(),
6285 vector<AttachmentReference>(1, AttachmentReference(0, rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayoutsColor), DE_ARRAY_END(subpassLayoutsColor)))),
6286 vector<AttachmentReference>(),
6287 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6288 vector<deUint32>()));
6290 for (size_t subpassNdx = 1; subpassNdx < attachmentCount; subpassNdx++)
6292 const VkImageAspectFlags inputAttachmentAspectMask = (testConfigExternal.groupParams->renderingType == RENDERING_TYPE_RENDERPASS2) ? VK_IMAGE_ASPECT_COLOR_BIT : static_cast<VkImageAspectFlagBits>(0);
6293 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
6294 vector<AttachmentReference>(1, AttachmentReference((deUint32)(subpassNdx - 1), VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, inputAttachmentAspectMask)),
6295 vector<AttachmentReference>(1, AttachmentReference((deUint32)(subpassNdx), rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayoutsColor), DE_ARRAY_END(subpassLayoutsColor)))),
6296 vector<AttachmentReference>(),
6297 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6298 vector<deUint32>()));
6302 DE_FATAL("Unknown allocation type");
6305 const TestConfig::RenderTypes render = rng.choose<TestConfig::RenderTypes>(DE_ARRAY_BEGIN(renderCommands), DE_ARRAY_END(renderCommands));
6306 const TestConfig::CommandBufferTypes commandBuffer = rng.choose<TestConfig::CommandBufferTypes>(DE_ARRAY_BEGIN(commandBuffers), DE_ARRAY_END(commandBuffers));
6307 const TestConfig::ImageMemory imageMemory = rng.choose<TestConfig::ImageMemory>(DE_ARRAY_BEGIN(imageMemories), DE_ARRAY_END(imageMemories));
6309 const string testCaseName = de::toString(testCaseNdx);
6310 const UVec2 targetSize = rng.choose<UVec2>(DE_ARRAY_BEGIN(targetSizes), DE_ARRAY_END(targetSizes));
6311 const UVec2 renderPos = rng.choose<UVec2>(DE_ARRAY_BEGIN(renderPositions), DE_ARRAY_END(renderPositions));
6312 const UVec2 renderSize = rng.choose<UVec2>(DE_ARRAY_BEGIN(renderSizes), DE_ARRAY_END(renderSizes));
6314 vector<SubpassDependency> deps;
6316 for (size_t subpassNdx = 0; subpassNdx < subpasses.size() - 1; subpassNdx++)
6318 const bool byRegion = rng.getBool();
6319 deps.push_back(SubpassDependency((deUint32)subpassNdx, (deUint32)subpassNdx + 1,
6320 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
6321 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
6322 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
6323 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
6325 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
6326 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
6327 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
6328 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
6330 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
6331 (VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT),
6333 byRegion ? (VkDependencyFlags)VK_DEPENDENCY_BY_REGION_BIT : 0u));
6336 const RenderPass renderPass (attachments, subpasses, deps);
6337 const TestConfig testConfig (renderPass,
6347 testConfigExternal.allocationKind,
6348 testConfigExternal.groupParams);
6350 addFunctionCaseWithPrograms<TestConfig>(allocationTypeGroup.get(), testCaseName.c_str(), testCaseName.c_str(), createTestShaders, renderPassTest, testConfig);
6354 group->addChild(allocationTypeGroup.release());
6358 void addSimpleTests (tcu::TestCaseGroup* group, const TestConfigExternal testConfigExternal)
6360 const UVec2 targetSize (64, 64);
6361 const UVec2 renderPos (0, 0);
6362 const UVec2 renderSize (64, 64);
6366 const RenderPass renderPass (vector<Attachment>(1, Attachment(VK_FORMAT_R8G8B8A8_UNORM,
6367 VK_SAMPLE_COUNT_1_BIT,
6368 VK_ATTACHMENT_LOAD_OP_CLEAR,
6369 VK_ATTACHMENT_STORE_OP_STORE,
6370 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6371 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6372 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
6373 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6374 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6376 vector<AttachmentReference>(),
6377 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6378 vector<AttachmentReference>(),
6379 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6380 vector<deUint32>())),
6381 vector<SubpassDependency>());
6382 const TestConfig testConfig (renderPass,
6383 TestConfig::RENDERTYPES_DRAW,
6384 TestConfig::COMMANDBUFFERTYPES_INLINE,
6385 TestConfig::IMAGEMEMORY_STRICT,
6392 testConfigExternal.allocationKind,
6393 testConfigExternal.groupParams);
6395 addFunctionCaseWithPrograms<TestConfig>(group, "color", "Single color attachment case.", createTestShaders, renderPassTest, testConfig);
6400 const RenderPass renderPass (vector<Attachment>(1, Attachment(VK_FORMAT_X8_D24_UNORM_PACK32,
6401 VK_SAMPLE_COUNT_1_BIT,
6402 VK_ATTACHMENT_LOAD_OP_CLEAR,
6403 VK_ATTACHMENT_STORE_OP_STORE,
6404 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6405 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6406 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
6407 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)),
6408 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6410 vector<AttachmentReference>(),
6411 vector<AttachmentReference>(),
6412 vector<AttachmentReference>(),
6413 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
6414 vector<deUint32>())),
6415 vector<SubpassDependency>());
6416 const TestConfig testConfig (renderPass,
6417 TestConfig::RENDERTYPES_DRAW,
6418 TestConfig::COMMANDBUFFERTYPES_INLINE,
6419 TestConfig::IMAGEMEMORY_STRICT,
6426 testConfigExternal.allocationKind,
6427 testConfigExternal.groupParams);
6429 addFunctionCaseWithPrograms<TestConfig>(group, "depth", "Single depth attachment case.", createTestShaders, renderPassTest, testConfig);
6434 const RenderPass renderPass (vector<Attachment>(1, Attachment(VK_FORMAT_S8_UINT,
6435 VK_SAMPLE_COUNT_1_BIT,
6436 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6437 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6438 VK_ATTACHMENT_LOAD_OP_CLEAR,
6439 VK_ATTACHMENT_STORE_OP_STORE,
6440 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
6441 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)),
6442 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6444 vector<AttachmentReference>(),
6445 vector<AttachmentReference>(),
6446 vector<AttachmentReference>(),
6447 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
6448 vector<deUint32>())),
6449 vector<SubpassDependency>());
6450 const TestConfig testConfig (renderPass,
6451 TestConfig::RENDERTYPES_DRAW,
6452 TestConfig::COMMANDBUFFERTYPES_INLINE,
6453 TestConfig::IMAGEMEMORY_STRICT,
6460 testConfigExternal.allocationKind,
6461 testConfigExternal.groupParams);
6463 addFunctionCaseWithPrograms<TestConfig>(group, "stencil", "Single stencil attachment case.", createTestShaders, renderPassTest, testConfig);
6468 const RenderPass renderPass (vector<Attachment>(1, Attachment(VK_FORMAT_D24_UNORM_S8_UINT,
6469 VK_SAMPLE_COUNT_1_BIT,
6470 VK_ATTACHMENT_LOAD_OP_CLEAR,
6471 VK_ATTACHMENT_STORE_OP_STORE,
6472 VK_ATTACHMENT_LOAD_OP_CLEAR,
6473 VK_ATTACHMENT_STORE_OP_STORE,
6474 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
6475 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)),
6476 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6478 vector<AttachmentReference>(),
6479 vector<AttachmentReference>(),
6480 vector<AttachmentReference>(),
6481 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
6482 vector<deUint32>())),
6483 vector<SubpassDependency>());
6484 const TestConfig testConfig (renderPass,
6485 TestConfig::RENDERTYPES_DRAW,
6486 TestConfig::COMMANDBUFFERTYPES_INLINE,
6487 TestConfig::IMAGEMEMORY_STRICT,
6494 testConfigExternal.allocationKind,
6495 testConfigExternal.groupParams);
6497 addFunctionCaseWithPrograms<TestConfig>(group, "depth_stencil", "Single depth stencil attachment case.", createTestShaders, renderPassTest, testConfig);
6502 const Attachment attachments[] =
6504 Attachment(VK_FORMAT_R8G8B8A8_UNORM,
6505 VK_SAMPLE_COUNT_1_BIT,
6506 VK_ATTACHMENT_LOAD_OP_CLEAR,
6507 VK_ATTACHMENT_STORE_OP_STORE,
6508 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6509 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6510 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
6511 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL),
6512 Attachment(VK_FORMAT_X8_D24_UNORM_PACK32,
6513 VK_SAMPLE_COUNT_1_BIT,
6514 VK_ATTACHMENT_LOAD_OP_CLEAR,
6515 VK_ATTACHMENT_STORE_OP_STORE,
6516 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6517 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6518 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
6519 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
6522 const RenderPass renderPass (vector<Attachment>(DE_ARRAY_BEGIN(attachments), DE_ARRAY_END(attachments)),
6523 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6525 vector<AttachmentReference>(),
6526 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6527 vector<AttachmentReference>(),
6528 AttachmentReference(1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
6529 vector<deUint32>())),
6530 vector<SubpassDependency>());
6531 const TestConfig testConfig (renderPass,
6532 TestConfig::RENDERTYPES_DRAW,
6533 TestConfig::COMMANDBUFFERTYPES_INLINE,
6534 TestConfig::IMAGEMEMORY_STRICT,
6541 testConfigExternal.allocationKind,
6542 testConfigExternal.groupParams);
6544 addFunctionCaseWithPrograms<TestConfig>(group, "color_depth", "Color and depth attachment case.", createTestShaders, renderPassTest, testConfig);
6549 const Attachment attachments[] =
6551 Attachment(VK_FORMAT_R8G8B8A8_UNORM,
6552 VK_SAMPLE_COUNT_1_BIT,
6553 VK_ATTACHMENT_LOAD_OP_CLEAR,
6554 VK_ATTACHMENT_STORE_OP_STORE,
6555 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6556 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6557 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
6558 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL),
6559 Attachment(VK_FORMAT_S8_UINT,
6560 VK_SAMPLE_COUNT_1_BIT,
6561 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6562 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6563 VK_ATTACHMENT_LOAD_OP_CLEAR,
6564 VK_ATTACHMENT_STORE_OP_STORE,
6565 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
6566 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
6569 const RenderPass renderPass (vector<Attachment>(DE_ARRAY_BEGIN(attachments), DE_ARRAY_END(attachments)),
6570 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6572 vector<AttachmentReference>(),
6573 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6574 vector<AttachmentReference>(),
6575 AttachmentReference(1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
6576 vector<deUint32>())),
6577 vector<SubpassDependency>());
6578 const TestConfig testConfig (renderPass,
6579 TestConfig::RENDERTYPES_DRAW,
6580 TestConfig::COMMANDBUFFERTYPES_INLINE,
6581 TestConfig::IMAGEMEMORY_STRICT,
6588 testConfigExternal.allocationKind,
6589 testConfigExternal.groupParams);
6591 addFunctionCaseWithPrograms<TestConfig>(group, "color_stencil", "Color and stencil attachment case.", createTestShaders, renderPassTest, testConfig);
6594 // color_depth_stencil
6596 const Attachment attachments[] =
6598 Attachment(VK_FORMAT_R8G8B8A8_UNORM,
6599 VK_SAMPLE_COUNT_1_BIT,
6600 VK_ATTACHMENT_LOAD_OP_CLEAR,
6601 VK_ATTACHMENT_STORE_OP_STORE,
6602 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6603 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6604 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
6605 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL),
6606 Attachment(VK_FORMAT_D24_UNORM_S8_UINT,
6607 VK_SAMPLE_COUNT_1_BIT,
6608 VK_ATTACHMENT_LOAD_OP_CLEAR,
6609 VK_ATTACHMENT_STORE_OP_STORE,
6610 VK_ATTACHMENT_LOAD_OP_CLEAR,
6611 VK_ATTACHMENT_STORE_OP_STORE,
6612 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
6613 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
6616 const RenderPass renderPass (vector<Attachment>(DE_ARRAY_BEGIN(attachments), DE_ARRAY_END(attachments)),
6617 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6619 vector<AttachmentReference>(),
6620 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6621 vector<AttachmentReference>(),
6622 AttachmentReference(1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
6623 vector<deUint32>())),
6624 vector<SubpassDependency>());
6625 const TestConfig testConfig (renderPass,
6626 TestConfig::RENDERTYPES_DRAW,
6627 TestConfig::COMMANDBUFFERTYPES_INLINE,
6628 TestConfig::IMAGEMEMORY_STRICT,
6635 testConfigExternal.allocationKind,
6636 testConfigExternal.groupParams);
6638 addFunctionCaseWithPrograms<TestConfig>(group, "color_depth_stencil", "Color, depth and stencil attachment case.", createTestShaders, renderPassTest, testConfig);
6643 const RenderPass renderPass (vector<Attachment>(),
6644 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6646 vector<AttachmentReference>(),
6647 vector<AttachmentReference>(),
6648 vector<AttachmentReference>(),
6649 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6650 vector<deUint32>())),
6651 vector<SubpassDependency>());
6652 const TestConfig testConfig (renderPass,
6653 TestConfig::RENDERTYPES_DRAW,
6654 TestConfig::COMMANDBUFFERTYPES_INLINE,
6655 TestConfig::IMAGEMEMORY_STRICT,
6662 testConfigExternal.allocationKind,
6663 testConfigExternal.groupParams);
6665 addFunctionCaseWithPrograms<TestConfig>(group, "no_attachments", "No attachments case.", createTestShaders, renderPassTest, testConfig);
6668 // color_unused_omit_blend_state
6669 if (testConfigExternal.groupParams->renderingType != RENDERING_TYPE_DYNAMIC_RENDERING)
6671 vector<Subpass> subpasses;
6673 // First subpass: use color attachment, create pipeline with color blend state
6674 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6676 vector<AttachmentReference>(),
6677 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6678 vector<AttachmentReference>(),
6679 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6683 // Second subpass: don't use color attachment, create pipeline without color blend state
6684 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6686 vector<AttachmentReference>(),
6687 vector<AttachmentReference>(1, AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6688 vector<AttachmentReference>(),
6689 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6693 const RenderPass renderPass (vector<Attachment>(1, Attachment(VK_FORMAT_R8G8B8A8_UNORM,
6694 VK_SAMPLE_COUNT_1_BIT,
6695 VK_ATTACHMENT_LOAD_OP_CLEAR,
6696 VK_ATTACHMENT_STORE_OP_STORE,
6697 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6698 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6699 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
6700 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6702 vector<SubpassDependency>());
6704 const TestConfig testConfig (renderPass,
6705 TestConfig::RENDERTYPES_DRAW,
6706 TestConfig::COMMANDBUFFERTYPES_INLINE,
6707 TestConfig::IMAGEMEMORY_STRICT,
6714 testConfigExternal.allocationKind,
6715 testConfigExternal.groupParams);
6716 addFunctionCaseWithPrograms<TestConfig>(group, "color_unused_omit_blend_state", "Two unused color attachment case without blend state", createTestShaders, renderPassTest, testConfig);
6720 std::string formatToName (VkFormat format)
6722 const std::string formatStr = de::toString(format);
6723 const std::string prefix = "VK_FORMAT_";
6725 DE_ASSERT(formatStr.substr(0, prefix.length()) == prefix);
6727 return de::toLower(formatStr.substr(prefix.length()));
6730 void addFormatTests (tcu::TestCaseGroup* group, const TestConfigExternal testConfigExternal)
6732 tcu::TestContext& testCtx = group->getTestContext();
6734 const UVec2 targetSize (64, 64);
6735 const UVec2 renderPos (0, 0);
6736 const UVec2 renderSize (64, 64);
6740 const char* const str;
6741 const VkAttachmentStoreOp op;
6744 { "store", VK_ATTACHMENT_STORE_OP_STORE },
6745 { "dont_care", VK_ATTACHMENT_STORE_OP_DONT_CARE }
6750 const char* const str;
6751 const VkAttachmentLoadOp op;
6754 { "clear", VK_ATTACHMENT_LOAD_OP_CLEAR },
6755 { "load", VK_ATTACHMENT_LOAD_OP_LOAD },
6756 { "dont_care", VK_ATTACHMENT_LOAD_OP_DONT_CARE }
6761 const char* const str;
6762 const TestConfig::RenderTypes types;
6765 { "clear", TestConfig::RENDERTYPES_CLEAR },
6766 { "draw", TestConfig::RENDERTYPES_DRAW },
6767 { "clear_draw", TestConfig::RENDERTYPES_CLEAR|TestConfig::RENDERTYPES_DRAW }
6771 for (size_t formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(s_coreColorFormats); formatNdx++)
6773 const VkFormat format = s_coreColorFormats[formatNdx];
6774 de::MovePtr<tcu::TestCaseGroup> formatGroup (new tcu::TestCaseGroup(testCtx, formatToName(format).c_str(), de::toString(format).c_str()));
6776 for (size_t loadOpNdx = 0; loadOpNdx < DE_LENGTH_OF_ARRAY(loadOps); loadOpNdx++)
6778 const VkAttachmentLoadOp loadOp = loadOps[loadOpNdx].op;
6779 de::MovePtr<tcu::TestCaseGroup> loadOpGroup (new tcu::TestCaseGroup(testCtx, loadOps[loadOpNdx].str, loadOps[loadOpNdx].str));
6781 for (size_t renderTypeNdx = 0; renderTypeNdx < DE_LENGTH_OF_ARRAY(renderTypes); renderTypeNdx++)
6783 const RenderPass renderPass (vector<Attachment>(1, Attachment(format,
6784 VK_SAMPLE_COUNT_1_BIT,
6786 VK_ATTACHMENT_STORE_OP_STORE,
6787 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6788 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6789 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
6790 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6791 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6793 vector<AttachmentReference>(),
6794 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6795 vector<AttachmentReference>(),
6796 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6797 vector<deUint32>())),
6798 vector<SubpassDependency>());
6799 const TestConfig testConfig (renderPass,
6800 renderTypes[renderTypeNdx].types,
6801 TestConfig::COMMANDBUFFERTYPES_INLINE,
6802 TestConfig::IMAGEMEMORY_STRICT,
6809 testConfigExternal.allocationKind,
6810 testConfigExternal.groupParams);
6812 addFunctionCaseWithPrograms<TestConfig>(loadOpGroup.get(), renderTypes[renderTypeNdx].str, renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
6815 formatGroup->addChild(loadOpGroup.release());
6818 if (testConfigExternal.groupParams->renderingType != RENDERING_TYPE_DYNAMIC_RENDERING)
6820 de::MovePtr<tcu::TestCaseGroup> inputGroup (new tcu::TestCaseGroup(testCtx, "input", "Test attachment format as input"));
6822 for (size_t loadOpNdx = 0; loadOpNdx < DE_LENGTH_OF_ARRAY(loadOps); loadOpNdx++)
6824 const VkAttachmentLoadOp loadOp = loadOps[loadOpNdx].op;
6825 de::MovePtr<tcu::TestCaseGroup> loadOpGroup (new tcu::TestCaseGroup(testCtx, loadOps[loadOpNdx].str, loadOps[loadOpNdx].str));
6827 for (size_t storeOpNdx = 0; storeOpNdx < DE_LENGTH_OF_ARRAY(storeOps); storeOpNdx++)
6829 const VkImageAspectFlags inputAttachmentAspectMask = (testConfigExternal.groupParams->renderingType == RENDERING_TYPE_RENDERPASS2)
6830 ? static_cast<VkImageAspectFlags>(VK_IMAGE_ASPECT_COLOR_BIT)
6831 : static_cast<VkImageAspectFlags>(0);
6832 const VkAttachmentStoreOp storeOp = storeOps[storeOpNdx].op;
6833 de::MovePtr<tcu::TestCaseGroup> storeOpGroup (new tcu::TestCaseGroup(testCtx, storeOps[storeOpNdx].str, storeOps[storeOpNdx].str));
6835 for (size_t useInputAspectNdx = 0; useInputAspectNdx < 2; useInputAspectNdx++)
6837 const bool useInputAspect = useInputAspectNdx != 0;
6839 if (testConfigExternal.groupParams->renderingType == RENDERING_TYPE_RENDERPASS2 && useInputAspect)
6842 for (size_t renderTypeNdx = 0; renderTypeNdx < DE_LENGTH_OF_ARRAY(renderTypes); renderTypeNdx++)
6845 vector<Attachment> attachments;
6846 vector<Subpass> subpasses;
6847 vector<SubpassDependency> deps;
6848 vector<VkInputAttachmentAspectReference> inputAspects;
6850 attachments.push_back(Attachment(format,
6851 VK_SAMPLE_COUNT_1_BIT,
6854 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6855 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6856 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
6857 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
6859 attachments.push_back(Attachment(vk::VK_FORMAT_R8G8B8A8_UNORM,
6860 VK_SAMPLE_COUNT_1_BIT,
6861 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6862 VK_ATTACHMENT_STORE_OP_STORE,
6863 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6864 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6865 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
6866 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
6868 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6870 vector<AttachmentReference>(),
6871 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6872 vector<AttachmentReference>(),
6873 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6874 vector<deUint32>()));
6875 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6877 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, inputAttachmentAspectMask)),
6878 vector<AttachmentReference>(1, AttachmentReference(1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6879 vector<AttachmentReference>(),
6880 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6881 vector<deUint32>()));
6883 deps.push_back(SubpassDependency(0, 1,
6885 vk::VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
6886 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
6888 vk::VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
6889 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
6890 vk::VK_DEPENDENCY_BY_REGION_BIT));
6894 const VkInputAttachmentAspectReference inputAspect =
6898 VK_IMAGE_ASPECT_COLOR_BIT
6901 inputAspects.push_back(inputAspect);
6905 const RenderPass renderPass (attachments, subpasses, deps, inputAspects);
6906 const TestConfig testConfig (renderPass,
6907 renderTypes[renderTypeNdx].types,
6908 TestConfig::COMMANDBUFFERTYPES_INLINE,
6909 TestConfig::IMAGEMEMORY_STRICT,
6916 testConfigExternal.allocationKind,
6917 testConfigExternal.groupParams);
6918 const string testName (renderTypes[renderTypeNdx].str + string(useInputAspect ? "_use_input_aspect" : ""));
6920 addFunctionCaseWithPrograms<TestConfig>(storeOpGroup.get(), testName, renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
6924 vector<Attachment> attachments;
6925 vector<Subpass> subpasses;
6926 vector<SubpassDependency> deps;
6927 vector<VkInputAttachmentAspectReference> inputAspects;
6929 attachments.push_back(Attachment(format,
6930 VK_SAMPLE_COUNT_1_BIT,
6933 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6934 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6935 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
6936 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
6938 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6940 vector<AttachmentReference>(),
6941 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6942 vector<AttachmentReference>(),
6943 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6944 vector<deUint32>()));
6945 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6947 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_GENERAL, inputAttachmentAspectMask)),
6948 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_GENERAL)),
6949 vector<AttachmentReference>(),
6950 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6951 vector<deUint32>()));
6953 deps.push_back(SubpassDependency(0, 1,
6954 vk::VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
6955 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
6957 vk::VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
6958 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
6959 vk::VK_DEPENDENCY_BY_REGION_BIT));
6961 deps.push_back(SubpassDependency(1, 1,
6962 vk::VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
6963 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
6965 vk::VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
6966 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
6967 vk::VK_DEPENDENCY_BY_REGION_BIT));
6971 const VkInputAttachmentAspectReference inputAspect =
6975 VK_IMAGE_ASPECT_COLOR_BIT
6978 inputAspects.push_back(inputAspect);
6982 const RenderPass renderPass (attachments, subpasses, deps, inputAspects);
6983 const TestConfig testConfig (renderPass,
6984 renderTypes[renderTypeNdx].types,
6985 TestConfig::COMMANDBUFFERTYPES_INLINE,
6986 TestConfig::IMAGEMEMORY_STRICT,
6993 testConfigExternal.allocationKind,
6994 testConfigExternal.groupParams);
6995 const string testName (string("self_dep_") + renderTypes[renderTypeNdx].str + (useInputAspect ? "_use_input_aspect" : ""));
6997 addFunctionCaseWithPrograms<TestConfig>(storeOpGroup.get(), testName, string("self_dep_") + renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
7003 loadOpGroup->addChild(storeOpGroup.release());
7006 inputGroup->addChild(loadOpGroup.release());
7009 formatGroup->addChild(inputGroup.release());
7012 group->addChild(formatGroup.release());
7015 // Depth stencil formats
7016 for (size_t formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(s_coreDepthStencilFormats); formatNdx++)
7018 const VkFormat vkFormat = s_coreDepthStencilFormats[formatNdx];
7019 const tcu::TextureFormat format = mapVkFormat(vkFormat);
7020 const bool isStencilAttachment = hasStencilComponent(format.order);
7021 const bool isDepthAttachment = hasDepthComponent(format.order);
7022 const VkImageAspectFlags formatAspectFlags = (isDepthAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_DEPTH_BIT : 0u)
7023 | (isStencilAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_STENCIL_BIT : 0u);
7024 de::MovePtr<tcu::TestCaseGroup> formatGroup (new tcu::TestCaseGroup(testCtx, formatToName(vkFormat).c_str(), de::toString(vkFormat).c_str()));
7026 for (size_t loadOpNdx = 0; loadOpNdx < DE_LENGTH_OF_ARRAY(loadOps); loadOpNdx++)
7028 const VkAttachmentLoadOp loadOp = loadOps[loadOpNdx].op;
7029 de::MovePtr<tcu::TestCaseGroup> loadOpGroup (new tcu::TestCaseGroup(testCtx, loadOps[loadOpNdx].str, loadOps[loadOpNdx].str));
7031 for (size_t renderTypeNdx = 0; renderTypeNdx < DE_LENGTH_OF_ARRAY(renderTypes); renderTypeNdx++)
7034 const RenderPass renderPass (vector<Attachment>(1, Attachment(vkFormat,
7035 VK_SAMPLE_COUNT_1_BIT,
7036 isDepthAttachment ? loadOp : VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7037 isDepthAttachment ? VK_ATTACHMENT_STORE_OP_STORE :VK_ATTACHMENT_STORE_OP_DONT_CARE,
7038 isStencilAttachment ? loadOp : VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7039 isStencilAttachment ? VK_ATTACHMENT_STORE_OP_STORE :VK_ATTACHMENT_STORE_OP_DONT_CARE,
7040 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
7041 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)),
7042 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7044 vector<AttachmentReference>(),
7045 vector<AttachmentReference>(),
7046 vector<AttachmentReference>(),
7047 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
7048 vector<deUint32>())),
7049 vector<SubpassDependency>());
7050 const TestConfig testConfig (renderPass,
7051 renderTypes[renderTypeNdx].types,
7052 TestConfig::COMMANDBUFFERTYPES_INLINE,
7053 TestConfig::IMAGEMEMORY_STRICT,
7060 testConfigExternal.allocationKind,
7061 testConfigExternal.groupParams);
7063 addFunctionCaseWithPrograms<TestConfig>(loadOpGroup.get(), renderTypes[renderTypeNdx].str, renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
7066 if (isStencilAttachment && isDepthAttachment && loadOp != VK_ATTACHMENT_LOAD_OP_CLEAR)
7069 const RenderPass renderPass (vector<Attachment>(1, Attachment(vkFormat,
7070 VK_SAMPLE_COUNT_1_BIT,
7071 isDepthAttachment ? loadOp : VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7072 isDepthAttachment ? VK_ATTACHMENT_STORE_OP_STORE :VK_ATTACHMENT_STORE_OP_DONT_CARE,
7073 isStencilAttachment ? loadOp : VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7074 isStencilAttachment ? VK_ATTACHMENT_STORE_OP_STORE :VK_ATTACHMENT_STORE_OP_DONT_CARE,
7075 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
7076 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)),
7077 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7079 vector<AttachmentReference>(),
7080 vector<AttachmentReference>(),
7081 vector<AttachmentReference>(),
7082 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL),
7083 vector<deUint32>())),
7084 vector<SubpassDependency>());
7085 const TestConfig testConfig (renderPass,
7086 renderTypes[renderTypeNdx].types,
7087 TestConfig::COMMANDBUFFERTYPES_INLINE,
7088 TestConfig::IMAGEMEMORY_STRICT,
7095 testConfigExternal.allocationKind,
7096 testConfigExternal.groupParams);
7097 const string testName (string(renderTypes[renderTypeNdx].str) + "_depth_read_only");
7099 addFunctionCaseWithPrograms<TestConfig>(loadOpGroup.get(), testName, renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
7103 const RenderPass renderPass (vector<Attachment>(1, Attachment(vkFormat,
7104 VK_SAMPLE_COUNT_1_BIT,
7105 isDepthAttachment ? loadOp : VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7106 isDepthAttachment ? VK_ATTACHMENT_STORE_OP_STORE :VK_ATTACHMENT_STORE_OP_DONT_CARE,
7107 isStencilAttachment ? loadOp : VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7108 isStencilAttachment ? VK_ATTACHMENT_STORE_OP_STORE :VK_ATTACHMENT_STORE_OP_DONT_CARE,
7109 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
7110 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)),
7111 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7113 vector<AttachmentReference>(),
7114 vector<AttachmentReference>(),
7115 vector<AttachmentReference>(),
7116 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL),
7117 vector<deUint32>())),
7118 vector<SubpassDependency>());
7119 const TestConfig testConfig (renderPass,
7120 renderTypes[renderTypeNdx].types,
7121 TestConfig::COMMANDBUFFERTYPES_INLINE,
7122 TestConfig::IMAGEMEMORY_STRICT,
7129 testConfigExternal.allocationKind,
7130 testConfigExternal.groupParams);
7131 const string testName (string(renderTypes[renderTypeNdx].str) + "_stencil_read_only");
7133 addFunctionCaseWithPrograms<TestConfig>(loadOpGroup.get(), testName, renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
7138 formatGroup->addChild(loadOpGroup.release());
7141 if (testConfigExternal.groupParams->renderingType != RENDERING_TYPE_DYNAMIC_RENDERING)
7143 de::MovePtr<tcu::TestCaseGroup> inputGroup (new tcu::TestCaseGroup(testCtx, "input", "Test attachment format as input"));
7145 for (size_t loadOpNdx = 0; loadOpNdx < DE_LENGTH_OF_ARRAY(loadOps); loadOpNdx++)
7147 const VkAttachmentLoadOp loadOp = loadOps[loadOpNdx].op;
7148 de::MovePtr<tcu::TestCaseGroup> loadOpGroup (new tcu::TestCaseGroup(testCtx, loadOps[loadOpNdx].str, loadOps[loadOpNdx].str));
7150 for (size_t storeOpNdx = 0; storeOpNdx < DE_LENGTH_OF_ARRAY(storeOps); storeOpNdx++)
7152 const VkImageAspectFlags inputAttachmentAspectMask = (testConfigExternal.groupParams->renderingType == RENDERING_TYPE_RENDERPASS2)
7154 : static_cast<VkImageAspectFlags>(0);
7155 const VkAttachmentStoreOp storeOp = storeOps[storeOpNdx].op;
7156 de::MovePtr<tcu::TestCaseGroup> storeOpGroup (new tcu::TestCaseGroup(testCtx, storeOps[storeOpNdx].str, storeOps[storeOpNdx].str));
7158 for (size_t useInputAspectNdx = 0; useInputAspectNdx < 2; useInputAspectNdx++)
7160 const bool useInputAspect = useInputAspectNdx != 0;
7162 if (testConfigExternal.groupParams->renderingType == RENDERING_TYPE_RENDERPASS2 && useInputAspect)
7165 for (size_t renderTypeNdx = 0; renderTypeNdx < DE_LENGTH_OF_ARRAY(renderTypes); renderTypeNdx++)
7168 vector<Attachment> attachments;
7169 vector<Subpass> subpasses;
7170 vector<SubpassDependency> deps;
7171 vector<VkInputAttachmentAspectReference> inputAspects;
7173 attachments.push_back(Attachment(vkFormat,
7174 VK_SAMPLE_COUNT_1_BIT,
7179 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
7180 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL));
7182 attachments.push_back(Attachment(vk::VK_FORMAT_R8G8B8A8_UNORM,
7183 VK_SAMPLE_COUNT_1_BIT,
7184 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7185 VK_ATTACHMENT_STORE_OP_STORE,
7186 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7187 VK_ATTACHMENT_STORE_OP_DONT_CARE,
7188 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
7189 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
7191 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7193 vector<AttachmentReference>(),
7194 vector<AttachmentReference>(),
7195 vector<AttachmentReference>(),
7196 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
7197 vector<deUint32>()));
7198 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7200 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, inputAttachmentAspectMask)),
7201 vector<AttachmentReference>(1, AttachmentReference(1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
7202 vector<AttachmentReference>(),
7203 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
7204 vector<deUint32>()));
7206 deps.push_back(SubpassDependency(0, 1,
7207 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
7208 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
7210 vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
7211 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
7216 const VkInputAttachmentAspectReference inputAspect =
7220 (isDepthAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_DEPTH_BIT : 0u)
7221 | (isStencilAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_STENCIL_BIT : 0u)
7224 inputAspects.push_back(inputAspect);
7228 const RenderPass renderPass (attachments, subpasses, deps, inputAspects);
7229 const TestConfig testConfig (renderPass,
7230 renderTypes[renderTypeNdx].types,
7231 TestConfig::COMMANDBUFFERTYPES_INLINE,
7232 TestConfig::IMAGEMEMORY_STRICT,
7239 testConfigExternal.allocationKind,
7240 testConfigExternal.groupParams);
7241 const string testName (renderTypes[renderTypeNdx].str + string(useInputAspect ? "_use_input_aspect" : ""));
7243 addFunctionCaseWithPrograms<TestConfig>(storeOpGroup.get(), testName, renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
7247 vector<Attachment> attachments;
7248 vector<Subpass> subpasses;
7249 vector<SubpassDependency> deps;
7250 vector<VkInputAttachmentAspectReference> inputAspects;
7252 attachments.push_back(Attachment(vkFormat,
7253 VK_SAMPLE_COUNT_1_BIT,
7256 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7257 VK_ATTACHMENT_STORE_OP_DONT_CARE,
7258 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
7259 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL));
7261 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7263 vector<AttachmentReference>(),
7264 vector<AttachmentReference>(),
7265 vector<AttachmentReference>(),
7266 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
7267 vector<deUint32>()));
7268 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7270 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_GENERAL, inputAttachmentAspectMask)),
7271 vector<AttachmentReference>(),
7272 vector<AttachmentReference>(),
7273 AttachmentReference(0, VK_IMAGE_LAYOUT_GENERAL),
7274 vector<deUint32>()));
7276 deps.push_back(SubpassDependency(0, 1,
7277 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
7278 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
7280 vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
7281 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
7282 vk::VK_DEPENDENCY_BY_REGION_BIT));
7284 deps.push_back(SubpassDependency(1, 1,
7285 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
7286 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
7287 vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
7288 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
7289 vk::VK_DEPENDENCY_BY_REGION_BIT));
7294 const VkInputAttachmentAspectReference inputAspect =
7299 (isDepthAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_DEPTH_BIT : 0u)
7300 | (isStencilAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_STENCIL_BIT : 0u)
7303 inputAspects.push_back(inputAspect);
7307 const RenderPass renderPass (attachments, subpasses, deps, inputAspects);
7308 const TestConfig testConfig (renderPass,
7309 renderTypes[renderTypeNdx].types,
7310 TestConfig::COMMANDBUFFERTYPES_INLINE,
7311 TestConfig::IMAGEMEMORY_STRICT,
7318 testConfigExternal.allocationKind,
7319 testConfigExternal.groupParams);
7320 const string testName (string("self_dep_") + renderTypes[renderTypeNdx].str + (useInputAspect ? "_use_input_aspect" : ""));
7322 addFunctionCaseWithPrograms<TestConfig>(storeOpGroup.get(), testName, string("self_dep_") + renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
7326 if (isStencilAttachment && isDepthAttachment)
7330 vector<Attachment> attachments;
7331 vector<Subpass> subpasses;
7332 vector<SubpassDependency> deps;
7333 vector<VkInputAttachmentAspectReference> inputAspects;
7335 attachments.push_back(Attachment(vkFormat,
7336 VK_SAMPLE_COUNT_1_BIT,
7341 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
7342 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL));
7344 attachments.push_back(Attachment(vk::VK_FORMAT_R8G8B8A8_UNORM,
7345 VK_SAMPLE_COUNT_1_BIT,
7346 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7347 VK_ATTACHMENT_STORE_OP_STORE,
7348 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7349 VK_ATTACHMENT_STORE_OP_DONT_CARE,
7350 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
7351 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
7353 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7355 vector<AttachmentReference>(),
7356 vector<AttachmentReference>(),
7357 vector<AttachmentReference>(),
7358 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
7359 vector<deUint32>()));
7360 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7362 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL, inputAttachmentAspectMask)),
7363 vector<AttachmentReference>(1, AttachmentReference(1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
7364 vector<AttachmentReference>(),
7365 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
7366 vector<deUint32>()));
7368 deps.push_back(SubpassDependency(0, 1,
7369 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
7370 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
7372 vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
7373 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
7378 const VkInputAttachmentAspectReference inputAspect =
7383 (isDepthAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_DEPTH_BIT : 0u)
7384 | (isStencilAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_STENCIL_BIT : 0u)
7387 inputAspects.push_back(inputAspect);
7391 const RenderPass renderPass (attachments, subpasses, deps, inputAspects);
7392 const TestConfig testConfig (renderPass,
7393 renderTypes[renderTypeNdx].types,
7394 TestConfig::COMMANDBUFFERTYPES_INLINE,
7395 TestConfig::IMAGEMEMORY_STRICT,
7402 testConfigExternal.allocationKind,
7403 testConfigExternal.groupParams);
7404 const string testName (renderTypes[renderTypeNdx].str + string(useInputAspect ? "_use_input_aspect" : "") + "_depth_read_only");
7406 addFunctionCaseWithPrograms<TestConfig>(storeOpGroup.get(), testName, renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
7410 vector<Attachment> attachments;
7411 vector<Subpass> subpasses;
7412 vector<SubpassDependency> deps;
7413 vector<VkInputAttachmentAspectReference> inputAspects;
7415 attachments.push_back(Attachment(vkFormat,
7416 VK_SAMPLE_COUNT_1_BIT,
7421 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
7422 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL));
7424 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7426 vector<AttachmentReference>(),
7427 vector<AttachmentReference>(),
7428 vector<AttachmentReference>(),
7429 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
7430 vector<deUint32>()));
7431 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7433 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL, inputAttachmentAspectMask)),
7434 vector<AttachmentReference>(),
7435 vector<AttachmentReference>(),
7436 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL),
7437 vector<deUint32>()));
7439 deps.push_back(SubpassDependency(0, 1,
7440 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
7441 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
7443 vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
7444 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
7445 vk::VK_DEPENDENCY_BY_REGION_BIT));
7447 deps.push_back(SubpassDependency(1, 1,
7448 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
7449 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
7451 vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
7452 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
7453 vk::VK_DEPENDENCY_BY_REGION_BIT));
7457 const VkInputAttachmentAspectReference inputAspect =
7462 (isDepthAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_DEPTH_BIT : 0u)
7463 | (isStencilAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_STENCIL_BIT : 0u)
7466 inputAspects.push_back(inputAspect);
7470 const RenderPass renderPass (attachments, subpasses, deps, inputAspects);
7471 const TestConfig testConfig (renderPass,
7472 renderTypes[renderTypeNdx].types,
7473 TestConfig::COMMANDBUFFERTYPES_INLINE,
7474 TestConfig::IMAGEMEMORY_STRICT,
7481 testConfigExternal.allocationKind,
7482 testConfigExternal.groupParams);
7483 const string testName (string("self_dep_") + renderTypes[renderTypeNdx].str + (useInputAspect ? "_use_input_aspect" : "") + "_depth_read_only");
7485 addFunctionCaseWithPrograms<TestConfig>(storeOpGroup.get(), testName, string("self_dep_") + renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
7488 // Stencil read only
7490 vector<Attachment> attachments;
7491 vector<Subpass> subpasses;
7492 vector<SubpassDependency> deps;
7493 vector<VkInputAttachmentAspectReference> inputAspects;
7495 attachments.push_back(Attachment(vkFormat,
7496 VK_SAMPLE_COUNT_1_BIT,
7501 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
7502 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL));
7504 attachments.push_back(Attachment(vk::VK_FORMAT_R8G8B8A8_UNORM,
7505 VK_SAMPLE_COUNT_1_BIT,
7506 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7507 VK_ATTACHMENT_STORE_OP_STORE,
7508 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7509 VK_ATTACHMENT_STORE_OP_DONT_CARE,
7510 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
7511 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
7513 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7515 vector<AttachmentReference>(),
7516 vector<AttachmentReference>(),
7517 vector<AttachmentReference>(),
7518 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
7519 vector<deUint32>()));
7520 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7522 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL, inputAttachmentAspectMask)),
7523 vector<AttachmentReference>(1, AttachmentReference(1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
7524 vector<AttachmentReference>(),
7525 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
7526 vector<deUint32>()));
7528 deps.push_back(SubpassDependency(0, 1,
7529 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
7530 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
7532 vk::VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
7533 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
7538 const VkInputAttachmentAspectReference inputAspect =
7543 (isDepthAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_DEPTH_BIT : 0u)
7544 | (isStencilAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_STENCIL_BIT : 0u)
7547 inputAspects.push_back(inputAspect);
7551 const RenderPass renderPass (attachments, subpasses, deps, inputAspects);
7552 const TestConfig testConfig (renderPass,
7553 renderTypes[renderTypeNdx].types,
7554 TestConfig::COMMANDBUFFERTYPES_INLINE,
7555 TestConfig::IMAGEMEMORY_STRICT,
7562 testConfigExternal.allocationKind,
7563 testConfigExternal.groupParams);
7564 const string testName (renderTypes[renderTypeNdx].str + string(useInputAspect ? "_use_input_aspect" : "") + "_stencil_read_only");
7566 addFunctionCaseWithPrograms<TestConfig>(storeOpGroup.get(), testName, renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
7570 vector<Attachment> attachments;
7571 vector<Subpass> subpasses;
7572 vector<SubpassDependency> deps;
7573 vector<VkInputAttachmentAspectReference> inputAspects;
7575 attachments.push_back(Attachment(vkFormat,
7576 VK_SAMPLE_COUNT_1_BIT,
7581 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
7582 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL));
7584 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7586 vector<AttachmentReference>(),
7587 vector<AttachmentReference>(),
7588 vector<AttachmentReference>(),
7589 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
7590 vector<deUint32>()));
7591 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7593 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL, inputAttachmentAspectMask)),
7594 vector<AttachmentReference>(),
7595 vector<AttachmentReference>(),
7596 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL),
7597 vector<deUint32>()));
7599 deps.push_back(SubpassDependency(0, 1,
7600 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
7601 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
7603 vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
7604 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
7605 vk::VK_DEPENDENCY_BY_REGION_BIT));
7607 deps.push_back(SubpassDependency(1, 1,
7608 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
7609 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
7611 vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
7612 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
7613 vk::VK_DEPENDENCY_BY_REGION_BIT));
7618 const VkInputAttachmentAspectReference inputAspect =
7623 (isDepthAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_DEPTH_BIT : 0u)
7624 | (isStencilAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_STENCIL_BIT : 0u)
7627 inputAspects.push_back(inputAspect);
7631 const RenderPass renderPass (attachments, subpasses, deps, inputAspects);
7632 const TestConfig testConfig (renderPass,
7633 renderTypes[renderTypeNdx].types,
7634 TestConfig::COMMANDBUFFERTYPES_INLINE,
7635 TestConfig::IMAGEMEMORY_STRICT,
7642 testConfigExternal.allocationKind,
7643 testConfigExternal.groupParams);
7644 const string testName (string("self_dep_") + renderTypes[renderTypeNdx].str + (useInputAspect ? "_use_input_aspect" : "") + "_stencil_read_only");
7646 addFunctionCaseWithPrograms<TestConfig>(storeOpGroup.get(), testName, string("self_dep_") + renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
7653 loadOpGroup->addChild(storeOpGroup.release());
7656 inputGroup->addChild(loadOpGroup.release());
7659 formatGroup->addChild(inputGroup.release());
7662 group->addChild(formatGroup.release());
7666 void addRenderPassTests (tcu::TestCaseGroup* group, const AllocationKind allocationKind, const SharedGroupParams groupParams)
7668 // tests added by this function have both primary and secondary cases and there is no need to repeat them for useSecondaryCmdBuffer flag;
7669 // but cases defined in other files that are later added to those groups in createRenderPassTestsInternal had to be adjusted and run
7670 // for useSecondaryCmdBuffer flag
7671 if (groupParams->useSecondaryCmdBuffer && !groupParams->secondaryCmdBufferCompletelyContainsDynamicRenderpass)
7674 const TestConfigExternal testConfigExternal (allocationKind, groupParams);
7676 // don't repeat cases that don't use CommandBufferTypes::COMMANDBUFFERTYPES_SECONDARY
7677 if (!groupParams->secondaryCmdBufferCompletelyContainsDynamicRenderpass)
7679 addTestGroup(group, "simple", "Simple basic render pass tests", addSimpleTests, testConfigExternal);
7680 addTestGroup(group, "formats", "Tests for different image formats.", addFormatTests, testConfigExternal);
7683 addTestGroup(group, "attachment", "Attachment format and count tests with load and store ops and image layouts", addAttachmentTests, testConfigExternal);
7685 // don't repeat cases that don't use CommandBufferTypes::COMMANDBUFFERTYPES_SECONDARY
7686 if (!groupParams->secondaryCmdBufferCompletelyContainsDynamicRenderpass)
7687 addTestGroup(group, "attachment_write_mask", "Attachment write mask tests", addAttachmentWriteMaskTests, testConfigExternal);
7689 if (groupParams->renderingType != RENDERING_TYPE_DYNAMIC_RENDERING)
7690 addTestGroup(group, "attachment_allocation", "Attachment allocation tests", addAttachmentAllocationTests, testConfigExternal);
7693 de::MovePtr<tcu::TestCaseGroup> createSuballocationTests(tcu::TestContext& testCtx, const SharedGroupParams groupParams)
7695 de::MovePtr<tcu::TestCaseGroup> suballocationTestsGroup(new tcu::TestCaseGroup(testCtx, "suballocation", "Suballocation RenderPass Tests"));
7697 addRenderPassTests(suballocationTestsGroup.get(), ALLOCATION_KIND_SUBALLOCATED, groupParams);
7699 return suballocationTestsGroup;
7702 de::MovePtr<tcu::TestCaseGroup> createDedicatedAllocationTests(tcu::TestContext& testCtx, const SharedGroupParams groupParams)
7704 de::MovePtr<tcu::TestCaseGroup> dedicatedAllocationTestsGroup(new tcu::TestCaseGroup(testCtx, "dedicated_allocation", "RenderPass Tests For Dedicated Allocation"));
7706 addRenderPassTests(dedicatedAllocationTestsGroup.get(), ALLOCATION_KIND_DEDICATED, groupParams);
7708 return dedicatedAllocationTestsGroup;
7711 tcu::TestCaseGroup* createRenderPassTestsInternal (tcu::TestContext& testCtx, const char* groupName, const SharedGroupParams groupParams)
7713 de::MovePtr<tcu::TestCaseGroup> renderingTests (new tcu::TestCaseGroup(testCtx, groupName, ""));
7714 de::MovePtr<tcu::TestCaseGroup> suballocationTestGroup = createSuballocationTests(testCtx, groupParams);
7715 de::MovePtr<tcu::TestCaseGroup> dedicatedAllocationTestGroup = createDedicatedAllocationTests(testCtx, groupParams);
7717 const RenderingType renderingType = groupParams->renderingType;
7719 switch (renderingType)
7721 case RENDERING_TYPE_RENDERPASS_LEGACY:
7722 suballocationTestGroup->addChild(createRenderPassMultisampleTests(testCtx));
7723 suballocationTestGroup->addChild(createRenderPassMultisampleResolveTests(testCtx, groupParams));
7724 suballocationTestGroup->addChild(createRenderPassSubpassDependencyTests(testCtx));
7725 suballocationTestGroup->addChild(createRenderPassSampleReadTests(testCtx));
7727 #ifndef CTS_USES_VULKANSC
7728 suballocationTestGroup->addChild(createRenderPassSparseRenderTargetTests(testCtx, groupParams));
7729 renderingTests->addChild(createDepthStencilWriteConditionsTests(testCtx));
7730 #endif // CTS_USES_VULKANSC
7732 renderingTests->addChild(createRenderPassMultipleSubpassesMultipleCommandBuffersTests(testCtx));
7736 case RENDERING_TYPE_RENDERPASS2:
7737 suballocationTestGroup->addChild(createRenderPass2MultisampleTests(testCtx));
7738 suballocationTestGroup->addChild(createRenderPass2MultisampleResolveTests(testCtx, groupParams));
7739 suballocationTestGroup->addChild(createRenderPass2SubpassDependencyTests(testCtx));
7740 suballocationTestGroup->addChild(createRenderPass2SampleReadTests(testCtx));
7742 #ifndef CTS_USES_VULKANSC
7743 suballocationTestGroup->addChild(createRenderPass2SparseRenderTargetTests(testCtx, groupParams));
7744 #endif // CTS_USES_VULKANSC
7746 renderingTests->addChild(createRenderPass2DepthStencilResolveTests(testCtx));
7749 #ifndef CTS_USES_VULKANSC
7750 case RENDERING_TYPE_DYNAMIC_RENDERING:
7751 suballocationTestGroup->addChild(createDynamicRenderingMultisampleResolveTests(testCtx, groupParams));
7752 suballocationTestGroup->addChild(createDynamicRenderingSparseRenderTargetTests(testCtx, groupParams));
7754 if (groupParams->useSecondaryCmdBuffer == false)
7756 renderingTests->addChild(createDynamicRenderingRandomTests(testCtx));
7757 renderingTests->addChild(createDynamicRenderingBasicTests(testCtx));
7760 #endif // CTS_USES_VULKANSC
7766 if (renderingType != RENDERING_TYPE_DYNAMIC_RENDERING)
7768 suballocationTestGroup->addChild(createRenderPassUnusedAttachmentTests(testCtx, renderingType));
7769 suballocationTestGroup->addChild(createRenderPassUnusedAttachmentSparseFillingTests(testCtx, renderingType));
7772 suballocationTestGroup->addChild(createRenderPassUnusedClearAttachmentTests(testCtx, groupParams));
7774 #ifndef CTS_USES_VULKANSC
7775 suballocationTestGroup->addChild(createRenderPassLoadStoreOpNoneTests(testCtx, groupParams));
7777 if (renderingType == RENDERING_TYPE_RENDERPASS2)
7779 suballocationTestGroup->addChild(createRenderPassSubpassMergeFeedbackTests(testCtx, renderingType));
7782 renderingTests->addChild(createFragmentDensityMapTests(testCtx, groupParams));
7783 #endif // CTS_USES_VULKANSC
7785 renderingTests->addChild(suballocationTestGroup.release());
7786 renderingTests->addChild(dedicatedAllocationTestGroup.release());
7788 return renderingTests.release();
7793 tcu::TestCaseGroup* createRenderPassTests (tcu::TestContext& testCtx)
7795 SharedGroupParams groupParams(
7798 RENDERING_TYPE_RENDERPASS_LEGACY, // RenderingType renderingType;
7799 false, // bool useSecondaryCmdBuffer;
7800 false, // bool secondaryCmdBufferCompletelyContainsDynamicRenderpass;
7802 return createRenderPassTestsInternal(testCtx, "renderpass", groupParams);
7805 tcu::TestCaseGroup* createRenderPass2Tests (tcu::TestContext& testCtx)
7807 SharedGroupParams groupParams(
7810 RENDERING_TYPE_RENDERPASS2, // RenderingType renderingType;
7811 false, // bool useSecondaryCmdBuffer;
7812 false, // bool secondaryCmdBufferCompletelyContainsDynamicRenderpass;
7814 return createRenderPassTestsInternal(testCtx, "renderpass2", groupParams);
7817 tcu::TestCaseGroup* createDynamicRenderingTests(tcu::TestContext& testCtx)
7819 de::MovePtr<tcu::TestCaseGroup> dynamicRenderingGroup(new tcu::TestCaseGroup(testCtx, "dynamic_rendering", "Draw using VK_KHR_dynamic_rendering"));
7821 dynamicRenderingGroup->addChild(createRenderPassTestsInternal(testCtx, "primary_cmd_buff", SharedGroupParams(
7824 RENDERING_TYPE_DYNAMIC_RENDERING, // RenderingType renderingType;
7825 false, // bool useSecondaryCmdBuffer;
7826 false, // bool secondaryCmdBufferCompletelyContainsDynamicRenderpass;
7828 dynamicRenderingGroup->addChild(createRenderPassTestsInternal(testCtx, "partial_secondary_cmd_buff", SharedGroupParams(
7831 RENDERING_TYPE_DYNAMIC_RENDERING, // RenderingType renderingType;
7832 true, // bool useSecondaryCmdBuffer;
7833 false, // bool secondaryCmdBufferCompletelyContainsDynamicRenderpass;
7835 dynamicRenderingGroup->addChild(createRenderPassTestsInternal(testCtx, "complete_secondary_cmd_buff", SharedGroupParams(
7838 RENDERING_TYPE_DYNAMIC_RENDERING, // RenderingType renderingType;
7839 true, // bool useSecondaryCmdBuffer;
7840 true, // bool secondaryCmdBufferCompletelyContainsDynamicRenderpass;
7843 return dynamicRenderingGroup.release();