From dae2e8ba17cc7ad9efa96c515ef82ecd6d0a4e53 Mon Sep 17 00:00:00 2001 From: Eidolon Date: Thu, 24 Oct 2024 13:56:13 -0500 Subject: [PATCH] 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. --- src/f_wipe.cpp | 33 ++----- src/hwr2/blit_postimg_screens.cpp | 25 +++-- src/hwr2/blit_postimg_screens.hpp | 4 +- src/hwr2/blit_rect.cpp | 48 +++++----- src/hwr2/blit_rect.hpp | 6 +- src/hwr2/pass.hpp | 4 +- src/hwr2/pass_imgui.cpp | 33 ++++--- src/hwr2/pass_imgui.hpp | 4 +- src/hwr2/pass_manager.cpp | 22 ++--- src/hwr2/pass_manager.hpp | 4 +- src/hwr2/pass_resource_managers.cpp | 46 +++++----- src/hwr2/pass_resource_managers.hpp | 20 ++-- src/hwr2/patch_atlas.cpp | 3 +- src/hwr2/patch_atlas.hpp | 2 +- src/hwr2/postprocess_wipe.cpp | 32 +++---- src/hwr2/postprocess_wipe.hpp | 6 +- src/hwr2/resource_management.cpp | 22 ++--- src/hwr2/resource_management.hpp | 8 +- src/hwr2/screen_capture.cpp | 4 +- src/hwr2/screen_capture.hpp | 2 +- src/hwr2/software_screen_renderer.cpp | 4 +- src/hwr2/software_screen_renderer.hpp | 2 +- src/hwr2/twodee_renderer.cpp | 42 ++++----- src/hwr2/twodee_renderer.hpp | 4 +- src/hwr2/upscale_backbuffer.cpp | 4 +- src/hwr2/upscale_backbuffer.hpp | 2 +- src/i_video.h | 1 - src/i_video_common.cpp | 126 +++++++++++--------------- src/rhi/gl2/gl2_rhi.cpp | 91 ++++--------------- src/rhi/gl2/gl2_rhi.hpp | 47 ++++------ src/rhi/rhi.hpp | 47 ++++------ src/v_video.cpp | 7 +- 32 files changed, 289 insertions(+), 416 deletions(-) diff --git a/src/f_wipe.cpp b/src/f_wipe.cpp index f553aafa6..6f75cb45f 100644 --- a/src/f_wipe.cpp +++ b/src/f_wipe.cpp @@ -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 ctx, rhi::Handle& tex) +static void refresh_wipe_screen_texture(rhi::Rhi& rhi, rhi::Handle& tex) { bool recreate = false; if (!tex) @@ -371,24 +371,17 @@ void F_WipeStartScreen(void) return; } - rhi::Handle 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(vid.width), static_cast(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 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(vid.width), static_cast(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 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(vid.width), static_cast(vid.height)); - hw_state->wipe->draw(*rhi, ctx); + hw_state->wipe->draw(*rhi); } I_OsPolling(); diff --git a/src/hwr2/blit_postimg_screens.cpp b/src/hwr2/blit_postimg_screens.cpp index 13a9e8213..f98a6d35b 100644 --- a/src/hwr2/blit_postimg_screens.cpp +++ b/src/hwr2/blit_postimg_screens.cpp @@ -99,21 +99,21 @@ BlitPostimgScreens::BlitPostimgScreens(PaletteManager* palette_mgr) { } -void BlitPostimgScreens::draw(Rhi& rhi, Handle 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 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 ctx) }; data.binding_set = rhi.create_binding_set( - ctx, data.pipeline, { vertex_bindings, @@ -234,7 +233,7 @@ void BlitPostimgScreens::transfer(Rhi& rhi, Handle 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); } diff --git a/src/hwr2/blit_postimg_screens.hpp b/src/hwr2/blit_postimg_screens.hpp index c91b65ca9..f4fec80fb 100644 --- a/src/hwr2/blit_postimg_screens.hpp +++ b/src/hwr2/blit_postimg_screens.hpp @@ -67,12 +67,12 @@ private: PaletteManager* palette_mgr_; void prepass(rhi::Rhi& rhi); - void transfer(rhi::Rhi& rhi, rhi::Handle ctx); + void transfer(rhi::Rhi& rhi); public: explicit BlitPostimgScreens(PaletteManager* palette_mgr); - void draw(rhi::Rhi& rhi, rhi::Handle ctx); + void draw(rhi::Rhi& rhi); void set_num_screens(uint32_t screens) noexcept { diff --git a/src/hwr2/blit_rect.cpp b/src/hwr2/blit_rect.cpp index 1e6edec2f..6e96b6957 100644 --- a/src/hwr2/blit_rect.cpp +++ b/src/hwr2/blit_rect.cpp @@ -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 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 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 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 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 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 vbs = {{{0, quad_vbo_}}}; std::array 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 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 vbs = {{{0, quad_vbo_}}}; std::array 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 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 vbs = {{{0, quad_vbo_}}}; std::array 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 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 vbs = {{{0, quad_vbo_}}}; std::array 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 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); } diff --git a/src/hwr2/blit_rect.hpp b/src/hwr2/blit_rect.hpp index d93841fe9..306e69f4c 100644 --- a/src/hwr2/blit_rect.hpp +++ b/src/hwr2/blit_rect.hpp @@ -52,8 +52,8 @@ private: bool dot_pattern_needs_upload_ = false; void prepass(rhi::Rhi& rhi); - void transfer(rhi::Rhi& rhi, rhi::Handle ctx); - void graphics(rhi::Rhi& rhi, rhi::Handle 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 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 diff --git a/src/hwr2/pass.hpp b/src/hwr2/pass.hpp index 716049de3..1ebb916e6 100644 --- a/src/hwr2/pass.hpp +++ b/src/hwr2/pass.hpp @@ -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 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 ctx) = 0; + virtual void graphics(rhi::Rhi& rhi) = 0; /// @brief Cleanup GPU resources. Transient resources should be cleaned up here. /// @param rhi diff --git a/src/hwr2/pass_imgui.cpp b/src/hwr2/pass_imgui.cpp index b11e724cf..3b8c04e04 100644 --- a/src/hwr2/pass_imgui.cpp +++ b/src/hwr2/pass_imgui.cpp @@ -128,7 +128,7 @@ void ImguiPass::prepass(Rhi& rhi) } } -void ImguiPass::transfer(Rhi& rhi, Handle ctx) +void ImguiPass::transfer(Rhi& rhi) { ImGuiIO& io = ImGui::GetIO(); @@ -137,7 +137,6 @@ void ImguiPass::transfer(Rhi& rhi, Handle ctx) int width, height; io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); rhi.update_texture( - ctx, font_atlas_, {0, 0, static_cast(width), static_cast(height)}, rhi::PixelFormat::kRGBA8, @@ -162,10 +161,10 @@ void ImguiPass::transfer(Rhi& rhi, Handle ctx) } tcb::span 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 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 g1_uniforms = { @@ -192,8 +191,8 @@ void ImguiPass::transfer(Rhi& rhi, Handle ctx) glm::vec3(0.f, 0.f, 1.f) ) }; - Handle us_1 = rhi.create_uniform_set(ctx, {g1_uniforms}); - Handle us_2 = rhi.create_uniform_set(ctx, {g2_uniforms}); + Handle us_1 = rhi.create_uniform_set({g1_uniforms}); + Handle 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 ctx) // Binding set std::array vbos = {{{0, vbo}}}; std::array tbs = {{{rhi::SamplerName::kSampler0, draw_cmd.tex}}}; - rhi::Handle binding_set = rhi.create_binding_set(ctx, pipeline_, {vbos, tbs}); + rhi::Handle binding_set = rhi.create_binding_set(pipeline_, {vbos, tbs}); draw_cmd.binding_set = binding_set; } } } -void ImguiPass::graphics(Rhi& rhi, Handle 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) diff --git a/src/hwr2/pass_imgui.hpp b/src/hwr2/pass_imgui.hpp index d0fa44db5..2a7e6ad4e 100644 --- a/src/hwr2/pass_imgui.hpp +++ b/src/hwr2/pass_imgui.hpp @@ -51,9 +51,9 @@ public: virtual void prepass(rhi::Rhi& rhi) override; - virtual void transfer(rhi::Rhi& rhi, rhi::Handle ctx) override; + virtual void transfer(rhi::Rhi& rhi) override; - virtual void graphics(rhi::Rhi& rhi, rhi::Handle ctx) override; + virtual void graphics(rhi::Rhi& rhi) override; virtual void postpass(rhi::Rhi& rhi) override; }; diff --git a/src/hwr2/pass_manager.cpp b/src/hwr2/pass_manager.cpp index d846e3770..a66d0d492 100644 --- a/src/hwr2/pass_manager.cpp +++ b/src/hwr2/pass_manager.cpp @@ -33,8 +33,8 @@ public: virtual ~LambdaPass(); virtual void prepass(rhi::Rhi& rhi) override; - virtual void transfer(rhi::Rhi& rhi, rhi::Handle ctx) override; - virtual void graphics(rhi::Rhi& rhi, rhi::Handle 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) +void LambdaPass::transfer(Rhi&) { } -void LambdaPass::graphics(Rhi&, Handle) +void LambdaPass::graphics(Rhi&) { } @@ -138,24 +138,24 @@ void PassManager::prepass(Rhi& rhi) } } -void PassManager::transfer(Rhi& rhi, Handle 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 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 gc = rhi.begin_graphics(); - transfer(rhi, gc); - graphics(rhi, gc); - rhi.end_graphics(gc); + transfer(rhi); + graphics(rhi); postpass(rhi); } diff --git a/src/hwr2/pass_manager.hpp b/src/hwr2/pass_manager.hpp index 12c40187b..b163c7886 100644 --- a/src/hwr2/pass_manager.hpp +++ b/src/hwr2/pass_manager.hpp @@ -44,8 +44,8 @@ public: PassManager& operator=(PassManager&&) = delete; virtual void prepass(rhi::Rhi& rhi) override; - virtual void transfer(rhi::Rhi& rhi, rhi::Handle ctx) override; - virtual void graphics(rhi::Rhi& rhi, rhi::Handle 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); diff --git a/src/hwr2/pass_resource_managers.cpp b/src/hwr2/pass_resource_managers.cpp index d7ace5d9b..e635a6511 100644 --- a/src/hwr2/pass_resource_managers.cpp +++ b/src/hwr2/pass_resource_managers.cpp @@ -120,11 +120,11 @@ void FramebufferManager::prepass(Rhi& rhi) } } -void FramebufferManager::transfer(Rhi& rhi, Handle ctx) +void FramebufferManager::transfer(Rhi& rhi) { } -void FramebufferManager::graphics(Rhi& rhi, Handle ctx) +void FramebufferManager::graphics(Rhi& rhi) { } @@ -161,28 +161,28 @@ void MainPaletteManager::prepass(Rhi& rhi) } } -void MainPaletteManager::upload_palette(Rhi& rhi, Handle ctx) +void MainPaletteManager::upload_palette(Rhi& rhi) { std::array 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 ctx) +void MainPaletteManager::upload_lighttables(Rhi& rhi) { if (colormaps != nullptr) { tcb::span 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 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 ct Handle lighttable_tex = find_extra_lighttable(lighttable); SRB2_ASSERT(lighttable_tex != kNullHandle); tcb::span 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 ctx) +void MainPaletteManager::upload_default_colormap(Rhi& rhi) { std::array 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 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 ctx) rhi::Handle map_texture = colormaps_.at(to_upload); tcb::span 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 MainPaletteManager::find_extra_lighttable(srb2::NotNul return lighttables_.at(lighttable); } -void MainPaletteManager::transfer(Rhi& rhi, Handle 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 ctx) +void MainPaletteManager::graphics(Rhi& rhi) { } @@ -319,7 +319,7 @@ void CommonResourcesManager::prepass(Rhi& rhi) } } -void CommonResourcesManager::transfer(Rhi& rhi, Handle ctx) +void CommonResourcesManager::transfer(Rhi& rhi) { if (!init_) { @@ -330,13 +330,13 @@ void CommonResourcesManager::transfer(Rhi& rhi, Handle ctx) uint8_t transparent[4] = {0, 0, 0, 0}; tcb::span 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 ctx) +void CommonResourcesManager::graphics(Rhi& rhi) { } diff --git a/src/hwr2/pass_resource_managers.hpp b/src/hwr2/pass_resource_managers.hpp index 30e93279e..faef32a42 100644 --- a/src/hwr2/pass_resource_managers.hpp +++ b/src/hwr2/pass_resource_managers.hpp @@ -37,8 +37,8 @@ public: virtual ~FramebufferManager(); virtual void prepass(rhi::Rhi& rhi) override; - virtual void transfer(rhi::Rhi& rhi, rhi::Handle ctx) override; - virtual void graphics(rhi::Rhi& rhi, rhi::Handle 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 colormaps_to_upload_; std::vector lighttables_to_upload_; - void upload_palette(rhi::Rhi& rhi, rhi::Handle ctx); - void upload_lighttables(rhi::Rhi& rhi, rhi::Handle ctx); - void upload_default_colormap(rhi::Rhi& rhi, rhi::Handle ctx); - void upload_colormaps(rhi::Rhi& rhi, rhi::Handle 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 ctx) override; - virtual void graphics(rhi::Rhi& rhi, rhi::Handle 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 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 ctx) override; - virtual void graphics(rhi::Rhi& rhi, rhi::Handle 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 black() const noexcept { return black_; } diff --git a/src/hwr2/patch_atlas.cpp b/src/hwr2/patch_atlas.cpp index b3b1d218d..8ee3c165a 100644 --- a/src/hwr2/patch_atlas.cpp +++ b/src/hwr2/patch_atlas.cpp @@ -216,7 +216,7 @@ static PatchAtlas create_atlas(Rhi& rhi, uint32_t size) return new_atlas; } -void PatchAtlasCache::pack(Rhi& rhi, Handle ctx) +void PatchAtlasCache::pack(Rhi& rhi) { // Prepare stbrp rects for patches to be loaded. std::vector rects; @@ -310,7 +310,6 @@ void PatchAtlasCache::pack(Rhi& rhi, Handle ctx) convert_patch_to_trimmed_rg8_pixels(patch_to_upload, patch_data); rhi.update_texture( - ctx, atlas->tex_, {static_cast(entry->x), static_cast(entry->y), entry->w, entry->h}, PixelFormat::kRG8, diff --git a/src/hwr2/patch_atlas.hpp b/src/hwr2/patch_atlas.hpp index f66bf7c36..6d9536d86 100644 --- a/src/hwr2/patch_atlas.hpp +++ b/src/hwr2/patch_atlas.hpp @@ -113,7 +113,7 @@ public: void queue_patch(srb2::NotNull patch); /// @brief Pack queued patches, allowing them to be looked up with find_patch. - void pack(rhi::Rhi& rhi, rhi::Handle 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. diff --git a/src/hwr2/postprocess_wipe.cpp b/src/hwr2/postprocess_wipe.cpp index 4b5f3ced7..4ce6fca66 100644 --- a/src/hwr2/postprocess_wipe.cpp +++ b/src/hwr2/postprocess_wipe.cpp @@ -63,11 +63,11 @@ PostprocessWipePass::PostprocessWipePass() PostprocessWipePass::~PostprocessWipePass() = default; -void PostprocessWipePass::draw(Rhi& rhi, Handle 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 ctx) +void PostprocessWipePass::transfer(Rhi& rhi) { if (wipe_tex_ == kNullHandle) { @@ -183,47 +183,47 @@ void PostprocessWipePass::transfer(Rhi& rhi, Handle 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 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::vec3(2.f, 2.f, 1.f)), static_cast(wipe_color_mode_), static_cast(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 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) diff --git a/src/hwr2/postprocess_wipe.hpp b/src/hwr2/postprocess_wipe.hpp index f1d13b4fd..838307ce0 100644 --- a/src/hwr2/postprocess_wipe.hpp +++ b/src/hwr2/postprocess_wipe.hpp @@ -44,15 +44,15 @@ class PostprocessWipePass final uint32_t mask_h_ = 0; void prepass(rhi::Rhi& rhi); - void transfer(rhi::Rhi& rhi, rhi::Handle ctx); - void graphics(rhi::Rhi& rhi, rhi::Handle 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 ctx); + void draw(rhi::Rhi& rhi); void set_start(rhi::Handle start) noexcept { start_ = start; } diff --git a/src/hwr2/resource_management.cpp b/src/hwr2/resource_management.cpp index e338c66dd..6e3d15e25 100644 --- a/src/hwr2/resource_management.cpp +++ b/src/hwr2/resource_management.cpp @@ -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 ctx) +void PaletteManager::update(Rhi& rhi) { if (!palette_) { @@ -57,7 +57,7 @@ void PaletteManager::update(Rhi& rhi, Handle 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 ctx) if (colormaps != nullptr) { tcb::span 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 ctx) if (encoremap != nullptr) { tcb::span 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 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 PaletteManager::find_or_create_colormap(Rhi& rhi, rhi::Handle ctx, srb2::NotNull colormap) +Handle PaletteManager::find_or_create_colormap(Rhi& rhi, srb2::NotNull colormap) { if (colormaps_.find(colormap) != colormaps_.end()) { @@ -117,13 +117,13 @@ Handle PaletteManager::find_or_create_colormap(Rhi& rhi, rhi::Handle texture = rhi.create_texture({TextureFormat::kLuminance, kPaletteSize, 1, TextureWrapMode::kClamp, TextureWrapMode::kClamp}); tcb::span 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 PaletteManager::find_or_create_extra_lighttable(Rhi& rhi, rhi::Handle ctx, srb2::NotNull lighttable) +Handle PaletteManager::find_or_create_extra_lighttable(Rhi& rhi, srb2::NotNull lighttable) { if (lighttables_.find(lighttable) != lighttables_.end()) { @@ -133,7 +133,7 @@ Handle PaletteManager::find_or_create_extra_lighttable(Rhi& rhi, rhi::H Handle texture = rhi.create_texture({TextureFormat::kLuminance, kPaletteSize, kLighttableRows, TextureWrapMode::kClamp, TextureWrapMode::kClamp}); tcb::span 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 FlatTextureManager::find_or_create_indexed(Rhi& rhi, Handle ctx, lumpnum_t lump) +Handle FlatTextureManager::find_or_create_indexed(Rhi& rhi, lumpnum_t lump) { SRB2_ASSERT(lump != LUMPERROR); @@ -206,7 +206,7 @@ Handle FlatTextureManager::find_or_create_indexed(Rhi& rhi, Handle 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; } diff --git a/src/hwr2/resource_management.hpp b/src/hwr2/resource_management.hpp index 965e276c1..b3a5c1589 100644 --- a/src/hwr2/resource_management.hpp +++ b/src/hwr2/resource_management.hpp @@ -45,11 +45,11 @@ public: #endif rhi::Handle default_colormap() const noexcept { return default_colormap_; } - void update(rhi::Rhi& rhi, rhi::Handle ctx); + void update(rhi::Rhi& rhi); void destroy_per_frame_resources(rhi::Rhi& rhi); - rhi::Handle find_or_create_colormap(rhi::Rhi& rhi, rhi::Handle ctx, srb2::NotNull colormap); - rhi::Handle find_or_create_extra_lighttable(rhi::Rhi& rhi, rhi::Handle ctx, srb2::NotNull lighttable); + rhi::Handle find_or_create_colormap(rhi::Rhi& rhi, srb2::NotNull colormap); + rhi::Handle find_or_create_extra_lighttable(rhi::Rhi& rhi, srb2::NotNull lighttable); }; /* @@ -79,7 +79,7 @@ public: /// in prepass. /// @param flat_lump /// @return - rhi::Handle find_or_create_indexed(rhi::Rhi& rhi, rhi::Handle ctx, lumpnum_t flat_lump); + rhi::Handle find_or_create_indexed(rhi::Rhi& rhi, lumpnum_t flat_lump); }; } // namespace srb2::hwr2 diff --git a/src/hwr2/screen_capture.cpp b/src/hwr2/screen_capture.cpp index 69e950650..a1484b8f6 100644 --- a/src/hwr2/screen_capture.cpp +++ b/src/hwr2/screen_capture.cpp @@ -21,7 +21,7 @@ using namespace srb2::rhi; ScreenshotPass::ScreenshotPass() = default; ScreenshotPass::~ScreenshotPass() = default; -void ScreenshotPass::capture(Rhi& rhi, Handle 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 ctx) packed_data_.resize(stride * height_); tcb::span 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++) { diff --git a/src/hwr2/screen_capture.hpp b/src/hwr2/screen_capture.hpp index 2b455adf2..fa5ecad5a 100644 --- a/src/hwr2/screen_capture.hpp +++ b/src/hwr2/screen_capture.hpp @@ -31,7 +31,7 @@ public: ScreenshotPass(); ~ScreenshotPass(); - void capture(rhi::Rhi& rhi, rhi::Handle ctx); + void capture(rhi::Rhi& rhi); void set_source(uint32_t width, uint32_t height) { diff --git a/src/hwr2/software_screen_renderer.cpp b/src/hwr2/software_screen_renderer.cpp index 021f609bc..0ce2bd470 100644 --- a/src/hwr2/software_screen_renderer.cpp +++ b/src/hwr2/software_screen_renderer.cpp @@ -20,7 +20,7 @@ using namespace srb2::rhi; SoftwareScreenRenderer::SoftwareScreenRenderer() = default; SoftwareScreenRenderer::~SoftwareScreenRenderer() = default; -void SoftwareScreenRenderer::draw(Rhi& rhi, Handle 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 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); } diff --git a/src/hwr2/software_screen_renderer.hpp b/src/hwr2/software_screen_renderer.hpp index e95027eb2..6b2f85deb 100644 --- a/src/hwr2/software_screen_renderer.hpp +++ b/src/hwr2/software_screen_renderer.hpp @@ -34,7 +34,7 @@ public: SoftwareScreenRenderer(); ~SoftwareScreenRenderer(); - void draw(rhi::Rhi& rhi, rhi::Handle ctx); + void draw(rhi::Rhi& rhi); rhi::Handle screen() const { return screen_texture_; } }; diff --git a/src/hwr2/twodee_renderer.cpp b/src/hwr2/twodee_renderer.cpp index b79e5063e..8d9eaabf7 100644 --- a/src/hwr2/twodee_renderer.cpp +++ b/src/hwr2/twodee_renderer.cpp @@ -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 ctx) +void TwodeeRenderer::initialize(Rhi& rhi) { { TwodeePipelineKey alpha_transparent_tris = {BlendMode::kAlphaTransparent, false}; @@ -269,17 +269,17 @@ void TwodeeRenderer::initialize(Rhi& rhi, Handle ctx) TextureWrapMode::kClamp }); std::array 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 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 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 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 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 t = MergedTwodeeCommandFlatTexture {cmd.flat_lump}; the_new_one.texture = t; } @@ -492,8 +492,8 @@ void TwodeeRenderer::flush(Rhi& rhi, Handle ctx, Twodee& twodee tcb::span vertex_data = tcb::as_bytes(tcb::span(orig_list.vertices)); tcb::span 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 ctx, Twodee& twodee }, [&](const MergedTwodeeCommandFlatTexture& tex) { - Handle th = flat_manager_->find_or_create_indexed(rhi, ctx, tex.lump); + Handle 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 ctx, Twodee& twodee Handle 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 ctx, Twodee& twodee // Sampler 0 Is Indexed Alpha (yes, it always is) static_cast(1) }; - Handle us_1 = rhi.create_uniform_set(ctx, {tcb::span(g1_uniforms)}); - Handle us_2 = rhi.create_uniform_set(ctx, {tcb::span(g2_uniforms)}); + Handle us_1 = rhi.create_uniform_set({tcb::span(g1_uniforms)}); + Handle 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 ctx, Twodee& twodee } SRB2_ASSERT(pipelines_.find(cmd.pipeline_key) != pipelines_.end()); Handle pl = pipelines_[cmd.pipeline_key]; - rhi.bind_pipeline(ctx, pl); - rhi.set_viewport(ctx, {0, 0, static_cast(vid.width), static_cast(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(vid.width), static_cast(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); } } diff --git a/src/hwr2/twodee_renderer.hpp b/src/hwr2/twodee_renderer.hpp index 9b3a895c9..b71b85fc4 100644 --- a/src/hwr2/twodee_renderer.hpp +++ b/src/hwr2/twodee_renderer.hpp @@ -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 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 ctx, Twodee& twodee); + void flush(rhi::Rhi& rhi, Twodee& twodee); }; } // namespace srb2::hwr2 diff --git a/src/hwr2/upscale_backbuffer.cpp b/src/hwr2/upscale_backbuffer.cpp index 790f5b332..3af6f9ed1 100644 --- a/src/hwr2/upscale_backbuffer.cpp +++ b/src/hwr2/upscale_backbuffer.cpp @@ -27,7 +27,7 @@ static bool size_equal(Rhi& rhi, Handle tex, uint32_t width, uint32_t h return deets.width == width && deets.height == height; } -void UpscaleBackbuffer::begin_pass(Rhi& rhi, Handle ctx) +void UpscaleBackbuffer::begin_pass(Rhi& rhi) { uint32_t vid_width = static_cast(vid.width); uint32_t vid_height = static_cast(vid.height); @@ -88,5 +88,5 @@ void UpscaleBackbuffer::begin_pass(Rhi& rhi, Handle 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); } diff --git a/src/hwr2/upscale_backbuffer.hpp b/src/hwr2/upscale_backbuffer.hpp index a60f30172..6c39d6639 100644 --- a/src/hwr2/upscale_backbuffer.hpp +++ b/src/hwr2/upscale_backbuffer.hpp @@ -31,7 +31,7 @@ public: UpscaleBackbuffer& operator=(const UpscaleBackbuffer&) = delete; UpscaleBackbuffer& operator=(UpscaleBackbuffer&&); - void begin_pass(rhi::Rhi& rhi, rhi::Handle ctx); + void begin_pass(rhi::Rhi& rhi); rhi::Handle color() const noexcept { return color_; } }; diff --git a/src/i_video.h b/src/i_video.h index 1617a7305..d12d5f782 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -28,7 +28,6 @@ extern rhi::Handle g_current_rhi; rhi::Rhi* get_rhi(rhi::Handle handle); -rhi::Handle main_graphics_context(); hwr2::HardwareState* main_hardware_state(); } // namespace srb2::sys diff --git a/src/i_video_common.cpp b/src/i_video_common.cpp index 82ab995c3..e9553daa6 100644 --- a/src/i_video_common.cpp +++ b/src/i_video_common.cpp @@ -56,7 +56,6 @@ using namespace srb2::rhi; static Rhi* g_last_known_rhi = nullptr; static bool g_imgui_frame_active = false; -static Handle g_main_graphics_context; static HardwareState g_hw_state; Handle 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 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 ctx = srb2::sys::main_graphics_context(); hwr2::HardwareState* hw_state = srb2::sys::main_hardware_state(); hw_state->screen_capture->set_source(static_cast(vid.width), static_cast(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 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 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(vid.width), static_cast(vid.height)); - g_hw_state.sharp_bilinear_blit_rect->set_texture(g_hw_state.backbuffer->color(), static_cast(vid.width), static_cast(vid.height)); - g_hw_state.crt_blit_rect->set_texture(g_hw_state.backbuffer->color(), static_cast(vid.width), static_cast(vid.height)); - g_hw_state.crtsharp_blit_rect->set_texture(g_hw_state.backbuffer->color(), static_cast(vid.width), static_cast(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(vid.width), static_cast(vid.height)); + g_hw_state.sharp_bilinear_blit_rect->set_texture(g_hw_state.backbuffer->color(), static_cast(vid.width), static_cast(vid.height)); + g_hw_state.crt_blit_rect->set_texture(g_hw_state.backbuffer->color(), static_cast(vid.width), static_cast(vid.height)); + g_hw_state.crtsharp_blit_rect->set_texture(g_hw_state.backbuffer->color(), static_cast(vid.width), static_cast(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(); diff --git a/src/rhi/gl2/gl2_rhi.cpp b/src/rhi/gl2/gl2_rhi.cpp index 340d24dbb..d591e554c 100644 --- a/src/rhi/gl2/gl2_rhi.cpp +++ b/src/rhi/gl2/gl2_rhi.cpp @@ -636,15 +636,12 @@ void Gl2Rhi::destroy_texture(rhi::Handle handle) } void Gl2Rhi::update_texture( - Handle ctx, Handle texture, Rect region, srb2::rhi::PixelFormat data_format, tcb::span 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 ctx, Handle 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 handle) } void Gl2Rhi::update_buffer( - rhi::Handle ctx, rhi::Handle handle, uint32_t offset, tcb::span 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 -Gl2Rhi::create_uniform_set(rhi::Handle 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 ctx, const rhi::Cre } rhi::Handle Gl2Rhi::create_binding_set( - rhi::Handle ctx, Handle 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 handle) GL_ASSERT; } -rhi::Handle Gl2Rhi::begin_graphics() -{ - SRB2_ASSERT(graphics_context_active_ == false); - graphics_context_active_ = true; - return rhi::Handle(0, graphics_context_generation_); -} - -void Gl2Rhi::end_graphics(rhi::Handle 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 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 ctx, bool clear) current_render_pass_ = Gl2Rhi::DefaultRenderPassState {}; } -void Gl2Rhi::begin_render_pass(Handle 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 ctx, const RenderPassBegi current_render_pass_ = info; } -void Gl2Rhi::end_render_pass(Handle 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 ctx, Handle pipeline) +void Gl2Rhi::bind_pipeline(Handle 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 ctx, Handle pipelin current_primitive_type_ = desc.primitive; } -void Gl2Rhi::bind_uniform_set(Handle ctx, uint32_t slot, Handle set) +void Gl2Rhi::bind_uniform_set(uint32_t slot, Handle 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 ctx, uint32_t slot, Handle } } -void Gl2Rhi::bind_binding_set(Handle ctx, Handle set) +void Gl2Rhi::bind_binding_set(Handle 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 ctx, Handle se } } -void Gl2Rhi::bind_index_buffer(Handle ctx, Handle buffer) +void Gl2Rhi::bind_index_buffer(Handle 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 ctx, Handle buffe gl_->BindBuffer(GL_ELEMENT_ARRAY_BUFFER, ib.buffer); } -void Gl2Rhi::set_scissor(Handle 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 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 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 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 ctx, uint32_t index_count, uin GL_ASSERT; } -void Gl2Rhi::read_pixels(Handle ctx, const Rect& rect, PixelFormat format, tcb::span out) +void Gl2Rhi::read_pixels(const Rect& rect, PixelFormat format, tcb::span out) { - SRB2_ASSERT(graphics_context_active_ == true && graphics_context_generation_ == ctx.generation()); SRB2_ASSERT(current_render_pass_.has_value()); std::tuple gl_format = map_pixel_data_format(format); @@ -1792,10 +1740,9 @@ void Gl2Rhi::read_pixels(Handle ctx, const Rect& rect, PixelFor GL_ASSERT; } -void Gl2Rhi::set_stencil_reference(Handle 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 ctx, CullMode face, u } } -void Gl2Rhi::set_stencil_compare_mask(Handle 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 ctx, CullMode face } } -void Gl2Rhi::set_stencil_write_mask(Handle 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) 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 ctx, Handle 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)); diff --git a/src/rhi/gl2/gl2_rhi.hpp b/src/rhi/gl2/gl2_rhi.hpp index 93f04446e..fcb26b962 100644 --- a/src/rhi/gl2/gl2_rhi.hpp +++ b/src/rhi/gl2/gl2_rhi.hpp @@ -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 current_render_pass_; std::optional> 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) override; virtual void update_buffer( - Handle ctx, Handle buffer, uint32_t offset, tcb::span data ) override; virtual void update_texture( - Handle ctx, Handle texture, Rect region, srb2::rhi::PixelFormat data_format, tcb::span data ) override; virtual void update_texture_settings( - Handle ctx, Handle texture, TextureWrapMode u_wrap, TextureWrapMode v_wrap, @@ -208,37 +199,33 @@ public: TextureFilterMode mag ) override; virtual Handle - create_uniform_set(Handle ctx, const CreateUniformSetInfo& info) override; + create_uniform_set(const CreateUniformSetInfo& info) override; virtual Handle - create_binding_set(Handle ctx, Handle pipeline, const CreateBindingSetInfo& info) + create_binding_set(Handle pipeline, const CreateBindingSetInfo& info) override; - virtual Handle begin_graphics() override; - virtual void end_graphics(Handle ctx) override; - // Graphics context functions - virtual void begin_default_render_pass(Handle ctx, bool clear) override; - virtual void begin_render_pass(Handle ctx, const RenderPassBeginInfo& info) override; - virtual void end_render_pass(Handle ctx) override; - virtual void bind_pipeline(Handle ctx, Handle pipeline) override; - virtual void bind_uniform_set(Handle ctx, uint32_t slot, Handle set) override; - virtual void bind_binding_set(Handle ctx, Handle set) override; - virtual void bind_index_buffer(Handle ctx, Handle buffer) override; - virtual void set_scissor(Handle ctx, const Rect& rect) override; - virtual void set_viewport(Handle ctx, const Rect& rect) override; - virtual void draw(Handle ctx, uint32_t vertex_count, uint32_t first_vertex) override; - virtual void draw_indexed(Handle 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) override; + virtual void bind_uniform_set(uint32_t slot, Handle set) override; + virtual void bind_binding_set(Handle set) override; + virtual void bind_index_buffer(Handle 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 ctx, const Rect& rect, PixelFormat format, tcb::span out) override; + read_pixels(const Rect& rect, PixelFormat format, tcb::span out) override; virtual void copy_framebuffer_to_texture( - Handle ctx, Handle dst_tex, const Rect& dst_region, const Rect& src_region ) override; - virtual void set_stencil_reference(Handle ctx, CullMode face, uint8_t reference) override; - virtual void set_stencil_compare_mask(Handle ctx, CullMode face, uint8_t mask) override; - virtual void set_stencil_write_mask(Handle 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; diff --git a/src/rhi/rhi.hpp b/src/rhi/rhi.hpp index 1a6f68236..da6c65740 100644 --- a/src/rhi/rhi.hpp +++ b/src/rhi/rhi.hpp @@ -13,9 +13,7 @@ #include #include -#include #include -#include #include #include @@ -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) = 0; virtual void update_buffer( - Handle ctx, Handle buffer, uint32_t offset, tcb::span data ) = 0; virtual void update_texture( - Handle ctx, Handle texture, Rect region, srb2::rhi::PixelFormat data_format, tcb::span data ) = 0; virtual void update_texture_settings( - Handle ctx, Handle texture, TextureWrapMode u_wrap, TextureWrapMode v_wrap, TextureFilterMode min, TextureFilterMode mag ) = 0; - virtual Handle create_uniform_set(Handle ctx, const CreateUniformSetInfo& info) = 0; + virtual Handle create_uniform_set(const CreateUniformSetInfo& info) = 0; virtual Handle - create_binding_set(Handle ctx, Handle pipeline, const CreateBindingSetInfo& info) = 0; - - virtual Handle begin_graphics() = 0; - virtual void end_graphics(Handle ctx) = 0; + create_binding_set(Handle pipeline, const CreateBindingSetInfo& info) = 0; // Graphics context functions - virtual void begin_default_render_pass(Handle ctx, bool clear) = 0; - virtual void begin_render_pass(Handle ctx, const RenderPassBeginInfo& info) = 0; - virtual void end_render_pass(Handle ctx) = 0; - virtual void bind_pipeline(Handle ctx, Handle pipeline) = 0; - virtual void bind_uniform_set(Handle ctx, uint32_t slot, Handle set) = 0; - virtual void bind_binding_set(Handle ctx, Handle set) = 0; - virtual void bind_index_buffer(Handle ctx, Handle buffer) = 0; - virtual void set_scissor(Handle ctx, const Rect& rect) = 0; - virtual void set_viewport(Handle ctx, const Rect& rect) = 0; - virtual void draw(Handle ctx, uint32_t vertex_count, uint32_t first_vertex) = 0; - virtual void draw_indexed(Handle 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) = 0; + virtual void bind_uniform_set(uint32_t slot, Handle set) = 0; + virtual void bind_binding_set(Handle set) = 0; + virtual void bind_index_buffer(Handle 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 ctx, const Rect& rect, PixelFormat format, tcb::span out) = 0; + read_pixels(const Rect& rect, PixelFormat format, tcb::span out) = 0; virtual void copy_framebuffer_to_texture( - Handle ctx, Handle dst_tex, const Rect& dst_region, const Rect& src_region ) = 0; - virtual void set_stencil_reference(Handle ctx, CullMode face, uint8_t reference) = 0; - virtual void set_stencil_compare_mask(Handle ctx, CullMode face, uint8_t mask) = 0; - virtual void set_stencil_write_mask(Handle 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; diff --git a/src/v_video.cpp b/src/v_video.cpp index 310171a41..05f6c4ed7 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -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 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)