Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions impeller/renderer/backend/vulkan/render_pass_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "impeller/renderer/backend/vulkan/shared_object_vk.h"
#include "impeller/renderer/backend/vulkan/texture_vk.h"
#include "impeller/renderer/backend/vulkan/vk.h"
#include "vulkan/vulkan_handles.hpp"

namespace impeller {

Expand Down Expand Up @@ -79,6 +80,7 @@ static std::vector<vk::ClearValue> GetVKClearValues(

SharedHandleVK<vk::RenderPass> RenderPassVK::CreateVKRenderPass(
const ContextVK& context,
const SharedHandleVK<vk::RenderPass>& old_renderpass,
const std::shared_ptr<CommandBufferVK>& command_buffer) const {
BarrierVK barrier;
barrier.new_layout = vk::ImageLayout::eGeneral;
Expand Down Expand Up @@ -126,6 +128,9 @@ SharedHandleVK<vk::RenderPass> RenderPassVK::CreateVKRenderPass(
);
TextureVK::Cast(*stencil->texture).SetLayout(barrier);
}
if (old_renderpass != nullptr) {
return old_renderpass;
}
Comment thread
gaaclarke marked this conversation as resolved.
Outdated

auto pass = builder.Build(context.GetDevice());

Expand All @@ -143,6 +148,11 @@ RenderPassVK::RenderPassVK(const std::shared_ptr<const Context>& context,
const RenderTarget& target,
std::shared_ptr<CommandBufferVK> command_buffer)
: RenderPass(context, target), command_buffer_(std::move(command_buffer)) {
color_image_vk_ =
render_target_.GetColorAttachments().find(0u)->second.texture;
resolve_image_vk_ =
render_target_.GetColorAttachments().find(0u)->second.resolve_texture;

const auto& vk_context = ContextVK::Cast(*context);
const std::shared_ptr<CommandEncoderVK>& encoder =
command_buffer_->GetEncoder();
Expand All @@ -153,17 +163,25 @@ RenderPassVK::RenderPassVK(const std::shared_ptr<const Context>& context,
encoder->Track(attachment.resolve_texture);
return true;
});
SharedHandleVK<vk::RenderPass> maybe_render_pass;
Comment thread
gaaclarke marked this conversation as resolved.
Outdated
SharedHandleVK<vk::Framebuffer> maybe_framebuffer;
if (resolve_image_vk_) {
maybe_render_pass = TextureVK::Cast(*resolve_image_vk_).GetRenderPass();
maybe_framebuffer = TextureVK::Cast(*resolve_image_vk_).GetFramebuffer();
}

const auto& target_size = render_target_.GetRenderTargetSize();

render_pass_ = CreateVKRenderPass(vk_context, command_buffer_);
render_pass_ =
CreateVKRenderPass(vk_context, maybe_render_pass, command_buffer_);
if (!render_pass_) {
VALIDATION_LOG << "Could not create renderpass.";
is_valid_ = false;
return;
}

auto framebuffer = CreateVKFramebuffer(vk_context, *render_pass_);
auto framebuffer =
CreateVKFramebuffer(vk_context, *render_pass_, maybe_framebuffer);
if (!framebuffer) {
VALIDATION_LOG << "Could not create framebuffer.";
is_valid_ = false;
Expand All @@ -174,6 +192,10 @@ RenderPassVK::RenderPassVK(const std::shared_ptr<const Context>& context,
is_valid_ = false;
return;
}
if (resolve_image_vk_) {
TextureVK::Cast(*resolve_image_vk_).SetFramebuffer(framebuffer);
TextureVK::Cast(*resolve_image_vk_).SetRenderPass(render_pass_);
}

auto clear_values = GetVKClearValues(render_target_);

Expand Down Expand Up @@ -205,10 +227,6 @@ RenderPassVK::RenderPassVK(const std::shared_ptr<const Context>& context,
.setExtent(vk::Extent2D(sc.GetWidth(), sc.GetHeight()));
command_buffer_vk_.setScissor(0, 1, &scissor);

color_image_vk_ =
render_target_.GetColorAttachments().find(0u)->second.texture;
resolve_image_vk_ =
render_target_.GetColorAttachments().find(0u)->second.resolve_texture;
is_valid_ = true;
}

Expand All @@ -227,7 +245,8 @@ void RenderPassVK::OnSetLabel(std::string label) {

SharedHandleVK<vk::Framebuffer> RenderPassVK::CreateVKFramebuffer(
const ContextVK& context,
const vk::RenderPass& pass) const {
const vk::RenderPass& pass,
const SharedHandleVK<vk::Framebuffer>& old_framebuffer) const {
vk::FramebufferCreateInfo fb_info;

fb_info.renderPass = pass;
Expand Down Expand Up @@ -263,6 +282,10 @@ SharedHandleVK<vk::Framebuffer> RenderPassVK::CreateVKFramebuffer(

fb_info.setAttachments(attachments);

if (old_framebuffer != nullptr) {
return old_framebuffer;
}
Comment thread
gaaclarke marked this conversation as resolved.
Outdated

auto [result, framebuffer] =
context.GetDevice().createFramebufferUnique(fb_info);

Expand Down
5 changes: 4 additions & 1 deletion impeller/renderer/backend/vulkan/render_pass_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "impeller/renderer/backend/vulkan/shared_object_vk.h"
#include "impeller/renderer/render_pass.h"
#include "impeller/renderer/render_target.h"
#include "vulkan/vulkan_handles.hpp"

namespace impeller {

Expand Down Expand Up @@ -123,11 +124,13 @@ class RenderPassVK final : public RenderPass {

SharedHandleVK<vk::RenderPass> CreateVKRenderPass(
const ContextVK& context,
const SharedHandleVK<vk::RenderPass>& old_renderpass,
const std::shared_ptr<CommandBufferVK>& command_buffer) const;

SharedHandleVK<vk::Framebuffer> CreateVKFramebuffer(
const ContextVK& context,
const vk::RenderPass& pass) const;
const vk::RenderPass& pass,
const SharedHandleVK<vk::Framebuffer>& old_framebuffer) const;

RenderPassVK(const RenderPassVK&) = delete;

Expand Down
1 change: 1 addition & 0 deletions impeller/renderer/backend/vulkan/swapchain_image_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "impeller/renderer/backend/vulkan/formats_vk.h"
#include "impeller/renderer/backend/vulkan/texture_source_vk.h"
#include "impeller/renderer/backend/vulkan/vk.h"
#include "vulkan/vulkan_handles.hpp"

namespace impeller {

Expand Down
2 changes: 2 additions & 0 deletions impeller/renderer/backend/vulkan/texture_source_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#include "impeller/core/texture_descriptor.h"
#include "impeller/renderer/backend/vulkan/barrier_vk.h"
#include "impeller/renderer/backend/vulkan/formats_vk.h"
#include "impeller/renderer/backend/vulkan/shared_object_vk.h"
#include "impeller/renderer/backend/vulkan/vk.h"
#include "vulkan/vulkan_handles.hpp"

namespace impeller {

Expand Down
18 changes: 18 additions & 0 deletions impeller/renderer/backend/vulkan/texture_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,22 @@ vk::ImageView TextureVK::GetRenderTargetView() const {
return source_->GetRenderTargetView();
}

void TextureVK::SetFramebuffer(
const SharedHandleVK<vk::Framebuffer>& framebuffer) {
framebuffer_ = framebuffer;
}

void TextureVK::SetRenderPass(
const SharedHandleVK<vk::RenderPass>& renderpass) {
renderpass_ = renderpass;
}

SharedHandleVK<vk::Framebuffer> TextureVK::GetFramebuffer() const {
return framebuffer_;
}

SharedHandleVK<vk::RenderPass> TextureVK::GetRenderPass() const {
return renderpass_;

@gaaclarke gaaclarke Feb 2, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are inconsistent about wether render pass is 2 words or one. It should be RenderPass and render_pass_ or Renderpass and renderpass_.

Same for "frame buffer".

@jonahwilliams jonahwilliams Feb 2, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, render pass is two words, framebuffer is one word.

}

} // namespace impeller
11 changes: 11 additions & 0 deletions impeller/renderer/backend/vulkan/texture_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,20 @@ class TextureVK final : public Texture, public BackendCast<TextureVK, Texture> {

bool IsSwapchainImage() const { return source_->IsSwapchainImage(); }

// These methods should only be used by render_pass_vk.h

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments look good 👍

void SetFramebuffer(const SharedHandleVK<vk::Framebuffer>& framebuffer);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to save this on the RenderTarget, not the Texture? This isn't applicable to every Texture, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The RenderTarget itself is const/immutable whereas the Texture is stateful.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not a problem though. We can make the frame buffer and render pass when we create the RenderTarget. We shouldn't ever have a RenderTarget without a render pass and it will never change, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately that is all constructed above the backend layer, and there are no metal or gles analogs for these objects.


void SetRenderPass(const SharedHandleVK<vk::RenderPass>& renderpass);

SharedHandleVK<vk::Framebuffer> GetFramebuffer() const;

SharedHandleVK<vk::RenderPass> GetRenderPass() const;
Comment thread
gaaclarke marked this conversation as resolved.

private:
std::weak_ptr<Context> context_;
std::shared_ptr<TextureSourceVK> source_;
SharedHandleVK<vk::Framebuffer> framebuffer_ = nullptr;
SharedHandleVK<vk::RenderPass> renderpass_ = nullptr;

// |Texture|
void SetLabel(std::string_view label) override;
Expand Down