UpscaleBackbuffer::begin_pass: use separate renderpass to clear framebuffer if texture was recreated

Fixes wipes potentially reading invalid data from the
framebuffer if the texture was recreated but not yet
rendered to.
This commit is contained in:
James R. 2023-09-30 19:21:53 -07:00
parent 2ec5d3e6b0
commit a7382ca9d0
2 changed files with 25 additions and 12 deletions

View file

@ -37,6 +37,19 @@ void UpscaleBackbuffer::begin_pass(Rhi& rhi, Handle<GraphicsContext> ctx)
remake = true; remake = true;
} }
auto new_renderpass = [&rhi = rhi](AttachmentLoadOp load_op, AttachmentStoreOp store_op)
{
RenderPassDesc desc {};
desc.use_depth_stencil = true;
desc.color_load_op = load_op;
desc.color_store_op = store_op;
desc.depth_load_op = load_op;
desc.depth_store_op = store_op;
desc.stencil_load_op = load_op;
desc.stencil_store_op = store_op;
return rhi.create_render_pass(desc);
};
if (remake) if (remake)
{ {
if (color_) if (color_)
@ -63,23 +76,22 @@ void UpscaleBackbuffer::begin_pass(Rhi& rhi, Handle<GraphicsContext> ctx)
depth_tex.height = vid_height; depth_tex.height = vid_height;
depth_ = rhi.create_renderbuffer(depth_tex); depth_ = rhi.create_renderbuffer(depth_tex);
}
if (!renderpass_) if (!renderpass_clear_)
{
renderpass_clear_ = new_renderpass(AttachmentLoadOp::kClear, AttachmentStoreOp::kStore);
}
}
else
{ {
RenderPassDesc desc {}; if (!renderpass_)
desc.use_depth_stencil = true; {
desc.color_load_op = AttachmentLoadOp::kLoad; renderpass_ = new_renderpass(AttachmentLoadOp::kLoad, AttachmentStoreOp::kStore);
desc.color_store_op = AttachmentStoreOp::kStore; }
desc.depth_load_op = AttachmentLoadOp::kLoad;
desc.depth_store_op = AttachmentStoreOp::kStore;
desc.stencil_load_op = AttachmentLoadOp::kLoad;
desc.stencil_store_op = AttachmentStoreOp::kStore;
renderpass_ = rhi.create_render_pass(desc);
} }
RenderPassBeginInfo begin_info {}; RenderPassBeginInfo begin_info {};
begin_info.render_pass = renderpass_; begin_info.render_pass = remake ? renderpass_clear_ : renderpass_;
begin_info.clear_color = {0, 0, 0, 1}; begin_info.clear_color = {0, 0, 0, 1};
begin_info.color_attachment = color_; begin_info.color_attachment = color_;
begin_info.depth_stencil_attachment = depth_; begin_info.depth_stencil_attachment = depth_;

View file

@ -20,6 +20,7 @@ class UpscaleBackbuffer
rhi::Handle<rhi::Texture> color_; rhi::Handle<rhi::Texture> color_;
rhi::Handle<rhi::Renderbuffer> depth_; rhi::Handle<rhi::Renderbuffer> depth_;
rhi::Handle<rhi::RenderPass> renderpass_; rhi::Handle<rhi::RenderPass> renderpass_;
rhi::Handle<rhi::RenderPass> renderpass_clear_;
public: public:
UpscaleBackbuffer(); UpscaleBackbuffer();