Skip to content

Commit

Permalink
GPU/HW: Ensure CLUT cache is synced when using SW-for-readbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed May 23, 2024
1 parent 6cad97b commit 10df7ba
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/core/gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<decltype(m_current_clut_reg_bits)>::max());
}

void GPU::ClearDisplay()
{
ClearDisplayTexture();
Expand Down
1 change: 1 addition & 0 deletions src/core/gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 20 additions & 4 deletions src/core/gpu_hw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 10df7ba

Please sign in to comment.