summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon
diff options
context:
space:
mode:
authorJordan Woyak <jordan.woyak@gmail.com>2025-05-03 02:48:44 -0500
committerJordan Woyak <jordan.woyak@gmail.com>2025-11-02 17:30:43 -0600
commitf289b06e0db8bba6a3491d6e3cf0c2dd1b7a29fa (patch)
tree4e95a04a656f571e4dc0a7024348d22c5a1c662e /Source/Core/VideoCommon
parent9c28f19e56307ac4de750ffa6ffb8c4e15e55def (diff)
Common: Make HookableEvent use non-static data.
Co-authored-by: Dentomologist <dentomologist@gmail.com>
Diffstat (limited to 'Source/Core/VideoCommon')
-rw-r--r--Source/Core/VideoCommon/AbstractGfx.cpp4
-rw-r--r--Source/Core/VideoCommon/Assets/CustomResourceManager.cpp4
-rw-r--r--Source/Core/VideoCommon/BPStructs.cpp6
-rw-r--r--Source/Core/VideoCommon/FrameDumper.cpp4
-rw-r--r--Source/Core/VideoCommon/FramebufferManager.cpp4
-rw-r--r--Source/Core/VideoCommon/GraphicsModSystem/Runtime/CustomShaderCache.cpp4
-rw-r--r--Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModManager.cpp4
-rw-r--r--Source/Core/VideoCommon/Present.cpp18
-rw-r--r--Source/Core/VideoCommon/ShaderCache.cpp4
-rw-r--r--Source/Core/VideoCommon/Statistics.cpp36
-rw-r--r--Source/Core/VideoCommon/Statistics.h3
-rw-r--r--Source/Core/VideoCommon/TextureCacheBase.h4
-rw-r--r--Source/Core/VideoCommon/VertexManagerBase.cpp10
-rw-r--r--Source/Core/VideoCommon/VideoConfig.cpp14
-rw-r--r--Source/Core/VideoCommon/VideoConfig.h1
-rw-r--r--Source/Core/VideoCommon/VideoEvents.h62
-rw-r--r--Source/Core/VideoCommon/Widescreen.cpp8
17 files changed, 113 insertions, 77 deletions
diff --git a/Source/Core/VideoCommon/AbstractGfx.cpp b/Source/Core/VideoCommon/AbstractGfx.cpp
index 90b85ddfff..ca6ad881b1 100644
--- a/Source/Core/VideoCommon/AbstractGfx.cpp
+++ b/Source/Core/VideoCommon/AbstractGfx.cpp
@@ -18,8 +18,8 @@ std::unique_ptr<AbstractGfx> g_gfx;
AbstractGfx::AbstractGfx()
{
- m_config_changed =
- ConfigChangedEvent::Register([this](u32 bits) { OnConfigChanged(bits); }, "AbstractGfx");
+ m_config_changed = GetVideoEvents().config_changed_event.Register(
+ [this](u32 bits) { OnConfigChanged(bits); }, "AbstractGfx");
}
bool AbstractGfx::IsHeadless() const
diff --git a/Source/Core/VideoCommon/Assets/CustomResourceManager.cpp b/Source/Core/VideoCommon/Assets/CustomResourceManager.cpp
index f2af4ccbea..ac8199ef86 100644
--- a/Source/Core/VideoCommon/Assets/CustomResourceManager.cpp
+++ b/Source/Core/VideoCommon/Assets/CustomResourceManager.cpp
@@ -29,8 +29,8 @@ void CustomResourceManager::Initialize()
m_asset_loader.Initialize();
- m_xfb_event =
- AfterFrameEvent::Register([this](Core::System&) { XFBTriggered(); }, "CustomResourceManager");
+ m_xfb_event = GetVideoEvents().after_frame_event.Register(
+ [this](Core::System&) { XFBTriggered(); }, "CustomResourceManager");
}
void CustomResourceManager::Shutdown()
diff --git a/Source/Core/VideoCommon/BPStructs.cpp b/Source/Core/VideoCommon/BPStructs.cpp
index dd0cd59570..1ece9f278e 100644
--- a/Source/Core/VideoCommon/BPStructs.cpp
+++ b/Source/Core/VideoCommon/BPStructs.cpp
@@ -4,7 +4,6 @@
#include "VideoCommon/BPStructs.h"
#include <algorithm>
-#include <cmath>
#include <cstring>
#include <string>
@@ -341,6 +340,8 @@ static void BPWritten(PixelShaderManager& pixel_shader_manager, XFStateManager&
false, false, yScale, s_gammaLUT[PE_copy.gamma], bpmem.triggerEFBCopy.clamp_top,
bpmem.triggerEFBCopy.clamp_bottom, bpmem.copyfilter.GetCoefficients());
+ auto& system = Core::System::GetInstance();
+
// This is as closest as we have to an "end of the frame"
// It works 99% of the time.
// But sometimes games want to render an XFB larger than the EFB's 640x528 pixel resolution
@@ -348,7 +349,7 @@ static void BPWritten(PixelShaderManager& pixel_shader_manager, XFStateManager&
// render multiple sub-frames and arrange the XFB copies in next to each-other in main memory
// so they form a single completed XFB.
// See https://dolphin-emu.org/blog/2017/11/19/hybridxfb/ for examples and more detail.
- AfterFrameEvent::Trigger(Core::System::GetInstance());
+ system.GetVideoEvents().after_frame_event.Trigger(system);
// Note: Theoretically, in the future we could track the VI configuration and try to detect
// when an XFB is the last XFB copy of a frame. Not only would we get a clean "end of
@@ -356,7 +357,6 @@ static void BPWritten(PixelShaderManager& pixel_shader_manager, XFStateManager&
// Might also clean up some issues with games doing XFB copies they don't intend to
// display.
- auto& system = Core::System::GetInstance();
if (g_ActiveConfig.bImmediateXFB)
{
// TODO: GetTicks is not sane from the GPU thread.
diff --git a/Source/Core/VideoCommon/FrameDumper.cpp b/Source/Core/VideoCommon/FrameDumper.cpp
index c98141e8eb..f39424805c 100644
--- a/Source/Core/VideoCommon/FrameDumper.cpp
+++ b/Source/Core/VideoCommon/FrameDumper.cpp
@@ -29,8 +29,8 @@ static bool DumpFrameToPNG(const FrameData& frame, const std::string& file_name)
FrameDumper::FrameDumper()
{
- m_frame_end_handle =
- AfterFrameEvent::Register([this](Core::System&) { FlushFrameDump(); }, "FrameDumper");
+ m_frame_end_handle = GetVideoEvents().after_frame_event.Register(
+ [this](Core::System&) { FlushFrameDump(); }, "FrameDumper");
}
FrameDumper::~FrameDumper()
diff --git a/Source/Core/VideoCommon/FramebufferManager.cpp b/Source/Core/VideoCommon/FramebufferManager.cpp
index 5a3c768311..fc514811d5 100644
--- a/Source/Core/VideoCommon/FramebufferManager.cpp
+++ b/Source/Core/VideoCommon/FramebufferManager.cpp
@@ -84,8 +84,8 @@ bool FramebufferManager::Initialize()
return false;
}
- m_end_of_frame_event =
- AfterFrameEvent::Register([this](Core::System&) { EndOfFrame(); }, "FramebufferManager");
+ m_end_of_frame_event = GetVideoEvents().after_frame_event.Register(
+ [this](Core::System&) { EndOfFrame(); }, "FramebufferManager");
return true;
}
diff --git a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/CustomShaderCache.cpp b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/CustomShaderCache.cpp
index a0dca15d38..0bf8e844ec 100644
--- a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/CustomShaderCache.cpp
+++ b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/CustomShaderCache.cpp
@@ -17,8 +17,8 @@ CustomShaderCache::CustomShaderCache()
m_async_uber_shader_compiler = g_gfx->CreateAsyncShaderCompiler();
m_async_uber_shader_compiler->StartWorkerThreads(1); // TODO
- m_frame_end_handler = AfterFrameEvent::Register([this](Core::System&) { RetrieveAsyncShaders(); },
- "RetrieveAsyncShaders");
+ m_frame_end_handler = GetVideoEvents().after_frame_event.Register(
+ [this](Core::System&) { RetrieveAsyncShaders(); }, "RetrieveAsyncShaders");
}
CustomShaderCache::~CustomShaderCache()
diff --git a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModManager.cpp b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModManager.cpp
index 70d3a9a5ca..6a523c61a2 100644
--- a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModManager.cpp
+++ b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModManager.cpp
@@ -95,8 +95,8 @@ bool GraphicsModManager::Initialize()
g_ActiveConfig.graphics_mod_config->SetChangeCount(old_game_mod_changes);
g_graphics_mod_manager->Load(*g_ActiveConfig.graphics_mod_config);
- m_end_of_frame_event =
- AfterFrameEvent::Register([this](Core::System&) { EndOfFrame(); }, "ModManager");
+ m_end_of_frame_event = GetVideoEvents().after_frame_event.Register(
+ [this](Core::System&) { EndOfFrame(); }, "ModManager");
}
return true;
diff --git a/Source/Core/VideoCommon/Present.cpp b/Source/Core/VideoCommon/Present.cpp
index 43f1c8140f..24c767cc69 100644
--- a/Source/Core/VideoCommon/Present.cpp
+++ b/Source/Core/VideoCommon/Present.cpp
@@ -94,8 +94,8 @@ static void TryToSnapToXFBSize(int& width, int& height, int xfb_width, int xfb_h
Presenter::Presenter()
{
- m_config_changed =
- ConfigChangedEvent::Register([this](u32 bits) { ConfigChanged(bits); }, "Presenter");
+ m_config_changed = GetVideoEvents().config_changed_event.Register(
+ [this](u32 bits) { ConfigChanged(bits); }, "Presenter");
}
Presenter::~Presenter()
@@ -195,14 +195,16 @@ void Presenter::ViSwap(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height,
}
}
- BeforePresentEvent::Trigger(present_info);
+ auto& video_events = GetVideoEvents();
+
+ video_events.before_present_event.Trigger(present_info);
if (!is_duplicate || !g_ActiveConfig.bSkipPresentingDuplicateXFBs)
{
Present(presentation_time);
ProcessFrameDumping(ticks);
- AfterPresentEvent::Trigger(present_info);
+ video_events.after_present_event.Trigger(present_info);
}
}
@@ -216,12 +218,14 @@ void Presenter::ImmediateSwap(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_
present_info.reason = PresentInfo::PresentReason::Immediate;
present_info.present_count = m_present_count++;
- BeforePresentEvent::Trigger(present_info);
+ auto& video_events = GetVideoEvents();
+
+ video_events.before_present_event.Trigger(present_info);
Present();
ProcessFrameDumping(ticks);
- AfterPresentEvent::Trigger(present_info);
+ video_events.after_present_event.Trigger(present_info);
}
void Presenter::ProcessFrameDumping(u64 ticks) const
@@ -925,7 +929,7 @@ void Presenter::DoState(PointerWrap& p)
if (p.IsReadMode() && m_last_xfb_stride != 0)
{
// This technically counts as the end of the frame
- AfterFrameEvent::Trigger(Core::System::GetInstance());
+ GetVideoEvents().after_frame_event.Trigger(Core::System::GetInstance());
ImmediateSwap(m_last_xfb_addr, m_last_xfb_width, m_last_xfb_stride, m_last_xfb_height,
m_last_xfb_ticks);
diff --git a/Source/Core/VideoCommon/ShaderCache.cpp b/Source/Core/VideoCommon/ShaderCache.cpp
index 44868808dd..fbed022aa5 100644
--- a/Source/Core/VideoCommon/ShaderCache.cpp
+++ b/Source/Core/VideoCommon/ShaderCache.cpp
@@ -46,8 +46,8 @@ bool ShaderCache::Initialize()
return false;
m_async_shader_compiler = g_gfx->CreateAsyncShaderCompiler();
- m_frame_end_handler = AfterFrameEvent::Register([this](Core::System&) { RetrieveAsyncShaders(); },
- "RetrieveAsyncShaders");
+ m_frame_end_handler = GetVideoEvents().after_frame_event.Register(
+ [this](Core::System&) { RetrieveAsyncShaders(); }, "RetrieveAsyncShaders");
return true;
}
diff --git a/Source/Core/VideoCommon/Statistics.cpp b/Source/Core/VideoCommon/Statistics.cpp
index db098db5c7..97c9264d18 100644
--- a/Source/Core/VideoCommon/Statistics.cpp
+++ b/Source/Core/VideoCommon/Statistics.cpp
@@ -20,18 +20,8 @@
Statistics g_stats;
-static Common::EventHook s_before_frame_event =
- BeforeFrameEvent::Register([] { g_stats.ResetFrame(); }, "Statistics::ResetFrame");
-
-static Common::EventHook s_after_frame_event = AfterFrameEvent::Register(
- [](const Core::System& system) {
- DolphinAnalytics::Instance().ReportPerformanceInfo({
- .speed_ratio = system.GetSystemTimers().GetEstimatedEmulationPerformance(),
- .num_prims = g_stats.this_frame.num_prims + g_stats.this_frame.num_dl_prims,
- .num_draw_calls = g_stats.this_frame.num_draw_calls,
- });
- },
- "Statistics::PerformanceSample");
+static Common::EventHook s_before_frame_event;
+static Common::EventHook s_after_frame_event;
static bool clear_scissors;
@@ -507,3 +497,25 @@ void Statistics::DisplayScissor()
ImGui::End();
}
+
+void Statistics::Init()
+{
+ s_before_frame_event = GetVideoEvents().before_frame_event.Register([] { g_stats.ResetFrame(); },
+ "Statistics::ResetFrame");
+
+ s_after_frame_event = GetVideoEvents().after_frame_event.Register(
+ [](const Core::System& system) {
+ DolphinAnalytics::Instance().ReportPerformanceInfo({
+ .speed_ratio = system.GetSystemTimers().GetEstimatedEmulationPerformance(),
+ .num_prims = g_stats.this_frame.num_prims + g_stats.this_frame.num_dl_prims,
+ .num_draw_calls = g_stats.this_frame.num_draw_calls,
+ });
+ },
+ "Statistics::PerformanceSample");
+}
+
+void Statistics::Shutdown()
+{
+ s_before_frame_event.reset();
+ s_after_frame_event.reset();
+}
diff --git a/Source/Core/VideoCommon/Statistics.h b/Source/Core/VideoCommon/Statistics.h
index 7d4b367ead..8b80d0f439 100644
--- a/Source/Core/VideoCommon/Statistics.h
+++ b/Source/Core/VideoCommon/Statistics.h
@@ -87,6 +87,9 @@ struct Statistics
void Display() const;
void DisplayProj() const;
void DisplayScissor();
+
+ static void Init();
+ static void Shutdown();
};
extern Statistics g_stats;
diff --git a/Source/Core/VideoCommon/TextureCacheBase.h b/Source/Core/VideoCommon/TextureCacheBase.h
index dd6cb46368..ee27c3e80b 100644
--- a/Source/Core/VideoCommon/TextureCacheBase.h
+++ b/Source/Core/VideoCommon/TextureCacheBase.h
@@ -463,8 +463,8 @@ private:
void OnFrameEnd();
- Common::EventHook m_frame_event =
- AfterFrameEvent::Register([this](Core::System&) { OnFrameEnd(); }, "TextureCache");
+ Common::EventHook m_frame_event = GetVideoEvents().after_frame_event.Register(
+ [this](Core::System&) { OnFrameEnd(); }, "TextureCache");
VideoCommon::TextureUtils::TextureDumper m_texture_dumper;
};
diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp
index 1797cb559f..1af9ad8eb4 100644
--- a/Source/Core/VideoCommon/VertexManagerBase.cpp
+++ b/Source/Core/VideoCommon/VertexManagerBase.cpp
@@ -118,9 +118,11 @@ VertexManagerBase::~VertexManagerBase() = default;
bool VertexManagerBase::Initialize()
{
- m_frame_end_event =
- AfterFrameEvent::Register([this](Core::System&) { OnEndFrame(); }, "VertexManagerBase");
- m_after_present_event = AfterPresentEvent::Register(
+ auto& video_events = GetVideoEvents();
+
+ m_frame_end_event = video_events.after_frame_event.Register(
+ [this](Core::System&) { OnEndFrame(); }, "VertexManagerBase");
+ m_after_present_event = video_events.after_present_event.Register(
[this](const PresentInfo& pi) { m_ticks_elapsed = pi.emulated_timestamp; },
"VertexManagerBase");
m_index_generator.Init();
@@ -442,7 +444,7 @@ void VertexManagerBase::Flush()
if (m_draw_counter == 0)
{
// This is more or less the start of the Frame
- BeforeFrameEvent::Trigger();
+ GetVideoEvents().before_frame_event.Trigger();
}
if (xfmem.numTexGen.numTexGens != bpmem.genMode.numtexgens ||
diff --git a/Source/Core/VideoCommon/VideoConfig.cpp b/Source/Core/VideoCommon/VideoConfig.cpp
index 0214dab9dd..63d061e684 100644
--- a/Source/Core/VideoCommon/VideoConfig.cpp
+++ b/Source/Core/VideoCommon/VideoConfig.cpp
@@ -38,6 +38,7 @@ VideoConfig g_ActiveConfig;
BackendInfo g_backend_info;
static std::optional<CPUThreadConfigCallback::ConfigChangedCallbackID>
s_config_changed_callback_id = std::nullopt;
+static Common::EventHook s_check_config_event;
static bool IsVSyncActive(bool enabled)
{
@@ -218,8 +219,16 @@ void VideoConfig::VerifyValidity()
}
}
+void VideoConfig::Init()
+{
+ s_check_config_event = GetVideoEvents().after_frame_event.Register(
+ [](Core::System&) { CheckForConfigChanges(); }, "CheckForConfigChanges");
+}
+
void VideoConfig::Shutdown()
{
+ s_check_config_event.reset();
+
if (!s_config_changed_callback_id.has_value())
return;
@@ -390,10 +399,7 @@ void CheckForConfigChanges()
}
// Notify all listeners
- ConfigChangedEvent::Trigger(changed_bits);
+ GetVideoEvents().config_changed_event.Trigger(changed_bits);
// TODO: Move everything else to the ConfigChanged event
}
-
-static Common::EventHook s_check_config_event = AfterFrameEvent::Register(
- [](Core::System&) { CheckForConfigChanges(); }, "CheckForConfigChanges");
diff --git a/Source/Core/VideoCommon/VideoConfig.h b/Source/Core/VideoCommon/VideoConfig.h
index a0baaa666c..e42b8e5d85 100644
--- a/Source/Core/VideoCommon/VideoConfig.h
+++ b/Source/Core/VideoCommon/VideoConfig.h
@@ -191,6 +191,7 @@ struct VideoConfig final
VideoConfig() = default;
void Refresh();
void VerifyValidity();
+ static void Init();
static void Shutdown();
// General
diff --git a/Source/Core/VideoCommon/VideoEvents.h b/Source/Core/VideoCommon/VideoEvents.h
index 9c763dce34..f8f29db589 100644
--- a/Source/Core/VideoCommon/VideoEvents.h
+++ b/Source/Core/VideoCommon/VideoEvents.h
@@ -14,18 +14,6 @@ namespace Core
class System;
}
-// Called when certain video config setting are changed
-using ConfigChangedEvent = Common::HookableEvent<"ConfigChanged", u32>;
-
-// An event called just before the first draw call of a frame
-using BeforeFrameEvent = Common::HookableEvent<"BeforeFrame">;
-
-// An event called after the frame XFB copy begins processing on the host GPU.
-// Useful for "once per frame" usecases.
-// Note: In a few rare cases, games do multiple XFB copies per frame and join them while presenting.
-// If this matters to your usecase, you should use BeforePresent instead.
-using AfterFrameEvent = Common::HookableEvent<"AfterFrame", Core::System&>;
-
struct PresentInfo
{
enum class PresentReason
@@ -78,19 +66,37 @@ struct PresentInfo
std::vector<std::string_view> xfb_copy_hashes;
};
-// An event called just as a frame is queued for presentation.
-// The exact timing of this event depends on the "Immediately Present XFB" option.
-//
-// If enabled, this event will trigger immediately after AfterFrame
-// If disabled, this event won't trigger until the emulated interface starts drawing out a new
-// frame.
-//
-// frame_count: The number of frames
-using BeforePresentEvent = Common::HookableEvent<"BeforePresent", PresentInfo&>;
-
-// An event that is triggered after a frame is presented.
-// The exact timing of this event depends on backend/driver support.
-using AfterPresentEvent = Common::HookableEvent<"AfterPresent", PresentInfo&>;
-
-// An end of frame event that runs on the CPU thread
-using VIEndFieldEvent = Common::HookableEvent<"VIEndField">;
+struct VideoEvents
+{
+ // Called when certain video config setting are changed
+ Common::HookableEvent<u32> config_changed_event{"ConfigChanged"};
+
+ // An event called just before the first draw call of a frame
+ Common::HookableEvent<> before_frame_event{"BeforeFrame"};
+
+ // An event called after the frame XFB copy begins processing on the host GPU.
+ // Useful for "once per frame" usecases.
+ // Note: In a few rare cases, games do multiple XFB copies per frame and join them while
+ // presenting.
+ // If this matters to your usecase, you should use BeforePresent instead.
+ Common::HookableEvent<Core::System&> after_frame_event{"AfterFrame"};
+
+ // An event called just as a frame is queued for presentation.
+ // The exact timing of this event depends on the "Immediately Present XFB" option.
+ //
+ // If enabled, this event will trigger immediately after AfterFrame
+ // If disabled, this event won't trigger until the emulated interface starts drawing out a new
+ // frame.
+ //
+ // frame_count: The number of frames
+ Common::HookableEvent<PresentInfo&> before_present_event{"BeforePresent"};
+
+ // An event that is triggered after a frame is presented.
+ // The exact timing of this event depends on backend/driver support.
+ Common::HookableEvent<PresentInfo&> after_present_event{"AfterPresent"};
+
+ // An end of frame event that runs on the CPU thread
+ Common::HookableEvent<> vi_end_field_event{"VIEndField"};
+};
+
+VideoEvents& GetVideoEvents();
diff --git a/Source/Core/VideoCommon/Widescreen.cpp b/Source/Core/VideoCommon/Widescreen.cpp
index 21309f3a98..e980d24d57 100644
--- a/Source/Core/VideoCommon/Widescreen.cpp
+++ b/Source/Core/VideoCommon/Widescreen.cpp
@@ -29,7 +29,10 @@ WidescreenManager::WidescreenManager()
"Invalid suggested aspect ratio mode: only Auto, 4:3 and 16:9 are supported");
}
- m_config_changed = ConfigChangedEvent::Register(
+ auto& system = Core::System::GetInstance();
+ auto& video_events = system.GetVideoEvents();
+
+ m_config_changed = video_events.config_changed_event.Register(
[this](u32 bits) {
if (bits & (CONFIG_CHANGE_BIT_ASPECT_RATIO))
{
@@ -45,10 +48,9 @@ WidescreenManager::WidescreenManager()
"Widescreen");
// VertexManager doesn't maintain statistics in Wii mode.
- auto& system = Core::System::GetInstance();
if (!system.IsWii())
{
- m_update_widescreen = AfterFrameEvent::Register(
+ m_update_widescreen = video_events.after_frame_event.Register(
[this](Core::System&) { UpdateWidescreenHeuristic(); }, "WideScreen Heuristic");
}
}