diff --git a/src/xrt/compositor/main/comp_renderer.c b/src/xrt/compositor/main/comp_renderer.c index aeab6d4e5..bf3bf3dc7 100644 --- a/src/xrt/compositor/main/comp_renderer.c +++ b/src/xrt/compositor/main/comp_renderer.c @@ -501,7 +501,7 @@ renderer_init(struct comp_renderer *r, struct comp_compositor *c, VkExtent2D scr &r->c->nr, // r VK_FORMAT_R8G8B8A8_SRGB, // format VK_ATTACHMENT_LOAD_OP_CLEAR, // load_op - VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); // final_layout + VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); // final_layout for (uint32_t i = 0; i < ARRAY_SIZE(r->scratch_targets); i++) { render_gfx_target_resources_init( // diff --git a/src/xrt/compositor/util/comp_render.h b/src/xrt/compositor/util/comp_render.h index 8be8f8ccb..18b32772e 100644 --- a/src/xrt/compositor/util/comp_render.h +++ b/src/xrt/compositor/util/comp_render.h @@ -31,7 +31,7 @@ struct comp_layer; * which set the layout. * * The render passes of @p rsi_rtrs must be created with a final_layout of - * VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL or there will be validation errors. + * VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL or there will be validation errors. * * Expected layouts: * * Layer images: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL diff --git a/src/xrt/compositor/util/comp_render_gfx.c b/src/xrt/compositor/util/comp_render_gfx.c index 4ad4f80d4..3a2a08513 100644 --- a/src/xrt/compositor/util/comp_render_gfx.c +++ b/src/xrt/compositor/util/comp_render_gfx.c @@ -804,6 +804,44 @@ comp_render_gfx_dispatch(struct render_gfx *rr, layers, // layers layer_count); // layer_count + + VkImageSubresourceRange first_color_level_subresource_range = { + .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, + .baseMipLevel = 0, + .levelCount = 1, + .baseArrayLayer = 0, + .layerCount = 1, + }; + + VkImageLayout transition_from = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + VkImageLayout transition_to = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + + vk_cmd_image_barrier_locked( // + rr->r->vk, // + rr->r->cmd, // + rsi->color[0].image, // + VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // + VK_ACCESS_SHADER_READ_BIT, // + transition_from, // + transition_to, // + VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, // + VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, // + first_color_level_subresource_range); // + + if (rsi->color[0].image != rsi->color[1].image) { + vk_cmd_image_barrier_locked( // + rr->r->vk, // + rr->r->cmd, // + rsi->color[1].image, // + VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // + VK_ACCESS_SHADER_READ_BIT, // + transition_from, // + transition_to, // + VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, // + VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, // + first_color_level_subresource_range); // + } + VkSampler clamp_to_border_black = rr->r->samplers.clamp_to_border_black; VkSampler src_samplers[2] = { clamp_to_border_black,