From 53fb5cd9e1d44bc09eb2923e2198264e592ef176 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Mon, 28 Oct 2024 01:38:52 +1000 Subject: [PATCH] GTE: Remove dependency on GPUDevice --- src/core/gte.cpp | 13 +++-------- src/core/gte.h | 2 +- src/core/host.cpp | 46 +++++++++++---------------------------- src/core/system.cpp | 22 ++++++++++++++----- src/core/system.h | 7 ------ src/core/system_private.h | 7 ++++++ 6 files changed, 41 insertions(+), 56 deletions(-) diff --git a/src/core/gte.cpp b/src/core/gte.cpp index d9cc2b266..f6d340f41 100644 --- a/src/core/gte.cpp +++ b/src/core/gte.cpp @@ -8,7 +8,6 @@ #include "cpu_pgxp.h" #include "settings.h" -#include "util/gpu_device.h" #include "util/state_wrapper.h" #include "common/assert.h" @@ -228,7 +227,7 @@ bool GTE::DoState(StateWrapper& sw) return !sw.HasError(); } -void GTE::UpdateAspectRatio() +void GTE::UpdateAspectRatio(u32 window_width, u32 window_height) { if (!g_settings.gpu_widescreen_hack) { @@ -243,14 +242,8 @@ void GTE::UpdateAspectRatio() { case DisplayAspectRatio::MatchWindow: { - if (!g_gpu_device || !g_gpu_device->HasMainSwapChain()) - { - s_config.aspect_ratio = DisplayAspectRatio::R4_3; - return; - } - - num = g_gpu_device->GetMainSwapChain()->GetWidth(); - denom = g_gpu_device->GetMainSwapChain()->GetHeight(); + num = window_width; + denom = window_height; } break; diff --git a/src/core/gte.h b/src/core/gte.h index 334a0cd15..444b39c10 100644 --- a/src/core/gte.h +++ b/src/core/gte.h @@ -11,7 +11,7 @@ namespace GTE { void Initialize(); void Reset(); bool DoState(StateWrapper& sw); -void UpdateAspectRatio(); +void UpdateAspectRatio(u32 window_width, u32 window_height); // control registers are offset by +32 u32 ReadRegister(u32 index); diff --git a/src/core/host.cpp b/src/core/host.cpp index cfde8bcad..3d6335717 100644 --- a/src/core/host.cpp +++ b/src/core/host.cpp @@ -7,6 +7,7 @@ #include "imgui_overlays.h" #include "shader_cache_version.h" #include "system.h" +#include "system_private.h" #include "scmversion/scmversion.h" @@ -354,10 +355,8 @@ void Host::UpdateDisplayWindow(bool fullscreen) if (!g_gpu_device) return; - const GPUVSyncMode vsync_mode = - g_gpu_device->HasMainSwapChain() ? g_gpu_device->GetMainSwapChain()->GetVSyncMode() : GPUVSyncMode::Disabled; - const bool allow_present_throttle = - g_gpu_device->HasMainSwapChain() && g_gpu_device->GetMainSwapChain()->IsPresentThrottleAllowed(); + const GPUVSyncMode vsync_mode = System::GetEffectiveVSyncMode(); + const bool allow_present_throttle = System::ShouldAllowPresentThrottle(); std::optional fullscreen_mode; if (fullscreen && g_gpu_device->SupportsExclusiveFullscreen()) { @@ -394,21 +393,13 @@ void Host::UpdateDisplayWindow(bool fullscreen) return; } - const float f_width = static_cast(g_gpu_device->GetMainSwapChain()->GetWidth()); - const float f_height = static_cast(g_gpu_device->GetMainSwapChain()->GetHeight()); + const u32 new_width = g_gpu_device->GetMainSwapChain()->GetWidth(); + const u32 new_height = g_gpu_device->GetMainSwapChain()->GetHeight(); + const float f_width = static_cast(new_width); + const float f_height = static_cast(new_height); ImGuiManager::WindowResized(f_width, f_height); InputManager::SetDisplayWindowSize(f_width, f_height); - System::HostDisplayResized(); - - if (System::IsValid()) - { - // Fix up vsync etc. - System::UpdateSpeedLimiterState(); - - // If we're paused, re-present the current frame at the new window size. - if (System::IsPaused()) - System::InvalidateDisplay(); - } + System::DisplayWindowResized(new_width, new_height); } void Host::ResizeDisplayWindow(s32 width, s32 height, float scale) @@ -426,24 +417,13 @@ void Host::ResizeDisplayWindow(s32 width, s32 height, float scale) return; } - const float f_width = static_cast(g_gpu_device->GetMainSwapChain()->GetWidth()); - const float f_height = static_cast(g_gpu_device->GetMainSwapChain()->GetHeight()); + const u32 new_width = g_gpu_device->GetMainSwapChain()->GetWidth(); + const u32 new_height = g_gpu_device->GetMainSwapChain()->GetHeight(); + const float f_width = static_cast(new_width); + const float f_height = static_cast(new_height); ImGuiManager::WindowResized(f_width, f_height); InputManager::SetDisplayWindowSize(f_width, f_height); - - // If we're paused, re-present the current frame at the new window size. - if (System::IsValid()) - { - if (System::IsPaused()) - { - // Hackity hack, on some systems, presenting a single frame isn't enough to actually get it - // displayed. Two seems to be good enough. Maybe something to do with direct scanout. - System::InvalidateDisplay(); - System::InvalidateDisplay(); - } - - System::HostDisplayResized(); - } + System::DisplayWindowResized(new_width, new_height); } void Host::ReleaseGPUDevice() diff --git a/src/core/system.cpp b/src/core/system.cpp index 53b843ef3..82bfa3132 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -1898,7 +1898,8 @@ bool System::Initialize(std::unique_ptr disc, DiscRegion disc_region, b if (!CreateGPU(force_software_renderer ? GPURenderer::Software : g_settings.gpu_renderer, false, fullscreen, error)) return false; - GTE::UpdateAspectRatio(); + if (GPUSwapChain* swap_chain = g_gpu_device->GetMainSwapChain()) + GTE::UpdateAspectRatio(swap_chain->GetWidth(), swap_chain->GetHeight()); if (g_settings.gpu_pgxp_enable) CPU::PGXP::Initialize(); @@ -4347,7 +4348,8 @@ void System::CheckForSettingsChanges(const Settings& old_settings) (g_settings.display_aspect_ratio_custom_numerator != old_settings.display_aspect_ratio_custom_numerator || g_settings.display_aspect_ratio_custom_denominator != old_settings.display_aspect_ratio_custom_denominator))) { - GTE::UpdateAspectRatio(); + if (GPUSwapChain* swap_chain = g_gpu_device->GetMainSwapChain()) + GTE::UpdateAspectRatio(swap_chain->GetWidth(), swap_chain->GetHeight()); } if (g_settings.gpu_pgxp_enable != old_settings.gpu_pgxp_enable || @@ -5604,7 +5606,8 @@ void System::ToggleWidescreen() Settings::GetDisplayAspectRatioDisplayName(g_settings.display_aspect_ratio), 5.0f)); } - GTE::UpdateAspectRatio(); + if (GPUSwapChain* swap_chain = g_gpu_device->GetMainSwapChain()) + GTE::UpdateAspectRatio(swap_chain->GetWidth(), swap_chain->GetHeight()); } void System::ToggleSoftwareRendering() @@ -5650,16 +5653,25 @@ void System::RequestDisplaySize(float scale /*= 0.0f*/) Host::RequestResizeHostDisplay(static_cast(requested_width), static_cast(requested_height)); } -void System::HostDisplayResized() +void System::DisplayWindowResized(u32 width, u32 height) { if (!IsValid()) return; if (g_settings.gpu_widescreen_hack && g_settings.display_aspect_ratio == DisplayAspectRatio::MatchWindow) - GTE::UpdateAspectRatio(); + GTE::UpdateAspectRatio(width, height); g_gpu->RestoreDeviceContext(); g_gpu->UpdateResolutionScale(); + + // If we're paused, re-present the current frame at the new window size. + if (IsPaused()) + { + // Hackity hack, on some systems, presenting a single frame isn't enough to actually get it + // displayed. Two seems to be good enough. Maybe something to do with direct scanout. + InvalidateDisplay(); + InvalidateDisplay(); + } } bool System::PresentDisplay(bool explicit_present, u64 present_time) diff --git a/src/core/system.h b/src/core/system.h index 9ca246879..7f8fadc5a 100644 --- a/src/core/system.h +++ b/src/core/system.h @@ -397,10 +397,6 @@ void StopMediaCapture(); /// Toggle Widescreen Hack and Aspect Ratio void ToggleWidescreen(); -/// Returns true if vsync should be used. -GPUVSyncMode GetEffectiveVSyncMode(); -bool ShouldAllowPresentThrottle(); - /// Quick switch between software and hardware rendering. void ToggleSoftwareRendering(); @@ -408,9 +404,6 @@ void ToggleSoftwareRendering(); /// If the scale is set to 0, the internal resolution will be used, otherwise it is treated as a multiplier to 1x. void RequestDisplaySize(float scale = 0.0f); -/// Call when host display size changes, use with "match display" aspect ratio setting. -void HostDisplayResized(); - /// Renders the display. bool PresentDisplay(bool explicit_present, u64 present_time); void InvalidateDisplay(); diff --git a/src/core/system_private.h b/src/core/system_private.h index 7ba41e226..86fc9ab74 100644 --- a/src/core/system_private.h +++ b/src/core/system_private.h @@ -27,6 +27,13 @@ void IncrementFrameNumber(); void IncrementInternalFrameNumber(); void FrameDone(); +/// Returns true if vsync should be used. +GPUVSyncMode GetEffectiveVSyncMode(); +bool ShouldAllowPresentThrottle(); + +/// Call when host display size changes, use with "match display" aspect ratio setting. +void DisplayWindowResized(u32 width, u32 height); + /// Performs mandatory hardware checks. bool PerformEarlyHardwareChecks(Error* error);