VideoCommon/Statistics: Remove global system accessor from s_after_frame_event

Instead, we make the event take a reference to the system and then pass
it in when the event is triggered.

This does introduce two other accessors, but these are much easier to
refactor out over time, and without modification to the existing event
interface.
This commit is contained in:
Lioncash
2024-01-31 13:12:06 -05:00
parent 30fdf25f8f
commit cac66317aa
14 changed files with 35 additions and 26 deletions

View File

@ -256,7 +256,7 @@ void FifoRecorder::StartRecording(s32 numFrames, CallbackFunc finishedCb)
m_FinishedCb = finishedCb; m_FinishedCb = finishedCb;
m_end_of_frame_event = AfterFrameEvent::Register( m_end_of_frame_event = AfterFrameEvent::Register(
[this] { [this](const Core::System& system) {
const bool was_recording = OpcodeDecoder::g_record_fifo_data; const bool was_recording = OpcodeDecoder::g_record_fifo_data;
OpcodeDecoder::g_record_fifo_data = IsRecording(); OpcodeDecoder::g_record_fifo_data = IsRecording();
@ -272,7 +272,7 @@ void FifoRecorder::StartRecording(s32 numFrames, CallbackFunc finishedCb)
RecordInitialVideoMemory(); RecordInitialVideoMemory();
} }
const auto& fifo = m_system.GetCommandProcessor().GetFifo(); const auto& fifo = system.GetCommandProcessor().GetFifo();
EndFrame(fifo.CPBase.load(std::memory_order_relaxed), EndFrame(fifo.CPBase.load(std::memory_order_relaxed),
fifo.CPEnd.load(std::memory_order_relaxed)); fifo.CPEnd.load(std::memory_order_relaxed));
}, },

View File

@ -346,7 +346,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 // render multiple sub-frames and arrange the XFB copies in next to each-other in main memory
// so they form a single completed XFB. // so they form a single completed XFB.
// See https://dolphin-emu.org/blog/2017/11/19/hybridxfb/ for examples and more detail. // See https://dolphin-emu.org/blog/2017/11/19/hybridxfb/ for examples and more detail.
AfterFrameEvent::Trigger(); AfterFrameEvent::Trigger(Core::System::GetInstance());
// Note: Theoretically, in the future we could track the VI configuration and try to detect // 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 // when an XFB is the last XFB copy of a frame. Not only would we get a clean "end of

View File

@ -27,7 +27,8 @@ static bool DumpFrameToPNG(const FrameData& frame, const std::string& file_name)
FrameDumper::FrameDumper() FrameDumper::FrameDumper()
{ {
m_frame_end_handle = AfterFrameEvent::Register([this] { FlushFrameDump(); }, "FrameDumper"); m_frame_end_handle =
AfterFrameEvent::Register([this](Core::System&) { FlushFrameDump(); }, "FrameDumper");
} }
FrameDumper::~FrameDumper() FrameDumper::~FrameDumper()

View File

@ -84,7 +84,8 @@ bool FramebufferManager::Initialize()
return false; return false;
} }
m_end_of_frame_event = AfterFrameEvent::Register([this] { EndOfFrame(); }, "FramebufferManager"); m_end_of_frame_event =
AfterFrameEvent::Register([this](Core::System&) { EndOfFrame(); }, "FramebufferManager");
return true; return true;
} }

View File

@ -16,8 +16,8 @@ CustomShaderCache::CustomShaderCache()
m_async_uber_shader_compiler = g_gfx->CreateAsyncShaderCompiler(); m_async_uber_shader_compiler = g_gfx->CreateAsyncShaderCompiler();
m_async_uber_shader_compiler->StartWorkerThreads(1); // TODO m_async_uber_shader_compiler->StartWorkerThreads(1); // TODO
m_frame_end_handler = m_frame_end_handler = AfterFrameEvent::Register([this](Core::System&) { RetrieveAsyncShaders(); },
AfterFrameEvent::Register([this] { RetrieveAsyncShaders(); }, "RetreiveAsyncShaders"); "RetrieveAsyncShaders");
} }
CustomShaderCache::~CustomShaderCache() CustomShaderCache::~CustomShaderCache()

View File

@ -95,7 +95,8 @@ bool GraphicsModManager::Initialize()
g_ActiveConfig.graphics_mod_config->SetChangeCount(old_game_mod_changes); g_ActiveConfig.graphics_mod_config->SetChangeCount(old_game_mod_changes);
g_graphics_mod_manager->Load(*g_ActiveConfig.graphics_mod_config); g_graphics_mod_manager->Load(*g_ActiveConfig.graphics_mod_config);
m_end_of_frame_event = AfterFrameEvent::Register([this] { EndOfFrame(); }, "ModManager"); m_end_of_frame_event =
AfterFrameEvent::Register([this](Core::System&) { EndOfFrame(); }, "ModManager");
} }
return true; return true;

View File

