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"
47 #include "vktRenderPassDitheringTests.hpp"
49 #include "vktTestCaseUtil.hpp"
50 #include "vktTestGroupUtil.hpp"
53 #include "vkDeviceUtil.hpp"
54 #include "vkImageUtil.hpp"
55 #include "vkMemUtil.hpp"
56 #include "vkPlatform.hpp"
57 #include "vkPrograms.hpp"
58 #include "vkQueryUtil.hpp"
60 #include "vkRefUtil.hpp"
61 #include "vkStrUtil.hpp"
62 #include "vkTypeUtil.hpp"
63 #include "vkCmdUtil.hpp"
64 #include "vkObjUtil.hpp"
66 #include "tcuFloat.hpp"
67 #include "tcuFormatUtil.hpp"
68 #include "tcuMaybe.hpp"
69 #include "tcuResultCollector.hpp"
70 #include "tcuTestLog.hpp"
71 #include "tcuTextureUtil.hpp"
72 #include "tcuVectorUtil.hpp"
74 #include "deRandom.hpp"
75 #include "deSTLUtil.hpp"
76 #include "deSharedPtr.hpp"
77 #include "deStringUtil.hpp"
78 #include "deUniquePtr.hpp"
99 using tcu::ConstPixelBufferAccess;
100 using tcu::PixelBufferAccess;
115 using namespace renderpass;
117 typedef vector<deUint8> DepthValuesArray;
119 static const deUint8 DEPTH_VALUES[] = { 0u, 255u, 1u };
123 ALLOCATION_KIND_SUBALLOCATED,
124 ALLOCATION_KIND_DEDICATED,
127 struct TestConfigExternal
129 TestConfigExternal (AllocationKind allocationKind_,
130 const SharedGroupParams groupParams_)
131 : allocationKind (allocationKind_)
132 , groupParams (groupParams_)
136 AllocationKind allocationKind;
137 const SharedGroupParams groupParams;
140 de::MovePtr<Allocation> allocateBuffer (const InstanceInterface& vki,
141 const DeviceInterface& vkd,
142 const VkPhysicalDevice& physDevice,
143 const VkDevice device,
144 const VkBuffer& buffer,
145 const MemoryRequirement requirement,
146 Allocator& allocator,
147 AllocationKind allocationKind)
149 switch (allocationKind)
151 case ALLOCATION_KIND_SUBALLOCATED:
153 const VkMemoryRequirements memoryRequirements = getBufferMemoryRequirements(vkd, device, buffer);
155 return allocator.allocate(memoryRequirements, requirement);
158 case ALLOCATION_KIND_DEDICATED:
160 return allocateDedicated(vki, vkd, physDevice, device, buffer, requirement);
165 TCU_THROW(InternalError, "Invalid allocation kind");
170 de::MovePtr<Allocation> allocateImage (const InstanceInterface& vki,
171 const DeviceInterface& vkd,
172 const VkPhysicalDevice& physDevice,
173 const VkDevice device,
174 const VkImage& image,
175 const MemoryRequirement requirement,
176 Allocator& allocator,
177 AllocationKind allocationKind)
179 switch (allocationKind)
181 case ALLOCATION_KIND_SUBALLOCATED:
183 const VkMemoryRequirements memoryRequirements = getImageMemoryRequirements(vkd, device, image);
185 return allocator.allocate(memoryRequirements, requirement);
188 case ALLOCATION_KIND_DEDICATED:
190 return allocateDedicated(vki, vkd, physDevice, device, image, requirement);
195 TCU_THROW(InternalError, "Invalid allocation kind");
208 const char* boolOpToString (BoolOp op)
225 DE_FATAL("Unknown boolean operation.");
230 bool performBoolOp (BoolOp op, bool a, bool b)
247 DE_FATAL("Unknown boolean operation.");
252 BoolOp boolOpFromIndex (size_t index)
262 return ops[index % DE_LENGTH_OF_ARRAY(ops)];
265 static float requiredDepthEpsilon(VkFormat format)
267 // Possible precision loss in the unorm depth pipeline means that we need to check depths
268 // that go in and back out of the depth buffer with an epsilon rather than an exact match
269 deUint32 unormBits = 0;
273 case VK_FORMAT_D16_UNORM:
276 case VK_FORMAT_X8_D24_UNORM_PACK32:
277 case VK_FORMAT_D24_UNORM_S8_UINT:
280 case VK_FORMAT_D32_SFLOAT:
281 case VK_FORMAT_D32_SFLOAT_S8_UINT:
288 return 1.0f / (float)((1 << unormBits) - 1);
290 return 0.0f; // Require exact match
293 static bool depthsEqual(float a, float b, float epsilon)
295 return fabs(a - b) <= epsilon;
298 Move<VkFramebuffer> createFramebuffer (const DeviceInterface& vk,
300 VkFramebufferCreateFlags pCreateInfo_flags,
301 VkRenderPass pCreateInfo_renderPass,
302 deUint32 pCreateInfo_attachmentCount,
303 const VkImageView* pCreateInfo_pAttachments,
304 deUint32 pCreateInfo_width,
305 deUint32 pCreateInfo_height,
306 deUint32 pCreateInfo_layers)
308 const VkFramebufferCreateInfo pCreateInfo =
310 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
313 pCreateInfo_renderPass,
314 pCreateInfo_attachmentCount,
315 pCreateInfo_pAttachments,
320 return createFramebuffer(vk, device, &pCreateInfo);
323 Move<VkImage> createImage (const DeviceInterface& vk,
325 VkImageCreateFlags pCreateInfo_flags,
326 VkImageType pCreateInfo_imageType,
327 VkFormat pCreateInfo_format,
328 VkExtent3D pCreateInfo_extent,
329 deUint32 pCreateInfo_mipLevels,
330 deUint32 pCreateInfo_arrayLayers,
331 VkSampleCountFlagBits pCreateInfo_samples,
332 VkImageTiling pCreateInfo_tiling,
333 VkImageUsageFlags pCreateInfo_usage,
334 VkSharingMode pCreateInfo_sharingMode,
335 deUint32 pCreateInfo_queueFamilyCount,
336 const deUint32* pCreateInfo_pQueueFamilyIndices,
337 VkImageLayout pCreateInfo_initialLayout)
339 const VkImageCreateInfo pCreateInfo =
341 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
344 pCreateInfo_imageType,
347 pCreateInfo_mipLevels,
348 pCreateInfo_arrayLayers,
352 pCreateInfo_sharingMode,
353 pCreateInfo_queueFamilyCount,
354 pCreateInfo_pQueueFamilyIndices,
355 pCreateInfo_initialLayout
357 return createImage(vk, device, &pCreateInfo);
360 void bindBufferMemory (const DeviceInterface& vk, VkDevice device, VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memOffset)
362 VK_CHECK(vk.bindBufferMemory(device, buffer, mem, memOffset));
365 void bindImageMemory (const DeviceInterface& vk, VkDevice device, VkImage image, VkDeviceMemory mem, VkDeviceSize memOffset)
367 VK_CHECK(vk.bindImageMemory(device, image, mem, memOffset));
370 Move<VkImageView> createImageView (const DeviceInterface& vk,
372 VkImageViewCreateFlags pCreateInfo_flags,
373 VkImage pCreateInfo_image,
374 VkImageViewType pCreateInfo_viewType,
375 VkFormat pCreateInfo_format,
376 VkComponentMapping pCreateInfo_components,
377 VkImageSubresourceRange pCreateInfo_subresourceRange)
379 const VkImageViewCreateInfo pCreateInfo =
381 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
385 pCreateInfo_viewType,
387 pCreateInfo_components,
388 pCreateInfo_subresourceRange,
390 return createImageView(vk, device, &pCreateInfo);
393 Move<VkBuffer> createBuffer (const DeviceInterface& vk,
395 VkBufferCreateFlags pCreateInfo_flags,
396 VkDeviceSize pCreateInfo_size,
397 VkBufferUsageFlags pCreateInfo_usage,
398 VkSharingMode pCreateInfo_sharingMode,
399 deUint32 pCreateInfo_queueFamilyCount,
400 const deUint32* pCreateInfo_pQueueFamilyIndices)
402 const VkBufferCreateInfo pCreateInfo =
404 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
409 pCreateInfo_sharingMode,
410 pCreateInfo_queueFamilyCount,
411 pCreateInfo_pQueueFamilyIndices,
413 return createBuffer(vk, device, &pCreateInfo);
416 VkRenderPassBeginInfo createRenderPassBeginInfo (VkRenderPass pRenderPassBegin_renderPass,
417 VkFramebuffer pRenderPassBegin_framebuffer,
418 VkRect2D pRenderPassBegin_renderArea,
419 deUint32 pRenderPassBegin_clearValueCount,
420 const VkClearValue* pRenderPassBegin_pAttachmentClearValues)
422 const VkRenderPassBeginInfo renderPassBeginInfo =
424 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
426 pRenderPassBegin_renderPass,
427 pRenderPassBegin_framebuffer,
428 pRenderPassBegin_renderArea,
429 pRenderPassBegin_clearValueCount,
430 pRenderPassBegin_pAttachmentClearValues,
433 return renderPassBeginInfo;
436 void queueSubmit (const DeviceInterface& vk, VkQueue queue, deUint32 cmdBufferCount, const VkCommandBuffer* pCmdBuffers, VkFence fence)
438 const VkSubmitInfo submitInfo =
440 VK_STRUCTURE_TYPE_SUBMIT_INFO,
442 0u, // waitSemaphoreCount
443 (const VkSemaphore*)DE_NULL, // pWaitSemaphores
444 (const VkPipelineStageFlags*)DE_NULL,
445 cmdBufferCount, // commandBufferCount
447 0u, // signalSemaphoreCount
448 (const VkSemaphore*)DE_NULL, // pSignalSemaphores
450 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, fence));
453 void waitForFences (const DeviceInterface& vk, VkDevice device, deUint32 fenceCount, const VkFence* pFences, VkBool32 waitAll, deUint64 timeout)
455 VK_CHECK(vk.waitForFences(device, fenceCount, pFences, waitAll, timeout));
458 VkImageAspectFlags getImageAspectFlags (VkFormat vkFormat)
460 const tcu::TextureFormat format = mapVkFormat(vkFormat);
462 DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELORDER_LAST == 22);
464 switch (format.order)
466 case tcu::TextureFormat::DS:
467 return VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
469 case tcu::TextureFormat::D:
470 return VK_IMAGE_ASPECT_DEPTH_BIT;
472 case tcu::TextureFormat::S:
473 return VK_IMAGE_ASPECT_STENCIL_BIT;
476 return VK_IMAGE_ASPECT_COLOR_BIT;
480 VkAccessFlags getAllMemoryReadFlags (void)
482 return VK_ACCESS_TRANSFER_READ_BIT
483 | VK_ACCESS_UNIFORM_READ_BIT
484 | VK_ACCESS_HOST_READ_BIT
485 | VK_ACCESS_INDEX_READ_BIT
486 | VK_ACCESS_SHADER_READ_BIT
487 | VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT
488 | VK_ACCESS_INDIRECT_COMMAND_READ_BIT
489 | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT
490 | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT
491 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
494 VkAccessFlags getAllMemoryWriteFlags (void)
496 return VK_ACCESS_TRANSFER_WRITE_BIT
497 | VK_ACCESS_HOST_WRITE_BIT
498 | VK_ACCESS_SHADER_WRITE_BIT
499 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT
500 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
503 VkAccessFlags getMemoryFlagsForLayout (const VkImageLayout layout)
507 case VK_IMAGE_LAYOUT_GENERAL: return getAllMemoryReadFlags() | getAllMemoryWriteFlags();
508 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: return VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
509 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: return VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
510 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: return VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
511 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: return VK_ACCESS_SHADER_READ_BIT;
512 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: return VK_ACCESS_TRANSFER_READ_BIT;
513 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: return VK_ACCESS_TRANSFER_WRITE_BIT;
514 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;
515 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;
517 return (VkAccessFlags)0;
521 VkPipelineStageFlags getAllPipelineStageFlags (void)
523 /* All relevant flags for a pipeline containing VS+PS. */
524 return VK_PIPELINE_STAGE_TRANSFER_BIT
525 | VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT
526 | VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT
527 | VK_PIPELINE_STAGE_VERTEX_INPUT_BIT
528 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT
529 | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
530 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
531 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT
532 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
533 | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT
534 | VK_PIPELINE_STAGE_HOST_BIT;
537 class AttachmentReference
540 AttachmentReference (deUint32 attachment,
541 VkImageLayout layout,
542 VkImageAspectFlags aspectMask = static_cast<VkImageAspectFlags>(0u))
543 : m_attachment (attachment)
545 , m_aspectMask (aspectMask)
549 deUint32 getAttachment (void) const { return m_attachment; }
550 VkImageLayout getImageLayout (void) const { return m_layout; }
551 VkImageAspectFlags getAspectMask (void) const { return m_aspectMask; }
552 void setImageLayout (VkImageLayout layout) { m_layout = layout; }
555 deUint32 m_attachment;
556 VkImageLayout m_layout;
557 VkImageAspectFlags m_aspectMask;
563 Subpass (VkPipelineBindPoint pipelineBindPoint,
564 VkSubpassDescriptionFlags flags,
565 const vector<AttachmentReference>& inputAttachments,
566 const vector<AttachmentReference>& colorAttachments,
567 const vector<AttachmentReference>& resolveAttachments,
568 AttachmentReference depthStencilAttachment,
569 const vector<deUint32>& preserveAttachments,
570 bool omitBlendState = false)
571 : m_pipelineBindPoint (pipelineBindPoint)
573 , m_inputAttachments (inputAttachments)
574 , m_colorAttachments (colorAttachments)
575 , m_resolveAttachments (resolveAttachments)
576 , m_depthStencilAttachment (depthStencilAttachment)
577 , m_preserveAttachments (preserveAttachments)
578 , m_omitBlendState (omitBlendState)
582 VkPipelineBindPoint getPipelineBindPoint (void) const { return m_pipelineBindPoint; }
583 VkSubpassDescriptionFlags getFlags (void) const { return m_flags; }
584 const vector<AttachmentReference>& getInputAttachments (void) const { return m_inputAttachments; }
585 const vector<AttachmentReference>& getColorAttachments (void) const { return m_colorAttachments; }
586 const vector<AttachmentReference>& getResolveAttachments (void) const { return m_resolveAttachments; }
587 const AttachmentReference& getDepthStencilAttachment (void) const { return m_depthStencilAttachment; }
588 const vector<deUint32>& getPreserveAttachments (void) const { return m_preserveAttachments; }
589 bool getOmitBlendState (void) const { return m_omitBlendState; }
592 VkPipelineBindPoint m_pipelineBindPoint;
593 VkSubpassDescriptionFlags m_flags;
595 vector<AttachmentReference> m_inputAttachments;
596 vector<AttachmentReference> m_colorAttachments;
597 vector<AttachmentReference> m_resolveAttachments;
598 AttachmentReference m_depthStencilAttachment;
600 vector<deUint32> m_preserveAttachments;
601 bool m_omitBlendState;
604 class SubpassDependency
607 SubpassDependency (deUint32 srcPass,
610 VkPipelineStageFlags srcStageMask,
611 VkPipelineStageFlags dstStageMask,
613 VkAccessFlags srcAccessMask,
614 VkAccessFlags dstAccessMask,
616 VkDependencyFlags flags)
617 : m_srcPass (srcPass)
618 , m_dstPass (dstPass)
620 , m_srcStageMask (srcStageMask)
621 , m_dstStageMask (dstStageMask)
623 , m_srcAccessMask (srcAccessMask)
624 , m_dstAccessMask (dstAccessMask)
629 deUint32 getSrcPass (void) const { return m_srcPass; }
630 deUint32 getDstPass (void) const { return m_dstPass; }
632 VkPipelineStageFlags getSrcStageMask (void) const { return m_srcStageMask; }
633 VkPipelineStageFlags getDstStageMask (void) const { return m_dstStageMask; }
635 VkAccessFlags getSrcAccessMask (void) const { return m_srcAccessMask; }
636 VkAccessFlags getDstAccessMask (void) const { return m_dstAccessMask; }
638 VkDependencyFlags getFlags (void) const { return m_flags; }
640 void setSrcAccessMask (const VkAccessFlags& flags) { m_srcAccessMask = flags; }
641 void setDstAccessMask (const VkAccessFlags& flags) { m_dstAccessMask = flags; }
647 VkPipelineStageFlags m_srcStageMask;
648 VkPipelineStageFlags m_dstStageMask;
650 VkAccessFlags m_srcAccessMask;
651 VkAccessFlags m_dstAccessMask;
652 VkDependencyFlags m_flags;
658 Attachment (VkFormat format,
659 VkSampleCountFlagBits samples,
661 VkAttachmentLoadOp loadOp,
662 VkAttachmentStoreOp storeOp,
664 VkAttachmentLoadOp stencilLoadOp,
665 VkAttachmentStoreOp stencilStoreOp,
667 VkImageLayout initialLayout,
668 VkImageLayout finalLayout)
670 , m_samples (samples)
673 , m_storeOp (storeOp)
675 , m_stencilLoadOp (stencilLoadOp)
676 , m_stencilStoreOp (stencilStoreOp)
678 , m_initialLayout (initialLayout)
679 , m_finalLayout (finalLayout)
683 VkFormat getFormat (void) const { return m_format; }
684 VkSampleCountFlagBits getSamples (void) const { return m_samples; }
686 VkAttachmentLoadOp getLoadOp (void) const { return m_loadOp; }
687 VkAttachmentStoreOp getStoreOp (void) const { return m_storeOp; }
690 VkAttachmentLoadOp getStencilLoadOp (void) const { return m_stencilLoadOp; }
691 VkAttachmentStoreOp getStencilStoreOp (void) const { return m_stencilStoreOp; }
693 VkImageLayout getInitialLayout (void) const { return m_initialLayout; }
694 VkImageLayout getFinalLayout (void) const { return m_finalLayout; }
698 VkSampleCountFlagBits m_samples;
700 VkAttachmentLoadOp m_loadOp;
701 VkAttachmentStoreOp m_storeOp;
703 VkAttachmentLoadOp m_stencilLoadOp;
704 VkAttachmentStoreOp m_stencilStoreOp;
706 VkImageLayout m_initialLayout;
707 VkImageLayout m_finalLayout;
713 RenderPass (const vector<Attachment>& attachments,
714 const vector<Subpass>& subpasses,
715 const vector<SubpassDependency>& dependencies,
716 const vector<VkInputAttachmentAspectReference> inputAspects = vector<VkInputAttachmentAspectReference>())
717 : m_attachments (attachments)
718 , m_subpasses (subpasses)
719 , m_dependencies (dependencies)
720 , m_inputAspects (inputAspects)
724 const vector<Attachment>& getAttachments (void) const { return m_attachments; }
725 const vector<Subpass>& getSubpasses (void) const { return m_subpasses; }
726 const vector<SubpassDependency>& getDependencies (void) const { return m_dependencies; }
727 const vector<VkInputAttachmentAspectReference>& getInputAspects (void) const { return m_inputAspects; }
730 const vector<Attachment> m_attachments;
731 const vector<Subpass> m_subpasses;
732 const vector<SubpassDependency> m_dependencies;
733 const vector<VkInputAttachmentAspectReference> m_inputAspects;
740 RENDERTYPES_NONE = 0,
741 RENDERTYPES_CLEAR = (1<<1),
742 RENDERTYPES_DRAW = (1<<2)
745 enum CommandBufferTypes
747 COMMANDBUFFERTYPES_INLINE = (1<<0),
748 COMMANDBUFFERTYPES_SECONDARY = (1<<1)
753 IMAGEMEMORY_STRICT = (1<<0),
754 IMAGEMEMORY_LAZY = (1<<1)
757 TestConfig (const RenderPass& renderPass_,
758 RenderTypes renderTypes_,
759 CommandBufferTypes commandBufferTypes_,
760 ImageMemory imageMemory_,
761 const UVec2& targetSize_,
762 const UVec2& renderPos_,
763 const UVec2& renderSize_,
764 deBool useFormatCompCount_,
766 deUint32 drawStartNdx_,
767 AllocationKind allocationKind_,
768 SharedGroupParams groupParams_,
769 vector<DeviceCoreFeature> requiredFeatures_ = vector<DeviceCoreFeature>())
770 : renderPass (renderPass_)
771 , renderTypes (renderTypes_)
772 , commandBufferTypes (commandBufferTypes_)
773 , imageMemory (imageMemory_)
774 , targetSize (targetSize_)
775 , renderPos (renderPos_)
776 , renderSize (renderSize_)
777 , useFormatCompCount (useFormatCompCount_)
779 , drawStartNdx (drawStartNdx_)
780 , allocationKind (allocationKind_)
781 , groupParams (groupParams_)
782 , requiredFeatures (requiredFeatures_)
784 DepthValuesArray shuffledDepthValues (&DEPTH_VALUES[0], &DEPTH_VALUES[DE_LENGTH_OF_ARRAY(DEPTH_VALUES)]);
785 de::Random rng (seed + 1);
787 rng.shuffle(shuffledDepthValues.begin(), shuffledDepthValues.end());
789 depthValues.push_back(shuffledDepthValues[0]);
790 depthValues.push_back(shuffledDepthValues[1]);
793 RenderPass renderPass;
794 RenderTypes renderTypes;
795 CommandBufferTypes commandBufferTypes;
796 ImageMemory imageMemory;
800 deBool useFormatCompCount;
802 deUint32 drawStartNdx;
803 AllocationKind allocationKind;
804 SharedGroupParams groupParams;
805 vector<DeviceCoreFeature> requiredFeatures;
806 DepthValuesArray depthValues;
809 TestConfig::RenderTypes operator| (TestConfig::RenderTypes a, TestConfig::RenderTypes b)
811 return (TestConfig::RenderTypes)(((deUint32)a) | ((deUint32)b));
814 TestConfig::CommandBufferTypes operator| (TestConfig::CommandBufferTypes a, TestConfig::CommandBufferTypes b)
816 return (TestConfig::CommandBufferTypes)(((deUint32)a) | ((deUint32)b));
819 TestConfig::ImageMemory operator| (TestConfig::ImageMemory a, TestConfig::ImageMemory b)
821 return (TestConfig::ImageMemory)(((deUint32)a) | ((deUint32)b));
824 void checkSupport (Context& context, TestConfig config)
826 for (size_t featureNdx = 0; featureNdx < config.requiredFeatures.size(); featureNdx++)
827 context.requireDeviceCoreFeature(config.requiredFeatures[featureNdx]);
830 void logRenderPassInfo (TestLog& log,
831 const RenderPass& renderPass)
833 const bool useExternalInputAspect = !renderPass.getInputAspects().empty();
834 const tcu::ScopedLogSection section (log, "RenderPass", "RenderPass");
837 const tcu::ScopedLogSection attachmentsSection (log, "Attachments", "Attachments");
838 const vector<Attachment>& attachments = renderPass.getAttachments();
840 for (size_t attachmentNdx = 0; attachmentNdx < attachments.size(); attachmentNdx++)
842 const tcu::ScopedLogSection attachmentSection (log, "Attachment" + de::toString(attachmentNdx), "Attachment " + de::toString(attachmentNdx));
843 const Attachment& attachment = attachments[attachmentNdx];
845 log << TestLog::Message << "Format: " << attachment.getFormat() << TestLog::EndMessage;
846 log << TestLog::Message << "Samples: " << attachment.getSamples() << TestLog::EndMessage;
848 log << TestLog::Message << "LoadOp: " << attachment.getLoadOp() << TestLog::EndMessage;
849 log << TestLog::Message << "StoreOp: " << attachment.getStoreOp() << TestLog::EndMessage;
851 log << TestLog::Message << "StencilLoadOp: " << attachment.getStencilLoadOp() << TestLog::EndMessage;
852 log << TestLog::Message << "StencilStoreOp: " << attachment.getStencilStoreOp() << TestLog::EndMessage;
854 log << TestLog::Message << "InitialLayout: " << attachment.getInitialLayout() << TestLog::EndMessage;
855 log << TestLog::Message << "FinalLayout: " << attachment.getFinalLayout() << TestLog::EndMessage;
859 if (useExternalInputAspect)
861 const tcu::ScopedLogSection inputAspectSection (log, "InputAspects", "InputAspects");
863 for (size_t aspectNdx = 0; aspectNdx < renderPass.getInputAspects().size(); aspectNdx++)
865 const VkInputAttachmentAspectReference& inputAspect (renderPass.getInputAspects()[aspectNdx]);
867 log << TestLog::Message << "Subpass: " << inputAspect.subpass << TestLog::EndMessage;
868 log << TestLog::Message << "InputAttachmentIndex: " << inputAspect.inputAttachmentIndex << TestLog::EndMessage;
869 log << TestLog::Message << "AspectFlags: " << getImageAspectFlagsStr(inputAspect.aspectMask) << TestLog::EndMessage;
874 const tcu::ScopedLogSection subpassesSection (log, "Subpasses", "Subpasses");
875 const vector<Subpass>& subpasses = renderPass.getSubpasses();
877 for (size_t subpassNdx = 0; subpassNdx < subpasses.size(); subpassNdx++)
879 const tcu::ScopedLogSection subpassSection (log, "Subpass" + de::toString(subpassNdx), "Subpass " + de::toString(subpassNdx));
880 const Subpass& subpass = subpasses[subpassNdx];
882 const vector<AttachmentReference>& inputAttachments = subpass.getInputAttachments();
883 const vector<AttachmentReference>& colorAttachments = subpass.getColorAttachments();
884 const vector<AttachmentReference>& resolveAttachments = subpass.getResolveAttachments();
885 const vector<deUint32>& preserveAttachments = subpass.getPreserveAttachments();
887 if (!inputAttachments.empty())
889 const tcu::ScopedLogSection inputAttachmentsSection (log, "Inputs", "Inputs");
891 for (size_t inputNdx = 0; inputNdx < inputAttachments.size(); inputNdx++)
893 const tcu::ScopedLogSection inputAttachmentSection (log, "Input" + de::toString(inputNdx), "Input " + de::toString(inputNdx));
894 const AttachmentReference& inputAttachment = inputAttachments[inputNdx];
896 log << TestLog::Message << "Attachment: " << inputAttachment.getAttachment() << TestLog::EndMessage;
897 log << TestLog::Message << "Layout: " << inputAttachment.getImageLayout() << TestLog::EndMessage;
898 if (!useExternalInputAspect)
899 log << TestLog::Message << "AspectMask: " << inputAttachment.getAspectMask() << TestLog::EndMessage;
903 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED)
905 const tcu::ScopedLogSection depthStencilAttachmentSection (log, "DepthStencil", "DepthStencil");
906 const AttachmentReference& depthStencilAttachment = subpass.getDepthStencilAttachment();
908 log << TestLog::Message << "Attachment: " << depthStencilAttachment.getAttachment() << TestLog::EndMessage;
909 log << TestLog::Message << "Layout: " << depthStencilAttachment.getImageLayout() << TestLog::EndMessage;
912 if (!colorAttachments.empty())
914 const tcu::ScopedLogSection colorAttachmentsSection (log, "Colors", "Colors");
916 for (size_t colorNdx = 0; colorNdx < colorAttachments.size(); colorNdx++)
918 const tcu::ScopedLogSection colorAttachmentSection (log, "Color" + de::toString(colorNdx), "Color " + de::toString(colorNdx));
919 const AttachmentReference& colorAttachment = colorAttachments[colorNdx];
921 log << TestLog::Message << "Attachment: " << colorAttachment.getAttachment() << TestLog::EndMessage;
922 log << TestLog::Message << "Layout: " << colorAttachment.getImageLayout() << TestLog::EndMessage;
926 if (!resolveAttachments.empty())
928 const tcu::ScopedLogSection resolveAttachmentsSection (log, "Resolves", "Resolves");
930 for (size_t resolveNdx = 0; resolveNdx < resolveAttachments.size(); resolveNdx++)
932 const tcu::ScopedLogSection resolveAttachmentSection (log, "Resolve" + de::toString(resolveNdx), "Resolve " + de::toString(resolveNdx));
933 const AttachmentReference& resolveAttachment = resolveAttachments[resolveNdx];
935 log << TestLog::Message << "Attachment: " << resolveAttachment.getAttachment() << TestLog::EndMessage;
936 log << TestLog::Message << "Layout: " << resolveAttachment.getImageLayout() << TestLog::EndMessage;
940 if (!preserveAttachments.empty())
942 const tcu::ScopedLogSection preserveAttachmentsSection (log, "Preserves", "Preserves");
944 for (size_t preserveNdx = 0; preserveNdx < preserveAttachments.size(); preserveNdx++)
946 const tcu::ScopedLogSection preserveAttachmentSection (log, "Preserve" + de::toString(preserveNdx), "Preserve " + de::toString(preserveNdx));
947 const deUint32 preserveAttachment = preserveAttachments[preserveNdx];
949 log << TestLog::Message << "Attachment: " << preserveAttachment << TestLog::EndMessage;
956 if (!renderPass.getDependencies().empty())
958 const tcu::ScopedLogSection dependenciesSection (log, "Dependencies", "Dependencies");
960 for (size_t depNdx = 0; depNdx < renderPass.getDependencies().size(); depNdx++)
962 const tcu::ScopedLogSection dependencySection (log, "Dependency" + de::toString(depNdx), "Dependency " + de::toString(depNdx));
963 const SubpassDependency& dep = renderPass.getDependencies()[depNdx];
965 log << TestLog::Message << "Source: " << dep.getSrcPass() << TestLog::EndMessage;
966 log << TestLog::Message << "Destination: " << dep.getDstPass() << TestLog::EndMessage;
968 log << TestLog::Message << "Source Stage Mask: " << dep.getSrcStageMask() << TestLog::EndMessage;
969 log << TestLog::Message << "Destination Stage Mask: " << dep.getDstStageMask() << TestLog::EndMessage;
971 log << TestLog::Message << "Input Mask: " << dep.getDstAccessMask() << TestLog::EndMessage;
972 log << TestLog::Message << "Output Mask: " << dep.getSrcAccessMask() << TestLog::EndMessage;
973 log << TestLog::Message << "Dependency Flags: " << getDependencyFlagsStr(dep.getFlags()) << TestLog::EndMessage;
978 std::string clearColorToString (VkFormat vkFormat, VkClearColorValue value, deBool useFormatCompCount)
980 const tcu::TextureFormat format = mapVkFormat(vkFormat);
981 const tcu::TextureChannelClass channelClass = tcu::getTextureChannelClass(format.type);
982 const tcu::BVec4 channelMask = tcu::getTextureFormatChannelMask(format);
983 const deUint32 componentCount = (useFormatCompCount ? (deUint32)tcu::getNumUsedChannels(format.order) : 4);
985 std::ostringstream stream;
989 switch (channelClass)
991 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
992 for (deUint32 i = 0; i < componentCount; i++)
998 stream << value.int32[i];
1004 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1005 for (deUint32 i = 0; i < componentCount; i++)
1011 stream << value.uint32[i];
1017 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1018 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1019 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
1020 for (deUint32 i = 0; i < componentCount; i++)
1026 stream << value.float32[i];
1033 DE_FATAL("Unknown channel class");
1038 return stream.str();
1041 std::string clearValueToString (VkFormat vkFormat, VkClearValue value, deBool useFormatCompCount)
1043 const tcu::TextureFormat format = mapVkFormat(vkFormat);
1045 if (tcu::hasStencilComponent(format.order) || tcu::hasDepthComponent(format.order))
1047 std::ostringstream stream;
1051 if (tcu::hasStencilComponent(format.order))
1052 stream << "stencil: " << value.depthStencil.stencil;
1054 if (tcu::hasStencilComponent(format.order) && tcu::hasDepthComponent(format.order))
1057 if (tcu::hasDepthComponent(format.order))
1058 stream << "depth: " << value.depthStencil.depth;
1062 return stream.str();
1065 return clearColorToString(vkFormat, value.color, useFormatCompCount);
1068 VkClearColorValue randomColorClearValue (const Attachment& attachment, de::Random& rng, deBool useFormatCompCount)
1070 const float clearNan = tcu::Float32::nan().asFloat();
1071 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
1072 const tcu::TextureChannelClass channelClass = tcu::getTextureChannelClass(format.type);
1073 const tcu::BVec4 channelMask = tcu::getTextureFormatChannelMask(format);
1074 const deUint32 componentCount = (useFormatCompCount ? (deUint32)tcu::getNumUsedChannels(format.order) : 4);
1075 VkClearColorValue clearColor;
1077 switch (channelClass)
1079 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
1081 for (deUint32 ndx = 0; ndx < componentCount; ndx++)
1083 if (!channelMask[ndx])
1084 clearColor.int32[ndx] = std::numeric_limits<deInt32>::min();
1086 clearColor.uint32[ndx] = rng.getBool() ? 1u : 0u;
1091 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1093 for (deUint32 ndx = 0; ndx < componentCount; ndx++)
1095 if (!channelMask[ndx])
1096 clearColor.uint32[ndx] = std::numeric_limits<deUint32>::max();
1098 clearColor.uint32[ndx] = rng.getBool() ? 1u : 0u;
1103 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1104 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1105 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
1107 for (deUint32 ndx = 0; ndx < componentCount; ndx++)
1109 if (!channelMask[ndx])
1110 clearColor.float32[ndx] = clearNan;
1112 clearColor.float32[ndx] = rng.getBool() ? 1.0f : 0.0f;
1118 DE_FATAL("Unknown channel class");
1124 template <typename AttachmentDesc>
1125 AttachmentDesc createAttachmentDescription (const Attachment& attachment)
1127 const AttachmentDesc attachmentDescription // VkAttachmentDescription || VkAttachmentDescription2KHR
1129 // || VkStructureType sType;
1130 DE_NULL, // || const void* pNext;
1131 0u, // VkAttachmentDescriptionFlags flags; || VkAttachmentDescriptionFlags flags;
1132 attachment.getFormat(), // VkFormat format; || VkFormat format;
1133 attachment.getSamples(), // VkSampleCountFlagBits samples; || VkSampleCountFlagBits samples;
1134 attachment.getLoadOp(), // VkAttachmentLoadOp loadOp; || VkAttachmentLoadOp loadOp;
1135 attachment.getStoreOp(), // VkAttachmentStoreOp storeOp; || VkAttachmentStoreOp storeOp;
1136 attachment.getStencilLoadOp(), // VkAttachmentLoadOp stencilLoadOp; || VkAttachmentLoadOp stencilLoadOp;
1137 attachment.getStencilStoreOp(), // VkAttachmentStoreOp stencilStoreOp; || VkAttachmentStoreOp stencilStoreOp;
1138 attachment.getInitialLayout(), // VkImageLayout initialLayout; || VkImageLayout initialLayout;
1139 attachment.getFinalLayout() // VkImageLayout finalLayout; || VkImageLayout finalLayout;
1142 return attachmentDescription;
1145 template <typename AttachmentRef>
1146 AttachmentRef createAttachmentReference (const AttachmentReference& referenceInfo)
1148 const AttachmentRef reference // VkAttachmentReference || VkAttachmentReference2KHR
1150 // || VkStructureType sType;
1151 DE_NULL, // || const void* pNext;
1152 referenceInfo.getAttachment(), // deUint32 attachment; || deUint32 attachment;
1153 referenceInfo.getImageLayout(), // VkImageLayout layout; || VkImageLayout layout;
1154 referenceInfo.getAspectMask() // || VkImageAspectFlags aspectMask;
1160 template <typename SubpassDesc, typename AttachmentRef>
1161 SubpassDesc createSubpassDescription (const Subpass& subpass,
1162 vector<AttachmentRef>* attachmentReferenceLists,
1163 vector<deUint32>* preserveAttachmentReferences)
1165 vector<AttachmentRef>& inputAttachmentReferences = attachmentReferenceLists[0];
1166 vector<AttachmentRef>& colorAttachmentReferences = attachmentReferenceLists[1];
1167 vector<AttachmentRef>& resolveAttachmentReferences = attachmentReferenceLists[2];
1168 vector<AttachmentRef>& depthStencilAttachmentReferences = attachmentReferenceLists[3];
1170 for (size_t attachmentNdx = 0; attachmentNdx < subpass.getColorAttachments().size(); attachmentNdx++)
1171 colorAttachmentReferences.push_back(createAttachmentReference<AttachmentRef>(subpass.getColorAttachments()[attachmentNdx]));
1173 for (size_t attachmentNdx = 0; attachmentNdx < subpass.getInputAttachments().size(); attachmentNdx++)
1174 inputAttachmentReferences.push_back(createAttachmentReference<AttachmentRef>(subpass.getInputAttachments()[attachmentNdx]));
1176 for (size_t attachmentNdx = 0; attachmentNdx < subpass.getResolveAttachments().size(); attachmentNdx++)
1177 resolveAttachmentReferences.push_back(createAttachmentReference<AttachmentRef>(subpass.getResolveAttachments()[attachmentNdx]));
1179 depthStencilAttachmentReferences.push_back(createAttachmentReference<AttachmentRef>(subpass.getDepthStencilAttachment()));
1181 for (size_t attachmentNdx = 0; attachmentNdx < subpass.getPreserveAttachments().size(); attachmentNdx++)
1182 preserveAttachmentReferences->push_back(subpass.getPreserveAttachments()[attachmentNdx]);
1184 DE_ASSERT(resolveAttachmentReferences.empty() || colorAttachmentReferences.size() == resolveAttachmentReferences.size());
1187 const SubpassDesc subpassDescription // VkSubpassDescription || VkSubpassDescription2KHR
1189 // || VkStructureType sType;
1190 DE_NULL, // || const void* pNext;
1191 subpass.getFlags(), // VkSubpassDescriptionFlags flags; || VkSubpassDescriptionFlags flags;
1192 subpass.getPipelineBindPoint(), // VkPipelineBindPoint pipelineBindPoint; || VkPipelineBindPoint pipelineBindPoint;
1193 0u, // || deUint32 viewMask;
1194 (deUint32)inputAttachmentReferences.size(), // deUint32 inputAttachmentCount; || deUint32 inputAttachmentCount;
1195 inputAttachmentReferences.empty() ? DE_NULL : &inputAttachmentReferences[0], // const VkAttachmentReference* pInputAttachments; || const VkAttachmentReference2KHR* pInputAttachments;
1196 (deUint32)colorAttachmentReferences.size(), // deUint32 colorAttachmentCount; || deUint32 colorAttachmentCount;
1197 colorAttachmentReferences.empty() ? DE_NULL : &colorAttachmentReferences[0], // const VkAttachmentReference* pColorAttachments; || const VkAttachmentReference2KHR* pColorAttachments;
1198 resolveAttachmentReferences.empty() ? DE_NULL : &resolveAttachmentReferences[0], // const VkAttachmentReference* pResolveAttachments; || const VkAttachmentReference2KHR* pResolveAttachments;
1199 &depthStencilAttachmentReferences[0], // const VkAttachmentReference* pDepthStencilAttachment; || const VkAttachmentReference2KHR* pDepthStencilAttachment;
1200 (deUint32)preserveAttachmentReferences->size(), // deUint32 preserveAttachmentCount; || deUint32 preserveAttachmentCount;
1201 preserveAttachmentReferences->empty() ? DE_NULL : &(*preserveAttachmentReferences)[0] // const deUint32* pPreserveAttachments; || const deUint32* pPreserveAttachments;
1204 return subpassDescription;
1208 template <typename SubpassDep>
1209 SubpassDep createSubpassDependency (const SubpassDependency& dependencyInfo)
1211 const SubpassDep dependency // VkSubpassDependency || VkSubpassDependency2KHR
1213 // || VkStructureType sType;
1214 DE_NULL, // || const void* pNext;
1215 dependencyInfo.getSrcPass(), // deUint32 srcSubpass; || deUint32 srcSubpass;
1216 dependencyInfo.getDstPass(), // deUint32 dstSubpass; || deUint32 dstSubpass;
1217 dependencyInfo.getSrcStageMask(), // VkPipelineStageFlags srcStageMask; || VkPipelineStageFlags srcStageMask;
1218 dependencyInfo.getDstStageMask(), // VkPipelineStageFlags dstStageMask; || VkPipelineStageFlags dstStageMask;
1219 dependencyInfo.getSrcAccessMask(), // VkAccessFlags srcAccessMask; || VkAccessFlags srcAccessMask;
1220 dependencyInfo.getDstAccessMask(), // VkAccessFlags dstAccessMask; || VkAccessFlags dstAccessMask;
1221 dependencyInfo.getFlags(), // VkDependencyFlags dependencyFlags; || VkDependencyFlags dependencyFlags;
1222 0u // || deInt32 viewOffset;
1228 de::MovePtr<VkRenderPassInputAttachmentAspectCreateInfo> createRenderPassInputAttachmentAspectCreateInfo(const RenderPass& renderPassInfo)
1230 de::MovePtr<VkRenderPassInputAttachmentAspectCreateInfo> result (DE_NULL);
1232 if (!renderPassInfo.getInputAspects().empty())
1234 const VkRenderPassInputAttachmentAspectCreateInfo inputAspectCreateInfo =
1236 VK_STRUCTURE_TYPE_RENDER_PASS_INPUT_ATTACHMENT_ASPECT_CREATE_INFO,
1239 (deUint32)renderPassInfo.getInputAspects().size(),
1240 renderPassInfo.getInputAspects().data(),
1243 result = de::MovePtr<VkRenderPassInputAttachmentAspectCreateInfo>(new VkRenderPassInputAttachmentAspectCreateInfo(inputAspectCreateInfo));
1249 template<typename AttachmentDesc, typename AttachmentRef, typename SubpassDesc, typename SubpassDep, typename RenderPassCreateInfo>
1250 Move<VkRenderPass> createRenderPass (const DeviceInterface& vk,
1252 const RenderPass& renderPassInfo)
1254 const size_t perSubpassAttachmentReferenceLists = 4;
1255 vector<AttachmentDesc> attachments;
1256 vector<SubpassDesc> subpasses;
1257 vector<SubpassDep> dependencies;
1258 vector<vector<AttachmentRef> > attachmentReferenceLists(renderPassInfo.getSubpasses().size() * perSubpassAttachmentReferenceLists);
1259 vector<vector<deUint32> > preserveAttachments(renderPassInfo.getSubpasses().size());
1260 de::MovePtr<VkRenderPassInputAttachmentAspectCreateInfo> inputAspectCreateInfo(createRenderPassInputAttachmentAspectCreateInfo(renderPassInfo));
1262 for (size_t attachmentNdx = 0; attachmentNdx < renderPassInfo.getAttachments().size(); attachmentNdx++)
1263 attachments.push_back(createAttachmentDescription<AttachmentDesc>(renderPassInfo.getAttachments()[attachmentNdx]));
1265 for (size_t subpassNdx = 0; subpassNdx < renderPassInfo.getSubpasses().size(); subpassNdx++)
1266 subpasses.push_back(createSubpassDescription<SubpassDesc>(renderPassInfo.getSubpasses()[subpassNdx], &(attachmentReferenceLists[subpassNdx * perSubpassAttachmentReferenceLists]), &preserveAttachments[subpassNdx]));
1268 for (size_t depNdx = 0; depNdx < renderPassInfo.getDependencies().size(); depNdx++)
1269 dependencies.push_back(createSubpassDependency<SubpassDep>(renderPassInfo.getDependencies()[depNdx]));
1271 const RenderPassCreateInfo renderPassCreator // VkRenderPassCreateInfo || VkRenderPassCreateInfo2KHR
1273 // VkStructureType sType; || VkStructureType sType;
1274 inputAspectCreateInfo.get(), // const void* pNext; || const void* pNext;
1275 (VkRenderPassCreateFlags)0u, // VkRenderPassCreateFlags flags; || VkRenderPassCreateFlags flags;
1276 (deUint32)attachments.size(), // deUint32 attachmentCount; || deUint32 attachmentCount;
1277 (attachments.empty() ? DE_NULL : &attachments[0]), // const VkAttachmentDescription* pAttachments; || const VkAttachmentDescription2KHR* pAttachments;
1278 (deUint32)subpasses.size(), // deUint32 subpassCount; || deUint32 subpassCount;
1279 (subpasses.empty() ? DE_NULL : &subpasses[0]), // const VkSubpassDescription* pSubpasses; || const VkSubpassDescription2KHR* pSubpasses;
1280 (deUint32)dependencies.size(), // deUint32 dependencyCount; || deUint32 dependencyCount;
1281 (dependencies.empty() ? DE_NULL : &dependencies[0]), // const VkSubpassDependency* pDependencies; || const VkSubpassDependency2KHR* pDependencies;
1282 0u, // || deUint32 correlatedViewMaskCount;
1283 DE_NULL // || const deUint32* pCorrelatedViewMasks;
1286 return renderPassCreator.createRenderPass(vk, device);
1289 Move<VkRenderPass> createRenderPass (const DeviceInterface& vk,
1291 const RenderPass& renderPassInfo,
1292 const RenderingType renderPassType)
1294 switch (renderPassType)
1296 case RENDERING_TYPE_RENDERPASS_LEGACY:
1297 return createRenderPass<AttachmentDescription1, AttachmentReference1, SubpassDescription1, SubpassDependency1, RenderPassCreateInfo1>(vk, device, renderPassInfo);
1298 case RENDERING_TYPE_RENDERPASS2:
1299 return createRenderPass<AttachmentDescription2, AttachmentReference2, SubpassDescription2, SubpassDependency2, RenderPassCreateInfo2>(vk, device, renderPassInfo);
1301 TCU_THROW(InternalError, "Impossible");
1305 Move<VkFramebuffer> createFramebuffer (const DeviceInterface& vk,
1307 VkRenderPass renderPass,
1309 const vector<VkImageView>& attachments)
1311 return createFramebuffer(vk, device, 0u, renderPass, (deUint32)attachments.size(), attachments.empty() ? DE_NULL : &attachments[0], size.x(), size.y(), 1u);
1314 Move<VkImage> createAttachmentImage (const DeviceInterface& vk,
1316 deUint32 queueIndex,
1319 VkSampleCountFlagBits samples,
1320 VkImageUsageFlags usageFlags,
1321 VkImageLayout layout)
1323 VkImageUsageFlags targetUsageFlags = 0;
1324 const tcu::TextureFormat textureFormat = mapVkFormat(format);
1326 DE_ASSERT(!(tcu::hasDepthComponent(vk::mapVkFormat(format).order) || tcu::hasStencilComponent(vk::mapVkFormat(format).order))
1327 || ((usageFlags & vk::VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) == 0));
1329 DE_ASSERT((tcu::hasDepthComponent(vk::mapVkFormat(format).order) || tcu::hasStencilComponent(vk::mapVkFormat(format).order))
1330 || ((usageFlags & vk::VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0));
1332 if (tcu::hasDepthComponent(textureFormat.order) || tcu::hasStencilComponent(textureFormat.order))
1333 targetUsageFlags |= vk::VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
1335 targetUsageFlags |= vk::VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
1337 return createImage(vk, device,
1338 (VkImageCreateFlags)0,
1341 vk::makeExtent3D(size.x(), size.y(), 1u),
1345 VK_IMAGE_TILING_OPTIMAL,
1346 usageFlags | targetUsageFlags,
1347 VK_SHARING_MODE_EXCLUSIVE,
1353 de::MovePtr<Allocation> createImageMemory (const InstanceInterface& vki,
1354 const VkPhysicalDevice& vkd,
1355 const DeviceInterface& vk,
1357 Allocator& allocator,
1360 AllocationKind allocationKind)
1362 const MemoryRequirement memoryRequirement = lazy ? MemoryRequirement::LazilyAllocated : MemoryRequirement::Any;
1363 de::MovePtr<Allocation> allocation = allocateImage(vki, vk, vkd, device, image, memoryRequirement, allocator, allocationKind);
1365 bindImageMemory(vk, device, image, allocation->getMemory(), allocation->getOffset());
1370 Move<VkImageView> createImageAttachmentView (const DeviceInterface& vk,
1374 VkImageAspectFlags aspect)
1376 const VkImageSubresourceRange range =
1385 return createImageView(vk, device, 0u, image, VK_IMAGE_VIEW_TYPE_2D, format, makeComponentMappingRGBA(), range);
1388 VkClearValue randomClearValue (const Attachment& attachment, de::Random& rng, deBool useFormatCompCount, const DepthValuesArray& depthValues)
1390 const float clearNan = tcu::Float32::nan().asFloat();
1391 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
1393 if (tcu::hasStencilComponent(format.order) || tcu::hasDepthComponent(format.order))
1395 VkClearValue clearValue;
1397 clearValue.depthStencil.depth = clearNan;
1398 clearValue.depthStencil.stencil = 0xCDu;
1400 if (tcu::hasStencilComponent(format.order))
1401 clearValue.depthStencil.stencil = rng.getBool()
1405 if (tcu::hasDepthComponent(format.order))
1406 clearValue.depthStencil.depth = float(depthValues[rng.getBool() ? 1 : 0]) / 255.0f;
1412 VkClearValue clearValue;
1414 clearValue.color = randomColorClearValue(attachment, rng, useFormatCompCount);
1420 class AttachmentResources
1423 AttachmentResources (const InstanceInterface& vki,
1424 const VkPhysicalDevice& physDevice,
1425 const DeviceInterface& vk,
1427 Allocator& allocator,
1428 deUint32 queueIndex,
1430 const Attachment& attachmentInfo,
1431 VkImageUsageFlags usageFlags,
1432 const AllocationKind allocationKind)
1433 : m_image (createAttachmentImage(vk, device, queueIndex, size, attachmentInfo.getFormat(), attachmentInfo.getSamples(), usageFlags, VK_IMAGE_LAYOUT_UNDEFINED))
1434 , m_imageMemory (createImageMemory(vki, physDevice, vk, device, allocator, *m_image, ((usageFlags & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) != 0), allocationKind))
1435 , m_attachmentView (createImageAttachmentView(vk, device, *m_image, attachmentInfo.getFormat(), getImageAspectFlags(attachmentInfo.getFormat())))
1437 const tcu::TextureFormat format = mapVkFormat(attachmentInfo.getFormat());
1438 const bool isDepthFormat = tcu::hasDepthComponent(format.order);
1439 const bool isStencilFormat = tcu::hasStencilComponent(format.order);
1441 if (isDepthFormat && isStencilFormat)
1443 m_depthInputAttachmentView = createImageAttachmentView(vk, device, *m_image, attachmentInfo.getFormat(), VK_IMAGE_ASPECT_DEPTH_BIT);
1444 m_stencilInputAttachmentView = createImageAttachmentView(vk, device, *m_image, attachmentInfo.getFormat(), VK_IMAGE_ASPECT_STENCIL_BIT);
1446 m_inputAttachmentViews = std::make_pair(*m_depthInputAttachmentView, *m_stencilInputAttachmentView);
1449 m_inputAttachmentViews = std::make_pair(*m_attachmentView, (vk::VkImageView)0u);
1451 if ((usageFlags & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) == 0)
1453 if (tcu::hasDepthComponent(format.order) && tcu::hasStencilComponent(format.order))
1455 const tcu::TextureFormat depthFormat = getDepthCopyFormat(attachmentInfo.getFormat());
1456 const tcu::TextureFormat stencilFormat = getStencilCopyFormat(attachmentInfo.getFormat());
1458 m_bufferSize = size.x() * size.y() * depthFormat.getPixelSize();
1459 m_secondaryBufferSize = size.x() * size.y() * stencilFormat.getPixelSize();
1461 m_buffer = createBuffer(vk, device, 0, m_bufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_SHARING_MODE_EXCLUSIVE, 1, &queueIndex);
1462 m_bufferMemory = allocateBuffer(vki, vk, physDevice, device, *m_buffer, MemoryRequirement::HostVisible, allocator, allocationKind);
1464 bindBufferMemory(vk, device, *m_buffer, m_bufferMemory->getMemory(), m_bufferMemory->getOffset());
1466 m_secondaryBuffer = createBuffer(vk, device, 0, m_secondaryBufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_SHARING_MODE_EXCLUSIVE, 1, &queueIndex);
1467 m_secondaryBufferMemory = allocateBuffer(vki, vk, physDevice, device, *m_secondaryBuffer, MemoryRequirement::HostVisible, allocator, allocationKind);
1469 bindBufferMemory(vk, device, *m_secondaryBuffer, m_secondaryBufferMemory->getMemory(), m_secondaryBufferMemory->getOffset());
1473 m_bufferSize = size.x() * size.y() * format.getPixelSize();
1475 m_buffer = createBuffer(vk, device, 0, m_bufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_SHARING_MODE_EXCLUSIVE, 1, &queueIndex);
1476 m_bufferMemory = allocateBuffer(vki, vk, physDevice, device, *m_buffer, MemoryRequirement::HostVisible, allocator, allocationKind);
1478 bindBufferMemory(vk, device, *m_buffer, m_bufferMemory->getMemory(), m_bufferMemory->getOffset());
1483 const pair<VkImageView, VkImageView>& getInputAttachmentViews (void) const
1485 return m_inputAttachmentViews;
1488 ~AttachmentResources (void)
1492 VkImageView getAttachmentView (void) const
1494 return *m_attachmentView;
1497 VkImage getImage (void) const
1502 VkBuffer getBuffer (void) const
1504 DE_ASSERT(*m_buffer != DE_NULL);
1508 VkDeviceSize getBufferSize (void) const
1510 DE_ASSERT(*m_buffer != DE_NULL);
1511 return m_bufferSize;
1514 const Allocation& getResultMemory (void) const
1516 DE_ASSERT(m_bufferMemory);
1517 return *m_bufferMemory;
1520 VkBuffer getSecondaryBuffer (void) const
1522 DE_ASSERT(*m_secondaryBuffer != DE_NULL);
1523 return *m_secondaryBuffer;
1526 VkDeviceSize getSecondaryBufferSize (void) const
1528 DE_ASSERT(*m_secondaryBuffer != DE_NULL);
1529 return m_secondaryBufferSize;
1532 const Allocation& getSecondaryResultMemory (void) const
1534 DE_ASSERT(m_secondaryBufferMemory);
1535 return *m_secondaryBufferMemory;
1539 const Unique<VkImage> m_image;
1540 const UniquePtr<Allocation> m_imageMemory;
1541 const Unique<VkImageView> m_attachmentView;
1543 Move<VkImageView> m_depthInputAttachmentView;
1544 Move<VkImageView> m_stencilInputAttachmentView;
1545 pair<VkImageView, VkImageView> m_inputAttachmentViews;
1547 Move<VkBuffer> m_buffer;
1548 VkDeviceSize m_bufferSize;
1549 de::MovePtr<Allocation> m_bufferMemory;
1551 Move<VkBuffer> m_secondaryBuffer;
1552 VkDeviceSize m_secondaryBufferSize;
1553 de::MovePtr<Allocation> m_secondaryBufferMemory;
1556 void uploadBufferData (const DeviceInterface& vk,
1558 const Allocation& memory,
1561 VkDeviceSize nonCoherentAtomSize)
1563 // Expand the range to flush to account for the nonCoherentAtomSize
1564 const VkDeviceSize roundedOffset = de::roundDown(memory.getOffset(), nonCoherentAtomSize);
1565 const VkDeviceSize roundedSize = de::roundUp(memory.getOffset() - roundedOffset + static_cast<VkDeviceSize>(size), nonCoherentAtomSize);
1567 const VkMappedMemoryRange range =
1569 VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, // sType;
1571 memory.getMemory(), // mem;
1572 roundedOffset, // offset;
1573 roundedSize, // size;
1575 void* const ptr = memory.getHostPtr();
1577 deMemcpy(ptr, data, size);
1578 VK_CHECK(vk.flushMappedMemoryRanges(device, 1, &range));
1581 VkImageAspectFlagBits getPrimaryImageAspect (tcu::TextureFormat::ChannelOrder order)
1583 DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELORDER_LAST == 22);
1587 case tcu::TextureFormat::D:
1588 case tcu::TextureFormat::DS:
1589 return VK_IMAGE_ASPECT_DEPTH_BIT;
1591 case tcu::TextureFormat::S:
1592 return VK_IMAGE_ASPECT_STENCIL_BIT;
1595 return VK_IMAGE_ASPECT_COLOR_BIT;
1599 deUint32 getAttachmentNdx (const vector<AttachmentReference>& colorAttachments, size_t ndx)
1601 return (colorAttachments[ndx].getAttachment() == VK_ATTACHMENT_UNUSED) ? (deUint32)ndx : colorAttachments[ndx].getAttachment();
1607 RenderQuad (const Vec2& posA, const Vec2& posB)
1610 m_vertices[0] = posA;
1611 m_vertices[1] = Vec2(posA[0], posB[1]);
1612 m_vertices[2] = posB;
1614 m_vertices[3] = posB;
1615 m_vertices[4] = Vec2(posB[0], posA[1]);
1616 m_vertices[5] = posA;
1619 const Vec2& getCornerA (void) const
1621 return m_vertices[0];
1624 const Vec2& getCornerB (void) const
1626 return m_vertices[2];
1629 const void* getVertexPointer (void) const
1631 return &m_vertices[0];
1634 size_t getVertexDataSize (void) const
1636 return sizeof(Vec2) * m_vertices.size();
1640 vector<Vec2> m_vertices;
1646 ColorClear (const UVec2& offset,
1648 const VkClearColorValue& color)
1655 const UVec2& getOffset (void) const { return m_offset; }
1656 const UVec2& getSize (void) const { return m_size; }
1657 const VkClearColorValue& getColor (void) const { return m_color; }
1662 VkClearColorValue m_color;
1665 class DepthStencilClear
1668 DepthStencilClear (const UVec2& offset,
1675 , m_stencil (stencil)
1679 const UVec2& getOffset (void) const { return m_offset; }
1680 const UVec2& getSize (void) const { return m_size; }
1681 float getDepth (void) const { return m_depth; }
1682 deUint32 getStencil (void) const { return m_stencil; }
1685 const UVec2 m_offset;
1688 const float m_depth;
1689 const deUint32 m_stencil;
1692 class SubpassRenderInfo
1695 SubpassRenderInfo (const RenderPass& renderPass,
1696 deUint32 subpassIndex,
1697 deUint32 drawStartNdx,
1700 bool omitBlendState_,
1702 const UVec2& viewportOffset,
1703 const UVec2& viewportSize,
1705 const Maybe<RenderQuad>& renderQuad,
1706 const vector<ColorClear>& colorClears,
1707 const Maybe<DepthStencilClear>& depthStencilClear)
1708 : m_viewportOffset (viewportOffset)
1709 , m_viewportSize (viewportSize)
1710 , m_subpassIndex (subpassIndex)
1711 , m_drawStartNdx (drawStartNdx)
1712 , m_isSecondary (isSecondary_)
1713 , m_omitBlendState (omitBlendState_)
1714 , m_flags (renderPass.getSubpasses()[subpassIndex].getFlags())
1715 , m_renderQuad (renderQuad)
1716 , m_colorClears (colorClears)
1717 , m_depthStencilClear (depthStencilClear)
1718 , m_colorAttachments (renderPass.getSubpasses()[subpassIndex].getColorAttachments())
1719 , m_inputAttachments (renderPass.getSubpasses()[subpassIndex].getInputAttachments())
1721 for (deUint32 attachmentNdx = 0; attachmentNdx < (deUint32)m_colorAttachments.size(); attachmentNdx++)
1722 m_colorAttachmentInfo.push_back(renderPass.getAttachments()[getAttachmentNdx(m_colorAttachments, attachmentNdx)]);
1724 if (renderPass.getSubpasses()[subpassIndex].getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED)
1726 m_depthStencilAttachment = tcu::just(renderPass.getSubpasses()[subpassIndex].getDepthStencilAttachment());
1727 m_depthStencilAttachmentInfo = tcu::just(renderPass.getAttachments()[renderPass.getSubpasses()[subpassIndex].getDepthStencilAttachment().getAttachment()]);
1731 const UVec2& getViewportOffset (void) const { return m_viewportOffset; }
1732 const UVec2& getViewportSize (void) const { return m_viewportSize; }
1734 deUint32 getSubpassIndex (void) const { return m_subpassIndex; }
1735 deUint32 getDrawStartNdx (void) const { return m_drawStartNdx; }
1736 bool isSecondary (void) const { return m_isSecondary; }
1737 bool getOmitBlendState (void) const { return m_omitBlendState; }
1739 const Maybe<RenderQuad>& getRenderQuad (void) const { return m_renderQuad; }
1740 const vector<ColorClear>& getColorClears (void) const { return m_colorClears; }
1741 const Maybe<DepthStencilClear>& getDepthStencilClear (void) const { return m_depthStencilClear; }
1743 deUint32 getInputAttachmentCount (void) const { return (deUint32)m_inputAttachments.size(); }
1744 deUint32 getInputAttachmentIndex (deUint32 attachmentNdx) const { return m_inputAttachments[attachmentNdx].getAttachment(); }
1745 VkImageLayout getInputAttachmentLayout (deUint32 attachmentNdx) const { return m_inputAttachments[attachmentNdx].getImageLayout(); }
1747 deUint32 getColorAttachmentCount (void) const { return (deUint32)m_colorAttachments.size(); }
1748 VkImageLayout getColorAttachmentLayout (deUint32 attachmentNdx) const { return m_colorAttachments[attachmentNdx].getImageLayout(); }
1749 deUint32 getColorAttachmentIndex (deUint32 attachmentNdx) const { return m_colorAttachments[attachmentNdx].getAttachment(); }
1750 const Attachment& getColorAttachment (deUint32 attachmentNdx) const { return m_colorAttachmentInfo[attachmentNdx]; }
1751 Maybe<VkImageLayout> getDepthStencilAttachmentLayout (void) const { return m_depthStencilAttachment ? tcu::just(m_depthStencilAttachment->getImageLayout()) : tcu::Nothing; }
1752 Maybe<deUint32> getDepthStencilAttachmentIndex (void) const { return m_depthStencilAttachment ? tcu::just(m_depthStencilAttachment->getAttachment()) : tcu::Nothing; }
1753 const Maybe<Attachment>& getDepthStencilAttachment (void) const { return m_depthStencilAttachmentInfo; }
1754 VkSubpassDescriptionFlags getSubpassFlags (void) const { return m_flags; }
1757 UVec2 m_viewportOffset;
1758 UVec2 m_viewportSize;
1760 deUint32 m_subpassIndex;
1761 deUint32 m_drawStartNdx;
1763 bool m_omitBlendState;
1764 VkSubpassDescriptionFlags m_flags;
1766 Maybe<RenderQuad> m_renderQuad;
1767 vector<ColorClear> m_colorClears;
1768 Maybe<DepthStencilClear> m_depthStencilClear;
1770 vector<AttachmentReference> m_colorAttachments;
1771 vector<Attachment> m_colorAttachmentInfo;
1773 Maybe<AttachmentReference> m_depthStencilAttachment;
1774 Maybe<Attachment> m_depthStencilAttachmentInfo;
1776 vector<AttachmentReference> m_inputAttachments;
1779 void beginCommandBuffer (const DeviceInterface& vk,
1780 VkCommandBuffer cmdBuffer,
1781 VkRenderPass pInheritanceInfo_renderPass,
1782 deUint32 pInheritanceInfo_subpass,
1783 VkFramebuffer pInheritanceInfo_framebuffer,
1784 VkBool32 pInheritanceInfo_occlusionQueryEnable,
1785 VkQueryControlFlags pInheritanceInfo_queryFlags,
1786 VkQueryPipelineStatisticFlags pInheritanceInfo_pipelineStatistics,
1787 const SubpassRenderInfo* pRenderInfo = 0,
1788 bool dynamicRenderPass = false,
1789 bool secondaryCmdBufferCompletelyContainsRenderpass = false)
1791 VkCommandBufferUsageFlags usageFlags = (VkCommandBufferUsageFlags)0;
1792 VkCommandBufferInheritanceInfo pInheritanceInfo
1794 VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO,
1796 pInheritanceInfo_renderPass,
1797 pInheritanceInfo_subpass,
1798 pInheritanceInfo_framebuffer,
1799 pInheritanceInfo_occlusionQueryEnable,
1800 pInheritanceInfo_queryFlags,
1801 pInheritanceInfo_pipelineStatistics,
1804 #ifndef CTS_USES_VULKANSC
1806 std::vector<vk::VkFormat> colorAttachmentFormats;
1807 VkCommandBufferInheritanceRenderingInfoKHR inheritanceRenderingInfo = initVulkanStructure();
1809 if (dynamicRenderPass && pRenderInfo)
1811 if (secondaryCmdBufferCompletelyContainsRenderpass)
1812 inheritanceRenderingInfo.flags = VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT;
1814 usageFlags |= VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
1816 for (deUint32 i = 0; i < pRenderInfo->getColorAttachmentCount(); ++i)
1817 colorAttachmentFormats.push_back(pRenderInfo->getColorAttachment(i).getFormat());
1819 inheritanceRenderingInfo.colorAttachmentCount = static_cast<deUint32>(colorAttachmentFormats.size());
1820 inheritanceRenderingInfo.pColorAttachmentFormats = colorAttachmentFormats.data();
1821 if (pRenderInfo->getDepthStencilAttachment())
1823 const VkFormat dsFormat = pRenderInfo->getDepthStencilAttachment()->getFormat();
1824 inheritanceRenderingInfo.depthAttachmentFormat = tcu::hasDepthComponent(mapVkFormat(dsFormat).order) ? dsFormat : VK_FORMAT_UNDEFINED;
1825 inheritanceRenderingInfo.stencilAttachmentFormat = tcu::hasStencilComponent(mapVkFormat(dsFormat).order) ? dsFormat : VK_FORMAT_UNDEFINED;
1828 if (pRenderInfo->getColorAttachmentCount())
1829 inheritanceRenderingInfo.rasterizationSamples = pRenderInfo->getColorAttachment(0).getSamples();
1830 else if (pRenderInfo->getDepthStencilAttachment())
1831 inheritanceRenderingInfo.rasterizationSamples = pRenderInfo->getDepthStencilAttachment()->getSamples();
1833 inheritanceRenderingInfo.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
1835 pInheritanceInfo.pNext = &inheritanceRenderingInfo;
1837 else if (!secondaryCmdBufferCompletelyContainsRenderpass)
1838 usageFlags = VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
1841 DE_UNREF(pRenderInfo);
1842 DE_UNREF(dynamicRenderPass);
1843 DE_UNREF(secondaryCmdBufferCompletelyContainsRenderpass);
1845 usageFlags = VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
1847 #endif // CTS_USES_VULKANSC
1849 const VkCommandBufferBeginInfo pBeginInfo
1851 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
1856 VK_CHECK(vk.beginCommandBuffer(cmdBuffer, &pBeginInfo));
1859 Move<VkPipeline> createSubpassPipeline (const DeviceInterface& vk,
1861 VkRenderPass renderPass,
1862 VkShaderModule vertexShaderModule,
1863 VkShaderModule fragmentShaderModule,
1864 VkPipelineLayout pipelineLayout,
1865 const SubpassRenderInfo& renderInfo)
1867 Maybe<VkSampleCountFlagBits> rasterSamples;
1868 vector<VkPipelineColorBlendAttachmentState> attachmentBlendStates;
1870 for (deUint32 attachmentNdx = 0; attachmentNdx < renderInfo.getColorAttachmentCount(); attachmentNdx++)
1872 const Attachment& attachment = renderInfo.getColorAttachment(attachmentNdx);
1874 DE_ASSERT(!rasterSamples || *rasterSamples == attachment.getSamples());
1876 rasterSamples = attachment.getSamples();
1879 const VkPipelineColorBlendAttachmentState attachmentBlendState =
1881 VK_FALSE, // blendEnable
1882 VK_BLEND_FACTOR_SRC_ALPHA, // srcBlendColor
1883 VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, // destBlendColor
1884 VK_BLEND_OP_ADD, // blendOpColor
1885 VK_BLEND_FACTOR_ONE, // srcBlendAlpha
1886 VK_BLEND_FACTOR_ONE, // destBlendAlpha
1887 VK_BLEND_OP_ADD, // blendOpAlpha
1888 (attachmentNdx < renderInfo.getDrawStartNdx() ? (deUint32)0 :
1889 VK_COLOR_COMPONENT_R_BIT|VK_COLOR_COMPONENT_G_BIT|VK_COLOR_COMPONENT_B_BIT|VK_COLOR_COMPONENT_A_BIT) // channelWriteMask
1892 attachmentBlendStates.push_back(attachmentBlendState);
1896 if (renderInfo.getDepthStencilAttachment())
1898 const Attachment& attachment = *renderInfo.getDepthStencilAttachment();
1900 DE_ASSERT(!rasterSamples || *rasterSamples == attachment.getSamples());
1901 rasterSamples = attachment.getSamples();
1904 // If there are no attachment use single sample
1906 rasterSamples = VK_SAMPLE_COUNT_1_BIT;
1908 const VkVertexInputBindingDescription vertexBinding =
1911 (deUint32)sizeof(tcu::Vec2), // strideInBytes
1912 VK_VERTEX_INPUT_RATE_VERTEX, // stepRate
1915 const VkVertexInputAttributeDescription vertexAttrib =
1919 VK_FORMAT_R32G32_SFLOAT, // format
1920 0u, // offsetInBytes
1923 const VkPipelineVertexInputStateCreateInfo vertexInputState =
1925 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, // sType
1927 (VkPipelineVertexInputStateCreateFlags)0u,
1929 &vertexBinding, // pVertexBindingDescriptions
1930 1u, // attributeCount
1931 &vertexAttrib, // pVertexAttributeDescriptions
1934 const VkPipelineInputAssemblyStateCreateInfo inputAssemblyState =
1936 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, // VkStructureType sType
1937 DE_NULL, // const void* pNext
1938 0u, // VkPipelineInputAssemblyStateCreateFlags flags
1939 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, // VkPrimitiveTopology topology
1940 VK_FALSE // VkBool32 primitiveRestartEnable
1943 const VkViewport viewport =
1945 (float)renderInfo.getViewportOffset().x(), (float)renderInfo.getViewportOffset().y(),
1946 (float)renderInfo.getViewportSize().x(), (float)renderInfo.getViewportSize().y(),
1950 const VkRect2D scissor =
1952 { (deInt32)renderInfo.getViewportOffset().x(), (deInt32)renderInfo.getViewportOffset().y() },
1953 { renderInfo.getViewportSize().x(), renderInfo.getViewportSize().y() }
1956 const VkPipelineViewportStateCreateInfo viewportState =
1958 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, // VkStructureType sType
1959 DE_NULL, // const void* pNext
1960 (VkPipelineViewportStateCreateFlags)0, // VkPipelineViewportStateCreateFlags flags
1961 1u, // deUint32 viewportCount
1962 &viewport, // const VkViewport* pViewports
1963 1u, // deUint32 scissorCount
1964 &scissor // const VkRect2D* pScissors
1967 const VkPipelineRasterizationStateCreateInfo rasterizationState =
1969 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, // VkStructureType sType
1970 DE_NULL, // const void* pNext
1971 0u, // VkPipelineRasterizationStateCreateFlags flags
1972 VK_FALSE, // VkBool32 depthClampEnable
1973 VK_FALSE, // VkBool32 rasterizerDiscardEnable
1974 VK_POLYGON_MODE_FILL, // VkPolygonMode polygonMode
1975 VK_CULL_MODE_NONE, // VkCullModeFlags cullMode
1976 VK_FRONT_FACE_COUNTER_CLOCKWISE, // VkFrontFace frontFace
1977 VK_FALSE, // VkBool32 depthBiasEnable
1978 0.0f, // float depthBiasConstantFactor
1979 0.0f, // float depthBiasClamp
1980 0.0f, // float depthBiasSlopeFactor
1981 1.0f // float lineWidth
1984 const VkPipelineMultisampleStateCreateInfo multisampleState =
1986 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // sType
1988 (VkPipelineMultisampleStateCreateFlags)0u,
1989 *rasterSamples, // rasterSamples
1990 VK_FALSE, // sampleShadingEnable
1991 0.0f, // minSampleShading
1992 DE_NULL, // pSampleMask
1993 VK_FALSE, // alphaToCoverageEnable
1994 VK_FALSE, // alphaToOneEnable
1996 const size_t stencilIndex = renderInfo.getSubpassIndex();
1998 const VkBool32 writeDepth = renderInfo.getDepthStencilAttachmentLayout()
1999 && *renderInfo.getDepthStencilAttachmentLayout() != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
2000 && *renderInfo.getDepthStencilAttachmentLayout() != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL
2004 const VkBool32 writeStencil = renderInfo.getDepthStencilAttachmentLayout()
2005 && *renderInfo.getDepthStencilAttachmentLayout() != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
2006 && *renderInfo.getDepthStencilAttachmentLayout() != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL
2010 const VkPipelineDepthStencilStateCreateInfo depthStencilState =
2012 VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, // sType
2014 (VkPipelineDepthStencilStateCreateFlags)0u,
2015 writeDepth, // depthTestEnable
2016 writeDepth, // depthWriteEnable
2017 VK_COMPARE_OP_ALWAYS, // depthCompareOp
2018 VK_FALSE, // depthBoundsEnable
2019 writeStencil, // stencilTestEnable
2021 VK_STENCIL_OP_REPLACE, // stencilFailOp
2022 VK_STENCIL_OP_REPLACE, // stencilPassOp
2023 VK_STENCIL_OP_REPLACE, // stencilDepthFailOp
2024 VK_COMPARE_OP_ALWAYS, // stencilCompareOp
2025 ~0u, // stencilCompareMask
2026 ~0u, // stencilWriteMask
2027 ((stencilIndex % 2) == 0) ? ~0x0u : 0x0u // stencilReference
2030 VK_STENCIL_OP_REPLACE, // stencilFailOp
2031 VK_STENCIL_OP_REPLACE, // stencilPassOp
2032 VK_STENCIL_OP_REPLACE, // stencilDepthFailOp
2033 VK_COMPARE_OP_ALWAYS, // stencilCompareOp
2034 ~0u, // stencilCompareMask
2035 ~0u, // stencilWriteMask
2036 ((stencilIndex % 2) == 0) ? ~0x0u : 0x0u // stencilReference
2039 0.0f, // minDepthBounds;
2040 1.0f // maxDepthBounds;
2043 const VkPipelineColorBlendStateCreateInfo blendState =
2045 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, // sType
2047 (VkPipelineColorBlendStateCreateFlags)0u,
2048 VK_FALSE, // logicOpEnable
2049 VK_LOGIC_OP_COPY, // logicOp
2050 (deUint32)attachmentBlendStates.size(), // attachmentCount
2051 attachmentBlendStates.empty() ? DE_NULL : &attachmentBlendStates[0],// pAttachments
2052 { 0.0f, 0.0f, 0.0f, 0.0f } // blendConst
2055 #ifndef CTS_USES_VULKANSC
2056 std::vector<vk::VkFormat> colorAttachmentFormats;
2057 for (deUint32 i = 0; i < renderInfo.getColorAttachmentCount(); ++i)
2058 colorAttachmentFormats.push_back(renderInfo.getColorAttachment(i).getFormat());
2060 vk::VkFormat depthFormat = VK_FORMAT_UNDEFINED;
2061 vk::VkFormat stencilFormat = VK_FORMAT_UNDEFINED;
2062 if (renderInfo.getDepthStencilAttachment())
2064 const Attachment& attachment = *renderInfo.getDepthStencilAttachment();
2065 vk::VkFormat depthStencilFormat = attachment.getFormat();
2066 if (depthStencilFormat != VK_FORMAT_UNDEFINED)
2068 if (tcu::hasDepthComponent(mapVkFormat(depthStencilFormat).order))
2070 depthFormat = depthStencilFormat;
2072 if (tcu::hasStencilComponent(mapVkFormat(depthStencilFormat).order))
2074 stencilFormat = depthStencilFormat;
2080 VkPipelineRenderingCreateInfoKHR renderingCreateInfo
2082 VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR,
2085 static_cast<deUint32>(colorAttachmentFormats.size()),
2086 colorAttachmentFormats.data(),
2090 #endif // CTS_USES_VULKANSC
2092 return makeGraphicsPipeline(vk, // const DeviceInterface& vk
2093 device, // const VkDevice device
2094 pipelineLayout, // const VkPipelineLayout pipelineLayout
2095 vertexShaderModule, // const VkShaderModule vertexShaderModule
2096 DE_NULL, // const VkShaderModule tessellationControlShaderModule
2097 DE_NULL, // const VkShaderModule tessellationEvalShaderModule
2098 DE_NULL, // const VkShaderModule geometryShaderModule
2099 fragmentShaderModule, // const VkShaderModule fragmentShaderModule
2100 renderPass, // const VkRenderPass renderPass
2101 renderInfo.getSubpassIndex(), // const deUint32 subpass
2102 &vertexInputState, // const VkPipelineVertexInputStateCreateInfo* vertexInputStateCreateInfo
2103 &inputAssemblyState, // const VkPipelineInputAssemblyStateCreateInfo* pInputAssemblyState;
2104 DE_NULL, // const VkPipelineRasterizationStateCreateInfo* rasterizationStateCreateInfo
2105 &viewportState, // const VkPipelineViewportStateCreateInfo* pViewportStat;
2106 &rasterizationState, // const VkPipelineRasterizationStateCreateInfo* pRasterizationState
2107 &multisampleState, // const VkPipelineMultisampleStateCreateInfo* multisampleStateCreateInfo
2108 &depthStencilState, // const VkPipelineDepthStencilStateCreateInfo* depthStencilStateCreateInfo
2109 renderInfo.getOmitBlendState()
2110 ? DE_NULL : &blendState, // const VkPipelineColorBlendStateCreateInfo* colorBlendStateCreateInfo
2111 DE_NULL, // const VkPipelineDynamicStateCreateInfo* dynamicStateCreateInfo
2112 #ifndef CTS_USES_VULKANSC
2113 (renderPass == DE_NULL)
2114 ? &renderingCreateInfo : DE_NULL); // const void* pNext)
2116 DE_NULL); // const void* pNext)
2117 #endif // CTS_USES_VULKANSC
2120 #ifndef CTS_USES_VULKANSC
2121 void beginDynamicRendering(const DeviceInterface& vk,
2122 VkCommandBuffer commandBuffer,
2123 const RenderPass& renderPassInfo,
2124 const vector<de::SharedPtr<AttachmentResources> >& attachmentResources,
2125 const VkRect2D& renderArea,
2126 const vector<Maybe<VkClearValue> >& renderPassClearValues,
2127 const VkRenderingFlagsKHR renderingFlags = 0u)
2129 const float clearNan = tcu::Float32::nan().asFloat();
2130 const VkClearValue clearValueNan = makeClearValueColorF32(clearNan, clearNan, clearNan, clearNan);
2132 // translate structures that were prepared to construct renderpass to structures needed for dynamic rendering
2134 std::vector<vk::VkRenderingAttachmentInfoKHR> colorAttachmentVect;
2135 const Subpass& subpassInfo = renderPassInfo.getSubpasses()[0];
2136 const vector<AttachmentReference>& colorAttachmentsInfo = subpassInfo.getColorAttachments();
2137 const vector<AttachmentReference>& resolveAttachmentsInfo = subpassInfo.getResolveAttachments();
2139 for (deUint32 i = 0; i < colorAttachmentsInfo.size(); ++i)
2141 const AttachmentReference& colorAttachmentReference = colorAttachmentsInfo[i];
2142 const deUint32 colorAttachmentIndex = colorAttachmentReference.getAttachment();
2143 const Attachment& colorAttachmentInfo = renderPassInfo.getAttachments()[colorAttachmentIndex];
2145 VkResolveModeFlagBits resolveMode = VK_RESOLVE_MODE_NONE;
2146 VkImageView resolveImageView = DE_NULL;
2147 VkImageLayout resolveImageLayout = VK_IMAGE_LAYOUT_UNDEFINED;
2149 // handle resolve attachments if they were specified
2150 if (!resolveAttachmentsInfo.empty())
2152 const AttachmentReference& resolveAttachmentReference = resolveAttachmentsInfo[i];
2153 const deUint32 resolveAttachmentIndex = resolveAttachmentReference.getAttachment();
2154 const Attachment& resolveAttachmentInfo = renderPassInfo.getAttachments()[resolveAttachmentIndex];
2156 resolveMode = VK_RESOLVE_MODE_AVERAGE_BIT;
2157 resolveImageView = attachmentResources[resolveAttachmentIndex]->getAttachmentView();
2158 resolveImageLayout = resolveAttachmentInfo.getInitialLayout();
2161 colorAttachmentVect.push_back({
2162 vk::VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR, // VkStructureType sType
2163 DE_NULL, // const void* pNext
2164 attachmentResources[colorAttachmentIndex]->getAttachmentView(), // VkImageView imageView
2165 colorAttachmentReference.getImageLayout(), // VkImageLayout imageLayout
2166 resolveMode, // VkResolveModeFlagBits resolveMode
2167 resolveImageView, // VkImageView resolveImageView
2168 resolveImageLayout, // VkImageLayout resolveImageLayout
2169 colorAttachmentInfo.getLoadOp(), // VkAttachmentLoadOp loadOp
2170 colorAttachmentInfo.getStoreOp(), // VkAttachmentStoreOp storeOp
2171 (renderPassClearValues[colorAttachmentIndex] ?
2172 *renderPassClearValues[colorAttachmentIndex] :
2173 clearValueNan) // VkClearValue clearValue
2177 VkRenderingAttachmentInfoKHR* pDepthAttachment = DE_NULL;
2178 VkRenderingAttachmentInfoKHR* pStencilAttachment = DE_NULL;
2179 VkRenderingAttachmentInfoKHR depthAttachment
2181 vk::VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR, // VkStructureType sType;
2182 DE_NULL, // const void* pNext;
2183 DE_NULL, // VkImageView imageView;
2184 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout imageLayout;
2185 VK_RESOLVE_MODE_NONE, // VkResolveModeFlagBits resolveMode;
2186 DE_NULL, // VkImageView resolveImageView;
2187 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout resolveImageLayout;
2188 VK_ATTACHMENT_LOAD_OP_LOAD, // VkAttachmentLoadOp loadOp;
2189 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
2190 clearValueNan // VkClearValue clearValue;
2192 VkRenderingAttachmentInfoKHR stencilAttachment = depthAttachment;
2193 const AttachmentReference& depthStencilAttachmentReference = subpassInfo.getDepthStencilAttachment();
2194 const deUint32 dsAttachmentIndex = depthStencilAttachmentReference.getAttachment();
2196 if (dsAttachmentIndex != VK_ATTACHMENT_UNUSED)
2198 const Attachment& dsAttachmentInfo = renderPassInfo.getAttachments()[dsAttachmentIndex];
2199 const tcu::TextureFormat format = mapVkFormat(dsAttachmentInfo.getFormat());
2201 if (tcu::hasDepthComponent(format.order))
2203 depthAttachment.imageView = attachmentResources[dsAttachmentIndex]->getAttachmentView();
2204 depthAttachment.imageLayout = depthStencilAttachmentReference.getImageLayout();
2205 depthAttachment.loadOp = dsAttachmentInfo.getLoadOp();
2206 depthAttachment.storeOp = dsAttachmentInfo.getStoreOp();
2208 if (renderPassClearValues[dsAttachmentIndex])
2209 depthAttachment.clearValue = *renderPassClearValues[dsAttachmentIndex];
2211 pDepthAttachment = &depthAttachment;
2214 if (tcu::hasStencilComponent(format.order))
2216 stencilAttachment.imageView = attachmentResources[dsAttachmentIndex]->getAttachmentView();
2217 stencilAttachment.imageLayout = depthStencilAttachmentReference.getImageLayout();
2218 stencilAttachment.loadOp = dsAttachmentInfo.getStencilLoadOp();
2219 stencilAttachment.storeOp = dsAttachmentInfo.getStencilStoreOp();
2221 if (renderPassClearValues[dsAttachmentIndex])
2222 stencilAttachment.clearValue = *renderPassClearValues[dsAttachmentIndex];
2224 pStencilAttachment = &stencilAttachment;
2228 vk::VkRenderingInfoKHR renderingInfo
2230 vk::VK_STRUCTURE_TYPE_RENDERING_INFO_KHR,
2232 renderingFlags, // VkRenderingFlagsKHR flags;
2233 renderArea, // VkRect2D renderArea;
2234 1u, // deUint32 layerCount;
2235 0u, // deUint32 viewMask;
2236 static_cast<deUint32>(colorAttachmentVect.size()), // deUint32 colorAttachmentCount;
2237 colorAttachmentVect.empty() ? DE_NULL : &colorAttachmentVect[0], // const VkRenderingAttachmentInfoKHR* pColorAttachments;
2238 pDepthAttachment, // const VkRenderingAttachmentInfoKHR* pDepthAttachment;
2239 pStencilAttachment // const VkRenderingAttachmentInfoKHR* pStencilAttachment;
2242 vk.cmdBeginRendering(commandBuffer, &renderingInfo);
2245 void endDynamicRendering(const DeviceInterface& vk, VkCommandBuffer commandBuffer)
2247 vk.cmdEndRendering(commandBuffer);
2249 #endif // CTS_USES_VULKANSC
2251 class SubpassRenderer
2254 SubpassRenderer (Context& context,
2255 const DeviceInterface& vk,
2257 Allocator& allocator,
2258 const RenderPass& renderPassInfo,
2259 const vector<de::SharedPtr<AttachmentResources> >& attachmentResources,
2260 const VkRect2D& renderArea,
2261 const vector<Maybe<VkClearValue> >& renderPassClearValues,
2262 VkRenderPass renderPass,
2263 VkFramebuffer framebuffer,
2264 VkCommandPool commandBufferPool,
2265 deUint32 queueFamilyIndex,
2266 const vector<VkImage>& attachmentImages,
2267 const vector<pair<VkImageView, VkImageView> >& attachmentViews,
2268 const SubpassRenderInfo& renderInfo,
2269 const AllocationKind allocationKind,
2270 const bool dynamicRendering,
2271 const bool secondaryCmdBufferCompletelyContainsDynamicRenderpass)
2272 : m_renderInfo (renderInfo)
2274 // unreference values not used by Vulkan SC, no need to pu this under ifdef
2275 DE_UNREF(attachmentResources);
2276 DE_UNREF(renderArea);
2277 DE_UNREF(renderPassClearValues);
2279 const InstanceInterface& vki = context.getInstanceInterface();
2280 const VkPhysicalDevice& physDevice = context.getPhysicalDevice();
2281 const vector<Attachment>& attachmentInfos = renderPassInfo.getAttachments();
2282 const deUint32 subpassIndex = renderInfo.getSubpassIndex();
2283 vector<VkDescriptorSetLayoutBinding> bindings;
2285 for (deUint32 colorAttachmentNdx = 0; colorAttachmentNdx < renderInfo.getColorAttachmentCount(); colorAttachmentNdx++)
2287 const deUint32 attachmentNdx = (renderInfo.getColorAttachmentIndex(colorAttachmentNdx) == VK_ATTACHMENT_UNUSED) ? colorAttachmentNdx
2288 : renderInfo.getColorAttachmentIndex(colorAttachmentNdx);
2290 m_colorAttachmentImages.push_back(attachmentImages[attachmentNdx]);
2293 if (renderInfo.getDepthStencilAttachmentIndex())
2294 m_depthStencilAttachmentImage = attachmentImages[*renderInfo.getDepthStencilAttachmentIndex()];
2296 if (renderInfo.getRenderQuad())
2298 const RenderQuad& renderQuad = *renderInfo.getRenderQuad();
2300 if (renderInfo.getInputAttachmentCount() > 0)
2302 deUint32 bindingIndex = 0;
2304 for (deUint32 inputAttachmentNdx = 0; inputAttachmentNdx < renderInfo.getInputAttachmentCount(); inputAttachmentNdx++)
2306 const Attachment attachmentInfo = attachmentInfos[renderInfo.getInputAttachmentIndex(inputAttachmentNdx)];
2307 const VkImageLayout layout = renderInfo.getInputAttachmentLayout(inputAttachmentNdx);
2308 const tcu::TextureFormat format = mapVkFormat(attachmentInfo.getFormat());
2309 const bool isDepthFormat = tcu::hasDepthComponent(format.order);
2310 const bool isStencilFormat = tcu::hasStencilComponent(format.order);
2311 const deUint32 bindingCount = (isDepthFormat && layout != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
2312 && (isStencilFormat && layout != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL)
2316 for (deUint32 bindingNdx = 0; bindingNdx < bindingCount; bindingNdx++)
2318 const VkDescriptorSetLayoutBinding binding =
2321 vk::VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
2323 vk::VK_SHADER_STAGE_FRAGMENT_BIT,
2327 bindings.push_back(binding);
2332 const VkDescriptorSetLayoutCreateInfo createInfo =
2334 vk::VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
2338 (deUint32)bindings.size(),
2342 m_descriptorSetLayout = vk::createDescriptorSetLayout(vk, device, &createInfo);
2345 const VkDescriptorSetLayout descriptorSetLayout = *m_descriptorSetLayout;
2346 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
2348 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // sType;
2350 (vk::VkPipelineLayoutCreateFlags)0,
2351 m_descriptorSetLayout ? 1u :0u , // setLayoutCount;
2352 m_descriptorSetLayout ? &descriptorSetLayout : DE_NULL, // pSetLayouts;
2353 0u, // pushConstantRangeCount;
2354 DE_NULL, // pPushConstantRanges;
2357 m_vertexShaderModule = createShaderModule(vk, device, context.getBinaryCollection().get(de::toString(subpassIndex) + "-vert"), 0u);
2358 m_fragmentShaderModule = createShaderModule(vk, device, context.getBinaryCollection().get(de::toString(subpassIndex) + "-frag"), 0u);
2359 m_pipelineLayout = createPipelineLayout(vk, device, &pipelineLayoutParams);
2360 m_pipeline = createSubpassPipeline(vk, device, renderPass, *m_vertexShaderModule, *m_fragmentShaderModule, *m_pipelineLayout, m_renderInfo);
2362 // Round up the vertex buffer size to honor nonCoherentAtomSize.
2363 const auto properties = vk::getPhysicalDeviceProperties(context.getInstanceInterface(), context.getPhysicalDevice());
2364 const auto vertexBufferSize = de::roundUp(static_cast<VkDeviceSize>(renderQuad.getVertexDataSize()), properties.limits.nonCoherentAtomSize);
2366 m_vertexBuffer = createBuffer(vk, device, 0u, vertexBufferSize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_SHARING_MODE_EXCLUSIVE, 1u, &queueFamilyIndex);
2367 m_vertexBufferMemory = allocateBuffer(vki, vk, physDevice, device, *m_vertexBuffer, MemoryRequirement::HostVisible, allocator, allocationKind);
2369 bindBufferMemory(vk, device, *m_vertexBuffer, m_vertexBufferMemory->getMemory(), m_vertexBufferMemory->getOffset());
2371 uploadBufferData(vk, device, *m_vertexBufferMemory, renderQuad.getVertexDataSize(), renderQuad.getVertexPointer(), properties.limits.nonCoherentAtomSize);
2373 if (renderInfo.getInputAttachmentCount() > 0)
2376 const VkDescriptorPoolSize poolSize =
2378 vk::VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
2379 // \note Reserve 2 per input attachment since depthStencil attachments require 2.
2380 renderInfo.getInputAttachmentCount() * 2u
2382 const VkDescriptorPoolCreateInfo createInfo =
2384 vk::VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
2386 VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT,
2388 // \note Reserve 2 per input attachment since depthStencil attachments require 2.
2389 renderInfo.getInputAttachmentCount() * 2u,
2394 m_descriptorPool = vk::createDescriptorPool(vk, device, &createInfo);
2397 const VkDescriptorSetAllocateInfo allocateInfo =
2399 vk::VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
2404 &descriptorSetLayout
2407 m_descriptorSet = vk::allocateDescriptorSet(vk, device, &allocateInfo);
2410 vector<VkWriteDescriptorSet> writes (bindings.size());
2411 vector<VkDescriptorImageInfo> imageInfos (bindings.size());
2412 deUint32 bindingIndex = 0;
2414 for (deUint32 inputAttachmentNdx = 0; inputAttachmentNdx < renderInfo.getInputAttachmentCount(); inputAttachmentNdx++)
2416 const Attachment attachmentInfo = attachmentInfos[renderInfo.getInputAttachmentIndex(inputAttachmentNdx)];
2417 const tcu::TextureFormat format = mapVkFormat(attachmentInfo.getFormat());
2418 const bool isDepthFormat = tcu::hasDepthComponent(format.order);
2419 const bool isStencilFormat = tcu::hasStencilComponent(format.order);
2420 const VkImageLayout inputAttachmentLayout = renderInfo.getInputAttachmentLayout(inputAttachmentNdx);
2423 if (isDepthFormat && isStencilFormat)
2425 if (inputAttachmentLayout != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL)
2427 const VkDescriptorImageInfo imageInfo =
2430 attachmentViews[renderInfo.getInputAttachmentIndex(inputAttachmentNdx)].first,
2431 inputAttachmentLayout
2433 imageInfos[bindingIndex] = imageInfo;
2436 const VkWriteDescriptorSet write =
2438 VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
2445 VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
2446 &imageInfos[bindingIndex],
2450 writes[bindingIndex] = write;
2456 if (inputAttachmentLayout != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
2458 const VkDescriptorImageInfo imageInfo =
2461 attachmentViews[renderInfo.getInputAttachmentIndex(inputAttachmentNdx)].second,
2462 inputAttachmentLayout
2464 imageInfos[bindingIndex] = imageInfo;
2467 const VkWriteDescriptorSet write =
2469 VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
2476 VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
2477 &imageInfos[bindingIndex],
2481 writes[bindingIndex] = write;
2489 const VkDescriptorImageInfo imageInfo =
2492 attachmentViews[renderInfo.getInputAttachmentIndex(inputAttachmentNdx)].first,
2493 inputAttachmentLayout
2495 imageInfos[bindingIndex] = imageInfo;
2498 const VkWriteDescriptorSet write =
2500 VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
2507 VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
2508 &imageInfos[bindingIndex],
2512 writes[bindingIndex] = write;
2519 vk.updateDescriptorSets(device, (deUint32)writes.size(), &writes[0], 0u, DE_NULL);
2524 if (renderInfo.isSecondary())
2526 m_commandBuffer = allocateCommandBuffer(vk, device, commandBufferPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
2528 beginCommandBuffer(vk, *m_commandBuffer, renderPass, subpassIndex, framebuffer, VK_FALSE, (VkQueryControlFlags)0,
2529 (VkQueryPipelineStatisticFlags)0, &renderInfo, dynamicRendering, secondaryCmdBufferCompletelyContainsDynamicRenderpass);
2531 if (dynamicRendering && secondaryCmdBufferCompletelyContainsDynamicRenderpass)
2533 #ifndef CTS_USES_VULKANSC
2534 beginDynamicRendering(vk, *m_commandBuffer, renderPassInfo, attachmentResources, renderArea, renderPassClearValues);
2535 pushRenderCommands(vk, *m_commandBuffer);
2536 endDynamicRendering(vk, *m_commandBuffer);
2537 #endif // CTS_USES_VULKANSC
2540 pushRenderCommands(vk, *m_commandBuffer);
2542 endCommandBuffer(vk, *m_commandBuffer);
2546 bool isSecondary (void) const
2548 return !!m_commandBuffer;
2551 VkCommandBuffer getCommandBuffer (void) const
2553 DE_ASSERT(isSecondary());
2554 return *m_commandBuffer;
2557 void pushRenderCommands (const DeviceInterface& vk,
2558 VkCommandBuffer commandBuffer)
2560 if (!m_renderInfo.getColorClears().empty())
2562 const vector<ColorClear>& colorClears (m_renderInfo.getColorClears());
2564 for (deUint32 attachmentNdx = 0; attachmentNdx < m_renderInfo.getColorAttachmentCount(); attachmentNdx++)
2566 const ColorClear& colorClear = colorClears[attachmentNdx];
2567 const VkClearAttachment attachment =
2569 VK_IMAGE_ASPECT_COLOR_BIT,
2571 makeClearValue(colorClear.getColor()),
2573 const VkClearRect rect =
2576 { (deInt32)colorClear.getOffset().x(), (deInt32)colorClear.getOffset().y() },
2577 { colorClear.getSize().x(), colorClear.getSize().y() }
2579 0u, // baseArrayLayer
2583 vk.cmdClearAttachments(commandBuffer, 1u, &attachment, 1u, &rect);
2587 if (m_renderInfo.getDepthStencilClear())
2589 const DepthStencilClear& depthStencilClear = *m_renderInfo.getDepthStencilClear();
2590 const deUint32 attachmentNdx = m_renderInfo.getColorAttachmentCount();
2591 tcu::TextureFormat format = mapVkFormat(m_renderInfo.getDepthStencilAttachment()->getFormat());
2592 const VkImageLayout layout = *m_renderInfo.getDepthStencilAttachmentLayout();
2593 const VkClearAttachment attachment =
2595 (VkImageAspectFlags)((hasDepthComponent(format.order) && layout != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL ? VK_IMAGE_ASPECT_DEPTH_BIT : 0)
2596 | (hasStencilComponent(format.order) && layout != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL ? VK_IMAGE_ASPECT_STENCIL_BIT : 0)),
2598 makeClearValueDepthStencil(depthStencilClear.getDepth(), depthStencilClear.getStencil())
2600 const VkClearRect rect =
2603 { (deInt32)depthStencilClear.getOffset().x(), (deInt32)depthStencilClear.getOffset().y() },
2604 { depthStencilClear.getSize().x(), depthStencilClear.getSize().y() }
2606 0u, // baseArrayLayer
2610 if ((tcu::hasDepthComponent(format.order) && layout != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
2611 || (tcu::hasStencilComponent(format.order) && layout != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL))
2613 vk.cmdClearAttachments(commandBuffer, 1u, &attachment, 1u, &rect);
2617 vector<VkImageMemoryBarrier> selfDeps;
2618 VkPipelineStageFlags srcStages = 0;
2619 VkPipelineStageFlags dstStages = 0;
2621 for (deUint32 inputAttachmentNdx = 0; inputAttachmentNdx < m_renderInfo.getInputAttachmentCount(); inputAttachmentNdx++)
2623 for (deUint32 colorAttachmentNdx = 0; colorAttachmentNdx < m_renderInfo.getColorAttachmentCount(); colorAttachmentNdx++)
2625 if (m_renderInfo.getInputAttachmentIndex(inputAttachmentNdx) == m_renderInfo.getColorAttachmentIndex(colorAttachmentNdx))
2627 const VkImageMemoryBarrier barrier =
2629 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
2632 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // srcAccessMask
2633 VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, // dstAccessMask
2635 VK_IMAGE_LAYOUT_GENERAL, // oldLayout
2636 VK_IMAGE_LAYOUT_GENERAL, // newLayout
2638 VK_QUEUE_FAMILY_IGNORED, // srcQueueFamilyIndex
2639 VK_QUEUE_FAMILY_IGNORED, // destQueueFamilyIndex
2641 m_colorAttachmentImages[colorAttachmentNdx], // image
2642 { // subresourceRange
2643 VK_IMAGE_ASPECT_COLOR_BIT, // aspect
2646 0, // baseArraySlice
2651 srcStages |= VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
2652 dstStages |= VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
2654 selfDeps.push_back(barrier);
2658 if (m_renderInfo.getDepthStencilAttachmentIndex() && (m_renderInfo.getInputAttachmentIndex(inputAttachmentNdx) == *m_renderInfo.getDepthStencilAttachmentIndex()))
2660 const tcu::TextureFormat format = mapVkFormat(m_renderInfo.getDepthStencilAttachment()->getFormat());
2661 const bool hasDepth = hasDepthComponent(format.order);
2662 const bool hasStencil = hasStencilComponent(format.order);
2663 const VkImageMemoryBarrier barrier =
2665 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType;
2668 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, // srcAccessMask
2669 VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, // dstAccessMask
2671 m_renderInfo.getInputAttachmentLayout(inputAttachmentNdx), // oldLayout
2672 m_renderInfo.getInputAttachmentLayout(inputAttachmentNdx), // newLayout;
2674 VK_QUEUE_FAMILY_IGNORED, // srcQueueFamilyIndex;
2675 VK_QUEUE_FAMILY_IGNORED, // destQueueFamilyIndex;
2677 m_depthStencilAttachmentImage, // image;
2678 { // subresourceRange;
2679 (hasDepth ? (VkImageAspectFlags)VK_IMAGE_ASPECT_DEPTH_BIT : 0u)
2680 | (hasStencil ? (VkImageAspectFlags)VK_IMAGE_ASPECT_STENCIL_BIT : 0u), // aspect;
2683 0, // baseArraySlice;
2688 srcStages |= VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT;
2689 dstStages |= VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
2691 selfDeps.push_back(barrier);
2695 if (!selfDeps.empty())
2697 DE_ASSERT(srcStages != 0);
2698 DE_ASSERT(dstStages != 0);
2699 vk.cmdPipelineBarrier(commandBuffer, srcStages, dstStages, VK_DEPENDENCY_BY_REGION_BIT, 0, DE_NULL, 0, DE_NULL, (deUint32)selfDeps.size(), &selfDeps[0]);
2702 if (m_renderInfo.getRenderQuad())
2704 const VkDeviceSize offset = 0;
2705 const VkBuffer vertexBuffer = *m_vertexBuffer;
2707 vk.cmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
2709 if (m_descriptorSet)
2711 const VkDescriptorSet descriptorSet = *m_descriptorSet;
2712 vk.cmdBindDescriptorSets(commandBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipelineLayout, 0u, 1u, &descriptorSet, 0u, NULL);
2715 vk.cmdBindVertexBuffers(commandBuffer, 0u, 1u, &vertexBuffer, &offset);
2716 vk.cmdDraw(commandBuffer, 6u, 1u, 0u, 0u);
2721 const SubpassRenderInfo m_renderInfo;
2722 Move<VkCommandBuffer> m_commandBuffer;
2723 Move<VkPipeline> m_pipeline;
2724 Move<VkDescriptorSetLayout> m_descriptorSetLayout;
2725 Move<VkPipelineLayout> m_pipelineLayout;
2727 Move<VkShaderModule> m_vertexShaderModule;
2728 Move<VkShaderModule> m_fragmentShaderModule;
2730 Move<VkDescriptorPool> m_descriptorPool;
2731 Move<VkDescriptorSet> m_descriptorSet;
2732 Move<VkBuffer> m_vertexBuffer;
2733 de::MovePtr<Allocation> m_vertexBufferMemory;
2734 vector<VkImage> m_colorAttachmentImages;
2735 VkImage m_depthStencilAttachmentImage;
2738 void pushImageInitializationCommands (const DeviceInterface& vk,
2739 VkCommandBuffer commandBuffer,
2740 const vector<Attachment>& attachmentInfo,
2741 const vector<de::SharedPtr<AttachmentResources> >& attachmentResources,
2742 deUint32 queueIndex,
2743 const vector<Maybe<VkClearValue> >& clearValues)
2746 vector<VkImageMemoryBarrier> initializeLayouts;
2748 for (size_t attachmentNdx = 0; attachmentNdx < attachmentInfo.size(); attachmentNdx++)
2750 if (!clearValues[attachmentNdx])
2753 const VkImageMemoryBarrier barrier =
2755 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType;
2758 (VkAccessFlags)0, // srcAccessMask
2759 getAllMemoryReadFlags() | VK_ACCESS_TRANSFER_WRITE_BIT, // dstAccessMask
2761 VK_IMAGE_LAYOUT_UNDEFINED, // oldLayout
2762 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // newLayout;
2764 queueIndex, // srcQueueFamilyIndex;
2765 queueIndex, // destQueueFamilyIndex;
2767 attachmentResources[attachmentNdx]->getImage(), // image;
2768 { // subresourceRange;
2769 getImageAspectFlags(attachmentInfo[attachmentNdx].getFormat()), // aspect;
2772 0, // baseArraySlice;
2777 initializeLayouts.push_back(barrier);
2780 if (!initializeLayouts.empty())
2781 vk.cmdPipelineBarrier(commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT,
2782 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, (VkDependencyFlags)0,
2783 0, (const VkMemoryBarrier*)DE_NULL,
2784 0, (const VkBufferMemoryBarrier*)DE_NULL,
2785 (deUint32)initializeLayouts.size(), &initializeLayouts[0]);
2788 for (size_t attachmentNdx = 0; attachmentNdx < attachmentInfo.size(); attachmentNdx++)
2790 if (!clearValues[attachmentNdx])
2793 const tcu::TextureFormat format = mapVkFormat(attachmentInfo[attachmentNdx].getFormat());
2795 if (hasStencilComponent(format.order) || hasDepthComponent(format.order))
2797 const float clearNan = tcu::Float32::nan().asFloat();
2798 const float clearDepth = hasDepthComponent(format.order) ? clearValues[attachmentNdx]->depthStencil.depth : clearNan;
2799 const deUint32 clearStencil = hasStencilComponent(format.order) ? clearValues[attachmentNdx]->depthStencil.stencil : 0xDEu;
2800 const VkClearDepthStencilValue depthStencil =
2805 const VkImageSubresourceRange range =
2807 (VkImageAspectFlags)((hasDepthComponent(format.order) ? VK_IMAGE_ASPECT_DEPTH_BIT : 0)
2808 | (hasStencilComponent(format.order) ? VK_IMAGE_ASPECT_STENCIL_BIT : 0)),
2815 vk.cmdClearDepthStencilImage(commandBuffer, attachmentResources[attachmentNdx]->getImage(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &depthStencil, 1, &range);
2819 const VkImageSubresourceRange range =
2821 VK_IMAGE_ASPECT_COLOR_BIT, // aspectMask;
2824 0, // baseArrayLayer;
2827 const VkClearColorValue clearColor = clearValues[attachmentNdx]->color;
2829 vk.cmdClearColorImage(commandBuffer, attachmentResources[attachmentNdx]->getImage(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clearColor, 1, &range);
2834 vector<VkImageMemoryBarrier> renderPassLayouts;
2836 for (size_t attachmentNdx = 0; attachmentNdx < attachmentInfo.size(); attachmentNdx++)
2838 const VkImageLayout oldLayout = clearValues[attachmentNdx] ? VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL : VK_IMAGE_LAYOUT_UNDEFINED;
2839 const VkImageMemoryBarrier barrier =
2841 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType;
2844 getMemoryFlagsForLayout(oldLayout), // srcAccessMask
2845 getAllMemoryReadFlags() | getMemoryFlagsForLayout(attachmentInfo[attachmentNdx].getInitialLayout()), // dstAccessMask
2847 oldLayout, // oldLayout
2848 attachmentInfo[attachmentNdx].getInitialLayout(), // newLayout;
2850 queueIndex, // srcQueueFamilyIndex;
2851 queueIndex, // destQueueFamilyIndex;
2853 attachmentResources[attachmentNdx]->getImage(), // image;
2854 { // subresourceRange;
2855 getImageAspectFlags(attachmentInfo[attachmentNdx].getFormat()), // aspect;
2858 0, // baseArraySlice;
2863 renderPassLayouts.push_back(barrier);
2866 if (!renderPassLayouts.empty())
2867 vk.cmdPipelineBarrier(commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT,
2868 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, (VkDependencyFlags)0,
2869 0, (const VkMemoryBarrier*)DE_NULL,
2870 0, (const VkBufferMemoryBarrier*)DE_NULL,
2871 (deUint32)renderPassLayouts.size(), &renderPassLayouts[0]);
2875 template<typename RenderpassSubpass>
2876 void pushRenderPassCommands (const DeviceInterface& vk,
2877 VkCommandBuffer commandBuffer,
2878 VkRenderPass renderPass,
2879 VkFramebuffer framebuffer,
2880 const vector<de::SharedPtr<SubpassRenderer> >& subpassRenderers,
2881 const VkRect2D& renderArea,
2882 const vector<Maybe<VkClearValue> >& renderPassClearValues,
2883 TestConfig::RenderTypes render)
2885 const float clearNan = tcu::Float32::nan().asFloat();
2886 vector<VkClearValue> attachmentClearValues;
2887 const typename RenderpassSubpass::SubpassEndInfo subpassEndInfo (DE_NULL);
2889 for (size_t attachmentNdx = 0; attachmentNdx < renderPassClearValues.size(); attachmentNdx++)
2891 if (renderPassClearValues[attachmentNdx])
2892 attachmentClearValues.push_back(*renderPassClearValues[attachmentNdx]);
2894 attachmentClearValues.push_back(makeClearValueColorF32(clearNan, clearNan, clearNan, clearNan));
2898 for (size_t subpassNdx = 0; subpassNdx < subpassRenderers.size(); subpassNdx++)
2900 const VkSubpassContents contents = subpassRenderers[subpassNdx]->isSecondary() ? VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS : VK_SUBPASS_CONTENTS_INLINE;
2901 const typename RenderpassSubpass::SubpassBeginInfo subpassBeginInfo (DE_NULL, contents);
2902 const VkRenderPassBeginInfo renderPassBeginInfo = createRenderPassBeginInfo(renderPass,
2905 (deUint32)attachmentClearValues.size(),
2906 attachmentClearValues.empty() ? DE_NULL : &attachmentClearValues[0]);
2908 if (subpassNdx == 0)
2909 RenderpassSubpass::cmdBeginRenderPass(vk, commandBuffer, &renderPassBeginInfo, &subpassBeginInfo);
2911 RenderpassSubpass::cmdNextSubpass(vk, commandBuffer, &subpassBeginInfo, &subpassEndInfo);
2915 if (contents == VK_SUBPASS_CONTENTS_INLINE)
2917 subpassRenderers[subpassNdx]->pushRenderCommands(vk, commandBuffer);
2919 else if (contents == VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS)
2921 const VkCommandBuffer cmd = subpassRenderers[subpassNdx]->getCommandBuffer();
2922 vk.cmdExecuteCommands(commandBuffer, 1, &cmd);
2925 DE_FATAL("Invalid contents");
2929 RenderpassSubpass::cmdEndRenderPass(vk, commandBuffer, &subpassEndInfo);
2933 #ifndef CTS_USES_VULKANSC
2934 void pushDynamicRenderingCommands (const DeviceInterface& vk,
2935 VkCommandBuffer commandBuffer,
2936 const RenderPass& renderPassInfo,
2937 const vector<de::SharedPtr<AttachmentResources> >& attachmentResources,
2938 const vector<de::SharedPtr<SubpassRenderer> >& subpassRenderers,
2939 const VkRect2D& renderArea,
2940 const vector<Maybe<VkClearValue> >& renderPassClearValues,
2941 deUint32 queueIndex,
2942 TestConfig::RenderTypes renderType,
2943 bool secondaryCmdBufferCompletelyContainsDynamicRenderpass)
2945 DE_ASSERT(subpassRenderers.size() == 1);
2947 vector<VkImageMemoryBarrier> imageBarriersBeforeRendering;
2948 vector<VkImageMemoryBarrier> imageBarriersAfterRendering;
2950 const Subpass& subpassInfo = renderPassInfo.getSubpasses()[0];
2951 const vector<AttachmentReference>& colorAttachmentsInfo = subpassInfo.getColorAttachments();
2953 for (deUint32 i = 0 ; i < colorAttachmentsInfo.size() ; ++i)
2955 const AttachmentReference& colorAttachmentReference = colorAttachmentsInfo[i];
2956 const deUint32 colorAttachmentIndex = colorAttachmentReference.getAttachment();
2957 const Attachment& colorAttachmentInfo = renderPassInfo.getAttachments()[colorAttachmentIndex];
2959 const VkImageLayout initialLayout = colorAttachmentInfo.getInitialLayout();
2960 const VkImageLayout renderingLayout = colorAttachmentReference.getImageLayout();
2961 const VkImageLayout finalLayout = colorAttachmentInfo.getFinalLayout();
2963 const VkImageMemoryBarrier barrierBeforeRendering
2965 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
2968 getAllMemoryWriteFlags() | getMemoryFlagsForLayout(initialLayout), // srcAccessMask
2969 getMemoryFlagsForLayout(renderingLayout), // dstAccessMask
2971 initialLayout, // oldLayout
2972 renderingLayout, // newLayout
2974 queueIndex, // srcQueueFamilyIndex
2975 queueIndex, // destQueueFamilyIndex
2977 attachmentResources[colorAttachmentIndex]->getImage(), // image
2978 { // subresourceRange
2979 getImageAspectFlags(colorAttachmentInfo.getFormat()), // aspect;
2982 0, // baseArraySlice
2986 imageBarriersBeforeRendering.push_back(barrierBeforeRendering);
2988 const VkImageMemoryBarrier barrierAfterRendering
2990 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
2993 getMemoryFlagsForLayout(renderingLayout), // srcAccessMask
2994 getAllMemoryReadFlags() | getMemoryFlagsForLayout(finalLayout), // dstAccessMask
2996 renderingLayout, // oldLayout
2997 finalLayout, // newLayout
2999 queueIndex, // srcQueueFamilyIndex
3000 queueIndex, // destQueueFamilyIndex
3002 attachmentResources[colorAttachmentIndex]->getImage(), // image
3003 { // subresourceRange
3004 getImageAspectFlags(colorAttachmentInfo.getFormat()), // aspect;
3007 0, // baseArraySlice
3011 imageBarriersAfterRendering.push_back(barrierAfterRendering);
3014 const AttachmentReference& depthStencilAttachmentReference = subpassInfo.getDepthStencilAttachment();
3015 const deUint32 dsAttachmentIndex = depthStencilAttachmentReference.getAttachment();
3017 if (dsAttachmentIndex != VK_ATTACHMENT_UNUSED)
3019 const Attachment& dsAttachmentInfo = renderPassInfo.getAttachments()[dsAttachmentIndex];
3021 const VkImageLayout initialLayout = dsAttachmentInfo.getInitialLayout();
3022 const VkImageLayout renderingLayout = depthStencilAttachmentReference.getImageLayout();
3023 const VkImageLayout finalLayout = dsAttachmentInfo.getFinalLayout();
3025 const VkImageMemoryBarrier barrierBeforeRendering
3027 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
3030 getAllMemoryWriteFlags() | getMemoryFlagsForLayout(initialLayout), // srcAccessMask
3031 getMemoryFlagsForLayout(renderingLayout), // dstAccessMask
3033 initialLayout, // oldLayout
3034 renderingLayout, // newLayout
3036 queueIndex, // srcQueueFamilyIndex
3037 queueIndex, // destQueueFamilyIndex
3039 attachmentResources[dsAttachmentIndex]->getImage(), // image
3040 { // subresourceRange
3041 getImageAspectFlags(dsAttachmentInfo.getFormat()), // aspect;
3044 0, // baseArraySlice
3048 imageBarriersBeforeRendering.push_back(barrierBeforeRendering);
3050 const VkImageMemoryBarrier barrierAfterRendering
3052 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
3055 getMemoryFlagsForLayout(renderingLayout), // srcAccessMask
3056 getAllMemoryReadFlags() | getMemoryFlagsForLayout(finalLayout), // dstAccessMask
3058 renderingLayout, // oldLayout
3059 finalLayout, // newLayout
3061 queueIndex, // srcQueueFamilyIndex
3062 queueIndex, // destQueueFamilyIndex
3064 attachmentResources[dsAttachmentIndex]->getImage(), // image
3065 { // subresourceRange
3066 getImageAspectFlags(dsAttachmentInfo.getFormat()), // aspect;
3069 0, // baseArraySlice
3073 imageBarriersAfterRendering.push_back(barrierAfterRendering);
3076 if (!imageBarriersBeforeRendering.empty())
3077 vk.cmdPipelineBarrier(commandBuffer,
3078 getAllPipelineStageFlags(),
3079 getAllPipelineStageFlags(),
3080 (VkDependencyFlags)0,
3081 0, (const VkMemoryBarrier*)DE_NULL,
3082 0, (const VkBufferMemoryBarrier*)DE_NULL,
3083 (deUint32)imageBarriersBeforeRendering.size(),
3084 &imageBarriersBeforeRendering[0]);
3086 bool executeRenderCommands = (renderType != TestConfig::RENDERTYPES_NONE);
3088 if (secondaryCmdBufferCompletelyContainsDynamicRenderpass)
3090 // when secondary command buffer completely contains dynamic renderpass
3091 // then we need to execute it even when render type is none
3092 executeRenderCommands = true;
3096 VkRenderingFlagsKHR renderingFlags = 0u;
3097 if (subpassRenderers[0]->isSecondary())
3098 renderingFlags = VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR;
3100 beginDynamicRendering(vk, commandBuffer, renderPassInfo, attachmentResources, renderArea, renderPassClearValues, renderingFlags);
3103 if (executeRenderCommands)
3105 if (subpassRenderers[0]->isSecondary())
3107 const VkCommandBuffer cmd = subpassRenderers[0]->getCommandBuffer();
3108 vk.cmdExecuteCommands(commandBuffer, 1, &cmd);
3111 subpassRenderers[0]->pushRenderCommands(vk, commandBuffer);
3114 if (!secondaryCmdBufferCompletelyContainsDynamicRenderpass)
3115 endDynamicRendering(vk, commandBuffer);
3117 if (!imageBarriersAfterRendering.empty())
3118 vk.cmdPipelineBarrier(commandBuffer,
3119 getAllPipelineStageFlags(),
3120 getAllPipelineStageFlags(),
3121 (VkDependencyFlags)0,
3122 0, (const VkMemoryBarrier*)DE_NULL,
3123 0, (const VkBufferMemoryBarrier*)DE_NULL,
3124 (deUint32)imageBarriersAfterRendering.size(),
3125 &imageBarriersAfterRendering[0]);
3127 #endif // CTS_USES_VULKANSC
3129 void pushRenderPassCommands (const DeviceInterface& vk,
3130 VkCommandBuffer commandBuffer,
3131 VkRenderPass renderPass,
3132 const RenderPass& renderPassInfo,
3133 const vector<de::SharedPtr<AttachmentResources> >& attachmentResources,
3134 VkFramebuffer framebuffer,
3135 const vector<de::SharedPtr<SubpassRenderer> >& subpassRenderers,
3136 const VkRect2D& renderArea,
3137 const vector<Maybe<VkClearValue> >& renderPassClearValues,
3138 deUint32 queueIndex,
3139 TestConfig::RenderTypes render,
3140 RenderingType renderingType,
3141 bool secondaryCmdBufferCompletelyContainsDynamicRenderpass)
3143 // unreference arguments not used by Vulkan SC, no need to put them under ifdef
3144 DE_UNREF(renderPassInfo);
3145 DE_UNREF(attachmentResources);
3146 DE_UNREF(queueIndex);
3147 DE_UNREF(secondaryCmdBufferCompletelyContainsDynamicRenderpass);
3149 switch (renderingType)
3151 case RENDERING_TYPE_RENDERPASS_LEGACY:
3152 return pushRenderPassCommands<RenderpassSubpass1>(vk, commandBuffer, renderPass, framebuffer, subpassRenderers, renderArea, renderPassClearValues, render);
3153 case RENDERING_TYPE_RENDERPASS2:
3154 return pushRenderPassCommands<RenderpassSubpass2>(vk, commandBuffer, renderPass, framebuffer, subpassRenderers, renderArea, renderPassClearValues, render);
3156 #ifndef CTS_USES_VULKANSC
3157 case RENDERING_TYPE_DYNAMIC_RENDERING:
3158 return pushDynamicRenderingCommands(vk, commandBuffer, renderPassInfo, attachmentResources, subpassRenderers, renderArea, renderPassClearValues, queueIndex, render, secondaryCmdBufferCompletelyContainsDynamicRenderpass);
3159 #endif // CTS_USES_VULKANSC
3162 TCU_THROW(InternalError, "Impossible");
3166 void pushReadImagesToBuffers (const DeviceInterface& vk,
3167 VkCommandBuffer commandBuffer,
3168 deUint32 queueIndex,
3170 const vector<de::SharedPtr<AttachmentResources> >& attachmentResources,
3171 const vector<Attachment>& attachmentInfo,
3172 const vector<bool>& isLazy,
3174 const UVec2& targetSize)
3177 vector<VkImageMemoryBarrier> imageBarriers;
3179 for (size_t attachmentNdx = 0; attachmentNdx < attachmentInfo.size(); attachmentNdx++)
3181 if (isLazy[attachmentNdx])
3184 const VkImageLayout oldLayout = attachmentInfo[attachmentNdx].getFinalLayout();
3185 const VkImageMemoryBarrier barrier =
3187 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
3190 getAllMemoryWriteFlags() | getMemoryFlagsForLayout(oldLayout), // srcAccessMask
3191 getAllMemoryReadFlags(), // dstAccessMask
3193 oldLayout, // oldLayout
3194 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // newLayout
3196 queueIndex, // srcQueueFamilyIndex
3197 queueIndex, // destQueueFamilyIndex
3199 attachmentResources[attachmentNdx]->getImage(), // image
3200 { // subresourceRange
3201 getImageAspectFlags(attachmentInfo[attachmentNdx].getFormat()), // aspect;
3204 0, // baseArraySlice
3209 imageBarriers.push_back(barrier);
3212 if (!imageBarriers.empty())
3213 vk.cmdPipelineBarrier(commandBuffer,
3214 getAllPipelineStageFlags(),
3215 getAllPipelineStageFlags(),
3216 (VkDependencyFlags)0,
3217 0, (const VkMemoryBarrier*)DE_NULL,
3218 0, (const VkBufferMemoryBarrier*)DE_NULL,
3219 (deUint32)imageBarriers.size(), &imageBarriers[0]);
3222 for (size_t attachmentNdx = 0; attachmentNdx < attachmentInfo.size(); attachmentNdx++)
3224 if (isLazy[attachmentNdx])
3227 const tcu::TextureFormat::ChannelOrder order = mapVkFormat(attachmentInfo[attachmentNdx].getFormat()).order;
3228 const VkBufferImageCopy rect =
3231 0, // bufferRowLength
3232 0, // bufferImageHeight
3233 { // imageSubresource
3234 (vk::VkImageAspectFlags)getPrimaryImageAspect(mapVkFormat(attachmentInfo[attachmentNdx].getFormat()).order), // aspect
3239 { 0, 0, 0 }, // imageOffset
3240 { targetSize.x(), targetSize.y(), 1u } // imageExtent
3243 vk.cmdCopyImageToBuffer(commandBuffer, attachmentResources[attachmentNdx]->getImage(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, attachmentResources[attachmentNdx]->getBuffer(), 1, &rect);
3245 if (tcu::TextureFormat::DS == order)
3247 const VkBufferImageCopy stencilRect =
3250 0, // bufferRowLength
3251 0, // bufferImageHeight
3252 { // imageSubresource
3253 VK_IMAGE_ASPECT_STENCIL_BIT, // aspect
3258 { 0, 0, 0 }, // imageOffset
3259 { targetSize.x(), targetSize.y(), 1u } // imageExtent
3262 vk.cmdCopyImageToBuffer(commandBuffer, attachmentResources[attachmentNdx]->getImage(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, attachmentResources[attachmentNdx]->getSecondaryBuffer(), 1, &stencilRect);
3267 vector<VkBufferMemoryBarrier> bufferBarriers;
3269 for (size_t attachmentNdx = 0; attachmentNdx < attachmentInfo.size(); attachmentNdx++)
3271 if (isLazy[attachmentNdx])
3274 const tcu::TextureFormat::ChannelOrder order = mapVkFormat(attachmentInfo[attachmentNdx].getFormat()).order;
3275 const VkBufferMemoryBarrier bufferBarrier =
3277 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
3280 getAllMemoryWriteFlags(),
3281 getAllMemoryReadFlags(),
3286 attachmentResources[attachmentNdx]->getBuffer(),
3288 attachmentResources[attachmentNdx]->getBufferSize()
3291 bufferBarriers.push_back(bufferBarrier);
3293 if (tcu::TextureFormat::DS == order)
3295 const VkBufferMemoryBarrier secondaryBufferBarrier =
3297 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
3300 getAllMemoryWriteFlags(),
3301 getAllMemoryReadFlags(),
3306 attachmentResources[attachmentNdx]->getSecondaryBuffer(),
3308 attachmentResources[attachmentNdx]->getSecondaryBufferSize()
3311 bufferBarriers.push_back(secondaryBufferBarrier);
3315 if (!bufferBarriers.empty())
3316 vk.cmdPipelineBarrier(commandBuffer,
3317 getAllPipelineStageFlags(),
3318 getAllPipelineStageFlags(),
3319 (VkDependencyFlags)0,
3320 0, (const VkMemoryBarrier*)DE_NULL,
3321 (deUint32)bufferBarriers.size(), &bufferBarriers[0],
3322 0, (const VkImageMemoryBarrier*)DE_NULL);
3329 PixelValue (const Maybe<bool>& x = tcu::Nothing,
3330 const Maybe<bool>& y = tcu::Nothing,
3331 const Maybe<bool>& z = tcu::Nothing,
3332 const Maybe<bool>& w = tcu::Nothing);
3334 void setUndefined (size_t ndx);
3335 void setValue (size_t ndx, bool value);
3336 Maybe<bool> getValue (size_t ndx) const;
3342 PixelValue::PixelValue (const Maybe<bool>& x,
3343 const Maybe<bool>& y,
3344 const Maybe<bool>& z,
3345 const Maybe<bool>& w)
3348 const Maybe<bool> values[] =
3353 for (size_t ndx = 0; ndx < DE_LENGTH_OF_ARRAY(values); ndx++)
3356 setValue(ndx, *values[ndx]);
3361 DE_ASSERT(m_status <= 0xFFu);
3364 void PixelValue::setUndefined (size_t ndx)
3367 DE_ASSERT(m_status <= 0xFFu);
3369 m_status &= (deUint16)~(0x1u << (deUint16)(ndx * 2));
3370 DE_ASSERT(m_status <= 0xFFu);
3373 void PixelValue::setValue (size_t ndx, bool value)
3376 DE_ASSERT(m_status <= 0xFFu);
3378 m_status = (deUint16)(m_status | (deUint16)(0x1u << (ndx * 2)));
3381 m_status = (deUint16)(m_status | (deUint16)(0x1u << (ndx * 2 + 1)));
3383 m_status &= (deUint16)~(0x1u << (deUint16)(ndx * 2 + 1));
3385 DE_ASSERT(m_status <= 0xFFu);
3388 Maybe<bool> PixelValue::getValue (size_t ndx) const
3391 DE_ASSERT(m_status <= 0xFFu);
3393 if ((m_status & (0x1u << (deUint16)(ndx * 2))) != 0)
3395 return just((m_status & (0x1u << (deUint32)(ndx * 2 + 1))) != 0);
3398 return tcu::Nothing;
3401 void clearReferenceValues (vector<PixelValue>& values,
3402 const UVec2& targetSize,
3403 const UVec2& offset,
3406 const PixelValue& value)
3408 DE_ASSERT(targetSize.x() * targetSize.y() == (deUint32)values.size());
3409 DE_ASSERT(offset.x() + size.x() <= targetSize.x());
3410 DE_ASSERT(offset.y() + size.y() <= targetSize.y());
3412 for (deUint32 y = offset.y(); y < offset.y() + size.y(); y++)
3413 for (deUint32 x = offset.x(); x < offset.x() + size.x(); x++)
3415 for (int compNdx = 0; compNdx < 4; compNdx++)
3419 if (value.getValue(compNdx))
3420 values[x + y * targetSize.x()].setValue(compNdx, *value.getValue(compNdx));
3422 values[x + y * targetSize.x()].setUndefined(compNdx);
3428 void markUndefined (vector<PixelValue>& values,
3430 const UVec2& targetSize,
3431 const UVec2& offset,
3434 DE_ASSERT(targetSize.x() * targetSize.y() == (deUint32)values.size());
3436 for (deUint32 y = offset.y(); y < offset.y() + size.y(); y++)
3437 for (deUint32 x = offset.x(); x < offset.x() + size.x(); x++)
3439 for (int compNdx = 0; compNdx < 4; compNdx++)
3442 values[x + y * targetSize.x()].setUndefined(compNdx);
3447 PixelValue clearValueToPixelValue (const VkClearValue& value,
3448 const tcu::TextureFormat& format,
3449 const DepthValuesArray& depthValues)
3451 const bool isDepthAttachment = hasDepthComponent(format.order);
3452 const bool isStencilAttachment = hasStencilComponent(format.order);
3453 const bool isDepthOrStencilAttachment = isDepthAttachment || isStencilAttachment;
3454 PixelValue pixelValue;
3456 if (isDepthOrStencilAttachment)
3458 if (isDepthAttachment)
3460 if (value.depthStencil.depth == float(depthValues[1]) / 255.0f)
3461 pixelValue.setValue(0, true);
3462 else if (value.depthStencil.depth == float(depthValues[0]) / 255.0f)
3463 pixelValue.setValue(0, false);
3465 DE_FATAL("Unknown depth value");
3468 if (isStencilAttachment)
3470 if (value.depthStencil.stencil == 0xFFu)
3471 pixelValue.setValue(1, true);
3472 else if (value.depthStencil.stencil == 0x0u)
3473 pixelValue.setValue(1, false);
3475 DE_FATAL("Unknown stencil value");
3480 const tcu::TextureChannelClass channelClass = tcu::getTextureChannelClass(format.type);
3481 const tcu::BVec4 channelMask = tcu::getTextureFormatChannelMask(format);
3483 switch (channelClass)
3485 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
3486 for (int i = 0; i < 4; i++)
3490 if (value.color.int32[i] == 1)
3491 pixelValue.setValue(i, true);
3492 else if (value.color.int32[i] == 0)
3493 pixelValue.setValue(i, false);
3495 DE_FATAL("Unknown clear color value");
3500 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
3501 for (int i = 0; i < 4; i++)
3505 if (value.color.uint32[i] == 1u)
3506 pixelValue.setValue(i, true);
3507 else if (value.color.uint32[i] == 0u)
3508 pixelValue.setValue(i, false);
3510 DE_FATAL("Unknown clear color value");
3515 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
3516 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
3517 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
3518 for (int i = 0; i < 4; i++)
3522 if (value.color.float32[i] == 1.0f)
3523 pixelValue.setValue(i, true);
3524 else if (value.color.float32[i] == 0.0f)
3525 pixelValue.setValue(i, false);
3527 DE_FATAL("Unknown clear color value");
3533 DE_FATAL("Unknown channel class");
3540 void renderReferenceValues (vector<vector<PixelValue> >& referenceAttachments,
3541 const RenderPass& renderPassInfo,
3542 const UVec2& targetSize,
3543 const vector<Maybe<VkClearValue> >& imageClearValues,
3544 const vector<Maybe<VkClearValue> >& renderPassClearValues,
3545 const vector<SubpassRenderInfo>& subpassRenderInfo,
3546 const UVec2& renderPos,
3547 const UVec2& renderSize,
3548 const deUint32 drawStartNdx,
3549 const DepthValuesArray& depthValues)
3551 const vector<Subpass>& subpasses = renderPassInfo.getSubpasses();
3552 vector<bool> attachmentUsed (renderPassInfo.getAttachments().size(), false);
3554 referenceAttachments.resize(renderPassInfo.getAttachments().size());
3556 for (size_t attachmentNdx = 0; attachmentNdx < renderPassInfo.getAttachments().size(); attachmentNdx++)
3558 const Attachment attachment = renderPassInfo.getAttachments()[attachmentNdx];
3559 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3560 vector<PixelValue>& reference = referenceAttachments[attachmentNdx];
3562 reference.resize(targetSize.x() * targetSize.y());
3564 if (imageClearValues[attachmentNdx])
3565 clearReferenceValues(reference, targetSize, UVec2(0, 0), targetSize, BVec4(true), clearValueToPixelValue(*imageClearValues[attachmentNdx], format, depthValues));
3568 for (size_t subpassNdx = 0; subpassNdx < subpasses.size(); subpassNdx++)
3570 const Subpass& subpass = subpasses[subpassNdx];
3571 const SubpassRenderInfo& renderInfo = subpassRenderInfo[subpassNdx];
3572 const vector<AttachmentReference>& colorAttachments = subpass.getColorAttachments();
3574 // Apply load op if attachment was used for the first time
3575 for (size_t attachmentNdx = 0; attachmentNdx < colorAttachments.size(); attachmentNdx++)
3577 const deUint32 attachmentIndex = getAttachmentNdx(colorAttachments, attachmentNdx);
3579 if (!attachmentUsed[attachmentIndex] && colorAttachments[attachmentNdx].getAttachment() != VK_ATTACHMENT_UNUSED)
3581 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3582 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3583 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3585 DE_ASSERT(!tcu::hasDepthComponent(format.order));
3586 DE_ASSERT(!tcu::hasStencilComponent(format.order));
3588 if (attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_CLEAR)
3589 clearReferenceValues(reference, targetSize, renderPos, renderSize, BVec4(true), clearValueToPixelValue(*renderPassClearValues[attachmentIndex], format, depthValues));
3590 else if (attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE)
3591 markUndefined(reference, BVec4(true), targetSize, renderPos, renderSize);
3593 attachmentUsed[attachmentIndex] = true;
3597 // Apply load op to depth/stencil attachment if it was used for the first time
3598 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED)
3600 const deUint32 attachmentIndex = subpass.getDepthStencilAttachment().getAttachment();
3602 // Apply load op if attachment was used for the first time
3603 if (!attachmentUsed[attachmentIndex])
3605 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3606 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3607 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3609 if (tcu::hasDepthComponent(format.order))
3611 if (attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_CLEAR)
3612 clearReferenceValues(reference, targetSize, renderPos, renderSize, BVec4(true, false, false, false), clearValueToPixelValue(*renderPassClearValues[attachmentIndex], format, depthValues));
3613 else if (attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE)
3614 markUndefined(reference, BVec4(true, false, false, false), targetSize, renderPos, renderSize);
3617 if (tcu::hasStencilComponent(format.order))
3619 if (attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_CLEAR)
3620 clearReferenceValues(reference, targetSize, renderPos, renderSize, BVec4(false, true, false, false), clearValueToPixelValue(*renderPassClearValues[attachmentIndex], format, depthValues));
3621 else if (attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE)
3622 markUndefined(reference, BVec4(false, true, false, false), targetSize, renderPos, renderSize);
3625 attachmentUsed[attachmentIndex] = true;
3629 for (size_t colorClearNdx = 0; colorClearNdx < renderInfo.getColorClears().size(); colorClearNdx++)
3631 const ColorClear& colorClear = renderInfo.getColorClears()[colorClearNdx];
3632 const UVec2 offset = colorClear.getOffset();
3633 const UVec2 size = colorClear.getSize();
3634 const deUint32 attachmentIndex = subpass.getColorAttachments()[colorClearNdx].getAttachment();
3635 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3636 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3637 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3640 value.color = colorClear.getColor();
3642 clearReferenceValues(reference, targetSize, offset, size, BVec4(true), clearValueToPixelValue(value, format, depthValues));
3645 if (renderInfo.getDepthStencilClear())
3647 const DepthStencilClear& dsClear = *renderInfo.getDepthStencilClear();
3648 const UVec2 offset = dsClear.getOffset();
3649 const UVec2 size = dsClear.getSize();
3650 const deUint32 attachmentIndex = subpass.getDepthStencilAttachment().getAttachment();
3651 const VkImageLayout layout = subpass.getDepthStencilAttachment().getImageLayout();
3652 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3653 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3654 const bool hasStencil = tcu::hasStencilComponent(format.order)
3655 && layout != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL;
3656 const bool hasDepth = tcu::hasDepthComponent(format.order)
3657 && layout != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL;
3658 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3661 value.depthStencil.depth = dsClear.getDepth();
3662 value.depthStencil.stencil = dsClear.getStencil();
3664 clearReferenceValues(reference, targetSize, offset, size, BVec4(hasDepth, hasStencil, false, false), clearValueToPixelValue(value, format, depthValues));
3667 if (renderInfo.getRenderQuad())
3669 const RenderQuad& renderQuad = *renderInfo.getRenderQuad();
3670 const Vec2 posA = renderQuad.getCornerA();
3671 const Vec2 posB = renderQuad.getCornerB();
3672 const Vec2 origin = Vec2((float)renderInfo.getViewportOffset().x(), (float)renderInfo.getViewportOffset().y()) + Vec2((float)renderInfo.getViewportSize().x(), (float)renderInfo.getViewportSize().y()) / Vec2(2.0f);
3673 const Vec2 p = Vec2((float)renderInfo.getViewportSize().x(), (float)renderInfo.getViewportSize().y()) / Vec2(2.0f);
3674 const IVec2 posAI (deRoundFloatToInt32(origin.x() + (p.x() * posA.x())),
3675 deRoundFloatToInt32(origin.y() + (p.y() * posA.y())));
3676 const IVec2 posBI (deRoundFloatToInt32(origin.x() + (p.x() * posB.x())),
3677 deRoundFloatToInt32(origin.y() + (p.y() * posB.y())));
3679 DE_ASSERT(posAI.x() < posBI.x());
3680 DE_ASSERT(posAI.y() < posBI.y());
3682 if (subpass.getInputAttachments().empty())
3684 for (size_t attachmentRefNdx = drawStartNdx; attachmentRefNdx < subpass.getColorAttachments().size(); attachmentRefNdx++)
3686 const deUint32 attachmentIndex = subpass.getColorAttachments()[attachmentRefNdx].getAttachment();
3688 if (attachmentIndex == VK_ATTACHMENT_UNUSED)
3691 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3692 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3693 const tcu::BVec4 channelMask = tcu::getTextureFormatChannelMask(format);
3694 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3696 for (int y = posAI.y(); y < (int)posBI.y(); y++)
3697 for (int x = posAI.x(); x < (int)posBI.x(); x++)
3699 for (int compNdx = 0; compNdx < 4; compNdx++)
3701 const size_t index = subpassNdx + attachmentIndex + compNdx;
3702 const BoolOp op = boolOpFromIndex(index);
3703 const bool boolX = x % 2 == (int)(index % 2);
3704 const bool boolY = y % 2 == (int)((index / 2) % 2);
3706 if (channelMask[compNdx])
3707 reference[x + y * targetSize.x()].setValue(compNdx, performBoolOp(op, boolX, boolY));
3712 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED)
3714 const deUint32 attachmentIndex = subpass.getDepthStencilAttachment().getAttachment();
3715 const VkImageLayout layout = subpass.getDepthStencilAttachment().getImageLayout();
3716 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3717 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3718 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3720 for (int y = posAI.y(); y < (int)posBI.y(); y++)
3721 for (int x = posAI.x(); x < (int)posBI.x(); x++)
3723 if (tcu::hasDepthComponent(format.order)
3724 && layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
3725 && layout != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
3727 const size_t index = subpassNdx + 1;
3728 const BoolOp op = boolOpFromIndex(index);
3729 const bool boolX = x % 2 == (int)(index % 2);
3730 const bool boolY = y % 2 == (int)((index / 2) % 2);
3732 reference[x + y * targetSize.x()].setValue(0, performBoolOp(op, boolX, boolY));
3735 if (tcu::hasStencilComponent(format.order)
3736 && layout != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
3737 && layout != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL)
3739 const size_t index = subpassNdx;
3740 reference[x + y * targetSize.x()].setValue(1, (index % 2) == 0);
3747 size_t outputComponentCount = 0;
3748 vector<Maybe<bool> > inputs;
3750 DE_ASSERT(posAI.x() < posBI.x());
3751 DE_ASSERT(posAI.y() < posBI.y());
3753 for (size_t attachmentRefNdx = 0; attachmentRefNdx < subpass.getColorAttachments().size(); attachmentRefNdx++)
3755 const deUint32 attachmentIndex = subpass.getColorAttachments()[attachmentRefNdx].getAttachment();
3756 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3757 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3758 const int componentCount = tcu::getNumUsedChannels(format.order);
3760 outputComponentCount += (size_t)componentCount;
3763 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED
3764 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
3765 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
3767 const Attachment& attachment (renderPassInfo.getAttachments()[subpass.getDepthStencilAttachment().getAttachment()]);
3768 const tcu::TextureFormat format (mapVkFormat(attachment.getFormat()));
3770 if (tcu::hasDepthComponent(format.order))
3771 outputComponentCount++;
3774 if (outputComponentCount > 0)
3776 for (int y = posAI.y(); y < (int)posBI.y(); y++)
3777 for (int x = posAI.x(); x < (int)posBI.x(); x++)
3779 for (size_t inputAttachmentNdx = 0; inputAttachmentNdx < subpass.getInputAttachments().size(); inputAttachmentNdx++)
3781 const deUint32 attachmentIndex = subpass.getInputAttachments()[inputAttachmentNdx].getAttachment();
3782 const VkImageLayout layout = subpass.getInputAttachments()[inputAttachmentNdx].getImageLayout();
3783 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3784 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3785 const int componentCount = tcu::getNumUsedChannels(format.order);
3787 for (int compNdx = 0; compNdx < componentCount; compNdx++)
3789 if ((compNdx != 0 || layout != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL)
3790 && (compNdx != 1 || layout != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL))
3792 inputs.push_back(referenceAttachments[attachmentIndex][x + y * targetSize.x()].getValue(compNdx));
3797 const size_t inputsPerOutput = inputs.size() >= outputComponentCount
3798 ? ((inputs.size() / outputComponentCount)
3799 + ((inputs.size() % outputComponentCount) != 0 ? 1 : 0))
3802 size_t outputValueNdx = 0;
3804 for (size_t attachmentRefNdx = 0; attachmentRefNdx < subpass.getColorAttachments().size(); attachmentRefNdx++)
3806 const deUint32 attachmentIndex = subpass.getColorAttachments()[attachmentRefNdx].getAttachment();
3807 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3808 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3809 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3810 const int componentCount = tcu::getNumUsedChannels(format.order);
3812 for (int compNdx = 0; compNdx < componentCount; compNdx++)
3814 const size_t index = subpassNdx + attachmentIndex + outputValueNdx;
3815 const BoolOp op = boolOpFromIndex(index);
3816 const bool boolX = x % 2 == (int)(index % 2);
3817 const bool boolY = y % 2 == (int)((index / 2) % 2);
3818 Maybe<bool> output = tcu::just(performBoolOp(op, boolX, boolY));
3820 for (size_t i = 0; i < inputsPerOutput; i++)
3824 else if (!inputs[((outputValueNdx + compNdx) * inputsPerOutput + i) % inputs.size()])
3825 output = tcu::Nothing;
3827 output = (*output) == (*inputs[((outputValueNdx + compNdx) * inputsPerOutput + i) % inputs.size()]);
3831 reference[x + y * targetSize.x()].setValue(compNdx, *output);
3833 reference[x + y * targetSize.x()].setUndefined(compNdx);
3836 outputValueNdx += componentCount;
3839 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED
3840 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
3841 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
3843 const deUint32 attachmentIndex = subpass.getDepthStencilAttachment().getAttachment();
3844 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3845 const size_t index = subpassNdx + attachmentIndex;
3846 const BoolOp op = boolOpFromIndex(index);
3847 const bool boolX = x % 2 == (int)(index % 2);
3848 const bool boolY = y % 2 == (int)((index / 2) % 2);
3849 Maybe<bool> output = tcu::just(performBoolOp(op, boolX, boolY));
3851 for (size_t i = 0; i < inputsPerOutput; i++)
3855 else if (inputs[(outputValueNdx * inputsPerOutput + i) % inputs.size()])
3856 output = (*output) == (*inputs[(outputValueNdx * inputsPerOutput + i) % inputs.size()]);
3858 output = tcu::Nothing;
3862 reference[x + y * targetSize.x()].setValue(0, *output);
3864 reference[x + y * targetSize.x()].setUndefined(0);
3871 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED
3872 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
3873 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL)
3875 const deUint32 attachmentIndex = subpass.getDepthStencilAttachment().getAttachment();
3876 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3877 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3878 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3880 if (tcu::hasStencilComponent(format.order))
3882 for (int y = posAI.y(); y < (int)posBI.y(); y++)
3883 for (int x = posAI.x(); x < (int)posBI.x(); x++)
3885 const size_t index = subpassNdx;
3886 reference[x + y * targetSize.x()].setValue(1, (index % 2) == 0);
3894 // Mark all attachments that were used but not stored as undefined
3895 for (size_t attachmentIndex = 0; attachmentIndex < renderPassInfo.getAttachments().size(); attachmentIndex++)
3897 const Attachment attachment = renderPassInfo.getAttachments()[attachmentIndex];
3898 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3899 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3900 const bool isStencilAttachment = hasStencilComponent(format.order);
3901 const bool isDepthOrStencilAttachment = hasDepthComponent(format.order) || isStencilAttachment;
3903 if (attachmentUsed[attachmentIndex] && renderPassInfo.getAttachments()[attachmentIndex].getStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE)
3905 if (isDepthOrStencilAttachment)
3906 markUndefined(reference, BVec4(true, false, false, false), targetSize, renderPos, renderSize);
3908 markUndefined(reference, BVec4(true), targetSize, renderPos, renderSize);
3911 if (attachmentUsed[attachmentIndex] && isStencilAttachment && renderPassInfo.getAttachments()[attachmentIndex].getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE)
3912 markUndefined(reference, BVec4(false, true, false, false), targetSize, renderPos, renderSize);
3916 void renderReferenceImagesFromValues (vector<tcu::TextureLevel>& referenceImages,
3917 const vector<vector<PixelValue> >& referenceValues,
3918 const UVec2& targetSize,
3919 const RenderPass& renderPassInfo,
3920 const DepthValuesArray& depthValues)
3922 referenceImages.resize(referenceValues.size());
3924 for (size_t attachmentNdx = 0; attachmentNdx < renderPassInfo.getAttachments().size(); attachmentNdx++)
3926 const Attachment attachment = renderPassInfo.getAttachments()[attachmentNdx];
3927 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3928 const vector<PixelValue>& reference = referenceValues[attachmentNdx];
3929 const bool hasDepth = tcu::hasDepthComponent(format.order);
3930 const bool hasStencil = tcu::hasStencilComponent(format.order);
3931 const bool hasDepthOrStencil = hasDepth || hasStencil;
3932 tcu::TextureLevel& referenceImage = referenceImages[attachmentNdx];
3934 referenceImage.setStorage(format, targetSize.x(), targetSize.y());
3936 if (hasDepthOrStencil)
3940 const PixelBufferAccess depthAccess (tcu::getEffectiveDepthStencilAccess(referenceImage.getAccess(), tcu::Sampler::MODE_DEPTH));
3942 for (deUint32 y = 0; y < targetSize.y(); y++)
3943 for (deUint32 x = 0; x < targetSize.x(); x++)
3945 if (reference[x + y * targetSize.x()].getValue(0))
3947 if (*reference[x + y * targetSize.x()].getValue(0))
3948 depthAccess.setPixDepth(float(depthValues[1]) / 255.0f, x, y);
3950 depthAccess.setPixDepth(float(depthValues[0]) / 255.0f, x, y);
3952 else // Fill with 3x3 grid
3953 depthAccess.setPixDepth(((x / 3) % 2) == ((y / 3) % 2) ? 0.33f : 0.66f, x, y);
3959 const PixelBufferAccess stencilAccess (tcu::getEffectiveDepthStencilAccess(referenceImage.getAccess(), tcu::Sampler::MODE_STENCIL));
3961 for (deUint32 y = 0; y < targetSize.y(); y++)
3962 for (deUint32 x = 0; x < targetSize.x(); x++)
3964 if (reference[x + y * targetSize.x()].getValue(1))
3966 if (*reference[x + y * targetSize.x()].getValue(1))
3967 stencilAccess.setPixStencil(0xFFu, x, y);
3969 stencilAccess.setPixStencil(0x0u, x, y);
3971 else // Fill with 3x3 grid
3972 stencilAccess.setPixStencil(((x / 3) % 2) == ((y / 3) % 2) ? 85 : 170, x, y);
3978 for (deUint32 y = 0; y < targetSize.y(); y++)
3979 for (deUint32 x = 0; x < targetSize.x(); x++)
3983 for (int compNdx = 0; compNdx < 4; compNdx++)
3985 if (reference[x + y * targetSize.x()].getValue(compNdx))
3987 if (*reference[x + y * targetSize.x()].getValue(compNdx))
3988 color[compNdx] = 1.0f;
3990 color[compNdx] = 0.0f;
3992 else // Fill with 3x3 grid
3993 color[compNdx] = ((compNdx + (x / 3)) % 2) == ((y / 3) % 2) ? 0.33f : 0.66f;
3996 referenceImage.getAccess().setPixel(color, x, y);
4002 bool verifyColorAttachment (const vector<PixelValue>& reference,
4003 const ConstPixelBufferAccess& result,
4004 const PixelBufferAccess& errorImage,
4005 const deBool useFormatCompCount)
4007 const Vec4 red (1.0f, 0.0f, 0.0f, 1.0f);
4008 const Vec4 green (0.0f, 1.0f, 0.0f, 1.0f);
4011 DE_ASSERT(result.getWidth() * result.getHeight() == (int)reference.size());
4012 DE_ASSERT(result.getWidth() == errorImage.getWidth());
4013 DE_ASSERT(result.getHeight() == errorImage.getHeight());
4015 for (int y = 0; y < result.getHeight(); y++)
4016 for (int x = 0; x < result.getWidth(); x++)
4018 const Vec4 resultColor = result.getPixel(x, y);
4019 const PixelValue& referenceValue = reference[x + y * result.getWidth()];
4020 bool pixelOk = true;
4021 const deUint32 componentCount = useFormatCompCount ? (deUint32)tcu::getNumUsedChannels(result.getFormat().order) : 4;
4023 for (deUint32 compNdx = 0; compNdx < componentCount; compNdx++)
4025 const Maybe<bool> maybeValue = referenceValue.getValue(compNdx);
4029 const bool value = *maybeValue;
4031 if ((value && (resultColor[compNdx] != 1.0f))
4032 || (!value && resultColor[compNdx] != 0.0f))
4039 errorImage.setPixel(red, x, y);
4043 errorImage.setPixel(green, x, y);
4049 // Setting the alpha value to 1.0f by default helps visualization when the alpha channel is not used.
4050 const tcu::Vec4 kDefaultColorForLog {0.0f, 0.0f, 0.0f, 1.0f};
4051 const float kTrueComponent = 1.0f;
4052 const float kFalseComponent = 0.5f;
4053 const float kUnsetComponentLow = 0.0f;
4054 const float kUnsetComponentHigh = 0.25f;
4056 std::unique_ptr<tcu::TextureLevel> renderColorImageForLog (const ConstPixelBufferAccess& image, int numChannels)
4058 // Same channel order, but using UNORM_INT8 for the color format.
4059 const auto order = image.getFormat().order;
4060 const tcu::TextureFormat loggableFormat {order, tcu::TextureFormat::UNORM_INT8};
4061 const int width = image.getWidth();
4062 const int height = image.getHeight();
4063 std::unique_ptr<tcu::TextureLevel> result {new tcu::TextureLevel{loggableFormat, width, height}};
4064 auto access = result->getAccess();
4065 tcu::Vec4 outColor = kDefaultColorForLog;
4067 for (int x = 0; x < width; ++x)
4068 for (int y = 0; y < height; ++y)
4070 const auto value = image.getPixel(x, y);
4071 for (int c = 0; c < numChannels; ++c)
4073 if (value[c] == 0.0f)
4074 outColor[c] = kFalseComponent;
4075 else if (value[c] == 1.0f)
4076 outColor[c] = kTrueComponent;
4080 access.setPixel(outColor, x, y);
4086 std::unique_ptr<tcu::TextureLevel> renderColorImageForLog (const vector<PixelValue>& reference, const UVec2& targetSize, int numChannels)
4088 const tcu::TextureFormat loggableFormat {tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8};
4089 const int width = static_cast<int>(targetSize.x());
4090 const int height = static_cast<int>(targetSize.y());
4091 std::unique_ptr<tcu::TextureLevel> result {new tcu::TextureLevel{loggableFormat, width, height}};
4092 auto access = result->getAccess();
4093 tcu::Vec4 outColor = kDefaultColorForLog;
4095 for (int x = 0; x < width; ++x)
4096 for (int y = 0; y < height; ++y)
4098 const int index = x + y * width;
4099 for (int c = 0; c < numChannels; ++c)
4101 const auto maybeValue = reference[index].getValue(c);
4103 outColor[c] = ((*maybeValue) ? kTrueComponent : kFalseComponent);
4105 outColor[c] = ((((x / 3) % 2) == ((y / 3) % 2)) ? kUnsetComponentLow : kUnsetComponentHigh);
4107 access.setPixel(outColor, x, y);
4113 bool verifyDepthAttachment (const vector<PixelValue>& reference,
4114 const ConstPixelBufferAccess& result,
4115 const PixelBufferAccess& errorImage,
4116 const DepthValuesArray& depthValues,
4119 const Vec4 red (1.0f, 0.0f, 0.0f, 1.0f);
4120 const Vec4 green (0.0f, 1.0f, 0.0f, 1.0f);
4123 DE_ASSERT(result.getWidth() * result.getHeight() == (int)reference.size());
4124 DE_ASSERT(result.getWidth() == errorImage.getWidth());
4125 DE_ASSERT(result.getHeight() == errorImage.getHeight());
4127 for (int y = 0; y < result.getHeight(); y++)
4128 for (int x = 0; x < result.getWidth(); x++)
4130 bool pixelOk = true;
4132 const float resultDepth = result.getPixDepth(x, y);
4133 const PixelValue& referenceValue = reference[x + y * result.getWidth()];
4134 const Maybe<bool> maybeValue = referenceValue.getValue(0);
4138 const bool value = *maybeValue;
4140 if ((value && !depthsEqual(resultDepth, float(depthValues[1]) / 255.0f, epsilon))
4141 || (!value && !depthsEqual(resultDepth, float(depthValues[0]) / 255.0f, epsilon)))
4147 errorImage.setPixel(red, x, y);
4151 errorImage.setPixel(green, x, y);
4157 bool verifyStencilAttachment (const vector<PixelValue>& reference,
4158 const ConstPixelBufferAccess& result,
4159 const PixelBufferAccess& errorImage)
4161 const Vec4 red (1.0f, 0.0f, 0.0f, 1.0f);
4162 const Vec4 green (0.0f, 1.0f, 0.0f, 1.0f);
4165 DE_ASSERT(result.getWidth() * result.getHeight() == (int)reference.size());
4166 DE_ASSERT(result.getWidth() == errorImage.getWidth());
4167 DE_ASSERT(result.getHeight() == errorImage.getHeight());
4169 for (int y = 0; y < result.getHeight(); y++)
4170 for (int x = 0; x < result.getWidth(); x++)
4172 bool pixelOk = true;
4174 const deUint32 resultStencil = result.getPixStencil(x, y);
4175 const PixelValue& referenceValue = reference[x + y * result.getWidth()];
4176 const Maybe<bool> maybeValue = referenceValue.getValue(1);
4180 const bool value = *maybeValue;
4182 if ((value && (resultStencil != 0xFFu))
4183 || (!value && resultStencil != 0x0u))
4189 errorImage.setPixel(red, x, y);
4193 errorImage.setPixel(green, x, y);
4199 bool logAndVerifyImages (TestLog& log,
4200 const DeviceInterface& vk,
4202 const vector<de::SharedPtr<AttachmentResources> >& attachmentResources,
4203 const vector<bool>& attachmentIsLazy,
4204 const RenderPass& renderPassInfo,
4205 const vector<Maybe<VkClearValue> >& renderPassClearValues,
4206 const vector<Maybe<VkClearValue> >& imageClearValues,
4207 const vector<SubpassRenderInfo>& subpassRenderInfo,
4208 const UVec2& targetSize,
4209 const TestConfig& config)
4211 vector<vector<PixelValue> > referenceValues;
4212 vector<tcu::TextureLevel> referenceAttachments;
4215 log << TestLog::Message << "Reference images fill undefined pixels with 3x3 grid pattern." << TestLog::EndMessage;
4217 renderReferenceValues(referenceValues, renderPassInfo, targetSize, imageClearValues, renderPassClearValues, subpassRenderInfo, config.renderPos, config.renderSize, config.drawStartNdx, config.depthValues);
4218 renderReferenceImagesFromValues(referenceAttachments, referenceValues, targetSize, renderPassInfo, config.depthValues);
4220 for (size_t attachmentNdx = 0; attachmentNdx < renderPassInfo.getAttachments().size(); attachmentNdx++)
4222 if (!attachmentIsLazy[attachmentNdx])
4224 bool attachmentOK = true;
4225 const Attachment attachment = renderPassInfo.getAttachments()[attachmentNdx];
4226 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
4228 if (tcu::hasDepthComponent(format.order) && tcu::hasStencilComponent(format.order))
4230 const tcu::TextureFormat depthFormat = getDepthCopyFormat(attachment.getFormat());
4231 void* const depthPtr = attachmentResources[attachmentNdx]->getResultMemory().getHostPtr();
4233 const tcu::TextureFormat stencilFormat = getStencilCopyFormat(attachment.getFormat());
4234 void* const stencilPtr = attachmentResources[attachmentNdx]->getSecondaryResultMemory().getHostPtr();
4236 invalidateAlloc(vk, device, attachmentResources[attachmentNdx]->getResultMemory());
4237 invalidateAlloc(vk, device, attachmentResources[attachmentNdx]->getSecondaryResultMemory());
4240 bool depthOK = true;
4241 bool stencilOK = true;
4242 const ConstPixelBufferAccess depthAccess (depthFormat, targetSize.x(), targetSize.y(), 1, depthPtr);
4243 const ConstPixelBufferAccess stencilAccess (stencilFormat, targetSize.x(), targetSize.y(), 1, stencilPtr);
4244 tcu::TextureLevel depthErrorImage (tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), targetSize.x(), targetSize.y());
4245 tcu::TextureLevel stencilErrorImage (tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), targetSize.x(), targetSize.y());
4247 if (renderPassInfo.getAttachments()[attachmentNdx].getStoreOp() == VK_ATTACHMENT_STORE_OP_STORE
4248 && !verifyDepthAttachment(referenceValues[attachmentNdx], depthAccess, depthErrorImage.getAccess(), config.depthValues, requiredDepthEpsilon(attachment.getFormat())))
4253 if (renderPassInfo.getAttachments()[attachmentNdx].getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_STORE
4254 && !verifyStencilAttachment(referenceValues[attachmentNdx], stencilAccess, stencilErrorImage.getAccess()))
4259 if (!depthOK || !stencilOK)
4261 const auto attachmentNdxStr = de::toString(attachmentNdx);
4264 log << TestLog::ImageSet("OutputAttachments" + attachmentNdxStr, "Output depth and stencil attachments " + attachmentNdxStr);
4265 log << TestLog::Image("Attachment" + attachmentNdxStr + "Depth", "Attachment " + attachmentNdxStr + " Depth", depthAccess);
4266 log << TestLog::Image("Attachment" + attachmentNdxStr + "Stencil", "Attachment " + attachmentNdxStr + " Stencil", stencilAccess);
4267 log << TestLog::EndImageSet;
4269 // Reference images. These will be logged as image sets due to having depth and stencil aspects.
4270 log << TestLog::Image("AttachmentReferences" + attachmentNdxStr, "Reference images " + attachmentNdxStr, referenceAttachments[attachmentNdx].getAccess());
4273 log << TestLog::ImageSet("ErrorMasks" + attachmentNdxStr, "Error masks " + attachmentNdxStr);
4275 log << TestLog::Image("DepthAttachmentError" + attachmentNdxStr, "Depth Attachment Error " + attachmentNdxStr, depthErrorImage.getAccess());
4277 log << TestLog::Image("StencilAttachmentError" + attachmentNdxStr, "Stencil Attachment Error " + attachmentNdxStr, stencilErrorImage.getAccess());
4278 log << TestLog::EndImageSet;
4280 attachmentOK = false;
4286 void* const ptr = attachmentResources[attachmentNdx]->getResultMemory().getHostPtr();
4288 invalidateAlloc(vk, device, attachmentResources[attachmentNdx]->getResultMemory());
4290 bool depthOK = true;
4291 bool stencilOK = true;
4292 bool colorOK = true;
4293 const ConstPixelBufferAccess access (format, targetSize.x(), targetSize.y(), 1, ptr);
4294 tcu::TextureLevel errorImage (tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), targetSize.x(), targetSize.y());
4296 if (tcu::hasDepthComponent(format.order))
4298 if ((renderPassInfo.getAttachments()[attachmentNdx].getStoreOp() == VK_ATTACHMENT_STORE_OP_STORE || renderPassInfo.getAttachments()[attachmentNdx].getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_STORE)
4299 && !verifyDepthAttachment(referenceValues[attachmentNdx], access, errorImage.getAccess(), config.depthValues, requiredDepthEpsilon(attachment.getFormat())))
4304 else if (tcu::hasStencilComponent(format.order))
4306 if ((renderPassInfo.getAttachments()[attachmentNdx].getStoreOp() == VK_ATTACHMENT_STORE_OP_STORE || renderPassInfo.getAttachments()[attachmentNdx].getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_STORE)
4307 && !verifyStencilAttachment(referenceValues[attachmentNdx], access, errorImage.getAccess()))
4314 if ((renderPassInfo.getAttachments()[attachmentNdx].getStoreOp() == VK_ATTACHMENT_STORE_OP_STORE || renderPassInfo.getAttachments()[attachmentNdx].getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_STORE)
4315 && !verifyColorAttachment(referenceValues[attachmentNdx], access, errorImage.getAccess(), config.useFormatCompCount))
4321 if (!depthOK || !stencilOK || !colorOK)
4323 log << TestLog::ImageSet("TestImages", "Output attachment, reference image and error mask");
4324 if (!depthOK || !stencilOK)
4326 // Log without conversions.
4327 log << TestLog::Image("Attachment" + de::toString(attachmentNdx), "Attachment " + de::toString(attachmentNdx), access);
4328 log << TestLog::Image("AttachmentReference" + de::toString(attachmentNdx), "Attachment reference " + de::toString(attachmentNdx), referenceAttachments[attachmentNdx].getAccess());
4332 // Convert color images to better reflect test status and output in any format.
4333 const auto numChannels = tcu::getNumUsedChannels(access.getFormat().order);
4334 const auto attachmentForLog = renderColorImageForLog(access, numChannels);
4335 const auto referenceForLog = renderColorImageForLog(referenceValues[attachmentNdx], targetSize, numChannels);
4337 log << TestLog::Message << "Check the attachment formats and test data to verify which components affect the test result." << TestLog::EndMessage;
4338 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;
4339 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;
4341 log << TestLog::Image("Attachment" + de::toString(attachmentNdx), "Attachment " + de::toString(attachmentNdx), attachmentForLog->getAccess());
4342 log << TestLog::Image("AttachmentReference" + de::toString(attachmentNdx), "Attachment reference " + de::toString(attachmentNdx), referenceForLog->getAccess());
4344 log << TestLog::Image("AttachmentError" + de::toString(attachmentNdx), "Attachment Error " + de::toString(attachmentNdx), errorImage.getAccess());
4345 log << TestLog::EndImageSet;
4347 attachmentOK = false;
4359 std::string getInputAttachmentType (VkFormat vkFormat)
4361 const tcu::TextureFormat format = mapVkFormat(vkFormat);
4362 const tcu::TextureChannelClass channelClass = tcu::getTextureChannelClass(format.type);
4364 switch (channelClass)
4366 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
4367 return "isubpassInput";
4369 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
4370 return "usubpassInput";
4372 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
4373 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
4374 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
4375 return "subpassInput";
4378 DE_FATAL("Unknown channel class");
4383 std::string getAttachmentType (VkFormat vkFormat, deBool useFormatCompCount)
4385 const tcu::TextureFormat format = mapVkFormat(vkFormat);
4386 const tcu::TextureChannelClass channelClass = tcu::getTextureChannelClass(format.type);
4387 const size_t componentCount = (size_t)tcu::getNumUsedChannels(format.order);
4389 switch (channelClass)
4391 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
4392 if (useFormatCompCount)
4393 return (componentCount == 1 ? "int" : "ivec" + de::toString(componentCount));
4397 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
4398 if (useFormatCompCount)
4399 return (componentCount == 1 ? "uint" : "uvec" + de::toString(componentCount));
4403 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
4404 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
4405 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
4406 if (useFormatCompCount)
4407 return (componentCount == 1 ? "float" : "vec" + de::toString(componentCount));
4412 DE_FATAL("Unknown channel class");
4417 void createTestShaders (SourceCollections& dst, TestConfig config)
4419 if (config.renderTypes & TestConfig::RENDERTYPES_DRAW)
4421 const vector<Subpass>& subpasses = config.renderPass.getSubpasses();
4423 for (size_t subpassNdx = 0; subpassNdx < subpasses.size(); subpassNdx++)
4425 const Subpass& subpass = subpasses[subpassNdx];
4426 deUint32 inputAttachmentBinding = 0;
4427 std::ostringstream vertexShader;
4428 std::ostringstream fragmentShader;
4430 vertexShader << "#version 310 es\n"
4431 << "layout(location = 0) in highp vec2 a_position;\n"
4432 << "void main (void) {\n"
4433 << "\tgl_Position = vec4(a_position, 1.0, 1.0);\n"
4436 fragmentShader << "#version 310 es\n"
4437 << "precision highp float;\n";
4439 bool hasAnyDepthFormats = false;
4441 for (size_t attachmentNdx = config.drawStartNdx; attachmentNdx < subpass.getInputAttachments().size(); attachmentNdx++)
4443 const deUint32 attachmentIndex = subpass.getInputAttachments()[attachmentNdx].getAttachment();
4444 const VkImageLayout layout = subpass.getInputAttachments()[attachmentNdx].getImageLayout();
4445 const Attachment attachment = config.renderPass.getAttachments()[attachmentIndex];
4446 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
4447 const bool isDepthFormat = tcu::hasDepthComponent(format.order);
4448 const bool isStencilFormat = tcu::hasStencilComponent(format.order);
4450 if (isDepthFormat || isStencilFormat)
4452 if (isDepthFormat && layout != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL)
4454 hasAnyDepthFormats = true;
4455 fragmentShader << "layout(input_attachment_index = " << attachmentNdx << ", set=0, binding=" << inputAttachmentBinding << ") uniform highp subpassInput i_depth" << attachmentNdx << ";\n";
4456 inputAttachmentBinding++;
4459 if (isStencilFormat && layout != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
4461 fragmentShader << "layout(input_attachment_index = " << attachmentNdx << ", set=0, binding=" << inputAttachmentBinding << ") uniform highp usubpassInput i_stencil" << attachmentNdx << ";\n";
4462 inputAttachmentBinding++;
4467 const std::string attachmentType = getInputAttachmentType(attachment.getFormat());
4469 fragmentShader << "layout(input_attachment_index = " << attachmentNdx << ", set=0, binding=" << inputAttachmentBinding << ") uniform highp " << attachmentType << " i_color" << attachmentNdx << ";\n";
4470 inputAttachmentBinding++;
4474 for (size_t attachmentNdx = config.drawStartNdx; attachmentNdx < subpass.getColorAttachments().size(); attachmentNdx++)
4476 const std::string attachmentType = getAttachmentType(config.renderPass.getAttachments()[getAttachmentNdx(subpass.getColorAttachments(), attachmentNdx)].getFormat(), config.useFormatCompCount);
4477 fragmentShader << "layout(location = " << attachmentNdx << ") out highp " << attachmentType << " o_color" << attachmentNdx << ";\n";
4480 if (hasAnyDepthFormats)
4481 fragmentShader << "\nbool depthsEqual(float a, float b, float epsilon) {\n"
4482 << "\treturn abs(a - b) <= epsilon;\n}\n\n";
4484 fragmentShader << "void main (void) {\n";
4486 if (subpass.getInputAttachments().empty())
4488 for (size_t attachmentNdx = config.drawStartNdx; attachmentNdx < subpass.getColorAttachments().size(); attachmentNdx++)
4490 const deUint32 attachmentIndex = subpass.getColorAttachments()[attachmentNdx].getAttachment();
4492 if (attachmentIndex == VK_ATTACHMENT_UNUSED)
4495 const Attachment attachment = config.renderPass.getAttachments()[attachmentIndex];
4496 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
4497 const size_t componentCount = config.useFormatCompCount ? (size_t)tcu::getNumUsedChannels(format.order) : 4;
4498 const std::string attachmentType = getAttachmentType(attachment.getFormat(), config.useFormatCompCount);
4500 fragmentShader << "\to_color" << attachmentNdx << " = " << attachmentType << "(" << attachmentType + "(";
4502 for (size_t compNdx = 0; compNdx < componentCount; compNdx++)
4504 const size_t index = subpassNdx + attachmentIndex + compNdx;
4505 const BoolOp op = boolOpFromIndex(index);
4508 fragmentShader << ",\n\t\t";
4510 fragmentShader << "((int(gl_FragCoord.x) % 2 == " << (index % 2)
4511 << ") " << boolOpToString(op) << " ("
4512 << "int(gl_FragCoord.y) % 2 == " << ((index / 2) % 2)
4513 << ") ? 1.0 : 0.0)";
4516 fragmentShader << "));\n";
4519 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED
4520 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
4521 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
4523 const size_t index = subpassNdx + 1;
4524 const BoolOp op = boolOpFromIndex(index);
4526 fragmentShader << "\tgl_FragDepth = ((int(gl_FragCoord.x) % 2 == " << (index % 2)
4527 << ") " << boolOpToString(op) << " ("
4528 << "int(gl_FragCoord.y) % 2 == " << ((index / 2) % 2)
4529 << ") ? " << deUint32(config.depthValues[1]) << ".0f/255.0f : " << deUint32(config.depthValues[0]) << ".0f/255.0f);\n";
4534 size_t inputComponentCount = 0;
4535 size_t outputComponentCount = 0;
4537 for (size_t attachmentNdx = config.drawStartNdx; attachmentNdx < subpass.getInputAttachments().size(); attachmentNdx++)
4539 const deUint32 attachmentIndex = subpass.getInputAttachments()[attachmentNdx].getAttachment();
4540 const VkImageLayout layout = subpass.getInputAttachments()[attachmentNdx].getImageLayout();
4541 const Attachment attachment = config.renderPass.getAttachments()[attachmentIndex];
4542 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
4543 const size_t componentCount = (size_t)tcu::getNumUsedChannels(format.order);
4545 if (layout == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
4546 inputComponentCount += 1;
4547 else if (layout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL)
4548 inputComponentCount += 1;
4550 inputComponentCount += componentCount;
4553 for (size_t attachmentNdx = config.drawStartNdx; attachmentNdx < subpass.getColorAttachments().size(); attachmentNdx++)
4555 const deUint32 attachmentIndex = subpass.getColorAttachments()[attachmentNdx].getAttachment();
4556 const Attachment attachment = config.renderPass.getAttachments()[attachmentIndex];
4557 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
4558 const size_t componentCount = (size_t)tcu::getNumUsedChannels(format.order);
4560 outputComponentCount += componentCount;
4563 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED
4564 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
4565 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
4567 outputComponentCount++;
4570 if (outputComponentCount > 0)
4572 const size_t inputsPerOutput = inputComponentCount >= outputComponentCount
4573 ? ((inputComponentCount / outputComponentCount)
4574 + ((inputComponentCount % outputComponentCount) != 0 ? 1 : 0))
4577 fragmentShader << "\tbool inputs[" << inputComponentCount << "];\n";
4579 if (outputComponentCount > 0)
4580 fragmentShader << "\tbool outputs[" << outputComponentCount << "];\n";
4582 size_t inputValueNdx = 0;
4584 for (size_t attachmentNdx = config.drawStartNdx; attachmentNdx < subpass.getInputAttachments().size(); attachmentNdx++)
4586 const char* const components[] =
4590 const deUint32 attachmentIndex = subpass.getInputAttachments()[attachmentNdx].getAttachment();
4591 const VkImageLayout layout = subpass.getInputAttachments()[attachmentNdx].getImageLayout();
4592 const Attachment attachment = config.renderPass.getAttachments()[attachmentIndex];
4593 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
4594 const size_t componentCount = (size_t)tcu::getNumUsedChannels(format.order);
4595 const bool isDepthFormat = tcu::hasDepthComponent(format.order);
4596 const bool isStencilFormat = tcu::hasStencilComponent(format.order);
4598 if (isDepthFormat || isStencilFormat)
4600 if (isDepthFormat && layout != VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL)
4602 fragmentShader << "\tinputs[" << inputValueNdx << "] = depthsEqual(" << deUint32(config.depthValues[1]) <<
4603 ".0f/255.0f, float(subpassLoad(i_depth" << attachmentNdx << ").x), " <<
4604 std::fixed << std::setprecision(12) << requiredDepthEpsilon(attachment.getFormat()) << ");\n";
4608 if (isStencilFormat && layout != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
4610 fragmentShader << "\tinputs[" << inputValueNdx << "] = 255u == subpassLoad(i_stencil" << attachmentNdx << ").x;\n";
4616 for (size_t compNdx = 0; compNdx < componentCount; compNdx++)
4618 fragmentShader << "\tinputs[" << inputValueNdx << "] = 1.0 == float(subpassLoad(i_color" << attachmentNdx << ")." << components[compNdx] << ");\n";
4624 size_t outputValueNdx = 0;
4626 for (size_t attachmentNdx = config.drawStartNdx; attachmentNdx < subpass.getColorAttachments().size(); attachmentNdx++)
4628 const deUint32 attachmentIndex = subpass.getColorAttachments()[attachmentNdx].getAttachment();
4629 const Attachment attachment = config.renderPass.getAttachments()[attachmentIndex];
4630 const std::string attachmentType = getAttachmentType(config.renderPass.getAttachments()[attachmentIndex].getFormat(), config.useFormatCompCount);
4631 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
4632 const size_t componentCount = (size_t)tcu::getNumUsedChannels(format.order);
4634 for (size_t compNdx = 0; compNdx < componentCount; compNdx++)
4636 const size_t index = subpassNdx + attachmentIndex + outputValueNdx;
4637 const BoolOp op = boolOpFromIndex(index);
4639 fragmentShader << "\toutputs[" << outputValueNdx + compNdx << "] = "
4640 << "(int(gl_FragCoord.x) % 2 == " << (index % 2)
4641 << ") " << boolOpToString(op) << " ("
4642 << "int(gl_FragCoord.y) % 2 == " << ((index / 2) % 2)
4645 for (size_t i = 0; i < inputsPerOutput; i++)
4646 fragmentShader << "\toutputs[" << outputValueNdx + compNdx << "] = outputs[" << outputValueNdx + compNdx << "] == inputs[" << ((outputValueNdx + compNdx) * inputsPerOutput + i) % inputComponentCount << "];\n";
4649 fragmentShader << "\to_color" << attachmentNdx << " = " << attachmentType << "(";
4651 for (size_t compNdx = 0; compNdx < (config.useFormatCompCount ? componentCount : 4); compNdx++)
4654 fragmentShader << ", ";
4656 if (compNdx < componentCount)
4657 fragmentShader << "outputs[" << outputValueNdx + compNdx << "]";
4659 fragmentShader << "0";
4662 outputValueNdx += componentCount;
4664 fragmentShader << ");\n";
4667 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED
4668 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
4669 && subpass.getDepthStencilAttachment().getImageLayout() != VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
4671 const deUint32 attachmentIndex = subpass.getDepthStencilAttachment().getAttachment();
4672 const size_t index = subpassNdx + attachmentIndex;
4673 const BoolOp op = boolOpFromIndex(index);
4675 fragmentShader << "\toutputs[" << outputValueNdx << "] = "
4676 << "(int(gl_FragCoord.x) % 2 == " << (index % 2)
4677 << ") " << boolOpToString(op) << " ("
4678 << "int(gl_FragCoord.y) % 2 == " << ((index / 2) % 2)
4681 for (size_t i = 0; i < inputsPerOutput; i++)
4682 fragmentShader << "\toutputs[" << outputValueNdx << "] = outputs[" << outputValueNdx << "] == inputs[" << (outputValueNdx * inputsPerOutput + i) % inputComponentCount << "];\n";
4684 fragmentShader << "\tgl_FragDepth = outputs[" << outputValueNdx << "] ? " << deUint32(config.depthValues[1]) << ".0f/255.0f : " << deUint32(config.depthValues[0]) << ".0f/255.0f;\n";
4689 fragmentShader << "}\n";
4691 dst.glslSources.add(de::toString(subpassNdx) + "-vert") << glu::VertexSource(vertexShader.str());
4692 dst.glslSources.add(de::toString(subpassNdx) + "-frag") << glu::FragmentSource(fragmentShader.str());
4697 void initializeAttachmentIsLazy (vector<bool>& attachmentIsLazy, const vector<Attachment>& attachments, TestConfig::ImageMemory imageMemory)
4699 bool lastAttachmentWasLazy = false;
4701 for (size_t attachmentNdx = 0; attachmentNdx < attachments.size(); attachmentNdx++)
4703 if (attachments[attachmentNdx].getLoadOp() != VK_ATTACHMENT_LOAD_OP_LOAD
4704 && attachments[attachmentNdx].getStoreOp() != VK_ATTACHMENT_STORE_OP_STORE
4705 && attachments[attachmentNdx].getStencilLoadOp() != VK_ATTACHMENT_LOAD_OP_LOAD
4706 && attachments[attachmentNdx].getStencilStoreOp() != VK_ATTACHMENT_STORE_OP_STORE)
4708 if (imageMemory == TestConfig::IMAGEMEMORY_LAZY || (imageMemory & TestConfig::IMAGEMEMORY_LAZY && !lastAttachmentWasLazy))
4710 attachmentIsLazy.push_back(true);
4712 lastAttachmentWasLazy = true;
4714 else if (imageMemory & TestConfig::IMAGEMEMORY_STRICT)
4716 attachmentIsLazy.push_back(false);
4717 lastAttachmentWasLazy = false;
4720 DE_FATAL("Unknown imageMemory");
4723 attachmentIsLazy.push_back(false);
4727 enum AttachmentRefType
4729 ATTACHMENTREFTYPE_COLOR,
4730 ATTACHMENTREFTYPE_DEPTH_STENCIL,
4731 ATTACHMENTREFTYPE_INPUT,
4732 ATTACHMENTREFTYPE_RESOLVE,
4735 VkImageUsageFlags getImageUsageFromLayout (VkImageLayout layout)
4739 case VK_IMAGE_LAYOUT_GENERAL:
4740 case VK_IMAGE_LAYOUT_PREINITIALIZED:
4743 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
4744 return VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
4746 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
4747 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
4748 return VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
4750 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
4751 return VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
4753 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL:
4754 return VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
4756 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL:
4757 return VK_IMAGE_USAGE_TRANSFER_DST_BIT;
4760 DE_FATAL("Unexpected image layout");
4765 void getImageUsageFromAttachmentReferences(vector<VkImageUsageFlags>& attachmentImageUsage, AttachmentRefType refType, size_t count, const AttachmentReference* references)
4767 for (size_t referenceNdx = 0; referenceNdx < count; ++referenceNdx)
4769 const deUint32 attachment = references[referenceNdx].getAttachment();
4771 if (attachment != VK_ATTACHMENT_UNUSED)
4773 VkImageUsageFlags usage;
4777 case ATTACHMENTREFTYPE_COLOR:
4778 case ATTACHMENTREFTYPE_RESOLVE:
4779 usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
4782 case ATTACHMENTREFTYPE_DEPTH_STENCIL:
4783 usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
4786 case ATTACHMENTREFTYPE_INPUT:
4787 usage = VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
4791 DE_FATAL("Unexpected attachment reference type");
4796 attachmentImageUsage[attachment] |= usage;
4801 void getImageUsageFromAttachmentReferences(vector<VkImageUsageFlags>& attachmentImageUsage, AttachmentRefType refType, const vector<AttachmentReference>& references)
4803 if (!references.empty())
4805 getImageUsageFromAttachmentReferences(attachmentImageUsage, refType, references.size(), &references[0]);
4809 void initializeAttachmentImageUsage (Context &context, vector<VkImageUsageFlags>& attachmentImageUsage, const RenderPass& renderPassInfo, const vector<bool>& attachmentIsLazy, const vector<Maybe<VkClearValue> >& clearValues)
4811 attachmentImageUsage.resize(renderPassInfo.getAttachments().size(), VkImageUsageFlags(0));
4813 for (size_t subpassNdx = 0; subpassNdx < renderPassInfo.getSubpasses().size(); ++subpassNdx)
4815 const Subpass& subpass = renderPassInfo.getSubpasses()[subpassNdx];
4817 getImageUsageFromAttachmentReferences(attachmentImageUsage, ATTACHMENTREFTYPE_COLOR, subpass.getColorAttachments());
4818 getImageUsageFromAttachmentReferences(attachmentImageUsage, ATTACHMENTREFTYPE_DEPTH_STENCIL, 1, &subpass.getDepthStencilAttachment());
4819 getImageUsageFromAttachmentReferences(attachmentImageUsage, ATTACHMENTREFTYPE_INPUT, subpass.getInputAttachments());
4820 getImageUsageFromAttachmentReferences(attachmentImageUsage, ATTACHMENTREFTYPE_RESOLVE, subpass.getResolveAttachments());
4823 for (size_t attachmentNdx = 0; attachmentNdx < renderPassInfo.getAttachments().size(); attachmentNdx++)
4825 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentNdx];
4826 const VkFormatProperties formatProperties = getPhysicalDeviceFormatProperties(context.getInstanceInterface(), context.getPhysicalDevice(), attachment.getFormat());
4827 const VkFormatFeatureFlags supportedFeatures = formatProperties.optimalTilingFeatures;
4829 if ((supportedFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) != 0)
4830 attachmentImageUsage[attachmentNdx] |= VK_IMAGE_USAGE_SAMPLED_BIT;
4832 if ((supportedFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) != 0)
4833 attachmentImageUsage[attachmentNdx] |= VK_IMAGE_USAGE_STORAGE_BIT;
4835 attachmentImageUsage[attachmentNdx] |= getImageUsageFromLayout(attachment.getInitialLayout());
4836 attachmentImageUsage[attachmentNdx] |= getImageUsageFromLayout(attachment.getFinalLayout());
4838 if (!attachmentIsLazy[attachmentNdx])
4840 if (clearValues[attachmentNdx])
4841 attachmentImageUsage[attachmentNdx] |= VK_IMAGE_USAGE_TRANSFER_DST_BIT;
4843 attachmentImageUsage[attachmentNdx] |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
4847 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);
4849 attachmentImageUsage[attachmentNdx] &= allowedTransientBits;
4850 attachmentImageUsage[attachmentNdx] |= VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT;
4855 void initializeSubpassIsSecondary (vector<bool>& subpassIsSecondary, const vector<Subpass>& subpasses, TestConfig::CommandBufferTypes commandBuffer)
4857 bool lastSubpassWasSecondary = false;
4859 for (size_t subpassNdx = 0; subpassNdx < subpasses.size(); subpassNdx++)
4861 if (commandBuffer == TestConfig::COMMANDBUFFERTYPES_SECONDARY || (commandBuffer & TestConfig::COMMANDBUFFERTYPES_SECONDARY && !lastSubpassWasSecondary))
4863 subpassIsSecondary.push_back(true);
4864 lastSubpassWasSecondary = true;
4866 else if (commandBuffer & TestConfig::COMMANDBUFFERTYPES_INLINE)
4868 subpassIsSecondary.push_back(false);
4869 lastSubpassWasSecondary = false;
4872 DE_FATAL("Unknown commandBuffer");
4876 void initializeImageClearValues (de::Random& rng, vector<Maybe<VkClearValue> >& clearValues, const vector<Attachment>& attachments, const vector<bool>& isLazy, deBool useFormatCompCount, const DepthValuesArray& depthValues)
4878 for (size_t attachmentNdx = 0; attachmentNdx < attachments.size(); attachmentNdx++)
4880 if (!isLazy[attachmentNdx])
4881 clearValues.push_back(just(randomClearValue(attachments[attachmentNdx], rng, useFormatCompCount, depthValues)));
4883 clearValues.push_back(tcu::Nothing);
4887 void initializeRenderPassClearValues (de::Random& rng, vector<Maybe<VkClearValue> >& clearValues, const vector<Attachment>& attachments, deBool useFormatCompCount, const DepthValuesArray& depthValues)
4889 for (size_t attachmentNdx = 0; attachmentNdx < attachments.size(); attachmentNdx++)
4891 if (attachments[attachmentNdx].getLoadOp() == VK_ATTACHMENT_LOAD_OP_CLEAR
4892 || attachments[attachmentNdx].getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_CLEAR)
4894 clearValues.push_back(just(randomClearValue(attachments[attachmentNdx], rng, useFormatCompCount, depthValues)));
4897 clearValues.push_back(tcu::Nothing);
4901 void logSubpassRenderInfo (TestLog& log, const SubpassRenderInfo& info, TestConfig config)
4903 log << TestLog::Message << "Viewport, offset: " << info.getViewportOffset() << ", size: " << info.getViewportSize() << TestLog::EndMessage;
4905 if (info.isSecondary())
4906 log << TestLog::Message << "Subpass uses secondary command buffers" << TestLog::EndMessage;
4908 log << TestLog::Message << "Subpass uses inlined commands" << TestLog::EndMessage;
4910 for (deUint32 attachmentNdx = 0; attachmentNdx < info.getColorClears().size(); attachmentNdx++)
4912 const ColorClear& colorClear = info.getColorClears()[attachmentNdx];
4914 log << TestLog::Message << "Clearing color attachment " << attachmentNdx
4915 << ". Offset: " << colorClear.getOffset()
4916 << ", Size: " << colorClear.getSize()
4917 << ", Color: " << clearColorToString(info.getColorAttachment(attachmentNdx).getFormat(), colorClear.getColor(), config.useFormatCompCount) << TestLog::EndMessage;
4920 if (info.getDepthStencilClear())
4922 const DepthStencilClear& depthStencilClear = *info.getDepthStencilClear();
4924 log << TestLog::Message << "Clearing depth stencil attachment"
4925 << ". Offset: " << depthStencilClear.getOffset()
4926 << ", Size: " << depthStencilClear.getSize()
4927 << ", Depth: " << depthStencilClear.getDepth()
4928 << ", Stencil: " << depthStencilClear.getStencil() << TestLog::EndMessage;
4931 if (info.getRenderQuad())
4933 const RenderQuad& renderQuad = *info.getRenderQuad();
4935 log << TestLog::Message << "Rendering grid quad to " << renderQuad.getCornerA() << " -> " << renderQuad.getCornerB() << TestLog::EndMessage;
4939 void logTestCaseInfo (TestLog& log,
4940 const TestConfig& config,
4941 const vector<bool>& attachmentIsLazy,
4942 const vector<Maybe<VkClearValue> >& imageClearValues,
4943 const vector<Maybe<VkClearValue> >& renderPassClearValues,
4944 const vector<SubpassRenderInfo>& subpassRenderInfo)
4946 const RenderPass& renderPass = config.renderPass;
4948 logRenderPassInfo(log, renderPass);
4950 DE_ASSERT(attachmentIsLazy.size() == renderPass.getAttachments().size());
4951 DE_ASSERT(imageClearValues.size() == renderPass.getAttachments().size());
4952 DE_ASSERT(renderPassClearValues.size() == renderPass.getAttachments().size());
4954 log << TestLog::Message << "TargetSize: " << config.targetSize << TestLog::EndMessage;
4955 log << TestLog::Message << "Render area, Offset: " << config.renderPos << ", Size: " << config.renderSize << TestLog::EndMessage;
4957 for (size_t attachmentNdx = 0; attachmentNdx < attachmentIsLazy.size(); attachmentNdx++)
4959 const tcu::ScopedLogSection section (log, "Attachment" + de::toString(attachmentNdx), "Attachment " + de::toString(attachmentNdx));
4961 if (attachmentIsLazy[attachmentNdx])
4962 log << TestLog::Message << "Is lazy." << TestLog::EndMessage;
4964 if (imageClearValues[attachmentNdx])
4965 log << TestLog::Message << "Image is cleared to " << clearValueToString(renderPass.getAttachments()[attachmentNdx].getFormat(),
4966 *imageClearValues[attachmentNdx], config.useFormatCompCount) << " before rendering." << TestLog::EndMessage;
4968 if (renderPass.getAttachments()[attachmentNdx].getLoadOp() == VK_ATTACHMENT_LOAD_OP_CLEAR && renderPassClearValues[attachmentNdx])
4969 log << TestLog::Message << "Attachment is cleared to " << clearValueToString(renderPass.getAttachments()[attachmentNdx].getFormat(),
4970 *renderPassClearValues[attachmentNdx], config.useFormatCompCount) << " in the beginning of the render pass." << TestLog::EndMessage;
4973 for (size_t subpassNdx = 0; subpassNdx < renderPass.getSubpasses().size(); subpassNdx++)
4975 const tcu::ScopedLogSection section (log, "Subpass" + de::toString(subpassNdx), "Subpass " + de::toString(subpassNdx));
4977 logSubpassRenderInfo(log, subpassRenderInfo[subpassNdx], config);
4981 float roundToViewport (float x, deUint32 offset, deUint32 size)
4983 const float origin = (float)(offset) + ((float(size) / 2.0f));
4984 const float p = (float)(size) / 2.0f;
4985 const deInt32 xi = deRoundFloatToInt32(origin + (p * x));
4987 return (((float)xi) - origin) / p;
4990 void initializeSubpassRenderInfo (vector<SubpassRenderInfo>& renderInfos, de::Random& rng, const RenderPass& renderPass, const TestConfig& config)
4992 const TestConfig::CommandBufferTypes commandBuffer = config.commandBufferTypes;
4993 const vector<Subpass>& subpasses = renderPass.getSubpasses();
4994 bool lastSubpassWasSecondary = false;
4996 for (deUint32 subpassNdx = 0; subpassNdx < (deUint32)subpasses.size(); subpassNdx++)
4998 const Subpass& subpass = subpasses[subpassNdx];
4999 const bool subpassIsSecondary = commandBuffer == TestConfig::COMMANDBUFFERTYPES_SECONDARY
5000 || (commandBuffer & TestConfig::COMMANDBUFFERTYPES_SECONDARY && !lastSubpassWasSecondary) ? true : false;
5001 const bool omitBlendState = subpass.getOmitBlendState();
5002 const UVec2 viewportSize ((config.renderSize * UVec2(2)) / UVec2(3));
5003 const UVec2 viewportOffset (config.renderPos.x() + (subpassNdx % 2) * (config.renderSize.x() / 3),
5004 config.renderPos.y() + ((subpassNdx / 2) % 2) * (config.renderSize.y() / 3));
5006 vector<ColorClear> colorClears;
5007 Maybe<DepthStencilClear> depthStencilClear;
5008 Maybe<RenderQuad> renderQuad;
5010 lastSubpassWasSecondary = subpassIsSecondary;
5012 if (config.renderTypes & TestConfig::RENDERTYPES_CLEAR)
5014 const vector<AttachmentReference>& colorAttachments = subpass.getColorAttachments();
5016 for (size_t attachmentRefNdx = 0; attachmentRefNdx < colorAttachments.size(); attachmentRefNdx++)
5018 const AttachmentReference& attachmentRef = colorAttachments[attachmentRefNdx];
5019 const Attachment& attachment = renderPass.getAttachments()[attachmentRef.getAttachment()];
5020 const UVec2 size ((viewportSize * UVec2(2)) / UVec2(3));
5021 const UVec2 offset (viewportOffset.x() + ((deUint32)attachmentRefNdx % 2u) * (viewportSize.x() / 3u),
5022 viewportOffset.y() + (((deUint32)attachmentRefNdx / 2u) % 2u) * (viewportSize.y() / 3u));
5023 const VkClearColorValue color = randomColorClearValue(attachment, rng, config.useFormatCompCount);
5025 colorClears.push_back(ColorClear(offset, size, color));
5028 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED)
5030 const Attachment& attachment = renderPass.getAttachments()[subpass.getDepthStencilAttachment().getAttachment()];
5031 const UVec2 size ((viewportSize * UVec2(2)) / UVec2(3));
5032 const UVec2 offset (viewportOffset.x() + ((deUint32)colorAttachments.size() % 2u) * (viewportSize.x() / 3u),
5033 viewportOffset.y() + (((deUint32)colorAttachments.size() / 2u) % 2u) * (viewportSize.y() / 3u));
5034 const VkClearValue value = randomClearValue(attachment, rng, config.useFormatCompCount, config.depthValues);
5036 depthStencilClear = tcu::just(DepthStencilClear(offset, size, value.depthStencil.depth, value.depthStencil.stencil));
5040 if (config.renderTypes & TestConfig::RENDERTYPES_DRAW)
5042 const float w = (subpassNdx % 2) == 0 ? 1.0f : 1.25f;
5043 const float h = (subpassNdx % 2) == 0 ? 1.25f : 1.0f;
5045 const float x0 = roundToViewport((subpassNdx % 2) == 0 ? 1.0f - w : -1.0f, viewportOffset.x(), viewportSize.x());
5046 const float x1 = roundToViewport((subpassNdx % 2) == 0 ? 1.0f : -1.0f + w, viewportOffset.x(), viewportSize.x());
5048 const float y0 = roundToViewport(((subpassNdx / 2) % 2) == 0 ? 1.0f - h : -1.0f, viewportOffset.y(), viewportSize.y());
5049 const float y1 = roundToViewport(((subpassNdx / 2) % 2) == 0 ? 1.0f : -1.0f + h, viewportOffset.y(), viewportSize.y());
5051 renderQuad = tcu::just(RenderQuad(tcu::Vec2(x0, y0), tcu::Vec2(x1, y1)));
5054 renderInfos.push_back(SubpassRenderInfo(renderPass, subpassNdx, config.drawStartNdx, subpassIsSecondary, omitBlendState, viewportOffset, viewportSize, renderQuad, colorClears, depthStencilClear));
5058 void checkTextureFormatSupport (TestLog& log,
5059 const InstanceInterface& vk,
5060 VkPhysicalDevice device,
5061 const vector<Attachment>& attachments)
5063 bool supported = true;
5065 for (size_t attachmentNdx = 0; attachmentNdx < attachments.size(); attachmentNdx++)
5067 const Attachment& attachment = attachments[attachmentNdx];
5068 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
5069 const bool isDepthOrStencilAttachment = hasDepthComponent(format.order) || hasStencilComponent(format.order);
5070 const VkFormatFeatureFlags flags = isDepthOrStencilAttachment? VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT : VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT;
5071 VkFormatProperties properties;
5073 vk.getPhysicalDeviceFormatProperties(device, attachment.getFormat(), &properties);
5075 if ((properties.optimalTilingFeatures & flags) != flags)
5078 log << TestLog::Message << "Format: " << attachment.getFormat() << " not supported as " << (isDepthOrStencilAttachment ? "depth stencil attachment" : "color attachment") << TestLog::EndMessage;
5083 TCU_THROW(NotSupportedError, "Format not supported");
5086 tcu::TestStatus renderPassTest (Context& context, TestConfig config)
5088 const UVec2 targetSize = config.targetSize;
5089 const UVec2 renderPos = config.renderPos;
5090 const UVec2 renderSize = config.renderSize;
5091 const RenderPass& renderPassInfo = config.renderPass;
5093 TestLog& log = context.getTestContext().getLog();
5094 de::Random rng (config.seed);
5096 vector<bool> attachmentIsLazy;
5097 vector<VkImageUsageFlags> attachmentImageUsage;
5098 vector<Maybe<VkClearValue> > imageClearValues;
5099 vector<Maybe<VkClearValue> > renderPassClearValues;
5101 vector<bool> subpassIsSecondary;
5102 vector<SubpassRenderInfo> subpassRenderInfo;
5104 if (config.groupParams->renderingType == RENDERING_TYPE_RENDERPASS2)
5105 context.requireDeviceFunctionality("VK_KHR_create_renderpass2");
5107 if (config.groupParams->renderingType == RENDERING_TYPE_DYNAMIC_RENDERING)
5108 context.requireDeviceFunctionality("VK_KHR_dynamic_rendering");
5110 if (config.allocationKind == ALLOCATION_KIND_DEDICATED)
5112 if (!context.isDeviceFunctionalitySupported("VK_KHR_dedicated_allocation"))
5113 TCU_THROW(NotSupportedError, "VK_KHR_dedicated_allocation is not supported");
5116 if (!renderPassInfo.getInputAspects().empty())
5118 if (!context.isDeviceFunctionalitySupported("VK_KHR_maintenance2"))
5119 TCU_THROW(NotSupportedError, "Extension VK_KHR_maintenance2 not supported.");
5123 bool requireDepthStencilLayout = false;
5125 for (size_t attachmentNdx = 0; attachmentNdx < renderPassInfo.getAttachments().size(); attachmentNdx++)
5127 if (renderPassInfo.getAttachments()[attachmentNdx].getInitialLayout() == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL
5128 || renderPassInfo.getAttachments()[attachmentNdx].getInitialLayout() == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL
5129 || renderPassInfo.getAttachments()[attachmentNdx].getFinalLayout() == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL
5130 || renderPassInfo.getAttachments()[attachmentNdx].getFinalLayout() == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
5132 requireDepthStencilLayout = true;
5137 for (size_t subpassNdx = 0; subpassNdx < renderPassInfo.getSubpasses().size() && !requireDepthStencilLayout; subpassNdx++)
5139 const Subpass& subpass (renderPassInfo.getSubpasses()[subpassNdx]);
5141 for (size_t attachmentNdx = 0; attachmentNdx < subpass.getColorAttachments().size(); attachmentNdx++)
5143 if (subpass.getColorAttachments()[attachmentNdx].getImageLayout() == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL
5144 || subpass.getColorAttachments()[attachmentNdx].getImageLayout() == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
5146 requireDepthStencilLayout = true;
5151 for (size_t attachmentNdx = 0; !requireDepthStencilLayout && attachmentNdx < subpass.getInputAttachments().size(); attachmentNdx++)
5153 if (subpass.getInputAttachments()[attachmentNdx].getImageLayout() == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL
5154 || subpass.getInputAttachments()[attachmentNdx].getImageLayout() == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
5156 requireDepthStencilLayout = true;
5161 for (size_t attachmentNdx = 0; !requireDepthStencilLayout && attachmentNdx < subpass.getResolveAttachments().size(); attachmentNdx++)
5163 if (subpass.getResolveAttachments()[attachmentNdx].getImageLayout() == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL
5164 || subpass.getResolveAttachments()[attachmentNdx].getImageLayout() == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
5166 requireDepthStencilLayout = true;
5171 if (subpass.getDepthStencilAttachment().getImageLayout() == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL
5172 || subpass.getDepthStencilAttachment().getImageLayout() == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL)
5174 requireDepthStencilLayout = true;
5179 if (requireDepthStencilLayout && !context.isDeviceFunctionalitySupported("VK_KHR_maintenance2"))
5180 TCU_THROW(NotSupportedError, "VK_KHR_maintenance2 is not supported");
5183 initializeAttachmentIsLazy(attachmentIsLazy, renderPassInfo.getAttachments(), config.imageMemory);
5184 initializeImageClearValues(rng, imageClearValues, renderPassInfo.getAttachments(), attachmentIsLazy, config.useFormatCompCount, config.depthValues);
5185 initializeAttachmentImageUsage(context, attachmentImageUsage, renderPassInfo, attachmentIsLazy, imageClearValues);
5186 initializeRenderPassClearValues(rng, renderPassClearValues, renderPassInfo.getAttachments(), config.useFormatCompCount, config.depthValues);
5188 initializeSubpassIsSecondary(subpassIsSecondary, renderPassInfo.getSubpasses(), config.commandBufferTypes);
5189 initializeSubpassRenderInfo(subpassRenderInfo, rng, renderPassInfo, config);
5191 logTestCaseInfo(log, config, attachmentIsLazy, imageClearValues, renderPassClearValues, subpassRenderInfo);
5193 checkTextureFormatSupport(log, context.getInstanceInterface(), context.getPhysicalDevice(), config.renderPass.getAttachments());
5196 const vk::VkPhysicalDeviceProperties properties = vk::getPhysicalDeviceProperties(context.getInstanceInterface(), context.getPhysicalDevice());
5198 log << TestLog::Message << "Max color attachments: " << properties.limits.maxColorAttachments << TestLog::EndMessage;
5200 for (size_t subpassNdx = 0; subpassNdx < renderPassInfo.getSubpasses().size(); subpassNdx++)
5202 if (renderPassInfo.getSubpasses()[subpassNdx].getColorAttachments().size() > (size_t)properties.limits.maxColorAttachments)
5203 TCU_THROW(NotSupportedError, "Subpass uses more than maxColorAttachments.");
5208 const InstanceInterface& vki = context.getInstanceInterface();
5209 const VkPhysicalDevice& physDevice = context.getPhysicalDevice();
5210 const VkDevice device = context.getDevice();
5211 const DeviceInterface& vk = context.getDeviceInterface();
5212 const VkQueue queue = context.getUniversalQueue();
5213 const deUint32 queueIndex = context.getUniversalQueueFamilyIndex();
5214 Allocator& allocator = context.getDefaultAllocator();
5216 const Unique<VkCommandPool> commandBufferPool (createCommandPool(vk, device, 0, queueIndex));
5217 const Unique<VkCommandBuffer> initializeImagesCommandBuffer (allocateCommandBuffer(vk, device, *commandBufferPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
5218 const Unique<VkCommandBuffer> renderCommandBuffer (allocateCommandBuffer(vk, device, *commandBufferPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
5219 const Unique<VkCommandBuffer> readImagesToBuffersCommandBuffer (allocateCommandBuffer(vk, device, *commandBufferPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
5221 vector<de::SharedPtr<AttachmentResources> > attachmentResources;
5222 vector<de::SharedPtr<SubpassRenderer> > subpassRenderers;
5223 vector<VkImage> attachmentImages;
5224 vector<VkImageView> attachmentViews;
5225 vector<pair<VkImageView, VkImageView> > inputAttachmentViews;
5227 Move<VkRenderPass> renderPass;
5228 if (config.groupParams->renderingType != RENDERING_TYPE_DYNAMIC_RENDERING)
5229 renderPass = createRenderPass(vk, device, renderPassInfo, config.groupParams->renderingType);
5231 for (size_t attachmentNdx = 0; attachmentNdx < renderPassInfo.getAttachments().size(); attachmentNdx++)
5233 const Attachment& attachmentInfo = renderPassInfo.getAttachments()[attachmentNdx];
5235 attachmentResources.push_back(de::SharedPtr<AttachmentResources>(new AttachmentResources(vki, physDevice, vk, device, allocator, queueIndex, targetSize, attachmentInfo, attachmentImageUsage[attachmentNdx], config.allocationKind)));
5236 attachmentViews.push_back(attachmentResources[attachmentNdx]->getAttachmentView());
5237 attachmentImages.push_back(attachmentResources[attachmentNdx]->getImage());
5239 inputAttachmentViews.push_back(attachmentResources[attachmentNdx]->getInputAttachmentViews());
5242 beginCommandBuffer(vk, *initializeImagesCommandBuffer, DE_NULL, 0, DE_NULL, VK_FALSE, (VkQueryControlFlags)0, (VkQueryPipelineStatisticFlags)0);
5243 pushImageInitializationCommands(vk, *initializeImagesCommandBuffer, renderPassInfo.getAttachments(), attachmentResources, queueIndex, imageClearValues);
5244 endCommandBuffer(vk, *initializeImagesCommandBuffer);
5247 Move<VkFramebuffer> framebuffer;
5248 if (config.groupParams->renderingType != RENDERING_TYPE_DYNAMIC_RENDERING)
5249 framebuffer = createFramebuffer(vk, device, *renderPass, targetSize, attachmentViews);
5251 const VkRect2D renderArea
5253 { (deInt32)renderPos.x(), (deInt32)renderPos.y() },
5254 { renderSize.x(), renderSize.y() }
5256 const bool dynamicRendering = (config.groupParams->renderingType == RENDERING_TYPE_DYNAMIC_RENDERING);
5257 const bool secondaryCmdBufferCompletelyContainsDynamicRenderpass = (config.commandBufferTypes == TestConfig::COMMANDBUFFERTYPES_SECONDARY) &&
5258 config.groupParams->secondaryCmdBufferCompletelyContainsDynamicRenderpass;
5260 for (size_t subpassNdx = 0; subpassNdx < renderPassInfo.getSubpasses().size(); subpassNdx++)
5262 subpassRenderers.push_back(de::SharedPtr<SubpassRenderer>(new SubpassRenderer(context, vk, device, allocator, renderPassInfo, attachmentResources,
5263 renderArea, renderPassClearValues, *renderPass, *framebuffer,
5264 *commandBufferPool, queueIndex, attachmentImages, inputAttachmentViews,
5265 subpassRenderInfo[subpassNdx], config.allocationKind, dynamicRendering,
5266 secondaryCmdBufferCompletelyContainsDynamicRenderpass)));
5269 beginCommandBuffer(vk, *renderCommandBuffer, DE_NULL, 0, DE_NULL, VK_FALSE, (VkQueryControlFlags)0, (VkQueryPipelineStatisticFlags)0);
5270 pushRenderPassCommands(vk, *renderCommandBuffer, *renderPass, renderPassInfo, attachmentResources, *framebuffer, subpassRenderers, renderArea,
5271 renderPassClearValues, queueIndex, config.renderTypes, config.groupParams->renderingType, secondaryCmdBufferCompletelyContainsDynamicRenderpass);
5272 endCommandBuffer(vk, *renderCommandBuffer);
5274 beginCommandBuffer(vk, *readImagesToBuffersCommandBuffer, DE_NULL, 0, DE_NULL, VK_FALSE, (VkQueryControlFlags)0, (VkQueryPipelineStatisticFlags)0);
5275 pushReadImagesToBuffers(vk, *readImagesToBuffersCommandBuffer, queueIndex, attachmentResources, renderPassInfo.getAttachments(), attachmentIsLazy, targetSize);
5276 endCommandBuffer(vk, *readImagesToBuffersCommandBuffer);
5278 const VkCommandBuffer commandBuffers[] =
5280 *initializeImagesCommandBuffer,
5281 *renderCommandBuffer,
5282 *readImagesToBuffersCommandBuffer
5284 const Unique<VkFence> fence (createFence(vk, device, 0u));
5286 queueSubmit(vk, queue, DE_LENGTH_OF_ARRAY(commandBuffers), commandBuffers, *fence);
5287 waitForFences(vk, device, 1, &fence.get(), VK_TRUE, ~0ull);
5290 #ifdef CTS_USES_VULKANSC
5291 if (!context.getTestContext().getCommandLine().isSubProcess())
5292 return tcu::TestStatus::pass("Pass");
5294 if (logAndVerifyImages(log, vk, device, attachmentResources, attachmentIsLazy, renderPassInfo, renderPassClearValues, imageClearValues, subpassRenderInfo, targetSize, config))
5295 return tcu::TestStatus::pass("Pass");
5297 return tcu::TestStatus::fail("Result verification failed");
5301 static const VkFormat s_coreColorFormats[] =
5303 VK_FORMAT_R5G6B5_UNORM_PACK16,
5308 VK_FORMAT_R8G8_UNORM,
5309 VK_FORMAT_R8G8_SNORM,
5310 VK_FORMAT_R8G8_UINT,
5311 VK_FORMAT_R8G8_SINT,
5312 VK_FORMAT_R8G8B8A8_UNORM,
5313 VK_FORMAT_R8G8B8A8_SNORM,
5314 VK_FORMAT_R8G8B8A8_UINT,
5315 VK_FORMAT_R8G8B8A8_SINT,
5316 VK_FORMAT_R8G8B8A8_SRGB,
5317 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
5318 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
5319 VK_FORMAT_A8B8G8R8_UINT_PACK32,
5320 VK_FORMAT_A8B8G8R8_SINT_PACK32,
5321 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
5322 VK_FORMAT_B8G8R8A8_UNORM,
5323 VK_FORMAT_B8G8R8A8_SRGB,
5324 VK_FORMAT_A2R10G10B10_UNORM_PACK32,
5325 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
5326 VK_FORMAT_A2B10G10R10_UINT_PACK32,
5327 VK_FORMAT_R16_UNORM,
5328 VK_FORMAT_R16_SNORM,
5331 VK_FORMAT_R16_SFLOAT,
5332 VK_FORMAT_R16G16_UNORM,
5333 VK_FORMAT_R16G16_SNORM,
5334 VK_FORMAT_R16G16_UINT,
5335 VK_FORMAT_R16G16_SINT,
5336 VK_FORMAT_R16G16_SFLOAT,
5337 VK_FORMAT_R16G16B16A16_UNORM,
5338 VK_FORMAT_R16G16B16A16_SNORM,
5339 VK_FORMAT_R16G16B16A16_UINT,
5340 VK_FORMAT_R16G16B16A16_SINT,
5341 VK_FORMAT_R16G16B16A16_SFLOAT,
5344 VK_FORMAT_R32_SFLOAT,
5345 VK_FORMAT_R32G32_UINT,
5346 VK_FORMAT_R32G32_SINT,
5347 VK_FORMAT_R32G32_SFLOAT,
5348 VK_FORMAT_R32G32B32A32_UINT,
5349 VK_FORMAT_R32G32B32A32_SINT,
5350 VK_FORMAT_R32G32B32A32_SFLOAT
5353 static const VkFormat s_coreDepthStencilFormats[] =
5355 VK_FORMAT_D16_UNORM,
5357 VK_FORMAT_X8_D24_UNORM_PACK32,
5358 VK_FORMAT_D32_SFLOAT,
5360 VK_FORMAT_D24_UNORM_S8_UINT,
5361 VK_FORMAT_D32_SFLOAT_S8_UINT
5364 void addAttachmentTests (tcu::TestCaseGroup* group, const TestConfigExternal testConfigExternal)
5366 const deUint32 attachmentCounts[] = { 1, 3, 4, 8 };
5367 const VkAttachmentLoadOp loadOps[] =
5369 VK_ATTACHMENT_LOAD_OP_LOAD,
5370 VK_ATTACHMENT_LOAD_OP_CLEAR,
5371 VK_ATTACHMENT_LOAD_OP_DONT_CARE
5374 const VkAttachmentStoreOp storeOps[] =
5376 VK_ATTACHMENT_STORE_OP_STORE,
5377 VK_ATTACHMENT_STORE_OP_DONT_CARE
5380 const VkImageLayout initialAndFinalColorLayouts[] =
5382 VK_IMAGE_LAYOUT_GENERAL,
5383 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
5384 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
5385 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
5386 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
5389 const VkImageLayout initialAndFinalColorLayoutsLazy[] =
5391 VK_IMAGE_LAYOUT_GENERAL,
5392 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
5393 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
5396 const VkImageLayout initialAndFinalDepthStencilLayouts[] =
5398 VK_IMAGE_LAYOUT_GENERAL,
5399 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
5400 VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL,
5401 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
5402 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
5403 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
5406 const VkImageLayout initialAndFinalDepthStencilLayoutsLazy[] =
5408 VK_IMAGE_LAYOUT_GENERAL,
5409 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
5410 VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL,
5411 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
5414 const VkImageLayout subpassLayouts[] =
5416 VK_IMAGE_LAYOUT_GENERAL,
5417 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
5420 const VkImageLayout depthStencilLayouts[] =
5422 VK_IMAGE_LAYOUT_GENERAL,
5423 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL
5426 const TestConfig::RenderTypes renderCommands[] =
5428 TestConfig::RENDERTYPES_NONE,
5429 TestConfig::RENDERTYPES_CLEAR,
5430 TestConfig::RENDERTYPES_DRAW,
5431 TestConfig::RENDERTYPES_CLEAR|TestConfig::RENDERTYPES_DRAW,
5434 const TestConfig::CommandBufferTypes commandBuffers[] =
5436 TestConfig::COMMANDBUFFERTYPES_INLINE,
5437 TestConfig::COMMANDBUFFERTYPES_SECONDARY,
5438 TestConfig::COMMANDBUFFERTYPES_INLINE|TestConfig::COMMANDBUFFERTYPES_SECONDARY
5441 const TestConfig::ImageMemory imageMemories[] =
5443 TestConfig::IMAGEMEMORY_STRICT,
5444 TestConfig::IMAGEMEMORY_LAZY,
5445 TestConfig::IMAGEMEMORY_STRICT|TestConfig::IMAGEMEMORY_LAZY
5448 const UVec2 targetSizes[] =
5454 const UVec2 renderPositions[] =
5460 const UVec2 renderSizes[] =
5466 tcu::TestContext& testCtx (group->getTestContext());
5467 bool useDynamicRendering (testConfigExternal.groupParams->renderingType == RENDERING_TYPE_DYNAMIC_RENDERING);
5468 de::Random rng (1433774382u);
5470 for (size_t attachmentCountNdx = 0; attachmentCountNdx < DE_LENGTH_OF_ARRAY(attachmentCounts); attachmentCountNdx++)
5472 const deUint32 attachmentCount = attachmentCounts[attachmentCountNdx];
5473 const deUint32 testCaseCount = (attachmentCount == 1 ? 100 : 200);
5474 de::MovePtr<tcu::TestCaseGroup> attachmentCountGroup (new tcu::TestCaseGroup(testCtx, de::toString(attachmentCount).c_str(), de::toString(attachmentCount).c_str()));
5476 for (size_t testCaseNdx = 0; testCaseNdx < testCaseCount; testCaseNdx++)
5478 const bool useDepthStencil = rng.getBool();
5479 const TestConfig::ImageMemory imageMemory = rng.choose<TestConfig::ImageMemory>(DE_ARRAY_BEGIN(imageMemories), DE_ARRAY_END(imageMemories));
5480 VkImageLayout depthStencilLayout = VK_IMAGE_LAYOUT_GENERAL;
5481 vector<Attachment> attachments;
5482 vector<AttachmentReference> colorAttachmentReferences;
5484 // we want to make sure that dynamic rendering test cases have corresponding renderpass
5485 // cases as this will allow drivers to easily compare GPU batches; since configurations
5486 // for those tests are generated we need to generate configurations for all cases
5487 // even when we know earlier that for dynamic rendering we will skip it
5488 bool executeForDynamicRendering = true;
5490 for (size_t attachmentNdx = 0; attachmentNdx < attachmentCount; attachmentNdx++)
5492 const VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_1_BIT;
5493 const VkFormat format = rng.choose<VkFormat>(DE_ARRAY_BEGIN(s_coreColorFormats), DE_ARRAY_END(s_coreColorFormats));
5494 const VkAttachmentLoadOp loadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
5495 const VkAttachmentStoreOp storeOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
5497 const VkImageLayout initialLayout = (imageMemory == TestConfig::IMAGEMEMORY_STRICT)
5498 ? rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalColorLayouts), DE_ARRAY_END(initialAndFinalColorLayouts))
5499 : rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalColorLayoutsLazy), DE_ARRAY_END(initialAndFinalColorLayoutsLazy));
5500 VkImageLayout finalizeLayout = (imageMemory == TestConfig::IMAGEMEMORY_STRICT)
5501 ? rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalColorLayouts), DE_ARRAY_END(initialAndFinalColorLayouts))
5502 : rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalColorLayoutsLazy), DE_ARRAY_END(initialAndFinalColorLayoutsLazy));
5503 const VkImageLayout subpassLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayouts), DE_ARRAY_END(subpassLayouts));
5505 const VkAttachmentLoadOp stencilLoadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
5506 const VkAttachmentStoreOp stencilStoreOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
5508 if (useDynamicRendering)
5510 // with renderpass we can have automatic layout transitions; to do the same with dynamic rendering cases
5511 // we would need to add addtional barries but since those tests won't add coverage we are skipping them
5512 if ((initialLayout == VK_IMAGE_LAYOUT_GENERAL) ||
5513 (initialLayout == VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL))
5514 finalizeLayout = initialLayout;
5516 executeForDynamicRendering = false;
5519 attachments.push_back(Attachment(format, sampleCount, loadOp, storeOp, stencilLoadOp, stencilStoreOp, initialLayout, finalizeLayout));
5520 colorAttachmentReferences.push_back(AttachmentReference((deUint32)attachmentNdx, subpassLayout));
5523 if (useDepthStencil)
5525 const VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_1_BIT;
5526 const VkFormat format = rng.choose<VkFormat>(DE_ARRAY_BEGIN(s_coreDepthStencilFormats), DE_ARRAY_END(s_coreDepthStencilFormats));
5527 const VkAttachmentLoadOp loadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
5528 const VkAttachmentStoreOp storeOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
5530 const VkImageLayout initialLayout = (imageMemory == TestConfig::IMAGEMEMORY_STRICT)
5531 ? rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalDepthStencilLayouts), DE_ARRAY_END(initialAndFinalDepthStencilLayouts))
5532 : rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalDepthStencilLayoutsLazy), DE_ARRAY_END(initialAndFinalDepthStencilLayoutsLazy));
5533 VkImageLayout finalizeLayout = (imageMemory == TestConfig::IMAGEMEMORY_STRICT)
5534 ? rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalDepthStencilLayouts), DE_ARRAY_END(initialAndFinalDepthStencilLayouts))
5535 : rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalDepthStencilLayoutsLazy), DE_ARRAY_END(initialAndFinalDepthStencilLayoutsLazy));
5537 const VkAttachmentLoadOp stencilLoadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
5538 const VkAttachmentStoreOp stencilStoreOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
5540 if (useDynamicRendering)
5542 if ((initialLayout == VK_IMAGE_LAYOUT_GENERAL) ||
5543 (initialLayout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) ||
5544 (initialLayout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL))
5545 finalizeLayout = initialLayout;
5547 executeForDynamicRendering = false;
5550 depthStencilLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(depthStencilLayouts), DE_ARRAY_END(depthStencilLayouts));
5551 attachments.push_back(Attachment(format, sampleCount, loadOp, storeOp, stencilLoadOp, stencilStoreOp, initialLayout, finalizeLayout));
5555 const TestConfig::RenderTypes render = rng.choose<TestConfig::RenderTypes>(DE_ARRAY_BEGIN(renderCommands), DE_ARRAY_END(renderCommands));
5556 const TestConfig::CommandBufferTypes commandBuffer = rng.choose<TestConfig::CommandBufferTypes>(DE_ARRAY_BEGIN(commandBuffers), DE_ARRAY_END(commandBuffers));
5557 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>()));
5558 const vector<SubpassDependency> deps;
5559 const string testCaseName = de::toString(attachmentCountNdx * testCaseCount + testCaseNdx);
5560 const RenderPass renderPass (attachments, subpasses, deps);
5561 const UVec2 targetSize = rng.choose<UVec2>(DE_ARRAY_BEGIN(targetSizes), DE_ARRAY_END(targetSizes));
5562 const UVec2 renderPos = rng.choose<UVec2>(DE_ARRAY_BEGIN(renderPositions), DE_ARRAY_END(renderPositions));
5563 const UVec2 renderSize = rng.choose<UVec2>(DE_ARRAY_BEGIN(renderSizes), DE_ARRAY_END(renderSizes));
5565 if (useDynamicRendering)
5567 // skip dynamic rendering cases (that don't add coverage) this can be done not earlier than after grabbing all
5568 // random numbers as we need to make sure that those tests that will be created for dynamic rendering have
5569 // corresponding renderpass tests with the same name
5570 if (!executeForDynamicRendering)
5573 // dont repeat non secondary buffer cases when testing secondaryCmdBufferCompletelyContainsDynamicRenderpass flag
5574 if (testConfigExternal.groupParams->secondaryCmdBufferCompletelyContainsDynamicRenderpass &&
5575 (commandBuffer != TestConfig::COMMANDBUFFERTYPES_SECONDARY))
5581 const TestConfig testConfig (renderPass,
5591 testConfigExternal.allocationKind,
5592 testConfigExternal.groupParams);
5594 addFunctionCaseWithPrograms<TestConfig>(attachmentCountGroup.get(), testCaseName.c_str(), testCaseName.c_str(), createTestShaders, renderPassTest, testConfig);
5598 group->addChild(attachmentCountGroup.release());
5602 void addAttachmentWriteMaskTests (tcu::TestCaseGroup* group, const TestConfigExternal testConfigExternal)
5604 const deUint32 attachmentCounts[] = { 1, 2, 3, 4, 8 };
5606 const VkFormat attachmentFormats[] =
5608 VK_FORMAT_R8G8B8A8_UINT,
5609 VK_FORMAT_R8G8B8A8_UNORM,
5610 VK_FORMAT_R5G6B5_UNORM_PACK16,
5611 VK_FORMAT_R8G8_UNORM
5614 tcu::TestContext& testCtx = group->getTestContext();
5616 for (deUint32 attachmentCountNdx = 0; attachmentCountNdx < DE_LENGTH_OF_ARRAY(attachmentCounts); attachmentCountNdx++)
5618 const deUint32 attachmentCount = attachmentCounts[attachmentCountNdx];
5619 const string groupName = "attachment_count_" + de::toString(attachmentCount);
5621 de::MovePtr<tcu::TestCaseGroup> attachmentCountGroup(new tcu::TestCaseGroup(testCtx, groupName.c_str(), de::toString(attachmentCount).c_str()));
5623 for (deUint32 drawStartNdx = 0; drawStartNdx < (attachmentCount); drawStartNdx++)
5625 deUint32 formatNdx = 0;
5626 vector<Attachment> attachments;
5627 vector<AttachmentReference> colorAttachmentReferences;
5629 for (deUint32 attachmentNdx = 0; attachmentNdx < attachmentCount; attachmentNdx++)
5631 const VkFormat format = attachmentFormats[formatNdx];
5632 const VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_1_BIT;
5633 const VkAttachmentLoadOp loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
5634 const VkAttachmentStoreOp storeOp = VK_ATTACHMENT_STORE_OP_STORE;
5635 const VkAttachmentLoadOp stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
5636 const VkAttachmentStoreOp stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
5637 const VkImageLayout initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
5638 const VkImageLayout finalizeLayout = (testConfigExternal.groupParams->renderingType == RENDERING_TYPE_DYNAMIC_RENDERING)
5639 ? initialLayout : VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
5640 const VkImageLayout subpassLayout = VK_IMAGE_LAYOUT_GENERAL;
5642 attachments.push_back(Attachment(format, sampleCount, loadOp, storeOp, stencilLoadOp, stencilStoreOp, initialLayout, finalizeLayout));
5643 colorAttachmentReferences.push_back(AttachmentReference((deUint32)attachmentNdx, subpassLayout));
5645 if (++formatNdx == DE_LENGTH_OF_ARRAY(attachmentFormats))
5650 const VkImageLayout depthStencilLayout = VK_IMAGE_LAYOUT_GENERAL;
5651 const vector<Subpass> subpass (1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u, vector<AttachmentReference>(), colorAttachmentReferences, vector<AttachmentReference>(), AttachmentReference(VK_ATTACHMENT_UNUSED, depthStencilLayout), vector<deUint32>()));
5652 const vector<SubpassDependency> deps;
5654 const string testCaseName = "start_index_" + de::toString(drawStartNdx);
5655 const RenderPass renderPass (attachments, subpass, deps);
5657 const TestConfig::RenderTypes render = TestConfig::RENDERTYPES_DRAW;
5658 const TestConfig::CommandBufferTypes commandBuffer = TestConfig::COMMANDBUFFERTYPES_INLINE;
5659 const TestConfig::ImageMemory imageMemory = TestConfig::IMAGEMEMORY_LAZY;
5660 const UVec2 targetSize = UVec2(64, 64);
5661 const UVec2 renderPos = UVec2(0, 0);
5662 const UVec2 renderSize = UVec2(64, 64);
5663 const deBool useFormatCompCount = DE_TRUE;
5664 const vector<DeviceCoreFeature> requiredFeatures = {DEVICE_CORE_FEATURE_INDEPENDENT_BLEND};
5665 const TestConfig testConfig (renderPass,
5675 testConfigExternal.allocationKind,
5676 testConfigExternal.groupParams,
5679 addFunctionCaseWithPrograms<TestConfig>(attachmentCountGroup.get(), testCaseName.c_str(), testCaseName.c_str(), checkSupport, createTestShaders, renderPassTest, testConfig);
5683 group->addChild(attachmentCountGroup.release());
5687 template<typename T>
5688 T chooseRandom (de::Random& rng, const set<T>& values)
5690 size_t ndx = ((size_t)rng.getUint32()) % values.size();
5691 typename set<T>::const_iterator iter = values.begin();
5693 for (; ndx > 0; ndx--)
5699 void addAttachmentAllocationTests (tcu::TestCaseGroup* group, const TestConfigExternal testConfigExternal)
5701 const deUint32 attachmentCounts[] = { 4, 8 };
5702 const VkAttachmentLoadOp loadOps[] =
5704 VK_ATTACHMENT_LOAD_OP_LOAD,
5705 VK_ATTACHMENT_LOAD_OP_CLEAR,
5706 VK_ATTACHMENT_LOAD_OP_DONT_CARE
5709 const VkAttachmentStoreOp storeOps[] =
5711 VK_ATTACHMENT_STORE_OP_STORE,
5712 VK_ATTACHMENT_STORE_OP_DONT_CARE
5715 const VkImageLayout initialAndFinalColorLayouts[] =
5717 VK_IMAGE_LAYOUT_GENERAL,
5718 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
5719 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
5720 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
5721 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
5724 const VkImageLayout initialAndFinalDepthStencilLayouts[] =
5726 VK_IMAGE_LAYOUT_GENERAL,
5727 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
5728 VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL,
5729 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
5730 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
5731 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
5734 const VkImageLayout subpassLayoutsColor[] =
5736 VK_IMAGE_LAYOUT_GENERAL,
5737 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
5740 const VkImageLayout subpassLayoutsDepthStencil[] =
5742 VK_IMAGE_LAYOUT_GENERAL,
5743 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL
5746 const VkImageLayout subpassLayoutsInput[] =
5748 VK_IMAGE_LAYOUT_GENERAL,
5749 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
5754 // Each pass uses one more attachmen than previous one
5755 ALLOCATIONTYPE_GROW,
5756 // Each pass uses one less attachment than previous one
5757 ALLOCATIONTYPE_SHRINK,
5758 // Each pass drops one attachment and picks up new one
5759 ALLOCATIONTYPE_ROLL,
5760 // Start by growing and end by shrinking
5761 ALLOCATIONTYPE_GROW_SHRINK,
5762 // Each subpass has single input and single output attachment
5763 ALLOCATIONTYPE_IO_CHAIN,
5764 // Each subpass has multiple inputs and multiple outputs attachment
5765 ALLOCATIONTYPE_IO_GENERIC
5768 const AllocationType allocationTypes[] =
5770 ALLOCATIONTYPE_GROW,
5771 ALLOCATIONTYPE_SHRINK,
5772 ALLOCATIONTYPE_ROLL,
5773 ALLOCATIONTYPE_GROW_SHRINK,
5774 ALLOCATIONTYPE_IO_CHAIN,
5775 ALLOCATIONTYPE_IO_GENERIC
5778 const char* const allocationTypeStr[] =
5784 "input_output_chain",
5788 const TestConfig::RenderTypes renderCommands[] =
5790 TestConfig::RENDERTYPES_NONE,
5791 TestConfig::RENDERTYPES_CLEAR,
5792 TestConfig::RENDERTYPES_DRAW,
5793 TestConfig::RENDERTYPES_CLEAR|TestConfig::RENDERTYPES_DRAW,
5796 const TestConfig::CommandBufferTypes commandBuffers[] =
5798 TestConfig::COMMANDBUFFERTYPES_INLINE,
5799 TestConfig::COMMANDBUFFERTYPES_SECONDARY,
5800 TestConfig::COMMANDBUFFERTYPES_INLINE|TestConfig::COMMANDBUFFERTYPES_SECONDARY
5803 const TestConfig::ImageMemory imageMemories[] =
5805 TestConfig::IMAGEMEMORY_STRICT,
5806 TestConfig::IMAGEMEMORY_LAZY,
5807 TestConfig::IMAGEMEMORY_STRICT|TestConfig::IMAGEMEMORY_LAZY
5810 const UVec2 targetSizes[] =
5816 const UVec2 renderPositions[] =
5822 const UVec2 renderSizes[] =
5828 tcu::TestContext& testCtx = group->getTestContext();
5829 de::Random rng (3700649827u);
5831 for (size_t allocationTypeNdx = 0; allocationTypeNdx < DE_LENGTH_OF_ARRAY(allocationTypes); allocationTypeNdx++)
5833 const AllocationType allocationType = allocationTypes[allocationTypeNdx];
5834 const size_t testCaseCount = 100;
5835 de::MovePtr<tcu::TestCaseGroup> allocationTypeGroup (new tcu::TestCaseGroup(testCtx, allocationTypeStr[allocationTypeNdx], allocationTypeStr[allocationTypeNdx]));
5837 for (size_t testCaseNdx = 0; testCaseNdx < testCaseCount; testCaseNdx++)
5839 if (allocationType == ALLOCATIONTYPE_IO_GENERIC)
5841 const deUint32 attachmentCount = 4u + rng.getUint32() % 31u;
5842 const deUint32 subpassCount = 4u + rng.getUint32() % 31u;
5843 vector<Attachment> attachments;
5845 set<deUint32> definedAttachments;
5847 vector<Subpass> subpasses;
5848 set<deUint32> colorAttachments;
5849 set<deUint32> depthStencilAttachments;
5851 for (deUint32 attachmentIndex = 0; attachmentIndex < attachmentCount; attachmentIndex++)
5853 const bool isDepthStencilAttachment = rng.getFloat() < 0.01f;
5854 const VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_1_BIT;
5855 const VkAttachmentLoadOp loadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
5856 const VkAttachmentStoreOp storeOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
5858 const VkImageLayout initialLayout = isDepthStencilAttachment
5859 ? rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalDepthStencilLayouts), DE_ARRAY_END(initialAndFinalDepthStencilLayouts))
5860 : rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalColorLayouts), DE_ARRAY_END(initialAndFinalColorLayouts));
5861 const VkImageLayout finalizeLayout = isDepthStencilAttachment
5862 ? rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalDepthStencilLayouts), DE_ARRAY_END(initialAndFinalDepthStencilLayouts))
5863 : rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalColorLayouts), DE_ARRAY_END(initialAndFinalColorLayouts));
5865 const VkAttachmentLoadOp stencilLoadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
5866 const VkAttachmentStoreOp stencilStoreOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
5868 if (isDepthStencilAttachment)
5870 const VkFormat format = rng.choose<VkFormat>(DE_ARRAY_BEGIN(s_coreDepthStencilFormats), DE_ARRAY_END(s_coreDepthStencilFormats));
5872 if (loadOp == VK_ATTACHMENT_LOAD_OP_LOAD || loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR
5873 || stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD || stencilLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR)
5874 definedAttachments.insert(attachmentIndex);
5876 depthStencilAttachments.insert(attachmentIndex);
5878 attachments.push_back(Attachment(format, sampleCount, loadOp, storeOp, stencilLoadOp, stencilStoreOp, initialLayout, finalizeLayout));
5882 const VkFormat format = rng.choose<VkFormat>(DE_ARRAY_BEGIN(s_coreColorFormats), DE_ARRAY_END(s_coreColorFormats));
5884 if (loadOp == VK_ATTACHMENT_LOAD_OP_LOAD || loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR)
5885 definedAttachments.insert(attachmentIndex);
5887 colorAttachments.insert(attachmentIndex);
5889 attachments.push_back(Attachment(format, sampleCount, loadOp, storeOp, stencilLoadOp, stencilStoreOp, initialLayout, finalizeLayout));
5892 vector<Maybe<deUint32> > lastUseOfAttachment (attachments.size(), tcu::Nothing);
5893 vector<SubpassDependency> deps;
5895 for (deUint32 subpassIndex = 0; subpassIndex < subpassCount; subpassIndex++)
5897 const deUint32 colorAttachmentCount = depthStencilAttachments.empty()
5898 ? 1 + rng.getUint32() % de::min(4u, (deUint32)colorAttachments.size())
5899 : rng.getUint32() % (de::min(4u, (deUint32)colorAttachments.size()) + 1u);
5900 const deUint32 inputAttachmentCount = rng.getUint32() % (deUint32)(de::min<size_t>(4, definedAttachments.size()) + 1);
5901 const bool useDepthStencilAttachment = !depthStencilAttachments.empty() && (colorAttachmentCount == 0 || rng.getBool());
5902 std::vector<deUint32> subpassColorAttachments (colorAttachmentCount);
5903 std::vector<deUint32> subpassInputAttachments (inputAttachmentCount);
5904 Maybe<deUint32> depthStencilAttachment (useDepthStencilAttachment
5905 ? just(chooseRandom(rng, depthStencilAttachments))
5907 std::vector<deUint32> subpassPreserveAttachments;
5909 rng.choose(colorAttachments.begin(), colorAttachments.end(), subpassColorAttachments.begin(), colorAttachmentCount);
5910 rng.choose(definedAttachments.begin(), definedAttachments.end(), subpassInputAttachments.begin(), inputAttachmentCount);
5912 for (size_t colorAttachmentNdx = 0; colorAttachmentNdx < subpassColorAttachments.size(); colorAttachmentNdx++)
5913 definedAttachments.insert(subpassColorAttachments[colorAttachmentNdx]);
5915 if (depthStencilAttachment)
5916 definedAttachments.insert(*depthStencilAttachment);
5919 std::vector<AttachmentReference> inputAttachmentReferences;
5920 std::vector<AttachmentReference> colorAttachmentReferences;
5921 AttachmentReference depthStencilAttachmentReference (VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL);
5923 for (size_t colorAttachmentNdx = 0; colorAttachmentNdx < subpassColorAttachments.size(); colorAttachmentNdx++)
5925 const deUint32 colorAttachmentIndex = subpassColorAttachments[colorAttachmentNdx];
5927 if (lastUseOfAttachment[colorAttachmentIndex])
5929 deBool foundDuplicate = false;
5931 const deUint32 srcPass = *lastUseOfAttachment[colorAttachmentIndex];
5932 const deUint32 dstPass = subpassIndex;
5933 const VkDependencyFlags dependencyFlags = rng.getBool() ? (VkDependencyFlags) VK_DEPENDENCY_BY_REGION_BIT : 0u;
5935 const SubpassDependency newDependency(srcPass, dstPass,
5936 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
5937 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
5938 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
5939 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
5941 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
5942 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
5943 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
5944 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
5946 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
5947 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT,
5951 for (SubpassDependency& dependency : deps)
5953 if (dependency.getSrcPass() == srcPass && dependency.getDstPass() == dstPass)
5955 const VkAccessFlags newDstFlags = dependency.getDstAccessMask() | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT;
5956 dependency.setDstAccessMask(newDstFlags);
5957 foundDuplicate = true;
5962 if (!foundDuplicate)
5964 deps.push_back(newDependency);
5968 lastUseOfAttachment[colorAttachmentIndex] = just(subpassIndex);
5970 colorAttachmentReferences.push_back(AttachmentReference((deUint32)subpassColorAttachments[colorAttachmentNdx], VK_IMAGE_LAYOUT_GENERAL));
5973 for (size_t inputAttachmentNdx = 0; inputAttachmentNdx < subpassInputAttachments.size(); inputAttachmentNdx++)
5975 const deUint32 inputAttachmentIndex = subpassInputAttachments[inputAttachmentNdx];
5977 if(lastUseOfAttachment[inputAttachmentIndex])
5979 deBool foundDuplicate = false;
5981 const deUint32 srcPass = *lastUseOfAttachment[inputAttachmentIndex];
5982 const deUint32 dstPass = subpassIndex;
5983 const VkDependencyFlags dependencyFlags = ((srcPass == subpassIndex) || rng.getBool()) ? (VkDependencyFlags)VK_DEPENDENCY_BY_REGION_BIT : 0u;
5985 const SubpassDependency newDependency(srcPass, dstPass,
5986 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
5987 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
5988 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
5989 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
5991 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
5992 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
5993 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
5994 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
5996 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
5997 VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
6000 for (SubpassDependency& dependency : deps)
6002 if (dependency.getSrcPass() == srcPass && dependency.getDstPass() == dstPass)
6004 const VkAccessFlags newSrcFlags = dependency.getSrcAccessMask() | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
6005 const VkAccessFlags newDstFlags = dependency.getDstAccessMask() | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT;
6006 dependency.setDstAccessMask(newSrcFlags);
6007 dependency.setDstAccessMask(newDstFlags);
6008 foundDuplicate = true;
6013 if (!foundDuplicate)
6015 deps.push_back(newDependency);
6018 lastUseOfAttachment[inputAttachmentIndex] = just(subpassIndex);
6020 VkImageAspectFlags aspect = 0u;
6021 if (testConfigExternal.groupParams->renderingType == RENDERING_TYPE_RENDERPASS2)
6023 bool col = colorAttachments.find(inputAttachmentIndex) != colorAttachments.end();
6024 aspect = col ? VK_IMAGE_ASPECT_COLOR_BIT : VK_IMAGE_ASPECT_DEPTH_BIT;
6026 inputAttachmentReferences.push_back(AttachmentReference((deUint32)subpassInputAttachments[inputAttachmentNdx], VK_IMAGE_LAYOUT_GENERAL, aspect));
6030 if (depthStencilAttachment)
6032 if (lastUseOfAttachment[*depthStencilAttachment])
6034 deBool foundDuplicate = false;
6036 const deUint32 srcPass = *lastUseOfAttachment[*depthStencilAttachment];
6037 const deUint32 dstPass = subpassIndex;
6038 const VkDependencyFlags dependencyFlags = ((srcPass == subpassIndex) || rng.getBool()) ? (VkDependencyFlags)VK_DEPENDENCY_BY_REGION_BIT : 0u;
6040 const SubpassDependency newDependency(srcPass, dstPass,
6041 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
6042 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
6043 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
6044 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
6046 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
6047 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
6048 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
6049 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
6051 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
6052 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT
6053 | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
6056 for (SubpassDependency& dependency : deps)
6058 if (dependency.getSrcPass() == srcPass && dependency.getDstPass() == dstPass)
6060 const VkAccessFlags newSrcFlags = dependency.getSrcAccessMask() | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
6061 const VkAccessFlags newDstFlags = dependency.getDstAccessMask() | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT;
6062 dependency.setDstAccessMask(newSrcFlags);
6063 dependency.setDstAccessMask(newDstFlags);
6064 foundDuplicate = true;
6069 if (!foundDuplicate)
6071 deps.push_back(newDependency);
6075 lastUseOfAttachment[*depthStencilAttachment] = just(subpassIndex);
6077 depthStencilAttachmentReference = AttachmentReference(*depthStencilAttachment, VK_IMAGE_LAYOUT_GENERAL);
6080 depthStencilAttachmentReference = AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL);
6082 vector<deUint32> preserveAttachments;
6083 for (deUint32 attachmentIndex = 0; attachmentIndex < (deUint32)attachments.size(); attachmentIndex++)
6085 if (lastUseOfAttachment[attachmentIndex] && (*lastUseOfAttachment[attachmentIndex]) != subpassIndex)
6086 preserveAttachments.push_back(attachmentIndex);
6089 // Use random image layout when possible
6090 for (size_t colorRefIdx = 0; colorRefIdx < colorAttachmentReferences.size(); ++colorRefIdx)
6092 bool usedAsInput = false;
6093 for (size_t inputRefIdx = 0; inputRefIdx < inputAttachmentReferences.size(); ++inputRefIdx)
6094 if (colorAttachmentReferences[colorRefIdx].getAttachment() == inputAttachmentReferences[inputRefIdx].getAttachment())
6098 colorAttachmentReferences[colorRefIdx].setImageLayout(rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayoutsColor), DE_ARRAY_END(subpassLayoutsColor)));
6100 for (size_t inputRefIdx = 0; inputRefIdx < inputAttachmentReferences.size(); ++inputRefIdx)
6102 bool usedAsDepthStencil = inputAttachmentReferences[inputRefIdx].getAttachment() == depthStencilAttachmentReference.getAttachment();
6103 bool usedAsColor = false;
6104 for (size_t colorRefIdx = 0; colorRefIdx < colorAttachmentReferences.size(); ++colorRefIdx)
6105 if (inputAttachmentReferences[inputRefIdx].getAttachment() == colorAttachmentReferences[colorRefIdx].getAttachment())
6108 if (!usedAsColor && !usedAsDepthStencil)
6109 inputAttachmentReferences[inputRefIdx].setImageLayout(rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayoutsInput), DE_ARRAY_END(subpassLayoutsInput)));
6112 bool usedAsInput = false;
6113 for (size_t inputRefIdx = 0; inputRefIdx < inputAttachmentReferences.size(); ++inputRefIdx)
6114 if (depthStencilAttachmentReference.getAttachment() == inputAttachmentReferences[inputRefIdx].getAttachment())
6118 depthStencilAttachmentReference.setImageLayout(rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayoutsDepthStencil), DE_ARRAY_END(subpassLayoutsDepthStencil)));
6121 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
6122 inputAttachmentReferences,
6123 colorAttachmentReferences,
6124 vector<AttachmentReference>(),
6125 depthStencilAttachmentReference,
6126 preserveAttachments));
6130 const TestConfig::RenderTypes render = rng.choose<TestConfig::RenderTypes>(DE_ARRAY_BEGIN(renderCommands), DE_ARRAY_END(renderCommands));
6131 const TestConfig::CommandBufferTypes commandBuffer = rng.choose<TestConfig::CommandBufferTypes>(DE_ARRAY_BEGIN(commandBuffers), DE_ARRAY_END(commandBuffers));
6132 const TestConfig::ImageMemory imageMemory = rng.choose<TestConfig::ImageMemory>(DE_ARRAY_BEGIN(imageMemories), DE_ARRAY_END(imageMemories));
6134 const string testCaseName = de::toString(testCaseNdx);
6135 const UVec2 targetSize = rng.choose<UVec2>(DE_ARRAY_BEGIN(targetSizes), DE_ARRAY_END(targetSizes));
6136 const UVec2 renderPos = rng.choose<UVec2>(DE_ARRAY_BEGIN(renderPositions), DE_ARRAY_END(renderPositions));
6137 const UVec2 renderSize = rng.choose<UVec2>(DE_ARRAY_BEGIN(renderSizes), DE_ARRAY_END(renderSizes));
6139 const RenderPass renderPass (attachments, subpasses, deps);
6140 const TestConfig testConfig (renderPass,
6150 testConfigExternal.allocationKind,
6151 testConfigExternal.groupParams);
6153 addFunctionCaseWithPrograms<TestConfig>(allocationTypeGroup.get(), testCaseName.c_str(), testCaseName.c_str(), createTestShaders, renderPassTest, testConfig);
6158 const deUint32 attachmentCount = rng.choose<deUint32>(DE_ARRAY_BEGIN(attachmentCounts), DE_ARRAY_END(attachmentCounts));
6159 vector<Attachment> attachments;
6160 vector<Subpass> subpasses;
6162 for (size_t attachmentNdx = 0; attachmentNdx < attachmentCount; attachmentNdx++)
6164 const VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_1_BIT;
6165 const VkFormat format = rng.choose<VkFormat>(DE_ARRAY_BEGIN(s_coreColorFormats), DE_ARRAY_END(s_coreColorFormats));
6166 const VkAttachmentLoadOp loadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
6167 const VkAttachmentStoreOp storeOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
6169 const VkImageLayout initialLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalColorLayouts), DE_ARRAY_END(initialAndFinalColorLayouts));
6170 const VkImageLayout finalizeLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalColorLayouts), DE_ARRAY_END(initialAndFinalColorLayouts));
6172 const VkAttachmentLoadOp stencilLoadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
6173 const VkAttachmentStoreOp stencilStoreOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
6175 attachments.push_back(Attachment(format, sampleCount, loadOp, storeOp, stencilLoadOp, stencilStoreOp, initialLayout, finalizeLayout));
6178 if (allocationType == ALLOCATIONTYPE_GROW)
6180 for (size_t subpassNdx = 0; subpassNdx < attachmentCount; subpassNdx++)
6182 vector<AttachmentReference> colorAttachmentReferences;
6184 for (size_t attachmentNdx = 0; attachmentNdx < subpassNdx + 1; attachmentNdx++)
6186 const VkImageLayout subpassLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayoutsColor), DE_ARRAY_END(subpassLayoutsColor));
6188 colorAttachmentReferences.push_back(AttachmentReference((deUint32)attachmentNdx, subpassLayout));
6191 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
6192 vector<AttachmentReference>(),
6193 colorAttachmentReferences,
6194 vector<AttachmentReference>(),
6195 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6196 vector<deUint32>()));
6199 else if (allocationType == ALLOCATIONTYPE_SHRINK)
6201 for (size_t subpassNdx = 0; subpassNdx < attachmentCount; subpassNdx++)
6203 vector<AttachmentReference> colorAttachmentReferences;
6205 for (size_t attachmentNdx = 0; attachmentNdx < (attachmentCount - subpassNdx); attachmentNdx++)
6207 const VkImageLayout subpassLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayoutsColor), DE_ARRAY_END(subpassLayoutsColor));
6209 colorAttachmentReferences.push_back(AttachmentReference((deUint32)attachmentNdx, subpassLayout));
6212 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
6213 vector<AttachmentReference>(),
6214 colorAttachmentReferences,
6215 vector<AttachmentReference>(),
6216 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6217 vector<deUint32>()));
6220 else if (allocationType == ALLOCATIONTYPE_ROLL)
6222 for (size_t subpassNdx = 0; subpassNdx < attachmentCount / 2; subpassNdx++)
6224 vector<AttachmentReference> colorAttachmentReferences;
6226 for (size_t attachmentNdx = 0; attachmentNdx < attachmentCount / 2; attachmentNdx++)
6228 const VkImageLayout subpassLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayoutsColor), DE_ARRAY_END(subpassLayoutsColor));
6230 colorAttachmentReferences.push_back(AttachmentReference((deUint32)(subpassNdx + attachmentNdx), subpassLayout));
6233 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
6234 vector<AttachmentReference>(),
6235 colorAttachmentReferences,
6236 vector<AttachmentReference>(),
6237 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6238 vector<deUint32>()));
6241 else if (allocationType == ALLOCATIONTYPE_GROW_SHRINK)
6243 for (size_t subpassNdx = 0; subpassNdx < attachmentCount; subpassNdx++)
6245 vector<AttachmentReference> colorAttachmentReferences;
6247 for (size_t attachmentNdx = 0; attachmentNdx < subpassNdx + 1; attachmentNdx++)
6249 const VkImageLayout subpassLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayoutsColor), DE_ARRAY_END(subpassLayoutsColor));
6251 colorAttachmentReferences.push_back(AttachmentReference((deUint32)attachmentNdx, subpassLayout));
6254 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
6255 vector<AttachmentReference>(),
6256 colorAttachmentReferences,
6257 vector<AttachmentReference>(),
6258 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6259 vector<deUint32>()));
6261 for (size_t subpassNdx = 0; subpassNdx < attachmentCount; subpassNdx++)
6263 vector<AttachmentReference> colorAttachmentReferences;
6265 for (size_t attachmentNdx = 0; attachmentNdx < (attachmentCount - subpassNdx); attachmentNdx++)
6267 const VkImageLayout subpassLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayoutsColor), DE_ARRAY_END(subpassLayoutsColor));
6269 colorAttachmentReferences.push_back(AttachmentReference((deUint32)attachmentNdx, subpassLayout));
6272 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
6273 vector<AttachmentReference>(),
6274 colorAttachmentReferences,
6275 vector<AttachmentReference>(),
6276 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6277 vector<deUint32>()));
6280 else if (allocationType == ALLOCATIONTYPE_IO_CHAIN)
6282 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
6283 vector<AttachmentReference>(),
6284 vector<AttachmentReference>(1, AttachmentReference(0, rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayoutsColor), DE_ARRAY_END(subpassLayoutsColor)))),
6285 vector<AttachmentReference>(),
6286 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6287 vector<deUint32>()));
6289 for (size_t subpassNdx = 1; subpassNdx < attachmentCount; subpassNdx++)
6291 const VkImageAspectFlags inputAttachmentAspectMask = (testConfigExternal.groupParams->renderingType == RENDERING_TYPE_RENDERPASS2) ? VK_IMAGE_ASPECT_COLOR_BIT : static_cast<VkImageAspectFlagBits>(0);
6292 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
6293 vector<AttachmentReference>(1, AttachmentReference((deUint32)(subpassNdx - 1), VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, inputAttachmentAspectMask)),
6294 vector<AttachmentReference>(1, AttachmentReference((deUint32)(subpassNdx), rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayoutsColor), DE_ARRAY_END(subpassLayoutsColor)))),
6295 vector<AttachmentReference>(),
6296 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6297 vector<deUint32>()));
6301 DE_FATAL("Unknown allocation type");
6304 const TestConfig::RenderTypes render = rng.choose<TestConfig::RenderTypes>(DE_ARRAY_BEGIN(renderCommands), DE_ARRAY_END(renderCommands));
6305 const TestConfig::CommandBufferTypes commandBuffer = rng.choose<TestConfig::CommandBufferTypes>(DE_ARRAY_BEGIN(commandBuffers), DE_ARRAY_END(commandBuffers));
6306 const TestConfig::ImageMemory imageMemory = rng.choose<TestConfig::ImageMemory>(DE_ARRAY_BEGIN(imageMemories), DE_ARRAY_END(imageMemories));
6308 const string testCaseName = de::toString(testCaseNdx);
6309 const UVec2 targetSize = rng.choose<UVec2>(DE_ARRAY_BEGIN(targetSizes), DE_ARRAY_END(targetSizes));
6310 const UVec2 renderPos = rng.choose<UVec2>(DE_ARRAY_BEGIN(renderPositions), DE_ARRAY_END(renderPositions));
6311 const UVec2 renderSize = rng.choose<UVec2>(DE_ARRAY_BEGIN(renderSizes), DE_ARRAY_END(renderSizes));
6313 vector<SubpassDependency> deps;
6315 for (size_t subpassNdx = 0; subpassNdx < subpasses.size() - 1; subpassNdx++)
6317 const bool byRegion = rng.getBool();
6318 deps.push_back(SubpassDependency((deUint32)subpassNdx, (deUint32)subpassNdx + 1,
6319 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
6320 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
6321 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
6322 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
6324 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
6325 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
6326 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
6327 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
6329 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
6330 (VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT),
6332 byRegion ? (VkDependencyFlags)VK_DEPENDENCY_BY_REGION_BIT : 0u));
6335 const RenderPass renderPass (attachments, subpasses, deps);
6336 const TestConfig testConfig (renderPass,
6346 testConfigExternal.allocationKind,
6347 testConfigExternal.groupParams);
6349 addFunctionCaseWithPrograms<TestConfig>(allocationTypeGroup.get(), testCaseName.c_str(), testCaseName.c_str(), createTestShaders, renderPassTest, testConfig);
6353 group->addChild(allocationTypeGroup.release());
6357 void addSimpleTests (tcu::TestCaseGroup* group, const TestConfigExternal testConfigExternal)
6359 const UVec2 targetSize (64, 64);
6360 const UVec2 renderPos (0, 0);
6361 const UVec2 renderSize (64, 64);
6365 const RenderPass renderPass (vector<Attachment>(1, Attachment(VK_FORMAT_R8G8B8A8_UNORM,
6366 VK_SAMPLE_COUNT_1_BIT,
6367 VK_ATTACHMENT_LOAD_OP_CLEAR,
6368 VK_ATTACHMENT_STORE_OP_STORE,
6369 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6370 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6371 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
6372 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6373 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6375 vector<AttachmentReference>(),
6376 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6377 vector<AttachmentReference>(),
6378 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6379 vector<deUint32>())),
6380 vector<SubpassDependency>());
6381 const TestConfig testConfig (renderPass,
6382 TestConfig::RENDERTYPES_DRAW,
6383 TestConfig::COMMANDBUFFERTYPES_INLINE,
6384 TestConfig::IMAGEMEMORY_STRICT,
6391 testConfigExternal.allocationKind,
6392 testConfigExternal.groupParams);
6394 addFunctionCaseWithPrograms<TestConfig>(group, "color", "Single color attachment case.", createTestShaders, renderPassTest, testConfig);
6399 const RenderPass renderPass (vector<Attachment>(1, Attachment(VK_FORMAT_X8_D24_UNORM_PACK32,
6400 VK_SAMPLE_COUNT_1_BIT,
6401 VK_ATTACHMENT_LOAD_OP_CLEAR,
6402 VK_ATTACHMENT_STORE_OP_STORE,
6403 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6404 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6405 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
6406 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)),
6407 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6409 vector<AttachmentReference>(),
6410 vector<AttachmentReference>(),
6411 vector<AttachmentReference>(),
6412 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
6413 vector<deUint32>())),
6414 vector<SubpassDependency>());
6415 const TestConfig testConfig (renderPass,
6416 TestConfig::RENDERTYPES_DRAW,
6417 TestConfig::COMMANDBUFFERTYPES_INLINE,
6418 TestConfig::IMAGEMEMORY_STRICT,
6425 testConfigExternal.allocationKind,
6426 testConfigExternal.groupParams);
6428 addFunctionCaseWithPrograms<TestConfig>(group, "depth", "Single depth attachment case.", createTestShaders, renderPassTest, testConfig);
6433 const RenderPass renderPass (vector<Attachment>(1, Attachment(VK_FORMAT_S8_UINT,
6434 VK_SAMPLE_COUNT_1_BIT,
6435 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6436 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6437 VK_ATTACHMENT_LOAD_OP_CLEAR,
6438 VK_ATTACHMENT_STORE_OP_STORE,
6439 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
6440 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)),
6441 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6443 vector<AttachmentReference>(),
6444 vector<AttachmentReference>(),
6445 vector<AttachmentReference>(),
6446 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
6447 vector<deUint32>())),
6448 vector<SubpassDependency>());
6449 const TestConfig testConfig (renderPass,
6450 TestConfig::RENDERTYPES_DRAW,
6451 TestConfig::COMMANDBUFFERTYPES_INLINE,
6452 TestConfig::IMAGEMEMORY_STRICT,
6459 testConfigExternal.allocationKind,
6460 testConfigExternal.groupParams);
6462 addFunctionCaseWithPrograms<TestConfig>(group, "stencil", "Single stencil attachment case.", createTestShaders, renderPassTest, testConfig);
6467 const RenderPass renderPass (vector<Attachment>(1, Attachment(VK_FORMAT_D24_UNORM_S8_UINT,
6468 VK_SAMPLE_COUNT_1_BIT,
6469 VK_ATTACHMENT_LOAD_OP_CLEAR,
6470 VK_ATTACHMENT_STORE_OP_STORE,
6471 VK_ATTACHMENT_LOAD_OP_CLEAR,
6472 VK_ATTACHMENT_STORE_OP_STORE,
6473 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
6474 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)),
6475 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6477 vector<AttachmentReference>(),
6478 vector<AttachmentReference>(),
6479 vector<AttachmentReference>(),
6480 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
6481 vector<deUint32>())),
6482 vector<SubpassDependency>());
6483 const TestConfig testConfig (renderPass,
6484 TestConfig::RENDERTYPES_DRAW,
6485 TestConfig::COMMANDBUFFERTYPES_INLINE,
6486 TestConfig::IMAGEMEMORY_STRICT,
6493 testConfigExternal.allocationKind,
6494 testConfigExternal.groupParams);
6496 addFunctionCaseWithPrograms<TestConfig>(group, "depth_stencil", "Single depth stencil attachment case.", createTestShaders, renderPassTest, testConfig);
6501 const Attachment attachments[] =
6503 Attachment(VK_FORMAT_R8G8B8A8_UNORM,
6504 VK_SAMPLE_COUNT_1_BIT,
6505 VK_ATTACHMENT_LOAD_OP_CLEAR,
6506 VK_ATTACHMENT_STORE_OP_STORE,
6507 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6508 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6509 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
6510 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL),
6511 Attachment(VK_FORMAT_X8_D24_UNORM_PACK32,
6512 VK_SAMPLE_COUNT_1_BIT,
6513 VK_ATTACHMENT_LOAD_OP_CLEAR,
6514 VK_ATTACHMENT_STORE_OP_STORE,
6515 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6516 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6517 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
6518 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
6521 const RenderPass renderPass (vector<Attachment>(DE_ARRAY_BEGIN(attachments), DE_ARRAY_END(attachments)),
6522 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6524 vector<AttachmentReference>(),
6525 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6526 vector<AttachmentReference>(),
6527 AttachmentReference(1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
6528 vector<deUint32>())),
6529 vector<SubpassDependency>());
6530 const TestConfig testConfig (renderPass,
6531 TestConfig::RENDERTYPES_DRAW,
6532 TestConfig::COMMANDBUFFERTYPES_INLINE,
6533 TestConfig::IMAGEMEMORY_STRICT,
6540 testConfigExternal.allocationKind,
6541 testConfigExternal.groupParams);
6543 addFunctionCaseWithPrograms<TestConfig>(group, "color_depth", "Color and depth attachment case.", createTestShaders, renderPassTest, testConfig);
6548 const Attachment attachments[] =
6550 Attachment(VK_FORMAT_R8G8B8A8_UNORM,
6551 VK_SAMPLE_COUNT_1_BIT,
6552 VK_ATTACHMENT_LOAD_OP_CLEAR,
6553 VK_ATTACHMENT_STORE_OP_STORE,
6554 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6555 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6556 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
6557 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL),
6558 Attachment(VK_FORMAT_S8_UINT,
6559 VK_SAMPLE_COUNT_1_BIT,
6560 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6561 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6562 VK_ATTACHMENT_LOAD_OP_CLEAR,
6563 VK_ATTACHMENT_STORE_OP_STORE,
6564 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
6565 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
6568 const RenderPass renderPass (vector<Attachment>(DE_ARRAY_BEGIN(attachments), DE_ARRAY_END(attachments)),
6569 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6571 vector<AttachmentReference>(),
6572 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6573 vector<AttachmentReference>(),
6574 AttachmentReference(1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
6575 vector<deUint32>())),
6576 vector<SubpassDependency>());
6577 const TestConfig testConfig (renderPass,
6578 TestConfig::RENDERTYPES_DRAW,
6579 TestConfig::COMMANDBUFFERTYPES_INLINE,
6580 TestConfig::IMAGEMEMORY_STRICT,
6587 testConfigExternal.allocationKind,
6588 testConfigExternal.groupParams);
6590 addFunctionCaseWithPrograms<TestConfig>(group, "color_stencil", "Color and stencil attachment case.", createTestShaders, renderPassTest, testConfig);
6593 // color_depth_stencil
6595 const Attachment attachments[] =
6597 Attachment(VK_FORMAT_R8G8B8A8_UNORM,
6598 VK_SAMPLE_COUNT_1_BIT,
6599 VK_ATTACHMENT_LOAD_OP_CLEAR,
6600 VK_ATTACHMENT_STORE_OP_STORE,
6601 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6602 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6603 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
6604 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL),
6605 Attachment(VK_FORMAT_D24_UNORM_S8_UINT,
6606 VK_SAMPLE_COUNT_1_BIT,
6607 VK_ATTACHMENT_LOAD_OP_CLEAR,
6608 VK_ATTACHMENT_STORE_OP_STORE,
6609 VK_ATTACHMENT_LOAD_OP_CLEAR,
6610 VK_ATTACHMENT_STORE_OP_STORE,
6611 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
6612 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
6615 const RenderPass renderPass (vector<Attachment>(DE_ARRAY_BEGIN(attachments), DE_ARRAY_END(attachments)),
6616 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6618 vector<AttachmentReference>(),
6619 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6620 vector<AttachmentReference>(),
6621 AttachmentReference(1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
6622 vector<deUint32>())),
6623 vector<SubpassDependency>());
6624 const TestConfig testConfig (renderPass,
6625 TestConfig::RENDERTYPES_DRAW,
6626 TestConfig::COMMANDBUFFERTYPES_INLINE,
6627 TestConfig::IMAGEMEMORY_STRICT,
6634 testConfigExternal.allocationKind,
6635 testConfigExternal.groupParams);
6637 addFunctionCaseWithPrograms<TestConfig>(group, "color_depth_stencil", "Color, depth and stencil attachment case.", createTestShaders, renderPassTest, testConfig);
6642 const RenderPass renderPass (vector<Attachment>(),
6643 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6645 vector<AttachmentReference>(),
6646 vector<AttachmentReference>(),
6647 vector<AttachmentReference>(),
6648 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6649 vector<deUint32>())),
6650 vector<SubpassDependency>());
6651 const TestConfig testConfig (renderPass,
6652 TestConfig::RENDERTYPES_DRAW,
6653 TestConfig::COMMANDBUFFERTYPES_INLINE,
6654 TestConfig::IMAGEMEMORY_STRICT,
6661 testConfigExternal.allocationKind,
6662 testConfigExternal.groupParams);
6664 addFunctionCaseWithPrograms<TestConfig>(group, "no_attachments", "No attachments case.", createTestShaders, renderPassTest, testConfig);
6667 // color_unused_omit_blend_state
6668 if (testConfigExternal.groupParams->renderingType != RENDERING_TYPE_DYNAMIC_RENDERING)
6670 vector<Subpass> subpasses;
6672 // First subpass: use color attachment, create pipeline with color blend state
6673 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6675 vector<AttachmentReference>(),
6676 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6677 vector<AttachmentReference>(),
6678 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6682 // Second subpass: don't use color attachment, create pipeline without color blend state
6683 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6685 vector<AttachmentReference>(),
6686 vector<AttachmentReference>(1, AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6687 vector<AttachmentReference>(),
6688 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6692 const RenderPass renderPass (vector<Attachment>(1, Attachment(VK_FORMAT_R8G8B8A8_UNORM,
6693 VK_SAMPLE_COUNT_1_BIT,
6694 VK_ATTACHMENT_LOAD_OP_CLEAR,
6695 VK_ATTACHMENT_STORE_OP_STORE,
6696 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6697 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6698 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
6699 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6701 vector<SubpassDependency>());
6703 const TestConfig testConfig (renderPass,
6704 TestConfig::RENDERTYPES_DRAW,
6705 TestConfig::COMMANDBUFFERTYPES_INLINE,
6706 TestConfig::IMAGEMEMORY_STRICT,
6713 testConfigExternal.allocationKind,
6714 testConfigExternal.groupParams);
6715 addFunctionCaseWithPrograms<TestConfig>(group, "color_unused_omit_blend_state", "Two unused color attachment case without blend state", createTestShaders, renderPassTest, testConfig);
6719 std::string formatToName (VkFormat format)
6721 const std::string formatStr = de::toString(format);
6722 const std::string prefix = "VK_FORMAT_";
6724 DE_ASSERT(formatStr.substr(0, prefix.length()) == prefix);
6726 return de::toLower(formatStr.substr(prefix.length()));
6729 void addFormatTests (tcu::TestCaseGroup* group, const TestConfigExternal testConfigExternal)
6731 tcu::TestContext& testCtx = group->getTestContext();
6733 const UVec2 targetSize (64, 64);
6734 const UVec2 renderPos (0, 0);
6735 const UVec2 renderSize (64, 64);
6739 const char* const str;
6740 const VkAttachmentStoreOp op;
6743 { "store", VK_ATTACHMENT_STORE_OP_STORE },
6744 { "dont_care", VK_ATTACHMENT_STORE_OP_DONT_CARE }
6749 const char* const str;
6750 const VkAttachmentLoadOp op;
6753 { "clear", VK_ATTACHMENT_LOAD_OP_CLEAR },
6754 { "load", VK_ATTACHMENT_LOAD_OP_LOAD },
6755 { "dont_care", VK_ATTACHMENT_LOAD_OP_DONT_CARE }
6760 const char* const str;
6761 const TestConfig::RenderTypes types;
6764 { "clear", TestConfig::RENDERTYPES_CLEAR },
6765 { "draw", TestConfig::RENDERTYPES_DRAW },
6766 { "clear_draw", TestConfig::RENDERTYPES_CLEAR|TestConfig::RENDERTYPES_DRAW }
6770 for (size_t formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(s_coreColorFormats); formatNdx++)
6772 const VkFormat format = s_coreColorFormats[formatNdx];
6773 de::MovePtr<tcu::TestCaseGroup> formatGroup (new tcu::TestCaseGroup(testCtx, formatToName(format).c_str(), de::toString(format).c_str()));
6775 for (size_t loadOpNdx = 0; loadOpNdx < DE_LENGTH_OF_ARRAY(loadOps); loadOpNdx++)
6777 const VkAttachmentLoadOp loadOp = loadOps[loadOpNdx].op;
6778 de::MovePtr<tcu::TestCaseGroup> loadOpGroup (new tcu::TestCaseGroup(testCtx, loadOps[loadOpNdx].str, loadOps[loadOpNdx].str));
6780 for (size_t renderTypeNdx = 0; renderTypeNdx < DE_LENGTH_OF_ARRAY(renderTypes); renderTypeNdx++)
6782 const RenderPass renderPass (vector<Attachment>(1, Attachment(format,
6783 VK_SAMPLE_COUNT_1_BIT,
6785 VK_ATTACHMENT_STORE_OP_STORE,
6786 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6787 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6788 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
6789 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6790 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6792 vector<AttachmentReference>(),
6793 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6794 vector<AttachmentReference>(),
6795 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6796 vector<deUint32>())),
6797 vector<SubpassDependency>());
6798 const TestConfig testConfig (renderPass,
6799 renderTypes[renderTypeNdx].types,
6800 TestConfig::COMMANDBUFFERTYPES_INLINE,
6801 TestConfig::IMAGEMEMORY_STRICT,
6808 testConfigExternal.allocationKind,
6809 testConfigExternal.groupParams);
6811 addFunctionCaseWithPrograms<TestConfig>(loadOpGroup.get(), renderTypes[renderTypeNdx].str, renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
6814 formatGroup->addChild(loadOpGroup.release());
6817 if (testConfigExternal.groupParams->renderingType != RENDERING_TYPE_DYNAMIC_RENDERING)
6819 de::MovePtr<tcu::TestCaseGroup> inputGroup (new tcu::TestCaseGroup(testCtx, "input", "Test attachment format as input"));
6821 for (size_t loadOpNdx = 0; loadOpNdx < DE_LENGTH_OF_ARRAY(loadOps); loadOpNdx++)
6823 const VkAttachmentLoadOp loadOp = loadOps[loadOpNdx].op;
6824 de::MovePtr<tcu::TestCaseGroup> loadOpGroup (new tcu::TestCaseGroup(testCtx, loadOps[loadOpNdx].str, loadOps[loadOpNdx].str));
6826 for (size_t storeOpNdx = 0; storeOpNdx < DE_LENGTH_OF_ARRAY(storeOps); storeOpNdx++)
6828 const VkImageAspectFlags inputAttachmentAspectMask = (testConfigExternal.groupParams->renderingType == RENDERING_TYPE_RENDERPASS2)
6829 ? static_cast<VkImageAspectFlags>(VK_IMAGE_ASPECT_COLOR_BIT)
6830 : static_cast<VkImageAspectFlags>(0);
6831 const VkAttachmentStoreOp storeOp = storeOps[storeOpNdx].op;
6832 de::MovePtr<tcu::TestCaseGroup> storeOpGroup (new tcu::TestCaseGroup(testCtx, storeOps[storeOpNdx].str, storeOps[storeOpNdx].str));
6834 for (size_t useInputAspectNdx = 0; useInputAspectNdx < 2; useInputAspectNdx++)
6836 const bool useInputAspect = useInputAspectNdx != 0;
6838 if (testConfigExternal.groupParams->renderingType == RENDERING_TYPE_RENDERPASS2 && useInputAspect)
6841 for (size_t renderTypeNdx = 0; renderTypeNdx < DE_LENGTH_OF_ARRAY(renderTypes); renderTypeNdx++)
6844 vector<Attachment> attachments;
6845 vector<Subpass> subpasses;
6846 vector<SubpassDependency> deps;
6847 vector<VkInputAttachmentAspectReference> inputAspects;
6849 attachments.push_back(Attachment(format,
6850 VK_SAMPLE_COUNT_1_BIT,
6853 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6854 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6855 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
6856 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
6858 attachments.push_back(Attachment(vk::VK_FORMAT_R8G8B8A8_UNORM,
6859 VK_SAMPLE_COUNT_1_BIT,
6860 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6861 VK_ATTACHMENT_STORE_OP_STORE,
6862 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6863 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6864 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
6865 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
6867 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6869 vector<AttachmentReference>(),
6870 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6871 vector<AttachmentReference>(),
6872 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6873 vector<deUint32>()));
6874 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6876 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, inputAttachmentAspectMask)),
6877 vector<AttachmentReference>(1, AttachmentReference(1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6878 vector<AttachmentReference>(),
6879 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6880 vector<deUint32>()));
6882 deps.push_back(SubpassDependency(0, 1,
6884 vk::VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
6885 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
6887 vk::VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
6888 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
6889 vk::VK_DEPENDENCY_BY_REGION_BIT));
6893 const VkInputAttachmentAspectReference inputAspect =
6897 VK_IMAGE_ASPECT_COLOR_BIT
6900 inputAspects.push_back(inputAspect);
6904 const RenderPass renderPass (attachments, subpasses, deps, inputAspects);
6905 const TestConfig testConfig (renderPass,
6906 renderTypes[renderTypeNdx].types,
6907 TestConfig::COMMANDBUFFERTYPES_INLINE,
6908 TestConfig::IMAGEMEMORY_STRICT,
6915 testConfigExternal.allocationKind,
6916 testConfigExternal.groupParams);
6917 const string testName (renderTypes[renderTypeNdx].str + string(useInputAspect ? "_use_input_aspect" : ""));
6919 addFunctionCaseWithPrograms<TestConfig>(storeOpGroup.get(), testName, renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
6923 vector<Attachment> attachments;
6924 vector<Subpass> subpasses;
6925 vector<SubpassDependency> deps;
6926 vector<VkInputAttachmentAspectReference> inputAspects;
6928 attachments.push_back(Attachment(format,
6929 VK_SAMPLE_COUNT_1_BIT,
6932 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
6933 VK_ATTACHMENT_STORE_OP_DONT_CARE,
6934 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
6935 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
6937 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6939 vector<AttachmentReference>(),
6940 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
6941 vector<AttachmentReference>(),
6942 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6943 vector<deUint32>()));
6944 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
6946 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_GENERAL, inputAttachmentAspectMask)),
6947 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_GENERAL)),
6948 vector<AttachmentReference>(),
6949 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
6950 vector<deUint32>()));
6952 deps.push_back(SubpassDependency(0, 1,
6953 vk::VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
6954 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
6956 vk::VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
6957 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
6958 vk::VK_DEPENDENCY_BY_REGION_BIT));
6960 deps.push_back(SubpassDependency(1, 1,
6961 vk::VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
6962 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
6964 vk::VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
6965 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
6966 vk::VK_DEPENDENCY_BY_REGION_BIT));
6970 const VkInputAttachmentAspectReference inputAspect =
6974 VK_IMAGE_ASPECT_COLOR_BIT
6977 inputAspects.push_back(inputAspect);
6981 const RenderPass renderPass (attachments, subpasses, deps, inputAspects);
6982 const TestConfig testConfig (renderPass,
6983 renderTypes[renderTypeNdx].types,
6984 TestConfig::COMMANDBUFFERTYPES_INLINE,
6985 TestConfig::IMAGEMEMORY_STRICT,
6992 testConfigExternal.allocationKind,
6993 testConfigExternal.groupParams);
6994 const string testName (string("self_dep_") + renderTypes[renderTypeNdx].str + (useInputAspect ? "_use_input_aspect" : ""));
6996 addFunctionCaseWithPrograms<TestConfig>(storeOpGroup.get(), testName, string("self_dep_") + renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
7002 loadOpGroup->addChild(storeOpGroup.release());
7005 inputGroup->addChild(loadOpGroup.release());
7008 formatGroup->addChild(inputGroup.release());
7011 group->addChild(formatGroup.release());
7014 // Depth stencil formats
7015 for (size_t formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(s_coreDepthStencilFormats); formatNdx++)
7017 const VkFormat vkFormat = s_coreDepthStencilFormats[formatNdx];
7018 const tcu::TextureFormat format = mapVkFormat(vkFormat);
7019 const bool isStencilAttachment = hasStencilComponent(format.order);
7020 const bool isDepthAttachment = hasDepthComponent(format.order);
7021 const VkImageAspectFlags formatAspectFlags = (isDepthAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_DEPTH_BIT : 0u)
7022 | (isStencilAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_STENCIL_BIT : 0u);
7023 de::MovePtr<tcu::TestCaseGroup> formatGroup (new tcu::TestCaseGroup(testCtx, formatToName(vkFormat).c_str(), de::toString(vkFormat).c_str()));
7025 for (size_t loadOpNdx = 0; loadOpNdx < DE_LENGTH_OF_ARRAY(loadOps); loadOpNdx++)
7027 const VkAttachmentLoadOp loadOp = loadOps[loadOpNdx].op;
7028 de::MovePtr<tcu::TestCaseGroup> loadOpGroup (new tcu::TestCaseGroup(testCtx, loadOps[loadOpNdx].str, loadOps[loadOpNdx].str));
7030 for (size_t renderTypeNdx = 0; renderTypeNdx < DE_LENGTH_OF_ARRAY(renderTypes); renderTypeNdx++)
7033 const RenderPass renderPass (vector<Attachment>(1, Attachment(vkFormat,
7034 VK_SAMPLE_COUNT_1_BIT,
7035 isDepthAttachment ? loadOp : VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7036 isDepthAttachment ? VK_ATTACHMENT_STORE_OP_STORE :VK_ATTACHMENT_STORE_OP_DONT_CARE,
7037 isStencilAttachment ? loadOp : VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7038 isStencilAttachment ? VK_ATTACHMENT_STORE_OP_STORE :VK_ATTACHMENT_STORE_OP_DONT_CARE,
7039 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
7040 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)),
7041 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7043 vector<AttachmentReference>(),
7044 vector<AttachmentReference>(),
7045 vector<AttachmentReference>(),
7046 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
7047 vector<deUint32>())),
7048 vector<SubpassDependency>());
7049 const TestConfig testConfig (renderPass,
7050 renderTypes[renderTypeNdx].types,
7051 TestConfig::COMMANDBUFFERTYPES_INLINE,
7052 TestConfig::IMAGEMEMORY_STRICT,
7059 testConfigExternal.allocationKind,
7060 testConfigExternal.groupParams);
7062 addFunctionCaseWithPrograms<TestConfig>(loadOpGroup.get(), renderTypes[renderTypeNdx].str, renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
7065 if (isStencilAttachment && isDepthAttachment && loadOp != VK_ATTACHMENT_LOAD_OP_CLEAR)
7068 const RenderPass renderPass (vector<Attachment>(1, Attachment(vkFormat,
7069 VK_SAMPLE_COUNT_1_BIT,
7070 isDepthAttachment ? loadOp : VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7071 isDepthAttachment ? VK_ATTACHMENT_STORE_OP_STORE :VK_ATTACHMENT_STORE_OP_DONT_CARE,
7072 isStencilAttachment ? loadOp : VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7073 isStencilAttachment ? VK_ATTACHMENT_STORE_OP_STORE :VK_ATTACHMENT_STORE_OP_DONT_CARE,
7074 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
7075 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)),
7076 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7078 vector<AttachmentReference>(),
7079 vector<AttachmentReference>(),
7080 vector<AttachmentReference>(),
7081 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL),
7082 vector<deUint32>())),
7083 vector<SubpassDependency>());
7084 const TestConfig testConfig (renderPass,
7085 renderTypes[renderTypeNdx].types,
7086 TestConfig::COMMANDBUFFERTYPES_INLINE,
7087 TestConfig::IMAGEMEMORY_STRICT,
7094 testConfigExternal.allocationKind,
7095 testConfigExternal.groupParams);
7096 const string testName (string(renderTypes[renderTypeNdx].str) + "_depth_read_only");
7098 addFunctionCaseWithPrograms<TestConfig>(loadOpGroup.get(), testName, renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
7102 const RenderPass renderPass (vector<Attachment>(1, Attachment(vkFormat,
7103 VK_SAMPLE_COUNT_1_BIT,
7104 isDepthAttachment ? loadOp : VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7105 isDepthAttachment ? VK_ATTACHMENT_STORE_OP_STORE :VK_ATTACHMENT_STORE_OP_DONT_CARE,
7106 isStencilAttachment ? loadOp : VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7107 isStencilAttachment ? VK_ATTACHMENT_STORE_OP_STORE :VK_ATTACHMENT_STORE_OP_DONT_CARE,
7108 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
7109 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)),
7110 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7112 vector<AttachmentReference>(),
7113 vector<AttachmentReference>(),
7114 vector<AttachmentReference>(),
7115 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL),
7116 vector<deUint32>())),
7117 vector<SubpassDependency>());
7118 const TestConfig testConfig (renderPass,
7119 renderTypes[renderTypeNdx].types,
7120 TestConfig::COMMANDBUFFERTYPES_INLINE,
7121 TestConfig::IMAGEMEMORY_STRICT,
7128 testConfigExternal.allocationKind,
7129 testConfigExternal.groupParams);
7130 const string testName (string(renderTypes[renderTypeNdx].str) + "_stencil_read_only");
7132 addFunctionCaseWithPrograms<TestConfig>(loadOpGroup.get(), testName, renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
7137 formatGroup->addChild(loadOpGroup.release());
7140 if (testConfigExternal.groupParams->renderingType != RENDERING_TYPE_DYNAMIC_RENDERING)
7142 de::MovePtr<tcu::TestCaseGroup> inputGroup (new tcu::TestCaseGroup(testCtx, "input", "Test attachment format as input"));
7144 for (size_t loadOpNdx = 0; loadOpNdx < DE_LENGTH_OF_ARRAY(loadOps); loadOpNdx++)
7146 const VkAttachmentLoadOp loadOp = loadOps[loadOpNdx].op;
7147 de::MovePtr<tcu::TestCaseGroup> loadOpGroup (new tcu::TestCaseGroup(testCtx, loadOps[loadOpNdx].str, loadOps[loadOpNdx].str));
7149 for (size_t storeOpNdx = 0; storeOpNdx < DE_LENGTH_OF_ARRAY(storeOps); storeOpNdx++)
7151 const VkImageAspectFlags inputAttachmentAspectMask = (testConfigExternal.groupParams->renderingType == RENDERING_TYPE_RENDERPASS2)
7153 : static_cast<VkImageAspectFlags>(0);
7154 const VkAttachmentStoreOp storeOp = storeOps[storeOpNdx].op;
7155 de::MovePtr<tcu::TestCaseGroup> storeOpGroup (new tcu::TestCaseGroup(testCtx, storeOps[storeOpNdx].str, storeOps[storeOpNdx].str));
7157 for (size_t useInputAspectNdx = 0; useInputAspectNdx < 2; useInputAspectNdx++)
7159 const bool useInputAspect = useInputAspectNdx != 0;
7161 if (testConfigExternal.groupParams->renderingType == RENDERING_TYPE_RENDERPASS2 && useInputAspect)
7164 for (size_t renderTypeNdx = 0; renderTypeNdx < DE_LENGTH_OF_ARRAY(renderTypes); renderTypeNdx++)
7167 vector<Attachment> attachments;
7168 vector<Subpass> subpasses;
7169 vector<SubpassDependency> deps;
7170 vector<VkInputAttachmentAspectReference> inputAspects;
7172 attachments.push_back(Attachment(vkFormat,
7173 VK_SAMPLE_COUNT_1_BIT,
7178 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
7179 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL));
7181 attachments.push_back(Attachment(vk::VK_FORMAT_R8G8B8A8_UNORM,
7182 VK_SAMPLE_COUNT_1_BIT,
7183 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7184 VK_ATTACHMENT_STORE_OP_STORE,
7185 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7186 VK_ATTACHMENT_STORE_OP_DONT_CARE,
7187 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
7188 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
7190 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7192 vector<AttachmentReference>(),
7193 vector<AttachmentReference>(),
7194 vector<AttachmentReference>(),
7195 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
7196 vector<deUint32>()));
7197 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7199 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, inputAttachmentAspectMask)),
7200 vector<AttachmentReference>(1, AttachmentReference(1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
7201 vector<AttachmentReference>(),
7202 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
7203 vector<deUint32>()));
7205 deps.push_back(SubpassDependency(0, 1,
7206 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
7207 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
7209 vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
7210 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
7215 const VkInputAttachmentAspectReference inputAspect =
7219 (isDepthAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_DEPTH_BIT : 0u)
7220 | (isStencilAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_STENCIL_BIT : 0u)
7223 inputAspects.push_back(inputAspect);
7227 const RenderPass renderPass (attachments, subpasses, deps, inputAspects);
7228 const TestConfig testConfig (renderPass,
7229 renderTypes[renderTypeNdx].types,
7230 TestConfig::COMMANDBUFFERTYPES_INLINE,
7231 TestConfig::IMAGEMEMORY_STRICT,
7238 testConfigExternal.allocationKind,
7239 testConfigExternal.groupParams);
7240 const string testName (renderTypes[renderTypeNdx].str + string(useInputAspect ? "_use_input_aspect" : ""));
7242 addFunctionCaseWithPrograms<TestConfig>(storeOpGroup.get(), testName, renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
7246 vector<Attachment> attachments;
7247 vector<Subpass> subpasses;
7248 vector<SubpassDependency> deps;
7249 vector<VkInputAttachmentAspectReference> inputAspects;
7251 attachments.push_back(Attachment(vkFormat,
7252 VK_SAMPLE_COUNT_1_BIT,
7255 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7256 VK_ATTACHMENT_STORE_OP_DONT_CARE,
7257 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
7258 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL));
7260 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7262 vector<AttachmentReference>(),
7263 vector<AttachmentReference>(),
7264 vector<AttachmentReference>(),
7265 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
7266 vector<deUint32>()));
7267 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7269 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_GENERAL, inputAttachmentAspectMask)),
7270 vector<AttachmentReference>(),
7271 vector<AttachmentReference>(),
7272 AttachmentReference(0, VK_IMAGE_LAYOUT_GENERAL),
7273 vector<deUint32>()));
7275 deps.push_back(SubpassDependency(0, 1,
7276 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
7277 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
7279 vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
7280 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
7281 vk::VK_DEPENDENCY_BY_REGION_BIT));
7283 deps.push_back(SubpassDependency(1, 1,
7284 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
7285 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
7286 vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
7287 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
7288 vk::VK_DEPENDENCY_BY_REGION_BIT));
7293 const VkInputAttachmentAspectReference inputAspect =
7298 (isDepthAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_DEPTH_BIT : 0u)
7299 | (isStencilAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_STENCIL_BIT : 0u)
7302 inputAspects.push_back(inputAspect);
7306 const RenderPass renderPass (attachments, subpasses, deps, inputAspects);
7307 const TestConfig testConfig (renderPass,
7308 renderTypes[renderTypeNdx].types,
7309 TestConfig::COMMANDBUFFERTYPES_INLINE,
7310 TestConfig::IMAGEMEMORY_STRICT,
7317 testConfigExternal.allocationKind,
7318 testConfigExternal.groupParams);
7319 const string testName (string("self_dep_") + renderTypes[renderTypeNdx].str + (useInputAspect ? "_use_input_aspect" : ""));
7321 addFunctionCaseWithPrograms<TestConfig>(storeOpGroup.get(), testName, string("self_dep_") + renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
7325 if (isStencilAttachment && isDepthAttachment)
7329 vector<Attachment> attachments;
7330 vector<Subpass> subpasses;
7331 vector<SubpassDependency> deps;
7332 vector<VkInputAttachmentAspectReference> inputAspects;
7334 attachments.push_back(Attachment(vkFormat,
7335 VK_SAMPLE_COUNT_1_BIT,
7340 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
7341 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL));
7343 attachments.push_back(Attachment(vk::VK_FORMAT_R8G8B8A8_UNORM,
7344 VK_SAMPLE_COUNT_1_BIT,
7345 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7346 VK_ATTACHMENT_STORE_OP_STORE,
7347 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7348 VK_ATTACHMENT_STORE_OP_DONT_CARE,
7349 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
7350 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
7352 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7354 vector<AttachmentReference>(),
7355 vector<AttachmentReference>(),
7356 vector<AttachmentReference>(),
7357 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
7358 vector<deUint32>()));
7359 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7361 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL, inputAttachmentAspectMask)),
7362 vector<AttachmentReference>(1, AttachmentReference(1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
7363 vector<AttachmentReference>(),
7364 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
7365 vector<deUint32>()));
7367 deps.push_back(SubpassDependency(0, 1,
7368 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
7369 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
7371 vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
7372 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
7377 const VkInputAttachmentAspectReference inputAspect =
7382 (isDepthAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_DEPTH_BIT : 0u)
7383 | (isStencilAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_STENCIL_BIT : 0u)
7386 inputAspects.push_back(inputAspect);
7390 const RenderPass renderPass (attachments, subpasses, deps, inputAspects);
7391 const TestConfig testConfig (renderPass,
7392 renderTypes[renderTypeNdx].types,
7393 TestConfig::COMMANDBUFFERTYPES_INLINE,
7394 TestConfig::IMAGEMEMORY_STRICT,
7401 testConfigExternal.allocationKind,
7402 testConfigExternal.groupParams);
7403 const string testName (renderTypes[renderTypeNdx].str + string(useInputAspect ? "_use_input_aspect" : "") + "_depth_read_only");
7405 addFunctionCaseWithPrograms<TestConfig>(storeOpGroup.get(), testName, renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
7409 vector<Attachment> attachments;
7410 vector<Subpass> subpasses;
7411 vector<SubpassDependency> deps;
7412 vector<VkInputAttachmentAspectReference> inputAspects;
7414 attachments.push_back(Attachment(vkFormat,
7415 VK_SAMPLE_COUNT_1_BIT,
7420 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
7421 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL));
7423 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7425 vector<AttachmentReference>(),
7426 vector<AttachmentReference>(),
7427 vector<AttachmentReference>(),
7428 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
7429 vector<deUint32>()));
7430 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7432 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL, inputAttachmentAspectMask)),
7433 vector<AttachmentReference>(),
7434 vector<AttachmentReference>(),
7435 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL),
7436 vector<deUint32>()));
7438 deps.push_back(SubpassDependency(0, 1,
7439 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
7440 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
7442 vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
7443 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
7444 vk::VK_DEPENDENCY_BY_REGION_BIT));
7446 deps.push_back(SubpassDependency(1, 1,
7447 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
7448 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
7450 vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
7451 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
7452 vk::VK_DEPENDENCY_BY_REGION_BIT));
7456 const VkInputAttachmentAspectReference inputAspect =
7461 (isDepthAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_DEPTH_BIT : 0u)
7462 | (isStencilAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_STENCIL_BIT : 0u)
7465 inputAspects.push_back(inputAspect);
7469 const RenderPass renderPass (attachments, subpasses, deps, inputAspects);
7470 const TestConfig testConfig (renderPass,
7471 renderTypes[renderTypeNdx].types,
7472 TestConfig::COMMANDBUFFERTYPES_INLINE,
7473 TestConfig::IMAGEMEMORY_STRICT,
7480 testConfigExternal.allocationKind,
7481 testConfigExternal.groupParams);
7482 const string testName (string("self_dep_") + renderTypes[renderTypeNdx].str + (useInputAspect ? "_use_input_aspect" : "") + "_depth_read_only");
7484 addFunctionCaseWithPrograms<TestConfig>(storeOpGroup.get(), testName, string("self_dep_") + renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
7487 // Stencil read only
7489 vector<Attachment> attachments;
7490 vector<Subpass> subpasses;
7491 vector<SubpassDependency> deps;
7492 vector<VkInputAttachmentAspectReference> inputAspects;
7494 attachments.push_back(Attachment(vkFormat,
7495 VK_SAMPLE_COUNT_1_BIT,
7500 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
7501 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL));
7503 attachments.push_back(Attachment(vk::VK_FORMAT_R8G8B8A8_UNORM,
7504 VK_SAMPLE_COUNT_1_BIT,
7505 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7506 VK_ATTACHMENT_STORE_OP_STORE,
7507 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
7508 VK_ATTACHMENT_STORE_OP_DONT_CARE,
7509 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
7510 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
7512 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7514 vector<AttachmentReference>(),
7515 vector<AttachmentReference>(),
7516 vector<AttachmentReference>(),
7517 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
7518 vector<deUint32>()));
7519 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7521 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL, inputAttachmentAspectMask)),
7522 vector<AttachmentReference>(1, AttachmentReference(1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
7523 vector<AttachmentReference>(),
7524 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
7525 vector<deUint32>()));
7527 deps.push_back(SubpassDependency(0, 1,
7528 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
7529 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
7531 vk::VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
7532 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
7537 const VkInputAttachmentAspectReference inputAspect =
7542 (isDepthAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_DEPTH_BIT : 0u)
7543 | (isStencilAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_STENCIL_BIT : 0u)
7546 inputAspects.push_back(inputAspect);
7550 const RenderPass renderPass (attachments, subpasses, deps, inputAspects);
7551 const TestConfig testConfig (renderPass,
7552 renderTypes[renderTypeNdx].types,
7553 TestConfig::COMMANDBUFFERTYPES_INLINE,
7554 TestConfig::IMAGEMEMORY_STRICT,
7561 testConfigExternal.allocationKind,
7562 testConfigExternal.groupParams);
7563 const string testName (renderTypes[renderTypeNdx].str + string(useInputAspect ? "_use_input_aspect" : "") + "_stencil_read_only");
7565 addFunctionCaseWithPrograms<TestConfig>(storeOpGroup.get(), testName, renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
7569 vector<Attachment> attachments;
7570 vector<Subpass> subpasses;
7571 vector<SubpassDependency> deps;
7572 vector<VkInputAttachmentAspectReference> inputAspects;
7574 attachments.push_back(Attachment(vkFormat,
7575 VK_SAMPLE_COUNT_1_BIT,
7580 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
7581 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL));
7583 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7585 vector<AttachmentReference>(),
7586 vector<AttachmentReference>(),
7587 vector<AttachmentReference>(),
7588 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
7589 vector<deUint32>()));
7590 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
7592 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL, inputAttachmentAspectMask)),
7593 vector<AttachmentReference>(),
7594 vector<AttachmentReference>(),
7595 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL),
7596 vector<deUint32>()));
7598 deps.push_back(SubpassDependency(0, 1,
7599 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
7600 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
7602 vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
7603 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
7604 vk::VK_DEPENDENCY_BY_REGION_BIT));
7606 deps.push_back(SubpassDependency(1, 1,
7607 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
7608 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
7610 vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
7611 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
7612 vk::VK_DEPENDENCY_BY_REGION_BIT));
7617 const VkInputAttachmentAspectReference inputAspect =
7622 (isDepthAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_DEPTH_BIT : 0u)
7623 | (isStencilAttachment ? (VkImageAspectFlags)VK_IMAGE_ASPECT_STENCIL_BIT : 0u)
7626 inputAspects.push_back(inputAspect);
7630 const RenderPass renderPass (attachments, subpasses, deps, inputAspects);
7631 const TestConfig testConfig (renderPass,
7632 renderTypes[renderTypeNdx].types,
7633 TestConfig::COMMANDBUFFERTYPES_INLINE,
7634 TestConfig::IMAGEMEMORY_STRICT,
7641 testConfigExternal.allocationKind,
7642 testConfigExternal.groupParams);
7643 const string testName (string("self_dep_") + renderTypes[renderTypeNdx].str + (useInputAspect ? "_use_input_aspect" : "") + "_stencil_read_only");
7645 addFunctionCaseWithPrograms<TestConfig>(storeOpGroup.get(), testName, string("self_dep_") + renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, testConfig);
7652 loadOpGroup->addChild(storeOpGroup.release());
7655 inputGroup->addChild(loadOpGroup.release());
7658 formatGroup->addChild(inputGroup.release());
7661 group->addChild(formatGroup.release());
7665 void addRenderPassTests (tcu::TestCaseGroup* group, const AllocationKind allocationKind, const SharedGroupParams groupParams)
7667 // tests added by this function have both primary and secondary cases and there is no need to repeat them for useSecondaryCmdBuffer flag;
7668 // but cases defined in other files that are later added to those groups in createRenderPassTestsInternal had to be adjusted and run
7669 // for useSecondaryCmdBuffer flag
7670 if (groupParams->useSecondaryCmdBuffer && !groupParams->secondaryCmdBufferCompletelyContainsDynamicRenderpass)
7673 const TestConfigExternal testConfigExternal (allocationKind, groupParams);
7675 // don't repeat cases that don't use CommandBufferTypes::COMMANDBUFFERTYPES_SECONDARY
7676 if (!groupParams->secondaryCmdBufferCompletelyContainsDynamicRenderpass)
7678 addTestGroup(group, "simple", "Simple basic render pass tests", addSimpleTests, testConfigExternal);
7679 addTestGroup(group, "formats", "Tests for different image formats.", addFormatTests, testConfigExternal);
7682 addTestGroup(group, "attachment", "Attachment format and count tests with load and store ops and image layouts", addAttachmentTests, testConfigExternal);
7684 // don't repeat cases that don't use CommandBufferTypes::COMMANDBUFFERTYPES_SECONDARY
7685 if (!groupParams->secondaryCmdBufferCompletelyContainsDynamicRenderpass)
7686 addTestGroup(group, "attachment_write_mask", "Attachment write mask tests", addAttachmentWriteMaskTests, testConfigExternal);
7688 if (groupParams->renderingType != RENDERING_TYPE_DYNAMIC_RENDERING)
7689 addTestGroup(group, "attachment_allocation", "Attachment allocation tests", addAttachmentAllocationTests, testConfigExternal);
7692 de::MovePtr<tcu::TestCaseGroup> createSuballocationTests(tcu::TestContext& testCtx, const SharedGroupParams groupParams)
7694 de::MovePtr<tcu::TestCaseGroup> suballocationTestsGroup(new tcu::TestCaseGroup(testCtx, "suballocation", "Suballocation RenderPass Tests"));
7696 addRenderPassTests(suballocationTestsGroup.get(), ALLOCATION_KIND_SUBALLOCATED, groupParams);
7698 return suballocationTestsGroup;
7701 de::MovePtr<tcu::TestCaseGroup> createDedicatedAllocationTests(tcu::TestContext& testCtx, const SharedGroupParams groupParams)
7703 de::MovePtr<tcu::TestCaseGroup> dedicatedAllocationTestsGroup(new tcu::TestCaseGroup(testCtx, "dedicated_allocation", "RenderPass Tests For Dedicated Allocation"));
7705 addRenderPassTests(dedicatedAllocationTestsGroup.get(), ALLOCATION_KIND_DEDICATED, groupParams);
7707 return dedicatedAllocationTestsGroup;
7710 tcu::TestCaseGroup* createRenderPassTestsInternal (tcu::TestContext& testCtx, const char* groupName, const SharedGroupParams groupParams)
7712 de::MovePtr<tcu::TestCaseGroup> renderingTests (new tcu::TestCaseGroup(testCtx, groupName, ""));
7713 de::MovePtr<tcu::TestCaseGroup> suballocationTestGroup = createSuballocationTests(testCtx, groupParams);
7714 de::MovePtr<tcu::TestCaseGroup> dedicatedAllocationTestGroup = createDedicatedAllocationTests(testCtx, groupParams);
7716 const RenderingType renderingType = groupParams->renderingType;
7718 switch (renderingType)
7720 case RENDERING_TYPE_RENDERPASS_LEGACY:
7721 suballocationTestGroup->addChild(createRenderPassMultisampleTests(testCtx));
7722 suballocationTestGroup->addChild(createRenderPassMultisampleResolveTests(testCtx, groupParams));
7723 suballocationTestGroup->addChild(createRenderPassSubpassDependencyTests(testCtx));
7724 suballocationTestGroup->addChild(createRenderPassSampleReadTests(testCtx));
7726 #ifndef CTS_USES_VULKANSC
7727 suballocationTestGroup->addChild(createRenderPassSparseRenderTargetTests(testCtx, groupParams));
7728 renderingTests->addChild(createDepthStencilWriteConditionsTests(testCtx));
7729 #endif // CTS_USES_VULKANSC
7731 renderingTests->addChild(createRenderPassMultipleSubpassesMultipleCommandBuffersTests(testCtx));
7735 case RENDERING_TYPE_RENDERPASS2:
7736 suballocationTestGroup->addChild(createRenderPass2MultisampleTests(testCtx));
7737 suballocationTestGroup->addChild(createRenderPass2MultisampleResolveTests(testCtx, groupParams));
7738 suballocationTestGroup->addChild(createRenderPass2SubpassDependencyTests(testCtx));
7739 suballocationTestGroup->addChild(createRenderPass2SampleReadTests(testCtx));
7741 #ifndef CTS_USES_VULKANSC
7742 suballocationTestGroup->addChild(createRenderPass2SparseRenderTargetTests(testCtx, groupParams));
7743 #endif // CTS_USES_VULKANSC
7745 renderingTests->addChild(createRenderPass2DepthStencilResolveTests(testCtx));
7748 #ifndef CTS_USES_VULKANSC
7749 case RENDERING_TYPE_DYNAMIC_RENDERING:
7750 suballocationTestGroup->addChild(createDynamicRenderingMultisampleResolveTests(testCtx, groupParams));
7751 suballocationTestGroup->addChild(createDynamicRenderingSparseRenderTargetTests(testCtx, groupParams));
7753 if (groupParams->useSecondaryCmdBuffer == false)
7755 renderingTests->addChild(createDynamicRenderingRandomTests(testCtx));
7756 renderingTests->addChild(createDynamicRenderingBasicTests(testCtx));
7759 #endif // CTS_USES_VULKANSC
7765 if (renderingType != RENDERING_TYPE_DYNAMIC_RENDERING)
7767 suballocationTestGroup->addChild(createRenderPassUnusedAttachmentTests(testCtx, renderingType));
7768 suballocationTestGroup->addChild(createRenderPassUnusedAttachmentSparseFillingTests(testCtx, renderingType));
7771 suballocationTestGroup->addChild(createRenderPassUnusedClearAttachmentTests(testCtx, groupParams));
7773 #ifndef CTS_USES_VULKANSC
7774 suballocationTestGroup->addChild(createRenderPassLoadStoreOpNoneTests(testCtx, groupParams));
7776 if (renderingType == RENDERING_TYPE_RENDERPASS2)
7778 suballocationTestGroup->addChild(createRenderPassSubpassMergeFeedbackTests(testCtx, renderingType));
7781 renderingTests->addChild(createFragmentDensityMapTests(testCtx, groupParams));
7782 renderingTests->addChild(createRenderPassDitheringTests(testCtx, renderingType));
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();