From 0c3d55a1a1fbb54e5d5d8cd4f25e8aed2a0b7d04 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 2 Feb 2025 16:07:06 +1000 Subject: [PATCH] GPU: Fix incorrect PAR with overscan cropping --- src/core/gpu.cpp | 53 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/src/core/gpu.cpp b/src/core/gpu.cpp index 9ba437a60..2e3560db2 100644 --- a/src/core/gpu.cpp +++ b/src/core/gpu.cpp @@ -695,22 +695,49 @@ float GPU::ComputeAspectRatioCorrection() const const CRTCState& cs = m_crtc_state; float relative_width = static_cast(cs.horizontal_visible_end - cs.horizontal_visible_start); float relative_height = static_cast(cs.vertical_visible_end - cs.vertical_visible_start); - if (relative_width <= 0 || relative_height <= 0 || g_settings.display_aspect_ratio == DisplayAspectRatio::PAR1_1 || - g_settings.display_crop_mode == DisplayCropMode::OverscanUncorrected || - g_settings.display_crop_mode == DisplayCropMode::BordersUncorrected) - { + if (relative_width <= 0 || relative_height <= 0 || g_settings.display_aspect_ratio == DisplayAspectRatio::PAR1_1) return 1.0f; - } - if (m_GPUSTAT.pal_mode) + // Apply aspect ratio correction for all borders, or overscan with altered display range. + // That way if cropping is performed, the original aspect ratio is maintained. + switch (g_settings.display_crop_mode) { - relative_width /= static_cast(PAL_HORIZONTAL_ACTIVE_END - PAL_HORIZONTAL_ACTIVE_START); - relative_height /= static_cast(PAL_VERTICAL_ACTIVE_END - PAL_VERTICAL_ACTIVE_START); - } - else - { - relative_width /= static_cast(NTSC_HORIZONTAL_ACTIVE_END - NTSC_HORIZONTAL_ACTIVE_START); - relative_height /= static_cast(NTSC_VERTICAL_ACTIVE_END - NTSC_VERTICAL_ACTIVE_START); + case DisplayCropMode::Borders: + case DisplayCropMode::None: + { + if (m_GPUSTAT.pal_mode) + { + relative_width /= static_cast(PAL_HORIZONTAL_ACTIVE_END - PAL_HORIZONTAL_ACTIVE_START); + relative_height /= static_cast(PAL_VERTICAL_ACTIVE_END - PAL_VERTICAL_ACTIVE_START); + } + else + { + relative_width /= static_cast(NTSC_HORIZONTAL_ACTIVE_END - NTSC_HORIZONTAL_ACTIVE_START); + relative_height /= static_cast(NTSC_VERTICAL_ACTIVE_END - NTSC_VERTICAL_ACTIVE_START); + } + } + break; + + case DisplayCropMode::Overscan: + { + if (m_GPUSTAT.pal_mode) + { + relative_width /= static_cast(PAL_OVERSCAN_HORIZONTAL_ACTIVE_END - PAL_OVERSCAN_HORIZONTAL_ACTIVE_START); + relative_height /= static_cast(PAL_OVERSCAN_VERTICAL_ACTIVE_END - PAL_OVERSCAN_VERTICAL_ACTIVE_START); + } + else + { + relative_width /= + static_cast(NTSC_OVERSCAN_HORIZONTAL_ACTIVE_END - NTSC_OVERSCAN_HORIZONTAL_ACTIVE_START); + relative_height /= static_cast(NTSC_OVERSCAN_VERTICAL_ACTIVE_END - NTSC_OVERSCAN_VERTICAL_ACTIVE_START); + } + } + break; + + case DisplayCropMode::OverscanUncorrected: + case DisplayCropMode::BordersUncorrected: + default: + return 1.0f; } return (relative_width / relative_height);