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"
26 #include "vktTestCaseUtil.hpp"
27 #include "vktTestGroupUtil.hpp"
30 #include "vkDeviceUtil.hpp"
31 #include "vkImageUtil.hpp"
32 #include "vkMemUtil.hpp"
33 #include "vkPlatform.hpp"
34 #include "vkPrograms.hpp"
35 #include "vkQueryUtil.hpp"
37 #include "vkRefUtil.hpp"
38 #include "vkStrUtil.hpp"
39 #include "vkTypeUtil.hpp"
41 #include "tcuFloat.hpp"
42 #include "tcuFormatUtil.hpp"
43 #include "tcuMaybe.hpp"
44 #include "tcuResultCollector.hpp"
45 #include "tcuTestLog.hpp"
46 #include "tcuTextureUtil.hpp"
47 #include "tcuVectorUtil.hpp"
49 #include "deRandom.hpp"
50 #include "deSTLUtil.hpp"
51 #include "deSharedPtr.hpp"
52 #include "deStringUtil.hpp"
53 #include "deUniquePtr.hpp"
74 using tcu::ConstPixelBufferAccess;
75 using tcu::PixelBufferAccess;
98 const char* boolOpToString (BoolOp op)
115 DE_FATAL("Unknown boolean operation.");
120 bool performBoolOp (BoolOp op, bool a, bool b)
137 DE_FATAL("Unknown boolean operation.");
142 BoolOp boolOpFromIndex (size_t index)
152 return ops[index % DE_LENGTH_OF_ARRAY(ops)];
155 // Utility functions using flattened structs
156 Move<VkFence> createFence (const DeviceInterface& vk, VkDevice device, VkFenceCreateFlags flags)
158 const VkFenceCreateInfo pCreateInfo =
160 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
165 return createFence(vk, device, &pCreateInfo);
168 Move<VkFramebuffer> createFramebuffer (const DeviceInterface& vk,
170 VkFramebufferCreateFlags pCreateInfo_flags,
171 VkRenderPass pCreateInfo_renderPass,
172 deUint32 pCreateInfo_attachmentCount,
173 const VkImageView* pCreateInfo_pAttachments,
174 deUint32 pCreateInfo_width,
175 deUint32 pCreateInfo_height,
176 deUint32 pCreateInfo_layers)
178 const VkFramebufferCreateInfo pCreateInfo =
180 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
183 pCreateInfo_renderPass,
184 pCreateInfo_attachmentCount,
185 pCreateInfo_pAttachments,
190 return createFramebuffer(vk, device, &pCreateInfo);
193 Move<VkImage> createImage (const DeviceInterface& vk,
195 VkImageCreateFlags pCreateInfo_flags,
196 VkImageType pCreateInfo_imageType,
197 VkFormat pCreateInfo_format,
198 VkExtent3D pCreateInfo_extent,
199 deUint32 pCreateInfo_mipLevels,
200 deUint32 pCreateInfo_arrayLayers,
201 VkSampleCountFlagBits pCreateInfo_samples,
202 VkImageTiling pCreateInfo_tiling,
203 VkImageUsageFlags pCreateInfo_usage,
204 VkSharingMode pCreateInfo_sharingMode,
205 deUint32 pCreateInfo_queueFamilyCount,
206 const deUint32* pCreateInfo_pQueueFamilyIndices,
207 VkImageLayout pCreateInfo_initialLayout)
209 const VkImageCreateInfo pCreateInfo =
211 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
214 pCreateInfo_imageType,
217 pCreateInfo_mipLevels,
218 pCreateInfo_arrayLayers,
222 pCreateInfo_sharingMode,
223 pCreateInfo_queueFamilyCount,
224 pCreateInfo_pQueueFamilyIndices,
225 pCreateInfo_initialLayout
227 return createImage(vk, device, &pCreateInfo);
230 void bindBufferMemory (const DeviceInterface& vk, VkDevice device, VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memOffset)
232 VK_CHECK(vk.bindBufferMemory(device, buffer, mem, memOffset));
235 void bindImageMemory (const DeviceInterface& vk, VkDevice device, VkImage image, VkDeviceMemory mem, VkDeviceSize memOffset)
237 VK_CHECK(vk.bindImageMemory(device, image, mem, memOffset));
240 Move<VkImageView> createImageView (const DeviceInterface& vk,
242 VkImageViewCreateFlags pCreateInfo_flags,
243 VkImage pCreateInfo_image,
244 VkImageViewType pCreateInfo_viewType,
245 VkFormat pCreateInfo_format,
246 VkComponentMapping pCreateInfo_components,
247 VkImageSubresourceRange pCreateInfo_subresourceRange)
249 const VkImageViewCreateInfo pCreateInfo =
251 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
255 pCreateInfo_viewType,
257 pCreateInfo_components,
258 pCreateInfo_subresourceRange,
260 return createImageView(vk, device, &pCreateInfo);
263 Move<VkBuffer> createBuffer (const DeviceInterface& vk,
265 VkBufferCreateFlags pCreateInfo_flags,
266 VkDeviceSize pCreateInfo_size,
267 VkBufferUsageFlags pCreateInfo_usage,
268 VkSharingMode pCreateInfo_sharingMode,
269 deUint32 pCreateInfo_queueFamilyCount,
270 const deUint32* pCreateInfo_pQueueFamilyIndices)
272 const VkBufferCreateInfo pCreateInfo =
274 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
279 pCreateInfo_sharingMode,
280 pCreateInfo_queueFamilyCount,
281 pCreateInfo_pQueueFamilyIndices,
283 return createBuffer(vk, device, &pCreateInfo);
286 Move<VkCommandPool> createCommandPool (const DeviceInterface& vk,
288 VkCommandPoolCreateFlags pCreateInfo_flags,
289 deUint32 pCreateInfo_queueFamilyIndex)
291 const VkCommandPoolCreateInfo pCreateInfo =
293 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
296 pCreateInfo_queueFamilyIndex,
298 return createCommandPool(vk, device, &pCreateInfo);
301 void cmdBeginRenderPass (const DeviceInterface& vk,
302 VkCommandBuffer cmdBuffer,
303 VkRenderPass pRenderPassBegin_renderPass,
304 VkFramebuffer pRenderPassBegin_framebuffer,
305 VkRect2D pRenderPassBegin_renderArea,
306 deUint32 pRenderPassBegin_clearValueCount,
307 const VkClearValue* pRenderPassBegin_pAttachmentClearValues,
308 VkSubpassContents contents)
310 const VkRenderPassBeginInfo pRenderPassBegin =
312 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
314 pRenderPassBegin_renderPass,
315 pRenderPassBegin_framebuffer,
316 pRenderPassBegin_renderArea,
317 pRenderPassBegin_clearValueCount,
318 pRenderPassBegin_pAttachmentClearValues,
320 vk.cmdBeginRenderPass(cmdBuffer, &pRenderPassBegin, contents);
323 Move<VkCommandBuffer> allocateCommandBuffer (const DeviceInterface& vk,
325 VkCommandPool pCreateInfo_commandPool,
326 VkCommandBufferLevel pCreateInfo_level)
328 const VkCommandBufferAllocateInfo pAllocateInfo =
330 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
332 pCreateInfo_commandPool,
336 return allocateCommandBuffer(vk, device, &pAllocateInfo);
339 void beginCommandBuffer (const DeviceInterface& vk,
340 VkCommandBuffer cmdBuffer,
341 VkCommandBufferUsageFlags pBeginInfo_flags,
342 VkRenderPass pInheritanceInfo_renderPass,
343 deUint32 pInheritanceInfo_subpass,
344 VkFramebuffer pInheritanceInfo_framebuffer,
345 VkBool32 pInheritanceInfo_occlusionQueryEnable,
346 VkQueryControlFlags pInheritanceInfo_queryFlags,
347 VkQueryPipelineStatisticFlags pInheritanceInfo_pipelineStatistics)
349 const VkCommandBufferInheritanceInfo pInheritanceInfo =
351 VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO,
353 pInheritanceInfo_renderPass,
354 pInheritanceInfo_subpass,
355 pInheritanceInfo_framebuffer,
356 pInheritanceInfo_occlusionQueryEnable,
357 pInheritanceInfo_queryFlags,
358 pInheritanceInfo_pipelineStatistics,
360 const VkCommandBufferBeginInfo pBeginInfo =
362 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
367 VK_CHECK(vk.beginCommandBuffer(cmdBuffer, &pBeginInfo));
370 void endCommandBuffer (const DeviceInterface& vk, VkCommandBuffer cmdBuffer)
372 VK_CHECK(vk.endCommandBuffer(cmdBuffer));
375 void queueSubmit (const DeviceInterface& vk, VkQueue queue, deUint32 cmdBufferCount, const VkCommandBuffer* pCmdBuffers, VkFence fence)
377 const VkSubmitInfo submitInfo =
379 VK_STRUCTURE_TYPE_SUBMIT_INFO,
381 0u, // waitSemaphoreCount
382 (const VkSemaphore*)DE_NULL, // pWaitSemaphores
383 (const VkPipelineStageFlags*)DE_NULL,
384 cmdBufferCount, // commandBufferCount
386 0u, // signalSemaphoreCount
387 (const VkSemaphore*)DE_NULL, // pSignalSemaphores
389 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, fence));
392 void waitForFences (const DeviceInterface& vk, VkDevice device, deUint32 fenceCount, const VkFence* pFences, VkBool32 waitAll, deUint64 timeout)
394 VK_CHECK(vk.waitForFences(device, fenceCount, pFences, waitAll, timeout));
397 VkImageAspectFlags getImageAspectFlags (VkFormat vkFormat)
399 const tcu::TextureFormat format = mapVkFormat(vkFormat);
401 DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELORDER_LAST == 21);
403 switch (format.order)
405 case tcu::TextureFormat::DS:
406 return VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
408 case tcu::TextureFormat::D:
409 return VK_IMAGE_ASPECT_DEPTH_BIT;
411 case tcu::TextureFormat::S:
412 return VK_IMAGE_ASPECT_STENCIL_BIT;
415 return VK_IMAGE_ASPECT_COLOR_BIT;
419 VkAccessFlags getAllMemoryReadFlags (void)
421 return VK_ACCESS_TRANSFER_READ_BIT
422 | VK_ACCESS_UNIFORM_READ_BIT
423 | VK_ACCESS_HOST_READ_BIT
424 | VK_ACCESS_INDEX_READ_BIT
425 | VK_ACCESS_SHADER_READ_BIT
426 | VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT
427 | VK_ACCESS_INDIRECT_COMMAND_READ_BIT
428 | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT
429 | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT
430 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
433 VkAccessFlags getAllMemoryWriteFlags (void)
435 return VK_ACCESS_TRANSFER_WRITE_BIT
436 | VK_ACCESS_HOST_WRITE_BIT
437 | VK_ACCESS_SHADER_WRITE_BIT
438 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT
439 | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
442 VkAccessFlags getMemoryFlagsForLayout (const VkImageLayout layout)
446 case VK_IMAGE_LAYOUT_GENERAL: return getAllMemoryReadFlags() | getAllMemoryWriteFlags();
447 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: return VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
448 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: return VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
449 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: return VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
450 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: return VK_ACCESS_SHADER_READ_BIT;
451 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: return VK_ACCESS_TRANSFER_READ_BIT;
452 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: return VK_ACCESS_TRANSFER_WRITE_BIT;
455 return (VkAccessFlags)0;
459 VkPipelineStageFlags getAllPipelineStageFlags (void)
461 return VK_PIPELINE_STAGE_TESSELLATION_EVALUATION_SHADER_BIT
462 | VK_PIPELINE_STAGE_TRANSFER_BIT
463 | VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT
464 | VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT
465 | VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT
466 | VK_PIPELINE_STAGE_VERTEX_INPUT_BIT
467 | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT
468 | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
469 | VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT
470 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
471 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT
472 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
473 | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
476 class AttachmentReference
479 AttachmentReference (deUint32 attachment,
480 VkImageLayout layout)
481 : m_attachment (attachment)
486 deUint32 getAttachment (void) const { return m_attachment; }
487 VkImageLayout getImageLayout (void) const { return m_layout; }
490 deUint32 m_attachment;
491 VkImageLayout m_layout;
497 Subpass (VkPipelineBindPoint pipelineBindPoint,
498 VkSubpassDescriptionFlags flags,
499 const vector<AttachmentReference>& inputAttachments,
500 const vector<AttachmentReference>& colorAttachments,
501 const vector<AttachmentReference>& resolveAttachments,
502 AttachmentReference depthStencilAttachment,
503 const vector<deUint32>& preserveAttachments)
504 : m_pipelineBindPoint (pipelineBindPoint)
506 , m_inputAttachments (inputAttachments)
507 , m_colorAttachments (colorAttachments)
508 , m_resolveAttachments (resolveAttachments)
509 , m_depthStencilAttachment (depthStencilAttachment)
510 , m_preserveAttachments (preserveAttachments)
514 VkPipelineBindPoint getPipelineBindPoint (void) const { return m_pipelineBindPoint; }
515 VkSubpassDescriptionFlags getFlags (void) const { return m_flags; }
516 const vector<AttachmentReference>& getInputAttachments (void) const { return m_inputAttachments; }
517 const vector<AttachmentReference>& getColorAttachments (void) const { return m_colorAttachments; }
518 const vector<AttachmentReference>& getResolveAttachments (void) const { return m_resolveAttachments; }
519 const AttachmentReference& getDepthStencilAttachment (void) const { return m_depthStencilAttachment; }
520 const vector<deUint32>& getPreserveAttachments (void) const { return m_preserveAttachments; }
523 VkPipelineBindPoint m_pipelineBindPoint;
524 VkSubpassDescriptionFlags m_flags;
526 vector<AttachmentReference> m_inputAttachments;
527 vector<AttachmentReference> m_colorAttachments;
528 vector<AttachmentReference> m_resolveAttachments;
529 AttachmentReference m_depthStencilAttachment;
531 vector<deUint32> m_preserveAttachments;
534 class SubpassDependency
537 SubpassDependency (deUint32 srcPass,
540 VkPipelineStageFlags srcStageMask,
541 VkPipelineStageFlags dstStageMask,
543 VkAccessFlags outputMask,
544 VkAccessFlags inputMask,
546 VkDependencyFlags flags)
547 : m_srcPass (srcPass)
548 , m_dstPass (dstPass)
550 , m_srcStageMask (srcStageMask)
551 , m_dstStageMask (dstStageMask)
553 , m_outputMask (outputMask)
554 , m_inputMask (inputMask)
559 deUint32 getSrcPass (void) const { return m_srcPass; }
560 deUint32 getDstPass (void) const { return m_dstPass; }
562 VkPipelineStageFlags getSrcStageMask (void) const { return m_srcStageMask; }
563 VkPipelineStageFlags getDstStageMask (void) const { return m_dstStageMask; }
565 VkAccessFlags getOutputMask (void) const { return m_outputMask; }
566 VkAccessFlags getInputMask (void) const { return m_inputMask; }
568 VkDependencyFlags getFlags (void) const { return m_flags; }
574 VkPipelineStageFlags m_srcStageMask;
575 VkPipelineStageFlags m_dstStageMask;
577 VkAccessFlags m_outputMask;
578 VkAccessFlags m_inputMask;
579 VkDependencyFlags m_flags;
585 Attachment (VkFormat format,
586 VkSampleCountFlagBits samples,
588 VkAttachmentLoadOp loadOp,
589 VkAttachmentStoreOp storeOp,
591 VkAttachmentLoadOp stencilLoadOp,
592 VkAttachmentStoreOp stencilStoreOp,
594 VkImageLayout initialLayout,
595 VkImageLayout finalLayout)
597 , m_samples (samples)
600 , m_storeOp (storeOp)
602 , m_stencilLoadOp (stencilLoadOp)
603 , m_stencilStoreOp (stencilStoreOp)
605 , m_initialLayout (initialLayout)
606 , m_finalLayout (finalLayout)
610 VkFormat getFormat (void) const { return m_format; }
611 VkSampleCountFlagBits getSamples (void) const { return m_samples; }
613 VkAttachmentLoadOp getLoadOp (void) const { return m_loadOp; }
614 VkAttachmentStoreOp getStoreOp (void) const { return m_storeOp; }
617 VkAttachmentLoadOp getStencilLoadOp (void) const { return m_stencilLoadOp; }
618 VkAttachmentStoreOp getStencilStoreOp (void) const { return m_stencilStoreOp; }
620 VkImageLayout getInitialLayout (void) const { return m_initialLayout; }
621 VkImageLayout getFinalLayout (void) const { return m_finalLayout; }
625 VkSampleCountFlagBits m_samples;
627 VkAttachmentLoadOp m_loadOp;
628 VkAttachmentStoreOp m_storeOp;
630 VkAttachmentLoadOp m_stencilLoadOp;
631 VkAttachmentStoreOp m_stencilStoreOp;
633 VkImageLayout m_initialLayout;
634 VkImageLayout m_finalLayout;
640 RenderPass (const vector<Attachment>& attachments,
641 const vector<Subpass>& subpasses,
642 const vector<SubpassDependency>& dependencies)
643 : m_attachments (attachments)
644 , m_subpasses (subpasses)
645 , m_dependencies (dependencies)
649 const vector<Attachment>& getAttachments (void) const { return m_attachments; }
650 const vector<Subpass>& getSubpasses (void) const { return m_subpasses; }
651 const vector<SubpassDependency>& getDependencies (void) const { return m_dependencies; }
654 const vector<Attachment> m_attachments;
655 const vector<Subpass> m_subpasses;
656 const vector<SubpassDependency> m_dependencies;
663 RENDERTYPES_NONE = 0,
664 RENDERTYPES_CLEAR = (1<<1),
665 RENDERTYPES_DRAW = (1<<2)
668 enum CommandBufferTypes
670 COMMANDBUFFERTYPES_INLINE = (1<<0),
671 COMMANDBUFFERTYPES_SECONDARY = (1<<1)
676 IMAGEMEMORY_STRICT = (1<<0),
677 IMAGEMEMORY_LAZY = (1<<1)
680 TestConfig (const RenderPass& renderPass_,
681 RenderTypes renderTypes_,
682 CommandBufferTypes commandBufferTypes_,
683 ImageMemory imageMemory_,
684 const UVec2& targetSize_,
685 const UVec2& renderPos_,
686 const UVec2& renderSize_,
688 : renderPass (renderPass_)
689 , renderTypes (renderTypes_)
690 , commandBufferTypes (commandBufferTypes_)
691 , imageMemory (imageMemory_)
692 , targetSize (targetSize_)
693 , renderPos (renderPos_)
694 , renderSize (renderSize_)
699 RenderPass renderPass;
700 RenderTypes renderTypes;
701 CommandBufferTypes commandBufferTypes;
702 ImageMemory imageMemory;
709 TestConfig::RenderTypes operator| (TestConfig::RenderTypes a, TestConfig::RenderTypes b)
711 return (TestConfig::RenderTypes)(((deUint32)a) | ((deUint32)b));
714 TestConfig::CommandBufferTypes operator| (TestConfig::CommandBufferTypes a, TestConfig::CommandBufferTypes b)
716 return (TestConfig::CommandBufferTypes)(((deUint32)a) | ((deUint32)b));
719 TestConfig::ImageMemory operator| (TestConfig::ImageMemory a, TestConfig::ImageMemory b)
721 return (TestConfig::ImageMemory)(((deUint32)a) | ((deUint32)b));
724 void logRenderPassInfo (TestLog& log,
725 const RenderPass& renderPass)
727 const tcu::ScopedLogSection section (log, "RenderPass", "RenderPass");
730 const tcu::ScopedLogSection attachmentsSection (log, "Attachments", "Attachments");
731 const vector<Attachment>& attachments = renderPass.getAttachments();
733 for (size_t attachmentNdx = 0; attachmentNdx < attachments.size(); attachmentNdx++)
735 const tcu::ScopedLogSection attachmentSection (log, "Attachment" + de::toString(attachmentNdx), "Attachment " + de::toString(attachmentNdx));
736 const Attachment& attachment = attachments[attachmentNdx];
738 log << TestLog::Message << "Format: " << attachment.getFormat() << TestLog::EndMessage;
739 log << TestLog::Message << "Samples: " << attachment.getSamples() << TestLog::EndMessage;
741 log << TestLog::Message << "LoadOp: " << attachment.getLoadOp() << TestLog::EndMessage;
742 log << TestLog::Message << "StoreOp: " << attachment.getStoreOp() << TestLog::EndMessage;
744 log << TestLog::Message << "StencilLoadOp: " << attachment.getStencilLoadOp() << TestLog::EndMessage;
745 log << TestLog::Message << "StencilStoreOp: " << attachment.getStencilStoreOp() << TestLog::EndMessage;
747 log << TestLog::Message << "InitialLayout: " << attachment.getInitialLayout() << TestLog::EndMessage;
748 log << TestLog::Message << "FinalLayout: " << attachment.getFinalLayout() << TestLog::EndMessage;
753 const tcu::ScopedLogSection subpassesSection (log, "Subpasses", "Subpasses");
754 const vector<Subpass>& subpasses = renderPass.getSubpasses();
756 for (size_t subpassNdx = 0; subpassNdx < subpasses.size(); subpassNdx++)
758 const tcu::ScopedLogSection subpassSection (log, "Subpass" + de::toString(subpassNdx), "Subpass " + de::toString(subpassNdx));
759 const Subpass& subpass = subpasses[subpassNdx];
761 const vector<AttachmentReference>& inputAttachments = subpass.getInputAttachments();
762 const vector<AttachmentReference>& colorAttachments = subpass.getColorAttachments();
763 const vector<AttachmentReference>& resolveAttachments = subpass.getResolveAttachments();
764 const vector<deUint32>& preserveAttachments = subpass.getPreserveAttachments();
766 if (!inputAttachments.empty())
768 const tcu::ScopedLogSection inputAttachmentsSection (log, "Inputs", "Inputs");
770 for (size_t inputNdx = 0; inputNdx < inputAttachments.size(); inputNdx++)
772 const tcu::ScopedLogSection inputAttachmentSection (log, "Input" + de::toString(inputNdx), "Input " + de::toString(inputNdx));
773 const AttachmentReference& inputAttachment = inputAttachments[inputNdx];
775 log << TestLog::Message << "Attachment: " << inputAttachment.getAttachment() << TestLog::EndMessage;
776 log << TestLog::Message << "Layout: " << inputAttachment.getImageLayout() << TestLog::EndMessage;
780 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED)
782 const tcu::ScopedLogSection depthStencilAttachmentSection (log, "DepthStencil", "DepthStencil");
783 const AttachmentReference& depthStencilAttachment = subpass.getDepthStencilAttachment();
785 log << TestLog::Message << "Attachment: " << depthStencilAttachment.getAttachment() << TestLog::EndMessage;
786 log << TestLog::Message << "Layout: " << depthStencilAttachment.getImageLayout() << TestLog::EndMessage;
789 if (!colorAttachments.empty())
791 const tcu::ScopedLogSection colorAttachmentsSection (log, "Colors", "Colors");
793 for (size_t colorNdx = 0; colorNdx < colorAttachments.size(); colorNdx++)
795 const tcu::ScopedLogSection colorAttachmentSection (log, "Color" + de::toString(colorNdx), "Color " + de::toString(colorNdx));
796 const AttachmentReference& colorAttachment = colorAttachments[colorNdx];
798 log << TestLog::Message << "Attachment: " << colorAttachment.getAttachment() << TestLog::EndMessage;
799 log << TestLog::Message << "Layout: " << colorAttachment.getImageLayout() << TestLog::EndMessage;
803 if (!resolveAttachments.empty())
805 const tcu::ScopedLogSection resolveAttachmentsSection (log, "Resolves", "Resolves");
807 for (size_t resolveNdx = 0; resolveNdx < resolveAttachments.size(); resolveNdx++)
809 const tcu::ScopedLogSection resolveAttachmentSection (log, "Resolve" + de::toString(resolveNdx), "Resolve " + de::toString(resolveNdx));
810 const AttachmentReference& resolveAttachment = resolveAttachments[resolveNdx];
812 log << TestLog::Message << "Attachment: " << resolveAttachment.getAttachment() << TestLog::EndMessage;
813 log << TestLog::Message << "Layout: " << resolveAttachment.getImageLayout() << TestLog::EndMessage;
817 if (!preserveAttachments.empty())
819 const tcu::ScopedLogSection preserveAttachmentsSection (log, "Preserves", "Preserves");
821 for (size_t preserveNdx = 0; preserveNdx < preserveAttachments.size(); preserveNdx++)
823 const tcu::ScopedLogSection preserveAttachmentSection (log, "Preserve" + de::toString(preserveNdx), "Preserve " + de::toString(preserveNdx));
824 const deUint32 preserveAttachment = preserveAttachments[preserveNdx];
826 log << TestLog::Message << "Attachment: " << preserveAttachment << TestLog::EndMessage;
833 if (!renderPass.getDependencies().empty())
835 const tcu::ScopedLogSection dependenciesSection (log, "Dependencies", "Dependencies");
837 for (size_t depNdx = 0; depNdx < renderPass.getDependencies().size(); depNdx++)
839 const tcu::ScopedLogSection dependencySection (log, "Dependency" + de::toString(depNdx), "Dependency " + de::toString(depNdx));
840 const SubpassDependency& dep = renderPass.getDependencies()[depNdx];
842 log << TestLog::Message << "Source: " << dep.getSrcPass() << TestLog::EndMessage;
843 log << TestLog::Message << "Destination: " << dep.getDstPass() << TestLog::EndMessage;
845 log << TestLog::Message << "Source Stage Mask: " << dep.getSrcStageMask() << TestLog::EndMessage;
846 log << TestLog::Message << "Destination Stage Mask: " << dep.getDstStageMask() << TestLog::EndMessage;
848 log << TestLog::Message << "Input Mask: " << dep.getInputMask() << TestLog::EndMessage;
849 log << TestLog::Message << "Output Mask: " << dep.getOutputMask() << TestLog::EndMessage;
850 log << TestLog::Message << "Dependency Flags: " << getDependencyFlagsStr(dep.getFlags()) << TestLog::EndMessage;
855 std::string clearColorToString (VkFormat vkFormat, VkClearColorValue value)
857 const tcu::TextureFormat format = mapVkFormat(vkFormat);
858 const tcu::TextureChannelClass channelClass = tcu::getTextureChannelClass(format.type);
859 const tcu::BVec4 channelMask = tcu::getTextureFormatChannelMask(format);
861 std::ostringstream stream;
865 switch (channelClass)
867 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
868 for (int i = 0; i < 4; i++)
874 stream << value.int32[i];
880 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
881 for (int i = 0; i < 4; i++)
887 stream << value.uint32[i];
893 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
894 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
895 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
896 for (int i = 0; i < 4; i++)
902 stream << value.float32[i];
909 DE_FATAL("Unknown channel class");
917 std::string clearValueToString (VkFormat vkFormat, VkClearValue value)
919 const tcu::TextureFormat format = mapVkFormat(vkFormat);
921 if (tcu::hasStencilComponent(format.order) || tcu::hasDepthComponent(format.order))
923 std::ostringstream stream;
927 if (tcu::hasStencilComponent(format.order))
928 stream << "stencil: " << value.depthStencil.stencil;
930 if (tcu::hasStencilComponent(format.order) && tcu::hasDepthComponent(format.order))
933 if (tcu::hasDepthComponent(format.order))
934 stream << "depth: " << value.depthStencil.depth;
941 return clearColorToString(vkFormat, value.color);
944 VkClearColorValue randomColorClearValue (const Attachment& attachment, de::Random& rng)
946 const float clearNan = tcu::Float32::nan().asFloat();
947 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
948 const tcu::TextureChannelClass channelClass = tcu::getTextureChannelClass(format.type);
949 const tcu::BVec4 channelMask = tcu::getTextureFormatChannelMask(format);
950 VkClearColorValue clearColor;
952 switch (channelClass)
954 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
956 for (int ndx = 0; ndx < 4; ndx++)
958 if (!channelMask[ndx])
959 clearColor.int32[ndx] = std::numeric_limits<deInt32>::min();
961 clearColor.uint32[ndx] = rng.getBool() ? 1u : 0u;
966 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
968 for (int ndx = 0; ndx < 4; ndx++)
970 if (!channelMask[ndx])
971 clearColor.uint32[ndx] = std::numeric_limits<deUint32>::max();
973 clearColor.uint32[ndx] = rng.getBool() ? 1u : 0u;
978 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
979 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
980 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
982 for (int ndx = 0; ndx < 4; ndx++)
984 if (!channelMask[ndx])
985 clearColor.float32[ndx] = clearNan;
987 clearColor.float32[ndx] = rng.getBool() ? 1.0f : 0.0f;
993 DE_FATAL("Unknown channel class");
999 VkAttachmentDescription createAttachmentDescription (const Attachment& attachment)
1001 const VkAttachmentDescription attachmentDescription =
1005 attachment.getFormat(), // format
1006 attachment.getSamples(), // samples
1008 attachment.getLoadOp(), // loadOp
1009 attachment.getStoreOp(), // storeOp
1011 attachment.getStencilLoadOp(), // stencilLoadOp
1012 attachment.getStencilStoreOp(), // stencilStoreOp
1014 attachment.getInitialLayout(), // initialLayout
1015 attachment.getFinalLayout(), // finalLayout
1018 return attachmentDescription;
1021 VkAttachmentReference createAttachmentReference (const AttachmentReference& referenceInfo)
1023 const VkAttachmentReference reference =
1025 referenceInfo.getAttachment(), // attachment;
1026 referenceInfo.getImageLayout() // layout;
1032 VkSubpassDescription createSubpassDescription (const Subpass& subpass,
1033 vector<VkAttachmentReference>* attachmentReferenceLists,
1034 vector<deUint32>* preserveAttachmentReferences)
1036 vector<VkAttachmentReference>& inputAttachmentReferences = attachmentReferenceLists[0];
1037 vector<VkAttachmentReference>& colorAttachmentReferences = attachmentReferenceLists[1];
1038 vector<VkAttachmentReference>& resolveAttachmentReferences = attachmentReferenceLists[2];
1039 vector<VkAttachmentReference>& depthStencilAttachmentReferences = attachmentReferenceLists[3];
1041 for (size_t attachmentNdx = 0; attachmentNdx < subpass.getColorAttachments().size(); attachmentNdx++)
1042 colorAttachmentReferences.push_back(createAttachmentReference(subpass.getColorAttachments()[attachmentNdx]));
1044 for (size_t attachmentNdx = 0; attachmentNdx < subpass.getInputAttachments().size(); attachmentNdx++)
1045 inputAttachmentReferences.push_back(createAttachmentReference(subpass.getInputAttachments()[attachmentNdx]));
1047 for (size_t attachmentNdx = 0; attachmentNdx < subpass.getResolveAttachments().size(); attachmentNdx++)
1048 resolveAttachmentReferences.push_back(createAttachmentReference(subpass.getResolveAttachments()[attachmentNdx]));
1050 depthStencilAttachmentReferences.push_back(createAttachmentReference(subpass.getDepthStencilAttachment()));
1052 for (size_t attachmentNdx = 0; attachmentNdx < subpass.getPreserveAttachments().size(); attachmentNdx++)
1053 preserveAttachmentReferences->push_back(subpass.getPreserveAttachments()[attachmentNdx]);
1055 DE_ASSERT(resolveAttachmentReferences.empty() || colorAttachmentReferences.size() == resolveAttachmentReferences.size());
1058 const VkSubpassDescription subpassDescription =
1060 subpass.getFlags(), // flags;
1061 subpass.getPipelineBindPoint(), // pipelineBindPoint;
1063 (deUint32)inputAttachmentReferences.size(), // inputCount;
1064 inputAttachmentReferences.empty() ? DE_NULL : &inputAttachmentReferences[0], // inputAttachments;
1066 (deUint32)colorAttachmentReferences.size(), // colorCount;
1067 colorAttachmentReferences.empty() ? DE_NULL : &colorAttachmentReferences[0], // colorAttachments;
1068 resolveAttachmentReferences.empty() ? DE_NULL : &resolveAttachmentReferences[0], // resolveAttachments;
1070 &depthStencilAttachmentReferences[0], // pDepthStencilAttachment;
1071 (deUint32)preserveAttachmentReferences->size(), // preserveCount;
1072 preserveAttachmentReferences->empty() ? DE_NULL : &(*preserveAttachmentReferences)[0] // preserveAttachments;
1075 return subpassDescription;
1079 VkSubpassDependency createSubpassDependency (const SubpassDependency& dependencyInfo)
1081 const VkSubpassDependency dependency =
1083 dependencyInfo.getSrcPass(), // srcSubpass;
1084 dependencyInfo.getDstPass(), // destSubpass;
1086 dependencyInfo.getSrcStageMask(), // srcStageMask;
1087 dependencyInfo.getDstStageMask(), // destStageMask;
1089 dependencyInfo.getOutputMask(), // outputMask;
1090 dependencyInfo.getInputMask(), // inputMask;
1092 dependencyInfo.getFlags() // dependencyFlags;
1098 Move<VkRenderPass> createRenderPass (const DeviceInterface& vk,
1100 const RenderPass& renderPassInfo)
1102 const size_t perSubpassAttachmentReferenceLists = 4;
1103 vector<VkAttachmentDescription> attachments;
1104 vector<VkSubpassDescription> subpasses;
1105 vector<VkSubpassDependency> dependencies;
1106 vector<vector<VkAttachmentReference> > attachmentReferenceLists(renderPassInfo.getSubpasses().size() * perSubpassAttachmentReferenceLists);
1107 vector<vector<deUint32> > preserveAttachments(renderPassInfo.getSubpasses().size());
1109 for (size_t attachmentNdx = 0; attachmentNdx < renderPassInfo.getAttachments().size(); attachmentNdx++)
1110 attachments.push_back(createAttachmentDescription(renderPassInfo.getAttachments()[attachmentNdx]));
1112 for (size_t subpassNdx = 0; subpassNdx < renderPassInfo.getSubpasses().size(); subpassNdx++)
1113 subpasses.push_back(createSubpassDescription(renderPassInfo.getSubpasses()[subpassNdx], &(attachmentReferenceLists[subpassNdx * perSubpassAttachmentReferenceLists]), &preserveAttachments[subpassNdx]));
1115 for (size_t depNdx = 0; depNdx < renderPassInfo.getDependencies().size(); depNdx++)
1116 dependencies.push_back(createSubpassDependency(renderPassInfo.getDependencies()[depNdx]));
1119 const VkRenderPassCreateInfo createInfo =
1121 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
1123 (VkRenderPassCreateFlags)0u,
1124 (deUint32)attachments.size(),
1125 (attachments.empty() ? DE_NULL : &attachments[0]),
1126 (deUint32)subpasses.size(),
1127 (subpasses.empty() ? DE_NULL : &subpasses[0]),
1128 (deUint32)dependencies.size(),
1129 (dependencies.empty() ? DE_NULL : &dependencies[0])
1132 return createRenderPass(vk, device, &createInfo);
1136 Move<VkFramebuffer> createFramebuffer (const DeviceInterface& vk,
1138 VkRenderPass renderPass,
1140 const vector<VkImageView>& attachments)
1142 return createFramebuffer(vk, device, 0u, renderPass, (deUint32)attachments.size(), attachments.empty() ? DE_NULL : &attachments[0], size.x(), size.y(), 1u);
1145 Move<VkImage> createAttachmentImage (const DeviceInterface& vk,
1147 deUint32 queueIndex,
1150 VkSampleCountFlagBits samples,
1151 VkImageUsageFlags usageFlags,
1152 VkImageLayout layout)
1154 VkImageUsageFlags targetUsageFlags = 0;
1155 const tcu::TextureFormat textureFormat = mapVkFormat(format);
1157 DE_ASSERT(!(tcu::hasDepthComponent(vk::mapVkFormat(format).order) || tcu::hasStencilComponent(vk::mapVkFormat(format).order))
1158 || ((usageFlags & vk::VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) == 0));
1160 DE_ASSERT((tcu::hasDepthComponent(vk::mapVkFormat(format).order) || tcu::hasStencilComponent(vk::mapVkFormat(format).order))
1161 || ((usageFlags & vk::VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0));
1163 if (tcu::hasDepthComponent(textureFormat.order) || tcu::hasStencilComponent(textureFormat.order))
1164 targetUsageFlags |= vk::VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
1166 targetUsageFlags |= vk::VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
1168 return createImage(vk, device,
1169 (VkImageCreateFlags)0,
1172 vk::makeExtent3D(size.x(), size.y(), 1u),
1176 VK_IMAGE_TILING_OPTIMAL,
1177 usageFlags | targetUsageFlags,
1178 VK_SHARING_MODE_EXCLUSIVE,
1184 de::MovePtr<Allocation> createImageMemory (const DeviceInterface& vk,
1186 Allocator& allocator,
1190 de::MovePtr<Allocation> allocation (allocator.allocate(getImageMemoryRequirements(vk, device, image), lazy ? MemoryRequirement::LazilyAllocated : MemoryRequirement::Any));
1191 bindImageMemory(vk, device, image, allocation->getMemory(), allocation->getOffset());
1195 Move<VkImageView> createImageAttachmentView (const DeviceInterface& vk,
1199 VkImageAspectFlags aspect)
1201 const VkImageSubresourceRange range =
1210 return createImageView(vk, device, 0u, image, VK_IMAGE_VIEW_TYPE_2D, format, makeComponentMappingRGBA(), range);
1213 VkClearValue randomClearValue (const Attachment& attachment, de::Random& rng)
1215 const float clearNan = tcu::Float32::nan().asFloat();
1216 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
1218 if (tcu::hasStencilComponent(format.order) || tcu::hasDepthComponent(format.order))
1220 VkClearValue clearValue;
1222 clearValue.depthStencil.depth = clearNan;
1223 clearValue.depthStencil.stencil = 0xCDu;
1225 if (tcu::hasStencilComponent(format.order))
1226 clearValue.depthStencil.stencil = rng.getBool()
1230 if (tcu::hasDepthComponent(format.order))
1231 clearValue.depthStencil.depth = rng.getBool()
1239 VkClearValue clearValue;
1241 clearValue.color = randomColorClearValue(attachment, rng);
1247 class AttachmentResources
1250 AttachmentResources (const DeviceInterface& vk,
1252 Allocator& allocator,
1253 deUint32 queueIndex,
1255 const Attachment& attachmentInfo,
1256 VkImageUsageFlags usageFlags)
1257 : m_image (createAttachmentImage(vk, device, queueIndex, size, attachmentInfo.getFormat(), attachmentInfo.getSamples(), usageFlags, VK_IMAGE_LAYOUT_UNDEFINED))
1258 , m_imageMemory (createImageMemory(vk, device, allocator, *m_image, ((usageFlags & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) != 0)))
1259 , m_attachmentView (createImageAttachmentView(vk, device, *m_image, attachmentInfo.getFormat(), getImageAspectFlags(attachmentInfo.getFormat())))
1261 const tcu::TextureFormat format = mapVkFormat(attachmentInfo.getFormat());
1262 const bool isDepthFormat = tcu::hasDepthComponent(format.order);
1263 const bool isStencilFormat = tcu::hasStencilComponent(format.order);
1265 if (isDepthFormat && isStencilFormat)
1267 m_depthInputAttachmentView = createImageAttachmentView(vk, device, *m_image, attachmentInfo.getFormat(), VK_IMAGE_ASPECT_DEPTH_BIT);
1268 m_stencilInputAttachmentView = createImageAttachmentView(vk, device, *m_image, attachmentInfo.getFormat(), VK_IMAGE_ASPECT_STENCIL_BIT);
1270 m_inputAttachmentViews = std::make_pair(*m_depthInputAttachmentView, *m_stencilInputAttachmentView);
1273 m_inputAttachmentViews = std::make_pair(*m_attachmentView, (vk::VkImageView)0u);
1275 if ((usageFlags & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) == 0)
1277 if (tcu::hasDepthComponent(format.order) && tcu::hasStencilComponent(format.order))
1279 const tcu::TextureFormat depthFormat = getDepthCopyFormat(attachmentInfo.getFormat());
1280 const tcu::TextureFormat stencilFormat = getStencilCopyFormat(attachmentInfo.getFormat());
1282 m_bufferSize = size.x() * size.y() * depthFormat.getPixelSize();
1283 m_secondaryBufferSize = size.x() * size.y() * stencilFormat.getPixelSize();
1285 m_buffer = createBuffer(vk, device, 0, m_bufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_SHARING_MODE_EXCLUSIVE, 1, &queueIndex);
1286 m_bufferMemory = allocator.allocate(getBufferMemoryRequirements(vk, device, *m_buffer), MemoryRequirement::HostVisible);
1288 bindBufferMemory(vk, device, *m_buffer, m_bufferMemory->getMemory(), m_bufferMemory->getOffset());
1290 m_secondaryBuffer = createBuffer(vk, device, 0, m_secondaryBufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_SHARING_MODE_EXCLUSIVE, 1, &queueIndex);
1291 m_secondaryBufferMemory = allocator.allocate(getBufferMemoryRequirements(vk, device, *m_secondaryBuffer), MemoryRequirement::HostVisible);
1293 bindBufferMemory(vk, device, *m_secondaryBuffer, m_secondaryBufferMemory->getMemory(), m_secondaryBufferMemory->getOffset());
1297 m_bufferSize = size.x() * size.y() * format.getPixelSize();
1299 m_buffer = createBuffer(vk, device, 0, m_bufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_SHARING_MODE_EXCLUSIVE, 1, &queueIndex);
1300 m_bufferMemory = allocator.allocate(getBufferMemoryRequirements(vk, device, *m_buffer), MemoryRequirement::HostVisible);
1302 bindBufferMemory(vk, device, *m_buffer, m_bufferMemory->getMemory(), m_bufferMemory->getOffset());
1307 const pair<VkImageView, VkImageView>& getInputAttachmentViews (void) const
1309 return m_inputAttachmentViews;
1312 ~AttachmentResources (void)
1316 VkImageView getAttachmentView (void) const
1318 return *m_attachmentView;
1321 VkImage getImage (void) const
1326 VkBuffer getBuffer (void) const
1328 DE_ASSERT(*m_buffer != DE_NULL);
1332 VkDeviceSize getBufferSize (void) const
1334 DE_ASSERT(*m_buffer != DE_NULL);
1335 return m_bufferSize;
1338 const Allocation& getResultMemory (void) const
1340 DE_ASSERT(m_bufferMemory);
1341 return *m_bufferMemory;
1344 VkBuffer getSecondaryBuffer (void) const
1346 DE_ASSERT(*m_secondaryBuffer != DE_NULL);
1347 return *m_secondaryBuffer;
1350 VkDeviceSize getSecondaryBufferSize (void) const
1352 DE_ASSERT(*m_secondaryBuffer != DE_NULL);
1353 return m_secondaryBufferSize;
1356 const Allocation& getSecondaryResultMemory (void) const
1358 DE_ASSERT(m_secondaryBufferMemory);
1359 return *m_secondaryBufferMemory;
1363 const Unique<VkImage> m_image;
1364 const UniquePtr<Allocation> m_imageMemory;
1365 const Unique<VkImageView> m_attachmentView;
1367 Move<VkImageView> m_depthInputAttachmentView;
1368 Move<VkImageView> m_stencilInputAttachmentView;
1369 pair<VkImageView, VkImageView> m_inputAttachmentViews;
1371 Move<VkBuffer> m_buffer;
1372 VkDeviceSize m_bufferSize;
1373 de::MovePtr<Allocation> m_bufferMemory;
1375 Move<VkBuffer> m_secondaryBuffer;
1376 VkDeviceSize m_secondaryBufferSize;
1377 de::MovePtr<Allocation> m_secondaryBufferMemory;
1380 void uploadBufferData (const DeviceInterface& vk,
1382 const Allocation& memory,
1386 const VkMappedMemoryRange range =
1388 VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, // sType;
1390 memory.getMemory(), // mem;
1391 memory.getOffset(), // offset;
1392 (VkDeviceSize)size // size;
1394 void* const ptr = memory.getHostPtr();
1396 deMemcpy(ptr, data, size);
1397 VK_CHECK(vk.flushMappedMemoryRanges(device, 1, &range));
1400 VkImageAspectFlagBits getPrimaryImageAspect (tcu::TextureFormat::ChannelOrder order)
1402 DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELORDER_LAST == 21);
1406 case tcu::TextureFormat::D:
1407 case tcu::TextureFormat::DS:
1408 return VK_IMAGE_ASPECT_DEPTH_BIT;
1410 case tcu::TextureFormat::S:
1411 return VK_IMAGE_ASPECT_STENCIL_BIT;
1414 return VK_IMAGE_ASPECT_COLOR_BIT;
1421 RenderQuad (const Vec2& posA, const Vec2& posB)
1424 m_vertices[0] = posA;
1425 m_vertices[1] = Vec2(posA[0], posB[1]);
1426 m_vertices[2] = posB;
1428 m_vertices[3] = posB;
1429 m_vertices[4] = Vec2(posB[0], posA[1]);
1430 m_vertices[5] = posA;
1433 const Vec2& getCornerA (void) const
1435 return m_vertices[0];
1438 const Vec2& getCornerB (void) const
1440 return m_vertices[2];
1443 const void* getVertexPointer (void) const
1445 return &m_vertices[0];
1448 size_t getVertexDataSize (void) const
1450 return sizeof(Vec2) * m_vertices.size();
1454 vector<Vec2> m_vertices;
1460 ColorClear (const UVec2& offset,
1462 const VkClearColorValue& color)
1469 const UVec2& getOffset (void) const { return m_offset; }
1470 const UVec2& getSize (void) const { return m_size; }
1471 const VkClearColorValue& getColor (void) const { return m_color; }
1476 VkClearColorValue m_color;
1479 class DepthStencilClear
1482 DepthStencilClear (const UVec2& offset,
1489 , m_stencil (stencil)
1493 const UVec2& getOffset (void) const { return m_offset; }
1494 const UVec2& getSize (void) const { return m_size; }
1495 float getDepth (void) const { return m_depth; }
1496 deUint32 getStencil (void) const { return m_stencil; }
1499 const UVec2 m_offset;
1502 const float m_depth;
1503 const deUint32 m_stencil;
1506 class SubpassRenderInfo
1509 SubpassRenderInfo (const RenderPass& renderPass,
1510 deUint32 subpassIndex,
1514 const UVec2& viewportOffset,
1515 const UVec2& viewportSize,
1517 const Maybe<RenderQuad>& renderQuad,
1518 const vector<ColorClear>& colorClears,
1519 const Maybe<DepthStencilClear>& depthStencilClear)
1520 : m_viewportOffset (viewportOffset)
1521 , m_viewportSize (viewportSize)
1522 , m_subpassIndex (subpassIndex)
1523 , m_isSecondary (isSecondary_)
1524 , m_flags (renderPass.getSubpasses()[subpassIndex].getFlags())
1525 , m_renderQuad (renderQuad)
1526 , m_colorClears (colorClears)
1527 , m_depthStencilClear (depthStencilClear)
1528 , m_colorAttachments (renderPass.getSubpasses()[subpassIndex].getColorAttachments())
1529 , m_inputAttachments (renderPass.getSubpasses()[subpassIndex].getInputAttachments())
1531 for (deUint32 attachmentNdx = 0; attachmentNdx < (deUint32)m_colorAttachments.size(); attachmentNdx++)
1532 m_colorAttachmentInfo.push_back(renderPass.getAttachments()[m_colorAttachments[attachmentNdx].getAttachment()]);
1534 if (renderPass.getSubpasses()[subpassIndex].getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED)
1536 m_depthStencilAttachment = tcu::just(renderPass.getSubpasses()[subpassIndex].getDepthStencilAttachment());
1537 m_depthStencilAttachmentInfo = tcu::just(renderPass.getAttachments()[renderPass.getSubpasses()[subpassIndex].getDepthStencilAttachment().getAttachment()]);
1541 const UVec2& getViewportOffset (void) const { return m_viewportOffset; }
1542 const UVec2& getViewportSize (void) const { return m_viewportSize; }
1544 deUint32 getSubpassIndex (void) const { return m_subpassIndex; }
1545 bool isSecondary (void) const { return m_isSecondary; }
1547 const Maybe<RenderQuad>& getRenderQuad (void) const { return m_renderQuad; }
1548 const vector<ColorClear>& getColorClears (void) const { return m_colorClears; }
1549 const Maybe<DepthStencilClear>& getDepthStencilClear (void) const { return m_depthStencilClear; }
1551 deUint32 getInputAttachmentCount (void) const { return (deUint32)m_inputAttachments.size(); }
1552 deUint32 getInputAttachmentIndex (deUint32 attachmentNdx) const { return m_inputAttachments[attachmentNdx].getAttachment(); }
1554 deUint32 getColorAttachmentCount (void) const { return (deUint32)m_colorAttachments.size(); }
1555 VkImageLayout getColorAttachmentLayout (deUint32 attachmentNdx) const { return m_colorAttachments[attachmentNdx].getImageLayout(); }
1556 deUint32 getColorAttachmentIndex (deUint32 attachmentNdx) const { return m_colorAttachments[attachmentNdx].getAttachment(); }
1557 const Attachment& getColorAttachment (deUint32 attachmentNdx) const { return m_colorAttachmentInfo[attachmentNdx]; }
1558 Maybe<VkImageLayout> getDepthStencilAttachmentLayout (void) const { return m_depthStencilAttachment ? tcu::just(m_depthStencilAttachment->getImageLayout()) : tcu::nothing<VkImageLayout>(); }
1559 Maybe<deUint32> getDepthStencilAttachmentIndex (void) const { return m_depthStencilAttachment ? tcu::just(m_depthStencilAttachment->getAttachment()) : tcu::nothing<deUint32>(); };
1560 const Maybe<Attachment>& getDepthStencilAttachment (void) const { return m_depthStencilAttachmentInfo; }
1561 VkSubpassDescriptionFlags getSubpassFlags (void) const { return m_flags; }
1564 UVec2 m_viewportOffset;
1565 UVec2 m_viewportSize;
1567 deUint32 m_subpassIndex;
1569 VkSubpassDescriptionFlags m_flags;
1571 Maybe<RenderQuad> m_renderQuad;
1572 vector<ColorClear> m_colorClears;
1573 Maybe<DepthStencilClear> m_depthStencilClear;
1575 vector<AttachmentReference> m_colorAttachments;
1576 vector<Attachment> m_colorAttachmentInfo;
1578 Maybe<AttachmentReference> m_depthStencilAttachment;
1579 Maybe<Attachment> m_depthStencilAttachmentInfo;
1581 vector<AttachmentReference> m_inputAttachments;
1584 Move<VkPipeline> createSubpassPipeline (const DeviceInterface& vk,
1586 VkRenderPass renderPass,
1587 VkShaderModule vertexShaderModule,
1588 VkShaderModule fragmentShaderModule,
1589 VkPipelineLayout pipelineLayout,
1590 const SubpassRenderInfo& renderInfo)
1592 const VkSpecializationInfo emptyShaderSpecializations =
1594 0u, // mapEntryCount
1600 Maybe<VkSampleCountFlagBits> rasterSamples;
1601 vector<VkPipelineColorBlendAttachmentState> attachmentBlendStates;
1603 for (deUint32 attachmentNdx = 0; attachmentNdx < renderInfo.getColorAttachmentCount(); attachmentNdx++)
1605 const Attachment& attachment = renderInfo.getColorAttachment(attachmentNdx);
1607 DE_ASSERT(!rasterSamples || *rasterSamples == attachment.getSamples());
1609 rasterSamples = attachment.getSamples();
1612 const VkPipelineColorBlendAttachmentState attachmentBlendState =
1614 VK_FALSE, // blendEnable
1615 VK_BLEND_FACTOR_SRC_ALPHA, // srcBlendColor
1616 VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, // destBlendColor
1617 VK_BLEND_OP_ADD, // blendOpColor
1618 VK_BLEND_FACTOR_ONE, // srcBlendAlpha
1619 VK_BLEND_FACTOR_ONE, // destBlendAlpha
1620 VK_BLEND_OP_ADD, // blendOpAlpha
1621 VK_COLOR_COMPONENT_R_BIT|VK_COLOR_COMPONENT_G_BIT|VK_COLOR_COMPONENT_B_BIT|VK_COLOR_COMPONENT_A_BIT, // channelWriteMask
1624 attachmentBlendStates.push_back(attachmentBlendState);
1628 if (renderInfo.getDepthStencilAttachment())
1630 const Attachment& attachment = *renderInfo.getDepthStencilAttachment();
1632 DE_ASSERT(!rasterSamples || *rasterSamples == attachment.getSamples());
1633 rasterSamples = attachment.getSamples();
1636 // If there are no attachment use single sample
1638 rasterSamples = VK_SAMPLE_COUNT_1_BIT;
1640 const VkPipelineShaderStageCreateInfo shaderStages[2] =
1643 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // sType
1645 (VkPipelineShaderStageCreateFlags)0u,
1646 VK_SHADER_STAGE_VERTEX_BIT, // stage
1647 vertexShaderModule, // shader
1649 &emptyShaderSpecializations
1652 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // sType
1654 (VkPipelineShaderStageCreateFlags)0u,
1655 VK_SHADER_STAGE_FRAGMENT_BIT, // stage
1656 fragmentShaderModule, // shader
1658 &emptyShaderSpecializations
1661 const VkVertexInputBindingDescription vertexBinding =
1664 (deUint32)sizeof(tcu::Vec2), // strideInBytes
1665 VK_VERTEX_INPUT_RATE_VERTEX, // stepRate
1667 const VkVertexInputAttributeDescription vertexAttrib =
1671 VK_FORMAT_R32G32B32A32_SFLOAT, // format
1672 0u, // offsetInBytes
1674 const VkPipelineVertexInputStateCreateInfo vertexInputState =
1676 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, // sType
1678 (VkPipelineVertexInputStateCreateFlags)0u,
1680 &vertexBinding, // pVertexBindingDescriptions
1681 1u, // attributeCount
1682 &vertexAttrib, // pVertexAttributeDescriptions
1684 const VkPipelineInputAssemblyStateCreateInfo inputAssemblyState =
1686 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, // sType
1688 (VkPipelineInputAssemblyStateCreateFlags)0u,
1689 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, // topology
1690 VK_FALSE, // primitiveRestartEnable
1692 const VkViewport viewport =
1694 (float)renderInfo.getViewportOffset().x(), (float)renderInfo.getViewportOffset().y(),
1695 (float)renderInfo.getViewportSize().x(), (float)renderInfo.getViewportSize().y(),
1698 const VkRect2D scissor =
1700 { (deInt32)renderInfo.getViewportOffset().x(), (deInt32)renderInfo.getViewportOffset().y() },
1701 { renderInfo.getViewportSize().x(), renderInfo.getViewportSize().y() }
1703 const VkPipelineViewportStateCreateInfo viewportState =
1705 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
1707 (VkPipelineViewportStateCreateFlags)0u,
1713 const VkPipelineRasterizationStateCreateInfo rasterState =
1715 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, // sType
1717 (VkPipelineRasterizationStateCreateFlags)0u,
1718 VK_TRUE, // depthClipEnable
1719 VK_FALSE, // rasterizerDiscardEnable
1720 VK_POLYGON_MODE_FILL, // fillMode
1721 VK_CULL_MODE_NONE, // cullMode
1722 VK_FRONT_FACE_COUNTER_CLOCKWISE, // frontFace
1723 VK_FALSE, // depthBiasEnable
1725 0.0f, // depthBiasClamp
1726 0.0f, // slopeScaledDepthBias
1729 const VkPipelineMultisampleStateCreateInfo multisampleState =
1731 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // sType
1733 (VkPipelineMultisampleStateCreateFlags)0u,
1734 *rasterSamples, // rasterSamples
1735 VK_FALSE, // sampleShadingEnable
1736 0.0f, // minSampleShading
1737 DE_NULL, // pSampleMask
1738 VK_FALSE, // alphaToCoverageEnable
1739 VK_FALSE, // alphaToOneEnable
1741 const size_t stencilIndex = renderInfo.getSubpassIndex();
1742 const VkPipelineDepthStencilStateCreateInfo depthStencilState =
1744 VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, // sType
1746 (VkPipelineDepthStencilStateCreateFlags)0u,
1747 VK_TRUE, // depthTestEnable
1748 VK_TRUE, // depthWriteEnable
1749 VK_COMPARE_OP_ALWAYS, // depthCompareOp
1750 VK_FALSE, // depthBoundsEnable
1751 VK_TRUE, // stencilTestEnable
1753 VK_STENCIL_OP_REPLACE, // stencilFailOp
1754 VK_STENCIL_OP_REPLACE, // stencilPassOp
1755 VK_STENCIL_OP_REPLACE, // stencilDepthFailOp
1756 VK_COMPARE_OP_ALWAYS, // stencilCompareOp
1757 ~0u, // stencilCompareMask
1758 ~0u, // stencilWriteMask
1759 ((stencilIndex % 2) == 0) ? ~0x0u : 0x0u // stencilReference
1762 VK_STENCIL_OP_REPLACE, // stencilFailOp
1763 VK_STENCIL_OP_REPLACE, // stencilPassOp
1764 VK_STENCIL_OP_REPLACE, // stencilDepthFailOp
1765 VK_COMPARE_OP_ALWAYS, // stencilCompareOp
1766 ~0u, // stencilCompareMask
1767 ~0u, // stencilWriteMask
1768 ((stencilIndex % 2) == 0) ? ~0x0u : 0x0u // stencilReference
1771 0.0f, // minDepthBounds;
1772 1.0f // maxDepthBounds;
1774 const VkPipelineColorBlendStateCreateInfo blendState =
1776 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, // sType
1778 (VkPipelineColorBlendStateCreateFlags)0u,
1779 VK_FALSE, // logicOpEnable
1780 VK_LOGIC_OP_COPY, // logicOp
1781 (deUint32)attachmentBlendStates.size(), // attachmentCount
1782 attachmentBlendStates.empty() ? DE_NULL : &attachmentBlendStates[0],// pAttachments
1783 { 0.0f, 0.0f, 0.0f, 0.0f } // blendConst
1785 const VkGraphicsPipelineCreateInfo createInfo =
1787 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, // sType
1789 (VkPipelineCreateFlags)0u,
1792 shaderStages, // pStages
1794 &vertexInputState, // pVertexInputState
1795 &inputAssemblyState, // pInputAssemblyState
1796 DE_NULL, // pTessellationState
1797 &viewportState, // pViewportState
1798 &rasterState, // pRasterState
1799 &multisampleState, // pMultisampleState
1800 &depthStencilState, // pDepthStencilState
1801 &blendState, // pColorBlendState
1802 (const VkPipelineDynamicStateCreateInfo*)DE_NULL, // pDynamicState
1803 pipelineLayout, // layout
1805 renderPass, // renderPass
1806 renderInfo.getSubpassIndex(), // subpass
1807 DE_NULL, // basePipelineHandle
1808 0u // basePipelineIndex
1811 return createGraphicsPipeline(vk, device, DE_NULL, &createInfo);
1814 class SubpassRenderer
1817 SubpassRenderer (Context& context,
1818 const DeviceInterface& vk,
1820 Allocator& allocator,
1821 VkRenderPass renderPass,
1822 VkFramebuffer framebuffer,
1823 VkCommandPool commandBufferPool,
1824 deUint32 queueFamilyIndex,
1825 const vector<VkImage>& attachmentImages,
1826 const vector<pair<VkImageView, VkImageView> >& attachmentViews,
1827 const SubpassRenderInfo& renderInfo,
1828 const vector<Attachment>& attachmentInfos)
1829 : m_renderInfo (renderInfo)
1831 const deUint32 subpassIndex = renderInfo.getSubpassIndex();
1832 vector<VkDescriptorSetLayoutBinding> bindings;
1834 for (deUint32 colorAttachmentNdx = 0; colorAttachmentNdx < renderInfo.getColorAttachmentCount(); colorAttachmentNdx++)
1835 m_colorAttachmentImages.push_back(attachmentImages[renderInfo.getColorAttachmentIndex(colorAttachmentNdx)]);
1837 if (renderInfo.getDepthStencilAttachmentIndex())
1838 m_depthStencilAttachmentImage = attachmentImages[*renderInfo.getDepthStencilAttachmentIndex()];
1840 if (renderInfo.getRenderQuad())
1842 const RenderQuad& renderQuad = *renderInfo.getRenderQuad();
1844 if (renderInfo.getInputAttachmentCount() > 0)
1846 deUint32 bindingIndex = 0;
1848 for (deUint32 inputAttachmentNdx = 0; inputAttachmentNdx < renderInfo.getInputAttachmentCount(); inputAttachmentNdx++)
1850 const Attachment attachmentInfo = attachmentInfos[renderInfo.getInputAttachmentIndex(inputAttachmentNdx)];
1851 const tcu::TextureFormat format = mapVkFormat(attachmentInfo.getFormat());
1852 const bool isDepthFormat = tcu::hasDepthComponent(format.order);
1853 const bool isStencilFormat = tcu::hasStencilComponent(format.order);
1854 const deUint32 bindingCount = isDepthFormat && isStencilFormat ? 2u : 1u;
1856 for (deUint32 bindingNdx = 0; bindingNdx < bindingCount; bindingNdx++)
1858 const VkDescriptorSetLayoutBinding binding =
1861 vk::VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
1863 vk::VK_SHADER_STAGE_FRAGMENT_BIT,
1867 bindings.push_back(binding);
1872 const VkDescriptorSetLayoutCreateInfo createInfo =
1874 vk::VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
1878 (deUint32)bindings.size(),
1882 m_descriptorSetLayout = vk::createDescriptorSetLayout(vk, device, &createInfo);
1885 const VkDescriptorSetLayout descriptorSetLayout = *m_descriptorSetLayout;
1886 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
1888 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // sType;
1890 (vk::VkPipelineLayoutCreateFlags)0,
1891 m_descriptorSetLayout ? 1u :0u , // setLayoutCount;
1892 m_descriptorSetLayout ? &descriptorSetLayout : DE_NULL, // pSetLayouts;
1893 0u, // pushConstantRangeCount;
1894 DE_NULL, // pPushConstantRanges;
1897 m_vertexShaderModule = createShaderModule(vk, device, context.getBinaryCollection().get(de::toString(subpassIndex) + "-vert"), 0u);
1898 m_fragmentShaderModule = createShaderModule(vk, device, context.getBinaryCollection().get(de::toString(subpassIndex) + "-frag"), 0u);
1899 m_pipelineLayout = createPipelineLayout(vk, device, &pipelineLayoutParams);
1900 m_pipeline = createSubpassPipeline(vk, device, renderPass, *m_vertexShaderModule, *m_fragmentShaderModule, *m_pipelineLayout, m_renderInfo);
1902 m_vertexBuffer = createBuffer(vk, device, 0u, (VkDeviceSize)renderQuad.getVertexDataSize(), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_SHARING_MODE_EXCLUSIVE, 1u, &queueFamilyIndex);
1903 m_vertexBufferMemory = allocator.allocate(getBufferMemoryRequirements(vk, device, *m_vertexBuffer), MemoryRequirement::HostVisible);
1905 bindBufferMemory(vk, device, *m_vertexBuffer, m_vertexBufferMemory->getMemory(), m_vertexBufferMemory->getOffset());
1906 uploadBufferData(vk, device, *m_vertexBufferMemory, renderQuad.getVertexDataSize(), renderQuad.getVertexPointer());
1908 if (renderInfo.getInputAttachmentCount() > 0)
1911 const VkDescriptorPoolSize poolSize =
1913 vk::VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
1914 // \note Reserve 2 per input attachment since depthStencil attachments require 2.
1915 renderInfo.getInputAttachmentCount() * 2u
1917 const VkDescriptorPoolCreateInfo createInfo =
1919 vk::VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
1921 VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT,
1923 // \note Reserve 2 per input attachment since depthStencil attachments require 2.
1924 renderInfo.getInputAttachmentCount() * 2u,
1929 m_descriptorPool = vk::createDescriptorPool(vk, device, &createInfo);
1932 const VkDescriptorSetAllocateInfo allocateInfo =
1934 vk::VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
1939 &descriptorSetLayout
1942 m_descriptorSet = vk::allocateDescriptorSet(vk, device, &allocateInfo);
1945 vector<VkWriteDescriptorSet> writes (bindings.size());
1946 vector<VkDescriptorImageInfo> imageInfos (bindings.size());
1947 deUint32 bindingIndex = 0;
1949 for (deUint32 inputAttachmentNdx = 0; inputAttachmentNdx < renderInfo.getInputAttachmentCount(); inputAttachmentNdx++)
1951 const Attachment attachmentInfo = attachmentInfos[renderInfo.getInputAttachmentIndex(inputAttachmentNdx)];
1952 const tcu::TextureFormat format = mapVkFormat(attachmentInfo.getFormat());
1953 const bool isDepthFormat = tcu::hasDepthComponent(format.order);
1954 const bool isStencilFormat = tcu::hasStencilComponent(format.order);
1956 if (isDepthFormat && isStencilFormat)
1959 const VkDescriptorImageInfo imageInfo =
1962 attachmentViews[renderInfo.getInputAttachmentIndex(inputAttachmentNdx)].first,
1963 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
1965 imageInfos[bindingIndex] = imageInfo;
1968 const VkWriteDescriptorSet write =
1970 VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
1977 VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
1978 &imageInfos[bindingIndex],
1982 writes[bindingIndex] = write;
1988 const VkDescriptorImageInfo imageInfo =
1991 attachmentViews[renderInfo.getInputAttachmentIndex(inputAttachmentNdx)].second,
1992 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
1994 imageInfos[bindingIndex] = imageInfo;
1997 const VkWriteDescriptorSet write =
1999 VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
2006 VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
2007 &imageInfos[bindingIndex],
2011 writes[bindingIndex] = write;
2019 const VkDescriptorImageInfo imageInfo =
2022 attachmentViews[renderInfo.getInputAttachmentIndex(inputAttachmentNdx)].first,
2023 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
2025 imageInfos[bindingIndex] = imageInfo;
2028 const VkWriteDescriptorSet write =
2030 VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
2037 VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
2038 &imageInfos[bindingIndex],
2042 writes[bindingIndex] = write;
2049 vk.updateDescriptorSets(device, (deUint32)writes.size(), &writes[0], 0u, DE_NULL);
2054 if (renderInfo.isSecondary())
2056 m_commandBuffer = allocateCommandBuffer(vk, device, commandBufferPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
2058 beginCommandBuffer(vk, *m_commandBuffer, vk::VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT, renderPass, subpassIndex, framebuffer, VK_FALSE, (VkQueryControlFlags)0, (VkQueryPipelineStatisticFlags)0);
2059 pushRenderCommands(vk, *m_commandBuffer);
2060 endCommandBuffer(vk, *m_commandBuffer);
2064 bool isSecondary (void) const
2066 return m_commandBuffer;
2069 VkCommandBuffer getCommandBuffer (void) const
2071 DE_ASSERT(isSecondary());
2072 return *m_commandBuffer;
2075 void pushRenderCommands (const DeviceInterface& vk,
2076 VkCommandBuffer commandBuffer)
2078 if (!m_renderInfo.getColorClears().empty())
2080 const vector<ColorClear>& colorClears (m_renderInfo.getColorClears());
2082 for (deUint32 attachmentNdx = 0; attachmentNdx < m_renderInfo.getColorAttachmentCount(); attachmentNdx++)
2084 const ColorClear& colorClear = colorClears[attachmentNdx];
2085 const VkClearAttachment attachment =
2087 VK_IMAGE_ASPECT_COLOR_BIT,
2089 makeClearValue(colorClear.getColor()),
2091 const VkClearRect rect =
2094 { (deInt32)colorClear.getOffset().x(), (deInt32)colorClear.getOffset().y() },
2095 { colorClear.getSize().x(), colorClear.getSize().y() }
2097 0u, // baseArrayLayer
2101 vk.cmdClearAttachments(commandBuffer, 1u, &attachment, 1u, &rect);
2105 if (m_renderInfo.getDepthStencilClear())
2107 const DepthStencilClear& depthStencilClear = *m_renderInfo.getDepthStencilClear();
2108 const deUint32 attachmentNdx = m_renderInfo.getColorAttachmentCount();
2109 tcu::TextureFormat format = mapVkFormat(m_renderInfo.getDepthStencilAttachment()->getFormat());
2110 const VkClearAttachment attachment =
2112 (VkImageAspectFlags)((hasDepthComponent(format.order) ? VK_IMAGE_ASPECT_DEPTH_BIT : 0)
2113 | (hasStencilComponent(format.order) ? VK_IMAGE_ASPECT_STENCIL_BIT : 0)),
2115 makeClearValueDepthStencil(depthStencilClear.getDepth(), depthStencilClear.getStencil())
2117 const VkClearRect rect =
2120 { (deInt32)depthStencilClear.getOffset().x(), (deInt32)depthStencilClear.getOffset().y() },
2121 { depthStencilClear.getSize().x(), depthStencilClear.getSize().y() }
2123 0u, // baseArrayLayer
2127 vk.cmdClearAttachments(commandBuffer, 1u, &attachment, 1u, &rect);
2130 vector<VkImageMemoryBarrier> selfDeps;
2131 VkPipelineStageFlags srcStages = 0;
2132 VkPipelineStageFlags dstStages = 0;
2134 for (deUint32 inputAttachmentNdx = 0; inputAttachmentNdx < m_renderInfo.getInputAttachmentCount(); inputAttachmentNdx++)
2136 for (deUint32 colorAttachmentNdx = 0; colorAttachmentNdx < m_renderInfo.getColorAttachmentCount(); colorAttachmentNdx++)
2138 if (m_renderInfo.getInputAttachmentIndex(inputAttachmentNdx) == m_renderInfo.getColorAttachmentIndex(colorAttachmentNdx))
2140 const VkImageMemoryBarrier barrier =
2142 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
2145 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // srcAccessMask
2146 VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, // dstAccessMask
2148 VK_IMAGE_LAYOUT_GENERAL, // oldLayout
2149 VK_IMAGE_LAYOUT_GENERAL, // newLayout
2151 VK_QUEUE_FAMILY_IGNORED, // srcQueueFamilyIndex
2152 VK_QUEUE_FAMILY_IGNORED, // destQueueFamilyIndex
2154 m_colorAttachmentImages[colorAttachmentNdx], // image
2155 { // subresourceRange
2156 VK_IMAGE_ASPECT_COLOR_BIT, // aspect
2159 0, // baseArraySlice
2164 srcStages |= VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
2165 dstStages |= VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
2167 selfDeps.push_back(barrier);
2171 if (m_renderInfo.getDepthStencilAttachmentIndex() && (m_renderInfo.getInputAttachmentIndex(inputAttachmentNdx) == *m_renderInfo.getDepthStencilAttachmentIndex()))
2173 const VkImageMemoryBarrier barrier =
2175 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType;
2178 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, // srcAccessMask
2179 VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, // dstAccessMask
2181 VK_IMAGE_LAYOUT_GENERAL, // oldLayout
2182 VK_IMAGE_LAYOUT_GENERAL, // newLayout;
2184 VK_QUEUE_FAMILY_IGNORED, // srcQueueFamilyIndex;
2185 VK_QUEUE_FAMILY_IGNORED, // destQueueFamilyIndex;
2187 m_depthStencilAttachmentImage, // image;
2188 { // subresourceRange;
2189 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, // aspect;
2192 0, // baseArraySlice;
2197 srcStages |= VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT;
2198 dstStages |= VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
2200 selfDeps.push_back(barrier);
2204 if (!selfDeps.empty())
2205 vk.cmdPipelineBarrier(commandBuffer, srcStages, dstStages, VK_DEPENDENCY_BY_REGION_BIT, 0, DE_NULL, 0, DE_NULL, (deUint32)selfDeps.size(), &selfDeps[0]);
2207 if (m_renderInfo.getRenderQuad())
2209 const VkDeviceSize offset = 0;
2210 const VkBuffer vertexBuffer = *m_vertexBuffer;
2212 vk.cmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
2214 if (m_descriptorSet)
2216 const VkDescriptorSet descriptorSet = *m_descriptorSet;
2217 vk.cmdBindDescriptorSets(commandBuffer, vk::VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipelineLayout, 0u, 1u, &descriptorSet, 0u, NULL);
2220 vk.cmdBindVertexBuffers(commandBuffer, 0u, 1u, &vertexBuffer, &offset);
2221 vk.cmdDraw(commandBuffer, 6u, 1u, 0u, 0u);
2226 const SubpassRenderInfo m_renderInfo;
2227 Move<VkCommandBuffer> m_commandBuffer;
2228 Move<VkPipeline> m_pipeline;
2229 Move<VkDescriptorSetLayout> m_descriptorSetLayout;
2230 Move<VkPipelineLayout> m_pipelineLayout;
2232 Move<VkShaderModule> m_vertexShaderModule;
2233 Move<VkShaderModule> m_fragmentShaderModule;
2235 Move<VkDescriptorPool> m_descriptorPool;
2236 Move<VkDescriptorSet> m_descriptorSet;
2237 Move<VkBuffer> m_vertexBuffer;
2238 de::MovePtr<Allocation> m_vertexBufferMemory;
2239 vector<VkImage> m_colorAttachmentImages;
2240 VkImage m_depthStencilAttachmentImage;
2243 void pushImageInitializationCommands (const DeviceInterface& vk,
2244 VkCommandBuffer commandBuffer,
2245 const vector<Attachment>& attachmentInfo,
2246 const vector<de::SharedPtr<AttachmentResources> >& attachmentResources,
2247 deUint32 queueIndex,
2248 const vector<Maybe<VkClearValue> >& clearValues)
2251 vector<VkImageMemoryBarrier> initializeLayouts;
2253 for (size_t attachmentNdx = 0; attachmentNdx < attachmentInfo.size(); attachmentNdx++)
2255 if (!clearValues[attachmentNdx])
2258 const VkImageMemoryBarrier barrier =
2260 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType;
2263 (VkAccessFlags)0, // srcAccessMask
2264 getAllMemoryReadFlags() | VK_ACCESS_TRANSFER_WRITE_BIT, // dstAccessMask
2266 VK_IMAGE_LAYOUT_UNDEFINED, // oldLayout
2267 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // newLayout;
2269 queueIndex, // srcQueueFamilyIndex;
2270 queueIndex, // destQueueFamilyIndex;
2272 attachmentResources[attachmentNdx]->getImage(), // image;
2273 { // subresourceRange;
2274 getImageAspectFlags(attachmentInfo[attachmentNdx].getFormat()), // aspect;
2277 0, // baseArraySlice;
2282 initializeLayouts.push_back(barrier);
2285 if (!initializeLayouts.empty())
2286 vk.cmdPipelineBarrier(commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT,
2287 VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, (VkDependencyFlags)0,
2288 0, (const VkMemoryBarrier*)DE_NULL,
2289 0, (const VkBufferMemoryBarrier*)DE_NULL,
2290 (deUint32)initializeLayouts.size(), &initializeLayouts[0]);
2293 for (size_t attachmentNdx = 0; attachmentNdx < attachmentInfo.size(); attachmentNdx++)
2295 if (!clearValues[attachmentNdx])
2298 const tcu::TextureFormat format = mapVkFormat(attachmentInfo[attachmentNdx].getFormat());
2300 if (hasStencilComponent(format.order) || hasDepthComponent(format.order))
2302 const float clearNan = tcu::Float32::nan().asFloat();
2303 const float clearDepth = hasDepthComponent(format.order) ? clearValues[attachmentNdx]->depthStencil.depth : clearNan;
2304 const deUint32 clearStencil = hasStencilComponent(format.order) ? clearValues[attachmentNdx]->depthStencil.stencil : 0xDEu;
2305 const VkClearDepthStencilValue depthStencil =
2310 const VkImageSubresourceRange range =
2312 (VkImageAspectFlags)((hasDepthComponent(format.order) ? VK_IMAGE_ASPECT_DEPTH_BIT : 0)
2313 | (hasStencilComponent(format.order) ? VK_IMAGE_ASPECT_STENCIL_BIT : 0)),
2320 vk.cmdClearDepthStencilImage(commandBuffer, attachmentResources[attachmentNdx]->getImage(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &depthStencil, 1, &range);
2324 const VkImageSubresourceRange range =
2326 VK_IMAGE_ASPECT_COLOR_BIT, // aspectMask;
2329 0, // baseArrayLayer;
2332 const VkClearColorValue clearColor = clearValues[attachmentNdx]->color;
2334 vk.cmdClearColorImage(commandBuffer, attachmentResources[attachmentNdx]->getImage(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clearColor, 1, &range);
2339 vector<VkImageMemoryBarrier> renderPassLayouts;
2341 for (size_t attachmentNdx = 0; attachmentNdx < attachmentInfo.size(); attachmentNdx++)
2343 const VkImageLayout oldLayout = clearValues[attachmentNdx] ? VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL : VK_IMAGE_LAYOUT_UNDEFINED;
2344 const VkImageMemoryBarrier barrier =
2346 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType;
2349 (oldLayout != VK_IMAGE_LAYOUT_UNDEFINED ? getAllMemoryWriteFlags() : (VkAccessFlags)0), // srcAccessMask
2350 getAllMemoryReadFlags() | getMemoryFlagsForLayout(attachmentInfo[attachmentNdx].getInitialLayout()), // dstAccessMask
2352 oldLayout, // oldLayout
2353 attachmentInfo[attachmentNdx].getInitialLayout(), // newLayout;
2355 queueIndex, // srcQueueFamilyIndex;
2356 queueIndex, // destQueueFamilyIndex;
2358 attachmentResources[attachmentNdx]->getImage(), // image;
2359 { // subresourceRange;
2360 getImageAspectFlags(attachmentInfo[attachmentNdx].getFormat()), // aspect;
2363 0, // baseArraySlice;
2368 renderPassLayouts.push_back(barrier);
2371 if (!renderPassLayouts.empty())
2372 vk.cmdPipelineBarrier(commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT,
2373 VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, (VkDependencyFlags)0,
2374 0, (const VkMemoryBarrier*)DE_NULL,
2375 0, (const VkBufferMemoryBarrier*)DE_NULL,
2376 (deUint32)renderPassLayouts.size(), &renderPassLayouts[0]);
2380 void pushRenderPassCommands (const DeviceInterface& vk,
2381 VkCommandBuffer commandBuffer,
2382 VkRenderPass renderPass,
2383 VkFramebuffer framebuffer,
2384 const vector<de::SharedPtr<SubpassRenderer> >& subpassRenderers,
2385 const UVec2& renderPos,
2386 const UVec2& renderSize,
2387 const vector<Maybe<VkClearValue> >& renderPassClearValues,
2388 TestConfig::RenderTypes render)
2390 const float clearNan = tcu::Float32::nan().asFloat();
2391 vector<VkClearValue> attachmentClearValues;
2393 for (size_t attachmentNdx = 0; attachmentNdx < renderPassClearValues.size(); attachmentNdx++)
2395 if (renderPassClearValues[attachmentNdx])
2396 attachmentClearValues.push_back(*renderPassClearValues[attachmentNdx]);
2398 attachmentClearValues.push_back(makeClearValueColorF32(clearNan, clearNan, clearNan, clearNan));
2402 const VkRect2D renderArea =
2404 { (deInt32)renderPos.x(), (deInt32)renderPos.y() },
2405 { renderSize.x(), renderSize.y() }
2408 for (size_t subpassNdx = 0; subpassNdx < subpassRenderers.size(); subpassNdx++)
2410 const VkSubpassContents contents = subpassRenderers[subpassNdx]->isSecondary() ? VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS : VK_SUBPASS_CONTENTS_INLINE;
2412 if (subpassNdx == 0)
2413 cmdBeginRenderPass(vk, commandBuffer, renderPass, framebuffer, renderArea, (deUint32)attachmentClearValues.size(), attachmentClearValues.empty() ? DE_NULL : &attachmentClearValues[0], contents);
2415 vk.cmdNextSubpass(commandBuffer, contents);
2419 if (contents == VK_SUBPASS_CONTENTS_INLINE)
2421 subpassRenderers[subpassNdx]->pushRenderCommands(vk, commandBuffer);
2423 else if (contents == VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS)
2425 const VkCommandBuffer cmd = subpassRenderers[subpassNdx]->getCommandBuffer();
2426 vk.cmdExecuteCommands(commandBuffer, 1, &cmd);
2429 DE_FATAL("Invalid contents");
2433 vk.cmdEndRenderPass(commandBuffer);
2437 void pushReadImagesToBuffers (const DeviceInterface& vk,
2438 VkCommandBuffer commandBuffer,
2439 deUint32 queueIndex,
2441 const vector<de::SharedPtr<AttachmentResources> >& attachmentResources,
2442 const vector<Attachment>& attachmentInfo,
2443 const vector<bool>& isLazy,
2445 const UVec2& targetSize)
2448 vector<VkImageMemoryBarrier> imageBarriers;
2450 for (size_t attachmentNdx = 0; attachmentNdx < attachmentInfo.size(); attachmentNdx++)
2452 if (isLazy[attachmentNdx])
2455 const VkImageLayout oldLayout = attachmentInfo[attachmentNdx].getFinalLayout();
2456 const VkImageMemoryBarrier barrier =
2458 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
2461 getAllMemoryWriteFlags() | getMemoryFlagsForLayout(oldLayout), // srcAccessMask
2462 getAllMemoryReadFlags(), // dstAccessMask
2464 oldLayout, // oldLayout
2465 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // newLayout
2467 queueIndex, // srcQueueFamilyIndex
2468 queueIndex, // destQueueFamilyIndex
2470 attachmentResources[attachmentNdx]->getImage(), // image
2471 { // subresourceRange
2472 getImageAspectFlags(attachmentInfo[attachmentNdx].getFormat()), // aspect;
2475 0, // baseArraySlice
2480 imageBarriers.push_back(barrier);
2483 if (!imageBarriers.empty())
2484 vk.cmdPipelineBarrier(commandBuffer,
2485 getAllPipelineStageFlags(),
2486 getAllPipelineStageFlags(),
2487 (VkDependencyFlags)0,
2488 0, (const VkMemoryBarrier*)DE_NULL,
2489 0, (const VkBufferMemoryBarrier*)DE_NULL,
2490 (deUint32)imageBarriers.size(), &imageBarriers[0]);
2493 for (size_t attachmentNdx = 0; attachmentNdx < attachmentInfo.size(); attachmentNdx++)
2495 if (isLazy[attachmentNdx])
2498 const tcu::TextureFormat::ChannelOrder order = mapVkFormat(attachmentInfo[attachmentNdx].getFormat()).order;
2499 const VkBufferImageCopy rect =
2502 0, // bufferRowLength
2503 0, // bufferImageHeight
2504 { // imageSubresource
2505 (vk::VkImageAspectFlags)getPrimaryImageAspect(mapVkFormat(attachmentInfo[attachmentNdx].getFormat()).order), // aspect
2510 { 0, 0, 0 }, // imageOffset
2511 { targetSize.x(), targetSize.y(), 1u } // imageExtent
2514 vk.cmdCopyImageToBuffer(commandBuffer, attachmentResources[attachmentNdx]->getImage(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, attachmentResources[attachmentNdx]->getBuffer(), 1, &rect);
2516 if (tcu::TextureFormat::DS == order)
2518 const VkBufferImageCopy stencilRect =
2521 0, // bufferRowLength
2522 0, // bufferImageHeight
2523 { // imageSubresource
2524 VK_IMAGE_ASPECT_STENCIL_BIT, // aspect
2529 { 0, 0, 0 }, // imageOffset
2530 { targetSize.x(), targetSize.y(), 1u } // imageExtent
2533 vk.cmdCopyImageToBuffer(commandBuffer, attachmentResources[attachmentNdx]->getImage(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, attachmentResources[attachmentNdx]->getSecondaryBuffer(), 1, &stencilRect);
2538 vector<VkBufferMemoryBarrier> bufferBarriers;
2540 for (size_t attachmentNdx = 0; attachmentNdx < attachmentInfo.size(); attachmentNdx++)
2542 if (isLazy[attachmentNdx])
2545 const tcu::TextureFormat::ChannelOrder order = mapVkFormat(attachmentInfo[attachmentNdx].getFormat()).order;
2546 const VkBufferMemoryBarrier bufferBarrier =
2548 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
2551 getAllMemoryWriteFlags(),
2552 getAllMemoryReadFlags(),
2557 attachmentResources[attachmentNdx]->getBuffer(),
2559 attachmentResources[attachmentNdx]->getBufferSize()
2562 bufferBarriers.push_back(bufferBarrier);
2564 if (tcu::TextureFormat::DS == order)
2566 const VkBufferMemoryBarrier secondaryBufferBarrier =
2568 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
2571 getAllMemoryWriteFlags(),
2572 getAllMemoryReadFlags(),
2577 attachmentResources[attachmentNdx]->getSecondaryBuffer(),
2579 attachmentResources[attachmentNdx]->getSecondaryBufferSize()
2582 bufferBarriers.push_back(secondaryBufferBarrier);
2586 if (!bufferBarriers.empty())
2587 vk.cmdPipelineBarrier(commandBuffer,
2588 getAllPipelineStageFlags(),
2589 getAllPipelineStageFlags(),
2590 (VkDependencyFlags)0,
2591 0, (const VkMemoryBarrier*)DE_NULL,
2592 (deUint32)bufferBarriers.size(), &bufferBarriers[0],
2593 0, (const VkImageMemoryBarrier*)DE_NULL);
2600 PixelValue (const Maybe<bool>& x = nothing<bool>(),
2601 const Maybe<bool>& y = nothing<bool>(),
2602 const Maybe<bool>& z = nothing<bool>(),
2603 const Maybe<bool>& w = nothing<bool>());
2605 void setUndefined (size_t ndx);
2606 void setValue (size_t ndx, bool value);
2607 Maybe<bool> getValue (size_t ndx) const;
2613 PixelValue::PixelValue (const Maybe<bool>& x,
2614 const Maybe<bool>& y,
2615 const Maybe<bool>& z,
2616 const Maybe<bool>& w)
2619 const Maybe<bool> values[] =
2624 for (size_t ndx = 0; ndx < DE_LENGTH_OF_ARRAY(values); ndx++)
2627 setValue(ndx, *values[ndx]);
2632 DE_ASSERT(m_status <= 0xFFu);
2635 void PixelValue::setUndefined (size_t ndx)
2638 DE_ASSERT(m_status <= 0xFFu);
2640 m_status &= (deUint16)~(0x1u << (deUint16)(ndx * 2));
2641 DE_ASSERT(m_status <= 0xFFu);
2644 void PixelValue::setValue (size_t ndx, bool value)
2647 DE_ASSERT(m_status <= 0xFFu);
2649 m_status |= (deUint16)(0x1u << (ndx * 2));
2652 m_status |= (deUint16)(0x1u << (ndx * 2 + 1));
2654 m_status &= (deUint16)~(0x1u << (deUint16)(ndx * 2 + 1));
2656 DE_ASSERT(m_status <= 0xFFu);
2659 Maybe<bool> PixelValue::getValue (size_t ndx) const
2662 DE_ASSERT(m_status <= 0xFFu);
2664 if ((m_status & (0x1u << (deUint16)(ndx * 2))) != 0)
2666 return just((m_status & (0x1u << (deUint32)(ndx * 2 + 1))) != 0);
2669 return nothing<bool>();
2672 void clearReferenceValues (vector<PixelValue>& values,
2673 const UVec2& targetSize,
2674 const UVec2& offset,
2677 const PixelValue& value)
2679 DE_ASSERT(targetSize.x() * targetSize.y() == (deUint32)values.size());
2680 DE_ASSERT(offset.x() + size.x() <= targetSize.x());
2681 DE_ASSERT(offset.y() + size.y() <= targetSize.y());
2683 for (deUint32 y = offset.y(); y < offset.y() + size.y(); y++)
2684 for (deUint32 x = offset.x(); x < offset.x() + size.x(); x++)
2686 for (int compNdx = 0; compNdx < 4; compNdx++)
2690 if (value.getValue(compNdx))
2691 values[x + y * targetSize.x()].setValue(compNdx, *value.getValue(compNdx));
2693 values[x + y * targetSize.x()].setUndefined(compNdx);
2699 void markUndefined (vector<PixelValue>& values,
2701 const UVec2& targetSize,
2702 const UVec2& offset,
2705 DE_ASSERT(targetSize.x() * targetSize.y() == (deUint32)values.size());
2707 for (deUint32 y = offset.y(); y < offset.y() + size.y(); y++)
2708 for (deUint32 x = offset.x(); x < offset.x() + size.x(); x++)
2710 for (int compNdx = 0; compNdx < 4; compNdx++)
2713 values[x + y * targetSize.x()].setUndefined(compNdx);
2718 PixelValue clearValueToPixelValue (const VkClearValue& value,
2719 const tcu::TextureFormat& format)
2721 const bool isDepthAttachment = hasDepthComponent(format.order);
2722 const bool isStencilAttachment = hasStencilComponent(format.order);
2723 const bool isDepthOrStencilAttachment = isDepthAttachment || isStencilAttachment;
2724 PixelValue pixelValue;
2726 if (isDepthOrStencilAttachment)
2728 if (isDepthAttachment)
2730 if (value.depthStencil.depth == 1.0f)
2731 pixelValue.setValue(0, true);
2732 else if (value.depthStencil.depth == 0.0f)
2733 pixelValue.setValue(0, false);
2735 DE_FATAL("Unknown depth value");
2738 if (isStencilAttachment)
2740 if (value.depthStencil.stencil == 0xFFu)
2741 pixelValue.setValue(1, true);
2742 else if (value.depthStencil.stencil == 0x0u)
2743 pixelValue.setValue(1, false);
2745 DE_FATAL("Unknown stencil value");
2750 const tcu::TextureChannelClass channelClass = tcu::getTextureChannelClass(format.type);
2751 const tcu::BVec4 channelMask = tcu::getTextureFormatChannelMask(format);
2753 switch (channelClass)
2755 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
2756 for (int i = 0; i < 4; i++)
2760 if (value.color.int32[i] == 1)
2761 pixelValue.setValue(i, true);
2762 else if (value.color.int32[i] == 0)
2763 pixelValue.setValue(i, false);
2765 DE_FATAL("Unknown clear color value");
2770 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
2771 for (int i = 0; i < 4; i++)
2775 if (value.color.uint32[i] == 1u)
2776 pixelValue.setValue(i, true);
2777 else if (value.color.uint32[i] == 0u)
2778 pixelValue.setValue(i, false);
2780 DE_FATAL("Unknown clear color value");
2785 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
2786 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
2787 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
2788 for (int i = 0; i < 4; i++)
2792 if (value.color.float32[i] == 1.0f)
2793 pixelValue.setValue(i, true);
2794 else if (value.color.float32[i] == 0.0f)
2795 pixelValue.setValue(i, false);
2797 DE_FATAL("Unknown clear color value");
2803 DE_FATAL("Unknown channel class");
2810 void renderReferenceValues (vector<vector<PixelValue> >& referenceAttachments,
2811 const RenderPass& renderPassInfo,
2812 const UVec2& targetSize,
2813 const vector<Maybe<VkClearValue> >& imageClearValues,
2814 const vector<Maybe<VkClearValue> >& renderPassClearValues,
2815 const vector<SubpassRenderInfo>& subpassRenderInfo,
2816 const UVec2& renderPos,
2817 const UVec2& renderSize)
2819 const vector<Subpass>& subpasses = renderPassInfo.getSubpasses();
2820 vector<bool> attachmentUsed (renderPassInfo.getAttachments().size(), false);
2822 referenceAttachments.resize(renderPassInfo.getAttachments().size());
2824 for (size_t attachmentNdx = 0; attachmentNdx < renderPassInfo.getAttachments().size(); attachmentNdx++)
2826 const Attachment attachment = renderPassInfo.getAttachments()[attachmentNdx];
2827 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
2828 vector<PixelValue>& reference = referenceAttachments[attachmentNdx];
2830 reference.resize(targetSize.x() * targetSize.y());
2832 if (imageClearValues[attachmentNdx])
2833 clearReferenceValues(reference, targetSize, UVec2(0, 0), targetSize, BVec4(true), clearValueToPixelValue(*imageClearValues[attachmentNdx], format));
2836 for (size_t subpassNdx = 0; subpassNdx < subpasses.size(); subpassNdx++)
2838 const Subpass& subpass = subpasses[subpassNdx];
2839 const SubpassRenderInfo& renderInfo = subpassRenderInfo[subpassNdx];
2840 const vector<AttachmentReference>& colorAttachments = subpass.getColorAttachments();
2842 // Apply load op if attachment was used for the first time
2843 for (size_t attachmentNdx = 0; attachmentNdx < colorAttachments.size(); attachmentNdx++)
2845 const deUint32 attachmentIndex = colorAttachments[attachmentNdx].getAttachment();
2847 if (!attachmentUsed[attachmentIndex])
2849 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
2850 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
2851 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
2853 DE_ASSERT(!tcu::hasDepthComponent(format.order));
2854 DE_ASSERT(!tcu::hasStencilComponent(format.order));
2856 if (attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_CLEAR)
2857 clearReferenceValues(reference, targetSize, renderPos, renderSize, BVec4(true), clearValueToPixelValue(*renderPassClearValues[attachmentIndex], format));
2858 else if (attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE)
2859 markUndefined(reference, BVec4(true), targetSize, renderPos, renderSize);
2861 attachmentUsed[attachmentIndex] = true;
2865 // Apply load op to depth/stencil attachment if it was used for the first time
2866 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED)
2868 const deUint32 attachmentIndex = subpass.getDepthStencilAttachment().getAttachment();
2870 // Apply load op if attachment was used for the first time
2871 if (!attachmentUsed[attachmentIndex])
2873 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
2874 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
2875 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
2877 if (tcu::hasDepthComponent(format.order))
2879 if (attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_CLEAR)
2880 clearReferenceValues(reference, targetSize, renderPos, renderSize, BVec4(true, false, false, false), clearValueToPixelValue(*renderPassClearValues[attachmentIndex], format));
2881 else if (attachment.getLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE)
2882 markUndefined(reference, BVec4(true, false, false, false), targetSize, renderPos, renderSize);
2885 if (tcu::hasStencilComponent(format.order))
2887 if (attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_CLEAR)
2888 clearReferenceValues(reference, targetSize, renderPos, renderSize, BVec4(false, true, false, false), clearValueToPixelValue(*renderPassClearValues[attachmentIndex], format));
2889 else if (attachment.getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_DONT_CARE)
2890 markUndefined(reference, BVec4(false, true, false, false), targetSize, renderPos, renderSize);
2893 attachmentUsed[attachmentIndex] = true;
2897 for (size_t colorClearNdx = 0; colorClearNdx < renderInfo.getColorClears().size(); colorClearNdx++)
2899 const ColorClear& colorClear = renderInfo.getColorClears()[colorClearNdx];
2900 const UVec2 offset = colorClear.getOffset();
2901 const UVec2 size = colorClear.getSize();
2902 const deUint32 attachmentIndex = subpass.getColorAttachments()[colorClearNdx].getAttachment();
2903 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
2904 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
2905 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
2908 value.color = colorClear.getColor();
2910 clearReferenceValues(reference, targetSize, offset, size, BVec4(true), clearValueToPixelValue(value, format));
2913 if (renderInfo.getDepthStencilClear())
2915 const DepthStencilClear& dsClear = *renderInfo.getDepthStencilClear();
2916 const UVec2 offset = dsClear.getOffset();
2917 const UVec2 size = dsClear.getSize();
2918 const deUint32 attachmentIndex = subpass.getDepthStencilAttachment().getAttachment();
2919 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
2920 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
2921 const bool hasStencil = tcu::hasStencilComponent(format.order);
2922 const bool hasDepth = tcu::hasDepthComponent(format.order);
2923 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
2926 value.depthStencil.depth = dsClear.getDepth();
2927 value.depthStencil.stencil = dsClear.getStencil();
2929 clearReferenceValues(reference, targetSize, offset, size, BVec4(hasDepth, hasStencil, false, false), clearValueToPixelValue(value, format));
2932 if (renderInfo.getRenderQuad())
2934 const RenderQuad& renderQuad = *renderInfo.getRenderQuad();
2935 const Vec2 posA = renderQuad.getCornerA();
2936 const Vec2 posB = renderQuad.getCornerB();
2937 const Vec2 origin = Vec2((float)renderInfo.getViewportOffset().x(), (float)renderInfo.getViewportOffset().y()) + Vec2((float)renderInfo.getViewportSize().x(), (float)renderInfo.getViewportSize().y()) / Vec2(2.0f);
2938 const Vec2 p = Vec2((float)renderInfo.getViewportSize().x(), (float)renderInfo.getViewportSize().y()) / Vec2(2.0f);
2939 const IVec2 posAI (deRoundFloatToInt32(origin.x() + (p.x() * posA.x())),
2940 deRoundFloatToInt32(origin.y() + (p.y() * posA.y())));
2941 const IVec2 posBI (deRoundFloatToInt32(origin.x() + (p.x() * posB.x())),
2942 deRoundFloatToInt32(origin.y() + (p.y() * posB.y())));
2944 DE_ASSERT(posAI.x() < posBI.x());
2945 DE_ASSERT(posAI.y() < posBI.y());
2947 if (subpass.getInputAttachments().empty())
2949 for (size_t attachmentRefNdx = 0; attachmentRefNdx < subpass.getColorAttachments().size(); attachmentRefNdx++)
2951 const deUint32 attachmentIndex = subpass.getColorAttachments()[attachmentRefNdx].getAttachment();
2952 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
2953 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
2954 const tcu::BVec4 channelMask = tcu::getTextureFormatChannelMask(format);
2955 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
2957 for (int y = posAI.y(); y < (int)posBI.y(); y++)
2958 for (int x = posAI.x(); x < (int)posBI.x(); x++)
2960 for (int compNdx = 0; compNdx < 4; compNdx++)
2962 const size_t index = subpassNdx + attachmentIndex + compNdx;
2963 const BoolOp op = boolOpFromIndex(index);
2964 const bool boolX = x % 2 == (int)(index % 2);
2965 const bool boolY = y % 2 == (int)((index / 2) % 2);
2967 if (channelMask[compNdx])
2968 reference[x + y * targetSize.x()].setValue(compNdx, performBoolOp(op, boolX, boolY));
2973 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED)
2975 const deUint32 attachmentIndex = subpass.getDepthStencilAttachment().getAttachment();
2976 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
2977 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
2978 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
2980 for (int y = posAI.y(); y < (int)posBI.y(); y++)
2981 for (int x = posAI.x(); x < (int)posBI.x(); x++)
2983 if (tcu::hasDepthComponent(format.order))
2985 const size_t index = subpassNdx + 1;
2986 const BoolOp op = boolOpFromIndex(index);
2987 const bool boolX = x % 2 == (int)(index % 2);
2988 const bool boolY = y % 2 == (int)((index / 2) % 2);
2990 reference[x + y * targetSize.x()].setValue(0, performBoolOp(op, boolX, boolY));
2993 if (tcu::hasStencilComponent(format.order))
2995 const size_t index = subpassNdx;
2996 reference[x + y * targetSize.x()].setValue(1, (index % 2) == 0);
3003 size_t outputComponentCount = 0;
3004 vector<Maybe<bool> > inputs;
3006 DE_ASSERT(posAI.x() < posBI.x());
3007 DE_ASSERT(posAI.y() < posBI.y());
3009 for (size_t attachmentRefNdx = 0; attachmentRefNdx < subpass.getColorAttachments().size(); attachmentRefNdx++)
3011 const deUint32 attachmentIndex = subpass.getColorAttachments()[attachmentRefNdx].getAttachment();
3012 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3013 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3014 const int componentCount = tcu::getNumUsedChannels(format.order);
3016 outputComponentCount += (size_t)componentCount;
3019 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED)
3020 outputComponentCount++;
3022 for (int y = posAI.y(); y < (int)posBI.y(); y++)
3023 for (int x = posAI.x(); x < (int)posBI.x(); x++)
3025 for (size_t inputAttachmentNdx = 0; inputAttachmentNdx < subpass.getInputAttachments().size(); inputAttachmentNdx++)
3027 const deUint32 attachmentIndex = subpass.getInputAttachments()[inputAttachmentNdx].getAttachment();
3028 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3029 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3030 const int componentCount = tcu::getNumUsedChannels(format.order);
3032 for (int compNdx = 0; compNdx < componentCount; compNdx++)
3033 inputs.push_back(referenceAttachments[attachmentIndex][x + y * targetSize.x()].getValue(compNdx));
3036 const size_t inputsPerOutput = inputs.size() >= outputComponentCount
3037 ? ((inputs.size() / outputComponentCount)
3038 + ((inputs.size() % outputComponentCount) != 0 ? 1 : 0))
3041 size_t outputValueNdx = 0;
3043 for (size_t attachmentRefNdx = 0; attachmentRefNdx < subpass.getColorAttachments().size(); attachmentRefNdx++)
3045 const deUint32 attachmentIndex = subpass.getColorAttachments()[attachmentRefNdx].getAttachment();
3046 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3047 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3048 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3049 const int componentCount = tcu::getNumUsedChannels(format.order);
3051 for (int compNdx = 0; compNdx < componentCount; compNdx++)
3053 const size_t index = subpassNdx + attachmentIndex + outputValueNdx;
3054 const BoolOp op = boolOpFromIndex(index);
3055 const bool boolX = x % 2 == (int)(index % 2);
3056 const bool boolY = y % 2 == (int)((index / 2) % 2);
3057 Maybe<bool> output = tcu::just(performBoolOp(op, boolX, boolY));
3059 for (size_t i = 0; i < inputsPerOutput; i++)
3063 else if (!inputs[((outputValueNdx + compNdx) * inputsPerOutput + i) % inputs.size()])
3064 output = tcu::nothing<bool>();
3066 output = (*output) == (*inputs[((outputValueNdx + compNdx) * inputsPerOutput + i) % inputs.size()]);
3070 reference[x + y * targetSize.x()].setValue(compNdx, *output);
3072 reference[x + y * targetSize.x()].setUndefined(compNdx);
3075 outputValueNdx += componentCount;
3078 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED)
3080 const deUint32 attachmentIndex = subpass.getDepthStencilAttachment().getAttachment();
3081 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3082 const size_t index = subpassNdx + attachmentIndex;
3083 const BoolOp op = boolOpFromIndex(index);
3084 const bool boolX = x % 2 == (int)(index % 2);
3085 const bool boolY = y % 2 == (int)((index / 2) % 2);
3086 Maybe<bool> output = tcu::just(performBoolOp(op, boolX, boolY));
3088 for (size_t i = 0; i < inputsPerOutput; i++)
3092 else if (inputs[(outputValueNdx * inputsPerOutput + i) % inputs.size()])
3093 output = (*output) == (*inputs[(outputValueNdx * inputsPerOutput + i) % inputs.size()]);
3095 output = tcu::nothing<bool>();
3099 reference[x + y * targetSize.x()].setValue(0, *output);
3101 reference[x + y * targetSize.x()].setUndefined(0);
3107 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED)
3109 const deUint32 attachmentIndex = subpass.getDepthStencilAttachment().getAttachment();
3110 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentIndex];
3111 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3112 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3114 if (tcu::hasStencilComponent(format.order))
3116 for (int y = posAI.y(); y < (int)posBI.y(); y++)
3117 for (int x = posAI.x(); x < (int)posBI.x(); x++)
3119 const size_t index = subpassNdx;
3120 reference[x + y * targetSize.x()].setValue(1, (index % 2) == 0);
3128 // Mark all attachments that were used but not stored as undefined
3129 for (size_t attachmentIndex = 0; attachmentIndex < renderPassInfo.getAttachments().size(); attachmentIndex++)
3131 const Attachment attachment = renderPassInfo.getAttachments()[attachmentIndex];
3132 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3133 vector<PixelValue>& reference = referenceAttachments[attachmentIndex];
3134 const bool isStencilAttachment = hasStencilComponent(format.order);
3135 const bool isDepthOrStencilAttachment = hasDepthComponent(format.order) || isStencilAttachment;
3137 if (attachmentUsed[attachmentIndex] && renderPassInfo.getAttachments()[attachmentIndex].getStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE)
3139 if (isDepthOrStencilAttachment)
3140 markUndefined(reference, BVec4(true, false, false, false), targetSize, renderPos, renderSize);
3142 markUndefined(reference, BVec4(true), targetSize, renderPos, renderSize);
3145 if (attachmentUsed[attachmentIndex] && isStencilAttachment && renderPassInfo.getAttachments()[attachmentIndex].getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_DONT_CARE)
3146 markUndefined(reference, BVec4(false, true, false, false), targetSize, renderPos, renderSize);
3150 void renderReferenceImagesFromValues (vector<tcu::TextureLevel>& referenceImages,
3151 const vector<vector<PixelValue> >& referenceValues,
3152 const UVec2& targetSize,
3153 const RenderPass& renderPassInfo)
3155 referenceImages.resize(referenceValues.size());
3157 for (size_t attachmentNdx = 0; attachmentNdx < renderPassInfo.getAttachments().size(); attachmentNdx++)
3159 const Attachment attachment = renderPassInfo.getAttachments()[attachmentNdx];
3160 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3161 const vector<PixelValue>& reference = referenceValues[attachmentNdx];
3162 const bool hasDepth = tcu::hasDepthComponent(format.order);
3163 const bool hasStencil = tcu::hasStencilComponent(format.order);
3164 const bool hasDepthOrStencil = hasDepth || hasStencil;
3165 tcu::TextureLevel& referenceImage = referenceImages[attachmentNdx];
3167 referenceImage.setStorage(format, targetSize.x(), targetSize.y());
3169 if (hasDepthOrStencil)
3173 const PixelBufferAccess depthAccess (tcu::getEffectiveDepthStencilAccess(referenceImage.getAccess(), tcu::Sampler::MODE_DEPTH));
3175 for (deUint32 y = 0; y < targetSize.y(); y++)
3176 for (deUint32 x = 0; x < targetSize.x(); x++)
3178 if (reference[x + y * targetSize.x()].getValue(0))
3180 if (*reference[x + y * targetSize.x()].getValue(0))
3181 depthAccess.setPixDepth(1.0f, x, y);
3183 depthAccess.setPixDepth(0.0f, x, y);
3185 else // Fill with 3x3 grid
3186 depthAccess.setPixDepth(((x / 3) % 2) == ((y / 3) % 2) ? 0.33f : 0.66f, x, y);
3192 const PixelBufferAccess stencilAccess (tcu::getEffectiveDepthStencilAccess(referenceImage.getAccess(), tcu::Sampler::MODE_STENCIL));
3194 for (deUint32 y = 0; y < targetSize.y(); y++)
3195 for (deUint32 x = 0; x < targetSize.x(); x++)
3197 if (reference[x + y * targetSize.x()].getValue(1))
3199 if (*reference[x + y * targetSize.x()].getValue(1))
3200 stencilAccess.setPixStencil(0xFFu, x, y);
3202 stencilAccess.setPixStencil(0x0u, x, y);
3204 else // Fill with 3x3 grid
3205 stencilAccess.setPixStencil(((x / 3) % 2) == ((y / 3) % 2) ? 85 : 170, x, y);
3211 for (deUint32 y = 0; y < targetSize.y(); y++)
3212 for (deUint32 x = 0; x < targetSize.x(); x++)
3216 for (int compNdx = 0; compNdx < 4; compNdx++)
3218 if (reference[x + y * targetSize.x()].getValue(compNdx))
3220 if (*reference[x + y * targetSize.x()].getValue(compNdx))
3221 color[compNdx] = 1.0f;
3223 color[compNdx] = 0.0f;
3225 else // Fill with 3x3 grid
3226 color[compNdx] = ((compNdx + (x / 3)) % 2) == ((y / 3) % 2) ? 0.33f : 0.66f;
3229 referenceImage.getAccess().setPixel(color, x, y);
3235 bool verifyColorAttachment (const vector<PixelValue>& reference,
3236 const ConstPixelBufferAccess& result,
3237 const PixelBufferAccess& errorImage)
3239 const Vec4 red (1.0f, 0.0f, 0.0f, 1.0f);
3240 const Vec4 green (0.0f, 1.0f, 0.0f, 1.0f);
3243 DE_ASSERT(result.getWidth() * result.getHeight() == (int)reference.size());
3244 DE_ASSERT(result.getWidth() == errorImage.getWidth());
3245 DE_ASSERT(result.getHeight() == errorImage.getHeight());
3247 for (int y = 0; y < result.getHeight(); y++)
3248 for (int x = 0; x < result.getWidth(); x++)
3250 const Vec4 resultColor = result.getPixel(x, y);
3251 const PixelValue& referenceValue = reference[x + y * result.getWidth()];
3252 bool pixelOk = true;
3254 for (int compNdx = 0; compNdx < 4; compNdx++)
3256 const Maybe<bool> maybeValue = referenceValue.getValue(compNdx);
3260 const bool value = *maybeValue;
3262 if ((value && (resultColor[compNdx] != 1.0f))
3263 || (!value && resultColor[compNdx] != 0.0f))
3270 errorImage.setPixel(red, x, y);
3274 errorImage.setPixel(green, x, y);
3280 bool verifyDepthAttachment (const vector<PixelValue>& reference,
3281 const ConstPixelBufferAccess& result,
3282 const PixelBufferAccess& errorImage)
3284 const Vec4 red (1.0f, 0.0f, 0.0f, 1.0f);
3285 const Vec4 green (0.0f, 1.0f, 0.0f, 1.0f);
3288 DE_ASSERT(result.getWidth() * result.getHeight() == (int)reference.size());
3289 DE_ASSERT(result.getWidth() == errorImage.getWidth());
3290 DE_ASSERT(result.getHeight() == errorImage.getHeight());
3292 for (int y = 0; y < result.getHeight(); y++)
3293 for (int x = 0; x < result.getWidth(); x++)
3295 bool pixelOk = true;
3297 const float resultDepth = result.getPixDepth(x, y);
3298 const PixelValue& referenceValue = reference[x + y * result.getWidth()];
3299 const Maybe<bool> maybeValue = referenceValue.getValue(0);
3303 const bool value = *maybeValue;
3305 if ((value && (resultDepth != 1.0f))
3306 || (!value && resultDepth != 0.0f))
3312 errorImage.setPixel(red, x, y);
3316 errorImage.setPixel(green, x, y);
3322 bool verifyStencilAttachment (const vector<PixelValue>& reference,
3323 const ConstPixelBufferAccess& result,
3324 const PixelBufferAccess& errorImage)
3326 const Vec4 red (1.0f, 0.0f, 0.0f, 1.0f);
3327 const Vec4 green (0.0f, 1.0f, 0.0f, 1.0f);
3330 DE_ASSERT(result.getWidth() * result.getHeight() == (int)reference.size());
3331 DE_ASSERT(result.getWidth() == errorImage.getWidth());
3332 DE_ASSERT(result.getHeight() == errorImage.getHeight());
3334 for (int y = 0; y < result.getHeight(); y++)
3335 for (int x = 0; x < result.getWidth(); x++)
3337 bool pixelOk = true;
3339 const deUint32 resultStencil = result.getPixStencil(x, y);
3340 const PixelValue& referenceValue = reference[x + y * result.getWidth()];
3341 const Maybe<bool> maybeValue = referenceValue.getValue(1);
3345 const bool value = *maybeValue;
3347 if ((value && (resultStencil != 0xFFu))
3348 || (!value && resultStencil != 0x0u))
3354 errorImage.setPixel(red, x, y);
3358 errorImage.setPixel(green, x, y);
3364 bool logAndVerifyImages (TestLog& log,
3365 const DeviceInterface& vk,
3367 const vector<de::SharedPtr<AttachmentResources> >& attachmentResources,
3368 const vector<bool>& attachmentIsLazy,
3369 const RenderPass& renderPassInfo,
3370 const vector<Maybe<VkClearValue> >& renderPassClearValues,
3371 const vector<Maybe<VkClearValue> >& imageClearValues,
3372 const vector<SubpassRenderInfo>& subpassRenderInfo,
3373 const UVec2& targetSize,
3374 const TestConfig& config)
3376 vector<vector<PixelValue> > referenceValues;
3377 vector<tcu::TextureLevel> referenceAttachments;
3380 log << TestLog::Message << "Reference images fill undefined pixels with 3x3 grid pattern." << TestLog::EndMessage;
3382 renderReferenceValues(referenceValues, renderPassInfo, targetSize, imageClearValues, renderPassClearValues, subpassRenderInfo, config.renderPos, config.renderSize);
3383 renderReferenceImagesFromValues(referenceAttachments, referenceValues, targetSize, renderPassInfo);
3385 for (size_t attachmentNdx = 0; attachmentNdx < renderPassInfo.getAttachments().size(); attachmentNdx++)
3387 if (!attachmentIsLazy[attachmentNdx])
3389 const Attachment attachment = renderPassInfo.getAttachments()[attachmentNdx];
3390 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3392 if (tcu::hasDepthComponent(format.order) && tcu::hasStencilComponent(format.order))
3394 const tcu::TextureFormat depthFormat = getDepthCopyFormat(attachment.getFormat());
3395 const VkDeviceSize depthBufferSize = targetSize.x() * targetSize.y() * depthFormat.getPixelSize();
3396 void* const depthPtr = attachmentResources[attachmentNdx]->getResultMemory().getHostPtr();
3398 const tcu::TextureFormat stencilFormat = getStencilCopyFormat(attachment.getFormat());
3399 const VkDeviceSize stencilBufferSize = targetSize.x() * targetSize.y() * stencilFormat.getPixelSize();
3400 void* const stencilPtr = attachmentResources[attachmentNdx]->getSecondaryResultMemory().getHostPtr();
3402 const VkMappedMemoryRange ranges[] =
3405 VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, // sType;
3407 attachmentResources[attachmentNdx]->getResultMemory().getMemory(), // mem;
3408 attachmentResources[attachmentNdx]->getResultMemory().getOffset(), // offset;
3409 depthBufferSize // size;
3412 VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, // sType;
3414 attachmentResources[attachmentNdx]->getSecondaryResultMemory().getMemory(), // mem;
3415 attachmentResources[attachmentNdx]->getSecondaryResultMemory().getOffset(), // offset;
3416 stencilBufferSize // size;
3419 VK_CHECK(vk.invalidateMappedMemoryRanges(device, 2u, ranges));
3422 const ConstPixelBufferAccess depthAccess (depthFormat, targetSize.x(), targetSize.y(), 1, depthPtr);
3423 const ConstPixelBufferAccess stencilAccess (stencilFormat, targetSize.x(), targetSize.y(), 1, stencilPtr);
3424 tcu::TextureLevel depthErrorImage (tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), targetSize.x(), targetSize.y());
3425 tcu::TextureLevel stencilErrorImage (tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), targetSize.x(), targetSize.y());
3427 log << TestLog::Image("Attachment" + de::toString(attachmentNdx) + "Depth", "Attachment " + de::toString(attachmentNdx) + " Depth", depthAccess);
3428 log << TestLog::Image("Attachment" + de::toString(attachmentNdx) + "Stencil", "Attachment " + de::toString(attachmentNdx) + " Stencil", stencilAccess);
3430 log << TestLog::Image("AttachmentReference" + de::toString(attachmentNdx), "Attachment reference " + de::toString(attachmentNdx), referenceAttachments[attachmentNdx].getAccess());
3432 if (renderPassInfo.getAttachments()[attachmentNdx].getStoreOp() == VK_ATTACHMENT_STORE_OP_STORE
3433 && !verifyDepthAttachment(referenceValues[attachmentNdx], depthAccess, depthErrorImage.getAccess()))
3435 log << TestLog::Image("DepthAttachmentError" + de::toString(attachmentNdx), "Depth Attachment Error " + de::toString(attachmentNdx), depthErrorImage.getAccess());
3439 if (renderPassInfo.getAttachments()[attachmentNdx].getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_STORE
3440 && !verifyStencilAttachment(referenceValues[attachmentNdx], stencilAccess, stencilErrorImage.getAccess()))
3442 log << TestLog::Image("StencilAttachmentError" + de::toString(attachmentNdx), "Stencil Attachment Error " + de::toString(attachmentNdx), stencilErrorImage.getAccess());
3449 const VkDeviceSize bufferSize = targetSize.x() * targetSize.y() * format.getPixelSize();
3450 void* const ptr = attachmentResources[attachmentNdx]->getResultMemory().getHostPtr();
3452 const VkMappedMemoryRange range =
3454 VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, // sType;
3456 attachmentResources[attachmentNdx]->getResultMemory().getMemory(), // mem;
3457 attachmentResources[attachmentNdx]->getResultMemory().getOffset(), // offset;
3460 VK_CHECK(vk.invalidateMappedMemoryRanges(device, 1u, &range));
3462 if (tcu::hasDepthComponent(format.order))
3464 const ConstPixelBufferAccess access (format, targetSize.x(), targetSize.y(), 1, ptr);
3465 tcu::TextureLevel errorImage (tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), targetSize.x(), targetSize.y());
3467 log << TestLog::Image("Attachment" + de::toString(attachmentNdx), "Attachment " + de::toString(attachmentNdx), access);
3468 log << TestLog::Image("AttachmentReference" + de::toString(attachmentNdx), "Attachment reference " + de::toString(attachmentNdx), referenceAttachments[attachmentNdx].getAccess());
3470 if ((renderPassInfo.getAttachments()[attachmentNdx].getStoreOp() == VK_ATTACHMENT_STORE_OP_STORE || renderPassInfo.getAttachments()[attachmentNdx].getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_STORE)
3471 && !verifyDepthAttachment(referenceValues[attachmentNdx], access, errorImage.getAccess()))
3473 log << TestLog::Image("AttachmentError" + de::toString(attachmentNdx), "Attachment Error " + de::toString(attachmentNdx), errorImage.getAccess());
3477 else if (tcu::hasStencilComponent(format.order))
3479 const ConstPixelBufferAccess access (format, targetSize.x(), targetSize.y(), 1, ptr);
3480 tcu::TextureLevel errorImage (tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), targetSize.x(), targetSize.y());
3482 log << TestLog::Image("Attachment" + de::toString(attachmentNdx), "Attachment " + de::toString(attachmentNdx), access);
3483 log << TestLog::Image("AttachmentReference" + de::toString(attachmentNdx), "Attachment reference " + de::toString(attachmentNdx), referenceAttachments[attachmentNdx].getAccess());
3485 if ((renderPassInfo.getAttachments()[attachmentNdx].getStoreOp() == VK_ATTACHMENT_STORE_OP_STORE || renderPassInfo.getAttachments()[attachmentNdx].getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_STORE)
3486 && !verifyStencilAttachment(referenceValues[attachmentNdx], access, errorImage.getAccess()))
3488 log << TestLog::Image("AttachmentError" + de::toString(attachmentNdx), "Attachment Error " + de::toString(attachmentNdx), errorImage.getAccess());
3494 const ConstPixelBufferAccess access (format, targetSize.x(), targetSize.y(), 1, ptr);
3495 tcu::TextureLevel errorImage (tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8), targetSize.x(), targetSize.y());
3497 log << TestLog::Image("Attachment" + de::toString(attachmentNdx), "Attachment " + de::toString(attachmentNdx), access);
3498 log << TestLog::Image("AttachmentReference" + de::toString(attachmentNdx), "Attachment reference " + de::toString(attachmentNdx), referenceAttachments[attachmentNdx].getAccess());
3500 if ((renderPassInfo.getAttachments()[attachmentNdx].getStoreOp() == VK_ATTACHMENT_STORE_OP_STORE || renderPassInfo.getAttachments()[attachmentNdx].getStencilStoreOp() == VK_ATTACHMENT_STORE_OP_STORE)
3501 && !verifyColorAttachment(referenceValues[attachmentNdx], access, errorImage.getAccess()))
3503 log << TestLog::Image("AttachmentError" + de::toString(attachmentNdx), "Attachment Error " + de::toString(attachmentNdx), errorImage.getAccess());
3514 std::string getInputAttachmentType (VkFormat vkFormat)
3516 const tcu::TextureFormat format = mapVkFormat(vkFormat);
3517 const tcu::TextureChannelClass channelClass = tcu::getTextureChannelClass(format.type);
3519 switch (channelClass)
3521 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
3522 return "isubpassInput";
3524 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
3525 return "usubpassInput";
3527 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
3528 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
3529 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
3530 return "subpassInput";
3533 DE_FATAL("Unknown channel class");
3538 std::string getAttachmentType (VkFormat vkFormat)
3540 const tcu::TextureFormat format = mapVkFormat(vkFormat);
3541 const tcu::TextureChannelClass channelClass = tcu::getTextureChannelClass(format.type);
3543 switch (channelClass)
3545 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
3548 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
3551 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
3552 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
3553 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
3557 DE_FATAL("Unknown channel class");
3562 void createTestShaders (SourceCollections& dst, TestConfig config)
3564 if (config.renderTypes & TestConfig::RENDERTYPES_DRAW)
3566 const vector<Subpass>& subpasses = config.renderPass.getSubpasses();
3568 for (size_t subpassNdx = 0; subpassNdx < subpasses.size(); subpassNdx++)
3570 const Subpass& subpass = subpasses[subpassNdx];
3571 deUint32 inputAttachmentBinding = 0;
3572 std::ostringstream vertexShader;
3573 std::ostringstream fragmentShader;
3575 vertexShader << "#version 310 es\n"
3576 << "layout(location = 0) in highp vec2 a_position;\n"
3577 << "void main (void) {\n"
3578 << "\tgl_Position = vec4(a_position, 1.0, 1.0);\n"
3581 fragmentShader << "#version 310 es\n"
3582 << "precision highp float;\n";
3584 for (size_t attachmentNdx = 0; attachmentNdx < subpass.getInputAttachments().size(); attachmentNdx++)
3586 const deUint32 attachmentIndex = subpass.getInputAttachments()[attachmentNdx].getAttachment();
3587 const Attachment attachment = config.renderPass.getAttachments()[attachmentIndex];
3588 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3589 const bool isDepthFormat = tcu::hasDepthComponent(format.order);
3590 const bool isStencilFormat = tcu::hasStencilComponent(format.order);
3592 if (isDepthFormat || isStencilFormat)
3596 fragmentShader << "layout(input_attachment_index = " << attachmentNdx << ", set=0, binding=" << inputAttachmentBinding << ") uniform highp subpassInput i_depth" << attachmentNdx << ";\n";
3597 inputAttachmentBinding++;
3600 if (isStencilFormat)
3602 fragmentShader << "layout(input_attachment_index = " << attachmentNdx << ", set=0, binding=" << inputAttachmentBinding << ") uniform highp usubpassInput i_stencil" << attachmentNdx << ";\n";
3603 inputAttachmentBinding++;
3608 const std::string attachmentType = getInputAttachmentType(attachment.getFormat());
3610 fragmentShader << "layout(input_attachment_index = " << attachmentNdx << ", set=0, binding=" << inputAttachmentBinding << ") uniform highp " << attachmentType << " i_color" << attachmentNdx << ";\n";
3611 inputAttachmentBinding++;
3615 for (size_t attachmentNdx = 0; attachmentNdx < subpass.getColorAttachments().size(); attachmentNdx++)
3617 const std::string attachmentType = getAttachmentType(config.renderPass.getAttachments()[subpass.getColorAttachments()[attachmentNdx].getAttachment()].getFormat());
3618 fragmentShader << "layout(location = " << attachmentNdx << ") out highp " << attachmentType << " o_color" << attachmentNdx << ";\n";
3621 fragmentShader << "void main (void) {\n";
3623 if (subpass.getInputAttachments().empty())
3625 for (size_t attachmentNdx = 0; attachmentNdx < subpass.getColorAttachments().size(); attachmentNdx++)
3627 const deUint32 attachmentIndex = subpass.getColorAttachments()[attachmentNdx].getAttachment();
3628 const std::string attachmentType = getAttachmentType(config.renderPass.getAttachments()[attachmentIndex].getFormat());
3630 fragmentShader << "\to_color" << attachmentNdx << " = " << attachmentType << "(vec4(";
3632 for (size_t compNdx = 0; compNdx < 4; compNdx++)
3634 const size_t index = subpassNdx + attachmentIndex + compNdx;
3635 const BoolOp op = boolOpFromIndex(index);
3638 fragmentShader << ",\n\t\t";
3640 fragmentShader << "((int(gl_FragCoord.x) % 2 == " << (index % 2)
3641 << ") " << boolOpToString(op) << " ("
3642 << "int(gl_FragCoord.y) % 2 == " << ((index / 2) % 2)
3643 << ") ? 1.0 : 0.0)";
3646 fragmentShader << "));\n";
3649 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED)
3651 const size_t index = subpassNdx + 1;
3652 const BoolOp op = boolOpFromIndex(index);
3654 fragmentShader << "\tgl_FragDepth = ((int(gl_FragCoord.x) % 2 == " << (index % 2)
3655 << ") " << boolOpToString(op) << " ("
3656 << "int(gl_FragCoord.y) % 2 == " << ((index / 2) % 2)
3657 << ") ? 1.0 : 0.0);\n";
3662 size_t inputComponentCount = 0;
3663 size_t outputComponentCount = 0;
3665 for (size_t attachmentNdx = 0; attachmentNdx < subpass.getInputAttachments().size(); attachmentNdx++)
3667 const deUint32 attachmentIndex = subpass.getInputAttachments()[attachmentNdx].getAttachment();
3668 const Attachment attachment = config.renderPass.getAttachments()[attachmentIndex];
3669 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3670 const size_t componentCount = (size_t)tcu::getNumUsedChannels(format.order);
3672 inputComponentCount += componentCount;
3675 for (size_t attachmentNdx = 0; attachmentNdx < subpass.getColorAttachments().size(); attachmentNdx++)
3677 const deUint32 attachmentIndex = subpass.getColorAttachments()[attachmentNdx].getAttachment();
3678 const Attachment attachment = config.renderPass.getAttachments()[attachmentIndex];
3679 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3680 const size_t componentCount = (size_t)tcu::getNumUsedChannels(format.order);
3682 outputComponentCount += componentCount;
3685 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED)
3686 outputComponentCount++;
3688 const size_t inputsPerOutput = inputComponentCount >= outputComponentCount
3689 ? ((inputComponentCount / outputComponentCount)
3690 + ((inputComponentCount % outputComponentCount) != 0 ? 1 : 0))
3693 fragmentShader << "\tbool inputs[" << inputComponentCount << "];\n"
3694 "\tbool outputs[" << outputComponentCount << "];\n";
3696 size_t inputValueNdx = 0;
3698 for (size_t attachmentNdx = 0; attachmentNdx < subpass.getInputAttachments().size(); attachmentNdx++)
3700 const char* const components[] =
3704 const deUint32 attachmentIndex = subpass.getInputAttachments()[attachmentNdx].getAttachment();
3705 const Attachment attachment = config.renderPass.getAttachments()[attachmentIndex];
3706 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3707 const size_t componentCount = (size_t)tcu::getNumUsedChannels(format.order);
3708 const bool isDepthFormat = tcu::hasDepthComponent(format.order);
3709 const bool isStencilFormat = tcu::hasStencilComponent(format.order);
3711 if (isDepthFormat || isStencilFormat)
3715 fragmentShader << "\tinputs[" << inputValueNdx << "] = 1.0 == float(subpassLoad(i_depth" << attachmentNdx << ").x);\n";
3719 if (isStencilFormat)
3721 fragmentShader << "\tinputs[" << inputValueNdx << "] = 255u == subpassLoad(i_stencil" << attachmentNdx << ").x;\n";
3727 for (size_t compNdx = 0; compNdx < componentCount; compNdx++)
3729 fragmentShader << "\tinputs[" << inputValueNdx << "] = 1.0 == float(subpassLoad(i_color" << attachmentNdx << ")." << components[compNdx] << ");\n";
3735 size_t outputValueNdx = 0;
3737 for (size_t attachmentNdx = 0; attachmentNdx < subpass.getColorAttachments().size(); attachmentNdx++)
3739 const deUint32 attachmentIndex = subpass.getColorAttachments()[attachmentNdx].getAttachment();
3740 const Attachment attachment = config.renderPass.getAttachments()[attachmentIndex];
3741 const std::string attachmentType = getAttachmentType(config.renderPass.getAttachments()[attachmentIndex].getFormat());
3742 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
3743 const size_t componentCount = (size_t)tcu::getNumUsedChannels(format.order);
3745 for (size_t compNdx = 0; compNdx < componentCount; compNdx++)
3747 const size_t index = subpassNdx + attachmentIndex + outputValueNdx;
3748 const BoolOp op = boolOpFromIndex(index);
3750 fragmentShader << "\toutputs[" << outputValueNdx + compNdx << "] = "
3751 << "(int(gl_FragCoord.x) % 2 == " << (index % 2)
3752 << ") " << boolOpToString(op) << " ("
3753 << "int(gl_FragCoord.y) % 2 == " << ((index / 2) % 2)
3756 for (size_t i = 0; i < inputsPerOutput; i++)
3757 fragmentShader << "\toutputs[" << outputValueNdx + compNdx << "] = outputs[" << outputValueNdx + compNdx << "] == inputs[" << ((outputValueNdx + compNdx) * inputsPerOutput + i) % inputComponentCount << "];\n";
3760 fragmentShader << "\to_color" << attachmentNdx << " = " << attachmentType << "(";
3762 for (size_t compNdx = 0; compNdx < 4; compNdx++)
3765 fragmentShader << ", ";
3767 if (compNdx < componentCount)
3768 fragmentShader << "outputs[" << outputValueNdx + compNdx << "]";
3770 fragmentShader << "0";
3773 outputValueNdx += componentCount;
3775 fragmentShader << ");\n";
3778 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED)
3780 const deUint32 attachmentIndex = subpass.getDepthStencilAttachment().getAttachment();
3781 const size_t index = subpassNdx + attachmentIndex;
3782 const BoolOp op = boolOpFromIndex(index);
3784 fragmentShader << "\toutputs[" << outputValueNdx << "] = "
3785 << "(int(gl_FragCoord.x) % 2 == " << (index % 2)
3786 << ") " << boolOpToString(op) << " ("
3787 << "int(gl_FragCoord.y) % 2 == " << ((index / 2) % 2)
3790 for (size_t i = 0; i < inputsPerOutput; i++)
3791 fragmentShader << "\toutputs[" << outputValueNdx << "] = outputs[" << outputValueNdx << "] == inputs[" << (outputValueNdx * inputsPerOutput + i) % inputComponentCount << "];\n";
3793 fragmentShader << "\tgl_FragDepth = outputs[" << outputValueNdx << "] ? 1.0 : 0.0;";
3797 fragmentShader << "}\n";
3799 dst.glslSources.add(de::toString(subpassNdx) + "-vert") << glu::VertexSource(vertexShader.str());
3800 dst.glslSources.add(de::toString(subpassNdx) + "-frag") << glu::FragmentSource(fragmentShader.str());
3805 void initializeAttachmentIsLazy (vector<bool>& attachmentIsLazy, const vector<Attachment>& attachments, TestConfig::ImageMemory imageMemory)
3807 bool lastAttachmentWasLazy = false;
3809 for (size_t attachmentNdx = 0; attachmentNdx < attachments.size(); attachmentNdx++)
3811 if (attachments[attachmentNdx].getLoadOp() != VK_ATTACHMENT_LOAD_OP_LOAD
3812 && attachments[attachmentNdx].getStoreOp() != VK_ATTACHMENT_STORE_OP_STORE
3813 && attachments[attachmentNdx].getStencilLoadOp() != VK_ATTACHMENT_LOAD_OP_LOAD
3814 && attachments[attachmentNdx].getStencilStoreOp() != VK_ATTACHMENT_STORE_OP_STORE)
3816 if (imageMemory == TestConfig::IMAGEMEMORY_LAZY || (imageMemory & TestConfig::IMAGEMEMORY_LAZY && !lastAttachmentWasLazy))
3818 attachmentIsLazy.push_back(true);
3819 lastAttachmentWasLazy = true;
3821 else if (imageMemory & TestConfig::IMAGEMEMORY_STRICT)
3823 attachmentIsLazy.push_back(false);
3824 lastAttachmentWasLazy = false;
3827 DE_FATAL("Unknown imageMemory");
3830 attachmentIsLazy.push_back(false);
3834 enum AttachmentRefType
3836 ATTACHMENTREFTYPE_COLOR,
3837 ATTACHMENTREFTYPE_DEPTH_STENCIL,
3838 ATTACHMENTREFTYPE_INPUT,
3839 ATTACHMENTREFTYPE_RESOLVE,
3842 VkImageUsageFlags getImageUsageFromLayout (VkImageLayout layout)
3846 case VK_IMAGE_LAYOUT_GENERAL:
3847 case VK_IMAGE_LAYOUT_PREINITIALIZED:
3850 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
3851 return VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
3853 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
3854 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
3855 return VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
3857 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
3858 return VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
3860 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL:
3861 return VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
3863 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL:
3864 return VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3867 DE_FATAL("Unexpected image layout");
3872 void getImageUsageFromAttachmentReferences(vector<VkImageUsageFlags>& attachmentImageUsage, AttachmentRefType refType, size_t count, const AttachmentReference* references)
3874 for (size_t referenceNdx = 0; referenceNdx < count; ++referenceNdx)
3876 const deUint32 attachment = references[referenceNdx].getAttachment();
3878 if (attachment != VK_ATTACHMENT_UNUSED)
3880 VkImageUsageFlags usage;
3884 case ATTACHMENTREFTYPE_COLOR:
3885 case ATTACHMENTREFTYPE_RESOLVE:
3886 usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
3889 case ATTACHMENTREFTYPE_DEPTH_STENCIL:
3890 usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
3893 case ATTACHMENTREFTYPE_INPUT:
3894 usage = VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
3898 DE_FATAL("Unexpected attachment reference type");
3903 attachmentImageUsage[attachment] |= usage;
3908 void getImageUsageFromAttachmentReferences(vector<VkImageUsageFlags>& attachmentImageUsage, AttachmentRefType refType, const vector<AttachmentReference>& references)
3910 if (!references.empty())
3912 getImageUsageFromAttachmentReferences(attachmentImageUsage, refType, references.size(), &references[0]);
3916 void initializeAttachmentImageUsage (Context &context, vector<VkImageUsageFlags>& attachmentImageUsage, const RenderPass& renderPassInfo, const vector<bool>& attachmentIsLazy, const vector<Maybe<VkClearValue> >& clearValues)
3918 attachmentImageUsage.resize(renderPassInfo.getAttachments().size(), VkImageUsageFlags(0));
3920 for (size_t subpassNdx = 0; subpassNdx < renderPassInfo.getSubpasses().size(); ++subpassNdx)
3922 const Subpass& subpass = renderPassInfo.getSubpasses()[subpassNdx];
3924 getImageUsageFromAttachmentReferences(attachmentImageUsage, ATTACHMENTREFTYPE_COLOR, subpass.getColorAttachments());
3925 getImageUsageFromAttachmentReferences(attachmentImageUsage, ATTACHMENTREFTYPE_DEPTH_STENCIL, 1, &subpass.getDepthStencilAttachment());
3926 getImageUsageFromAttachmentReferences(attachmentImageUsage, ATTACHMENTREFTYPE_INPUT, subpass.getInputAttachments());
3927 getImageUsageFromAttachmentReferences(attachmentImageUsage, ATTACHMENTREFTYPE_RESOLVE, subpass.getResolveAttachments());
3930 for (size_t attachmentNdx = 0; attachmentNdx < renderPassInfo.getAttachments().size(); attachmentNdx++)
3932 const Attachment& attachment = renderPassInfo.getAttachments()[attachmentNdx];
3933 const VkFormatProperties formatProperties = getPhysicalDeviceFormatProperties(context.getInstanceInterface(), context.getPhysicalDevice(), attachment.getFormat());
3934 const VkFormatFeatureFlags supportedFeatures = formatProperties.optimalTilingFeatures;
3936 if ((supportedFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) != 0)
3937 attachmentImageUsage[attachmentNdx] |= VK_IMAGE_USAGE_SAMPLED_BIT;
3939 if ((supportedFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) != 0)
3940 attachmentImageUsage[attachmentNdx] |= VK_IMAGE_USAGE_STORAGE_BIT;
3942 attachmentImageUsage[attachmentNdx] |= getImageUsageFromLayout(attachment.getInitialLayout());
3943 attachmentImageUsage[attachmentNdx] |= getImageUsageFromLayout(attachment.getFinalLayout());
3945 if (!attachmentIsLazy[attachmentNdx])
3947 if (clearValues[attachmentNdx])
3948 attachmentImageUsage[attachmentNdx] |= VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3950 attachmentImageUsage[attachmentNdx] |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
3955 void initializeSubpassIsSecondary (vector<bool>& subpassIsSecondary, const vector<Subpass>& subpasses, TestConfig::CommandBufferTypes commandBuffer)
3957 bool lastSubpassWasSecondary = false;
3959 for (size_t subpassNdx = 0; subpassNdx < subpasses.size(); subpassNdx++)
3961 if (commandBuffer == TestConfig::COMMANDBUFFERTYPES_SECONDARY || (commandBuffer & TestConfig::COMMANDBUFFERTYPES_SECONDARY && !lastSubpassWasSecondary))
3963 subpassIsSecondary.push_back(true);
3964 lastSubpassWasSecondary = true;
3966 else if (commandBuffer & TestConfig::COMMANDBUFFERTYPES_INLINE)
3968 subpassIsSecondary.push_back(false);
3969 lastSubpassWasSecondary = false;
3972 DE_FATAL("Unknown commandBuffer");
3976 void initializeImageClearValues (de::Random& rng, vector<Maybe<VkClearValue> >& clearValues, const vector<Attachment>& attachments, const vector<bool>& isLazy)
3978 for (size_t attachmentNdx = 0; attachmentNdx < attachments.size(); attachmentNdx++)
3980 if (!isLazy[attachmentNdx])
3981 clearValues.push_back(just(randomClearValue(attachments[attachmentNdx], rng)));
3983 clearValues.push_back(nothing<VkClearValue>());
3987 void initializeRenderPassClearValues (de::Random& rng, vector<Maybe<VkClearValue> >& clearValues, const vector<Attachment>& attachments)
3989 for (size_t attachmentNdx = 0; attachmentNdx < attachments.size(); attachmentNdx++)
3991 if (attachments[attachmentNdx].getLoadOp() == VK_ATTACHMENT_LOAD_OP_CLEAR
3992 || attachments[attachmentNdx].getStencilLoadOp() == VK_ATTACHMENT_LOAD_OP_CLEAR)
3994 clearValues.push_back(just(randomClearValue(attachments[attachmentNdx], rng)));
3997 clearValues.push_back(nothing<VkClearValue>());
4001 void initializeSubpassClearValues (de::Random& rng, vector<vector<VkClearColorValue> >& clearValues, const RenderPass& renderPass)
4003 clearValues.resize(renderPass.getSubpasses().size());
4005 for (size_t subpassNdx = 0; subpassNdx < renderPass.getSubpasses().size(); subpassNdx++)
4007 const Subpass& subpass = renderPass.getSubpasses()[subpassNdx];
4008 const vector<AttachmentReference>& colorAttachments = subpass.getColorAttachments();
4010 clearValues[subpassNdx].resize(colorAttachments.size());
4012 for (size_t attachmentRefNdx = 0; attachmentRefNdx < colorAttachments.size(); attachmentRefNdx++)
4014 const AttachmentReference& attachmentRef = colorAttachments[attachmentRefNdx];
4015 const Attachment& attachment = renderPass.getAttachments()[attachmentRef.getAttachment()];
4017 clearValues[subpassNdx][attachmentRefNdx] = randomColorClearValue(attachment, rng);
4022 void logSubpassRenderInfo (TestLog& log,
4023 const SubpassRenderInfo& info)
4025 log << TestLog::Message << "Viewport, offset: " << info.getViewportOffset() << ", size: " << info.getViewportSize() << TestLog::EndMessage;
4027 if (info.isSecondary())
4028 log << TestLog::Message << "Subpass uses secondary command buffers" << TestLog::EndMessage;
4030 log << TestLog::Message << "Subpass uses inlined commands" << TestLog::EndMessage;
4032 for (deUint32 attachmentNdx = 0; attachmentNdx < info.getColorClears().size(); attachmentNdx++)
4034 const ColorClear& colorClear = info.getColorClears()[attachmentNdx];
4036 log << TestLog::Message << "Clearing color attachment " << attachmentNdx
4037 << ". Offset: " << colorClear.getOffset()
4038 << ", Size: " << colorClear.getSize()
4039 << ", Color: " << clearColorToString(info.getColorAttachment(attachmentNdx).getFormat(), colorClear.getColor()) << TestLog::EndMessage;
4042 if (info.getDepthStencilClear())
4044 const DepthStencilClear& depthStencilClear = *info.getDepthStencilClear();
4046 log << TestLog::Message << "Clearing depth stencil attachment"
4047 << ". Offset: " << depthStencilClear.getOffset()
4048 << ", Size: " << depthStencilClear.getSize()
4049 << ", Depth: " << depthStencilClear.getDepth()
4050 << ", Stencil: " << depthStencilClear.getStencil() << TestLog::EndMessage;
4053 if (info.getRenderQuad())
4055 const RenderQuad& renderQuad = *info.getRenderQuad();
4057 log << TestLog::Message << "Rendering grid quad to " << renderQuad.getCornerA() << " -> " << renderQuad.getCornerB() << TestLog::EndMessage;
4061 void logTestCaseInfo (TestLog& log,
4062 const TestConfig& config,
4063 const vector<bool>& attachmentIsLazy,
4064 const vector<Maybe<VkClearValue> >& imageClearValues,
4065 const vector<Maybe<VkClearValue> >& renderPassClearValues,
4066 const vector<SubpassRenderInfo>& subpassRenderInfo)
4068 const RenderPass& renderPass = config.renderPass;
4070 logRenderPassInfo(log, renderPass);
4072 DE_ASSERT(attachmentIsLazy.size() == renderPass.getAttachments().size());
4073 DE_ASSERT(imageClearValues.size() == renderPass.getAttachments().size());
4074 DE_ASSERT(renderPassClearValues.size() == renderPass.getAttachments().size());
4076 log << TestLog::Message << "TargetSize: " << config.targetSize << TestLog::EndMessage;
4077 log << TestLog::Message << "Render area, Offset: " << config.renderPos << ", Size: " << config.renderSize << TestLog::EndMessage;
4079 for (size_t attachmentNdx = 0; attachmentNdx < attachmentIsLazy.size(); attachmentNdx++)
4081 const tcu::ScopedLogSection section (log, "Attachment" + de::toString(attachmentNdx), "Attachment " + de::toString(attachmentNdx));
4083 if (attachmentIsLazy[attachmentNdx])
4084 log << TestLog::Message << "Is lazy." << TestLog::EndMessage;
4086 if (imageClearValues[attachmentNdx])
4087 log << TestLog::Message << "Image is cleared to " << clearValueToString(renderPass.getAttachments()[attachmentNdx].getFormat(), *imageClearValues[attachmentNdx]) << " before rendering." << TestLog::EndMessage;
4089 if (renderPass.getAttachments()[attachmentNdx].getLoadOp() == VK_ATTACHMENT_LOAD_OP_CLEAR && renderPassClearValues[attachmentNdx])
4090 log << TestLog::Message << "Attachment is cleared to " << clearValueToString(renderPass.getAttachments()[attachmentNdx].getFormat(), *renderPassClearValues[attachmentNdx]) << " in the beginning of the render pass." << TestLog::EndMessage;
4093 for (size_t subpassNdx = 0; subpassNdx < renderPass.getSubpasses().size(); subpassNdx++)
4095 const tcu::ScopedLogSection section (log, "Subpass" + de::toString(subpassNdx), "Subpass " + de::toString(subpassNdx));
4097 logSubpassRenderInfo(log, subpassRenderInfo[subpassNdx]);
4101 float roundToViewport (float x, deUint32 offset, deUint32 size)
4103 const float origin = (float)(offset) + ((float(size) / 2.0f));
4104 const float p = (float)(size) / 2.0f;
4105 const deInt32 xi = deRoundFloatToInt32(origin + (p * x));
4107 return (((float)xi) - origin) / p;
4110 void initializeSubpassRenderInfo (vector<SubpassRenderInfo>& renderInfos, de::Random& rng, const RenderPass& renderPass, const TestConfig& config)
4112 const TestConfig::CommandBufferTypes commandBuffer = config.commandBufferTypes;
4113 const vector<Subpass>& subpasses = renderPass.getSubpasses();
4114 bool lastSubpassWasSecondary = false;
4116 for (deUint32 subpassNdx = 0; subpassNdx < (deUint32)subpasses.size(); subpassNdx++)
4118 const Subpass& subpass = subpasses[subpassNdx];
4119 const bool subpassIsSecondary = commandBuffer == TestConfig::COMMANDBUFFERTYPES_SECONDARY
4120 || (commandBuffer & TestConfig::COMMANDBUFFERTYPES_SECONDARY && !lastSubpassWasSecondary) ? true : false;
4121 const UVec2 viewportSize ((config.renderSize * UVec2(2)) / UVec2(3));
4122 const UVec2 viewportOffset (config.renderPos.x() + (subpassNdx % 2) * (config.renderSize.x() / 3),
4123 config.renderPos.y() + ((subpassNdx / 2) % 2) * (config.renderSize.y() / 3));
4125 vector<ColorClear> colorClears;
4126 Maybe<DepthStencilClear> depthStencilClear;
4127 Maybe<RenderQuad> renderQuad;
4129 lastSubpassWasSecondary = subpassIsSecondary;
4131 if (config.renderTypes & TestConfig::RENDERTYPES_CLEAR)
4133 const vector<AttachmentReference>& colorAttachments = subpass.getColorAttachments();
4135 for (size_t attachmentRefNdx = 0; attachmentRefNdx < colorAttachments.size(); attachmentRefNdx++)
4137 const AttachmentReference& attachmentRef = colorAttachments[attachmentRefNdx];
4138 const Attachment& attachment = renderPass.getAttachments()[attachmentRef.getAttachment()];
4139 const UVec2 size ((viewportSize * UVec2(2)) / UVec2(3));
4140 const UVec2 offset (viewportOffset.x() + ((deUint32)attachmentRefNdx % 2u) * (viewportSize.x() / 3u),
4141 viewportOffset.y() + (((deUint32)attachmentRefNdx / 2u) % 2u) * (viewportSize.y() / 3u));
4142 const VkClearColorValue color = randomColorClearValue(attachment, rng);
4144 colorClears.push_back(ColorClear(offset, size, color));
4147 if (subpass.getDepthStencilAttachment().getAttachment() != VK_ATTACHMENT_UNUSED)
4149 const Attachment& attachment = renderPass.getAttachments()[subpass.getDepthStencilAttachment().getAttachment()];
4150 const UVec2 size ((viewportSize * UVec2(2)) / UVec2(3));
4151 const UVec2 offset (viewportOffset.x() + ((deUint32)colorAttachments.size() % 2u) * (viewportSize.x() / 3u),
4152 viewportOffset.y() + (((deUint32)colorAttachments.size() / 2u) % 2u) * (viewportSize.y() / 3u));
4153 const VkClearValue value = randomClearValue(attachment, rng);
4155 depthStencilClear = tcu::just(DepthStencilClear(offset, size, value.depthStencil.depth, value.depthStencil.stencil));
4159 if (config.renderTypes & TestConfig::RENDERTYPES_DRAW)
4161 const float w = (subpassNdx % 2) == 0 ? 1.0f : 1.25f;
4162 const float h = (subpassNdx % 2) == 0 ? 1.25f : 1.0f;
4164 const float x0 = roundToViewport((subpassNdx % 2) == 0 ? 1.0f - w : -1.0f, viewportOffset.x(), viewportSize.x());
4165 const float x1 = roundToViewport((subpassNdx % 2) == 0 ? 1.0f : -1.0f + w, viewportOffset.x(), viewportSize.x());
4167 const float y0 = roundToViewport(((subpassNdx / 2) % 2) == 0 ? 1.0f - h : -1.0f, viewportOffset.y(), viewportSize.y());
4168 const float y1 = roundToViewport(((subpassNdx / 2) % 2) == 0 ? 1.0f : -1.0f + h, viewportOffset.y(), viewportSize.y());
4170 renderQuad = tcu::just(RenderQuad(tcu::Vec2(x0, y0), tcu::Vec2(x1, y1)));
4173 renderInfos.push_back(SubpassRenderInfo(renderPass, subpassNdx, subpassIsSecondary, viewportOffset, viewportSize, renderQuad, colorClears, depthStencilClear));
4177 void checkTextureFormatSupport (TestLog& log,
4178 const InstanceInterface& vk,
4179 VkPhysicalDevice device,
4180 const vector<Attachment>& attachments)
4182 bool supported = true;
4184 for (size_t attachmentNdx = 0; attachmentNdx < attachments.size(); attachmentNdx++)
4186 const Attachment& attachment = attachments[attachmentNdx];
4187 const tcu::TextureFormat format = mapVkFormat(attachment.getFormat());
4188 const bool isDepthOrStencilAttachment = hasDepthComponent(format.order) || hasStencilComponent(format.order);
4189 const VkFormatFeatureFlags flags = isDepthOrStencilAttachment? VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT : VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT;
4190 VkFormatProperties properties;
4192 vk.getPhysicalDeviceFormatProperties(device, attachment.getFormat(), &properties);
4194 if ((properties.optimalTilingFeatures & flags) != flags)
4197 log << TestLog::Message << "Format: " << attachment.getFormat() << " not supported as " << (isDepthOrStencilAttachment ? "depth stencil attachment" : "color attachment") << TestLog::EndMessage;
4202 TCU_THROW(NotSupportedError, "Format not supported");
4205 tcu::TestStatus renderPassTest (Context& context, TestConfig config)
4207 const UVec2 targetSize = config.targetSize;
4208 const UVec2 renderPos = config.renderPos;
4209 const UVec2 renderSize = config.renderSize;
4210 const RenderPass& renderPassInfo = config.renderPass;
4212 TestLog& log = context.getTestContext().getLog();
4213 de::Random rng (config.seed);
4215 vector<bool> attachmentIsLazy;
4216 vector<VkImageUsageFlags> attachmentImageUsage;
4217 vector<Maybe<VkClearValue> > imageClearValues;
4218 vector<Maybe<VkClearValue> > renderPassClearValues;
4220 vector<bool> subpassIsSecondary;
4221 vector<SubpassRenderInfo> subpassRenderInfo;
4222 vector<vector<VkClearColorValue> > subpassColorClearValues;
4224 initializeAttachmentIsLazy(attachmentIsLazy, renderPassInfo.getAttachments(), config.imageMemory);
4225 initializeImageClearValues(rng, imageClearValues, renderPassInfo.getAttachments(), attachmentIsLazy);
4226 initializeAttachmentImageUsage(context, attachmentImageUsage, renderPassInfo, attachmentIsLazy, imageClearValues);
4227 initializeRenderPassClearValues(rng, renderPassClearValues, renderPassInfo.getAttachments());
4229 initializeSubpassIsSecondary(subpassIsSecondary, renderPassInfo.getSubpasses(), config.commandBufferTypes);
4230 initializeSubpassClearValues(rng, subpassColorClearValues, renderPassInfo);
4231 initializeSubpassRenderInfo(subpassRenderInfo, rng, renderPassInfo, config);
4233 logTestCaseInfo(log, config, attachmentIsLazy, imageClearValues, renderPassClearValues, subpassRenderInfo);
4235 checkTextureFormatSupport(log, context.getInstanceInterface(), context.getPhysicalDevice(), config.renderPass.getAttachments());
4238 const vk::VkPhysicalDeviceProperties properties = vk::getPhysicalDeviceProperties(context.getInstanceInterface(), context.getPhysicalDevice());
4240 log << TestLog::Message << "Max color attachments: " << properties.limits.maxColorAttachments << TestLog::EndMessage;
4242 for (size_t subpassNdx = 0; subpassNdx < renderPassInfo.getSubpasses().size(); subpassNdx++)
4244 if (renderPassInfo.getSubpasses()[subpassNdx].getColorAttachments().size() > (size_t)properties.limits.maxColorAttachments)
4245 TCU_THROW(NotSupportedError, "Subpass uses more than maxColorAttachments.");
4250 const VkDevice device = context.getDevice();
4251 const DeviceInterface& vk = context.getDeviceInterface();
4252 const VkQueue queue = context.getUniversalQueue();
4253 const deUint32 queueIndex = context.getUniversalQueueFamilyIndex();
4254 Allocator& allocator = context.getDefaultAllocator();
4256 const Unique<VkRenderPass> renderPass (createRenderPass(vk, device, renderPassInfo));
4257 const Unique<VkCommandPool> commandBufferPool (createCommandPool(vk, device, queueIndex, 0));
4258 const Unique<VkCommandBuffer> initializeImagesCommandBuffer (allocateCommandBuffer(vk, device, *commandBufferPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
4259 const Unique<VkCommandBuffer> renderCommandBuffer (allocateCommandBuffer(vk, device, *commandBufferPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
4260 const Unique<VkCommandBuffer> readImagesToBuffersCommandBuffer (allocateCommandBuffer(vk, device, *commandBufferPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
4262 vector<de::SharedPtr<AttachmentResources> > attachmentResources;
4263 vector<de::SharedPtr<SubpassRenderer> > subpassRenderers;
4264 vector<VkImage> attachmentImages;
4265 vector<VkImageView> attachmentViews;
4266 vector<pair<VkImageView, VkImageView> > inputAttachmentViews;
4268 for (size_t attachmentNdx = 0; attachmentNdx < renderPassInfo.getAttachments().size(); attachmentNdx++)
4270 const Attachment& attachmentInfo = renderPassInfo.getAttachments()[attachmentNdx];
4272 attachmentResources.push_back(de::SharedPtr<AttachmentResources>(new AttachmentResources(vk, device, allocator, queueIndex, targetSize, attachmentInfo, attachmentImageUsage[attachmentNdx])));
4273 attachmentViews.push_back(attachmentResources[attachmentNdx]->getAttachmentView());
4274 attachmentImages.push_back(attachmentResources[attachmentNdx]->getImage());
4276 inputAttachmentViews.push_back(attachmentResources[attachmentNdx]->getInputAttachmentViews());
4279 beginCommandBuffer(vk, *initializeImagesCommandBuffer, (VkCommandBufferUsageFlags)0, DE_NULL, 0, DE_NULL, VK_FALSE, (VkQueryControlFlags)0, (VkQueryPipelineStatisticFlags)0);
4280 pushImageInitializationCommands(vk, *initializeImagesCommandBuffer, renderPassInfo.getAttachments(), attachmentResources, queueIndex, imageClearValues);
4281 endCommandBuffer(vk, *initializeImagesCommandBuffer);
4284 const Unique<VkFramebuffer> framebuffer (createFramebuffer(vk, device, *renderPass, targetSize, attachmentViews));
4286 for (size_t subpassNdx = 0; subpassNdx < renderPassInfo.getSubpasses().size(); subpassNdx++)
4287 subpassRenderers.push_back(de::SharedPtr<SubpassRenderer>(new SubpassRenderer(context, vk, device, allocator, *renderPass, *framebuffer, *commandBufferPool, queueIndex, attachmentImages, inputAttachmentViews, subpassRenderInfo[subpassNdx], config.renderPass.getAttachments())));
4289 beginCommandBuffer(vk, *renderCommandBuffer, (VkCommandBufferUsageFlags)0, DE_NULL, 0, DE_NULL, VK_FALSE, (VkQueryControlFlags)0, (VkQueryPipelineStatisticFlags)0);
4290 pushRenderPassCommands(vk, *renderCommandBuffer, *renderPass, *framebuffer, subpassRenderers, renderPos, renderSize, renderPassClearValues, config.renderTypes);
4291 endCommandBuffer(vk, *renderCommandBuffer);
4293 beginCommandBuffer(vk, *readImagesToBuffersCommandBuffer, (VkCommandBufferUsageFlags)0, DE_NULL, 0, DE_NULL, VK_FALSE, (VkQueryControlFlags)0, (VkQueryPipelineStatisticFlags)0);
4294 pushReadImagesToBuffers(vk, *readImagesToBuffersCommandBuffer, queueIndex, attachmentResources, renderPassInfo.getAttachments(), attachmentIsLazy, targetSize);
4295 endCommandBuffer(vk, *readImagesToBuffersCommandBuffer);
4297 const VkCommandBuffer commandBuffers[] =
4299 *initializeImagesCommandBuffer,
4300 *renderCommandBuffer,
4301 *readImagesToBuffersCommandBuffer
4303 const Unique<VkFence> fence (createFence(vk, device, 0u));
4305 queueSubmit(vk, queue, DE_LENGTH_OF_ARRAY(commandBuffers), commandBuffers, *fence);
4306 waitForFences(vk, device, 1, &fence.get(), VK_TRUE, ~0ull);
4310 if (logAndVerifyImages(log, vk, device, attachmentResources, attachmentIsLazy, renderPassInfo, renderPassClearValues, imageClearValues, subpassRenderInfo, targetSize, config))
4311 return tcu::TestStatus::pass("Pass");
4313 return tcu::TestStatus::fail("Result verification failed");
4317 static const VkFormat s_coreColorFormats[] =
4319 VK_FORMAT_R5G6B5_UNORM_PACK16,
4324 VK_FORMAT_R8G8_UNORM,
4325 VK_FORMAT_R8G8_SNORM,
4326 VK_FORMAT_R8G8_UINT,
4327 VK_FORMAT_R8G8_SINT,
4328 VK_FORMAT_R8G8B8A8_UNORM,
4329 VK_FORMAT_R8G8B8A8_SNORM,
4330 VK_FORMAT_R8G8B8A8_UINT,
4331 VK_FORMAT_R8G8B8A8_SINT,
4332 VK_FORMAT_R8G8B8A8_SRGB,
4333 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
4334 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
4335 VK_FORMAT_A8B8G8R8_UINT_PACK32,
4336 VK_FORMAT_A8B8G8R8_SINT_PACK32,
4337 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
4338 VK_FORMAT_B8G8R8A8_UNORM,
4339 VK_FORMAT_B8G8R8A8_SRGB,
4340 VK_FORMAT_A2R10G10B10_UNORM_PACK32,
4341 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
4342 VK_FORMAT_A2B10G10R10_UINT_PACK32,
4343 VK_FORMAT_R16_UNORM,
4344 VK_FORMAT_R16_SNORM,
4347 VK_FORMAT_R16_SFLOAT,
4348 VK_FORMAT_R16G16_UNORM,
4349 VK_FORMAT_R16G16_SNORM,
4350 VK_FORMAT_R16G16_UINT,
4351 VK_FORMAT_R16G16_SINT,
4352 VK_FORMAT_R16G16_SFLOAT,
4353 VK_FORMAT_R16G16B16A16_UNORM,
4354 VK_FORMAT_R16G16B16A16_SNORM,
4355 VK_FORMAT_R16G16B16A16_UINT,
4356 VK_FORMAT_R16G16B16A16_SINT,
4357 VK_FORMAT_R16G16B16A16_SFLOAT,
4360 VK_FORMAT_R32_SFLOAT,
4361 VK_FORMAT_R32G32_UINT,
4362 VK_FORMAT_R32G32_SINT,
4363 VK_FORMAT_R32G32_SFLOAT,
4364 VK_FORMAT_R32G32B32A32_UINT,
4365 VK_FORMAT_R32G32B32A32_SINT,
4366 VK_FORMAT_R32G32B32A32_SFLOAT
4369 static const VkFormat s_coreDepthStencilFormats[] =
4371 VK_FORMAT_D16_UNORM,
4373 VK_FORMAT_X8_D24_UNORM_PACK32,
4374 VK_FORMAT_D32_SFLOAT,
4376 VK_FORMAT_D24_UNORM_S8_UINT,
4377 VK_FORMAT_D32_SFLOAT_S8_UINT
4380 void addAttachmentTests (tcu::TestCaseGroup* group)
4382 const deUint32 attachmentCounts[] = { 1, 3, 4, 8 };
4383 const VkAttachmentLoadOp loadOps[] =
4385 VK_ATTACHMENT_LOAD_OP_LOAD,
4386 VK_ATTACHMENT_LOAD_OP_CLEAR,
4387 VK_ATTACHMENT_LOAD_OP_DONT_CARE
4390 const VkAttachmentStoreOp storeOps[] =
4392 VK_ATTACHMENT_STORE_OP_STORE,
4393 VK_ATTACHMENT_STORE_OP_DONT_CARE
4396 const VkImageLayout initialAndFinalColorLayouts[] =
4398 VK_IMAGE_LAYOUT_GENERAL,
4399 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4400 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
4401 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
4402 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
4405 const VkImageLayout initialAndFinalDepthStencilLayouts[] =
4407 VK_IMAGE_LAYOUT_GENERAL,
4408 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
4409 VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL,
4410 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
4411 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
4412 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
4415 const VkImageLayout subpassLayouts[] =
4417 VK_IMAGE_LAYOUT_GENERAL,
4418 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
4421 const VkImageLayout depthStencilLayouts[] =
4423 VK_IMAGE_LAYOUT_GENERAL,
4424 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL
4427 const TestConfig::RenderTypes renderCommands[] =
4429 TestConfig::RENDERTYPES_NONE,
4430 TestConfig::RENDERTYPES_CLEAR,
4431 TestConfig::RENDERTYPES_DRAW,
4432 TestConfig::RENDERTYPES_CLEAR|TestConfig::RENDERTYPES_DRAW,
4435 const TestConfig::CommandBufferTypes commandBuffers[] =
4437 TestConfig::COMMANDBUFFERTYPES_INLINE,
4438 TestConfig::COMMANDBUFFERTYPES_SECONDARY,
4439 TestConfig::COMMANDBUFFERTYPES_INLINE|TestConfig::COMMANDBUFFERTYPES_SECONDARY
4442 const TestConfig::ImageMemory imageMemories[] =
4444 TestConfig::IMAGEMEMORY_STRICT,
4445 TestConfig::IMAGEMEMORY_LAZY,
4446 TestConfig::IMAGEMEMORY_STRICT|TestConfig::IMAGEMEMORY_LAZY
4449 const UVec2 targetSizes[] =
4455 const UVec2 renderPositions[] =
4461 const UVec2 renderSizes[] =
4467 tcu::TestContext& testCtx = group->getTestContext();
4468 de::Random rng (1433774382u);
4470 for (size_t attachmentCountNdx = 0; attachmentCountNdx < DE_LENGTH_OF_ARRAY(attachmentCounts); attachmentCountNdx++)
4472 const deUint32 attachmentCount = attachmentCounts[attachmentCountNdx];
4473 const deUint32 testCaseCount = (attachmentCount == 1 ? 100 : 200);
4474 de::MovePtr<tcu::TestCaseGroup> attachmentCountGroup (new tcu::TestCaseGroup(testCtx, de::toString(attachmentCount).c_str(), de::toString(attachmentCount).c_str()));
4476 for (size_t testCaseNdx = 0; testCaseNdx < testCaseCount; testCaseNdx++)
4478 const bool useDepthStencil = rng.getBool();
4479 VkImageLayout depthStencilLayout = VK_IMAGE_LAYOUT_GENERAL;
4480 vector<Attachment> attachments;
4481 vector<AttachmentReference> colorAttachmentReferences;
4483 for (size_t attachmentNdx = 0; attachmentNdx < attachmentCount; attachmentNdx++)
4485 const VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_1_BIT;
4486 const VkFormat format = rng.choose<VkFormat>(DE_ARRAY_BEGIN(s_coreColorFormats), DE_ARRAY_END(s_coreColorFormats));
4487 const VkAttachmentLoadOp loadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
4488 const VkAttachmentStoreOp storeOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
4490 const VkImageLayout initialLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalColorLayouts), DE_ARRAY_END(initialAndFinalColorLayouts));
4491 const VkImageLayout finalizeLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalColorLayouts), DE_ARRAY_END(initialAndFinalColorLayouts));
4492 const VkImageLayout subpassLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayouts), DE_ARRAY_END(subpassLayouts));
4494 const VkAttachmentLoadOp stencilLoadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
4495 const VkAttachmentStoreOp stencilStoreOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
4497 attachments.push_back(Attachment(format, sampleCount, loadOp, storeOp, stencilLoadOp, stencilStoreOp, initialLayout, finalizeLayout));
4498 colorAttachmentReferences.push_back(AttachmentReference((deUint32)attachmentNdx, subpassLayout));
4501 if (useDepthStencil)
4503 const VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_1_BIT;
4504 const VkFormat format = rng.choose<VkFormat>(DE_ARRAY_BEGIN(s_coreDepthStencilFormats), DE_ARRAY_END(s_coreDepthStencilFormats));
4505 const VkAttachmentLoadOp loadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
4506 const VkAttachmentStoreOp storeOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
4508 const VkImageLayout initialLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalDepthStencilLayouts), DE_ARRAY_END(initialAndFinalDepthStencilLayouts));
4509 const VkImageLayout finalizeLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalDepthStencilLayouts), DE_ARRAY_END(initialAndFinalDepthStencilLayouts));
4511 const VkAttachmentLoadOp stencilLoadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
4512 const VkAttachmentStoreOp stencilStoreOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
4514 depthStencilLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(depthStencilLayouts), DE_ARRAY_END(depthStencilLayouts));
4515 attachments.push_back(Attachment(format, sampleCount, loadOp, storeOp, stencilLoadOp, stencilStoreOp, initialLayout, finalizeLayout));
4519 const TestConfig::RenderTypes render = rng.choose<TestConfig::RenderTypes>(DE_ARRAY_BEGIN(renderCommands), DE_ARRAY_END(renderCommands));
4520 const TestConfig::CommandBufferTypes commandBuffer = rng.choose<TestConfig::CommandBufferTypes>(DE_ARRAY_BEGIN(commandBuffers), DE_ARRAY_END(commandBuffers));
4521 const TestConfig::ImageMemory imageMemory = rng.choose<TestConfig::ImageMemory>(DE_ARRAY_BEGIN(imageMemories), DE_ARRAY_END(imageMemories));
4522 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>()));
4523 const vector<SubpassDependency> deps;
4525 const string testCaseName = de::toString(attachmentCountNdx * testCaseCount + testCaseNdx);
4526 const RenderPass renderPass (attachments, subpasses, deps);
4527 const UVec2 targetSize = rng.choose<UVec2>(DE_ARRAY_BEGIN(targetSizes), DE_ARRAY_END(targetSizes));
4528 const UVec2 renderPos = rng.choose<UVec2>(DE_ARRAY_BEGIN(renderPositions), DE_ARRAY_END(renderPositions));
4529 const UVec2 renderSize = rng.choose<UVec2>(DE_ARRAY_BEGIN(renderSizes), DE_ARRAY_END(renderSizes));
4531 addFunctionCaseWithPrograms<TestConfig>(attachmentCountGroup.get(), testCaseName.c_str(), testCaseName.c_str(), createTestShaders, renderPassTest, TestConfig(renderPass, render, commandBuffer, imageMemory, targetSize, renderPos, renderSize, 1293809));
4535 group->addChild(attachmentCountGroup.release());
4539 template<typename T>
4540 T chooseRandom (de::Random& rng, const set<T>& values)
4542 size_t ndx = ((size_t)rng.getUint32()) % values.size();
4543 typename set<T>::const_iterator iter = values.begin();
4545 for (; ndx > 0; ndx--)
4551 void addAttachmentAllocationTests (tcu::TestCaseGroup* group)
4553 const deUint32 attachmentCounts[] = { 4, 8 };
4554 const VkAttachmentLoadOp loadOps[] =
4556 VK_ATTACHMENT_LOAD_OP_LOAD,
4557 VK_ATTACHMENT_LOAD_OP_CLEAR,
4558 VK_ATTACHMENT_LOAD_OP_DONT_CARE
4561 const VkAttachmentStoreOp storeOps[] =
4563 VK_ATTACHMENT_STORE_OP_STORE,
4564 VK_ATTACHMENT_STORE_OP_DONT_CARE
4567 const VkImageLayout initialAndFinalColorLayouts[] =
4569 VK_IMAGE_LAYOUT_GENERAL,
4570 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4571 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
4572 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
4573 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
4576 const VkImageLayout initialAndFinalDepthStencilLayouts[] =
4578 VK_IMAGE_LAYOUT_GENERAL,
4579 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
4580 VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL,
4581 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
4582 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
4583 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
4586 const VkImageLayout subpassLayouts[] =
4588 VK_IMAGE_LAYOUT_GENERAL,
4589 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
4594 // Each pass uses one more attachmen than previous one
4595 ALLOCATIONTYPE_GROW,
4596 // Each pass uses one less attachment than previous one
4597 ALLOCATIONTYPE_SHRINK,
4598 // Each pass drops one attachment and picks up new one
4599 ALLOCATIONTYPE_ROLL,
4600 // Start by growing and end by shrinking
4601 ALLOCATIONTYPE_GROW_SHRINK,
4602 // Each subpass has single input and single output attachment
4603 ALLOCATIONTYPE_IO_CHAIN,
4604 // Each subpass has multiple inputs and multiple outputs attachment
4605 ALLOCATIONTYPE_IO_GENERIC
4608 const AllocationType allocationTypes[] =
4610 ALLOCATIONTYPE_GROW,
4611 ALLOCATIONTYPE_SHRINK,
4612 ALLOCATIONTYPE_ROLL,
4613 ALLOCATIONTYPE_GROW_SHRINK,
4614 ALLOCATIONTYPE_IO_CHAIN,
4615 ALLOCATIONTYPE_IO_GENERIC
4618 const char* const allocationTypeStr[] =
4624 "input_output_chain",
4628 const TestConfig::RenderTypes renderCommands[] =
4630 TestConfig::RENDERTYPES_NONE,
4631 TestConfig::RENDERTYPES_CLEAR,
4632 TestConfig::RENDERTYPES_DRAW,
4633 TestConfig::RENDERTYPES_CLEAR|TestConfig::RENDERTYPES_DRAW,
4636 const TestConfig::CommandBufferTypes commandBuffers[] =
4638 TestConfig::COMMANDBUFFERTYPES_INLINE,
4639 TestConfig::COMMANDBUFFERTYPES_SECONDARY,
4640 TestConfig::COMMANDBUFFERTYPES_INLINE|TestConfig::COMMANDBUFFERTYPES_SECONDARY
4643 const TestConfig::ImageMemory imageMemories[] =
4645 TestConfig::IMAGEMEMORY_STRICT,
4646 TestConfig::IMAGEMEMORY_LAZY,
4647 TestConfig::IMAGEMEMORY_STRICT|TestConfig::IMAGEMEMORY_LAZY
4650 const UVec2 targetSizes[] =
4656 const UVec2 renderPositions[] =
4662 const UVec2 renderSizes[] =
4668 tcu::TestContext& testCtx = group->getTestContext();
4669 de::Random rng (3700649827u);
4671 for (size_t allocationTypeNdx = 0; allocationTypeNdx < DE_LENGTH_OF_ARRAY(allocationTypes); allocationTypeNdx++)
4673 const AllocationType allocationType = allocationTypes[allocationTypeNdx];
4674 const size_t testCaseCount = 100;
4675 de::MovePtr<tcu::TestCaseGroup> allocationTypeGroup (new tcu::TestCaseGroup(testCtx, allocationTypeStr[allocationTypeNdx], allocationTypeStr[allocationTypeNdx]));
4677 for (size_t testCaseNdx = 0; testCaseNdx < testCaseCount; testCaseNdx++)
4679 if (allocationType == ALLOCATIONTYPE_IO_GENERIC)
4681 const deUint32 attachmentCount = 4u + rng.getUint32() % 31u;
4682 const deUint32 subpassCount = 4u + rng.getUint32() % 31u;
4683 vector<Attachment> attachments;
4685 set<deUint32> definedAttachments;
4687 vector<Subpass> subpasses;
4688 set<deUint32> colorAttachments;
4689 set<deUint32> depthStencilAttachments;
4691 for (deUint32 attachmentIndex = 0; attachmentIndex < attachmentCount; attachmentIndex++)
4693 const bool isDepthStencilAttachment = rng.getFloat() < 0.01f;
4694 const VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_1_BIT;
4695 const VkAttachmentLoadOp loadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
4696 const VkAttachmentStoreOp storeOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
4698 const VkImageLayout initialLayout = isDepthStencilAttachment
4699 ? rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalDepthStencilLayouts), DE_ARRAY_END(initialAndFinalDepthStencilLayouts))
4700 : rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalColorLayouts), DE_ARRAY_END(initialAndFinalColorLayouts));
4701 const VkImageLayout finalizeLayout = isDepthStencilAttachment
4702 ? rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalDepthStencilLayouts), DE_ARRAY_END(initialAndFinalDepthStencilLayouts))
4703 : rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalColorLayouts), DE_ARRAY_END(initialAndFinalColorLayouts));
4705 const VkAttachmentLoadOp stencilLoadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
4706 const VkAttachmentStoreOp stencilStoreOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
4708 if (isDepthStencilAttachment)
4710 const VkFormat format = rng.choose<VkFormat>(DE_ARRAY_BEGIN(s_coreDepthStencilFormats), DE_ARRAY_END(s_coreDepthStencilFormats));
4712 if (loadOp == VK_ATTACHMENT_LOAD_OP_LOAD || loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR
4713 || stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD || stencilLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR)
4714 definedAttachments.insert(attachmentIndex);
4716 depthStencilAttachments.insert(attachmentIndex);
4718 attachments.push_back(Attachment(format, sampleCount, loadOp, storeOp, stencilLoadOp, stencilStoreOp, initialLayout, finalizeLayout));
4722 const VkFormat format = rng.choose<VkFormat>(DE_ARRAY_BEGIN(s_coreColorFormats), DE_ARRAY_END(s_coreColorFormats));
4724 if (loadOp == VK_ATTACHMENT_LOAD_OP_LOAD || loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR)
4725 definedAttachments.insert(attachmentIndex);
4727 colorAttachments.insert(attachmentIndex);
4729 attachments.push_back(Attachment(format, sampleCount, loadOp, storeOp, stencilLoadOp, stencilStoreOp, initialLayout, finalizeLayout));
4732 vector<Maybe<deUint32> > lastUseOfAttachment (attachments.size(), nothing<deUint32>());
4733 vector<SubpassDependency> deps;
4735 for (deUint32 subpassIndex = 0; subpassIndex < subpassCount; subpassIndex++)
4737 const deUint32 colorAttachmentCount = depthStencilAttachments.empty()
4738 ? 1 + rng.getUint32() % de::min(4u, (deUint32)colorAttachments.size())
4739 : rng.getUint32() % (de::min(4u, (deUint32)colorAttachments.size()) + 1u);
4740 const deUint32 inputAttachmentCount = rng.getUint32() % (deUint32)(de::min<size_t>(4, definedAttachments.size()) + 1);
4741 const bool useDepthStencilAttachment = !depthStencilAttachments.empty() && (colorAttachmentCount == 0 || rng.getBool());
4742 std::vector<deUint32> subpassColorAttachments (colorAttachmentCount);
4743 std::vector<deUint32> subpassInputAttachments (inputAttachmentCount);
4744 Maybe<deUint32> depthStencilAttachment (useDepthStencilAttachment
4745 ? just(chooseRandom(rng, depthStencilAttachments))
4746 : nothing<deUint32>());
4747 std::vector<deUint32> subpassPreserveAttachments;
4749 rng.choose(colorAttachments.begin(), colorAttachments.end(), subpassColorAttachments.begin(), colorAttachmentCount);
4750 rng.choose(definedAttachments.begin(), definedAttachments.end(), subpassInputAttachments.begin(), inputAttachmentCount);
4752 for (size_t colorAttachmentNdx = 0; colorAttachmentNdx < subpassColorAttachments.size(); colorAttachmentNdx++)
4753 definedAttachments.insert(subpassColorAttachments[colorAttachmentNdx]);
4755 if (depthStencilAttachment)
4756 definedAttachments.insert(*depthStencilAttachment);
4759 std::vector<AttachmentReference> inputAttachmentReferences;
4760 std::vector<AttachmentReference> colorAttachmentReferences;
4761 AttachmentReference depthStencilAttachmentReference (VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL);
4763 for (size_t colorAttachmentNdx = 0; colorAttachmentNdx < subpassColorAttachments.size(); colorAttachmentNdx++)
4765 const deUint32 colorAttachmentIndex = subpassColorAttachments[colorAttachmentNdx];
4766 // \todo [mika 2016-08-25] Check if attachment is not used as input attachment and use other image layouts
4767 const VkImageLayout subpassLayout = VK_IMAGE_LAYOUT_GENERAL;
4769 if (lastUseOfAttachment[colorAttachmentIndex])
4771 const bool byRegion = rng.getBool();
4773 deps.push_back(SubpassDependency(*lastUseOfAttachment[colorAttachmentIndex], subpassIndex,
4774 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
4775 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
4776 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
4777 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
4779 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
4780 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
4781 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
4782 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
4784 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
4785 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT,
4787 byRegion ? (VkDependencyFlags)VK_DEPENDENCY_BY_REGION_BIT : 0u));
4790 lastUseOfAttachment[colorAttachmentIndex] = just(subpassIndex);
4792 colorAttachmentReferences.push_back(AttachmentReference((deUint32)subpassColorAttachments[colorAttachmentNdx], subpassLayout));
4795 for (size_t inputAttachmentNdx = 0; inputAttachmentNdx < subpassInputAttachments.size(); inputAttachmentNdx++)
4797 const deUint32 inputAttachmentIndex = subpassInputAttachments[inputAttachmentNdx];
4798 // \todo [mika 2016-08-25] Check if attachment is not used as color attachment and use other image layouts
4799 const VkImageLayout subpassLayout = VK_IMAGE_LAYOUT_GENERAL;
4801 if(lastUseOfAttachment[inputAttachmentIndex])
4803 if(*lastUseOfAttachment[inputAttachmentIndex] == subpassIndex)
4805 deps.push_back(SubpassDependency(subpassIndex, subpassIndex,
4806 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
4807 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
4808 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
4809 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
4811 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
4812 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
4813 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
4814 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
4816 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
4817 VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
4819 VK_DEPENDENCY_BY_REGION_BIT));
4823 const bool byRegion = rng.getBool();
4825 deps.push_back(SubpassDependency(*lastUseOfAttachment[inputAttachmentIndex], subpassIndex,
4826 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
4827 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
4828 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
4829 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
4831 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
4832 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
4833 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
4834 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
4836 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
4837 VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
4839 byRegion ? (VkDependencyFlags)VK_DEPENDENCY_BY_REGION_BIT : 0u));
4842 lastUseOfAttachment[inputAttachmentIndex] = just(subpassIndex);
4844 inputAttachmentReferences.push_back(AttachmentReference((deUint32)subpassInputAttachments[inputAttachmentNdx], subpassLayout));
4848 if (depthStencilAttachment)
4850 // \todo [mika 2016-08-25] Check if attachment is not used as input attachment and use other image layouts
4851 if (lastUseOfAttachment[*depthStencilAttachment])
4853 if(*lastUseOfAttachment[*depthStencilAttachment] == subpassIndex)
4855 deps.push_back(SubpassDependency(subpassIndex, subpassIndex,
4856 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
4857 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
4858 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
4859 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
4861 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
4862 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
4863 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
4864 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
4866 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
4867 VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
4869 VK_DEPENDENCY_BY_REGION_BIT));
4873 const bool byRegion = rng.getBool();
4875 deps.push_back(SubpassDependency(*lastUseOfAttachment[*depthStencilAttachment], subpassIndex,
4876 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
4877 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
4878 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
4879 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
4881 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
4882 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
4883 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
4884 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
4886 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
4887 VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
4889 byRegion ? (VkDependencyFlags)VK_DEPENDENCY_BY_REGION_BIT : 0u));
4893 lastUseOfAttachment[*depthStencilAttachment] = just(subpassIndex);
4894 depthStencilAttachmentReference = AttachmentReference(*depthStencilAttachment, VK_IMAGE_LAYOUT_GENERAL);
4897 depthStencilAttachmentReference = AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL);
4899 vector<deUint32> preserveAttachments;
4900 for (deUint32 attachmentIndex = 0; attachmentIndex < (deUint32)attachments.size(); attachmentIndex++)
4902 if (lastUseOfAttachment[attachmentIndex] && (*lastUseOfAttachment[attachmentIndex]) != subpassIndex)
4903 preserveAttachments.push_back(attachmentIndex);
4906 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
4907 inputAttachmentReferences,
4908 colorAttachmentReferences,
4909 vector<AttachmentReference>(),
4910 depthStencilAttachmentReference,
4911 preserveAttachments));
4915 const TestConfig::RenderTypes render = rng.choose<TestConfig::RenderTypes>(DE_ARRAY_BEGIN(renderCommands), DE_ARRAY_END(renderCommands));
4916 const TestConfig::CommandBufferTypes commandBuffer = rng.choose<TestConfig::CommandBufferTypes>(DE_ARRAY_BEGIN(commandBuffers), DE_ARRAY_END(commandBuffers));
4917 const TestConfig::ImageMemory imageMemory = rng.choose<TestConfig::ImageMemory>(DE_ARRAY_BEGIN(imageMemories), DE_ARRAY_END(imageMemories));
4919 const string testCaseName = de::toString(testCaseNdx);
4920 const UVec2 targetSize = rng.choose<UVec2>(DE_ARRAY_BEGIN(targetSizes), DE_ARRAY_END(targetSizes));
4921 const UVec2 renderPos = rng.choose<UVec2>(DE_ARRAY_BEGIN(renderPositions), DE_ARRAY_END(renderPositions));
4922 const UVec2 renderSize = rng.choose<UVec2>(DE_ARRAY_BEGIN(renderSizes), DE_ARRAY_END(renderSizes));
4924 const RenderPass renderPass (attachments, subpasses, deps);
4926 addFunctionCaseWithPrograms<TestConfig>(allocationTypeGroup.get(), testCaseName.c_str(), testCaseName.c_str(), createTestShaders, renderPassTest, TestConfig(renderPass, render, commandBuffer, imageMemory, targetSize, renderPos, renderSize, 80329));
4931 const deUint32 attachmentCount = rng.choose<deUint32>(DE_ARRAY_BEGIN(attachmentCounts), DE_ARRAY_END(attachmentCounts));
4932 vector<Attachment> attachments;
4933 vector<Subpass> subpasses;
4935 for (size_t attachmentNdx = 0; attachmentNdx < attachmentCount; attachmentNdx++)
4937 const VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_1_BIT;
4938 const VkFormat format = rng.choose<VkFormat>(DE_ARRAY_BEGIN(s_coreColorFormats), DE_ARRAY_END(s_coreColorFormats));
4939 const VkAttachmentLoadOp loadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
4940 const VkAttachmentStoreOp storeOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
4942 const VkImageLayout initialLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalColorLayouts), DE_ARRAY_END(initialAndFinalColorLayouts));
4943 const VkImageLayout finalizeLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(initialAndFinalColorLayouts), DE_ARRAY_END(initialAndFinalColorLayouts));
4945 const VkAttachmentLoadOp stencilLoadOp = rng.choose<VkAttachmentLoadOp>(DE_ARRAY_BEGIN(loadOps), DE_ARRAY_END(loadOps));
4946 const VkAttachmentStoreOp stencilStoreOp = rng.choose<VkAttachmentStoreOp>(DE_ARRAY_BEGIN(storeOps), DE_ARRAY_END(storeOps));
4948 attachments.push_back(Attachment(format, sampleCount, loadOp, storeOp, stencilLoadOp, stencilStoreOp, initialLayout, finalizeLayout));
4951 if (allocationType == ALLOCATIONTYPE_GROW)
4953 for (size_t subpassNdx = 0; subpassNdx < attachmentCount; subpassNdx++)
4955 vector<AttachmentReference> colorAttachmentReferences;
4957 for (size_t attachmentNdx = 0; attachmentNdx < subpassNdx + 1; attachmentNdx++)
4959 const VkImageLayout subpassLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayouts), DE_ARRAY_END(subpassLayouts));
4961 colorAttachmentReferences.push_back(AttachmentReference((deUint32)attachmentNdx, subpassLayout));
4964 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
4965 vector<AttachmentReference>(),
4966 colorAttachmentReferences,
4967 vector<AttachmentReference>(),
4968 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
4969 vector<deUint32>()));
4972 else if (allocationType == ALLOCATIONTYPE_SHRINK)
4974 for (size_t subpassNdx = 0; subpassNdx < attachmentCount; subpassNdx++)
4976 vector<AttachmentReference> colorAttachmentReferences;
4978 for (size_t attachmentNdx = 0; attachmentNdx < (attachmentCount - subpassNdx); attachmentNdx++)
4980 const VkImageLayout subpassLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayouts), DE_ARRAY_END(subpassLayouts));
4982 colorAttachmentReferences.push_back(AttachmentReference((deUint32)attachmentNdx, subpassLayout));
4985 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
4986 vector<AttachmentReference>(),
4987 colorAttachmentReferences,
4988 vector<AttachmentReference>(),
4989 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
4990 vector<deUint32>()));
4993 else if (allocationType == ALLOCATIONTYPE_ROLL)
4995 for (size_t subpassNdx = 0; subpassNdx < attachmentCount / 2; subpassNdx++)
4997 vector<AttachmentReference> colorAttachmentReferences;
4999 for (size_t attachmentNdx = 0; attachmentNdx < attachmentCount / 2; attachmentNdx++)
5001 const VkImageLayout subpassLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayouts), DE_ARRAY_END(subpassLayouts));
5003 colorAttachmentReferences.push_back(AttachmentReference((deUint32)(subpassNdx + attachmentNdx), subpassLayout));
5006 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
5007 vector<AttachmentReference>(),
5008 colorAttachmentReferences,
5009 vector<AttachmentReference>(),
5010 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
5011 vector<deUint32>()));
5014 else if (allocationType == ALLOCATIONTYPE_GROW_SHRINK)
5016 for (size_t subpassNdx = 0; subpassNdx < attachmentCount; subpassNdx++)
5018 vector<AttachmentReference> colorAttachmentReferences;
5020 for (size_t attachmentNdx = 0; attachmentNdx < subpassNdx + 1; attachmentNdx++)
5022 const VkImageLayout subpassLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayouts), DE_ARRAY_END(subpassLayouts));
5024 colorAttachmentReferences.push_back(AttachmentReference((deUint32)attachmentNdx, subpassLayout));
5027 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
5028 vector<AttachmentReference>(),
5029 colorAttachmentReferences,
5030 vector<AttachmentReference>(),
5031 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
5032 vector<deUint32>()));
5035 for (size_t subpassNdx = 0; subpassNdx < attachmentCount; subpassNdx++)
5037 vector<AttachmentReference> colorAttachmentReferences;
5039 for (size_t attachmentNdx = 0; attachmentNdx < (attachmentCount - subpassNdx); attachmentNdx++)
5041 const VkImageLayout subpassLayout = rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayouts), DE_ARRAY_END(subpassLayouts));
5043 colorAttachmentReferences.push_back(AttachmentReference((deUint32)attachmentNdx, subpassLayout));
5046 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
5047 vector<AttachmentReference>(),
5048 colorAttachmentReferences,
5049 vector<AttachmentReference>(),
5050 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
5051 vector<deUint32>()));
5054 else if (allocationType == ALLOCATIONTYPE_IO_CHAIN)
5056 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
5057 vector<AttachmentReference>(),
5058 vector<AttachmentReference>(1, AttachmentReference(0, rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayouts), DE_ARRAY_END(subpassLayouts)))),
5059 vector<AttachmentReference>(),
5060 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
5061 vector<deUint32>()));
5063 for (size_t subpassNdx = 1; subpassNdx < attachmentCount; subpassNdx++)
5065 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS, 0u,
5066 vector<AttachmentReference>(1, AttachmentReference((deUint32)(subpassNdx - 1), VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL)),
5067 vector<AttachmentReference>(1, AttachmentReference((deUint32)(subpassNdx), rng.choose<VkImageLayout>(DE_ARRAY_BEGIN(subpassLayouts), DE_ARRAY_END(subpassLayouts)))),
5068 vector<AttachmentReference>(),
5069 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
5070 vector<deUint32>()));
5074 DE_FATAL("Unknown allocation type");
5077 const TestConfig::RenderTypes render = rng.choose<TestConfig::RenderTypes>(DE_ARRAY_BEGIN(renderCommands), DE_ARRAY_END(renderCommands));
5078 const TestConfig::CommandBufferTypes commandBuffer = rng.choose<TestConfig::CommandBufferTypes>(DE_ARRAY_BEGIN(commandBuffers), DE_ARRAY_END(commandBuffers));
5079 const TestConfig::ImageMemory imageMemory = rng.choose<TestConfig::ImageMemory>(DE_ARRAY_BEGIN(imageMemories), DE_ARRAY_END(imageMemories));
5081 const string testCaseName = de::toString(testCaseNdx);
5082 const UVec2 targetSize = rng.choose<UVec2>(DE_ARRAY_BEGIN(targetSizes), DE_ARRAY_END(targetSizes));
5083 const UVec2 renderPos = rng.choose<UVec2>(DE_ARRAY_BEGIN(renderPositions), DE_ARRAY_END(renderPositions));
5084 const UVec2 renderSize = rng.choose<UVec2>(DE_ARRAY_BEGIN(renderSizes), DE_ARRAY_END(renderSizes));
5086 vector<SubpassDependency> deps;
5088 for (size_t subpassNdx = 0; subpassNdx < subpasses.size() - 1; subpassNdx++)
5090 const bool byRegion = rng.getBool();
5091 deps.push_back(SubpassDependency((deUint32)subpassNdx, (deUint32)subpassNdx + 1,
5092 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
5093 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
5094 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
5095 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
5097 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
5098 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
5099 | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
5100 | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
5102 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
5103 VK_ACCESS_COLOR_ATTACHMENT_READ_BIT,
5105 byRegion ? (VkDependencyFlags)VK_DEPENDENCY_BY_REGION_BIT : 0u));
5108 const RenderPass renderPass (attachments, subpasses, deps);
5110 addFunctionCaseWithPrograms<TestConfig>(allocationTypeGroup.get(), testCaseName.c_str(), testCaseName.c_str(), createTestShaders, renderPassTest, TestConfig(renderPass, render, commandBuffer, imageMemory, targetSize, renderPos, renderSize, 80329));
5114 group->addChild(allocationTypeGroup.release());
5118 void addSimpleTests (tcu::TestCaseGroup* group)
5120 const UVec2 targetSize (64, 64);
5121 const UVec2 renderPos (0, 0);
5122 const UVec2 renderSize (64, 64);
5126 const RenderPass renderPass (vector<Attachment>(1, Attachment(VK_FORMAT_R8G8B8A8_UNORM,
5127 VK_SAMPLE_COUNT_1_BIT,
5128 VK_ATTACHMENT_LOAD_OP_CLEAR,
5129 VK_ATTACHMENT_STORE_OP_STORE,
5130 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
5131 VK_ATTACHMENT_STORE_OP_DONT_CARE,
5132 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
5133 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
5134 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
5136 vector<AttachmentReference>(),
5137 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
5138 vector<AttachmentReference>(),
5139 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
5140 vector<deUint32>())),
5141 vector<SubpassDependency>());
5143 addFunctionCaseWithPrograms<TestConfig>(group, "color", "Single color attachment case.", createTestShaders, renderPassTest, TestConfig(renderPass, TestConfig::RENDERTYPES_DRAW, TestConfig::COMMANDBUFFERTYPES_INLINE, TestConfig::IMAGEMEMORY_STRICT, targetSize, renderPos, renderSize, 90239));
5148 const RenderPass renderPass (vector<Attachment>(1, Attachment(VK_FORMAT_X8_D24_UNORM_PACK32,
5149 VK_SAMPLE_COUNT_1_BIT,
5150 VK_ATTACHMENT_LOAD_OP_CLEAR,
5151 VK_ATTACHMENT_STORE_OP_STORE,
5152 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
5153 VK_ATTACHMENT_STORE_OP_DONT_CARE,
5154 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
5155 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)),
5156 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
5158 vector<AttachmentReference>(),
5159 vector<AttachmentReference>(),
5160 vector<AttachmentReference>(),
5161 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
5162 vector<deUint32>())),
5163 vector<SubpassDependency>());
5165 addFunctionCaseWithPrograms<TestConfig>(group, "depth", "Single depth attachment case.", createTestShaders, renderPassTest, TestConfig(renderPass, TestConfig::RENDERTYPES_DRAW, TestConfig::COMMANDBUFFERTYPES_INLINE, TestConfig::IMAGEMEMORY_STRICT, targetSize, renderPos, renderSize, 90239));
5170 const RenderPass renderPass (vector<Attachment>(1, Attachment(VK_FORMAT_S8_UINT,
5171 VK_SAMPLE_COUNT_1_BIT,
5172 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
5173 VK_ATTACHMENT_STORE_OP_DONT_CARE,
5174 VK_ATTACHMENT_LOAD_OP_CLEAR,
5175 VK_ATTACHMENT_STORE_OP_STORE,
5176 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
5177 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)),
5178 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
5180 vector<AttachmentReference>(),
5181 vector<AttachmentReference>(),
5182 vector<AttachmentReference>(),
5183 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
5184 vector<deUint32>())),
5185 vector<SubpassDependency>());
5187 addFunctionCaseWithPrograms<TestConfig>(group, "stencil", "Single stencil attachment case.", createTestShaders, renderPassTest, TestConfig(renderPass, TestConfig::RENDERTYPES_DRAW, TestConfig::COMMANDBUFFERTYPES_INLINE, TestConfig::IMAGEMEMORY_STRICT, targetSize, renderPos, renderSize, 90239));
5192 const RenderPass renderPass (vector<Attachment>(1, Attachment(VK_FORMAT_D24_UNORM_S8_UINT,
5193 VK_SAMPLE_COUNT_1_BIT,
5194 VK_ATTACHMENT_LOAD_OP_CLEAR,
5195 VK_ATTACHMENT_STORE_OP_STORE,
5196 VK_ATTACHMENT_LOAD_OP_CLEAR,
5197 VK_ATTACHMENT_STORE_OP_STORE,
5198 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
5199 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)),
5200 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
5202 vector<AttachmentReference>(),
5203 vector<AttachmentReference>(),
5204 vector<AttachmentReference>(),
5205 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
5206 vector<deUint32>())),
5207 vector<SubpassDependency>());
5209 addFunctionCaseWithPrograms<TestConfig>(group, "depth_stencil", "Single depth stencil attachment case.", createTestShaders, renderPassTest, TestConfig(renderPass, TestConfig::RENDERTYPES_DRAW, TestConfig::COMMANDBUFFERTYPES_INLINE, TestConfig::IMAGEMEMORY_STRICT, targetSize, renderPos, renderSize, 90239));
5214 const Attachment attachments[] =
5216 Attachment(VK_FORMAT_R8G8B8A8_UNORM,
5217 VK_SAMPLE_COUNT_1_BIT,
5218 VK_ATTACHMENT_LOAD_OP_CLEAR,
5219 VK_ATTACHMENT_STORE_OP_STORE,
5220 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
5221 VK_ATTACHMENT_STORE_OP_DONT_CARE,
5222 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
5223 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL),
5224 Attachment(VK_FORMAT_X8_D24_UNORM_PACK32,
5225 VK_SAMPLE_COUNT_1_BIT,
5226 VK_ATTACHMENT_LOAD_OP_CLEAR,
5227 VK_ATTACHMENT_STORE_OP_STORE,
5228 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
5229 VK_ATTACHMENT_STORE_OP_DONT_CARE,
5230 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
5231 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
5234 const RenderPass renderPass (vector<Attachment>(DE_ARRAY_BEGIN(attachments), DE_ARRAY_END(attachments)),
5235 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
5237 vector<AttachmentReference>(),
5238 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
5239 vector<AttachmentReference>(),
5240 AttachmentReference(1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
5241 vector<deUint32>())),
5242 vector<SubpassDependency>());
5244 addFunctionCaseWithPrograms<TestConfig>(group, "color_depth", "Color and depth attachment case.", createTestShaders, renderPassTest, TestConfig(renderPass, TestConfig::RENDERTYPES_DRAW, TestConfig::COMMANDBUFFERTYPES_INLINE, TestConfig::IMAGEMEMORY_STRICT, targetSize, renderPos, renderSize, 90239));
5249 const Attachment attachments[] =
5251 Attachment(VK_FORMAT_R8G8B8A8_UNORM,
5252 VK_SAMPLE_COUNT_1_BIT,
5253 VK_ATTACHMENT_LOAD_OP_CLEAR,
5254 VK_ATTACHMENT_STORE_OP_STORE,
5255 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
5256 VK_ATTACHMENT_STORE_OP_DONT_CARE,
5257 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
5258 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL),
5259 Attachment(VK_FORMAT_S8_UINT,
5260 VK_SAMPLE_COUNT_1_BIT,
5261 VK_ATTACHMENT_LOAD_OP_CLEAR,
5262 VK_ATTACHMENT_STORE_OP_STORE,
5263 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
5264 VK_ATTACHMENT_STORE_OP_DONT_CARE,
5265 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
5266 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
5269 const RenderPass renderPass (vector<Attachment>(DE_ARRAY_BEGIN(attachments), DE_ARRAY_END(attachments)),
5270 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
5272 vector<AttachmentReference>(),
5273 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
5274 vector<AttachmentReference>(),
5275 AttachmentReference(1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
5276 vector<deUint32>())),
5277 vector<SubpassDependency>());
5280 addFunctionCaseWithPrograms<TestConfig>(group, "color_stencil", "Color and stencil attachment case.", createTestShaders, renderPassTest, TestConfig(renderPass, TestConfig::RENDERTYPES_DRAW, TestConfig::COMMANDBUFFERTYPES_INLINE, TestConfig::IMAGEMEMORY_STRICT, targetSize, renderPos, renderSize, 90239));
5283 // color_depth_stencil
5285 const Attachment attachments[] =
5287 Attachment(VK_FORMAT_R8G8B8A8_UNORM,
5288 VK_SAMPLE_COUNT_1_BIT,
5289 VK_ATTACHMENT_LOAD_OP_CLEAR,
5290 VK_ATTACHMENT_STORE_OP_STORE,
5291 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
5292 VK_ATTACHMENT_STORE_OP_DONT_CARE,
5293 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
5294 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL),
5295 Attachment(VK_FORMAT_D24_UNORM_S8_UINT,
5296 VK_SAMPLE_COUNT_1_BIT,
5297 VK_ATTACHMENT_LOAD_OP_CLEAR,
5298 VK_ATTACHMENT_STORE_OP_STORE,
5299 VK_ATTACHMENT_LOAD_OP_CLEAR,
5300 VK_ATTACHMENT_STORE_OP_STORE,
5301 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
5302 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
5305 const RenderPass renderPass (vector<Attachment>(DE_ARRAY_BEGIN(attachments), DE_ARRAY_END(attachments)),
5306 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
5308 vector<AttachmentReference>(),
5309 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
5310 vector<AttachmentReference>(),
5311 AttachmentReference(1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
5312 vector<deUint32>())),
5313 vector<SubpassDependency>());
5315 addFunctionCaseWithPrograms<TestConfig>(group, "color_depth_stencil", "Color, depth and stencil attachment case.", createTestShaders, renderPassTest, TestConfig(renderPass, TestConfig::RENDERTYPES_DRAW, TestConfig::COMMANDBUFFERTYPES_INLINE, TestConfig::IMAGEMEMORY_STRICT, targetSize, renderPos, renderSize, 90239));
5319 std::string formatToName (VkFormat format)
5321 const std::string formatStr = de::toString(format);
5322 const std::string prefix = "VK_FORMAT_";
5324 DE_ASSERT(formatStr.substr(0, prefix.length()) == prefix);
5326 return de::toLower(formatStr.substr(prefix.length()));
5329 void addFormatTests (tcu::TestCaseGroup* group)
5331 tcu::TestContext& testCtx = group->getTestContext();
5333 const UVec2 targetSize (64, 64);
5334 const UVec2 renderPos (0, 0);
5335 const UVec2 renderSize (64, 64);
5339 const char* const str;
5340 const VkAttachmentStoreOp op;
5343 { "store", VK_ATTACHMENT_STORE_OP_STORE },
5344 { "dont_care", VK_ATTACHMENT_STORE_OP_DONT_CARE }
5349 const char* const str;
5350 const VkAttachmentLoadOp op;
5353 { "clear", VK_ATTACHMENT_LOAD_OP_CLEAR },
5354 { "load", VK_ATTACHMENT_LOAD_OP_LOAD },
5355 { "dont_care", VK_ATTACHMENT_LOAD_OP_DONT_CARE }
5360 const char* const str;
5361 const TestConfig::RenderTypes types;
5364 { "clear", TestConfig::RENDERTYPES_CLEAR },
5365 { "draw", TestConfig::RENDERTYPES_DRAW },
5366 { "clear_draw", TestConfig::RENDERTYPES_CLEAR|TestConfig::RENDERTYPES_DRAW }
5370 for (size_t formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(s_coreColorFormats); formatNdx++)
5372 const VkFormat format = s_coreColorFormats[formatNdx];
5373 de::MovePtr<tcu::TestCaseGroup> formatGroup (new tcu::TestCaseGroup(testCtx, formatToName(format).c_str(), de::toString(format).c_str()));
5375 for (size_t loadOpNdx = 0; loadOpNdx < DE_LENGTH_OF_ARRAY(loadOps); loadOpNdx++)
5377 const VkAttachmentLoadOp loadOp = loadOps[loadOpNdx].op;
5378 de::MovePtr<tcu::TestCaseGroup> loadOpGroup (new tcu::TestCaseGroup(testCtx, loadOps[loadOpNdx].str, loadOps[loadOpNdx].str));
5380 for (size_t renderTypeNdx = 0; renderTypeNdx < DE_LENGTH_OF_ARRAY(renderTypes); renderTypeNdx++)
5382 const RenderPass renderPass (vector<Attachment>(1, Attachment(format,
5383 VK_SAMPLE_COUNT_1_BIT,
5385 VK_ATTACHMENT_STORE_OP_STORE,
5386 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
5387 VK_ATTACHMENT_STORE_OP_DONT_CARE,
5388 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
5389 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
5390 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
5392 vector<AttachmentReference>(),
5393 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
5394 vector<AttachmentReference>(),
5395 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
5396 vector<deUint32>())),
5397 vector<SubpassDependency>());
5399 addFunctionCaseWithPrograms<TestConfig>(loadOpGroup.get(), renderTypes[renderTypeNdx].str, renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, TestConfig(renderPass, renderTypes[renderTypeNdx].types, TestConfig::COMMANDBUFFERTYPES_INLINE, TestConfig::IMAGEMEMORY_STRICT, targetSize, renderPos, renderSize, 90239));
5402 formatGroup->addChild(loadOpGroup.release());
5406 de::MovePtr<tcu::TestCaseGroup> inputGroup (new tcu::TestCaseGroup(testCtx, "input", "Test attachment format as input"));
5408 for (size_t loadOpNdx = 0; loadOpNdx < DE_LENGTH_OF_ARRAY(loadOps); loadOpNdx++)
5410 const VkAttachmentLoadOp loadOp = loadOps[loadOpNdx].op;
5411 de::MovePtr<tcu::TestCaseGroup> loadOpGroup (new tcu::TestCaseGroup(testCtx, loadOps[loadOpNdx].str, loadOps[loadOpNdx].str));
5413 for (size_t storeOpNdx = 0; storeOpNdx < DE_LENGTH_OF_ARRAY(storeOps); storeOpNdx++)
5415 const VkAttachmentStoreOp storeOp = storeOps[storeOpNdx].op;
5416 de::MovePtr<tcu::TestCaseGroup> storeOpGroup (new tcu::TestCaseGroup(testCtx, storeOps[storeOpNdx].str, storeOps[storeOpNdx].str));
5418 for (size_t renderTypeNdx = 0; renderTypeNdx < DE_LENGTH_OF_ARRAY(renderTypes); renderTypeNdx++)
5421 vector<Attachment> attachments;
5422 vector<Subpass> subpasses;
5423 vector<SubpassDependency> deps;
5425 attachments.push_back(Attachment(format,
5426 VK_SAMPLE_COUNT_1_BIT,
5429 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
5430 VK_ATTACHMENT_STORE_OP_DONT_CARE,
5431 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
5432 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
5434 attachments.push_back(Attachment(vk::VK_FORMAT_R8G8B8A8_UNORM,
5435 VK_SAMPLE_COUNT_1_BIT,
5436 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
5437 VK_ATTACHMENT_STORE_OP_STORE,
5438 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
5439 VK_ATTACHMENT_STORE_OP_DONT_CARE,
5440 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
5441 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
5443 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
5445 vector<AttachmentReference>(),
5446 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
5447 vector<AttachmentReference>(),
5448 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
5449 vector<deUint32>()));
5450 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
5452 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL)),
5453 vector<AttachmentReference>(1, AttachmentReference(1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
5454 vector<AttachmentReference>(),
5455 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
5456 vector<deUint32>()));
5458 deps.push_back(SubpassDependency(0, 1,
5460 vk::VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
5461 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
5463 vk::VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
5464 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
5465 vk::VK_DEPENDENCY_BY_REGION_BIT));
5468 const RenderPass renderPass (attachments, subpasses, deps);
5470 addFunctionCaseWithPrograms<TestConfig>(storeOpGroup.get(), renderTypes[renderTypeNdx].str, renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, TestConfig(renderPass, renderTypes[renderTypeNdx].types, TestConfig::COMMANDBUFFERTYPES_INLINE, TestConfig::IMAGEMEMORY_STRICT, targetSize, renderPos, renderSize, 89246));
5474 vector<Attachment> attachments;
5475 vector<Subpass> subpasses;
5476 vector<SubpassDependency> deps;
5478 attachments.push_back(Attachment(format,
5479 VK_SAMPLE_COUNT_1_BIT,
5482 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
5483 VK_ATTACHMENT_STORE_OP_DONT_CARE,
5484 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
5485 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
5487 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
5489 vector<AttachmentReference>(),
5490 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
5491 vector<AttachmentReference>(),
5492 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
5493 vector<deUint32>()));
5494 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
5496 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_GENERAL)),
5497 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_GENERAL)),
5498 vector<AttachmentReference>(),
5499 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
5500 vector<deUint32>()));
5502 deps.push_back(SubpassDependency(0, 1,
5503 vk::VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
5504 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
5506 vk::VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
5507 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
5508 vk::VK_DEPENDENCY_BY_REGION_BIT));
5511 const RenderPass renderPass (attachments, subpasses, deps);
5513 addFunctionCaseWithPrograms<TestConfig>(storeOpGroup.get(), string("self_dep_") + renderTypes[renderTypeNdx].str, string("self_dep_") + renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, TestConfig(renderPass, renderTypes[renderTypeNdx].types, TestConfig::COMMANDBUFFERTYPES_INLINE, TestConfig::IMAGEMEMORY_STRICT, targetSize, renderPos, renderSize, 89246));
5518 loadOpGroup->addChild(storeOpGroup.release());
5521 inputGroup->addChild(loadOpGroup.release());
5524 formatGroup->addChild(inputGroup.release());
5527 group->addChild(formatGroup.release());
5530 // Depth stencil formats
5531 for (size_t formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(s_coreDepthStencilFormats); formatNdx++)
5533 const VkFormat vkFormat = s_coreDepthStencilFormats[formatNdx];
5534 de::MovePtr<tcu::TestCaseGroup> formatGroup (new tcu::TestCaseGroup(testCtx, formatToName(vkFormat).c_str(), de::toString(vkFormat).c_str()));
5536 for (size_t loadOpNdx = 0; loadOpNdx < DE_LENGTH_OF_ARRAY(loadOps); loadOpNdx++)
5538 const VkAttachmentLoadOp loadOp = loadOps[loadOpNdx].op;
5539 de::MovePtr<tcu::TestCaseGroup> loadOpGroup (new tcu::TestCaseGroup(testCtx, loadOps[loadOpNdx].str, loadOps[loadOpNdx].str));
5541 for (size_t renderTypeNdx = 0; renderTypeNdx < DE_LENGTH_OF_ARRAY(renderTypes); renderTypeNdx++)
5543 const tcu::TextureFormat format = mapVkFormat(vkFormat);
5544 const bool isStencilAttachment = hasStencilComponent(format.order);
5545 const bool isDepthAttachment = hasDepthComponent(format.order);
5546 const RenderPass renderPass (vector<Attachment>(1, Attachment(vkFormat,
5547 VK_SAMPLE_COUNT_1_BIT,
5548 isDepthAttachment ? loadOp : VK_ATTACHMENT_LOAD_OP_DONT_CARE,
5549 isDepthAttachment ? VK_ATTACHMENT_STORE_OP_STORE :VK_ATTACHMENT_STORE_OP_DONT_CARE,
5550 isStencilAttachment ? loadOp : VK_ATTACHMENT_LOAD_OP_DONT_CARE,
5551 isStencilAttachment ? VK_ATTACHMENT_STORE_OP_STORE :VK_ATTACHMENT_STORE_OP_DONT_CARE,
5552 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
5553 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL)),
5554 vector<Subpass>(1, Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
5556 vector<AttachmentReference>(),
5557 vector<AttachmentReference>(),
5558 vector<AttachmentReference>(),
5559 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
5560 vector<deUint32>())),
5561 vector<SubpassDependency>());
5563 addFunctionCaseWithPrograms<TestConfig>(loadOpGroup.get(), renderTypes[renderTypeNdx].str, renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, TestConfig(renderPass, renderTypes[renderTypeNdx].types, TestConfig::COMMANDBUFFERTYPES_INLINE, TestConfig::IMAGEMEMORY_STRICT, targetSize, renderPos, renderSize, 90239));
5566 formatGroup->addChild(loadOpGroup.release());
5570 de::MovePtr<tcu::TestCaseGroup> inputGroup (new tcu::TestCaseGroup(testCtx, "input", "Test attachment format as input"));
5572 for (size_t loadOpNdx = 0; loadOpNdx < DE_LENGTH_OF_ARRAY(loadOps); loadOpNdx++)
5574 const VkAttachmentLoadOp loadOp = loadOps[loadOpNdx].op;
5575 de::MovePtr<tcu::TestCaseGroup> loadOpGroup (new tcu::TestCaseGroup(testCtx, loadOps[loadOpNdx].str, loadOps[loadOpNdx].str));
5577 for (size_t storeOpNdx = 0; storeOpNdx < DE_LENGTH_OF_ARRAY(storeOps); storeOpNdx++)
5579 const VkAttachmentStoreOp storeOp = storeOps[storeOpNdx].op;
5580 de::MovePtr<tcu::TestCaseGroup> storeOpGroup (new tcu::TestCaseGroup(testCtx, storeOps[storeOpNdx].str, storeOps[storeOpNdx].str));
5582 for (size_t renderTypeNdx = 0; renderTypeNdx < DE_LENGTH_OF_ARRAY(renderTypes); renderTypeNdx++)
5585 vector<Attachment> attachments;
5586 vector<Subpass> subpasses;
5587 vector<SubpassDependency> deps;
5589 attachments.push_back(Attachment(vkFormat,
5590 VK_SAMPLE_COUNT_1_BIT,
5593 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
5594 VK_ATTACHMENT_STORE_OP_DONT_CARE,
5595 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
5596 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL));
5598 attachments.push_back(Attachment(vk::VK_FORMAT_R8G8B8A8_UNORM,
5599 VK_SAMPLE_COUNT_1_BIT,
5600 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
5601 VK_ATTACHMENT_STORE_OP_STORE,
5602 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
5603 VK_ATTACHMENT_STORE_OP_DONT_CARE,
5604 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
5605 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
5607 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
5609 vector<AttachmentReference>(),
5610 vector<AttachmentReference>(),
5611 vector<AttachmentReference>(),
5612 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
5613 vector<deUint32>()));
5614 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
5616 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL)),
5617 vector<AttachmentReference>(1, AttachmentReference(1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)),
5618 vector<AttachmentReference>(),
5619 AttachmentReference(VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_GENERAL),
5620 vector<deUint32>()));
5622 deps.push_back(SubpassDependency(0, 1,
5623 vk::VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
5624 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
5626 vk::VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
5627 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
5630 deps.push_back(SubpassDependency(1, 1,
5631 vk::VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
5632 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
5634 vk::VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
5635 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
5636 vk::VK_DEPENDENCY_BY_REGION_BIT));
5638 const RenderPass renderPass (attachments, subpasses, deps);
5640 addFunctionCaseWithPrograms<TestConfig>(storeOpGroup.get(), renderTypes[renderTypeNdx].str, renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, TestConfig(renderPass, renderTypes[renderTypeNdx].types, TestConfig::COMMANDBUFFERTYPES_INLINE, TestConfig::IMAGEMEMORY_STRICT, targetSize, renderPos, renderSize, 89246));
5644 vector<Attachment> attachments;
5645 vector<Subpass> subpasses;
5646 vector<SubpassDependency> deps;
5648 attachments.push_back(Attachment(vkFormat,
5649 VK_SAMPLE_COUNT_1_BIT,
5652 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
5653 VK_ATTACHMENT_STORE_OP_DONT_CARE,
5654 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
5655 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL));
5657 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
5659 vector<AttachmentReference>(),
5660 vector<AttachmentReference>(),
5661 vector<AttachmentReference>(),
5662 AttachmentReference(0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL),
5663 vector<deUint32>()));
5664 subpasses.push_back(Subpass(VK_PIPELINE_BIND_POINT_GRAPHICS,
5666 vector<AttachmentReference>(1, AttachmentReference(0, VK_IMAGE_LAYOUT_GENERAL)),
5667 vector<AttachmentReference>(),
5668 vector<AttachmentReference>(),
5669 AttachmentReference(0, VK_IMAGE_LAYOUT_GENERAL),
5670 vector<deUint32>()));
5672 deps.push_back(SubpassDependency(0, 1,
5673 vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
5674 vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
5676 vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
5677 vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
5678 vk::VK_DEPENDENCY_BY_REGION_BIT));
5681 const RenderPass renderPass (attachments, subpasses, deps);
5683 addFunctionCaseWithPrograms<TestConfig>(storeOpGroup.get(), string("self_dep_") + renderTypes[renderTypeNdx].str, string("self_dep_") + renderTypes[renderTypeNdx].str, createTestShaders, renderPassTest, TestConfig(renderPass, renderTypes[renderTypeNdx].types, TestConfig::COMMANDBUFFERTYPES_INLINE, TestConfig::IMAGEMEMORY_STRICT, targetSize, renderPos, renderSize, 89246));
5688 loadOpGroup->addChild(storeOpGroup.release());
5691 inputGroup->addChild(loadOpGroup.release());
5694 formatGroup->addChild(inputGroup.release());
5697 group->addChild(formatGroup.release());
5703 tcu::TestCaseGroup* createRenderPassTests (tcu::TestContext& testCtx)
5705 de::MovePtr<tcu::TestCaseGroup> renderpassTests (new tcu::TestCaseGroup(testCtx, "renderpass", "RenderPass Tests"));
5707 addTestGroup(renderpassTests.get(), "simple", "Simple basic render pass tests", addSimpleTests);
5708 addTestGroup(renderpassTests.get(), "formats", "Tests for different image formats.", addFormatTests);
5709 addTestGroup(renderpassTests.get(), "attachment", "Attachment format and count tests with load and store ops and image layouts", addAttachmentTests);
5710 addTestGroup(renderpassTests.get(), "attachment_allocation", "Attachment allocation tests", addAttachmentAllocationTests);
5712 return renderpassTests.release();