From 637fd4990914831ae164c2f410cf60fe4f0d28c4 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Fri, 12 Jan 2024 13:35:47 +0100 Subject: [PATCH] FifoRecorder: Move instance to System. --- Source/Core/Core/FifoPlayer/FifoRecorder.cpp | 19 +++++--------- Source/Core/Core/FifoPlayer/FifoRecorder.h | 15 +++++++++-- Source/Core/Core/System.cpp | 9 ++++++- Source/Core/Core/System.h | 2 ++ .../Core/DolphinQt/FIFO/FIFOPlayerWindow.cpp | 26 +++++++++---------- Source/Core/DolphinQt/FIFO/FIFOPlayerWindow.h | 5 +++- Source/Core/DolphinQt/MainWindow.cpp | 3 ++- Source/Core/VideoCommon/BPStructs.cpp | 7 +++-- Source/Core/VideoCommon/OpcodeDecoding.cpp | 2 +- Source/Core/VideoCommon/TextureCacheBase.cpp | 10 +++---- 10 files changed, 60 insertions(+), 38 deletions(-) diff --git a/Source/Core/Core/FifoPlayer/FifoRecorder.cpp b/Source/Core/Core/FifoPlayer/FifoRecorder.cpp index 30422091f3..bdd6276799 100644 --- a/Source/Core/Core/FifoPlayer/FifoRecorder.cpp +++ b/Source/Core/Core/FifoPlayer/FifoRecorder.cpp @@ -213,9 +213,11 @@ void FifoRecorder::FifoRecordAnalyzer::ProcessVertexComponent( m_owner->UseMemory(array_start, array_size, MemoryUpdate::Type::VertexStream); } -static FifoRecorder instance; +FifoRecorder::FifoRecorder(Core::System& system) : m_system(system) +{ +} -FifoRecorder::FifoRecorder() = default; +FifoRecorder::~FifoRecorder() = default; void FifoRecorder::StartRecording(s32 numFrames, CallbackFunc finishedCb) { @@ -235,8 +237,7 @@ void FifoRecorder::StartRecording(s32 numFrames, CallbackFunc finishedCb) // - Global variables suck // - Multithreading with the above two sucks // - auto& system = Core::System::GetInstance(); - auto& memory = system.GetMemory(); + auto& memory = m_system.GetMemory(); m_Ram.resize(memory.GetRamSize()); m_ExRam.resize(memory.GetExRamSize()); @@ -272,7 +273,7 @@ void FifoRecorder::StartRecording(s32 numFrames, CallbackFunc finishedCb) RecordInitialVideoMemory(); } - const auto& fifo = Core::System::GetInstance().GetCommandProcessor().GetFifo(); + const auto& fifo = m_system.GetCommandProcessor().GetFifo(); EndFrame(fifo.CPBase.load(std::memory_order_relaxed), fifo.CPEnd.load(std::memory_order_relaxed)); }, @@ -356,8 +357,7 @@ void FifoRecorder::WriteGPCommand(const u8* data, u32 size) void FifoRecorder::UseMemory(u32 address, u32 size, MemoryUpdate::Type type, bool dynamicUpdate) { - auto& system = Core::System::GetInstance(); - auto& memory = system.GetMemory(); + auto& memory = m_system.GetMemory(); u8* curData; u8* newData; @@ -461,8 +461,3 @@ bool FifoRecorder::IsRecording() const { return m_IsRecording; } - -FifoRecorder& FifoRecorder::GetInstance() -{ - return instance; -} diff --git a/Source/Core/Core/FifoPlayer/FifoRecorder.h b/Source/Core/Core/FifoPlayer/FifoRecorder.h index b6330c2e28..637d386c39 100644 --- a/Source/Core/Core/FifoPlayer/FifoRecorder.h +++ b/Source/Core/Core/FifoPlayer/FifoRecorder.h @@ -12,12 +12,22 @@ #include "Common/HookableEvent.h" #include "Core/FifoPlayer/FifoDataFile.h" +namespace Core +{ +class System; +} + class FifoRecorder { public: using CallbackFunc = std::function; - FifoRecorder(); + explicit FifoRecorder(Core::System& system); + FifoRecorder(const FifoRecorder&) = delete; + FifoRecorder(FifoRecorder&&) = delete; + FifoRecorder& operator=(const FifoRecorder&) = delete; + FifoRecorder& operator=(FifoRecorder&&) = delete; + ~FifoRecorder(); void StartRecording(s32 numFrames, CallbackFunc finishedCb); void StopRecording(); @@ -46,7 +56,6 @@ public: // Checked once per frame prior to callng EndFrame() bool IsRecording() const; - static FifoRecorder& GetInstance(); private: class FifoRecordAnalyzer; @@ -77,4 +86,6 @@ private: std::vector m_ExRam; Common::EventHook m_end_of_frame_event; + + Core::System& m_system; }; diff --git a/Source/Core/Core/System.cpp b/Source/Core/Core/System.cpp index d4898d9e97..fa325d909b 100644 --- a/Source/Core/Core/System.cpp +++ b/Source/Core/Core/System.cpp @@ -9,6 +9,7 @@ #include "Core/Config/MainSettings.h" #include "Core/CoreTiming.h" #include "Core/FifoPlayer/FifoPlayer.h" +#include "Core/FifoPlayer/FifoRecorder.h" #include "Core/HW/AudioInterface.h" #include "Core/HW/CPU.h" #include "Core/HW/DSP.h" @@ -51,7 +52,7 @@ struct System::Impl m_mmu(system, m_memory, m_power_pc), m_processor_interface(system), m_serial_interface(system), m_system_timers(system), m_video_interface(system), m_interpreter(system, m_power_pc.GetPPCState(), m_mmu), m_jit_interface(system), - m_fifo_player(system) + m_fifo_player(system), m_fifo_recorder(system) { } @@ -91,6 +92,7 @@ struct System::Impl JitInterface m_jit_interface; VideoCommon::CustomAssetLoader m_custom_asset_loader; FifoPlayer m_fifo_player; + FifoRecorder m_fifo_recorder; }; System::System() : m_impl{std::make_unique(*this)} @@ -186,6 +188,11 @@ FifoPlayer& System::GetFifoPlayer() const return m_impl->m_fifo_player; } +FifoRecorder& System::GetFifoRecorder() const +{ + return m_impl->m_fifo_recorder; +} + GeometryShaderManager& System::GetGeometryShaderManager() const { return m_impl->m_geometry_shader_manager; diff --git a/Source/Core/Core/System.h b/Source/Core/Core/System.h index ef38d88d08..c835464987 100644 --- a/Source/Core/Core/System.h +++ b/Source/Core/Core/System.h @@ -48,6 +48,7 @@ namespace Fifo class FifoManager; } class FifoPlayer; +class FifoRecorder; namespace GPFifo { class GPFifoManager; @@ -148,6 +149,7 @@ public: ExpansionInterface::ExpansionInterfaceManager& GetExpansionInterface() const; Fifo::FifoManager& GetFifo() const; FifoPlayer& GetFifoPlayer() const; + FifoRecorder& GetFifoRecorder() const; GeometryShaderManager& GetGeometryShaderManager() const; GPFifo::GPFifoManager& GetGPFifo() const; HSP::HSPManager& GetHSP() const; diff --git a/Source/Core/DolphinQt/FIFO/FIFOPlayerWindow.cpp b/Source/Core/DolphinQt/FIFO/FIFOPlayerWindow.cpp index 6c108477f5..1071a88f8c 100644 --- a/Source/Core/DolphinQt/FIFO/FIFOPlayerWindow.cpp +++ b/Source/Core/DolphinQt/FIFO/FIFOPlayerWindow.cpp @@ -32,8 +32,9 @@ #include "DolphinQt/Resources.h" #include "DolphinQt/Settings.h" -FIFOPlayerWindow::FIFOPlayerWindow(FifoPlayer& fifo_player, QWidget* parent) - : QWidget(parent), m_fifo_player(fifo_player) +FIFOPlayerWindow::FIFOPlayerWindow(FifoPlayer& fifo_player, FifoRecorder& fifo_recorder, + QWidget* parent) + : QWidget(parent), m_fifo_player(fifo_player), m_fifo_recorder(fifo_recorder) { setWindowTitle(tr("FIFO Player")); setWindowIcon(Resources::GetAppIcon()); @@ -229,7 +230,7 @@ void FIFOPlayerWindow::SaveRecording() if (path.isEmpty()) return; - FifoDataFile* file = FifoRecorder::GetInstance().GetRecordedFile(); + FifoDataFile* file = m_fifo_recorder.GetRecordedFile(); bool result = file->Save(path.toStdString()); @@ -242,9 +243,8 @@ void FIFOPlayerWindow::SaveRecording() void FIFOPlayerWindow::StartRecording() { // Start recording - FifoRecorder::GetInstance().StartRecording(m_frame_record_count->value(), [this] { - QueueOnObject(this, [this] { OnRecordingDone(); }); - }); + m_fifo_recorder.StartRecording(m_frame_record_count->value(), + [this] { QueueOnObject(this, [this] { OnRecordingDone(); }); }); UpdateControls(); @@ -253,7 +253,7 @@ void FIFOPlayerWindow::StartRecording() void FIFOPlayerWindow::StopRecording() { - FifoRecorder::GetInstance().StopRecording(); + m_fifo_recorder.StopRecording(); UpdateControls(); UpdateInfo(); @@ -270,7 +270,7 @@ void FIFOPlayerWindow::OnEmulationStarted() void FIFOPlayerWindow::OnEmulationStopped() { // If we have previously been recording, stop now. - if (FifoRecorder::GetInstance().IsRecording()) + if (m_fifo_recorder.IsRecording()) StopRecording(); UpdateControls(); @@ -297,9 +297,9 @@ void FIFOPlayerWindow::UpdateInfo() return; } - if (FifoRecorder::GetInstance().IsRecordingDone()) + if (m_fifo_recorder.IsRecordingDone()) { - FifoDataFile* file = FifoRecorder::GetInstance().GetRecordedFile(); + FifoDataFile* file = m_fifo_recorder.GetRecordedFile(); size_t fifo_bytes = 0; size_t mem_bytes = 0; @@ -316,7 +316,7 @@ void FIFOPlayerWindow::UpdateInfo() return; } - if (Core::IsRunning() && FifoRecorder::GetInstance().IsRecording()) + if (Core::IsRunning() && m_fifo_recorder.IsRecording()) { m_info_label->setText(tr("Recording...")); return; @@ -376,7 +376,7 @@ void FIFOPlayerWindow::UpdateLimits() void FIFOPlayerWindow::UpdateControls() { bool running = Core::IsRunning(); - bool is_recording = FifoRecorder::GetInstance().IsRecording(); + bool is_recording = m_fifo_recorder.IsRecording(); bool is_playing = m_fifo_player.IsPlaying(); m_frame_range_from->setEnabled(is_playing); @@ -399,7 +399,7 @@ void FIFOPlayerWindow::UpdateControls() m_stop->setVisible(running && is_recording); m_record->setVisible(!m_stop->isVisible()); - m_save->setEnabled(FifoRecorder::GetInstance().IsRecordingDone()); + m_save->setEnabled(m_fifo_recorder.IsRecordingDone()); } bool FIFOPlayerWindow::eventFilter(QObject* object, QEvent* event) diff --git a/Source/Core/DolphinQt/FIFO/FIFOPlayerWindow.h b/Source/Core/DolphinQt/FIFO/FIFOPlayerWindow.h index beb549c481..647c95710d 100644 --- a/Source/Core/DolphinQt/FIFO/FIFOPlayerWindow.h +++ b/Source/Core/DolphinQt/FIFO/FIFOPlayerWindow.h @@ -14,13 +14,15 @@ class QSpinBox; class QTabWidget; class ToolTipCheckBox; class FifoPlayer; +class FifoRecorder; class FIFOAnalyzer; class FIFOPlayerWindow : public QWidget { Q_OBJECT public: - explicit FIFOPlayerWindow(FifoPlayer& fifo_player, QWidget* parent = nullptr); + explicit FIFOPlayerWindow(FifoPlayer& fifo_player, FifoRecorder& fifo_recorder, + QWidget* parent = nullptr); ~FIFOPlayerWindow(); signals: @@ -51,6 +53,7 @@ private: bool eventFilter(QObject* object, QEvent* event) final override; FifoPlayer& m_fifo_player; + FifoRecorder& m_fifo_recorder; QLabel* m_info_label; QPushButton* m_load; diff --git a/Source/Core/DolphinQt/MainWindow.cpp b/Source/Core/DolphinQt/MainWindow.cpp index 45289dbee3..74e6198c84 100644 --- a/Source/Core/DolphinQt/MainWindow.cpp +++ b/Source/Core/DolphinQt/MainWindow.cpp @@ -1363,7 +1363,8 @@ void MainWindow::ShowFIFOPlayer() { if (!m_fifo_window) { - m_fifo_window = new FIFOPlayerWindow(Core::System::GetInstance().GetFifoPlayer()); + m_fifo_window = new FIFOPlayerWindow(Core::System::GetInstance().GetFifoPlayer(), + Core::System::GetInstance().GetFifoRecorder()); connect(m_fifo_window, &FIFOPlayerWindow::LoadFIFORequested, this, [this](const QString& path) { StartGame(path, ScanForSecondDisc::No); }); } diff --git a/Source/Core/VideoCommon/BPStructs.cpp b/Source/Core/VideoCommon/BPStructs.cpp index 1a8580df8f..689570ae55 100644 --- a/Source/Core/VideoCommon/BPStructs.cpp +++ b/Source/Core/VideoCommon/BPStructs.cpp @@ -405,7 +405,7 @@ static void BPWritten(PixelShaderManager& pixel_shader_manager, XFStateManager& memory.CopyFromEmu(texMem + tmem_addr, addr, tmem_transfer_count); if (OpcodeDecoder::g_record_fifo_data) - FifoRecorder::GetInstance().UseMemory(addr, tmem_transfer_count, MemoryUpdate::Type::TMEM); + system.GetFifoRecorder().UseMemory(addr, tmem_transfer_count, MemoryUpdate::Type::TMEM); TMEM::InvalidateAll(); @@ -624,7 +624,10 @@ static void BPWritten(PixelShaderManager& pixel_shader_manager, XFStateManager& } if (OpcodeDecoder::g_record_fifo_data) - FifoRecorder::GetInstance().UseMemory(src_addr, bytes_read, MemoryUpdate::Type::TMEM); + { + Core::System::GetInstance().GetFifoRecorder().UseMemory(src_addr, bytes_read, + MemoryUpdate::Type::TMEM); + } TMEM::InvalidateAll(); } diff --git a/Source/Core/VideoCommon/OpcodeDecoding.cpp b/Source/Core/VideoCommon/OpcodeDecoding.cpp index b82d79f005..1456fbf2d0 100644 --- a/Source/Core/VideoCommon/OpcodeDecoding.cpp +++ b/Source/Core/VideoCommon/OpcodeDecoding.cpp @@ -234,7 +234,7 @@ public: // process them. if (g_record_fifo_data && static_cast(data[0]) != Opcode::GX_CMD_CALL_DL) { - FifoRecorder::GetInstance().WriteGPCommand(data, size); + Core::System::GetInstance().GetFifoRecorder().WriteGPCommand(data, size); } } } diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp index 9294748397..e5b8122982 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/TextureCacheBase.cpp @@ -1349,9 +1349,9 @@ RcTcacheEntry TextureCacheBase::GetTexture(const int textureCacheSafetyColorSamp // its own memory modification tracking independent of the texture hashing below. if (OpcodeDecoder::g_record_fifo_data && !texture_info.IsFromTmem()) { - FifoRecorder::GetInstance().UseMemory(texture_info.GetRawAddress(), - texture_info.GetFullLevelSize(), - MemoryUpdate::Type::TextureMap); + Core::System::GetInstance().GetFifoRecorder().UseMemory(texture_info.GetRawAddress(), + texture_info.GetFullLevelSize(), + MemoryUpdate::Type::TextureMap); } // TODO: This doesn't hash GB tiles for preloaded RGBA8 textures (instead, it's hashing more data @@ -2534,8 +2534,8 @@ void TextureCacheBase::CopyRenderTargetToTexture( u32 address = dstAddr; for (u32 i = 0; i < num_blocks_y; i++) { - FifoRecorder::GetInstance().UseMemory(address, bytes_per_row, MemoryUpdate::Type::TextureMap, - true); + Core::System::GetInstance().GetFifoRecorder().UseMemory(address, bytes_per_row, + MemoryUpdate::Type::TextureMap, true); address += dstStride; } }