From 0a9e9bbbaec7a899fd3d088708fc11eb098bf427 Mon Sep 17 00:00:00 2001 From: Eidolon Date: Sun, 12 Feb 2023 11:46:00 -0600 Subject: [PATCH] hwr2: use palette manager in twodee --- src/hwr2/pass_twodee.cpp | 31 +++++-------------------------- src/hwr2/pass_twodee.hpp | 1 + src/i_video_common.cpp | 3 ++- 3 files changed, 8 insertions(+), 27 deletions(-) diff --git a/src/hwr2/pass_twodee.cpp b/src/hwr2/pass_twodee.cpp index 469fdcd2a..da3e47176 100644 --- a/src/hwr2/pass_twodee.cpp +++ b/src/hwr2/pass_twodee.cpp @@ -58,7 +58,6 @@ struct Atlas struct srb2::hwr2::TwodeePassData { Handle default_tex; - Handle palette_tex; Handle default_colormap_tex; std::vector patch_atlases; std::unordered_map patch_lookup; @@ -482,10 +481,6 @@ void TwodeePass::prepass(Rhi& rhi) data_->default_tex = rhi.create_texture({TextureFormat::kLuminanceAlpha, 2, 1}); data_->upload_default_tex = true; } - if (!data_->palette_tex) - { - data_->palette_tex = rhi.create_texture({TextureFormat::kRGBA, 256, 1}); - } if (!data_->default_colormap_tex) { data_->default_colormap_tex = rhi.create_texture({TextureFormat::kLuminance, 256, 1}); @@ -772,24 +767,6 @@ void TwodeePass::transfer(Rhi& rhi, Handle ctx) data_->upload_default_tex = false; } - { - // TODO share palette tex with software pass - // Unfortunately, pMasterPalette must be swizzled to get a linear layout. - // Maybe some adjustments to palette storage can make this a straight upload. - std::array palette_32; - for (size_t i = 0; i < 256; i++) - { - palette_32[i] = pMasterPalette[i].s; - } - rhi.update_texture( - ctx, - data_->palette_tex, - {0, 0, 256, 1}, - rhi::PixelFormat::kRGBA8, - tcb::as_bytes(tcb::span(palette_32)) - ); - } - for (auto colormap : data_->colormaps_to_upload) { rhi.update_texture( @@ -821,6 +798,8 @@ void TwodeePass::transfer(Rhi& rhi, Handle ctx) } data_->patches_to_upload.clear(); + Handle palette_tex = palette_manager_->palette(); + // Update the buffers for each list auto ctx_list_itr = ctx_->begin(); for (size_t i = 0; i < cmd_lists_.size() && ctx_list_itr != ctx_->end(); i++) @@ -843,14 +822,14 @@ void TwodeePass::transfer(Rhi& rhi, Handle ctx) { Atlas& atlas = data_->patch_atlases[atlas_index]; tx[0] = {SamplerName::kSampler0, atlas.tex}; - tx[1] = {SamplerName::kSampler1, data_->palette_tex}; + tx[1] = {SamplerName::kSampler1, palette_tex}; }, [&](const MergedTwodeeCommandFlatTexture& tex) { Handle th = flat_manager_->find_indexed(tex.lump); SRB2_ASSERT(th != kNullHandle); tx[0] = {SamplerName::kSampler0, th}; - tx[1] = {SamplerName::kSampler1, data_->palette_tex}; + tx[1] = {SamplerName::kSampler1, palette_tex}; }}; if (mcmd.texture) { @@ -859,7 +838,7 @@ void TwodeePass::transfer(Rhi& rhi, Handle ctx) else { tx[0] = {SamplerName::kSampler0, data_->default_tex}; - tx[1] = {SamplerName::kSampler1, data_->palette_tex}; + tx[1] = {SamplerName::kSampler1, palette_tex}; } const uint8_t* colormap = mcmd.colormap; diff --git a/src/hwr2/pass_twodee.hpp b/src/hwr2/pass_twodee.hpp index da9c2b563..4edb495c2 100644 --- a/src/hwr2/pass_twodee.hpp +++ b/src/hwr2/pass_twodee.hpp @@ -76,6 +76,7 @@ struct TwodeePass final : public Pass std::variant, rhi::Handle> out_color_; std::shared_ptr data_; + std::shared_ptr palette_manager_; std::shared_ptr flat_manager_; rhi::Handle us_1; rhi::Handle us_2; diff --git a/src/i_video_common.cpp b/src/i_video_common.cpp index 844d86cdf..493faa821 100644 --- a/src/i_video_common.cpp +++ b/src/i_video_common.cpp @@ -158,9 +158,10 @@ static std::shared_ptr build_pass_manager() manager->insert( "2d_prepare", - [twodee, framebuffer_manager](PassManager& mgr, Rhi&) + [twodee, framebuffer_manager, palette_manager](PassManager& mgr, Rhi&) { twodee->output_ = framebuffer_manager->current_main_color(); + twodee->palette_manager_ = palette_manager; twodee->output_width_ = vid.width; twodee->output_height_ = vid.height; }