From 176c55da252fcca05e2b862124adc0bd16ba3b0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 18 Oct 2025 15:15:32 +0200 Subject: [PATCH] Remove unused "interval" concept from presentation mode --- Common/GPU/D3D11/thin3d_d3d11.cpp | 6 +++--- Common/GPU/OpenGL/thin3d_gl.cpp | 4 ++-- Common/GPU/Vulkan/thin3d_vulkan.cpp | 7 ++----- Common/GPU/thin3d.cpp | 2 +- Common/GPU/thin3d.h | 9 ++++++--- Core/FrameTiming.cpp | 5 +---- Core/FrameTiming.h | 3 +-- Core/HLE/sceDisplay.cpp | 3 +-- GPU/Common/FramebufferManagerCommon.cpp | 1 + UI/DebugOverlay.cpp | 5 ++--- UI/NativeApp.cpp | 5 ++--- libretro/libretro.cpp | 2 +- 12 files changed, 23 insertions(+), 29 deletions(-) diff --git a/Common/GPU/D3D11/thin3d_d3d11.cpp b/Common/GPU/D3D11/thin3d_d3d11.cpp index c77ba6c629..fe0a7e6a92 100644 --- a/Common/GPU/D3D11/thin3d_d3d11.cpp +++ b/Common/GPU/D3D11/thin3d_d3d11.cpp @@ -160,7 +160,7 @@ public: void BeginFrame(DebugFlags debugFlags) override; void EndFrame() override; - void Present(PresentMode presentMode, int vblanks) override; + void Present(PresentMode presentMode) override; int GetFrameCount() override { return frameCount_; } @@ -478,12 +478,12 @@ void D3D11DrawContext::EndFrame() { curPipeline_ = nullptr; } -void D3D11DrawContext::Present(PresentMode presentMode, int vblanks) { +void D3D11DrawContext::Present(PresentMode presentMode) { frameTimeHistory_[frameCount_].queuePresent = time_now_d(); // Safety for libretro if (swapChain_) { - uint32_t interval = vblanks; + uint32_t interval = 1; uint32_t flags = 0; if (presentMode != PresentMode::FIFO) { interval = 0; diff --git a/Common/GPU/OpenGL/thin3d_gl.cpp b/Common/GPU/OpenGL/thin3d_gl.cpp index 3b027d192d..0b3debbba3 100644 --- a/Common/GPU/OpenGL/thin3d_gl.cpp +++ b/Common/GPU/OpenGL/thin3d_gl.cpp @@ -367,7 +367,7 @@ public: void BeginFrame(DebugFlags debugFlags) override; void EndFrame() override; - void Present(PresentMode mode, int vblanks) override; + void Present(PresentMode mode) override; int GetFrameCount() override { return frameCount_; @@ -811,7 +811,7 @@ void OpenGLContext::EndFrame() { Invalidate(InvalidationFlags::CACHED_RENDER_STATE); } -void OpenGLContext::Present(PresentMode presentMode, int vblanks) { +void OpenGLContext::Present(PresentMode presentMode) { renderManager_.Present(); frameCount_++; } diff --git a/Common/GPU/Vulkan/thin3d_vulkan.cpp b/Common/GPU/Vulkan/thin3d_vulkan.cpp index a417f52b38..007d6d937f 100644 --- a/Common/GPU/Vulkan/thin3d_vulkan.cpp +++ b/Common/GPU/Vulkan/thin3d_vulkan.cpp @@ -503,7 +503,7 @@ public: void BeginFrame(DebugFlags debugFlags) override; void EndFrame() override; - void Present(PresentMode presentMode, int vblanks) override; + void Present(PresentMode presentMode) override; int GetFrameCount() override { return frameCount_; @@ -1141,10 +1141,7 @@ void VKContext::EndFrame() { Invalidate(InvalidationFlags::CACHED_RENDER_STATE); } -void VKContext::Present(PresentMode presentMode, int vblanks) { - if (presentMode == PresentMode::FIFO) { - _dbg_assert_(vblanks == 0 || vblanks == 1); - } +void VKContext::Present(PresentMode presentMode) { renderManager_.Present(); frameCount_++; } diff --git a/Common/GPU/thin3d.cpp b/Common/GPU/thin3d.cpp index 1c1b749fba..cc4e5f6ca7 100644 --- a/Common/GPU/thin3d.cpp +++ b/Common/GPU/thin3d.cpp @@ -261,7 +261,7 @@ static const std::vector fsCol = { "float4 main(PS_INPUT input) : SV_Target {\n" " float4 col = input.color;\n" " col.rgb *= input.color.a;\n" - " return input.color;\n" + " return col;\n" "}\n" }, { ShaderLanguage::GLSL_VULKAN, diff --git a/Common/GPU/thin3d.h b/Common/GPU/thin3d.h index 3d0881421c..c836e386d2 100644 --- a/Common/GPU/thin3d.h +++ b/Common/GPU/thin3d.h @@ -587,6 +587,10 @@ enum class PresentMode { }; ENUM_CLASS_BITOPS(PresentMode); +inline bool PresentationModeBlocks(PresentMode mode) { + return mode & (PresentMode::FIFO | PresentMode::FIFO_RELAXED | PresentMode::FIFO_LATEST_READY); +} + struct DeviceCaps { GPUVendor vendor; uint32_t deviceID; // use caution! @@ -856,9 +860,8 @@ public: virtual void BeginFrame(DebugFlags debugFlags) = 0; virtual void EndFrame() = 0; - // vblanks is only relevant in FIFO present mode. - // NOTE: Not all backends support vblanks > 1. Some backends also can't change presentation mode immediately. - virtual void Present(PresentMode presentMode, int vblanks) = 0; + // Some backends also can't change presentation mode immediately. + virtual void Present(PresentMode presentMode) = 0; // This should be avoided as much as possible, in favor of clearing when binding a render target, which is native // on Vulkan. diff --git a/Core/FrameTiming.cpp b/Core/FrameTiming.cpp index b42c70f19a..a7fbfe9d01 100644 --- a/Core/FrameTiming.cpp +++ b/Core/FrameTiming.cpp @@ -67,10 +67,8 @@ inline Draw::PresentMode GetBestImmediateMode(Draw::PresentMode supportedModes) void FrameTiming::Reset(Draw::DrawContext *draw) { if (g_Config.bVSync || !(draw->GetDeviceCaps().presentModesSupported & (Draw::PresentMode::MAILBOX | Draw::PresentMode::IMMEDIATE))) { presentMode = Draw::PresentMode::FIFO; - presentInterval = 1; } else { presentMode = GetBestImmediateMode(draw->GetDeviceCaps().presentModesSupported); - presentInterval = 0; } } @@ -91,7 +89,7 @@ void FrameTiming::PostSubmit() { } } -Draw::PresentMode ComputePresentMode(Draw::DrawContext *draw, int *interval) { +Draw::PresentMode ComputePresentMode(Draw::DrawContext *draw) { _assert_(draw); Draw::PresentMode mode = Draw::PresentMode::FIFO; @@ -140,6 +138,5 @@ Draw::PresentMode ComputePresentMode(Draw::DrawContext *draw, int *interval) { } } - *interval = (mode == Draw::PresentMode::FIFO) ? 1 : 0; return mode; } diff --git a/Core/FrameTiming.h b/Core/FrameTiming.h index 1c535b37d0..b8ceaa2ab1 100644 --- a/Core/FrameTiming.h +++ b/Core/FrameTiming.h @@ -16,7 +16,6 @@ public: // Some backends won't allow changing this willy nilly. Draw::PresentMode presentMode; - int presentInterval; private: double waitUntil_; @@ -25,6 +24,6 @@ private: extern FrameTiming g_frameTiming; -Draw::PresentMode ComputePresentMode(Draw::DrawContext *draw, int *interval); +Draw::PresentMode ComputePresentMode(Draw::DrawContext *draw); void WaitUntil(double now, double timestamp, const char *reason); diff --git a/Core/HLE/sceDisplay.cpp b/Core/HLE/sceDisplay.cpp index c448f24a2f..72a74126d3 100644 --- a/Core/HLE/sceDisplay.cpp +++ b/Core/HLE/sceDisplay.cpp @@ -584,7 +584,7 @@ void __DisplayFlip(int cyclesLate) { Draw::DrawContext *draw = gpu->GetDrawContext(); if (draw) { - g_frameTiming.presentMode = ComputePresentMode(draw, &g_frameTiming.presentInterval); + g_frameTiming.presentMode = ComputePresentMode(draw); if (!draw->GetDeviceCaps().presentInstantModeChange && g_frameTiming.presentMode == Draw::PresentMode::FIFO) { // Some backends can't just flip into MAILBOX/IMMEDIATE mode instantly. // Vulkan doesn't support the interval setting, so we force skipping the flip. @@ -594,7 +594,6 @@ void __DisplayFlip(int cyclesLate) { } else { // Surely can never get here? g_frameTiming.presentMode = Draw::PresentMode::FIFO; - g_frameTiming.presentInterval = 1; } if (!g_Config.bSkipBufferEffects) { diff --git a/GPU/Common/FramebufferManagerCommon.cpp b/GPU/Common/FramebufferManagerCommon.cpp index 02c671621e..21fbe1cee0 100644 --- a/GPU/Common/FramebufferManagerCommon.cpp +++ b/GPU/Common/FramebufferManagerCommon.cpp @@ -3098,6 +3098,7 @@ bool GetOutputFramebuffer(Draw::DrawContext *draw, GPUDebugBuffer &buffer) { draw->GetFramebufferDimensions(nullptr, &w, &h); Draw::DataFormat fmt = draw->PreferredFramebufferReadbackFormat(nullptr); // Ignore preferred formats other than BGRA. + _dbg_assert_(fmt == Draw::DataFormat::B8G8R8A8_UNORM || fmt == Draw::DataFormat::R8G8B8A8_UNORM); if (fmt != Draw::DataFormat::B8G8R8A8_UNORM) fmt = Draw::DataFormat::R8G8B8A8_UNORM; diff --git a/UI/DebugOverlay.cpp b/UI/DebugOverlay.cpp index e59a8b8ebd..1243208d5f 100644 --- a/UI/DebugOverlay.cpp +++ b/UI/DebugOverlay.cpp @@ -138,9 +138,8 @@ static void DrawFrameTiming(UIContext *ctx, const Bounds &bounds) { // NOTE: This is not necessarily the same as the actual present mode. snprintf(statBuf, sizeof(statBuf), - "Timing mode (interval): %s (%d)", - Draw::PresentModeToString(g_frameTiming.presentMode), - g_frameTiming.presentInterval); + "Timing mode (interval): %s", + Draw::PresentModeToString(g_frameTiming.presentMode)); ctx->Draw()->DrawTextRect(ubuntu24, statBuf, bounds.x + 10, bounds.y + 50, bounds.w - 20, bounds.h - 30, 0xFFFFFFFF, FLAG_DYNAMIC_ASCII); diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 8238ff4ee9..b4a4f153b1 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -1206,9 +1206,8 @@ void NativeFrame(GraphicsContext *graphicsContext) { ClearFailedGPUBackends(); } - int interval; - Draw::PresentMode presentMode = ComputePresentMode(g_draw, &interval); - g_draw->Present(presentMode, interval); + Draw::PresentMode presentMode = ComputePresentMode(g_draw); + g_draw->Present(presentMode); if (resized) { INFO_LOG(Log::G3D, "Resized flag set - recalculating bounds"); diff --git a/libretro/libretro.cpp b/libretro/libretro.cpp index 19b4fc13db..b796f57906 100644 --- a/libretro/libretro.cpp +++ b/libretro/libretro.cpp @@ -1388,7 +1388,7 @@ namespace Libretro if (ctx->GetDrawContext()) { ctx->GetDrawContext()->EndFrame(); - ctx->GetDrawContext()->Present(Draw::PresentMode::FIFO, 1); + ctx->GetDrawContext()->Present(Draw::PresentMode::FIFO); } }