VideoCommon/Fifo: Pass Core::System to methods.

This commit is contained in:
Admiral H. Curtiss 2022-12-09 22:59:11 +01:00
parent 5624dd6d39
commit ceae4242fc
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
8 changed files with 76 additions and 82 deletions

View File

@ -599,7 +599,7 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi
wiifs_guard.Dismiss(); wiifs_guard.Dismiss();
// This adds the SyncGPU handler to CoreTiming, so now CoreTiming::Advance might block. // This adds the SyncGPU handler to CoreTiming, so now CoreTiming::Advance might block.
system.GetFifo().Prepare(); system.GetFifo().Prepare(system);
// Setup our core // Setup our core
if (Config::Get(Config::MAIN_CPU_CORE) != PowerPC::CPUCore::Interpreter) if (Config::Get(Config::MAIN_CPU_CORE) != PowerPC::CPUCore::Interpreter)
@ -624,7 +624,7 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi
s_cpu_thread = std::thread(cpuThreadFunc, savestate_path, delete_savestate); s_cpu_thread = std::thread(cpuThreadFunc, savestate_path, delete_savestate);
// become the GPU thread // become the GPU thread
system.GetFifo().RunGpuLoop(); system.GetFifo().RunGpuLoop(system);
// We have now exited the Video Loop // We have now exited the Video Loop
INFO_LOG_FMT(CONSOLE, "{}", StopMessage(false, "Video Loop Ended")); INFO_LOG_FMT(CONSOLE, "{}", StopMessage(false, "Video Loop Ended"));
@ -769,7 +769,7 @@ static bool PauseAndLock(bool do_lock, bool unpause_on_unlock)
// video has to come after CPU, because CPU thread can wait for video thread // video has to come after CPU, because CPU thread can wait for video thread
// (s_efbAccessRequested). // (s_efbAccessRequested).
auto& system = Core::System::GetInstance(); auto& system = Core::System::GetInstance();
system.GetFifo().PauseAndLock(do_lock, false); system.GetFifo().PauseAndLock(system, do_lock, false);
ResetRumble(); ResetRumble();
@ -1034,7 +1034,7 @@ void UpdateWantDeterminism(bool initial)
ios->UpdateWantDeterminism(new_want_determinism); ios->UpdateWantDeterminism(new_want_determinism);
auto& system = Core::System::GetInstance(); auto& system = Core::System::GetInstance();
system.GetFifo().UpdateWantDeterminism(new_want_determinism); system.GetFifo().UpdateWantDeterminism(system, new_want_determinism);
// We need to clear the cache because some parts of the JIT depend on want_determinism, // We need to clear the cache because some parts of the JIT depend on want_determinism,
// e.g. use of FMA. // e.g. use of FMA.

View File

@ -355,7 +355,7 @@ void CoreTimingManager::Idle()
// the VI will be desynchronized. So, We are waiting until the FIFO finish and // the VI will be desynchronized. So, We are waiting until the FIFO finish and
// while we process only the events required by the FIFO. // while we process only the events required by the FIFO.
auto& system = Core::System::GetInstance(); auto& system = Core::System::GetInstance();
system.GetFifo().FlushGpu(); system.GetFifo().FlushGpu(system);
} }
PowerPC::UpdatePerformanceMonitor(PowerPC::ppcState.downcount, 0, 0); PowerPC::UpdatePerformanceMonitor(PowerPC::ppcState.downcount, 0, 0);

View File

