GPU: Feed buffer through SetDisplayTexture() on all paths

This commit is contained in:
Stenzek 2024-03-24 20:14:09 +10:00
parent 252861f071
commit ac1fcb4c93
No known key found for this signature in database
5 changed files with 39 additions and 39 deletions

View File

@ -1806,14 +1806,6 @@ void GPU::SetDisplayTexture(GPUTexture* texture, s32 view_x, s32 view_y, s32 vie
m_display_texture_view_height = view_height;
}
void GPU::SetDisplayTextureRect(s32 view_x, s32 view_y, s32 view_width, s32 view_height)
{
m_display_texture_view_x = view_x;
m_display_texture_view_y = view_y;
m_display_texture_view_width = view_width;
m_display_texture_view_height = view_height;
}
void GPU::SetDisplayParameters(s32 display_width, s32 display_height, s32 active_left, s32 active_top, s32 active_width,
s32 active_height, float display_aspect_ratio)
{
@ -1958,17 +1950,20 @@ void GPU::DestroyDeinterlaceTextures()
m_current_deinterlace_buffer = 0;
}
bool GPU::Deinterlace(GPUTexture* src, u32 x, u32 y, u32 width, u32 height, u32 field, u32 line_skip)
bool GPU::Deinterlace(u32 field, u32 line_skip)
{
GPUTexture* src = m_display_texture;
const u32 x = m_display_texture_view_x;
const u32 y = m_display_texture_view_y;
const u32 width = m_display_texture_view_width;
const u32 height = m_display_texture_view_height;
switch (g_settings.display_deinterlacing_mode)
{
case DisplayDeinterlacingMode::Disabled:
{
if (line_skip == 0)
{
SetDisplayTexture(src, x, y, width, height);
return true;
}
// Still have to extract the field.
if (!DeinterlaceExtractField(0, src, x, y, width, height, line_skip)) [[unlikely]]
@ -2138,8 +2133,12 @@ bool GPU::DeinterlaceSetTargetSize(u32 width, u32 height, bool preserve)
return true;
}
bool GPU::ApplyChromaSmoothing(GPUTexture* src, u32 x, u32 y, u32 width, u32 height)
bool GPU::ApplyChromaSmoothing()
{
const u32 x = m_display_texture_view_x;
const u32 y = m_display_texture_view_y;
const u32 width = m_display_texture_view_width;
const u32 height = m_display_texture_view_height;
if (!m_chroma_smoothing_texture || m_chroma_smoothing_texture->GetWidth() != width ||
m_chroma_smoothing_texture->GetHeight() != height)
{
@ -2155,11 +2154,11 @@ bool GPU::ApplyChromaSmoothing(GPUTexture* src, u32 x, u32 y, u32 width, u32 hei
GL_SCOPE_FMT("ApplyChromaSmoothing({{{},{}}}, {}x{})", x, y, width, height);
src->MakeReadyForSampling();
m_display_texture->MakeReadyForSampling();
g_gpu_device->InvalidateRenderTarget(m_chroma_smoothing_texture.get());
g_gpu_device->SetRenderTarget(m_chroma_smoothing_texture.get());
g_gpu_device->SetPipeline(m_chroma_smoothing_pipeline.get());
g_gpu_device->SetTextureSampler(0, src, g_gpu_device->GetNearestSampler());
g_gpu_device->SetTextureSampler(0, m_display_texture, g_gpu_device->GetNearestSampler());
const u32 uniforms[] = {x, y, width - 1, height - 1};
g_gpu_device->PushUniformBuffer(uniforms, sizeof(uniforms));
g_gpu_device->SetViewportAndScissor(0, 0, width, height);

View File

@ -570,7 +570,6 @@ protected:
void ClearDisplayTexture();
void SetDisplayTexture(GPUTexture* texture, s32 view_x, s32 view_y, s32 view_width, s32 view_height);
void SetDisplayTextureRect(s32 view_x, s32 view_y, s32 view_width, s32 view_height);
void SetDisplayParameters(s32 display_width, s32 display_height, s32 active_left, s32 active_top, s32 active_width,
s32 active_height, float display_aspect_ratio);
@ -580,11 +579,11 @@ protected:
bool RenderDisplay(GPUTexture* target, const Common::Rectangle<s32>& draw_rect, bool postfx);
bool Deinterlace(GPUTexture* src, u32 x, u32 y, u32 width, u32 height, u32 field, u32 line_skip);
bool Deinterlace(u32 field, u32 line_skip);
bool DeinterlaceExtractField(u32 dst_bufidx, GPUTexture* src, u32 x, u32 y, u32 width, u32 height, u32 line_skip);
bool DeinterlaceSetTargetSize(u32 width, u32 height, bool preserve);
void DestroyDeinterlaceTextures();
bool ApplyChromaSmoothing(GPUTexture* src, u32 x, u32 y, u32 width, u32 height);
bool ApplyChromaSmoothing();
s32 m_display_width = 0;
s32 m_display_height = 0;

View File

@ -3177,19 +3177,19 @@ void GPU_HW::UpdateDisplay()
(scaled_vram_offset_x + scaled_display_width) <= m_vram_texture->GetWidth() &&
(scaled_vram_offset_y + scaled_display_height) <= m_vram_texture->GetHeight())
{
SetDisplayTexture(m_vram_texture.get(), scaled_vram_offset_x, scaled_vram_offset_y, scaled_display_width,
read_height);
// Fast path if no copies are needed.
if (interlaced)
{
GL_INS("Deinterlace fast path");
drew_anything = true;
Deinterlace(m_vram_texture.get(), scaled_vram_offset_x, scaled_vram_offset_y, scaled_display_width, read_height,
interlaced_field, line_skip);
Deinterlace(interlaced_field, line_skip);
}
else
{
GL_INS("Direct display");
SetDisplayTexture(m_vram_texture.get(), scaled_vram_offset_x, scaled_vram_offset_y, scaled_display_width,
scaled_display_height);
}
}
else
@ -3223,28 +3223,26 @@ void GPU_HW::UpdateDisplay()
m_vram_extract_texture->MakeReadyForSampling();
drew_anything = true;
SetDisplayTexture(m_vram_extract_texture.get(), 0, 0, scaled_display_width, read_height);
if (g_settings.gpu_24bit_chroma_smoothing)
{
if (ApplyChromaSmoothing(m_vram_extract_texture.get(), 0, 0, scaled_display_width, read_height))
if (ApplyChromaSmoothing())
{
if (interlaced)
Deinterlace(m_display_texture, 0, 0, scaled_display_width, read_height, interlaced_field, 0);
Deinterlace(interlaced_field, 0);
}
}
else
{
if (interlaced)
Deinterlace(m_vram_extract_texture.get(), 0, 0, scaled_display_width, read_height, interlaced_field, 0);
else
SetDisplayTexture(m_vram_extract_texture.get(), 0, 0, scaled_display_width, read_height);
Deinterlace(interlaced_field, 0);
}
}
if (m_downsample_mode != GPUDownsampleMode::Disabled)
{
DebugAssert(m_display_texture);
DownsampleFramebuffer(m_display_texture, m_display_texture_view_x, m_display_texture_view_y,
m_display_texture_view_width, m_display_texture_view_height);
DownsampleFramebuffer();
}
if (drew_anything)
@ -3256,8 +3254,14 @@ void GPU_HW::OnBufferSwapped()
GL_INS("OnBufferSwapped()");
}
void GPU_HW::DownsampleFramebuffer(GPUTexture* source, u32 left, u32 top, u32 width, u32 height)
void GPU_HW::DownsampleFramebuffer()
{
GPUTexture* source = m_display_texture;
const u32 left = m_display_texture_view_x;
const u32 top = m_display_texture_view_y;
const u32 width = m_display_texture_view_width;
const u32 height = m_display_texture_view_height;
if (m_downsample_mode == GPUDownsampleMode::Adaptive)
DownsampleFramebufferAdaptive(source, left, top, width, height);
else
@ -3291,7 +3295,6 @@ void GPU_HW::DownsampleFramebufferAdaptive(GPUTexture* source, u32 left, u32 top
if (!m_downsample_texture || !level_texture || !weight_texture)
{
Log_ErrorFmt("Failed to create {}x{} RTs for adaptive downsampling", width, height);
SetDisplayTexture(source, left, top, width, height);
return;
}
@ -3401,7 +3404,6 @@ void GPU_HW::DownsampleFramebufferBoxFilter(GPUTexture* source, u32 left, u32 to
if (!m_downsample_texture)
{
Log_ErrorFmt("Failed to create {}x{} RT for box downsampling", width, height);
SetDisplayTexture(source, left, top, width, height);
return;
}

View File

@ -197,7 +197,7 @@ private:
/// Returns the number of mipmap levels used for adaptive smoothing.
u32 GetAdaptiveDownsamplingMipLevels() const;
void DownsampleFramebuffer(GPUTexture* source, u32 left, u32 top, u32 width, u32 height);
void DownsampleFramebuffer();
void DownsampleFramebufferAdaptive(GPUTexture* source, u32 left, u32 top, u32 width, u32 height);
void DownsampleFramebufferBoxFilter(GPUTexture* source, u32 left, u32 top, u32 width, u32 height);

View File

@ -490,14 +490,15 @@ void GPU_SW::UpdateDisplay()
const u32 line_skip = m_GPUSTAT.vertical_resolution;
if (CopyOut(vram_offset_x, vram_offset_y, skip_x, read_width, read_height, line_skip, is_24bit))
{
SetDisplayTexture(m_upload_texture.get(), 0, 0, read_width, read_height);
if (is_24bit && g_settings.gpu_24bit_chroma_smoothing)
{
if (ApplyChromaSmoothing(m_upload_texture.get(), 0, 0, read_width, read_height))
Deinterlace(m_display_texture, 0, 0, read_width, read_height, field, 0);
if (ApplyChromaSmoothing())
Deinterlace(field, 0);
}
else
{
Deinterlace(m_upload_texture.get(), 0, 0, read_width, read_height, field, 0);
Deinterlace(field, 0);
}
}
}
@ -505,10 +506,9 @@ void GPU_SW::UpdateDisplay()
{
if (CopyOut(vram_offset_x, vram_offset_y, skip_x, read_width, read_height, 0, is_24bit))
{
SetDisplayTexture(m_upload_texture.get(), 0, 0, read_width, read_height);
if (is_24bit && g_settings.gpu_24bit_chroma_smoothing)
ApplyChromaSmoothing(m_upload_texture.get(), 0, 0, read_width, read_height);
else
SetDisplayTexture(m_upload_texture.get(), 0, 0, read_width, read_height);
ApplyChromaSmoothing();
}
}
}