From 4a2d3c83c77f71334bcb167621bcdde8f89efe87 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Sat, 18 Feb 2023 12:35:02 -0800 Subject: [PATCH 1/3] Software: Implement GetSurfaceInfo() Before, it used a fallback where it returned a default object, where the width and height were set to 0. Presenter::Initialize() used GetSurfaceInfo to set the backbuffer size, then used that size when initializing the on-screen UI (even for the software renderer, where the on-screen UI isn't currently present), which meant that ImGui got a window size of 0 and thus resulted in a failed assertion. Although BindBackbuffer checks for size changes, it doesn't help because ImGui has already been initialized, and the size hasn't actually changed since initialization occured. Fixes one aspect of https://bugs.dolphin-emu.org/issues/13172. --- Source/Core/VideoBackends/Null/NullGfx.h | 1 + Source/Core/VideoBackends/Software/SWGfx.cpp | 7 +++++++ Source/Core/VideoBackends/Software/SWGfx.h | 2 ++ Source/Core/VideoCommon/AbstractGfx.h | 2 +- 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Source/Core/VideoBackends/Null/NullGfx.h b/Source/Core/VideoBackends/Null/NullGfx.h index b1dff2bc2f..63b999b859 100644 --- a/Source/Core/VideoBackends/Null/NullGfx.h +++ b/Source/Core/VideoBackends/Null/NullGfx.h @@ -34,6 +34,7 @@ public: std::unique_ptr CreatePipeline(const AbstractPipelineConfig& config, const void* cache_data = nullptr, size_t cache_data_length = 0) override; + SurfaceInfo GetSurfaceInfo() const override { return {}; } }; class NullRenderer final : public Renderer diff --git a/Source/Core/VideoBackends/Software/SWGfx.cpp b/Source/Core/VideoBackends/Software/SWGfx.cpp index 4dfd5dc0f2..5837e19bf8 100644 --- a/Source/Core/VideoBackends/Software/SWGfx.cpp +++ b/Source/Core/VideoBackends/Software/SWGfx.cpp @@ -128,4 +128,11 @@ void SWGfx::SetScissorRect(const MathUtil::Rectangle& rc) Rasterizer::ScissorChanged(); } +SurfaceInfo SWGfx::GetSurfaceInfo() const +{ + GLContext* context = m_window->GetContext(); + return {std::max(context->GetBackBufferWidth(), 1u), std::max(context->GetBackBufferHeight(), 1u), + 1.0f, AbstractTextureFormat::RGBA8}; +} + } // namespace SW diff --git a/Source/Core/VideoBackends/Software/SWGfx.h b/Source/Core/VideoBackends/Software/SWGfx.h index 74ead3a323..6993c40882 100644 --- a/Source/Core/VideoBackends/Software/SWGfx.h +++ b/Source/Core/VideoBackends/Software/SWGfx.h @@ -49,6 +49,8 @@ public: void ClearRegion(const MathUtil::Rectangle& target_rc, bool colorEnable, bool alphaEnable, bool zEnable, u32 color, u32 z) override; + SurfaceInfo GetSurfaceInfo() const override; + private: std::unique_ptr m_window; }; diff --git a/Source/Core/VideoCommon/AbstractGfx.h b/Source/Core/VideoCommon/AbstractGfx.h index 916bcd4e11..ac51415806 100644 --- a/Source/Core/VideoCommon/AbstractGfx.h +++ b/Source/Core/VideoCommon/AbstractGfx.h @@ -161,7 +161,7 @@ public: bool UseGeometryShaderForUI() const; // Returns info about the main surface (aka backbuffer) - virtual SurfaceInfo GetSurfaceInfo() const { return {}; } + virtual SurfaceInfo GetSurfaceInfo() const = 0; protected: AbstractFramebuffer* m_current_framebuffer = nullptr; From 78428dd8db9e6711cb3bf77b7dc8c99998d8ba72 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Sat, 18 Feb 2023 12:28:15 -0800 Subject: [PATCH 2/3] Software: Fix crash on startup when using "Compile Shaders Before Starting" When that setting is enabled, m_xfb_entry is initially not present (during the phase where a shader compilation progress bar would be shown). The main path checks for m_xfb_entry, but the software renderer fallback path didn't. Fixes another aspect of https://bugs.dolphin-emu.org/issues/13172. --- Source/Core/VideoCommon/Present.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/Core/VideoCommon/Present.cpp b/Source/Core/VideoCommon/Present.cpp index 181dfea140..78e09de3e5 100644 --- a/Source/Core/VideoCommon/Present.cpp +++ b/Source/Core/VideoCommon/Present.cpp @@ -521,9 +521,10 @@ void Presenter::Present() if (!g_gfx->SupportsUtilityDrawing()) { - // Video Software doesn't support Drawing a UI or doing post-processing - // So just Show the XFB - g_gfx->ShowImage(m_xfb_entry->texture.get(), m_xfb_rect); + // Video Software doesn't support drawing a UI or doing post-processing + // So just show the XFB + if (m_xfb_entry) + g_gfx->ShowImage(m_xfb_entry->texture.get(), m_xfb_rect); return; } From 9cdc0aca9b599cd5626cba853b63dc99ce4a2213 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Sat, 18 Feb 2023 12:58:25 -0800 Subject: [PATCH 3/3] Software: Fix "Auto-Adjust Window Size" This also needs to be handled on the software renderer path. --- Source/Core/VideoCommon/Present.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Source/Core/VideoCommon/Present.cpp b/Source/Core/VideoCommon/Present.cpp index 78e09de3e5..25ec2f27b0 100644 --- a/Source/Core/VideoCommon/Present.cpp +++ b/Source/Core/VideoCommon/Present.cpp @@ -524,7 +524,13 @@ void Presenter::Present() // Video Software doesn't support drawing a UI or doing post-processing // So just show the XFB if (m_xfb_entry) + { g_gfx->ShowImage(m_xfb_entry->texture.get(), m_xfb_rect); + + // Update the window size based on the frame that was just rendered. + // Due to depending on guest state, we need to call this every frame. + SetWindowSize(m_xfb_rect.GetWidth(), m_xfb_rect.GetHeight()); + } return; }