rhi: Remove RenderPass object

While this has an analog in Vulkan, it is trivial to manage vkRenderPass
on the backend side. We are already having to dynamically manage GL FBOs
for binding framebuffers for drawing in begin_render_pass, so I see
little reason to keep this object around.
This commit is contained in:
Eidolon 2024-10-24 15:22:51 -05:00
parent bba1d56529
commit 4499979458
9 changed files with 26 additions and 108 deletions

View file

@ -119,21 +119,6 @@ void BlitPostimgScreens::draw(Rhi& rhi)
void BlitPostimgScreens::prepass(Rhi& rhi)
{
if (!renderpass_)
{
renderpass_ = rhi.create_render_pass(
{
false,
AttachmentLoadOp::kClear,
AttachmentStoreOp::kStore,
AttachmentLoadOp::kDontCare,
AttachmentStoreOp::kDontCare,
AttachmentLoadOp::kDontCare,
AttachmentStoreOp::kDontCare
}
);
}
if (!pipeline_)
{
pipeline_ = rhi.create_pipeline(kPostimgPipelineDesc);

View file

@ -53,7 +53,6 @@ private:
rhi::Handle<rhi::Pipeline> pipeline_;
rhi::Handle<rhi::Pipeline> indexed_pipeline_;
rhi::Handle<rhi::RenderPass> renderpass_;
rhi::Handle<rhi::Buffer> quad_vbo_;
rhi::Handle<rhi::Buffer> quad_ibo_;
bool upload_quad_buffer_;

View file

@ -21,7 +21,6 @@ namespace srb2::hwr2
class ScreenshotPass
{
rhi::Handle<rhi::RenderPass> render_pass_;
std::vector<uint8_t> pixel_data_;
std::vector<uint8_t> packed_data_;
uint32_t width_ = 0;

View file

@ -94,7 +94,6 @@ class TwodeeRenderer final
std::vector<MergedTwodeeCommandList> cmd_lists_;
std::vector<std::tuple<rhi::Handle<rhi::Buffer>, std::size_t>> vbos_;
std::vector<std::tuple<rhi::Handle<rhi::Buffer>, std::size_t>> ibos_;
rhi::Handle<rhi::RenderPass> render_pass_;
rhi::Handle<rhi::Texture> output_;
rhi::Handle<rhi::Texture> default_tex_;
std::unordered_map<TwodeePipelineKey, rhi::Handle<rhi::Pipeline>> pipelines_;

View file

@ -38,19 +38,6 @@ void UpscaleBackbuffer::begin_pass(Rhi& rhi)
remake = true;
}
auto new_renderpass = [&rhi = rhi](AttachmentLoadOp load_op, AttachmentStoreOp store_op)
{
RenderPassDesc desc {};
desc.use_depth_stencil = false;
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 (color_)
@ -70,23 +57,16 @@ void UpscaleBackbuffer::begin_pass(Rhi& rhi)
RenderbufferDesc depth_tex {};
depth_tex.width = vid_width;
depth_tex.height = vid_height;
if (!renderpass_clear_)
{
renderpass_clear_ = new_renderpass(AttachmentLoadOp::kClear, AttachmentStoreOp::kStore);
}
}
else
{
if (!renderpass_)
{
renderpass_ = new_renderpass(AttachmentLoadOp::kLoad, AttachmentStoreOp::kStore);
}
}
RenderPassBeginInfo begin_info {};
begin_info.render_pass = remake ? renderpass_clear_ : renderpass_;
begin_info.clear_color = {0, 0, 0, 1};
begin_info.color_attachment = color_;
begin_info.color_load_op = rhi::AttachmentLoadOp::kLoad;
begin_info.color_store_op = rhi::AttachmentStoreOp::kStore;
begin_info.depth_load_op = rhi::AttachmentLoadOp::kLoad;
begin_info.depth_store_op = rhi::AttachmentStoreOp::kStore;
begin_info.stencil_load_op = rhi::AttachmentLoadOp::kLoad;
begin_info.stencil_store_op = rhi::AttachmentStoreOp::kStore;
rhi.begin_render_pass(begin_info);
}

View file

@ -19,8 +19,6 @@ namespace srb2::hwr2
class UpscaleBackbuffer
{
rhi::Handle<rhi::Texture> color_;
rhi::Handle<rhi::RenderPass> renderpass_;
rhi::Handle<rhi::RenderPass> renderpass_clear_;
public:
UpscaleBackbuffer();

View file

@ -585,19 +585,6 @@ Gl2Rhi::Gl2Rhi(std::unique_ptr<Gl2Platform>&& platform, GlLoadFunc load_func) :
Gl2Rhi::~Gl2Rhi() = default;
rhi::Handle<rhi::RenderPass> Gl2Rhi::create_render_pass(const rhi::RenderPassDesc& desc)
{
// GL has no formal render pass object
Gl2RenderPass pass;
pass.desc = desc;
return render_pass_slab_.insert(std::move(pass));
}
void Gl2Rhi::destroy_render_pass(rhi::Handle<rhi::RenderPass> handle)
{
render_pass_slab_.remove(handle);
}
rhi::Handle<rhi::Texture> Gl2Rhi::create_texture(const rhi::TextureDesc& desc)
{
GLenum internal_format = map_internal_texture_format(desc.format);
@ -1224,10 +1211,6 @@ void Gl2Rhi::begin_render_pass(const RenderPassBeginInfo& info)
{
SRB2_ASSERT(current_render_pass_.has_value() == false);
SRB2_ASSERT(render_pass_slab_.is_valid(info.render_pass) == true);
auto& rp = render_pass_slab_[info.render_pass];
SRB2_ASSERT(rp.desc.use_depth_stencil == info.depth_stencil_attachment.has_value());
auto fb_itr = framebuffers_.find(Gl2FramebufferKey {info.color_attachment, info.depth_stencil_attachment});
if (fb_itr == framebuffers_.end())
{
@ -1237,12 +1220,10 @@ void Gl2Rhi::begin_render_pass(const RenderPassBeginInfo& info)
GL_ASSERT;
gl_->BindFramebuffer(GL_FRAMEBUFFER, fb_name);
GL_ASSERT;
fb_itr = framebuffers_
.insert(
{Gl2FramebufferKey {info.color_attachment, info.depth_stencil_attachment},
static_cast<uint32_t>(fb_name)}
)
.first;
fb_itr = framebuffers_.insert({
Gl2FramebufferKey {info.color_attachment, info.depth_stencil_attachment},
static_cast<uint32_t>(fb_name)
}).first;
SRB2_ASSERT(texture_slab_.is_valid(info.color_attachment));
auto& texture = texture_slab_[info.color_attachment];
@ -1250,7 +1231,7 @@ void Gl2Rhi::begin_render_pass(const RenderPassBeginInfo& info)
gl_->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.texture, 0);
GL_ASSERT;
if (rp.desc.use_depth_stencil && info.depth_stencil_attachment.has_value())
if (info.depth_stencil_attachment.has_value())
{
SRB2_ASSERT(renderbuffer_slab_.is_valid(*info.depth_stencil_attachment));
auto& renderbuffer = renderbuffer_slab_[*info.depth_stencil_attachment];
@ -1270,24 +1251,21 @@ void Gl2Rhi::begin_render_pass(const RenderPassBeginInfo& info)
GL_ASSERT;
GLint clear_bits = 0;
if (rp.desc.color_load_op == rhi::AttachmentLoadOp::kClear)
if (info.color_load_op == rhi::AttachmentLoadOp::kClear)
{
gl_->ClearColor(info.clear_color.r, info.clear_color.g, info.clear_color.b, info.clear_color.a);
clear_bits |= GL_COLOR_BUFFER_BIT;
}
if (rp.desc.use_depth_stencil)
if (info.depth_load_op == rhi::AttachmentLoadOp::kClear)
{
if (rp.desc.depth_load_op == rhi::AttachmentLoadOp::kClear)
{
gl_->ClearDepth(1.f);
clear_bits |= GL_DEPTH_BUFFER_BIT;
}
if (rp.desc.stencil_load_op == rhi::AttachmentLoadOp::kClear)
{
gl_->ClearStencil(0);
clear_bits |= GL_STENCIL_BUFFER_BIT;
}
gl_->ClearDepth(1.f);
clear_bits |= GL_DEPTH_BUFFER_BIT;
}
if (info.stencil_load_op == rhi::AttachmentLoadOp::kClear)
{
gl_->ClearStencil(0);
clear_bits |= GL_STENCIL_BUFFER_BIT;
}
if (clear_bits != 0)

View file

@ -87,11 +87,6 @@ struct Gl2Buffer : public rhi::Buffer
rhi::BufferDesc desc;
};
struct Gl2RenderPass : public rhi::RenderPass
{
rhi::RenderPassDesc desc;
};
struct Gl2Renderbuffer : public rhi::Renderbuffer
{
uint32_t renderbuffer;
@ -132,7 +127,6 @@ class Gl2Rhi final : public Rhi
std::unique_ptr<GladGLContext> gl_;
Slab<Gl2RenderPass> render_pass_slab_;
Slab<Gl2Texture> texture_slab_;
Slab<Gl2Buffer> buffer_slab_;
Slab<Gl2Renderbuffer> renderbuffer_slab_;
@ -164,8 +158,6 @@ public:
Gl2Rhi(std::unique_ptr<Gl2Platform>&& platform, GlLoadFunc load_func);
virtual ~Gl2Rhi();
virtual Handle<RenderPass> create_render_pass(const RenderPassDesc& desc) override;
virtual void destroy_render_pass(Handle<RenderPass> handle) override;
virtual Handle<Pipeline> create_pipeline(const PipelineDesc& desc) override;
virtual void destroy_pipeline(Handle<Pipeline> handle) override;

View file

@ -42,10 +42,6 @@ struct Pipeline
{
};
struct RenderPass
{
};
/// @brief Depth-stencil image attachment.
struct Renderbuffer
{
@ -461,17 +457,6 @@ struct PipelineDesc
glm::vec4 blend_color;
};
struct RenderPassDesc
{
bool use_depth_stencil;
AttachmentLoadOp color_load_op;
AttachmentStoreOp color_store_op;
AttachmentLoadOp depth_load_op;
AttachmentStoreOp depth_store_op;
AttachmentLoadOp stencil_load_op;
AttachmentStoreOp stencil_store_op;
};
struct RenderbufferDesc
{
uint32_t width;
@ -511,10 +496,15 @@ struct BufferDesc
struct RenderPassBeginInfo
{
Handle<RenderPass> render_pass;
Handle<Texture> color_attachment;
std::optional<Handle<Renderbuffer>> depth_stencil_attachment;
glm::vec4 clear_color;
AttachmentLoadOp color_load_op;
AttachmentStoreOp color_store_op;
AttachmentLoadOp depth_load_op;
AttachmentStoreOp depth_store_op;
AttachmentLoadOp stencil_load_op;
AttachmentStoreOp stencil_store_op;
};
using UniformVariant = std::variant<
@ -598,8 +588,6 @@ struct Rhi
{
virtual ~Rhi();
virtual Handle<RenderPass> create_render_pass(const RenderPassDesc& desc) = 0;
virtual void destroy_render_pass(Handle<RenderPass> handle) = 0;
virtual Handle<Pipeline> create_pipeline(const PipelineDesc& desc) = 0;
virtual void destroy_pipeline(Handle<Pipeline> handle) = 0;