@ -784,7 +784,7 @@ void Presenter::DoState(PointerWrap& p)
if (p.IsReadMode() && m_last_xfb_stride != 0) if (p.IsReadMode() && m_last_xfb_stride != 0)
{ {
// This technically counts as the end of the frame // This technically counts as the end of the frame
AfterFrameEvent::Trigger(); AfterFrameEvent::Trigger(Core::System::GetInstance());
ImmediateSwap(m_last_xfb_addr, m_last_xfb_width, m_last_xfb_stride, m_last_xfb_height, ImmediateSwap(m_last_xfb_addr, m_last_xfb_width, m_last_xfb_stride, m_last_xfb_height,
m_last_xfb_ticks); m_last_xfb_ticks);

View File

@ -46,8 +46,8 @@ bool ShaderCache::Initialize()
return false; return false;
m_async_shader_compiler = g_gfx->CreateAsyncShaderCompiler(); m_async_shader_compiler = g_gfx->CreateAsyncShaderCompiler();
m_frame_end_handler = m_frame_end_handler = AfterFrameEvent::Register([this](Core::System&) { RetrieveAsyncShaders(); },
AfterFrameEvent::Register([this] { RetrieveAsyncShaders(); }, "RetreiveAsyncShaders"); "RetrieveAsyncShaders");
return true; return true;
} }

View File

@ -23,13 +23,12 @@ static Common::EventHook s_before_frame_event =
BeforeFrameEvent::Register([] { g_stats.ResetFrame(); }, "Statistics::ResetFrame"); BeforeFrameEvent::Register([] { g_stats.ResetFrame(); }, "Statistics::ResetFrame");
static Common::EventHook s_after_frame_event = AfterFrameEvent::Register( static Common::EventHook s_after_frame_event = AfterFrameEvent::Register(
[] { [](const Core::System& system) {
DolphinAnalytics::PerformanceSample perf_sample; DolphinAnalytics::Instance().ReportPerformanceInfo({
perf_sample.speed_ratio = .speed_ratio = system.GetSystemTimers().GetEstimatedEmulationPerformance(),
Core::System::GetInstance().GetSystemTimers().GetEstimatedEmulationPerformance(); .num_prims = g_stats.this_frame.num_prims + g_stats.this_frame.num_dl_prims,
perf_sample.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,
perf_sample.num_draw_calls = g_stats.this_frame.num_draw_calls; });
DolphinAnalytics::Instance().ReportPerformanceInfo(std::move(perf_sample));
}, },
"Statistics::PerformanceSample"); "Statistics::PerformanceSample");

View File

@ -459,7 +459,7 @@ private:
void OnFrameEnd(); void OnFrameEnd();
Common::EventHook m_frame_event = Common::EventHook m_frame_event =
AfterFrameEvent::Register([this] { OnFrameEnd(); }, "TextureCache"); AfterFrameEvent::Register([this](Core::System&) { OnFrameEnd(); }, "TextureCache");
}; };
extern std::unique_ptr<TextureCacheBase> g_texture_cache; extern std::unique_ptr<TextureCacheBase> g_texture_cache;

View File

@ -117,9 +117,11 @@ VertexManagerBase::~VertexManagerBase() = default;
bool VertexManagerBase::Initialize() bool VertexManagerBase::Initialize()
{ {
m_frame_end_event = AfterFrameEvent::Register([this] { OnEndFrame(); }, "VertexManagerBase"); m_frame_end_event =
AfterFrameEvent::Register([this](Core::System&) { OnEndFrame(); }, "VertexManagerBase");
m_after_present_event = AfterPresentEvent::Register( m_after_present_event = AfterPresentEvent::Register(
[this](PresentInfo& pi) { m_ticks_elapsed = pi.emulated_timestamp; }, "VertexManagerBase"); [this](const PresentInfo& pi) { m_ticks_elapsed = pi.emulated_timestamp; },
"VertexManagerBase");
m_index_generator.Init(); m_index_generator.Init();
m_custom_shader_cache = std::make_unique<CustomShaderCache>(); m_custom_shader_cache = std::make_unique<CustomShaderCache>();
m_cpu_cull.Init(); m_cpu_cull.Init();

View File

@ -395,5 +395,5 @@ void CheckForConfigChanges()
// TODO: Move everything else to the ConfigChanged event // TODO: Move everything else to the ConfigChanged event
} }
static Common::EventHook s_check_config_event = static Common::EventHook s_check_config_event = AfterFrameEvent::Register(
AfterFrameEvent::Register([] { CheckForConfigChanges(); }, "CheckForConfigChanges"); [](Core::System&) { CheckForConfigChanges(); }, "CheckForConfigChanges");

View File

@ -6,6 +6,11 @@
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/HookableEvent.h" #include "Common/HookableEvent.h"
namespace Core
{
class System;
}
// Called when certain video config setting are changed // Called when certain video config setting are changed
using ConfigChangedEvent = Common::HookableEvent<"ConfigChanged", u32>; using ConfigChangedEvent = Common::HookableEvent<"ConfigChanged", u32>;
@ -16,7 +21,7 @@ using BeforeFrameEvent = Common::HookableEvent<"BeforeFrame">;
// Useful for "once per frame" usecases. // Useful for "once per frame" usecases.
// Note: In a few rare cases, games do multiple XFB copies per frame and join them while presenting. // 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. // If this matters to your usecase, you should use BeforePresent instead.
using AfterFrameEvent = Common::HookableEvent<"AfterFrame">; using AfterFrameEvent = Common::HookableEvent<"AfterFrame", Core::System&>;
struct PresentInfo struct PresentInfo
{ {

View File

@ -26,8 +26,8 @@ WidescreenManager::WidescreenManager()
auto& system = Core::System::GetInstance(); auto& system = Core::System::GetInstance();
if (!system.IsWii()) if (!system.IsWii())
{ {
m_update_widescreen = m_update_widescreen = AfterFrameEvent::Register(
AfterFrameEvent::Register([this] { UpdateWidescreenHeuristic(); }, "WideScreen Heuristic"); [this](Core::System&) { UpdateWidescreenHeuristic(); }, "WideScreen Heuristic");
} }
} }