rhi: Remove GraphicsContext

I've come to the conclusion that some aspects of RHI are overengineered
to suit a future where we would theoretically support Vulkan with
minimal implementation effort. In an effort of architectural astronaut
engineering this has had the consequence of making much of the code
interacting with RHI significantly more complex.

The GraphicsContext was originally an opaque object to wrap and
contextualize operations that would eventually be inserted into a Vulkan
CommandBuffer for dispatch. In practice, for the GL backend, this does
nothing but introduce another pointer to pass around across all RHI
code, when it had already been previously accepted that the idea of
recording multiple GraphicsContexts at the same time was infeasible.

Thus, I'm choosing to excise GraphicsContext entirely. This doesn't do
much except remove passing around the context object. This is one of
many changes I would like to make that would simplify RHI-related code
and defer the complexity to the hypothetical future. Vulkan can come at
a later date, and we can solve the problems of Vulkan then. Right now, I
am actually more concerned for supporting a d3d9 renderer to shore up
that Intel 945GM laptop GPU support gap we currently have.
This commit is contained in:
Eidolon 2024-10-24 13:56:13 -05:00
parent 9c2e4a350a
commit dae2e8ba17
32 changed files with 289 additions and 416 deletions

View file

@ -319,7 +319,7 @@ static fademask_t *F_GetFadeMask(UINT8 masknum, UINT8 scrnnum) {
#endif
static void refresh_wipe_screen_texture(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx, rhi::Handle<rhi::Texture>& tex)
static void refresh_wipe_screen_texture(rhi::Rhi& rhi, rhi::Handle<rhi::Texture>& tex)
{
bool recreate = false;
if (!tex)
@ -371,24 +371,17 @@ void F_WipeStartScreen(void)
return;
}
rhi::Handle<rhi::GraphicsContext> ctx = srb2::sys::main_graphics_context();
if (!ctx)
{
return;
}
hwr2::HardwareState* hw_state = srb2::sys::main_hardware_state();
refresh_wipe_screen_texture(*rhi, ctx, hw_state->wipe_frames.start);
refresh_wipe_screen_texture(*rhi, hw_state->wipe_frames.start);
hw_state->twodee_renderer->flush(*rhi, ctx, g_2d);
hw_state->twodee_renderer->flush(*rhi, g_2d);
rhi::Rect dst_region = {0, 0, static_cast<uint32_t>(vid.width), static_cast<uint32_t>(vid.height)};
rhi::TextureDetails backbuf_deets = rhi->get_texture_details(hw_state->backbuffer->color());
dst_region.w = std::min(dst_region.w, backbuf_deets.width);
dst_region.h = std::min(dst_region.h, backbuf_deets.height);
rhi->copy_framebuffer_to_texture(ctx, hw_state->wipe_frames.start, dst_region, dst_region);
rhi->copy_framebuffer_to_texture(hw_state->wipe_frames.start, dst_region, dst_region);
I_FinishUpdate();
#endif
@ -414,29 +407,22 @@ void F_WipeEndScreen(void)
return;
}
rhi::Handle<rhi::GraphicsContext> ctx = srb2::sys::main_graphics_context();
if (!ctx)
{
return;
}
hwr2::HardwareState* hw_state = srb2::sys::main_hardware_state();
refresh_wipe_screen_texture(*rhi, ctx, hw_state->wipe_frames.end);
refresh_wipe_screen_texture(*rhi, hw_state->wipe_frames.end);
hw_state->twodee_renderer->flush(*rhi, ctx, g_2d);
hw_state->twodee_renderer->flush(*rhi, g_2d);
rhi::Rect dst_region = {0, 0, static_cast<uint32_t>(vid.width), static_cast<uint32_t>(vid.height)};
rhi::TextureDetails backbuf_deets = rhi->get_texture_details(hw_state->backbuffer->color());
dst_region.w = std::min(dst_region.w, backbuf_deets.width);
dst_region.h = std::min(dst_region.h, backbuf_deets.height);
rhi->copy_framebuffer_to_texture(ctx, hw_state->wipe_frames.end, dst_region, dst_region);
rhi->copy_framebuffer_to_texture(hw_state->wipe_frames.end, dst_region, dst_region);
hw_state->blit_rect->set_output(0, 0, dst_region.w, dst_region.h, false, true);
rhi::TextureDetails start_deets = rhi->get_texture_details(hw_state->wipe_frames.start);
hw_state->blit_rect->set_texture(hw_state->wipe_frames.start, start_deets.width, start_deets.height);
hw_state->blit_rect->draw(*rhi, ctx);
hw_state->blit_rect->draw(*rhi);
I_FinishUpdate();
#endif
@ -535,7 +521,6 @@ void F_RunWipe(UINT8 wipemode, UINT8 wipetype, boolean drawMenu, const char *col
g_wipeencorewiggle = 0;
}
rhi::Rhi* rhi = srb2::sys::get_rhi(srb2::sys::g_current_rhi);
rhi::Handle<rhi::GraphicsContext> ctx = srb2::sys::main_graphics_context();
hwr2::HardwareState* hw_state = srb2::sys::main_hardware_state();
if (reverse)
@ -550,7 +535,7 @@ void F_RunWipe(UINT8 wipemode, UINT8 wipetype, boolean drawMenu, const char *col
}
hw_state->wipe->set_target_size(static_cast<uint32_t>(vid.width), static_cast<uint32_t>(vid.height));
hw_state->wipe->draw(*rhi, ctx);
hw_state->wipe->draw(*rhi);
}
I_OsPolling();

View file

@ -99,21 +99,21 @@ BlitPostimgScreens::BlitPostimgScreens(PaletteManager* palette_mgr)
{
}
void BlitPostimgScreens::draw(Rhi& rhi, Handle<GraphicsContext> ctx)
void BlitPostimgScreens::draw(Rhi& rhi)
{
prepass(rhi);
transfer(rhi, ctx);
transfer(rhi);
for (uint32_t i = 0; i < screens_; i++)
{
BlitPostimgScreens::ScreenData& data = screen_data_[i];
rhi.bind_pipeline(ctx, data.pipeline);
rhi.set_viewport(ctx, get_screen_viewport(i, screens_, target_width_, target_height_));
rhi.bind_uniform_set(ctx, 0, data.uniform_set);
rhi.bind_binding_set(ctx, data.binding_set);
rhi.bind_index_buffer(ctx, quad_ibo_);
rhi.draw_indexed(ctx, 6, 0);
rhi.bind_pipeline(data.pipeline);
rhi.set_viewport(get_screen_viewport(i, screens_, target_width_, target_height_));
rhi.bind_uniform_set(0, data.uniform_set);
rhi.bind_binding_set(data.binding_set);
rhi.bind_index_buffer(quad_ibo_);
rhi.draw_indexed(6, 0);
}
}
@ -159,13 +159,13 @@ void BlitPostimgScreens::prepass(Rhi& rhi)
screen_data_.clear();
}
void BlitPostimgScreens::transfer(Rhi& rhi, Handle<GraphicsContext> ctx)
void BlitPostimgScreens::transfer(Rhi& rhi)
{
// Upload needed buffers
if (upload_quad_buffer_)
{
rhi.update_buffer(ctx, quad_vbo_, 0, tcb::as_bytes(tcb::span(kVerts)));
rhi.update_buffer(ctx, quad_ibo_, 0, tcb::as_bytes(tcb::span(kIndices)));
rhi.update_buffer(quad_vbo_, 0, tcb::as_bytes(tcb::span(kVerts)));
rhi.update_buffer(quad_ibo_, 0, tcb::as_bytes(tcb::span(kIndices)));
upload_quad_buffer_ = false;
}
@ -191,7 +191,6 @@ void BlitPostimgScreens::transfer(Rhi& rhi, Handle<GraphicsContext> ctx)
};
data.binding_set = rhi.create_binding_set(
ctx,
data.pipeline,
{
vertex_bindings,
@ -234,7 +233,7 @@ void BlitPostimgScreens::transfer(Rhi& rhi, Handle<GraphicsContext> ctx)
screen_config.post.heat
};
data.uniform_set = rhi.create_uniform_set(ctx, {uniforms});
data.uniform_set = rhi.create_uniform_set({uniforms});
screen_data_[i] = std::move(data);
}

View file

