diff --git a/Source/Core/Core/System.cpp b/Source/Core/Core/System.cpp index 9327f96f97..178c92175a 100644 --- a/Source/Core/Core/System.cpp +++ b/Source/Core/Core/System.cpp @@ -43,8 +43,9 @@ struct System::Impl explicit Impl(System& system) : m_audio_interface(system), m_core_timing(system), m_command_processor{system}, m_cpu(system), m_dsp(system), m_dvd_interface(system), m_dvd_thread(system), - m_expansion_interface(system), m_fifo{system}, m_gp_fifo(system), m_memory(system), - m_power_pc(system), m_mmu(system, m_memory, m_power_pc), m_processor_interface(system), + m_expansion_interface(system), m_fifo{system}, m_gp_fifo(system), + m_memory(system), m_pixel_engine{system}, m_power_pc(system), + m_mmu(system, m_memory, m_power_pc), m_processor_interface(system), m_serial_interface(system), m_video_interface(system), m_interpreter(system, m_power_pc.GetPPCState(), m_mmu), m_jit_interface(system) { diff --git a/Source/Core/VideoCommon/BPStructs.cpp b/Source/Core/VideoCommon/BPStructs.cpp index bf67ebcaa5..f1dff8fd97 100644 --- a/Source/Core/VideoCommon/BPStructs.cpp +++ b/Source/Core/VideoCommon/BPStructs.cpp @@ -190,7 +190,7 @@ static void BPWritten(PixelShaderManager& pixel_shader_manager, XFStateManager& g_framebuffer_manager->RefreshPeekCache(); auto& system = Core::System::GetInstance(); if (!system.GetFifo().UseDeterministicGPUThread()) - system.GetPixelEngine().SetFinish(system, cycles_into_future); // may generate interrupt + system.GetPixelEngine().SetFinish(cycles_into_future); // may generate interrupt DEBUG_LOG_FMT(VIDEO, "GXSetDrawDone SetPEFinish (value: {:#04X})", bp.newvalue & 0xFFFF); return; } @@ -210,7 +210,7 @@ static void BPWritten(PixelShaderManager& pixel_shader_manager, XFStateManager& auto& system = Core::System::GetInstance(); if (!system.GetFifo().UseDeterministicGPUThread()) { - system.GetPixelEngine().SetToken(system, static_cast(bp.newvalue & 0xFFFF), false, + system.GetPixelEngine().SetToken(static_cast(bp.newvalue & 0xFFFF), false, cycles_into_future); } DEBUG_LOG_FMT(VIDEO, "SetPEToken {:#06X}", bp.newvalue & 0xFFFF); @@ -226,7 +226,7 @@ static void BPWritten(PixelShaderManager& pixel_shader_manager, XFStateManager& auto& system = Core::System::GetInstance(); if (!system.GetFifo().UseDeterministicGPUThread()) { - system.GetPixelEngine().SetToken(system, static_cast(bp.newvalue & 0xFFFF), true, + system.GetPixelEngine().SetToken(static_cast(bp.newvalue & 0xFFFF), true, cycles_into_future); } DEBUG_LOG_FMT(VIDEO, "SetPEToken + INT {:#06X}", bp.newvalue & 0xFFFF); @@ -803,13 +803,13 @@ void LoadBPRegPreprocess(u8 reg, u32 value, int cycles_into_future) { case BPMEM_SETDRAWDONE: if ((newval & 0xff) == 0x02) - system.GetPixelEngine().SetFinish(system, cycles_into_future); + system.GetPixelEngine().SetFinish(cycles_into_future); break; case BPMEM_PE_TOKEN_ID: - system.GetPixelEngine().SetToken(system, newval & 0xffff, false, cycles_into_future); + system.GetPixelEngine().SetToken(newval & 0xffff, false, cycles_into_future); break; case BPMEM_PE_TOKEN_INT_ID: // Pixel Engine Interrupt Token ID - system.GetPixelEngine().SetToken(system, newval & 0xffff, true, cycles_into_future); + system.GetPixelEngine().SetToken(newval & 0xffff, true, cycles_into_future); break; } } diff --git a/Source/Core/VideoCommon/PixelEngine.cpp b/Source/Core/VideoCommon/PixelEngine.cpp index 9817e38c07..880fa575dd 100644 --- a/Source/Core/VideoCommon/PixelEngine.cpp +++ b/Source/Core/VideoCommon/PixelEngine.cpp @@ -30,6 +30,10 @@ enum INT_CAUSE_PE_FINISH = 0x400, // GP Finished }; +PixelEngineManager::PixelEngineManager(Core::System& system) : m_system{system} +{ +} + void PixelEngineManager::DoState(PointerWrap& p) { p.Do(m_z_conf); @@ -49,7 +53,7 @@ void PixelEngineManager::DoState(PointerWrap& p) p.Do(m_signal_finish_interrupt); } -void PixelEngineManager::Init(Core::System& system) +void PixelEngineManager::Init() { m_control.hex = 0; m_z_conf.hex = 0; @@ -68,7 +72,7 @@ void PixelEngineManager::Init(Core::System& system) m_signal_finish_interrupt = false; m_event_type_set_token_finish = - system.GetCoreTiming().RegisterEvent("SetTokenFinish", SetTokenFinish_OnMainThread_Static); + m_system.GetCoreTiming().RegisterEvent("SetTokenFinish", SetTokenFinish_OnMainThread_Static); } void PixelEngineManager::RegisterMMIO(MMIO::Mapping* mmio, u32 base) @@ -171,11 +175,10 @@ void PixelEngineManager::UpdateInterrupts() void PixelEngineManager::SetTokenFinish_OnMainThread_Static(Core::System& system, u64 userdata, s64 cycles_late) { - system.GetPixelEngine().SetTokenFinish_OnMainThread(system, userdata, cycles_late); + system.GetPixelEngine().SetTokenFinish_OnMainThread(userdata, cycles_late); } -void PixelEngineManager::SetTokenFinish_OnMainThread(Core::System& system, u64 userdata, - s64 cycles_late) +void PixelEngineManager::SetTokenFinish_OnMainThread(u64 userdata, s64 cycles_late) { std::unique_lock lk(m_token_finish_mutex); m_event_raised = false; @@ -202,7 +205,7 @@ void PixelEngineManager::SetTokenFinish_OnMainThread(Core::System& system, u64 u // Raise the event handler above on the CPU thread. // m_token_finish_mutex must be locked. // THIS IS EXECUTED FROM VIDEO THREAD -void PixelEngineManager::RaiseEvent(Core::System& system, int cycles_into_future) +void PixelEngineManager::RaiseEvent(int cycles_into_future) { if (m_event_raised) return; @@ -211,7 +214,7 @@ void PixelEngineManager::RaiseEvent(Core::System& system, int cycles_into_future CoreTiming::FromThread from = CoreTiming::FromThread::NON_CPU; s64 cycles = 0; // we don't care about timings for dual core mode. - if (!system.IsDualCoreMode() || system.GetFifo().UseDeterministicGPUThread()) + if (!m_system.IsDualCoreMode() || m_system.GetFifo().UseDeterministicGPUThread()) { from = CoreTiming::FromThread::CPU; @@ -219,13 +222,12 @@ void PixelEngineManager::RaiseEvent(Core::System& system, int cycles_into_future // games time to setup any interrupt state cycles = std::max(500, cycles_into_future); } - system.GetCoreTiming().ScheduleEvent(cycles, m_event_type_set_token_finish, 0, from); + m_system.GetCoreTiming().ScheduleEvent(cycles, m_event_type_set_token_finish, 0, from); } // SetToken // THIS IS EXECUTED FROM VIDEO THREAD -void PixelEngineManager::SetToken(Core::System& system, const u16 token, const bool interrupt, - int cycles_into_future) +void PixelEngineManager::SetToken(const u16 token, const bool interrupt, int cycles_into_future) { DEBUG_LOG_FMT(PIXELENGINE, "VIDEO Backend raises INT_CAUSE_PE_TOKEN (btw, token: {:04x})", token); @@ -234,12 +236,12 @@ void PixelEngineManager::SetToken(Core::System& system, const u16 token, const b m_token_pending = token; m_token_interrupt_pending |= interrupt; - RaiseEvent(system, cycles_into_future); + RaiseEvent(cycles_into_future); } // SetFinish // THIS IS EXECUTED FROM VIDEO THREAD (BPStructs.cpp) when a new frame has been drawn -void PixelEngineManager::SetFinish(Core::System& system, int cycles_into_future) +void PixelEngineManager::SetFinish(int cycles_into_future) { DEBUG_LOG_FMT(PIXELENGINE, "VIDEO Set Finish"); @@ -247,7 +249,7 @@ void PixelEngineManager::SetFinish(Core::System& system, int cycles_into_future) m_finish_interrupt_pending |= true; - RaiseEvent(system, cycles_into_future); + RaiseEvent(cycles_into_future); } } // namespace PixelEngine diff --git a/Source/Core/VideoCommon/PixelEngine.h b/Source/Core/VideoCommon/PixelEngine.h index 6e60d5a761..6dfc8556c5 100644 --- a/Source/Core/VideoCommon/PixelEngine.h +++ b/Source/Core/VideoCommon/PixelEngine.h @@ -179,20 +179,22 @@ union UPECtrlReg class PixelEngineManager { public: - void Init(Core::System& system); + explicit PixelEngineManager(Core::System& system); + + void Init(); void DoState(PointerWrap& p); void RegisterMMIO(MMIO::Mapping* mmio, u32 base); // gfx backend support - void SetToken(Core::System& system, const u16 token, const bool interrupt, int cycle_delay); - void SetFinish(Core::System& system, int cycle_delay); + void SetToken(const u16 token, const bool interrupt, int cycle_delay); + void SetFinish(int cycle_delay); AlphaReadMode GetAlphaReadMode() const { return m_alpha_read.read_mode; } private: - void RaiseEvent(Core::System& system, int cycles_into_future); + void RaiseEvent(int cycles_into_future); void UpdateInterrupts(); - void SetTokenFinish_OnMainThread(Core::System& system, u64 userdata, s64 cycles_late); + void SetTokenFinish_OnMainThread(u64 userdata, s64 cycles_late); static void SetTokenFinish_OnMainThread_Static(Core::System& system, u64 userdata, s64 cycles_late); @@ -216,6 +218,8 @@ private: bool m_signal_finish_interrupt = false; CoreTiming::EventType* m_event_type_set_token_finish = nullptr; + + Core::System& m_system; }; } // namespace PixelEngine diff --git a/Source/Core/VideoCommon/VideoBackendBase.cpp b/Source/Core/VideoCommon/VideoBackendBase.cpp index ef39216167..f0e9970e6d 100644 --- a/Source/Core/VideoCommon/VideoBackendBase.cpp +++ b/Source/Core/VideoCommon/VideoBackendBase.cpp @@ -380,7 +380,7 @@ bool VideoBackendBase::InitializeShared(std::unique_ptr gfx, auto& command_processor = system.GetCommandProcessor(); command_processor.Init(); system.GetFifo().Init(); - system.GetPixelEngine().Init(system); + system.GetPixelEngine().Init(); BPInit(); VertexLoaderManager::Init(); system.GetVertexShaderManager().Init();