@@ -80,6 +80,33 @@ Headset::Headset(const Context* context) : context(context)
8080 resolveAttachmentReference.attachment = 2u ;
8181 resolveAttachmentReference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8282
83+ // This subpass dependency waits with the transition to the color attachment optimal layout that takes place when
84+ // calling vkCmdBeginRenderPass() until the draw calls in the render pass are in the appropriate pipeline stages
85+ VkSubpassDependency subpassDependencyRenderPassBegin;
86+ subpassDependencyRenderPassBegin.dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
87+ subpassDependencyRenderPassBegin.srcSubpass = VK_SUBPASS_EXTERNAL;
88+ subpassDependencyRenderPassBegin.dstSubpass = 0 ;
89+ subpassDependencyRenderPassBegin.srcAccessMask = VK_ACCESS_NONE;
90+ subpassDependencyRenderPassBegin.dstAccessMask =
91+ VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
92+ subpassDependencyRenderPassBegin.srcStageMask =
93+ VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT;
94+ subpassDependencyRenderPassBegin.dstStageMask =
95+ VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT;
96+
97+ // This subpass dependency ensures that all color and depth/stencil attachment writes in the color attachment output
98+ // and late fragment tests stages have finished before any draw calls after vkCmdEndRenderPass() begin
99+ VkSubpassDependency subpassDependencyRenderPassEnd;
100+ subpassDependencyRenderPassEnd.dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
101+ subpassDependencyRenderPassEnd.srcSubpass = 0 ;
102+ subpassDependencyRenderPassEnd.dstSubpass = VK_SUBPASS_EXTERNAL;
103+ subpassDependencyRenderPassEnd.srcAccessMask =
104+ VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
105+ subpassDependencyRenderPassEnd.dstAccessMask = VK_ACCESS_NONE;
106+ subpassDependencyRenderPassEnd.srcStageMask =
107+ VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT;
108+ subpassDependencyRenderPassEnd.dstStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
109+
83110 VkSubpassDescription subpassDescription{};
84111 subpassDescription.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
85112 subpassDescription.colorAttachmentCount = 1u ;
@@ -90,12 +117,16 @@ Headset::Headset(const Context* context) : context(context)
90117 const std::array attachments = { colorAttachmentDescription, depthAttachmentDescription,
91118 resolveAttachmentDescription };
92119
120+ const std::array subpassDependencies = { subpassDependencyRenderPassBegin, subpassDependencyRenderPassEnd };
121+
93122 VkRenderPassCreateInfo renderPassCreateInfo{ VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO };
94123 renderPassCreateInfo.pNext = &renderPassMultiviewCreateInfo;
95124 renderPassCreateInfo.attachmentCount = static_cast <uint32_t >(attachments.size ());
96125 renderPassCreateInfo.pAttachments = attachments.data ();
97126 renderPassCreateInfo.subpassCount = 1u ;
98127 renderPassCreateInfo.pSubpasses = &subpassDescription;
128+ renderPassCreateInfo.dependencyCount = static_cast <uint32_t >(subpassDependencies.size ());
129+ renderPassCreateInfo.pDependencies = subpassDependencies.data ();
99130 if (vkCreateRenderPass (device, &renderPassCreateInfo, nullptr , &renderPass) != VK_SUCCESS)
100131 {
101132 util::error (Error::GenericVulkan);
0 commit comments