@@ -31,10 +31,8 @@ namespace impeller {
3131
3232static vk::AttachmentDescription CreateAttachmentDescription (
3333 const Attachment& attachment,
34- const std::shared_ptr<CommandBufferVK>& command_buffer,
35- bool resolve_texture = false ) {
36- const auto & texture =
37- resolve_texture ? attachment.resolve_texture : attachment.texture ;
34+ const std::shared_ptr<Texture> Attachment::*texture_ptr) {
35+ const auto & texture = attachment.*texture_ptr;
3836 if (!texture) {
3937 return {};
4038 }
@@ -51,12 +49,36 @@ static vk::AttachmentDescription CreateAttachmentDescription(
5149
5250 if (desc.storage_mode == StorageMode::kDeviceTransient ) {
5351 store_action = StoreAction::kDontCare ;
54- } else if (resolve_texture) {
52+ } else if (texture_ptr == &Attachment:: resolve_texture) {
5553 store_action = StoreAction::kStore ;
5654 }
5755
5856 if (current_layout != vk::ImageLayout::ePresentSrcKHR &&
5957 current_layout != vk::ImageLayout::eUndefined) {
58+ // Note: This should incur a barrier.
59+ current_layout = vk::ImageLayout::eGeneral;
60+ }
61+
62+ return CreateAttachmentDescription (desc.format , //
63+ desc.sample_count , //
64+ load_action, //
65+ store_action, //
66+ current_layout //
67+ );
68+ }
69+
70+ static void SetTextureLayout (
71+ const Attachment& attachment,
72+ const vk::AttachmentDescription& attachment_desc,
73+ const std::shared_ptr<CommandBufferVK>& command_buffer,
74+ const std::shared_ptr<Texture> Attachment::*texture_ptr) {
75+ const auto & texture = attachment.*texture_ptr;
76+ if (!texture) {
77+ return ;
78+ }
79+ const auto & texture_vk = TextureVK::Cast (*texture);
80+
81+ if (attachment_desc.initialLayout == vk::ImageLayout::eGeneral) {
6082 BarrierVK barrier;
6183 barrier.new_layout = vk::ImageLayout::eGeneral;
6284 barrier.cmd_buffer = command_buffer->GetEncoder ()->GetCommandBuffer ();
@@ -68,22 +90,11 @@ static vk::AttachmentDescription CreateAttachmentDescription(
6890 vk::PipelineStageFlagBits::eTransfer;
6991
7092 texture_vk.SetLayout (barrier);
71- current_layout = vk::ImageLayout::eGeneral;
7293 }
7394
74- const auto attachment_desc =
75- CreateAttachmentDescription (desc.format , //
76- desc.sample_count , //
77- load_action, //
78- store_action, //
79- current_layout //
80- );
81-
8295 // Instead of transitioning layouts manually using barriers, we are going to
8396 // make the subpass perform our transitions.
8497 texture_vk.SetLayoutWithoutEncoding (attachment_desc.finalLayout );
85-
86- return attachment_desc;
8798}
8899
89100SharedHandleVK<vk::RenderPass> RenderPassVK::CreateVKRenderPass (
@@ -113,12 +124,16 @@ SharedHandleVK<vk::RenderPass> RenderPassVK::CreateVKRenderPass(
113124 vk::AttachmentReference{static_cast <uint32_t >(attachments.size ()),
114125 vk::ImageLayout::eColorAttachmentOptimal};
115126 attachments.emplace_back (
116- CreateAttachmentDescription (color, command_buffer));
127+ CreateAttachmentDescription (color, &Attachment::texture));
128+ SetTextureLayout (color, attachments.back (), command_buffer,
129+ &Attachment::texture);
117130 if (color.resolve_texture ) {
118131 resolve_refs[bind_point] = vk::AttachmentReference{
119132 static_cast <uint32_t >(attachments.size ()), vk::ImageLayout::eGeneral};
120133 attachments.emplace_back (
121- CreateAttachmentDescription (color, command_buffer, true ));
134+ CreateAttachmentDescription (color, &Attachment::resolve_texture));
135+ SetTextureLayout (color, attachments.back (), command_buffer,
136+ &Attachment::resolve_texture);
122137 }
123138 }
124139
@@ -127,7 +142,9 @@ SharedHandleVK<vk::RenderPass> RenderPassVK::CreateVKRenderPass(
127142 static_cast <uint32_t >(attachments.size ()),
128143 vk::ImageLayout::eDepthStencilAttachmentOptimal};
129144 attachments.emplace_back (
130- CreateAttachmentDescription (depth.value (), command_buffer));
145+ CreateAttachmentDescription (depth.value (), &Attachment::texture));
146+ SetTextureLayout (depth.value (), attachments.back (), command_buffer,
147+ &Attachment::texture);
131148 }
132149
133150 if (auto stencil = render_target_.GetStencilAttachment ();
@@ -136,7 +153,9 @@ SharedHandleVK<vk::RenderPass> RenderPassVK::CreateVKRenderPass(
136153 static_cast <uint32_t >(attachments.size ()),
137154 vk::ImageLayout::eDepthStencilAttachmentOptimal};
138155 attachments.emplace_back (
139- CreateAttachmentDescription (stencil.value (), command_buffer));
156+ CreateAttachmentDescription (stencil.value (), &Attachment::texture));
157+ SetTextureLayout (stencil.value (), attachments.back (), command_buffer,
158+ &Attachment::texture);
140159 }
141160
142161 vk::SubpassDescription subpass_desc;
0 commit comments