From a13f09433c87ace659d0e8edf713013d46e203e5 Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Sat, 30 Jul 2022 01:32:55 -0500 Subject: [PATCH] VideoBackends:Metal: Add config option to use presentDrawable --- Source/Core/Core/Config/GraphicsSettings.cpp | 2 ++ Source/Core/Core/Config/GraphicsSettings.h | 1 + Source/Core/VideoBackends/Metal/MTLRenderer.mm | 11 +++++++++-- Source/Core/VideoCommon/VideoConfig.cpp | 1 + Source/Core/VideoCommon/VideoConfig.h | 1 + 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Source/Core/Core/Config/GraphicsSettings.cpp b/Source/Core/Core/Config/GraphicsSettings.cpp index 204a7fc82a..5bc9599784 100644 --- a/Source/Core/Core/Config/GraphicsSettings.cpp +++ b/Source/Core/Core/Config/GraphicsSettings.cpp @@ -94,6 +94,8 @@ const Info GFX_SAVE_TEXTURE_CACHE_TO_STATE{ const Info GFX_MTL_MANUALLY_UPLOAD_BUFFERS{ {System::GFX, "Settings", "ManuallyUploadBuffers"}, TriState::Auto}; +const Info GFX_MTL_USE_PRESENT_DRAWABLE{{System::GFX, "Settings", "MTLUsePresentDrawable"}, + false}; const Info GFX_SW_DUMP_OBJECTS{{System::GFX, "Settings", "SWDumpObjects"}, false}; const Info GFX_SW_DUMP_TEV_STAGES{{System::GFX, "Settings", "SWDumpTevStages"}, false}; diff --git a/Source/Core/Core/Config/GraphicsSettings.h b/Source/Core/Core/Config/GraphicsSettings.h index b91f985289..4bdbb3b690 100644 --- a/Source/Core/Core/Config/GraphicsSettings.h +++ b/Source/Core/Core/Config/GraphicsSettings.h @@ -76,6 +76,7 @@ extern const Info GFX_SHADER_PRECOMPILER_THREADS; extern const Info GFX_SAVE_TEXTURE_CACHE_TO_STATE; extern const Info GFX_MTL_MANUALLY_UPLOAD_BUFFERS; +extern const Info GFX_MTL_USE_PRESENT_DRAWABLE; extern const Info GFX_SW_DUMP_OBJECTS; extern const Info GFX_SW_DUMP_TEV_STAGES; diff --git a/Source/Core/VideoBackends/Metal/MTLRenderer.mm b/Source/Core/VideoBackends/Metal/MTLRenderer.mm index dba0c58d22..7d6c583599 100644 --- a/Source/Core/VideoBackends/Metal/MTLRenderer.mm +++ b/Source/Core/VideoBackends/Metal/MTLRenderer.mm @@ -455,8 +455,15 @@ void Metal::Renderer::PresentBackbuffer() g_state_tracker->EndRenderPass(); if (m_drawable) { - [g_state_tracker->GetRenderCmdBuf() - addScheduledHandler:[drawable = std::move(m_drawable)](id) { [drawable present]; }]; + // PresentDrawable refuses to allow Dolphin to present faster than the display's refresh rate + // when windowed (or fullscreen with vsync enabled, but that's more understandable). + // On the other hand, it helps Xcode's GPU captures start and stop on frame boundaries + // which is convenient. Put it here as a default-off config, which we can override in Xcode. + if (g_ActiveConfig.bUsePresentDrawable) + [g_state_tracker->GetRenderCmdBuf() presentDrawable:m_drawable]; + else + [g_state_tracker->GetRenderCmdBuf() + addScheduledHandler:[drawable = std::move(m_drawable)](id) { [drawable present]; }]; m_bb_texture->SetMTLTexture(nullptr); m_drawable = nullptr; } diff --git a/Source/Core/VideoCommon/VideoConfig.cpp b/Source/Core/VideoCommon/VideoConfig.cpp index 845a59f05c..2411dca4f7 100644 --- a/Source/Core/VideoCommon/VideoConfig.cpp +++ b/Source/Core/VideoCommon/VideoConfig.cpp @@ -56,6 +56,7 @@ void VideoConfig::Refresh() bVSync = Config::Get(Config::GFX_VSYNC); iAdapter = Config::Get(Config::GFX_ADAPTER); iManuallyUploadBuffers = Config::Get(Config::GFX_MTL_MANUALLY_UPLOAD_BUFFERS); + bUsePresentDrawable = Config::Get(Config::GFX_MTL_USE_PRESENT_DRAWABLE); bWidescreenHack = Config::Get(Config::GFX_WIDESCREEN_HACK); aspect_mode = Config::Get(Config::GFX_ASPECT_RATIO); diff --git a/Source/Core/VideoCommon/VideoConfig.h b/Source/Core/VideoCommon/VideoConfig.h index f7477d6d3d..9664ad473c 100644 --- a/Source/Core/VideoCommon/VideoConfig.h +++ b/Source/Core/VideoCommon/VideoConfig.h @@ -157,6 +157,7 @@ struct VideoConfig final // Metal only config TriState iManuallyUploadBuffers = TriState::Auto; + bool bUsePresentDrawable = false; // Enable API validation layers, currently only supported with Vulkan. bool bEnableValidationLayer = false;