@ -67,12 +67,12 @@ private:
PaletteManager* palette_mgr_;
void prepass(rhi::Rhi& rhi);
void transfer(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx);
void transfer(rhi::Rhi& rhi);
public:
explicit BlitPostimgScreens(PaletteManager* palette_mgr);
void draw(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx);
void draw(rhi::Rhi& rhi);
void set_num_screens(uint32_t screens) noexcept
{

View file

@ -98,11 +98,11 @@ BlitRectPass::BlitRectPass() : BlitRectPass(BlitRectPass::BlitMode::kNearest) {}
BlitRectPass::BlitRectPass(BlitRectPass::BlitMode blit_mode) : blit_mode_(blit_mode) {}
BlitRectPass::~BlitRectPass() = default;
void BlitRectPass::draw(Rhi& rhi, Handle<GraphicsContext> ctx)
void BlitRectPass::draw(Rhi& rhi)
{
prepass(rhi);
transfer(rhi, ctx);
graphics(rhi, ctx);
transfer(rhi);
graphics(rhi);
}
void BlitRectPass::prepass(Rhi& rhi)
@ -156,17 +156,17 @@ void BlitRectPass::prepass(Rhi& rhi)
}
}
void BlitRectPass::transfer(Rhi& rhi, Handle<GraphicsContext> ctx)
void BlitRectPass::transfer(Rhi& rhi)
{
if (quad_vbo_needs_upload_ && quad_vbo_)
{
rhi.update_buffer(ctx, quad_vbo_, 0, tcb::as_bytes(tcb::span(kVerts)));
rhi.update_buffer(quad_vbo_, 0, tcb::as_bytes(tcb::span(kVerts)));
quad_vbo_needs_upload_ = false;
}
if (quad_ibo_needs_upload_ && quad_ibo_)
{
rhi.update_buffer(ctx, quad_ibo_, 0, tcb::as_bytes(tcb::span(kIndices)));
rhi.update_buffer(quad_ibo_, 0, tcb::as_bytes(tcb::span(kIndices)));
quad_ibo_needs_upload_ = false;
}
@ -227,7 +227,7 @@ void BlitRectPass::transfer(Rhi& rhi, Handle<GraphicsContext> ctx)
0, 0, 255, 255,
0, 0, 0, 255,
};
rhi.update_texture(ctx, dot_pattern_, {0, 0, 12, 4}, PixelFormat::kRGBA8, tcb::as_bytes(tcb::span(kDotPattern)));
rhi.update_texture(dot_pattern_, {0, 0, 12, 4}, PixelFormat::kRGBA8, tcb::as_bytes(tcb::span(kDotPattern)));
dot_pattern_needs_upload_ = false;
}
@ -250,7 +250,7 @@ void BlitRectPass::transfer(Rhi& rhi, Handle<GraphicsContext> ctx)
)
}};
uniform_sets_[0] = rhi.create_uniform_set(ctx, {g1_uniforms});
uniform_sets_[0] = rhi.create_uniform_set({g1_uniforms});
switch (blit_mode_)
{
@ -271,11 +271,11 @@ void BlitRectPass::transfer(Rhi& rhi, Handle<GraphicsContext> ctx)
// Sampler 0 Size
glm::vec2(texture_details.width, texture_details.height)
};
uniform_sets_[1] = rhi.create_uniform_set(ctx, {g2_uniforms});
uniform_sets_[1] = rhi.create_uniform_set({g2_uniforms});
std::array<rhi::VertexAttributeBufferBinding, 1> vbs = {{{0, quad_vbo_}}};
std::array<rhi::TextureBinding, 2> tbs = {{{rhi::SamplerName::kSampler0, texture_}, {rhi::SamplerName::kSampler1, dot_pattern_}}};
binding_set_ = rhi.create_binding_set(ctx, pipeline_, {vbs, tbs});
binding_set_ = rhi.create_binding_set(pipeline_, {vbs, tbs});
break;
}
case BlitRectPass::BlitMode::kCrtSharp:
@ -295,11 +295,11 @@ void BlitRectPass::transfer(Rhi& rhi, Handle<GraphicsContext> ctx)
// Sampler 0 Size
glm::vec2(texture_details.width, texture_details.height)
};
uniform_sets_[1] = rhi.create_uniform_set(ctx, {g2_uniforms});
uniform_sets_[1] = rhi.create_uniform_set({g2_uniforms});
std::array<rhi::VertexAttributeBufferBinding, 1> vbs = {{{0, quad_vbo_}}};
std::array<rhi::TextureBinding, 2> tbs = {{{rhi::SamplerName::kSampler0, texture_}, {rhi::SamplerName::kSampler1, dot_pattern_}}};
binding_set_ = rhi.create_binding_set(ctx, pipeline_, {vbs, tbs});
binding_set_ = rhi.create_binding_set(pipeline_, {vbs, tbs});
break;
}
case BlitRectPass::BlitMode::kSharpBilinear:
@ -319,11 +319,11 @@ void BlitRectPass::transfer(Rhi& rhi, Handle<GraphicsContext> ctx)
// Sampler0 size
glm::vec2(texture_details.width, texture_details.height)
};
uniform_sets_[1] = rhi.create_uniform_set(ctx, {g2_uniforms});
uniform_sets_[1] = rhi.create_uniform_set({g2_uniforms});
std::array<rhi::VertexAttributeBufferBinding, 1> vbs = {{{0, quad_vbo_}}};
std::array<rhi::TextureBinding, 1> tbs = {{{rhi::SamplerName::kSampler0, texture_}}};
binding_set_ = rhi.create_binding_set(ctx, pipeline_, {vbs, tbs});
binding_set_ = rhi.create_binding_set(pipeline_, {vbs, tbs});
break;
}
default:
@ -341,23 +341,23 @@ void BlitRectPass::transfer(Rhi& rhi, Handle<GraphicsContext> ctx)
glm::vec3(0.f, output_flip_ ? 1.f : 0.f, 1.f)
)
};
uniform_sets_[1] = rhi.create_uniform_set(ctx, {g2_uniforms});
uniform_sets_[1] = rhi.create_uniform_set({g2_uniforms});
std::array<rhi::VertexAttributeBufferBinding, 1> vbs = {{{0, quad_vbo_}}};
std::array<rhi::TextureBinding, 1> tbs = {{{rhi::SamplerName::kSampler0, texture_}}};
binding_set_ = rhi.create_binding_set(ctx, pipeline_, {vbs, tbs});
binding_set_ = rhi.create_binding_set(pipeline_, {vbs, tbs});
break;
}
}
}
void BlitRectPass::graphics(Rhi& rhi, Handle<GraphicsContext> ctx)
void BlitRectPass::graphics(Rhi& rhi)
{
rhi.bind_pipeline(ctx, pipeline_);
rhi.set_viewport(ctx, output_position_);
rhi.bind_uniform_set(ctx, 0, uniform_sets_[0]);
rhi.bind_uniform_set(ctx, 1, uniform_sets_[1]);
rhi.bind_binding_set(ctx, binding_set_);
rhi.bind_index_buffer(ctx, quad_ibo_);
rhi.draw_indexed(ctx, 6, 0);
rhi.bind_pipeline(pipeline_);
rhi.set_viewport(output_position_);
rhi.bind_uniform_set(0, uniform_sets_[0]);
rhi.bind_uniform_set(1, uniform_sets_[1]);
rhi.bind_binding_set(binding_set_);
rhi.bind_index_buffer(quad_ibo_);
rhi.draw_indexed(6, 0);
}

View file

@ -52,8 +52,8 @@ private:
bool dot_pattern_needs_upload_ = false;
void prepass(rhi::Rhi& rhi);
void transfer(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx);
void graphics(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx);
void transfer(rhi::Rhi& rhi);
void graphics(rhi::Rhi& rhi);
public:
@ -61,7 +61,7 @@ public:
BlitRectPass();
~BlitRectPass();
void draw(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx);
void draw(rhi::Rhi& rhi);
/// @brief Set the next blit texture. Don't call during graphics phase!
/// @param texture the texture to use when blitting

View file

@ -30,12 +30,12 @@ public:
/// @brief Upload contents for needed GPU resources. Passes must implement but this will be removed soon.
/// @param rhi
/// @param ctx
virtual void transfer(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx) = 0;
virtual void transfer(rhi::Rhi& rhi) = 0;
/// @brief Issue draw calls.
/// @param rhi
/// @param ctx
virtual void graphics(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx) = 0;
virtual void graphics(rhi::Rhi& rhi) = 0;
/// @brief Cleanup GPU resources. Transient resources should be cleaned up here.
/// @param rhi

View file

@ -128,7 +128,7 @@ void ImguiPass::prepass(Rhi& rhi)
}
}
void ImguiPass::transfer(Rhi& rhi, Handle<GraphicsContext> ctx)
void ImguiPass::transfer(Rhi& rhi)
{
ImGuiIO& io = ImGui::GetIO();
@ -137,7 +137,6 @@ void ImguiPass::transfer(Rhi& rhi, Handle<GraphicsContext> ctx)
int width, height;
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
rhi.update_texture(
ctx,
font_atlas_,
{0, 0, static_cast<uint32_t>(width), static_cast<uint32_t>(height)},
rhi::PixelFormat::kRGBA8,
@ -162,10 +161,10 @@ void ImguiPass::transfer(Rhi& rhi, Handle<GraphicsContext> ctx)
}
tcb::span<ImDrawVert> vert_span = tcb::span(im_list->VtxBuffer.Data, im_list->VtxBuffer.size());
rhi.update_buffer(ctx, vbo, 0, tcb::as_bytes(vert_span));
rhi.update_buffer(vbo, 0, tcb::as_bytes(vert_span));
tcb::span<ImDrawIdx> index_span = tcb::span(im_list->IdxBuffer.Data, im_list->IdxBuffer.size());
rhi.update_buffer(ctx, ibo, 0, tcb::as_bytes(index_span));
rhi.update_buffer(ibo, 0, tcb::as_bytes(index_span));
// Uniform sets
std::array<UniformVariant, 1> g1_uniforms = {
@ -192,8 +191,8 @@ void ImguiPass::transfer(Rhi& rhi, Handle<GraphicsContext> ctx)
glm::vec3(0.f, 0.f, 1.f)
)
};
Handle<UniformSet> us_1 = rhi.create_uniform_set(ctx, {g1_uniforms});
Handle<UniformSet> us_2 = rhi.create_uniform_set(ctx, {g2_uniforms});
Handle<UniformSet> us_1 = rhi.create_uniform_set({g1_uniforms});
Handle<UniformSet> us_2 = rhi.create_uniform_set({g2_uniforms});
draw_list.us_1 = us_1;
draw_list.us_2 = us_2;
@ -203,29 +202,29 @@ void ImguiPass::transfer(Rhi& rhi, Handle<GraphicsContext> ctx)
// Binding set
std::array<rhi::VertexAttributeBufferBinding, 1> vbos = {{{0, vbo}}};
std::array<rhi::TextureBinding, 1> tbs = {{{rhi::SamplerName::kSampler0, draw_cmd.tex}}};
rhi::Handle<rhi::BindingSet> binding_set = rhi.create_binding_set(ctx, pipeline_, {vbos, tbs});
rhi::Handle<rhi::BindingSet> binding_set = rhi.create_binding_set(pipeline_, {vbos, tbs});
draw_cmd.binding_set = binding_set;
}
}
}
void ImguiPass::graphics(Rhi& rhi, Handle<GraphicsContext> ctx)
void ImguiPass::graphics(Rhi& rhi)
{
rhi.begin_default_render_pass(ctx, false);
rhi.bind_pipeline(ctx, pipeline_);
rhi.begin_default_render_pass(false);
rhi.bind_pipeline(pipeline_);
for (auto& draw_list : draw_lists_)
{
rhi.bind_uniform_set(ctx, 0, draw_list.us_1);
rhi.bind_uniform_set(ctx, 1, draw_list.us_2);
rhi.bind_uniform_set(0, draw_list.us_1);
rhi.bind_uniform_set(1, draw_list.us_2);
for (auto& cmd : draw_list.cmds)
{
rhi.bind_binding_set(ctx, cmd.binding_set);
rhi.bind_index_buffer(ctx, draw_list.ibo);
rhi.set_scissor(ctx, cmd.clip);
rhi.draw_indexed(ctx, cmd.elems, cmd.i_offset);
rhi.bind_binding_set(cmd.binding_set);
rhi.bind_index_buffer(draw_list.ibo);
rhi.set_scissor(cmd.clip);
rhi.draw_indexed(cmd.elems, cmd.i_offset);
}
}
rhi.end_render_pass(ctx);
rhi.end_render_pass();
}
void ImguiPass::postpass(Rhi& rhi)

View file

@ -51,9 +51,9 @@ public:
virtual void prepass(rhi::Rhi& rhi) override;
virtual void transfer(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx) override;
virtual void transfer(rhi::Rhi& rhi) override;
virtual void graphics(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx) override;
virtual void graphics(rhi::Rhi& rhi) override;
virtual void postpass(rhi::Rhi& rhi) override;
};

View file

@ -33,8 +33,8 @@ public:
virtual ~LambdaPass();
virtual void prepass(rhi::Rhi& rhi) override;
virtual void transfer(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx) override;
virtual void graphics(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx) override;
virtual void transfer(rhi::Rhi& rhi) override;
virtual void graphics(rhi::Rhi& rhi) override;
virtual void postpass(rhi::Rhi& rhi) override;
};
@ -64,11 +64,11 @@ void LambdaPass::prepass(Rhi& rhi)
}
}
void LambdaPass::transfer(Rhi&, Handle<GraphicsContext>)
void LambdaPass::transfer(Rhi&)
{
}
void LambdaPass::graphics(Rhi&, Handle<GraphicsContext>)
void LambdaPass::graphics(Rhi&)
{
}
@ -138,24 +138,24 @@ void PassManager::prepass(Rhi& rhi)
}
}
void PassManager::transfer(Rhi& rhi, Handle<GraphicsContext> ctx)
void PassManager::transfer(Rhi& rhi)
{
for (auto& pass : passes_)
{
if (pass.enabled)
{
pass.pass->transfer(rhi, ctx);
pass.pass->transfer(rhi);
}
}
}
void PassManager::graphics(Rhi& rhi, Handle<GraphicsContext> ctx)
void PassManager::graphics(Rhi& rhi)
{
for (auto& pass : passes_)
{
if (pass.enabled)
{
pass.pass->graphics(rhi, ctx);
pass.pass->graphics(rhi);
}
}
}
@ -180,10 +180,8 @@ void PassManager::render(Rhi& rhi)
prepass(rhi);
Handle<GraphicsContext> gc = rhi.begin_graphics();
transfer(rhi, gc);
graphics(rhi, gc);
rhi.end_graphics(gc);
transfer(rhi);
graphics(rhi);
postpass(rhi);
}

