From 3ae78b8e762787a3114baeabec2dd0178562ed1c Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Tue, 31 Jan 2023 00:49:23 +1300 Subject: [PATCH] Also use events for config changed --- Source/Core/VideoBackends/D3D/D3DGfx.cpp | 2 ++ Source/Core/VideoBackends/D3D12/D3D12Gfx.cpp | 2 ++ Source/Core/VideoBackends/Metal/MTLGfx.mm | 2 ++ Source/Core/VideoBackends/OGL/OGLGfx.cpp | 2 ++ Source/Core/VideoBackends/Vulkan/VKGfx.cpp | 2 ++ Source/Core/VideoBackends/Vulkan/VKMain.cpp | 2 +- Source/Core/VideoCommon/AbstractGfx.cpp | 15 +++++++++++++ Source/Core/VideoCommon/AbstractGfx.h | 3 ++- Source/Core/VideoCommon/RenderBase.cpp | 3 +++ Source/Core/VideoCommon/VideoConfig.cpp | 22 +++++++++++--------- Source/Core/VideoCommon/VideoConfig.h | 4 +++- 11 files changed, 46 insertions(+), 13 deletions(-) diff --git a/Source/Core/VideoBackends/D3D/D3DGfx.cpp b/Source/Core/VideoBackends/D3D/D3DGfx.cpp index dc391f08b3..32dc21fb6a 100644 --- a/Source/Core/VideoBackends/D3D/D3DGfx.cpp +++ b/Source/Core/VideoBackends/D3D/D3DGfx.cpp @@ -169,6 +169,8 @@ void Gfx::PresentBackbuffer() void Gfx::OnConfigChanged(u32 bits) { + AbstractGfx::OnConfigChanged(bits); + // Quad-buffer changes require swap chain recreation. if (bits & CONFIG_CHANGE_BIT_STEREO_MODE && m_swap_chain) m_swap_chain->SetStereo(SwapChain::WantsStereo()); diff --git a/Source/Core/VideoBackends/D3D12/D3D12Gfx.cpp b/Source/Core/VideoBackends/D3D12/D3D12Gfx.cpp index ea9610ae34..68b0436134 100644 --- a/Source/Core/VideoBackends/D3D12/D3D12Gfx.cpp +++ b/Source/Core/VideoBackends/D3D12/D3D12Gfx.cpp @@ -437,6 +437,8 @@ SurfaceInfo Gfx::GetSurfaceInfo() const void Gfx::OnConfigChanged(u32 bits) { + AbstractGfx::OnConfigChanged(bits); + // For quad-buffered stereo we need to change the layer count, so recreate the swap chain. if (m_swap_chain && bits & CONFIG_CHANGE_BIT_STEREO_MODE) { diff --git a/Source/Core/VideoBackends/Metal/MTLGfx.mm b/Source/Core/VideoBackends/Metal/MTLGfx.mm index 2d44156102..f1e307d808 100644 --- a/Source/Core/VideoBackends/Metal/MTLGfx.mm +++ b/Source/Core/VideoBackends/Metal/MTLGfx.mm @@ -273,6 +273,8 @@ void Metal::Gfx::WaitForGPUIdle() void Metal::Gfx::OnConfigChanged(u32 bits) { + AbstractGfx::OnConfigChanged(bits); + if (bits & CONFIG_CHANGE_BIT_VSYNC) [m_layer setDisplaySyncEnabled:g_ActiveConfig.bVSyncActive]; diff --git a/Source/Core/VideoBackends/OGL/OGLGfx.cpp b/Source/Core/VideoBackends/OGL/OGLGfx.cpp index 88e544c235..ec0dd3181e 100644 --- a/Source/Core/VideoBackends/OGL/OGLGfx.cpp +++ b/Source/Core/VideoBackends/OGL/OGLGfx.cpp @@ -436,6 +436,8 @@ void OGLGfx::PresentBackbuffer() void OGLGfx::OnConfigChanged(u32 bits) { + AbstractGfx::OnConfigChanged(bits); + if (bits & CONFIG_CHANGE_BIT_VSYNC && !DriverDetails::HasBug(DriverDetails::BUG_BROKEN_VSYNC)) m_main_gl_context->SwapInterval(g_ActiveConfig.bVSyncActive); diff --git a/Source/Core/VideoBackends/Vulkan/VKGfx.cpp b/Source/Core/VideoBackends/Vulkan/VKGfx.cpp index f2aeaef0ca..35d6174cec 100644 --- a/Source/Core/VideoBackends/Vulkan/VKGfx.cpp +++ b/Source/Core/VideoBackends/Vulkan/VKGfx.cpp @@ -369,6 +369,8 @@ void VKGfx::CheckForSurfaceResize() void VKGfx::OnConfigChanged(u32 bits) { + AbstractGfx::OnConfigChanged(bits); + if (bits & CONFIG_CHANGE_BIT_HOST_CONFIG) g_object_cache->ReloadPipelineCache(); diff --git a/Source/Core/VideoBackends/Vulkan/VKMain.cpp b/Source/Core/VideoBackends/Vulkan/VKMain.cpp index 721887af7a..7521915897 100644 --- a/Source/Core/VideoBackends/Vulkan/VKMain.cpp +++ b/Source/Core/VideoBackends/Vulkan/VKMain.cpp @@ -239,7 +239,7 @@ bool VideoBackend::Initialize(const WindowSystemInfo& wsi) auto perf_query = std::make_unique(); auto bounding_box = std::make_unique(); - return !InitializeShared(std::move(gfx), std::move(vertex_manager), std::move(perf_query), + return InitializeShared(std::move(gfx), std::move(vertex_manager), std::move(perf_query), std::move(bounding_box)); } diff --git a/Source/Core/VideoCommon/AbstractGfx.cpp b/Source/Core/VideoCommon/AbstractGfx.cpp index 74fb12ddbf..6ec74210c9 100644 --- a/Source/Core/VideoCommon/AbstractGfx.cpp +++ b/Source/Core/VideoCommon/AbstractGfx.cpp @@ -16,6 +16,11 @@ std::unique_ptr g_gfx; +AbstractGfx::AbstractGfx() +{ + ConfigChangedEvent::Register([this](u32 bits) { OnConfigChanged(bits); }, "AbstractGfx"); +} + bool AbstractGfx::IsHeadless() const { return true; @@ -132,6 +137,16 @@ std::unique_ptr AbstractGfx::CreateAsyncShader return std::make_unique(); } +void AbstractGfx::OnConfigChanged(u32 changed_bits) +{ + // If there's any shader changes, wait for the GPU to finish before destroying anything. + if (changed_bits & (CONFIG_CHANGE_BIT_HOST_CONFIG | CONFIG_CHANGE_BIT_MULTISAMPLES)) + { + WaitForGPUIdle(); + SetPipeline(nullptr); + } +} + bool AbstractGfx::UseGeometryShaderForUI() const { // OpenGL doesn't render to a 2-layer backbuffer like D3D/Vulkan for quad-buffered stereo, diff --git a/Source/Core/VideoCommon/AbstractGfx.h b/Source/Core/VideoCommon/AbstractGfx.h index bdbcdc1001..be9708c12f 100644 --- a/Source/Core/VideoCommon/AbstractGfx.h +++ b/Source/Core/VideoCommon/AbstractGfx.h @@ -42,6 +42,7 @@ using ClearColor = std::array; class AbstractGfx { public: + AbstractGfx(); virtual ~AbstractGfx() = default; virtual bool IsHeadless() const = 0; @@ -149,7 +150,7 @@ public: virtual std::unique_ptr CreateAsyncShaderCompiler(); // Called when the configuration changes, and backend structures need to be updated. - virtual void OnConfigChanged(u32 bits) {} + virtual void OnConfigChanged(u32 changed_bits); // Returns true if a layer-expanding geometry shader should be used when rendering the user // interface and final XFB. diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp index 69555f9919..0e8bb41393 100644 --- a/Source/Core/VideoCommon/RenderBase.cpp +++ b/Source/Core/VideoCommon/RenderBase.cpp @@ -65,6 +65,9 @@ Renderer::Renderer() UpdateActiveConfig(); CalculateTargetSize(); UpdateWidescreen(); + + m_config_changed_handle = ConfigChangedEvent::Register([this](u32 bits) { OnConfigChanged(bits); }, "Renderer"); + // VertexManager doesn't maintain statistics in Wii mode. if (!SConfig::GetInstance().bWii) m_update_widescreen_handle = AfterFrameEvent::Register([this] { UpdateWidescreenHeuristic(); }, "WideScreen Heuristic"); diff --git a/Source/Core/VideoCommon/VideoConfig.cpp b/Source/Core/VideoCommon/VideoConfig.cpp index 86cfc97ade..7f710730bc 100644 --- a/Source/Core/VideoCommon/VideoConfig.cpp +++ b/Source/Core/VideoCommon/VideoConfig.cpp @@ -256,6 +256,9 @@ void CheckForConfigChanges() const u32 old_game_mod_changes = g_ActiveConfig.graphics_mod_config ? g_ActiveConfig.graphics_mod_config->GetChangeCount() : 0; const bool old_graphics_mods_enabled = g_ActiveConfig.bGraphicMods; + const AspectMode old_suggested_aspect_mode = g_ActiveConfig.suggested_aspect_mode; + const bool old_widescreen_hack = g_ActiveConfig.bWidescreenHack; + const auto old_post_processing_shader = g_ActiveConfig.sPostProcessingShader; UpdateActiveConfig(); FreeLook::UpdateActiveConfig(); @@ -301,22 +304,21 @@ void CheckForConfigChanges() changed_bits |= CONFIG_CHANGE_BIT_BBOX; if (g_renderer->CalculateTargetSize()) changed_bits |= CONFIG_CHANGE_BIT_TARGET_SIZE; - - g_presenter->CheckForConfigChanges(changed_bits); + if (old_suggested_aspect_mode != g_ActiveConfig.suggested_aspect_mode) + changed_bits |= CONFIG_CHANGE_BIT_ASPECT_RATIO; + if (old_widescreen_hack != g_ActiveConfig.bWidescreenHack) + changed_bits |= CONFIG_CHANGE_BIT_ASPECT_RATIO; + if (old_post_processing_shader != g_ActiveConfig.sPostProcessingShader) + changed_bits |= CONFIG_CHANGE_BIT_POST_PROCESSING_SHADER; // No changes? if (changed_bits == 0) return; - // Notify the backend of the changes, if any. - g_gfx->OnConfigChanged(changed_bits); + // Notify all listeners + ConfigChangedEvent::Trigger(changed_bits); - // If there's any shader changes, wait for the GPU to finish before destroying anything. - if (changed_bits & (CONFIG_CHANGE_BIT_HOST_CONFIG | CONFIG_CHANGE_BIT_MULTISAMPLES)) - { - g_gfx->WaitForGPUIdle(); - g_gfx->SetPipeline(nullptr); - } + // TODO: Move everything else to the ConfigChanged event // Framebuffer changed? if (changed_bits & (CONFIG_CHANGE_BIT_MULTISAMPLES | CONFIG_CHANGE_BIT_STEREO_MODE | diff --git a/Source/Core/VideoCommon/VideoConfig.h b/Source/Core/VideoCommon/VideoConfig.h index 2c05a6d4ae..c86ec647bc 100644 --- a/Source/Core/VideoCommon/VideoConfig.h +++ b/Source/Core/VideoCommon/VideoConfig.h @@ -70,7 +70,9 @@ enum ConfigChangeBits : u32 CONFIG_CHANGE_BIT_ANISOTROPY = (1 << 4), CONFIG_CHANGE_BIT_FORCE_TEXTURE_FILTERING = (1 << 5), CONFIG_CHANGE_BIT_VSYNC = (1 << 6), - CONFIG_CHANGE_BIT_BBOX = (1 << 7) + CONFIG_CHANGE_BIT_BBOX = (1 << 7), + CONFIG_CHANGE_BIT_ASPECT_RATIO = (1 << 8), + CONFIG_CHANGE_BIT_POST_PROCESSING_SHADER = (1 << 9), }; // NEVER inherit from this class.