@@ -325,7 +325,11 @@ void ColorWriteEnable::setup_render_pass()
325325 attachments[i].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE ;
326326 attachments[i].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE ;
327327 attachments[i].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED ;
328- attachments[i].finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR ;
328+ // Per-attachment final layouts:
329+ // - attachment 0 is the swapchain image; first use is subpass 1 (color), so the finalLayout must be PRESENT.
330+ // - attachments 1..3 are written in subpass 0 (color) and read in subpass 1
331+ // as input attachments, so they should end as SHADER_READ_ONLY_OPTIMAL.
332+ attachments[i].finalLayout = (i == 0 ) ? VK_IMAGE_LAYOUT_PRESENT_SRC_KHR : VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL ;
329333 }
330334
331335 std::array<VkAttachmentReference, 4 > color_references = {
@@ -378,13 +382,15 @@ void ColorWriteEnable::setup_render_pass()
378382 dependencies[1 ].dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT ;
379383 dependencies[1 ].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT ;
380384
381- // Color pass to composition pass.
385+ // Color pass -> composition pass (make color attachment writes visible to input-attachment reads)
386+ // Also include COLOR_ATTACHMENT_OUTPUT/COLOR_ATTACHMENT_WRITE on the dst side so the layout
387+ // transition performed at vkCmdNextSubpass is ordered with prior color writes and the final store.
382388 dependencies[2 ].srcSubpass = 0 ;
383389 dependencies[2 ].dstSubpass = 1 ;
384390 dependencies[2 ].srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT ;
385- dependencies[2 ].dstStageMask = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT ;
391+ dependencies[2 ].dstStageMask = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT ;
386392 dependencies[2 ].srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT ;
387- dependencies[2 ].dstAccessMask = VK_ACCESS_INPUT_ATTACHMENT_READ_BIT ;
393+ dependencies[2 ].dstAccessMask = VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT ;
388394 dependencies[2 ].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT ;
389395
390396 // Composition pass to external.
0 commit comments