summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon
diff options
context:
space:
mode:
authorJMC47 <JMC4789@gmail.com>2025-03-13 14:23:18 -0400
committerGitHub <noreply@github.com>2025-03-13 14:23:18 -0400
commit0e2785a5627872a8ae8c46180cdef8b7f0fde4de (patch)
treebc086371342195a595a0afd2ef8884d7394aa0b1 /Source/Core/VideoCommon
parenta421d6859f00d0912be1066f424b9d5f118f2208 (diff)
parent7222188cde8f1699e1384d3ec773928f7fb415e2 (diff)
Merge pull request #13387 from jordan-woyak/frame-pacing
CoreTiming: Improve frame pacing
Diffstat (limited to 'Source/Core/VideoCommon')
-rw-r--r--Source/Core/VideoCommon/AsyncRequests.cpp2
-rw-r--r--Source/Core/VideoCommon/AsyncRequests.h3
-rw-r--r--Source/Core/VideoCommon/Present.cpp13
-rw-r--r--Source/Core/VideoCommon/Present.h6
-rw-r--r--Source/Core/VideoCommon/VideoBackendBase.cpp2
5 files changed, 18 insertions, 8 deletions
diff --git a/Source/Core/VideoCommon/AsyncRequests.cpp b/Source/Core/VideoCommon/AsyncRequests.cpp
index e79ba51482..81b44ca042 100644
--- a/Source/Core/VideoCommon/AsyncRequests.cpp
+++ b/Source/Core/VideoCommon/AsyncRequests.cpp
@@ -125,7 +125,7 @@ void AsyncRequests::HandleEvent(const AsyncRequests::Event& e)
case Event::SWAP_EVENT:
g_presenter->ViSwap(e.swap_event.xfbAddr, e.swap_event.fbWidth, e.swap_event.fbStride,
- e.swap_event.fbHeight, e.time);
+ e.swap_event.fbHeight, e.time, e.swap_event.presentation_time);
break;
case Event::BBOX_READ:
diff --git a/Source/Core/VideoCommon/AsyncRequests.h b/Source/Core/VideoCommon/AsyncRequests.h
index 1df6d91f0a..74d73c6cca 100644
--- a/Source/Core/VideoCommon/AsyncRequests.h
+++ b/Source/Core/VideoCommon/AsyncRequests.h
@@ -18,6 +18,8 @@ class AsyncRequests
public:
struct Event
{
+ Event() {}
+
enum Type
{
EFB_POKE_COLOR,
@@ -54,6 +56,7 @@ public:
u32 fbWidth;
u32 fbStride;
u32 fbHeight;
+ TimePoint presentation_time;
} swap_event;
struct
diff --git a/Source/Core/VideoCommon/Present.cpp b/Source/Core/VideoCommon/Present.cpp
index 8f88c90588..1d1a77b4ca 100644
--- a/Source/Core/VideoCommon/Present.cpp
+++ b/Source/Core/VideoCommon/Present.cpp
@@ -5,6 +5,7 @@
#include "Common/ChunkFile.h"
#include "Core/Config/GraphicsSettings.h"
+#include "Core/CoreTiming.h"
#include "Core/HW/VideoInterface.h"
#include "Core/Host.h"
#include "Core/System.h"
@@ -17,7 +18,6 @@
#include "VideoCommon/FramebufferManager.h"
#include "VideoCommon/OnScreenUI.h"
#include "VideoCommon/PostProcessing.h"
-#include "VideoCommon/Statistics.h"
#include "VideoCommon/VertexManagerBase.h"
#include "VideoCommon/VideoConfig.h"
#include "VideoCommon/VideoEvents.h"
@@ -157,7 +157,8 @@ bool Presenter::FetchXFB(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_heigh
return old_xfb_id == m_last_xfb_id;
}
-void Presenter::ViSwap(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height, u64 ticks)
+void Presenter::ViSwap(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height, u64 ticks,
+ TimePoint presentation_time)
{
bool is_duplicate = FetchXFB(xfb_addr, fb_width, fb_stride, fb_height, ticks);
@@ -198,7 +199,7 @@ void Presenter::ViSwap(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height,
if (!is_duplicate || !g_ActiveConfig.bSkipPresentingDuplicateXFBs)
{
- Present();
+ Present(presentation_time);
ProcessFrameDumping(ticks);
AfterPresentEvent::Trigger(present_info);
@@ -814,7 +815,7 @@ void Presenter::RenderXFBToScreen(const MathUtil::Rectangle<int>& target_rc,
}
}
-void Presenter::Present()
+void Presenter::Present(std::optional<TimePoint> presentation_time)
{
m_present_count++;
@@ -867,6 +868,10 @@ void Presenter::Present()
// Present to the window system.
{
std::lock_guard<std::mutex> guard(m_swap_mutex);
+
+ if (presentation_time.has_value())
+ Core::System::GetInstance().GetCoreTiming().SleepUntil(*presentation_time);
+
g_gfx->PresentBackbuffer();
}
diff --git a/Source/Core/VideoCommon/Present.h b/Source/Core/VideoCommon/Present.h
index 3f8f43a687..a355af4385 100644
--- a/Source/Core/VideoCommon/Present.h
+++ b/Source/Core/VideoCommon/Present.h
@@ -14,7 +14,6 @@
#include <array>
#include <memory>
#include <mutex>
-#include <span>
#include <tuple>
class AbstractTexture;
@@ -36,10 +35,11 @@ public:
Presenter();
virtual ~Presenter();
- void ViSwap(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height, u64 ticks);
+ void ViSwap(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height, u64 ticks,
+ TimePoint presentation_time);
void ImmediateSwap(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height, u64 ticks);
- void Present();
+ void Present(std::optional<TimePoint> presentation_time = std::nullopt);
void ClearLastXfbId() { m_last_xfb_id = std::numeric_limits<u64>::max(); }
bool Initialize();
diff --git a/Source/Core/VideoCommon/VideoBackendBase.cpp b/Source/Core/VideoCommon/VideoBackendBase.cpp
index ba63b335de..8150120610 100644
--- a/Source/Core/VideoCommon/VideoBackendBase.cpp
+++ b/Source/Core/VideoCommon/VideoBackendBase.cpp
@@ -19,6 +19,7 @@
#include "Core/Config/MainSettings.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
+#include "Core/CoreTiming.h"
#include "Core/DolphinAnalytics.h"
#include "Core/System.h"
@@ -105,6 +106,7 @@ void VideoBackendBase::Video_OutputXFB(u32 xfb_addr, u32 fb_width, u32 fb_stride
e.swap_event.fbWidth = fb_width;
e.swap_event.fbStride = fb_stride;
e.swap_event.fbHeight = fb_height;
+ e.swap_event.presentation_time = system.GetCoreTiming().GetTargetHostTime(ticks);
AsyncRequests::GetInstance()->PushEvent(e, false);
}
}