From 10df7ba3195e730059462c356664bd0118296007 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Thu, 23 May 2024 14:30:18 +1000 Subject: [PATCH] GPU/HW: Ensure CLUT cache is synced when using SW-for-readbacks --- src/core/gpu.cpp | 5 +++++ src/core/gpu.h | 1 + src/core/gpu_hw.cpp | 24 ++++++++++++++++++++---- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/core/gpu.cpp b/src/core/gpu.cpp index 14a3eebafa..8c61a88c55 100644 --- a/src/core/gpu.cpp +++ b/src/core/gpu.cpp @@ -1481,6 +1481,11 @@ void GPU::InvalidateCLUT() m_current_clut_is_8bit = false; } +bool GPU::IsCLUTValid() const +{ + return (m_current_clut_reg_bits != std::numeric_limits::max()); +} + void GPU::ClearDisplay() { ClearDisplayTexture(); diff --git a/src/core/gpu.h b/src/core/gpu.h index 1ee2c3b1fc..cede79e8eb 100644 --- a/src/core/gpu.h +++ b/src/core/gpu.h @@ -311,6 +311,7 @@ class GPU void HandleGetGPUInfoCommand(u32 value); void UpdateCLUTIfNeeded(GPUTextureMode texmode, GPUTexturePaletteReg clut); void InvalidateCLUT(); + bool IsCLUTValid() const; // Rendering in the backend virtual void ReadVRAM(u32 x, u32 y, u32 width, u32 height); diff --git a/src/core/gpu_hw.cpp b/src/core/gpu_hw.cpp index 45c4ff96ea..9dfd6252bc 100644 --- a/src/core/gpu_hw.cpp +++ b/src/core/gpu_hw.cpp @@ -2594,10 +2594,16 @@ void GPU_HW::UpdateSoftwareRenderer(bool copy_vram_from_hw) FlushRender(); ReadVRAM(0, 0, VRAM_WIDTH, VRAM_HEIGHT); - // Sync the drawing area. - GPUBackendSetDrawingAreaCommand* cmd = sw_renderer->NewSetDrawingAreaCommand(); - cmd->new_area = m_drawing_area; - sw_renderer->PushCommand(cmd); + // Sync the drawing area and CLUT. + GPUBackendSetDrawingAreaCommand* clip_cmd = sw_renderer->NewSetDrawingAreaCommand(); + clip_cmd->new_area = m_drawing_area; + sw_renderer->PushCommand(clip_cmd); + + GPUBackendUpdateCLUTCommand* clut_cmd = sw_renderer->NewUpdateCLUTCommand(); + FillBackendCommandParameters(clut_cmd); + clut_cmd->reg.bits = m_current_clut_reg_bits; + clut_cmd->clut_is_8bit = m_current_clut_is_8bit; + sw_renderer->PushCommand(clut_cmd); } m_sw_renderer = std::move(sw_renderer); @@ -3115,6 +3121,16 @@ void GPU_HW::UpdateCLUT(GPUTexturePaletteReg reg, bool clut_is_8bit) // Not done in HW GL_INS_FMT("Reloading CLUT from {},{}, {} not implemented", reg.GetXBase(), reg.GetYBase(), clut_is_8bit ? "8-bit" : "4-bit"); + + // But need to forward through to SW if using that for readbacks + if (m_sw_renderer) + { + GPUBackendUpdateCLUTCommand* cmd = m_sw_renderer->NewUpdateCLUTCommand(); + FillBackendCommandParameters(cmd); + cmd->reg.bits = reg.bits; + cmd->clut_is_8bit = clut_is_8bit; + m_sw_renderer->PushCommand(cmd); + } } void GPU_HW::FlushRender()