Skip to content

Commit

Permalink
[Impeller] fix image layout when resolve texture has mip levels.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahwilliams committed Dec 15, 2024
1 parent 93b7c61 commit 37de16c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
35 changes: 25 additions & 10 deletions impeller/renderer/backend/vulkan/render_pass_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
#include "impeller/renderer/backend/vulkan/sampler_vk.h"
#include "impeller/renderer/backend/vulkan/shared_object_vk.h"
#include "impeller/renderer/backend/vulkan/texture_vk.h"
#include "vulkan/vulkan.hpp"
#include "vulkan/vulkan_handles.hpp"

namespace impeller {

Expand Down Expand Up @@ -91,15 +89,8 @@ SharedHandleVK<vk::RenderPass> RenderPassVK::CreateVKRenderPass(
attachment.texture->GetTextureDescriptor().format, //
attachment.texture->GetTextureDescriptor().sample_count, //
attachment.load_action, //
attachment.store_action, //
TextureVK::Cast(*attachment.texture).GetLayout() //
attachment.store_action //
);
TextureVK::Cast(*attachment.texture)
.SetLayoutWithoutEncoding(vk::ImageLayout::eGeneral);
if (attachment.resolve_texture) {
TextureVK::Cast(*attachment.resolve_texture)
.SetLayoutWithoutEncoding(vk::ImageLayout::eGeneral);
}
return true;
});

Expand Down Expand Up @@ -202,6 +193,30 @@ RenderPassVK::RenderPassVK(const std::shared_ptr<const Context>& context,
pass_info.setPClearValues(clears.data());
pass_info.setClearValueCount(clear_count);

if (resolve_image_vk_) {
// If the resolve image has mip levels, only mip level 0 will be
// transitioned by the render pass. All subsequent mip levels must have an
// explicit barrier inserted to transition from undefined.
if (resolve_image_vk_->GetTextureDescriptor().mip_count > 1) {
BarrierVK barrier;
barrier.new_layout = vk::ImageLayout::eGeneral;
barrier.cmd_buffer = command_buffer_vk_;
barrier.src_access = vk::AccessFlagBits::eShaderRead;
barrier.src_stage = vk::PipelineStageFlagBits::eFragmentShader;
barrier.dst_access = vk::AccessFlagBits::eColorAttachmentWrite |
vk::AccessFlagBits::eTransferWrite;
barrier.dst_stage = vk::PipelineStageFlagBits::eColorAttachmentOutput |
vk::PipelineStageFlagBits::eTransfer;
TextureVK::Cast(*resolve_image_vk_).SetLayout(barrier);
} else {
TextureVK::Cast(*resolve_image_vk_)
.SetLayoutWithoutEncoding(vk::ImageLayout::eGeneral);
}
} else if (color_image_vk_) {
TextureVK::Cast(*resolve_image_vk_)
.SetLayoutWithoutEncoding(vk::ImageLayout::eGeneral);
}

command_buffer_vk_.beginRenderPass(pass_info, vk::SubpassContents::eInline);

// Set the initial viewport.
Expand Down
1 change: 0 additions & 1 deletion impeller/renderer/backend/vulkan/render_pass_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "impeller/renderer/command_buffer.h"
#include "impeller/renderer/render_pass.h"
#include "impeller/renderer/render_target.h"
#include "vulkan/vulkan_handles.hpp"

namespace impeller {

Expand Down

0 comments on commit 37de16c

Please sign in to comment.