@ -114,10 +114,11 @@ static void RunWithGPUThreadInactive(std::function<void()> f)
// the CPU and GPU threads are the same thread, and we already checked for the GPU thread.) // the CPU and GPU threads are the same thread, and we already checked for the GPU thread.)
const bool was_running = Core::GetState() == Core::State::Running; const bool was_running = Core::GetState() == Core::State::Running;
auto& fifo = Core::System::GetInstance().GetFifo(); auto& system = Core::System::GetInstance();
fifo.PauseAndLock(true, was_running); auto& fifo = system.GetFifo();
fifo.PauseAndLock(system, true, was_running);
f(); f();
fifo.PauseAndLock(false, was_running); fifo.PauseAndLock(system, false, was_running);
} }
else else
{ {

View File

@ -92,7 +92,7 @@ void AsyncRequests::PushEvent(const AsyncRequests::Event& event, bool blocking)
m_queue.push(event); m_queue.push(event);
auto& system = Core::System::GetInstance(); auto& system = Core::System::GetInstance();
system.GetFifo().RunGpu(); system.GetFifo().RunGpu(system);
if (blocking) if (blocking)
{ {
m_cond.wait(lock, [this] { return m_queue.empty(); }); m_cond.wait(lock, [this] { return m_queue.empty(); });

View File

@ -223,7 +223,7 @@ void CommandProcessorManager::RegisterMMIO(Core::System& system, MMIO::Mapping*
mmio->Register(base | STATUS_REGISTER, MMIO::ComplexRead<u16>([](Core::System& system, u32) { mmio->Register(base | STATUS_REGISTER, MMIO::ComplexRead<u16>([](Core::System& system, u32) {
auto& cp = system.GetCommandProcessor(); auto& cp = system.GetCommandProcessor();
system.GetFifo().SyncGPUForRegisterAccess(); system.GetFifo().SyncGPUForRegisterAccess(system);
cp.SetCpStatusRegister(system); cp.SetCpStatusRegister(system);
return cp.m_cp_status_reg.Hex; return cp.m_cp_status_reg.Hex;
}), }),
@ -235,7 +235,7 @@ void CommandProcessorManager::RegisterMMIO(Core::System& system, MMIO::Mapping*
UCPCtrlReg tmp(val); UCPCtrlReg tmp(val);
cp.m_cp_ctrl_reg.Hex = tmp.Hex; cp.m_cp_ctrl_reg.Hex = tmp.Hex;
cp.SetCpControlRegister(system); cp.SetCpControlRegister(system);
system.GetFifo().RunGpu(); system.GetFifo().RunGpu(system);
})); }));
mmio->Register(base | CLEAR_REGISTER, MMIO::DirectRead<u16>(&m_cp_clear_reg.Hex), mmio->Register(base | CLEAR_REGISTER, MMIO::DirectRead<u16>(&m_cp_clear_reg.Hex),
@ -244,7 +244,7 @@ void CommandProcessorManager::RegisterMMIO(Core::System& system, MMIO::Mapping*
UCPClearReg tmp(val); UCPClearReg tmp(val);
cp.m_cp_clear_reg.Hex = tmp.Hex; cp.m_cp_clear_reg.Hex = tmp.Hex;
cp.SetCpClearRegister(); cp.SetCpClearRegister();
system.GetFifo().RunGpu(); system.GetFifo().RunGpu(system);
})); }));
mmio->Register(base | PERF_SELECT, MMIO::InvalidRead<u16>(), MMIO::Nop<u16>()); mmio->Register(base | PERF_SELECT, MMIO::InvalidRead<u16>(), MMIO::Nop<u16>());
@ -284,7 +284,7 @@ void CommandProcessorManager::RegisterMMIO(Core::System& system, MMIO::Mapping*
{ {
fifo_rw_distance_hi_r = MMIO::ComplexRead<u16>([](Core::System& system, u32) { fifo_rw_distance_hi_r = MMIO::ComplexRead<u16>([](Core::System& system, u32) {
const auto& fifo = system.GetCommandProcessor().GetFifo(); const auto& fifo = system.GetCommandProcessor().GetFifo();
system.GetFifo().SyncGPUForRegisterAccess(); system.GetFifo().SyncGPUForRegisterAccess(system);
if (fifo.CPWritePointer.load(std::memory_order_relaxed) >= if (fifo.CPWritePointer.load(std::memory_order_relaxed) >=
fifo.SafeCPReadPointer.load(std::memory_order_relaxed)) fifo.SafeCPReadPointer.load(std::memory_order_relaxed))
{ {
@ -306,16 +306,16 @@ void CommandProcessorManager::RegisterMMIO(Core::System& system, MMIO::Mapping*
{ {
fifo_rw_distance_hi_r = MMIO::ComplexRead<u16>([](Core::System& system, u32) { fifo_rw_distance_hi_r = MMIO::ComplexRead<u16>([](Core::System& system, u32) {
const auto& fifo = system.GetCommandProcessor().GetFifo(); const auto& fifo = system.GetCommandProcessor().GetFifo();
system.GetFifo().SyncGPUForRegisterAccess(); system.GetFifo().SyncGPUForRegisterAccess(system);
return fifo.CPReadWriteDistance.load(std::memory_order_relaxed) >> 16; return fifo.CPReadWriteDistance.load(std::memory_order_relaxed) >> 16;
}); });
} }
mmio->Register(base | FIFO_RW_DISTANCE_HI, fifo_rw_distance_hi_r, mmio->Register(base | FIFO_RW_DISTANCE_HI, fifo_rw_distance_hi_r,
MMIO::ComplexWrite<u16>([WMASK_HI_RESTRICT](Core::System& system, u32, u16 val) { MMIO::ComplexWrite<u16>([WMASK_HI_RESTRICT](Core::System& system, u32, u16 val) {
auto& fifo = system.GetCommandProcessor().GetFifo(); auto& fifo = system.GetCommandProcessor().GetFifo();
system.GetFifo().SyncGPUForRegisterAccess(); system.GetFifo().SyncGPUForRegisterAccess(system);
WriteHigh(fifo.CPReadWriteDistance, val & WMASK_HI_RESTRICT); WriteHigh(fifo.CPReadWriteDistance, val & WMASK_HI_RESTRICT);
system.GetFifo().RunGpu(); system.GetFifo().RunGpu(system);
})); }));
mmio->Register( mmio->Register(
@ -330,12 +330,12 @@ void CommandProcessorManager::RegisterMMIO(Core::System& system, MMIO::Mapping*
{ {
fifo_read_hi_r = MMIO::ComplexRead<u16>([](Core::System& system, u32) { fifo_read_hi_r = MMIO::ComplexRead<u16>([](Core::System& system, u32) {
auto& fifo = system.GetCommandProcessor().GetFifo(); auto& fifo = system.GetCommandProcessor().GetFifo();
system.GetFifo().SyncGPUForRegisterAccess(); system.GetFifo().SyncGPUForRegisterAccess(system);
return fifo.SafeCPReadPointer.load(std::memory_order_relaxed) >> 16; return fifo.SafeCPReadPointer.load(std::memory_order_relaxed) >> 16;
}); });
fifo_read_hi_w = MMIO::ComplexWrite<u16>([WMASK_HI_RESTRICT](Core::System& sys, u32, u16 val) { fifo_read_hi_w = MMIO::ComplexWrite<u16>([WMASK_HI_RESTRICT](Core::System& sys, u32, u16 val) {
auto& fifo = sys.GetCommandProcessor().GetFifo(); auto& fifo = sys.GetCommandProcessor().GetFifo();
sys.GetFifo().SyncGPUForRegisterAccess(); sys.GetFifo().SyncGPUForRegisterAccess(sys);
WriteHigh(fifo.CPReadPointer, val & WMASK_HI_RESTRICT); WriteHigh(fifo.CPReadPointer, val & WMASK_HI_RESTRICT);
fifo.SafeCPReadPointer.store(fifo.CPReadPointer.load(std::memory_order_relaxed), fifo.SafeCPReadPointer.store(fifo.CPReadPointer.load(std::memory_order_relaxed),
std::memory_order_relaxed); std::memory_order_relaxed);
@ -345,12 +345,12 @@ void CommandProcessorManager::RegisterMMIO(Core::System& system, MMIO::Mapping*
{ {
fifo_read_hi_r = MMIO::ComplexRead<u16>([](Core::System& system, u32) { fifo_read_hi_r = MMIO::ComplexRead<u16>([](Core::System& system, u32) {
const auto& fifo = system.GetCommandProcessor().GetFifo(); const auto& fifo = system.GetCommandProcessor().GetFifo();
system.GetFifo().SyncGPUForRegisterAccess(); system.GetFifo().SyncGPUForRegisterAccess(system);
return fifo.CPReadPointer.load(std::memory_order_relaxed) >> 16; return fifo.CPReadPointer.load(std::memory_order_relaxed) >> 16;
}); });
fifo_read_hi_w = MMIO::ComplexWrite<u16>([WMASK_HI_RESTRICT](Core::System& sys, u32, u16 val) { fifo_read_hi_w = MMIO::ComplexWrite<u16>([WMASK_HI_RESTRICT](Core::System& sys, u32, u16 val) {
auto& fifo = sys.GetCommandProcessor().GetFifo(); auto& fifo = sys.GetCommandProcessor().GetFifo();
sys.GetFifo().SyncGPUForRegisterAccess(); sys.GetFifo().SyncGPUForRegisterAccess(sys);
WriteHigh(fifo.CPReadPointer, val & WMASK_HI_RESTRICT); WriteHigh(fifo.CPReadPointer, val & WMASK_HI_RESTRICT);
}); });
} }
@ -374,10 +374,10 @@ void CommandProcessorManager::GatherPipeBursted(Core::System& system)
(ProcessorInterface::Fifo_CPUBase == fifo.CPBase.load(std::memory_order_relaxed)) && (ProcessorInterface::Fifo_CPUBase == fifo.CPBase.load(std::memory_order_relaxed)) &&
fifo.CPReadWriteDistance.load(std::memory_order_relaxed) > 0) fifo.CPReadWriteDistance.load(std::memory_order_relaxed) > 0)
{ {
system.GetFifo().FlushGpu(); system.GetFifo().FlushGpu(system);
} }
} }
system.GetFifo().RunGpu(); system.GetFifo().RunGpu(system);
return; return;
} }
@ -405,7 +405,7 @@ void CommandProcessorManager::GatherPipeBursted(Core::System& system)
fifo.CPReadWriteDistance.fetch_add(GPFifo::GATHER_PIPE_SIZE, std::memory_order_seq_cst); fifo.CPReadWriteDistance.fetch_add(GPFifo::GATHER_PIPE_SIZE, std::memory_order_seq_cst);
system.GetFifo().RunGpu(); system.GetFifo().RunGpu(system);
ASSERT_MSG(COMMANDPROCESSOR, ASSERT_MSG(COMMANDPROCESSOR,
fifo.CPReadWriteDistance.load(std::memory_order_relaxed) <= fifo.CPReadWriteDistance.load(std::memory_order_relaxed) <=
@ -442,7 +442,7 @@ void CommandProcessorManager::UpdateInterrupts(Core::System& system, u64 userdat
} }
system.GetCoreTiming().ForceExceptionCheck(0); system.GetCoreTiming().ForceExceptionCheck(0);
m_interrupt_waiting.Clear(); m_interrupt_waiting.Clear();
system.GetFifo().RunGpu(); system.GetFifo().RunGpu(system);
} }
void CommandProcessorManager::UpdateInterruptsFromVideoBackend(Core::System& system, u64 userdata) void CommandProcessorManager::UpdateInterruptsFromVideoBackend(Core::System& system, u64 userdata)
@ -583,7 +583,7 @@ void CommandProcessorManager::SetCpStatusRegister(Core::System& system)
(fifo.CPReadPointer.load(std::memory_order_relaxed) == (fifo.CPReadPointer.load(std::memory_order_relaxed) ==
fifo.CPWritePointer.load(std::memory_order_relaxed)); fifo.CPWritePointer.load(std::memory_order_relaxed));
m_cp_status_reg.CommandIdle = !fifo.CPReadWriteDistance.load(std::memory_order_relaxed) || m_cp_status_reg.CommandIdle = !fifo.CPReadWriteDistance.load(std::memory_order_relaxed) ||
system.GetFifo().AtBreakpoint() || Fifo::AtBreakpoint(system) ||
!fifo.bFF_GPReadEnable.load(std::memory_order_relaxed); !fifo.bFF_GPReadEnable.load(std::memory_order_relaxed);
m_cp_status_reg.UnderflowLoWatermark = fifo.bFF_LoWatermark.load(std::memory_order_relaxed); m_cp_status_reg.UnderflowLoWatermark = fifo.bFF_LoWatermark.load(std::memory_order_relaxed);
m_cp_status_reg.OverflowHiWatermark = fifo.bFF_HiWatermark.load(std::memory_order_relaxed); m_cp_status_reg.OverflowHiWatermark = fifo.bFF_HiWatermark.load(std::memory_order_relaxed);
@ -610,7 +610,7 @@ void CommandProcessorManager::SetCpControlRegister(Core::System& system)
if (fifo.bFF_GPReadEnable.load(std::memory_order_relaxed) && !m_cp_ctrl_reg.GPReadEnable) if (fifo.bFF_GPReadEnable.load(std::memory_order_relaxed) && !m_cp_ctrl_reg.GPReadEnable)
{ {
fifo.bFF_GPReadEnable.store(m_cp_ctrl_reg.GPReadEnable, std::memory_order_relaxed); fifo.bFF_GPReadEnable.store(m_cp_ctrl_reg.GPReadEnable, std::memory_order_relaxed);
system.GetFifo().FlushGpu(); system.GetFifo().FlushGpu(system);
} }
else else
{ {

View File

@ -64,14 +64,14 @@ void FifoManager::DoState(PointerWrap& p)
p.Do(m_syncing_suspended); p.Do(m_syncing_suspended);
} }
void FifoManager::PauseAndLock(bool doLock, bool unpauseOnUnlock) void FifoManager::PauseAndLock(Core::System& system, bool doLock, bool unpauseOnUnlock)
{ {
if (doLock) if (doLock)
{ {
SyncGPU(SyncGPUReason::Other); SyncGPU(SyncGPUReason::Other);
EmulatorState(false); EmulatorState(false);
if (!Core::System::GetInstance().IsDualCoreMode() || m_use_deterministic_gpu_thread) if (!system.IsDualCoreMode() || m_use_deterministic_gpu_thread)
return; return;
m_gpu_mainloop.WaitYield(std::chrono::milliseconds(100), Host_YieldToUI); m_gpu_mainloop.WaitYield(std::chrono::milliseconds(100), Host_YieldToUI);
@ -83,7 +83,7 @@ void FifoManager::PauseAndLock(bool doLock, bool unpauseOnUnlock)
} }
} }
void FifoManager::Init() void FifoManager::Init(Core::System& system)
{ {
if (!m_config_callback_id) if (!m_config_callback_id)
m_config_callback_id = Config::AddConfigChangedCallback([this] { RefreshConfig(); }); m_config_callback_id = Config::AddConfigChangedCallback([this] { RefreshConfig(); });
@ -92,7 +92,7 @@ void FifoManager::Init()
// Padded so that SIMD overreads in the vertex loader are safe // Padded so that SIMD overreads in the vertex loader are safe
m_video_buffer = static_cast<u8*>(Common::AllocateMemoryPages(FIFO_SIZE + 4)); m_video_buffer = static_cast<u8*>(Common::AllocateMemoryPages(FIFO_SIZE + 4));
ResetVideoBuffer(); ResetVideoBuffer();
if (Core::System::GetInstance().IsDualCoreMode()) if (system.IsDualCoreMode())
m_gpu_mainloop.Prepare(); m_gpu_mainloop.Prepare();
m_sync_ticks.store(0); m_sync_ticks.store(0);
} }
@ -120,15 +120,14 @@ void FifoManager::Shutdown()
// May be executed from any thread, even the graphics thread. // May be executed from any thread, even the graphics thread.
// Created to allow for self shutdown. // Created to allow for self shutdown.
void FifoManager::ExitGpuLoop() void FifoManager::ExitGpuLoop(Core::System& system)
{ {
auto& system = Core::System::GetInstance();
auto& command_processor = system.GetCommandProcessor(); auto& command_processor = system.GetCommandProcessor();
auto& fifo = command_processor.GetFifo(); auto& fifo = command_processor.GetFifo();
// This should break the wait loop in CPU thread // This should break the wait loop in CPU thread
fifo.bFF_GPReadEnable.store(0, std::memory_order_relaxed); fifo.bFF_GPReadEnable.store(0, std::memory_order_relaxed);
FlushGpu(); FlushGpu(system);
// Terminate GPU thread loop // Terminate GPU thread loop
m_emu_running_state.Set(); m_emu_running_state.Set();
@ -212,7 +211,7 @@ void* FifoManager::PopFifoAuxBuffer(size_t size)
} }
// Description: RunGpuLoop() sends data through this function. // Description: RunGpuLoop() sends data through this function.
void FifoManager::ReadDataFromFifo(u32 readPtr) void FifoManager::ReadDataFromFifo(Core::System& system, u32 readPtr)
{ {
if (GPFifo::GATHER_PIPE_SIZE > if (GPFifo::GATHER_PIPE_SIZE >
static_cast<size_t>(m_video_buffer + FIFO_SIZE - m_video_buffer_write_ptr)) static_cast<size_t>(m_video_buffer + FIFO_SIZE - m_video_buffer_write_ptr))
@ -229,14 +228,13 @@ void FifoManager::ReadDataFromFifo(u32 readPtr)
m_video_buffer_read_ptr = m_video_buffer; m_video_buffer_read_ptr = m_video_buffer;
} }
// Copy new video instructions to m_video_buffer for future use in rendering the new picture // Copy new video instructions to m_video_buffer for future use in rendering the new picture
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory(); auto& memory = system.GetMemory();
memory.CopyFromEmu(m_video_buffer_write_ptr, readPtr, GPFifo::GATHER_PIPE_SIZE); memory.CopyFromEmu(m_video_buffer_write_ptr, readPtr, GPFifo::GATHER_PIPE_SIZE);
m_video_buffer_write_ptr += GPFifo::GATHER_PIPE_SIZE; m_video_buffer_write_ptr += GPFifo::GATHER_PIPE_SIZE;
} }
// The deterministic_gpu_thread version. // The deterministic_gpu_thread version.
void FifoManager::ReadDataFromFifoOnCPU(u32 readPtr) void FifoManager::ReadDataFromFifoOnCPU(Core::System& system, u32 readPtr)
{ {
u8* write_ptr = m_video_buffer_write_ptr; u8* write_ptr = m_video_buffer_write_ptr;
if (GPFifo::GATHER_PIPE_SIZE > static_cast<size_t>(m_video_buffer + FIFO_SIZE - write_ptr)) if (GPFifo::GATHER_PIPE_SIZE > static_cast<size_t>(m_video_buffer + FIFO_SIZE - write_ptr))
@ -264,7 +262,6 @@ void FifoManager::ReadDataFromFifoOnCPU(u32 readPtr)
return; return;
} }
} }
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory(); auto& memory = system.GetMemory();
memory.CopyFromEmu(m_video_buffer_write_ptr, readPtr, GPFifo::GATHER_PIPE_SIZE); memory.CopyFromEmu(m_video_buffer_write_ptr, readPtr, GPFifo::GATHER_PIPE_SIZE);
m_video_buffer_pp_read_ptr = OpcodeDecoder::RunFifo<true>( m_video_buffer_pp_read_ptr = OpcodeDecoder::RunFifo<true>(
@ -285,13 +282,13 @@ void FifoManager::ResetVideoBuffer()
// Description: Main FIFO update loop // Description: Main FIFO update loop
// Purpose: Keep the Core HW updated about the CPU-GPU distance // Purpose: Keep the Core HW updated about the CPU-GPU distance
void FifoManager::RunGpuLoop() void FifoManager::RunGpuLoop(Core::System& system)
{ {
AsyncRequests::GetInstance()->SetEnable(true); AsyncRequests::GetInstance()->SetEnable(true);
AsyncRequests::GetInstance()->SetPassthrough(false); AsyncRequests::GetInstance()->SetPassthrough(false);
m_gpu_mainloop.Run( m_gpu_mainloop.Run(
[this] { [this, &system] {
// Run events from the CPU thread. // Run events from the CPU thread.
AsyncRequests::GetInstance()->PullEvents(); AsyncRequests::GetInstance()->PullEvents();
@ -314,7 +311,6 @@ void FifoManager::RunGpuLoop()
} }
else else
{ {
auto& system = Core::System::GetInstance();
auto& command_processor = system.GetCommandProcessor(); auto& command_processor = system.GetCommandProcessor();
auto& fifo = command_processor.GetFifo(); auto& fifo = command_processor.GetFifo();
command_processor.SetCPStatusFromGPU(system); command_processor.SetCPStatusFromGPU(system);
@ -322,14 +318,14 @@ void FifoManager::RunGpuLoop()
// check if we are able to run this buffer // check if we are able to run this buffer
while (!command_processor.IsInterruptWaiting() && while (!command_processor.IsInterruptWaiting() &&
fifo.bFF_GPReadEnable.load(std::memory_order_relaxed) && fifo.bFF_GPReadEnable.load(std::memory_order_relaxed) &&
fifo.CPReadWriteDistance.load(std::memory_order_relaxed) && !AtBreakpoint()) fifo.CPReadWriteDistance.load(std::memory_order_relaxed) && !AtBreakpoint(system))
{ {
if (m_config_sync_gpu && m_sync_ticks.load() < m_config_sync_gpu_min_distance) if (m_config_sync_gpu && m_sync_ticks.load() < m_config_sync_gpu_min_distance)
break; break;
u32 cyclesExecuted = 0; u32 cyclesExecuted = 0;
u32 readPtr = fifo.CPReadPointer.load(std::memory_order_relaxed); u32 readPtr = fifo.CPReadPointer.load(std::memory_order_relaxed);
ReadDataFromFifo(readPtr); ReadDataFromFifo(system, readPtr);
if (readPtr == fifo.CPEnd.load(std::memory_order_relaxed)) if (readPtr == fifo.CPEnd.load(std::memory_order_relaxed))
readPtr = fifo.CPBase.load(std::memory_order_relaxed); readPtr = fifo.CPBase.load(std::memory_order_relaxed);
@ -396,9 +392,9 @@ void FifoManager::RunGpuLoop()
AsyncRequests::GetInstance()->SetPassthrough(true); AsyncRequests::GetInstance()->SetPassthrough(true);
} }
void FifoManager::FlushGpu() void FifoManager::FlushGpu(Core::System& system)
{ {
if (!Core::System::GetInstance().IsDualCoreMode() || m_use_deterministic_gpu_thread) if (!system.IsDualCoreMode() || m_use_deterministic_gpu_thread)
return; return;
m_gpu_mainloop.Wait(); m_gpu_mainloop.Wait();
@ -409,9 +405,8 @@ void FifoManager::GpuMaySleep()
m_gpu_mainloop.AllowSleep(); m_gpu_mainloop.AllowSleep();
} }
bool FifoManager::AtBreakpoint() const bool AtBreakpoint(Core::System& system)
{ {
auto& system = Core::System::GetInstance();
auto& command_processor = system.GetCommandProcessor(); auto& command_processor = system.GetCommandProcessor();
const auto& fifo = command_processor.GetFifo(); const auto& fifo = command_processor.GetFifo();
return fifo.bFF_BPEnable.load(std::memory_order_relaxed) && return fifo.bFF_BPEnable.load(std::memory_order_relaxed) &&
@ -419,9 +414,8 @@ bool FifoManager::AtBreakpoint() const
fifo.CPBreakpoint.load(std::memory_order_relaxed)); fifo.CPBreakpoint.load(std::memory_order_relaxed));
} }
void FifoManager::RunGpu() void FifoManager::RunGpu(Core::System& system)
{ {
auto& system = Core::System::GetInstance();
const bool is_dual_core = system.IsDualCoreMode(); const bool is_dual_core = system.IsDualCoreMode();
// wake up GPU thread // wake up GPU thread
@ -442,20 +436,19 @@ void FifoManager::RunGpu()
} }
} }
int FifoManager::RunGpuOnCpu(int ticks) int FifoManager::RunGpuOnCpu(Core::System& system, int ticks)
{ {
auto& system = Core::System::GetInstance();
auto& command_processor = system.GetCommandProcessor(); auto& command_processor = system.GetCommandProcessor();
auto& fifo = command_processor.GetFifo(); auto& fifo = command_processor.GetFifo();
bool reset_simd_state = false; bool reset_simd_state = false;
int available_ticks = int(ticks * m_config_sync_gpu_overclock) + m_sync_ticks.load(); int available_ticks = int(ticks * m_config_sync_gpu_overclock) + m_sync_ticks.load();
while (fifo.bFF_GPReadEnable.load(std::memory_order_relaxed) && while (fifo.bFF_GPReadEnable.load(std::memory_order_relaxed) &&
fifo.CPReadWriteDistance.load(std::memory_order_relaxed) && !AtBreakpoint() && fifo.CPReadWriteDistance.load(std::memory_order_relaxed) && !AtBreakpoint(system) &&
available_ticks >= 0) available_ticks >= 0)
{ {
if (m_use_deterministic_gpu_thread) if (m_use_deterministic_gpu_thread)
{ {
ReadDataFromFifoOnCPU(fifo.CPReadPointer.load(std::memory_order_relaxed)); ReadDataFromFifoOnCPU(system, fifo.CPReadPointer.load(std::memory_order_relaxed));
m_gpu_mainloop.Wakeup(); m_gpu_mainloop.Wakeup();
} }
else else
@ -466,7 +459,7 @@ int FifoManager::RunGpuOnCpu(int ticks)
FPURoundMode::LoadDefaultSIMDState(); FPURoundMode::LoadDefaultSIMDState();
reset_simd_state = true; reset_simd_state = true;
} }
ReadDataFromFifo(fifo.CPReadPointer.load(std::memory_order_relaxed)); ReadDataFromFifo(system, fifo.CPReadPointer.load(std::memory_order_relaxed));
u32 cycles = 0; u32 cycles = 0;
m_video_buffer_read_ptr = OpcodeDecoder::RunFifo( m_video_buffer_read_ptr = OpcodeDecoder::RunFifo(
DataReader(m_video_buffer_read_ptr, m_video_buffer_write_ptr), &cycles); DataReader(m_video_buffer_read_ptr, m_video_buffer_write_ptr), &cycles);
@ -505,7 +498,7 @@ int FifoManager::RunGpuOnCpu(int ticks)
return -available_ticks + GPU_TIME_SLOT_SIZE; return -available_ticks + GPU_TIME_SLOT_SIZE;
} }
void FifoManager::UpdateWantDeterminism(bool want) void FifoManager::UpdateWantDeterminism(Core::System& system, bool want)
{ {
// We are paused (or not running at all yet), so // We are paused (or not running at all yet), so
// it should be safe to change this. // it should be safe to change this.
@ -523,7 +516,7 @@ void FifoManager::UpdateWantDeterminism(bool want)
break; break;
} }
gpu_thread = gpu_thread && Core::System::GetInstance().IsDualCoreMode(); gpu_thread = gpu_thread && system.IsDualCoreMode();
if (m_use_deterministic_gpu_thread != gpu_thread) if (m_use_deterministic_gpu_thread != gpu_thread)
{ {
@ -543,7 +536,7 @@ void FifoManager::UpdateWantDeterminism(bool want)
* @ticks The gone emulated CPU time. * @ticks The gone emulated CPU time.
* @return A good time to call WaitForGpuThread() next. * @return A good time to call WaitForGpuThread() next.
*/ */
int FifoManager::WaitForGpuThread(int ticks) int FifoManager::WaitForGpuThread(Core::System& system, int ticks)
{ {
int old = m_sync_ticks.fetch_add(ticks); int old = m_sync_ticks.fetch_add(ticks);
int now = old + ticks; int now = old + ticks;
@ -554,7 +547,7 @@ int FifoManager::WaitForGpuThread(int ticks)
// Wakeup GPU // Wakeup GPU
if (old < m_config_sync_gpu_min_distance && now >= m_config_sync_gpu_min_distance) if (old < m_config_sync_gpu_min_distance && now >= m_config_sync_gpu_min_distance)
RunGpu(); RunGpu(system);
// If the GPU is still sleeping, wait for a longer time // If the GPU is still sleeping, wait for a longer time
if (now < m_config_sync_gpu_min_distance) if (now < m_config_sync_gpu_min_distance)
@ -575,11 +568,11 @@ void FifoManager::SyncGPUCallback(Core::System& system, u64 ticks, s64 cyclesLat
auto& fifo = system.GetFifo(); auto& fifo = system.GetFifo();
if (!system.IsDualCoreMode() || fifo.m_use_deterministic_gpu_thread) if (!system.IsDualCoreMode() || fifo.m_use_deterministic_gpu_thread)
{ {
next = fifo.RunGpuOnCpu((int)ticks); next = fifo.RunGpuOnCpu(system, (int)ticks);
} }
else if (fifo.m_config_sync_gpu) else if (fifo.m_config_sync_gpu)
{ {
next = fifo.WaitForGpuThread((int)ticks); next = fifo.WaitForGpuThread(system, (int)ticks);
} }
fifo.m_syncing_suspended = next < 0; fifo.m_syncing_suspended = next < 0;
@ -587,21 +580,20 @@ void FifoManager::SyncGPUCallback(Core::System& system, u64 ticks, s64 cyclesLat
system.GetCoreTiming().ScheduleEvent(next, fifo.m_event_sync_gpu, next); system.GetCoreTiming().ScheduleEvent(next, fifo.m_event_sync_gpu, next);
} }
void FifoManager::SyncGPUForRegisterAccess() void FifoManager::SyncGPUForRegisterAccess(Core::System& system)
{ {
SyncGPU(SyncGPUReason::Other); SyncGPU(SyncGPUReason::Other);
if (!Core::System::GetInstance().IsDualCoreMode() || m_use_deterministic_gpu_thread) if (!system.IsDualCoreMode() || m_use_deterministic_gpu_thread)
RunGpuOnCpu(GPU_TIME_SLOT_SIZE); RunGpuOnCpu(system, GPU_TIME_SLOT_SIZE);
else if (m_config_sync_gpu) else if (m_config_sync_gpu)
WaitForGpuThread(GPU_TIME_SLOT_SIZE); WaitForGpuThread(system, GPU_TIME_SLOT_SIZE);
} }
// Initialize GPU - CPU thread syncing, this gives us a deterministic way to start the GPU thread. // Initialize GPU - CPU thread syncing, this gives us a deterministic way to start the GPU thread.
void FifoManager::Prepare() void FifoManager::Prepare(Core::System& system)
{ {
m_event_sync_gpu = m_event_sync_gpu = system.GetCoreTiming().RegisterEvent("SyncGPUCallback", SyncGPUCallback);
Core::System::GetInstance().GetCoreTiming().RegisterEvent("SyncGPUCallback", SyncGPUCallback);
m_syncing_suspended = true; m_syncing_suspended = true;
} }
} // namespace Fifo } // namespace Fifo

View File

@ -47,12 +47,12 @@ public:
FifoManager& operator=(FifoManager&& other) = delete; FifoManager& operator=(FifoManager&& other) = delete;
~FifoManager(); ~FifoManager();
void Init(); void Init(Core::System& system);
void Shutdown(); void Shutdown();
void Prepare(); // Must be called from the CPU thread. void Prepare(Core::System& system); // Must be called from the CPU thread.
void DoState(PointerWrap& f); void DoState(PointerWrap& f);
void PauseAndLock(bool doLock, bool unpauseOnUnlock); void PauseAndLock(Core::System& system, bool doLock, bool unpauseOnUnlock);
void UpdateWantDeterminism(bool want); void UpdateWantDeterminism(Core::System& system, bool want);
bool UseDeterministicGPUThread() const { return m_use_deterministic_gpu_thread; } bool UseDeterministicGPUThread() const { return m_use_deterministic_gpu_thread; }
// In deterministic GPU thread mode this waits for the GPU to be done with pending work. // In deterministic GPU thread mode this waits for the GPU to be done with pending work.
@ -60,26 +60,25 @@ public:
// In single core mode, this runs the GPU for a single slice. // In single core mode, this runs the GPU for a single slice.
// In dual core mode, this synchronizes with the GPU thread. // In dual core mode, this synchronizes with the GPU thread.
void SyncGPUForRegisterAccess(); void SyncGPUForRegisterAccess(Core::System& system);
void PushFifoAuxBuffer(const void* ptr, size_t size); void PushFifoAuxBuffer(const void* ptr, size_t size);
void* PopFifoAuxBuffer(size_t size); void* PopFifoAuxBuffer(size_t size);
void FlushGpu(); void FlushGpu(Core::System& system);
void RunGpu(); void RunGpu(Core::System& system);
void GpuMaySleep(); void GpuMaySleep();
void RunGpuLoop(); void RunGpuLoop(Core::System& system);
void ExitGpuLoop(); void ExitGpuLoop(Core::System& system);
void EmulatorState(bool running); void EmulatorState(bool running);
bool AtBreakpoint() const;
void ResetVideoBuffer(); void ResetVideoBuffer();
private: private:
void RefreshConfig(); void RefreshConfig();
void ReadDataFromFifo(u32 readPtr); void ReadDataFromFifo(Core::System& system, u32 readPtr);
void ReadDataFromFifoOnCPU(u32 readPtr); void ReadDataFromFifoOnCPU(Core::System& system, u32 readPtr);
int RunGpuOnCpu(int ticks); int RunGpuOnCpu(Core::System& system, int ticks);
int WaitForGpuThread(int ticks); int WaitForGpuThread(Core::System& system, int ticks);
static void SyncGPUCallback(Core::System& system, u64 ticks, s64 cyclesLate); static void SyncGPUCallback(Core::System& system, u64 ticks, s64 cyclesLate);
static constexpr u32 FIFO_SIZE = 2 * 1024 * 1024; static constexpr u32 FIFO_SIZE = 2 * 1024 * 1024;
@ -127,4 +126,6 @@ private:
int m_config_sync_gpu_min_distance = 0; int m_config_sync_gpu_min_distance = 0;
float m_config_sync_gpu_overclock = 0.0f; float m_config_sync_gpu_overclock = 0.0f;
}; };
bool AtBreakpoint(Core::System& system);
} // namespace Fifo } // namespace Fifo

View File

@ -84,7 +84,7 @@ std::string VideoBackendBase::BadShaderFilename(const char* shader_stage, int co
void VideoBackendBase::Video_ExitLoop() void VideoBackendBase::Video_ExitLoop()
{ {
auto& system = Core::System::GetInstance(); auto& system = Core::System::GetInstance();
system.GetFifo().ExitGpuLoop(); system.GetFifo().ExitGpuLoop(system);
} }
// Run from the CPU thread (from VideoInterface.cpp) // Run from the CPU thread (from VideoInterface.cpp)
@ -324,7 +324,7 @@ void VideoBackendBase::InitializeShared()
auto& system = Core::System::GetInstance(); auto& system = Core::System::GetInstance();
auto& command_processor = system.GetCommandProcessor(); auto& command_processor = system.GetCommandProcessor();
command_processor.Init(system); command_processor.Init(system);
system.GetFifo().Init(); system.GetFifo().Init(system);
PixelEngine::Init(); PixelEngine::Init();
BPInit(); BPInit();
VertexLoaderManager::Init(); VertexLoaderManager::Init();