Skip to content

Commit

Permalink
GPU/HW: Download VRAM when enabling sw-for-readbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Dec 23, 2024
1 parent 8e254c4 commit 9a22ac3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/core/gpu_hw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,8 @@ void GPU_HW::UpdateSettings(const GPUSettings& old_settings)
// Need to reload CLUT if we're enabling SW rendering.
if (g_gpu_settings.gpu_use_software_renderer_for_readbacks && !old_settings.gpu_use_software_renderer_for_readbacks)
{
DownloadVRAMFromGPU(0, 0, VRAM_WIDTH, VRAM_HEIGHT);

if (m_draw_mode.mode_reg.texture_mode <= GPUTextureMode::Palette8Bit)
{
GPU_SW_Rasterizer::UpdateCLUT(m_draw_mode.palette_reg,
Expand Down Expand Up @@ -3094,9 +3096,9 @@ ALWAYS_INLINE float GPU_HW::GetCurrentNormalizedVertexDepth() const
void GPU_HW::FillVRAM(u32 x, u32 y, u32 width, u32 height, u32 color, bool interlaced_rendering, u8 active_line_lsb)
{
FlushRender();
DeactivateROV();

GL_SCOPE_FMT("FillVRAM({},{} => {},{} ({}x{}) with 0x{:08X}", x, y, x + width, y + height, width, height, color);
DeactivateROV();

GL_INS_FMT("Dirty draw area before: {}", m_vram_dirty_draw_rect);

Expand Down Expand Up @@ -3149,17 +3151,21 @@ void GPU_HW::FillVRAM(u32 x, u32 y, u32 width, u32 height, u32 color, bool inter

void GPU_HW::ReadVRAM(u32 x, u32 y, u32 width, u32 height)
{
FlushRender();

GL_PUSH_FMT("ReadVRAM({},{} => {},{} ({}x{})", x, y, x + width, y + height, width, height);
GL_SCOPE_FMT("ReadVRAM({},{} => {},{} ({}x{})", x, y, x + width, y + height, width, height);

if (ShouldDrawWithSoftwareRenderer())
{
GL_INS("VRAM is already up to date due to SW draws.");
GL_POP();
return;
}

DownloadVRAMFromGPU(x, y, width, height);
}

void GPU_HW::DownloadVRAMFromGPU(u32 x, u32 y, u32 width, u32 height)
{
FlushRender();

// TODO: Only read if it's in the drawn area

// Get bounds with wrap-around handled.
Expand Down
1 change: 1 addition & 0 deletions src/core/gpu_hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ class GPU_HW final : public GPUBackend
/// Returns true if the draw is going to use shader blending/framebuffer fetch.
bool NeedsShaderBlending(GPUTransparencyMode transparency, BatchTextureMode texture, bool check_mask) const;

void DownloadVRAMFromGPU(u32 x, u32 y, u32 width, u32 height);
void UpdateVRAMOnGPU(u32 x, u32 y, u32 width, u32 height, const void* data, u32 data_pitch, bool set_mask,
bool check_mask, const GSVector4i bounds);
bool BlitVRAMReplacementTexture(GPUTexture* tex, u32 dst_x, u32 dst_y, u32 width, u32 height);
Expand Down

0 comments on commit 9a22ac3

Please sign in to comment.