From 7d2431fa32358104866ee66eae15d8cb2e254086 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Tue, 11 Mar 2025 03:28:00 -0500 Subject: [PATCH] VideoConfig: Eliminate the widescreen hack adjustment values. --- Source/Core/VideoCommon/Present.cpp | 20 +++--------- .../Core/VideoCommon/VertexShaderManager.cpp | 32 +++++++++++++------ Source/Core/VideoCommon/VertexShaderManager.h | 6 +++- Source/Core/VideoCommon/VideoConfig.h | 2 -- 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/Source/Core/VideoCommon/Present.cpp b/Source/Core/VideoCommon/Present.cpp index 8f88c90588..a23352e16e 100644 --- a/Source/Core/VideoCommon/Present.cpp +++ b/Source/Core/VideoCommon/Present.cpp @@ -19,6 +19,7 @@ #include "VideoCommon/PostProcessing.h" #include "VideoCommon/Statistics.h" #include "VideoCommon/VertexManagerBase.h" +#include "VideoCommon/VertexShaderManager.h" #include "VideoCommon/VideoConfig.h" #include "VideoCommon/VideoEvents.h" #include "VideoCommon/Widescreen.h" @@ -622,8 +623,7 @@ void Presenter::UpdateDrawRectangle() const float draw_aspect_ratio = CalculateDrawAspectRatio(); // Update aspect ratio hack values - // Won't take effect until next frame - // Don't know if there is a better place for this code so there isn't a 1 frame delay + auto& system = Core::System::GetInstance(); if (g_ActiveConfig.bWidescreenHack) { const auto& vi = Core::System::GetInstance().GetVideoInterface(); @@ -634,24 +634,12 @@ void Presenter::UpdateDrawRectangle() source_aspect_ratio = SourceAspectRatioToWidescreen(source_aspect_ratio); const float adjust = source_aspect_ratio / draw_aspect_ratio; - if (adjust > 1) - { - // Vert+ - g_Config.fAspectRatioHackW = 1; - g_Config.fAspectRatioHackH = 1 / adjust; - } - else - { - // Hor+ - g_Config.fAspectRatioHackW = adjust; - g_Config.fAspectRatioHackH = 1; - } + system.GetVertexShaderManager().SetAspectRatioHack(adjust); } else { // Hack is disabled. - g_Config.fAspectRatioHackW = 1; - g_Config.fAspectRatioHackH = 1; + system.GetVertexShaderManager().SetAspectRatioHack(1.f); } // The rendering window size diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index bb3a7f2910..78cb91a2fa 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -8,15 +8,11 @@ #include #include -#include "Common/BitSet.h" #include "Common/ChunkFile.h" #include "Common/CommonTypes.h" -#include "Common/Config/Config.h" #include "Common/Logging/Log.h" #include "Common/Matrix.h" -#include "Core/Config/GraphicsSettings.h" -#include "Core/ConfigManager.h" -#include "Core/Core.h" + #include "VideoCommon/BPFunctions.h" #include "VideoCommon/BPMemory.h" #include "VideoCommon/CPMemory.h" @@ -25,7 +21,6 @@ #include "VideoCommon/GraphicsModSystem/Runtime/GraphicsModActionData.h" #include "VideoCommon/GraphicsModSystem/Runtime/GraphicsModManager.h" #include "VideoCommon/Statistics.h" -#include "VideoCommon/VertexLoaderManager.h" #include "VideoCommon/VertexManagerBase.h" #include "VideoCommon/VideoCommon.h" #include "VideoCommon/VideoConfig.h" @@ -43,9 +38,16 @@ void VertexShaderManager::Init() m_viewport_correction = Common::Matrix44::Identity(); m_projection_matrix = Common::Matrix44::Identity().data; + m_aspect_ratio_hack = 1.f; + dirty = true; } +void VertexShaderManager::SetAspectRatioHack(float adjustment) +{ + m_aspect_ratio_hack = adjustment; +} + Common::Matrix44 VertexShaderManager::LoadProjectionMatrix() { const auto& rawProjection = xfmem.projection.rawProjection; @@ -57,14 +59,24 @@ Common::Matrix44 VertexShaderManager::LoadProjectionMatrix() const Common::Vec2 fov_multiplier = g_freelook_camera.IsActive() ? g_freelook_camera.GetFieldOfViewMultiplier() : Common::Vec2{1, 1}; - m_projection_matrix[0] = rawProjection[0] * g_ActiveConfig.fAspectRatioHackW * fov_multiplier.x; + + // "Widescreen Hack": + float aspect_ratio_hack_w = m_aspect_ratio_hack.load(); + float aspect_ratio_hack_h = 1.f; + if (aspect_ratio_hack_w > 1) + { + aspect_ratio_hack_h = 1.f / aspect_ratio_hack_w; + aspect_ratio_hack_w = 1.f; + } + + m_projection_matrix[0] = rawProjection[0] * aspect_ratio_hack_w * fov_multiplier.x; m_projection_matrix[1] = 0.0f; - m_projection_matrix[2] = rawProjection[1] * g_ActiveConfig.fAspectRatioHackW * fov_multiplier.x; + m_projection_matrix[2] = rawProjection[1] * aspect_ratio_hack_w * fov_multiplier.x; m_projection_matrix[3] = 0.0f; m_projection_matrix[4] = 0.0f; - m_projection_matrix[5] = rawProjection[2] * g_ActiveConfig.fAspectRatioHackH * fov_multiplier.y; - m_projection_matrix[6] = rawProjection[3] * g_ActiveConfig.fAspectRatioHackH * fov_multiplier.y; + m_projection_matrix[5] = rawProjection[2] * aspect_ratio_hack_h * fov_multiplier.y; + m_projection_matrix[6] = rawProjection[3] * aspect_ratio_hack_h * fov_multiplier.y; m_projection_matrix[7] = 0.0f; m_projection_matrix[8] = 0.0f; diff --git a/Source/Core/VideoCommon/VertexShaderManager.h b/Source/Core/VideoCommon/VertexShaderManager.h index e4e158f54d..374e32a8d3 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.h +++ b/Source/Core/VideoCommon/VertexShaderManager.h @@ -4,10 +4,10 @@ #pragma once #include +#include #include #include -#include "Common/BitSet.h" #include "Common/CommonTypes.h" #include "Common/Matrix.h" #include "VideoCommon/ConstantManager.h" @@ -78,6 +78,8 @@ public: UpdateOffsets(&dirty, false, &constants.vertex_offset_normals, format.normals); } + void SetAspectRatioHack(float adjustment); + private: alignas(16) std::array m_projection_matrix; @@ -87,4 +89,6 @@ private: Common::Matrix44 m_viewport_correction{}; Common::Matrix44 LoadProjectionMatrix(); + + std::atomic m_aspect_ratio_hack = 1.f; }; diff --git a/Source/Core/VideoCommon/VideoConfig.h b/Source/Core/VideoCommon/VideoConfig.h index 9e7bf950a2..c9ad3fdb10 100644 --- a/Source/Core/VideoCommon/VideoConfig.h +++ b/Source/Core/VideoCommon/VideoConfig.h @@ -293,8 +293,6 @@ struct VideoConfig final bool bSkipPresentingDuplicateXFBs = false; bool bCopyEFBScaled = false; int iSafeTextureCache_ColorSamples = 0; - float fAspectRatioHackW = 1; // Initial value needed for the first frame - float fAspectRatioHackH = 1; bool bEnablePixelLighting = false; bool bFastDepthCalc = false; bool bVertexRounding = false;