View file

@ -44,8 +44,8 @@ public:
PassManager& operator=(PassManager&&) = delete;
virtual void prepass(rhi::Rhi& rhi) override;
virtual void transfer(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx) override;
virtual void graphics(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx) override;
virtual void transfer(rhi::Rhi& rhi) override;
virtual void graphics(rhi::Rhi& rhi) override;
virtual void postpass(rhi::Rhi& rhi) override;
void insert(const std::string& name, std::shared_ptr<Pass> pass);

View file

@ -120,11 +120,11 @@ void FramebufferManager::prepass(Rhi& rhi)
}
}
void FramebufferManager::transfer(Rhi& rhi, Handle<GraphicsContext> ctx)
void FramebufferManager::transfer(Rhi& rhi)
{
}
void FramebufferManager::graphics(Rhi& rhi, Handle<GraphicsContext> ctx)
void FramebufferManager::graphics(Rhi& rhi)
{
}
@ -161,28 +161,28 @@ void MainPaletteManager::prepass(Rhi& rhi)
}
}
void MainPaletteManager::upload_palette(Rhi& rhi, Handle<GraphicsContext> ctx)
void MainPaletteManager::upload_palette(Rhi& rhi)
{
std::array<byteColor_t, kPaletteSize> palette_32;
for (std::size_t i = 0; i < kPaletteSize; i++)
{
palette_32[i] = V_GetColor(i).s;
}
rhi.update_texture(ctx, palette_, {0, 0, kPaletteSize, 1}, PixelFormat::kRGBA8, tcb::as_bytes(tcb::span(palette_32)));
rhi.update_texture(palette_, {0, 0, kPaletteSize, 1}, PixelFormat::kRGBA8, tcb::as_bytes(tcb::span(palette_32)));
}
void MainPaletteManager::upload_lighttables(Rhi& rhi, Handle<GraphicsContext> ctx)
void MainPaletteManager::upload_lighttables(Rhi& rhi)
{
if (colormaps != nullptr)
{
tcb::span<const std::byte> colormap_bytes = tcb::as_bytes(tcb::span(colormaps, kPaletteSize * kLighttableRows));
rhi.update_texture(ctx, lighttable_, {0, 0, kPaletteSize, kLighttableRows}, PixelFormat::kR8, colormap_bytes);
rhi.update_texture(lighttable_, {0, 0, kPaletteSize, kLighttableRows}, PixelFormat::kR8, colormap_bytes);
}
if (encoremap != nullptr)
{
tcb::span<const std::byte> encoremap_bytes = tcb::as_bytes(tcb::span(encoremap, kPaletteSize * kLighttableRows));
rhi.update_texture(ctx, encore_lighttable_, {0, 0, kPaletteSize, kLighttableRows}, PixelFormat::kR8, encoremap_bytes);
rhi.update_texture(encore_lighttable_, {0, 0, kPaletteSize, kLighttableRows}, PixelFormat::kR8, encoremap_bytes);
}
if (!lighttables_to_upload_.empty())
@ -192,23 +192,23 @@ void MainPaletteManager::upload_lighttables(Rhi& rhi, Handle<GraphicsContext> ct
Handle<Texture> lighttable_tex = find_extra_lighttable(lighttable);
SRB2_ASSERT(lighttable_tex != kNullHandle);
tcb::span<const std::byte> lighttable_bytes = tcb::as_bytes(tcb::span(lighttable, kPaletteSize * kLighttableRows));
rhi.update_texture(ctx, lighttable_tex, {0, 0, kPaletteSize, kLighttableRows}, PixelFormat::kR8, lighttable_bytes);
rhi.update_texture(lighttable_tex, {0, 0, kPaletteSize, kLighttableRows}, PixelFormat::kR8, lighttable_bytes);
}
lighttables_to_upload_.clear();
}
}
void MainPaletteManager::upload_default_colormap(Rhi& rhi, Handle<GraphicsContext> ctx)
void MainPaletteManager::upload_default_colormap(Rhi& rhi)
{
std::array<uint8_t, kPaletteSize> data;
for (std::size_t i = 0; i < kPaletteSize; i++)
{
data[i] = i;
}
rhi.update_texture(ctx, default_colormap_, {0, 0, kPaletteSize, 1}, PixelFormat::kR8, tcb::as_bytes(tcb::span(data)));
rhi.update_texture(default_colormap_, {0, 0, kPaletteSize, 1}, PixelFormat::kR8, tcb::as_bytes(tcb::span(data)));
}
void MainPaletteManager::upload_colormaps(Rhi& rhi, Handle<GraphicsContext> ctx)
void MainPaletteManager::upload_colormaps(Rhi& rhi)
{
for (auto to_upload : colormaps_to_upload_)
{
@ -218,7 +218,7 @@ void MainPaletteManager::upload_colormaps(Rhi& rhi, Handle<GraphicsContext> ctx)
rhi::Handle<rhi::Texture> map_texture = colormaps_.at(to_upload);
tcb::span<const std::byte> map_bytes = tcb::as_bytes(tcb::span(to_upload, kPaletteSize));
rhi.update_texture(ctx, map_texture, {0, 0, kPaletteSize, 1}, PixelFormat::kR8, map_bytes);
rhi.update_texture(map_texture, {0, 0, kPaletteSize, 1}, PixelFormat::kR8, map_bytes);
}
colormaps_to_upload_.clear();
}
@ -271,15 +271,15 @@ rhi::Handle<rhi::Texture> MainPaletteManager::find_extra_lighttable(srb2::NotNul
return lighttables_.at(lighttable);
}
void MainPaletteManager::transfer(Rhi& rhi, Handle<GraphicsContext> ctx)
void MainPaletteManager::transfer(Rhi& rhi)
{
upload_palette(rhi, ctx);
upload_lighttables(rhi, ctx);
upload_default_colormap(rhi, ctx);
upload_colormaps(rhi, ctx);
upload_palette(rhi);
upload_lighttables(rhi);
upload_default_colormap(rhi);
upload_colormaps(rhi);
}
void MainPaletteManager::graphics(Rhi& rhi, Handle<GraphicsContext> ctx)
void MainPaletteManager::graphics(Rhi& rhi)
{
}
@ -319,7 +319,7 @@ void CommonResourcesManager::prepass(Rhi& rhi)
}
}
void CommonResourcesManager::transfer(Rhi& rhi, Handle<GraphicsContext> ctx)
void CommonResourcesManager::transfer(Rhi& rhi)
{
if (!init_)
{
@ -330,13 +330,13 @@ void CommonResourcesManager::transfer(Rhi& rhi, Handle<GraphicsContext> ctx)
uint8_t transparent[4] = {0, 0, 0, 0};
tcb::span<const std::byte> transparent_bytes = tcb::as_bytes(tcb::span(transparent, 4));
rhi.update_texture(ctx, black_, {0, 0, 1, 1}, PixelFormat::kRGBA8, black_bytes);
rhi.update_texture(ctx, white_, {0, 0, 1, 1}, PixelFormat::kRGBA8, white_bytes);
rhi.update_texture(ctx, transparent_, {0, 0, 1, 1}, PixelFormat::kRGBA8, transparent_bytes);
rhi.update_texture(black_, {0, 0, 1, 1}, PixelFormat::kRGBA8, black_bytes);
rhi.update_texture(white_, {0, 0, 1, 1}, PixelFormat::kRGBA8, white_bytes);
rhi.update_texture(transparent_, {0, 0, 1, 1}, PixelFormat::kRGBA8, transparent_bytes);
}
}
void CommonResourcesManager::graphics(Rhi& rhi, Handle<GraphicsContext> ctx)
void CommonResourcesManager::graphics(Rhi& rhi)
{
}

View file

@ -37,8 +37,8 @@ public:
virtual ~FramebufferManager();
virtual void prepass(rhi::Rhi& rhi) override;
virtual void transfer(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx) override;
virtual void graphics(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx) override;
virtual void transfer(rhi::Rhi& rhi) override;
virtual void graphics(rhi::Rhi& rhi) override;
virtual void postpass(rhi::Rhi& rhi) override;
/// @brief Swap the current and previous postprocess FB textures. Use between pass prepass phases to alternate.
@ -82,18 +82,18 @@ class MainPaletteManager final : public Pass
std::vector<const uint8_t*> colormaps_to_upload_;
std::vector<const uint8_t*> lighttables_to_upload_;
void upload_palette(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx);
void upload_lighttables(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx);
void upload_default_colormap(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx);
void upload_colormaps(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx);
void upload_palette(rhi::Rhi& rhi);
void upload_lighttables(rhi::Rhi& rhi);
void upload_default_colormap(rhi::Rhi& rhi);
void upload_colormaps(rhi::Rhi& rhi);
public:
MainPaletteManager();
virtual ~MainPaletteManager();
virtual void prepass(rhi::Rhi& rhi) override;
virtual void transfer(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx) override;
virtual void graphics(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx) override;
virtual void transfer(rhi::Rhi& rhi) override;
virtual void graphics(rhi::Rhi& rhi) override;
virtual void postpass(rhi::Rhi& rhi) override;
rhi::Handle<rhi::Texture> palette() const noexcept { return palette_; }
@ -119,8 +119,8 @@ public:
virtual ~CommonResourcesManager();
virtual void prepass(rhi::Rhi& rhi) override;
virtual void transfer(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx) override;
virtual void graphics(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx) override;
virtual void transfer(rhi::Rhi& rhi) override;
virtual void graphics(rhi::Rhi& rhi) override;
virtual void postpass(rhi::Rhi& rhi) override;
rhi::Handle<rhi::Texture> black() const noexcept { return black_; }

View file

@ -216,7 +216,7 @@ static PatchAtlas create_atlas(Rhi& rhi, uint32_t size)
return new_atlas;
}
void PatchAtlasCache::pack(Rhi& rhi, Handle<GraphicsContext> ctx)
void PatchAtlasCache::pack(Rhi& rhi)
{
// Prepare stbrp rects for patches to be loaded.
std::vector<stbrp_rect> rects;
@ -310,7 +310,6 @@ void PatchAtlasCache::pack(Rhi& rhi, Handle<GraphicsContext> ctx)
convert_patch_to_trimmed_rg8_pixels(patch_to_upload, patch_data);
rhi.update_texture(
ctx,
atlas->tex_,
{static_cast<int32_t>(entry->x), static_cast<int32_t>(entry->y), entry->w, entry->h},
PixelFormat::kRG8,

View file

@ -113,7 +113,7 @@ public:
void queue_patch(srb2::NotNull<const patch_t*> patch);
/// @brief Pack queued patches, allowing them to be looked up with find_patch.
void pack(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx);
void pack(rhi::Rhi& rhi);
/// @brief Find the atlas a patch belongs to, or nullopt if it is not cached.
/// This may not be called if there are still patches that need to be packed.

View file

@ -63,11 +63,11 @@ PostprocessWipePass::PostprocessWipePass()
PostprocessWipePass::~PostprocessWipePass() = default;
void PostprocessWipePass::draw(Rhi& rhi, Handle<GraphicsContext> ctx)
void PostprocessWipePass::draw(Rhi& rhi)
{
prepass(rhi);
transfer(rhi, ctx);
graphics(rhi, ctx);
transfer(rhi);
graphics(rhi);
postpass(rhi);
}
@ -169,7 +169,7 @@ void PostprocessWipePass::prepass(Rhi& rhi)
});
}
void PostprocessWipePass::transfer(Rhi& rhi, Handle<GraphicsContext> ctx)
void PostprocessWipePass::transfer(Rhi& rhi)
{
if (wipe_tex_ == kNullHandle)
{
@ -183,47 +183,47 @@ void PostprocessWipePass::transfer(Rhi& rhi, Handle<GraphicsContext> ctx)
if (upload_vbo_)
{
rhi.update_buffer(ctx, vbo_, 0, tcb::as_bytes(tcb::span(kPostprocessVerts)));
rhi.update_buffer(vbo_, 0, tcb::as_bytes(tcb::span(kPostprocessVerts)));
upload_vbo_ = false;
}
if (upload_ibo_)
{
rhi.update_buffer(ctx, ibo_, 0, tcb::as_bytes(tcb::span(kPostprocessIndices)));
rhi.update_buffer(ibo_, 0, tcb::as_bytes(tcb::span(kPostprocessIndices)));
upload_ibo_ = false;
}
tcb::span<const std::byte> data = tcb::as_bytes(tcb::span(mask_data_));
rhi.update_texture(ctx, wipe_tex_, {0, 0, mask_w_, mask_h_}, PixelFormat::kR8, data);
rhi.update_texture(wipe_tex_, {0, 0, mask_w_, mask_h_}, PixelFormat::kR8, data);
UniformVariant uniforms[] = {
glm::scale(glm::identity<glm::mat4>(), glm::vec3(2.f, 2.f, 1.f)),
static_cast<int32_t>(wipe_color_mode_),
static_cast<int32_t>(wipe_swizzle_)
};
us_ = rhi.create_uniform_set(ctx, {tcb::span(uniforms)});
us_ = rhi.create_uniform_set({tcb::span(uniforms)});
VertexAttributeBufferBinding vbos[] = {{0, vbo_}};
TextureBinding tx[] = {
{SamplerName::kSampler0, start_},
{SamplerName::kSampler1, end_},
{SamplerName::kSampler2, wipe_tex_}};
bs_ = rhi.create_binding_set(ctx, pipeline_, {vbos, tx});
bs_ = rhi.create_binding_set(pipeline_, {vbos, tx});
}
void PostprocessWipePass::graphics(Rhi& rhi, Handle<GraphicsContext> ctx)
void PostprocessWipePass::graphics(Rhi& rhi)
{
if (wipe_tex_ == kNullHandle)
{
return;
}
rhi.bind_pipeline(ctx, pipeline_);
rhi.set_viewport(ctx, {0, 0, width_, height_});
rhi.bind_uniform_set(ctx, 0, us_);
rhi.bind_binding_set(ctx, bs_);
rhi.bind_index_buffer(ctx, ibo_);
rhi.draw_indexed(ctx, 6, 0);
rhi.bind_pipeline(pipeline_);
rhi.set_viewport({0, 0, width_, height_});
rhi.bind_uniform_set(0, us_);
rhi.bind_binding_set(bs_);
rhi.bind_index_buffer(ibo_);
rhi.draw_indexed(6, 0);
}
void PostprocessWipePass::postpass(Rhi& rhi)

View file

@ -44,15 +44,15 @@ class PostprocessWipePass final
uint32_t mask_h_ = 0;
void prepass(rhi::Rhi& rhi);
void transfer(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx);
void graphics(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx);
void transfer(rhi::Rhi& rhi);
void graphics(rhi::Rhi& rhi);
void postpass(rhi::Rhi& rhi);
public:
PostprocessWipePass();
virtual ~PostprocessWipePass();
void draw(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx);
void draw(rhi::Rhi& rhi);
void set_start(rhi::Handle<rhi::Texture> start) noexcept { start_ = start; }

View file

@ -26,7 +26,7 @@ PaletteManager& PaletteManager::operator=(PaletteManager&&) = default;
constexpr std::size_t kPaletteSize = 256;
constexpr std::size_t kLighttableRows = LIGHTLEVELS;
void PaletteManager::update(Rhi& rhi, Handle<GraphicsContext> ctx)
void PaletteManager::update(Rhi& rhi)
{
if (!palette_)
{
@ -57,7 +57,7 @@ void PaletteManager::update(Rhi& rhi, Handle<GraphicsContext> ctx)
{
palette_32[i] = V_GetColor(i).s;
}
rhi.update_texture(ctx, palette_, {0, 0, kPaletteSize, 1}, PixelFormat::kRGBA8, tcb::as_bytes(tcb::span(palette_32)));
rhi.update_texture(palette_, {0, 0, kPaletteSize, 1}, PixelFormat::kRGBA8, tcb::as_bytes(tcb::span(palette_32)));
}
#if 0
@ -66,7 +66,7 @@ void PaletteManager::update(Rhi& rhi, Handle<GraphicsContext> ctx)
if (colormaps != nullptr)
{
tcb::span<const std::byte> colormap_bytes = tcb::as_bytes(tcb::span(colormaps, kPaletteSize * kLighttableRows));
rhi.update_texture(ctx, lighttable_, {0, 0, kPaletteSize, kLighttableRows}, PixelFormat::kR8, colormap_bytes);
rhi.update_texture(lighttable_, {0, 0, kPaletteSize, kLighttableRows}, PixelFormat::kR8, colormap_bytes);
}
// FIXME: This is broken, encoremap should not be used directly.
@ -74,7 +74,7 @@ void PaletteManager::update(Rhi& rhi, Handle<GraphicsContext> ctx)
if (encoremap != nullptr)
{
tcb::span<const std::byte> encoremap_bytes = tcb::as_bytes(tcb::span(encoremap, kPaletteSize * kLighttableRows));
rhi.update_texture(ctx, encore_lighttable_, {0, 0, kPaletteSize, kLighttableRows}, PixelFormat::kR8, encoremap_bytes);
rhi.update_texture(encore_lighttable_, {0, 0, kPaletteSize, kLighttableRows}, PixelFormat::kR8, encoremap_bytes);
}
}
#endif
@ -86,7 +86,7 @@ void PaletteManager::update(Rhi& rhi, Handle<GraphicsContext> ctx)
{
data[i] = i;
}
rhi.update_texture(ctx, default_colormap_, {0, 0, kPaletteSize, 1}, PixelFormat::kR8, tcb::as_bytes(tcb::span(data)));
rhi.update_texture(default_colormap_, {0, 0, kPaletteSize, 1}, PixelFormat::kR8, tcb::as_bytes(tcb::span(data)));
}
}
@ -107,7 +107,7 @@ void PaletteManager::destroy_per_frame_resources(Rhi& rhi)
lighttables_.clear();
}
Handle<Texture> PaletteManager::find_or_create_colormap(Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx, srb2::NotNull<const uint8_t*> colormap)
Handle<Texture> PaletteManager::find_or_create_colormap(Rhi& rhi, srb2::NotNull<const uint8_t*> colormap)
{
if (colormaps_.find(colormap) != colormaps_.end())
{
@ -117,13 +117,13 @@ Handle<Texture> PaletteManager::find_or_create_colormap(Rhi& rhi, rhi::Handle<rh
Handle<Texture> texture = rhi.create_texture({TextureFormat::kLuminance, kPaletteSize, 1, TextureWrapMode::kClamp, TextureWrapMode::kClamp});
tcb::span<const std::byte> map_bytes = tcb::as_bytes(tcb::span(colormap.get(), kPaletteSize));
rhi.update_texture(ctx, texture, {0, 0, kPaletteSize, 1}, PixelFormat::kR8, map_bytes);
rhi.update_texture(texture, {0, 0, kPaletteSize, 1}, PixelFormat::kR8, map_bytes);
colormaps_.insert_or_assign(colormap, texture);
return texture;
}
Handle<Texture> PaletteManager::find_or_create_extra_lighttable(Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx, srb2::NotNull<const uint8_t*> lighttable)
Handle<Texture> PaletteManager::find_or_create_extra_lighttable(Rhi& rhi, srb2::NotNull<const uint8_t*> lighttable)
{
if (lighttables_.find(lighttable) != lighttables_.end())
{
@ -133,7 +133,7 @@ Handle<Texture> PaletteManager::find_or_create_extra_lighttable(Rhi& rhi, rhi::H
Handle<Texture> texture = rhi.create_texture({TextureFormat::kLuminance, kPaletteSize, kLighttableRows, TextureWrapMode::kClamp, TextureWrapMode::kClamp});
tcb::span<const std::byte> lighttable_bytes = tcb::as_bytes(tcb::span(lighttable.get(), kPaletteSize * kLighttableRows));
rhi.update_texture(ctx, texture, {0, 0, kPaletteSize, kLighttableRows}, PixelFormat::kR8, lighttable_bytes);
rhi.update_texture(texture, {0, 0, kPaletteSize, kLighttableRows}, PixelFormat::kR8, lighttable_bytes);
lighttables_.insert_or_assign(lighttable, texture);
return texture;
@ -161,7 +161,7 @@ static uint32_t get_flat_size(lumpnum_t lump)
return lumpsize;
}
Handle<Texture> FlatTextureManager::find_or_create_indexed(Rhi& rhi, Handle<GraphicsContext> ctx, lumpnum_t lump)
Handle<Texture> FlatTextureManager::find_or_create_indexed(Rhi& rhi, lumpnum_t lump)
{
SRB2_ASSERT(lump != LUMPERROR);
@ -206,7 +206,7 @@ Handle<Texture> FlatTextureManager::find_or_create_indexed(Rhi& rhi, Handle<Grap
}
tcb::span<const std::byte> data_bytes = tcb::as_bytes(tcb::span(flat_data));
rhi.update_texture(ctx, new_tex, {0, 0, flat_size, flat_size}, rhi::PixelFormat::kRG8, data_bytes);
rhi.update_texture(new_tex, {0, 0, flat_size, flat_size}, rhi::PixelFormat::kRG8, data_bytes);
return new_tex;
}

View file

@ -45,11 +45,11 @@ public:
#endif
rhi::Handle<rhi::Texture> default_colormap() const noexcept { return default_colormap_; }
void update(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx);
void update(rhi::Rhi& rhi);
void destroy_per_frame_resources(rhi::Rhi& rhi);
rhi::Handle<rhi::Texture> find_or_create_colormap(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx, srb2::NotNull<const uint8_t*> colormap);
rhi::Handle<rhi::Texture> find_or_create_extra_lighttable(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx, srb2::NotNull<const uint8_t*> lighttable);
rhi::Handle<rhi::Texture> find_or_create_colormap(rhi::Rhi& rhi, srb2::NotNull<const uint8_t*> colormap);
rhi::Handle<rhi::Texture> find_or_create_extra_lighttable(rhi::Rhi& rhi, srb2::NotNull<const uint8_t*> lighttable);
};
/*
@ -79,7 +79,7 @@ public:
/// in prepass.
/// @param flat_lump
/// @return
rhi::Handle<rhi::Texture> find_or_create_indexed(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx, lumpnum_t flat_lump);
rhi::Handle<rhi::Texture> find_or_create_indexed(rhi::Rhi& rhi, lumpnum_t flat_lump);
};
} // namespace srb2::hwr2

View file

@ -21,7 +21,7 @@ using namespace srb2::rhi;
ScreenshotPass::ScreenshotPass() = default;
ScreenshotPass::~ScreenshotPass() = default;
void ScreenshotPass::capture(Rhi& rhi, Handle<GraphicsContext> ctx)
void ScreenshotPass::capture(Rhi& rhi)
{
bool doing_screenshot = takescreenshot || moviemode != MM_OFF || g_takemapthumbnail != TMT_NO;
@ -39,7 +39,7 @@ void ScreenshotPass::capture(Rhi& rhi, Handle<GraphicsContext> ctx)
packed_data_.resize(stride * height_);
tcb::span<std::byte> data_bytes = tcb::as_writable_bytes(tcb::span(pixel_data_));
rhi.read_pixels(ctx, {0, 0, width_, height_}, PixelFormat::kRGB8, data_bytes);
rhi.read_pixels({0, 0, width_, height_}, PixelFormat::kRGB8, data_bytes);
for (uint32_t row = 0; row < height_; row++)
{

View file

@ -31,7 +31,7 @@ public:
ScreenshotPass();
~ScreenshotPass();
void capture(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx);
void capture(rhi::Rhi& rhi);
void set_source(uint32_t width, uint32_t height)
{

View file

@ -20,7 +20,7 @@ using namespace srb2::rhi;
SoftwareScreenRenderer::SoftwareScreenRenderer() = default;
SoftwareScreenRenderer::~SoftwareScreenRenderer() = default;
void SoftwareScreenRenderer::draw(Rhi& rhi, Handle<GraphicsContext> ctx)
void SoftwareScreenRenderer::draw(Rhi& rhi)
{
// Render the player views... or not yet? Needs to be moved out of D_Display in d_main.c
// Assume it's already been done and vid.buffer contains the composited splitscreen view.
@ -71,5 +71,5 @@ void SoftwareScreenRenderer::draw(Rhi& rhi, Handle<GraphicsContext> ctx)
screen_span = tcb::as_bytes(tcb::span(vid.buffer, width_ * height_));
}
rhi.update_texture(ctx, screen_texture_, {0, 0, width_, height_}, PixelFormat::kR8, screen_span);
rhi.update_texture(screen_texture_, {0, 0, width_, height_}, PixelFormat::kR8, screen_span);
}

View file

@ -34,7 +34,7 @@ public:
SoftwareScreenRenderer();
~SoftwareScreenRenderer();
void draw(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx);
void draw(rhi::Rhi& rhi);
rhi::Handle<rhi::Texture> screen() const { return screen_texture_; }
};

View file

@ -231,7 +231,7 @@ void TwodeeRenderer::rewrite_patch_quad_vertices(Draw2dList& list, const Draw2dP
list.vertices[vtx_offs + 3].v = clipped_vmax;
}
void TwodeeRenderer::initialize(Rhi& rhi, Handle<GraphicsContext> ctx)
void TwodeeRenderer::initialize(Rhi& rhi)
{
{
TwodeePipelineKey alpha_transparent_tris = {BlendMode::kAlphaTransparent, false};
@ -269,17 +269,17 @@ void TwodeeRenderer::initialize(Rhi& rhi, Handle<GraphicsContext> ctx)
TextureWrapMode::kClamp
});
std::array<uint8_t, 4> data = {0, 255, 0, 255};
rhi.update_texture(ctx, default_tex_, {0, 0, 2, 1}, PixelFormat::kRG8, tcb::as_bytes(tcb::span(data)));
rhi.update_texture(default_tex_, {0, 0, 2, 1}, PixelFormat::kRG8, tcb::as_bytes(tcb::span(data)));
}
initialized_ = true;
}
void TwodeeRenderer::flush(Rhi& rhi, Handle<GraphicsContext> ctx, Twodee& twodee)
void TwodeeRenderer::flush(Rhi& rhi, Twodee& twodee)
{
if (!initialized_)
{
initialize(rhi, ctx);
initialize(rhi);
}
// Stage 1 - command list patch detection
@ -297,7 +297,7 @@ void TwodeeRenderer::flush(Rhi& rhi, Handle<GraphicsContext> ctx, Twodee& twodee
}
if (cmd.colormap != nullptr)
{
palette_manager_->find_or_create_colormap(rhi, ctx, cmd.colormap);
palette_manager_->find_or_create_colormap(rhi, cmd.colormap);
}
},
[&](const Draw2dVertices& cmd) {}};
@ -309,7 +309,7 @@ void TwodeeRenderer::flush(Rhi& rhi, Handle<GraphicsContext> ctx, Twodee& twodee
{
patch_atlas_cache_->queue_patch(patch);
}
patch_atlas_cache_->pack(rhi, ctx);
patch_atlas_cache_->pack(rhi);
size_t list_index = 0;
for (auto& list : twodee)
@ -445,7 +445,7 @@ void TwodeeRenderer::flush(Rhi& rhi, Handle<GraphicsContext> ctx, Twodee& twodee
{
if (cmd.flat_lump != LUMPERROR)
{
flat_manager_->find_or_create_indexed(rhi, ctx, cmd.flat_lump);
flat_manager_->find_or_create_indexed(rhi, cmd.flat_lump);
std::optional<MergedTwodeeCommand::Texture> t = MergedTwodeeCommandFlatTexture {cmd.flat_lump};
the_new_one.texture = t;
}
@ -492,8 +492,8 @@ void TwodeeRenderer::flush(Rhi& rhi, Handle<GraphicsContext> ctx, Twodee& twodee
tcb::span<const std::byte> vertex_data = tcb::as_bytes(tcb::span(orig_list.vertices));
tcb::span<const std::byte> index_data = tcb::as_bytes(tcb::span(orig_list.indices));
rhi.update_buffer(ctx, merged_list.vbo, 0, vertex_data);
rhi.update_buffer(ctx, merged_list.ibo, 0, index_data);
rhi.update_buffer(merged_list.vbo, 0, vertex_data);
rhi.update_buffer(merged_list.ibo, 0, index_data);
// Update the binding sets for each individual merged command
VertexAttributeBufferBinding vbos[] = {{0, merged_list.vbo}};
@ -508,7 +508,7 @@ void TwodeeRenderer::flush(Rhi& rhi, Handle<GraphicsContext> ctx, Twodee& twodee
},
[&](const MergedTwodeeCommandFlatTexture& tex)
{
Handle<Texture> th = flat_manager_->find_or_create_indexed(rhi, ctx, tex.lump);
Handle<Texture> th = flat_manager_->find_or_create_indexed(rhi, tex.lump);
SRB2_ASSERT(th != kNullHandle);
tx[0] = {SamplerName::kSampler0, th};
tx[1] = {SamplerName::kSampler1, palette_tex};
@ -527,12 +527,12 @@ void TwodeeRenderer::flush(Rhi& rhi, Handle<GraphicsContext> ctx, Twodee& twodee
Handle<Texture> colormap_h = palette_manager_->default_colormap();
if (colormap)
{
colormap_h = palette_manager_->find_or_create_colormap(rhi, ctx, colormap);
colormap_h = palette_manager_->find_or_create_colormap(rhi, colormap);
SRB2_ASSERT(colormap_h != kNullHandle);
}
tx[2] = {SamplerName::kSampler2, colormap_h};
mcmd.binding_set =
rhi.create_binding_set(ctx, pipelines_[mcmd.pipeline_key], {tcb::span(vbos), tcb::span(tx)});
rhi.create_binding_set(pipelines_[mcmd.pipeline_key], {tcb::span(vbos), tcb::span(tx)});
}
ctx_list_itr++;
@ -556,8 +556,8 @@ void TwodeeRenderer::flush(Rhi& rhi, Handle<GraphicsContext> ctx, Twodee& twodee
// Sampler 0 Is Indexed Alpha (yes, it always is)
static_cast<int32_t>(1)
};
Handle<UniformSet> us_1 = rhi.create_uniform_set(ctx, {tcb::span(g1_uniforms)});
Handle<UniformSet> us_2 = rhi.create_uniform_set(ctx, {tcb::span(g2_uniforms)});
Handle<UniformSet> us_1 = rhi.create_uniform_set({tcb::span(g1_uniforms)});
Handle<UniformSet> us_2 = rhi.create_uniform_set({tcb::span(g2_uniforms)});
// Presumably, we're already in a renderpass when flush is called
for (auto& list : cmd_lists_)
@ -572,13 +572,13 @@ void TwodeeRenderer::flush(Rhi& rhi, Handle<GraphicsContext> ctx, Twodee& twodee
}
SRB2_ASSERT(pipelines_.find(cmd.pipeline_key) != pipelines_.end());
Handle<Pipeline> pl = pipelines_[cmd.pipeline_key];
rhi.bind_pipeline(ctx, pl);
rhi.set_viewport(ctx, {0, 0, static_cast<uint32_t>(vid.width), static_cast<uint32_t>(vid.height)});
rhi.bind_uniform_set(ctx, 0, us_1);
rhi.bind_uniform_set(ctx, 1, us_2);
rhi.bind_binding_set(ctx, cmd.binding_set);
rhi.bind_index_buffer(ctx, list.ibo);
rhi.draw_indexed(ctx, cmd.elements, cmd.index_offset);
rhi.bind_pipeline(pl);
rhi.set_viewport({0, 0, static_cast<uint32_t>(vid.width), static_cast<uint32_t>(vid.height)});
rhi.bind_uniform_set(0, us_1);
rhi.bind_uniform_set(1, us_2);
rhi.bind_binding_set(cmd.binding_set);
rhi.bind_index_buffer(list.ibo);
rhi.draw_indexed(cmd.elements, cmd.index_offset);
}
}

View file

@ -101,7 +101,7 @@ class TwodeeRenderer final
void rewrite_patch_quad_vertices(Draw2dList& list, const Draw2dPatchQuad& cmd) const;
void initialize(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx);
void initialize(rhi::Rhi& rhi);
public:
TwodeeRenderer(
@ -118,7 +118,7 @@ public:
/// @brief Flush accumulated Twodee state and perform draws.
/// @param rhi
/// @param ctx
void flush(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx, Twodee& twodee);
void flush(rhi::Rhi& rhi, Twodee& twodee);
};
} // namespace srb2::hwr2

View file

@ -27,7 +27,7 @@ static bool size_equal(Rhi& rhi, Handle<Texture> tex, uint32_t width, uint32_t h
return deets.width == width && deets.height == height;
}
void UpscaleBackbuffer::begin_pass(Rhi& rhi, Handle<GraphicsContext> ctx)
void UpscaleBackbuffer::begin_pass(Rhi& rhi)
{
uint32_t vid_width = static_cast<uint32_t>(vid.width);
uint32_t vid_height = static_cast<uint32_t>(vid.height);
@ -88,5 +88,5 @@ void UpscaleBackbuffer::begin_pass(Rhi& rhi, Handle<GraphicsContext> ctx)
begin_info.render_pass = remake ? renderpass_clear_ : renderpass_;
begin_info.clear_color = {0, 0, 0, 1};
begin_info.color_attachment = color_;
rhi.begin_render_pass(ctx, begin_info);
rhi.begin_render_pass(begin_info);
}

View file

@ -31,7 +31,7 @@ public:
UpscaleBackbuffer& operator=(const UpscaleBackbuffer&) = delete;
UpscaleBackbuffer& operator=(UpscaleBackbuffer&&);
void begin_pass(rhi::Rhi& rhi, rhi::Handle<rhi::GraphicsContext> ctx);
void begin_pass(rhi::Rhi& rhi);
rhi::Handle<rhi::Texture> color() const noexcept { return color_; }
};

View file

@ -28,7 +28,6 @@ extern rhi::Handle<rhi::Rhi> g_current_rhi;
rhi::Rhi* get_rhi(rhi::Handle<rhi::Rhi> handle);
rhi::Handle<rhi::GraphicsContext> main_graphics_context();
hwr2::HardwareState* main_hardware_state();
} // namespace srb2::sys

View file

@ -56,7 +56,6 @@ using namespace srb2::rhi;
static Rhi* g_last_known_rhi = nullptr;
static bool g_imgui_frame_active = false;
static Handle<GraphicsContext> g_main_graphics_context;
static HardwareState g_hw_state;
Handle<Rhi> srb2::sys::g_current_rhi = kNullHandle;
@ -98,9 +97,7 @@ static void new_imgui_frame();
static void preframe_update(Rhi& rhi)
{
SRB2_ASSERT(g_main_graphics_context != kNullHandle);
g_hw_state.palette_manager->update(rhi, g_main_graphics_context);
g_hw_state.palette_manager->update(rhi);
new_twodee_frame();
new_imgui_frame();
}
@ -196,11 +193,6 @@ static void new_imgui_frame()
g_imgui_frame_active = true;
}
rhi::Handle<rhi::GraphicsContext> sys::main_graphics_context()
{
return g_main_graphics_context;
}
HardwareState* sys::main_hardware_state()
{
return &g_hw_state;
@ -209,11 +201,10 @@ HardwareState* sys::main_hardware_state()
void I_CaptureVideoFrame()
{
rhi::Rhi* rhi = srb2::sys::get_rhi(srb2::sys::g_current_rhi);
rhi::Handle<rhi::GraphicsContext> ctx = srb2::sys::main_graphics_context();
hwr2::HardwareState* hw_state = srb2::sys::main_hardware_state();
hw_state->screen_capture->set_source(static_cast<uint32_t>(vid.width), static_cast<uint32_t>(vid.height));
hw_state->screen_capture->capture(*rhi, ctx);
hw_state->screen_capture->capture(*rhi);
}
void I_StartDisplayUpdate(void)
@ -244,12 +235,9 @@ void I_StartDisplayUpdate(void)
reset_hardware_state(rhi);
}
rhi::Handle<rhi::GraphicsContext> ctx = rhi->begin_graphics();
HardwareState* hw_state = &g_hw_state;
hw_state->backbuffer->begin_pass(*rhi, ctx);
g_main_graphics_context = ctx;
hw_state->backbuffer->begin_pass(*rhi);
preframe_update(*rhi);
}
@ -283,68 +271,60 @@ void I_FinishUpdate(void)
return;
}
rhi::Handle<rhi::GraphicsContext> ctx = g_main_graphics_context;
// better hope the drawing code left the context in a render pass, I guess
g_hw_state.twodee_renderer->flush(*rhi, g_2d);
rhi->end_render_pass();
if (ctx != kNullHandle)
rhi->begin_default_render_pass(true);
// Upscale draw the backbuffer (with postprocessing maybe?)
if (cv_scr_scale.value != FRACUNIT)
{
// better hope the drawing code left the context in a render pass, I guess
g_hw_state.twodee_renderer->flush(*rhi, ctx, g_2d);
rhi->end_render_pass(ctx);
float f = std::max(FixedToFloat(cv_scr_scale.value), 0.f);
float w = vid.realwidth * f;
float h = vid.realheight * f;
float x = (vid.realwidth - w) * (0.5f + (FixedToFloat(cv_scr_x.value) * 0.5f));
float y = (vid.realheight - h) * (0.5f + (FixedToFloat(cv_scr_y.value) * 0.5f));
rhi->begin_default_render_pass(ctx, true);
// Upscale draw the backbuffer (with postprocessing maybe?)
if (cv_scr_scale.value != FRACUNIT)
{
float f = std::max(FixedToFloat(cv_scr_scale.value), 0.f);
float w = vid.realwidth * f;
float h = vid.realheight * f;
float x = (vid.realwidth - w) * (0.5f + (FixedToFloat(cv_scr_x.value) * 0.5f));
float y = (vid.realheight - h) * (0.5f + (FixedToFloat(cv_scr_y.value) * 0.5f));
g_hw_state.blit_rect->set_output(x, y, w, h, true, true);
g_hw_state.sharp_bilinear_blit_rect->set_output(x, y, w, h, true, true);
g_hw_state.crt_blit_rect->set_output(x, y, w, h, true, true);
g_hw_state.crtsharp_blit_rect->set_output(x, y, w, h, true, true);
}
else
{
g_hw_state.blit_rect->set_output(0, 0, vid.realwidth, vid.realheight, true, true);
g_hw_state.sharp_bilinear_blit_rect->set_output(0, 0, vid.realwidth, vid.realheight, true, true);
g_hw_state.crt_blit_rect->set_output(0, 0, vid.realwidth, vid.realheight, true, true);
g_hw_state.crtsharp_blit_rect->set_output(0, 0, vid.realwidth, vid.realheight, true, true);
}
g_hw_state.blit_rect->set_texture(g_hw_state.backbuffer->color(), static_cast<uint32_t>(vid.width), static_cast<uint32_t>(vid.height));
g_hw_state.sharp_bilinear_blit_rect->set_texture(g_hw_state.backbuffer->color(), static_cast<uint32_t>(vid.width), static_cast<uint32_t>(vid.height));
g_hw_state.crt_blit_rect->set_texture(g_hw_state.backbuffer->color(), static_cast<uint32_t>(vid.width), static_cast<uint32_t>(vid.height));
g_hw_state.crtsharp_blit_rect->set_texture(g_hw_state.backbuffer->color(), static_cast<uint32_t>(vid.width), static_cast<uint32_t>(vid.height));
switch (cv_scr_effect.value)
{
case 1:
rhi->update_texture_settings(ctx, g_hw_state.backbuffer->color(), TextureWrapMode::kClamp, TextureWrapMode::kClamp, TextureFilterMode::kLinear, TextureFilterMode::kLinear);
g_hw_state.sharp_bilinear_blit_rect->draw(*rhi, ctx);
break;
case 2:
rhi->update_texture_settings(ctx, g_hw_state.backbuffer->color(), TextureWrapMode::kClamp, TextureWrapMode::kClamp, TextureFilterMode::kLinear, TextureFilterMode::kLinear);
g_hw_state.crt_blit_rect->draw(*rhi, ctx);
break;
case 3:
rhi->update_texture_settings(ctx, g_hw_state.backbuffer->color(), TextureWrapMode::kClamp, TextureWrapMode::kClamp, TextureFilterMode::kLinear, TextureFilterMode::kLinear);
g_hw_state.crtsharp_blit_rect->draw(*rhi, ctx);
break;
default:
rhi->update_texture_settings(ctx, g_hw_state.backbuffer->color(), TextureWrapMode::kClamp, TextureWrapMode::kClamp, TextureFilterMode::kNearest, TextureFilterMode::kNearest);
g_hw_state.blit_rect->draw(*rhi, ctx);
break;
}
rhi->end_render_pass(ctx);
rhi->end_graphics(ctx);
g_main_graphics_context = kNullHandle;
postframe_update(*rhi);
g_hw_state.blit_rect->set_output(x, y, w, h, true, true);
g_hw_state.sharp_bilinear_blit_rect->set_output(x, y, w, h, true, true);
g_hw_state.crt_blit_rect->set_output(x, y, w, h, true, true);
g_hw_state.crtsharp_blit_rect->set_output(x, y, w, h, true, true);
}
else
{
g_hw_state.blit_rect->set_output(0, 0, vid.realwidth, vid.realheight, true, true);
g_hw_state.sharp_bilinear_blit_rect->set_output(0, 0, vid.realwidth, vid.realheight, true, true);
g_hw_state.crt_blit_rect->set_output(0, 0, vid.realwidth, vid.realheight, true, true);
g_hw_state.crtsharp_blit_rect->set_output(0, 0, vid.realwidth, vid.realheight, true, true);
}
g_hw_state.blit_rect->set_texture(g_hw_state.backbuffer->color(), static_cast<uint32_t>(vid.width), static_cast<uint32_t>(vid.height));
g_hw_state.sharp_bilinear_blit_rect->set_texture(g_hw_state.backbuffer->color(), static_cast<uint32_t>(vid.width), static_cast<uint32_t>(vid.height));
g_hw_state.crt_blit_rect->set_texture(g_hw_state.backbuffer->color(), static_cast<uint32_t>(vid.width), static_cast<uint32_t>(vid.height));
g_hw_state.crtsharp_blit_rect->set_texture(g_hw_state.backbuffer->color(), static_cast<uint32_t>(vid.width), static_cast<uint32_t>(vid.height));
switch (cv_scr_effect.value)
{
case 1:
rhi->update_texture_settings(g_hw_state.backbuffer->color(), TextureWrapMode::kClamp, TextureWrapMode::kClamp, TextureFilterMode::kLinear, TextureFilterMode::kLinear);
g_hw_state.sharp_bilinear_blit_rect->draw(*rhi);
break;
case 2:
rhi->update_texture_settings(g_hw_state.backbuffer->color(), TextureWrapMode::kClamp, TextureWrapMode::kClamp, TextureFilterMode::kLinear, TextureFilterMode::kLinear);
g_hw_state.crt_blit_rect->draw(*rhi);
break;
case 3:
rhi->update_texture_settings(g_hw_state.backbuffer->color(), TextureWrapMode::kClamp, TextureWrapMode::kClamp, TextureFilterMode::kLinear, TextureFilterMode::kLinear);
g_hw_state.crtsharp_blit_rect->draw(*rhi);
break;
default:
rhi->update_texture_settings(g_hw_state.backbuffer->color(), TextureWrapMode::kClamp, TextureWrapMode::kClamp, TextureFilterMode::kNearest, TextureFilterMode::kNearest);
g_hw_state.blit_rect->draw(*rhi);
break;
}
rhi->end_render_pass();
postframe_update(*rhi);
rhi->present();
rhi->finish();

View file

@ -636,15 +636,12 @@ void Gl2Rhi::destroy_texture(rhi::Handle<rhi::Texture> handle)
}
void Gl2Rhi::update_texture(
Handle<GraphicsContext> ctx,
Handle<Texture> texture,
Rect region,
srb2::rhi::PixelFormat data_format,
tcb::span<const std::byte> data
)
{
SRB2_ASSERT(graphics_context_active_ == true);
if (data.empty())
{
return;
@ -687,7 +684,6 @@ void Gl2Rhi::update_texture(
}
void Gl2Rhi::update_texture_settings(
Handle<GraphicsContext> ctx,
Handle<Texture> texture,
TextureWrapMode u_wrap,
TextureWrapMode v_wrap,
@ -695,8 +691,6 @@ void Gl2Rhi::update_texture_settings(
TextureFilterMode mag
)
{
SRB2_ASSERT(graphics_context_active_ == true);
SRB2_ASSERT(texture_slab_.is_valid(texture) == true);
auto& t = texture_slab_[texture];
@ -749,15 +743,11 @@ void Gl2Rhi::destroy_buffer(rhi::Handle<rhi::Buffer> handle)
}
void Gl2Rhi::update_buffer(
rhi::Handle<GraphicsContext> ctx,
rhi::Handle<rhi::Buffer> handle,
uint32_t offset,
tcb::span<const std::byte> data
)
{
SRB2_ASSERT(graphics_context_active_ == true);
SRB2_ASSERT(ctx.generation() == graphics_context_generation_);
if (data.empty())
{
return;
@ -786,11 +776,8 @@ void Gl2Rhi::update_buffer(
}
rhi::Handle<rhi::UniformSet>
Gl2Rhi::create_uniform_set(rhi::Handle<rhi::GraphicsContext> ctx, const rhi::CreateUniformSetInfo& info)
Gl2Rhi::create_uniform_set(const rhi::CreateUniformSetInfo& info)
{
SRB2_ASSERT(graphics_context_active_ == true);
SRB2_ASSERT(ctx.generation() == graphics_context_generation_);
Gl2UniformSet uniform_set;
for (auto& uniform : info.uniforms)
@ -802,14 +789,10 @@ Gl2Rhi::create_uniform_set(rhi::Handle<rhi::GraphicsContext> ctx, const rhi::Cre
}
rhi::Handle<rhi::BindingSet> Gl2Rhi::create_binding_set(
rhi::Handle<rhi::GraphicsContext> ctx,
Handle<Pipeline> pipeline,
const rhi::CreateBindingSetInfo& info
)
{
SRB2_ASSERT(graphics_context_active_ == true);
SRB2_ASSERT(ctx.generation() == graphics_context_generation_);
SRB2_ASSERT(pipeline_slab_.is_valid(pipeline) == true);
auto& pl = pipeline_slab_[pipeline];
@ -1204,39 +1187,16 @@ void Gl2Rhi::destroy_pipeline(rhi::Handle<rhi::Pipeline> handle)
GL_ASSERT;
}
rhi::Handle<rhi::GraphicsContext> Gl2Rhi::begin_graphics()
{
SRB2_ASSERT(graphics_context_active_ == false);
graphics_context_active_ = true;
return rhi::Handle<rhi::GraphicsContext>(0, graphics_context_generation_);
}
void Gl2Rhi::end_graphics(rhi::Handle<rhi::GraphicsContext> handle)
{
SRB2_ASSERT(graphics_context_active_ == true);
SRB2_ASSERT(current_pipeline_.has_value() == false && current_render_pass_.has_value() == false);
graphics_context_generation_ += 1;
if (graphics_context_generation_ == 0)
{
graphics_context_generation_ = 1;
}
graphics_context_active_ = false;
gl_->Flush();
GL_ASSERT;
}
void Gl2Rhi::present()
{
SRB2_ASSERT(platform_ != nullptr);
SRB2_ASSERT(graphics_context_active_ == false);
platform_->present();
}
void Gl2Rhi::begin_default_render_pass(Handle<GraphicsContext> ctx, bool clear)
void Gl2Rhi::begin_default_render_pass(bool clear)
{
SRB2_ASSERT(platform_ != nullptr);
SRB2_ASSERT(graphics_context_active_ == true);
SRB2_ASSERT(current_render_pass_.has_value() == false);
const Rect fb_rect = platform_->get_default_framebuffer_dimensions();
@ -1260,9 +1220,8 @@ void Gl2Rhi::begin_default_render_pass(Handle<GraphicsContext> ctx, bool clear)
current_render_pass_ = Gl2Rhi::DefaultRenderPassState {};
}
void Gl2Rhi::begin_render_pass(Handle<GraphicsContext> ctx, const RenderPassBeginInfo& info)
void Gl2Rhi::begin_render_pass(const RenderPassBeginInfo& info)
{
SRB2_ASSERT(graphics_context_active_ == true && graphics_context_generation_ == ctx.generation());
SRB2_ASSERT(current_render_pass_.has_value() == false);
SRB2_ASSERT(render_pass_slab_.is_valid(info.render_pass) == true);
@ -1340,18 +1299,16 @@ void Gl2Rhi::begin_render_pass(Handle<GraphicsContext> ctx, const RenderPassBegi
current_render_pass_ = info;
}
void Gl2Rhi::end_render_pass(Handle<GraphicsContext> ctx)
void Gl2Rhi::end_render_pass()
{
SRB2_ASSERT(graphics_context_active_ == true && graphics_context_generation_ == ctx.generation());
SRB2_ASSERT(current_render_pass_.has_value() == true);
current_pipeline_ = std::nullopt;
current_render_pass_ = std::nullopt;
}
void Gl2Rhi::bind_pipeline(Handle<GraphicsContext> ctx, Handle<Pipeline> pipeline)
void Gl2Rhi::bind_pipeline(Handle<Pipeline> pipeline)
{
SRB2_ASSERT(graphics_context_active_ == true && graphics_context_generation_ == ctx.generation());
SRB2_ASSERT(current_render_pass_.has_value() == true);
SRB2_ASSERT(pipeline_slab_.is_valid(pipeline) == true);
@ -1491,9 +1448,8 @@ void Gl2Rhi::bind_pipeline(Handle<GraphicsContext> ctx, Handle<Pipeline> pipelin
current_primitive_type_ = desc.primitive;
}
void Gl2Rhi::bind_uniform_set(Handle<GraphicsContext> ctx, uint32_t slot, Handle<UniformSet> set)
void Gl2Rhi::bind_uniform_set(uint32_t slot, Handle<UniformSet> set)
{
SRB2_ASSERT(graphics_context_active_ == true && graphics_context_generation_ == ctx.generation());
SRB2_ASSERT(current_render_pass_.has_value() == true && current_pipeline_.has_value() == true);
SRB2_ASSERT(pipeline_slab_.is_valid(*current_pipeline_));
@ -1587,9 +1543,8 @@ void Gl2Rhi::bind_uniform_set(Handle<GraphicsContext> ctx, uint32_t slot, Handle
}
}
void Gl2Rhi::bind_binding_set(Handle<GraphicsContext> ctx, Handle<BindingSet> set)
void Gl2Rhi::bind_binding_set(Handle<BindingSet> set)
{
SRB2_ASSERT(graphics_context_active_ == true && graphics_context_generation_ == ctx.generation());
SRB2_ASSERT(current_render_pass_.has_value() == true && current_pipeline_.has_value() == true);
SRB2_ASSERT(pipeline_slab_.is_valid(*current_pipeline_));
@ -1685,9 +1640,8 @@ void Gl2Rhi::bind_binding_set(Handle<GraphicsContext> ctx, Handle<BindingSet> se
}
}
void Gl2Rhi::bind_index_buffer(Handle<GraphicsContext> ctx, Handle<Buffer> buffer)
void Gl2Rhi::bind_index_buffer(Handle<Buffer> buffer)
{
SRB2_ASSERT(graphics_context_active_ == true && graphics_context_generation_ == ctx.generation());
SRB2_ASSERT(current_render_pass_.has_value() == true && current_pipeline_.has_value() == true);
SRB2_ASSERT(buffer_slab_.is_valid(buffer));
@ -1700,37 +1654,32 @@ void Gl2Rhi::bind_index_buffer(Handle<GraphicsContext> ctx, Handle<Buffer> buffe
gl_->BindBuffer(GL_ELEMENT_ARRAY_BUFFER, ib.buffer);
}
void Gl2Rhi::set_scissor(Handle<GraphicsContext> ctx, const Rect& rect)
void Gl2Rhi::set_scissor(const Rect& rect)
{
SRB2_ASSERT(graphics_context_active_ == true && graphics_context_generation_ == ctx.generation());
SRB2_ASSERT(current_render_pass_.has_value() == true && current_pipeline_.has_value() == true);
gl_->Enable(GL_SCISSOR_TEST);
gl_->Scissor(rect.x, rect.y, rect.w, rect.h);
}
void Gl2Rhi::set_viewport(Handle<GraphicsContext> ctx, const Rect& rect)
void Gl2Rhi::set_viewport(const Rect& rect)
{
SRB2_ASSERT(graphics_context_active_ == true && graphics_context_generation_ == ctx.generation());
SRB2_ASSERT(current_render_pass_.has_value() == true && current_pipeline_.has_value() == true);
gl_->Viewport(rect.x, rect.y, rect.w, rect.h);
GL_ASSERT;
}
void Gl2Rhi::draw(Handle<GraphicsContext> ctx, uint32_t vertex_count, uint32_t first_vertex)
void Gl2Rhi::draw(uint32_t vertex_count, uint32_t first_vertex)
{
SRB2_ASSERT(graphics_context_active_ == true && graphics_context_generation_ == ctx.generation());
SRB2_ASSERT(current_render_pass_.has_value() == true && current_pipeline_.has_value() == true);
gl_->DrawArrays(map_primitive_mode(current_primitive_type_), first_vertex, vertex_count);
GL_ASSERT;
}
void Gl2Rhi::draw_indexed(Handle<GraphicsContext> ctx, uint32_t index_count, uint32_t first_index)
void Gl2Rhi::draw_indexed(uint32_t index_count, uint32_t first_index)
{
SRB2_ASSERT(graphics_context_active_ == true && graphics_context_generation_ == ctx.generation());
SRB2_ASSERT(current_index_buffer_ != kNullHandle);
#ifndef NDEBUG
{
@ -1748,9 +1697,8 @@ void Gl2Rhi::draw_indexed(Handle<GraphicsContext> ctx, uint32_t index_count, uin
GL_ASSERT;
}
void Gl2Rhi::read_pixels(Handle<GraphicsContext> ctx, const Rect& rect, PixelFormat format, tcb::span<std::byte> out)
void Gl2Rhi::read_pixels(const Rect& rect, PixelFormat format, tcb::span<std::byte> out)
{
SRB2_ASSERT(graphics_context_active_ == true && graphics_context_generation_ == ctx.generation());
SRB2_ASSERT(current_render_pass_.has_value());
std::tuple<GLenum, GLenum, GLuint> gl_format = map_pixel_data_format(format);
@ -1792,10 +1740,9 @@ void Gl2Rhi::read_pixels(Handle<GraphicsContext> ctx, const Rect& rect, PixelFor
GL_ASSERT;
}
void Gl2Rhi::set_stencil_reference(Handle<GraphicsContext> ctx, CullMode face, uint8_t reference)
void Gl2Rhi::set_stencil_reference(CullMode face, uint8_t reference)
{
SRB2_ASSERT(face != CullMode::kNone);
SRB2_ASSERT(graphics_context_active_ == true && graphics_context_generation_ == ctx.generation());
SRB2_ASSERT(current_render_pass_.has_value());
SRB2_ASSERT(current_pipeline_.has_value());
@ -1823,10 +1770,9 @@ void Gl2Rhi::set_stencil_reference(Handle<GraphicsContext> ctx, CullMode face, u
}
}
void Gl2Rhi::set_stencil_compare_mask(Handle<GraphicsContext> ctx, CullMode face, uint8_t compare_mask)
void Gl2Rhi::set_stencil_compare_mask(CullMode face, uint8_t compare_mask)
{
SRB2_ASSERT(face != CullMode::kNone);
SRB2_ASSERT(graphics_context_active_ == true && graphics_context_generation_ == ctx.generation());
SRB2_ASSERT(current_render_pass_.has_value());
SRB2_ASSERT(current_pipeline_.has_value());
@ -1854,10 +1800,9 @@ void Gl2Rhi::set_stencil_compare_mask(Handle<GraphicsContext> ctx, CullMode face
}
}
void Gl2Rhi::set_stencil_write_mask(Handle<GraphicsContext> ctx, CullMode face, uint8_t write_mask)
void Gl2Rhi::set_stencil_write_mask(CullMode face, uint8_t write_mask)
{
SRB2_ASSERT(face != CullMode::kNone);
SRB2_ASSERT(graphics_context_active_ == true && graphics_context_generation_ == ctx.generation());
SRB2_ASSERT(current_render_pass_.has_value());
SRB2_ASSERT(current_pipeline_.has_value());
@ -1910,8 +1855,6 @@ uint32_t Gl2Rhi::get_buffer_size(Handle<Buffer> buffer)
void Gl2Rhi::finish()
{
SRB2_ASSERT(graphics_context_active_ == false);
binding_set_slab_.clear();
uniform_set_slab_.clear();
@ -1925,13 +1868,11 @@ void Gl2Rhi::finish()
}
void Gl2Rhi::copy_framebuffer_to_texture(
Handle<GraphicsContext> ctx,
Handle<Texture> dst_tex,
const Rect& dst_region,
const Rect& src_region
)
{
SRB2_ASSERT(graphics_context_active_ == true);
SRB2_ASSERT(current_render_pass_.has_value());
SRB2_ASSERT(texture_slab_.is_valid(dst_tex));

View file

@ -120,10 +120,6 @@ struct Gl2Pipeline : public rhi::Pipeline
rhi::PipelineDesc desc;
};
struct Gl2GraphicsContext : public rhi::GraphicsContext
{
};
struct Gl2ActiveUniform
{
uint32_t type;
@ -155,8 +151,6 @@ class Gl2Rhi final : public Rhi
std::optional<RenderPassState> current_render_pass_;
std::optional<Handle<Pipeline>> current_pipeline_;
PrimitiveType current_primitive_type_ = PrimitiveType::kPoints;
bool graphics_context_active_ = false;
uint32_t graphics_context_generation_ = 1;
uint32_t index_buffer_offset_ = 0;
uint8_t stencil_front_reference_ = 0;
@ -187,20 +181,17 @@ public:
virtual uint32_t get_buffer_size(Handle<Buffer> buffer) override;
virtual void update_buffer(
Handle<GraphicsContext> ctx,
Handle<Buffer> buffer,
uint32_t offset,
tcb::span<const std::byte> data
) override;
virtual void update_texture(
Handle<GraphicsContext> ctx,
Handle<Texture> texture,
Rect region,
srb2::rhi::PixelFormat data_format,
tcb::span<const std::byte> data
) override;
virtual void update_texture_settings(
Handle<GraphicsContext> ctx,
Handle<Texture> texture,
TextureWrapMode u_wrap,
TextureWrapMode v_wrap,
@ -208,37 +199,33 @@ public:
TextureFilterMode mag
) override;
virtual Handle<UniformSet>
create_uniform_set(Handle<GraphicsContext> ctx, const CreateUniformSetInfo& info) override;
create_uniform_set(const CreateUniformSetInfo& info) override;
virtual Handle<BindingSet>
create_binding_set(Handle<GraphicsContext> ctx, Handle<Pipeline> pipeline, const CreateBindingSetInfo& info)
create_binding_set(Handle<Pipeline> pipeline, const CreateBindingSetInfo& info)
override;
virtual Handle<GraphicsContext> begin_graphics() override;
virtual void end_graphics(Handle<GraphicsContext> ctx) override;
// Graphics context functions
virtual void begin_default_render_pass(Handle<GraphicsContext> ctx, bool clear) override;
virtual void begin_render_pass(Handle<GraphicsContext> ctx, const RenderPassBeginInfo& info) override;
virtual void end_render_pass(Handle<GraphicsContext> ctx) override;
virtual void bind_pipeline(Handle<GraphicsContext> ctx, Handle<Pipeline> pipeline) override;
virtual void bind_uniform_set(Handle<GraphicsContext> ctx, uint32_t slot, Handle<UniformSet> set) override;
virtual void bind_binding_set(Handle<GraphicsContext> ctx, Handle<BindingSet> set) override;
virtual void bind_index_buffer(Handle<GraphicsContext> ctx, Handle<Buffer> buffer) override;
virtual void set_scissor(Handle<GraphicsContext> ctx, const Rect& rect) override;
virtual void set_viewport(Handle<GraphicsContext> ctx, const Rect& rect) override;
virtual void draw(Handle<GraphicsContext> ctx, uint32_t vertex_count, uint32_t first_vertex) override;
virtual void draw_indexed(Handle<GraphicsContext> ctx, uint32_t index_count, uint32_t first_index) override;
virtual void begin_default_render_pass(bool clear) override;
virtual void begin_render_pass(const RenderPassBeginInfo& info) override;
virtual void end_render_pass() override;
virtual void bind_pipeline(Handle<Pipeline> pipeline) override;
virtual void bind_uniform_set(uint32_t slot, Handle<UniformSet> set) override;
virtual void bind_binding_set(Handle<BindingSet> set) override;
virtual void bind_index_buffer(Handle<Buffer> buffer) override;
virtual void set_scissor(const Rect& rect) override;
virtual void set_viewport(const Rect& rect) override;
virtual void draw(uint32_t vertex_count, uint32_t first_vertex) override;
virtual void draw_indexed(uint32_t index_count, uint32_t first_index) override;
virtual void
read_pixels(Handle<GraphicsContext> ctx, const Rect& rect, PixelFormat format, tcb::span<std::byte> out) override;
read_pixels(const Rect& rect, PixelFormat format, tcb::span<std::byte> out) override;
virtual void copy_framebuffer_to_texture(
Handle<GraphicsContext> ctx,
Handle<Texture> dst_tex,
const Rect& dst_region,
const Rect& src_region
) override;
virtual void set_stencil_reference(Handle<GraphicsContext> ctx, CullMode face, uint8_t reference) override;
virtual void set_stencil_compare_mask(Handle<GraphicsContext> ctx, CullMode face, uint8_t mask) override;
virtual void set_stencil_write_mask(Handle<GraphicsContext> ctx, CullMode face, uint8_t mask) override;
virtual void set_stencil_reference(CullMode face, uint8_t reference) override;
virtual void set_stencil_compare_mask(CullMode face, uint8_t mask) override;
virtual void set_stencil_write_mask(CullMode face, uint8_t mask) override;
virtual void present() override;

View file

@ -13,9 +13,7 @@
#include <cstdint>
#include <optional>
#include <set>
#include <variant>
#include <vector>
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
@ -584,10 +582,6 @@ struct BindingSet
{
};
struct GraphicsContext
{
};
struct TextureDetails
{
uint32_t width;
@ -621,56 +615,49 @@ struct Rhi
virtual uint32_t get_buffer_size(Handle<Buffer> buffer) = 0;
virtual void update_buffer(
Handle<GraphicsContext> ctx,
Handle<Buffer> buffer,
uint32_t offset,
tcb::span<const std::byte> data
) = 0;
virtual void update_texture(
Handle<GraphicsContext> ctx,
Handle<Texture> texture,
Rect region,
srb2::rhi::PixelFormat data_format,
tcb::span<const std::byte> data
) = 0;
virtual void update_texture_settings(
Handle<GraphicsContext> ctx,
Handle<Texture> texture,
TextureWrapMode u_wrap,
TextureWrapMode v_wrap,
TextureFilterMode min,
TextureFilterMode mag
) = 0;
virtual Handle<UniformSet> create_uniform_set(Handle<GraphicsContext> ctx, const CreateUniformSetInfo& info) = 0;
virtual Handle<UniformSet> create_uniform_set(const CreateUniformSetInfo& info) = 0;
virtual Handle<BindingSet>
create_binding_set(Handle<GraphicsContext> ctx, Handle<Pipeline> pipeline, const CreateBindingSetInfo& info) = 0;
virtual Handle<GraphicsContext> begin_graphics() = 0;
virtual void end_graphics(Handle<GraphicsContext> ctx) = 0;
create_binding_set(Handle<Pipeline> pipeline, const CreateBindingSetInfo& info) = 0;
// Graphics context functions
virtual void begin_default_render_pass(Handle<GraphicsContext> ctx, bool clear) = 0;
virtual void begin_render_pass(Handle<GraphicsContext> ctx, const RenderPassBeginInfo& info) = 0;
virtual void end_render_pass(Handle<GraphicsContext> ctx) = 0;
virtual void bind_pipeline(Handle<GraphicsContext> ctx, Handle<Pipeline> pipeline) = 0;
virtual void bind_uniform_set(Handle<GraphicsContext> ctx, uint32_t slot, Handle<UniformSet> set) = 0;
virtual void bind_binding_set(Handle<GraphicsContext> ctx, Handle<BindingSet> set) = 0;
virtual void bind_index_buffer(Handle<GraphicsContext> ctx, Handle<Buffer> buffer) = 0;
virtual void set_scissor(Handle<GraphicsContext> ctx, const Rect& rect) = 0;
virtual void set_viewport(Handle<GraphicsContext> ctx, const Rect& rect) = 0;
virtual void draw(Handle<GraphicsContext> ctx, uint32_t vertex_count, uint32_t first_vertex) = 0;
virtual void draw_indexed(Handle<GraphicsContext> ctx, uint32_t index_count, uint32_t first_index) = 0;
virtual void begin_default_render_pass(bool clear) = 0;
virtual void begin_render_pass(const RenderPassBeginInfo& info) = 0;
virtual void end_render_pass() = 0;
virtual void bind_pipeline(Handle<Pipeline> pipeline) = 0;
virtual void bind_uniform_set(uint32_t slot, Handle<UniformSet> set) = 0;
virtual void bind_binding_set(Handle<BindingSet> set) = 0;
virtual void bind_index_buffer(Handle<Buffer> buffer) = 0;
virtual void set_scissor(const Rect& rect) = 0;
virtual void set_viewport(const Rect& rect) = 0;
virtual void draw(uint32_t vertex_count, uint32_t first_vertex) = 0;
virtual void draw_indexed(uint32_t index_count, uint32_t first_index) = 0;
virtual void
read_pixels(Handle<GraphicsContext> ctx, const Rect& rect, PixelFormat format, tcb::span<std::byte> out) = 0;
read_pixels(const Rect& rect, PixelFormat format, tcb::span<std::byte> out) = 0;
virtual void copy_framebuffer_to_texture(
Handle<GraphicsContext> ctx,
Handle<Texture> dst_tex,
const Rect& dst_region,
const Rect& src_region
) = 0;
virtual void set_stencil_reference(Handle<GraphicsContext> ctx, CullMode face, uint8_t reference) = 0;
virtual void set_stencil_compare_mask(Handle<GraphicsContext> ctx, CullMode face, uint8_t mask) = 0;
virtual void set_stencil_write_mask(Handle<GraphicsContext> ctx, CullMode face, uint8_t mask) = 0;
virtual void set_stencil_reference(CullMode face, uint8_t reference) = 0;
virtual void set_stencil_compare_mask(CullMode face, uint8_t mask) = 0;
virtual void set_stencil_write_mask(CullMode face, uint8_t mask) = 0;
virtual void present() = 0;

View file

@ -2986,7 +2986,7 @@ void V_DrawStringScaled(
case gb_dpad: return {{1, 4, Draw::GenericButton::dpad}};
default: return {};
}
}();
}();
}
if (bt_inst)
@ -3766,11 +3766,10 @@ void VID_DisplaySoftwareScreen()
// TODO implement
// upload framebuffer, bind pipeline, draw
rhi::Rhi* rhi = srb2::sys::get_rhi(srb2::sys::g_current_rhi);
rhi::Handle<rhi::GraphicsContext> ctx = srb2::sys::main_graphics_context();
hwr2::HardwareState* hw_state = srb2::sys::main_hardware_state();
// Misnomer; this just uploads the screen to the software indexed screen texture
hw_state->software_screen_renderer->draw(*rhi, ctx);
hw_state->software_screen_renderer->draw(*rhi);
const int screens = std::clamp(r_splitscreen + 1, 1, MAXSPLITSCREENPLAYERS);
hw_state->blit_postimg_screens->set_num_screens(screens);
@ -3827,7 +3826,7 @@ void VID_DisplaySoftwareScreen()
}
// Post-process blit to the 'default' framebuffer
hw_state->blit_postimg_screens->draw(*rhi, ctx);
hw_state->blit_postimg_screens->draw(*rhi);
}
char *V_ParseText(const char *rawText)