mirror of
https://github.com/izzy2lost/dolphin.git
synced 2026-06-19 01:16:48 -07:00
VideoCommon/Fifo: Refactor to class, move to Core::System.
This commit is contained in:
@@ -277,7 +277,9 @@ void Stop() // - Hammertime!
|
||||
// Dump left over jobs
|
||||
HostDispatchJobs();
|
||||
|
||||
Fifo::EmulatorState(false);
|
||||
auto& system = Core::System::GetInstance();
|
||||
|
||||
system.GetFifo().EmulatorState(false);
|
||||
|
||||
INFO_LOG_FMT(CONSOLE, "Stop [Main Thread]\t\t---- Shutting down ----");
|
||||
|
||||
@@ -285,7 +287,7 @@ void Stop() // - Hammertime!
|
||||
INFO_LOG_FMT(CONSOLE, "{}", StopMessage(true, "Stop CPU"));
|
||||
CPU::Stop();
|
||||
|
||||
if (Core::System::GetInstance().IsDualCoreMode())
|
||||
if (system.IsDualCoreMode())
|
||||
{
|
||||
// Video_EnterLoop() should now exit so that EmuThread()
|
||||
// will continue concurrently with the rest of the commands
|
||||
@@ -597,7 +599,7 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi
|
||||
wiifs_guard.Dismiss();
|
||||
|
||||
// This adds the SyncGPU handler to CoreTiming, so now CoreTiming::Advance might block.
|
||||
Fifo::Prepare();
|
||||
system.GetFifo().Prepare();
|
||||
|
||||
// Setup our core
|
||||
if (Config::Get(Config::MAIN_CPU_CORE) != PowerPC::CPUCore::Interpreter)
|
||||
@@ -622,7 +624,7 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi
|
||||
s_cpu_thread = std::thread(cpuThreadFunc, savestate_path, delete_savestate);
|
||||
|
||||
// become the GPU thread
|
||||
Fifo::RunGpuLoop();
|
||||
system.GetFifo().RunGpuLoop();
|
||||
|
||||
// We have now exited the Video Loop
|
||||
INFO_LOG_FMT(CONSOLE, "{}", StopMessage(false, "Video Loop Ended"));
|
||||
@@ -766,7 +768,8 @@ static bool PauseAndLock(bool do_lock, bool unpause_on_unlock)
|
||||
|
||||
// video has to come after CPU, because CPU thread can wait for video thread
|
||||
// (s_efbAccessRequested).
|
||||
Fifo::PauseAndLock(do_lock, false);
|
||||
auto& system = Core::System::GetInstance();
|
||||
system.GetFifo().PauseAndLock(do_lock, false);
|
||||
|
||||
ResetRumble();
|
||||
|
||||
@@ -1029,7 +1032,10 @@ void UpdateWantDeterminism(bool initial)
|
||||
const auto ios = IOS::HLE::GetIOS();
|
||||
if (ios)
|
||||
ios->UpdateWantDeterminism(new_want_determinism);
|
||||
Fifo::UpdateWantDeterminism(new_want_determinism);
|
||||
|
||||
auto& system = Core::System::GetInstance();
|
||||
system.GetFifo().UpdateWantDeterminism(new_want_determinism);
|
||||
|
||||
// We need to clear the cache because some parts of the JIT depend on want_determinism,
|
||||
// e.g. use of FMA.
|
||||
JitInterface::ClearCache();
|
||||
|
||||
@@ -354,7 +354,8 @@ void CoreTimingManager::Idle()
|
||||
// When the FIFO is processing data we must not advance because in this way
|
||||
// the VI will be desynchronized. So, We are waiting until the FIFO finish and
|
||||
// while we process only the events required by the FIFO.
|
||||
Fifo::FlushGpu();
|
||||
auto& system = Core::System::GetInstance();
|
||||
system.GetFifo().FlushGpu();
|
||||
}
|
||||
|
||||
PowerPC::UpdatePerformanceMonitor(PowerPC::ppcState.downcount, 0, 0);
|
||||
|
||||
@@ -191,7 +191,8 @@ void Run()
|
||||
static void RunAdjacentSystems(bool running)
|
||||
{
|
||||
// NOTE: We're assuming these will not try to call Break or EnableStepping.
|
||||
Fifo::EmulatorState(running);
|
||||
auto& system = Core::System::GetInstance();
|
||||
system.GetFifo().EmulatorState(running);
|
||||
// Core is responsible for shutting down the sound stream.
|
||||
if (s_state != State::PowerDown)
|
||||
AudioCommon::SetSoundStreamRunning(Core::System::GetInstance(), running);
|
||||
|
||||
@@ -173,7 +173,7 @@ void PatchEngineCallback(Core::System& system, u64 userdata, s64 cycles_late)
|
||||
void ThrottleCallback(Core::System& system, u64 deadline, s64 cyclesLate)
|
||||
{
|
||||
// Allow the GPU thread to sleep. Setting this flag here limits the wakeups to 1 kHz.
|
||||
Fifo::GpuMaySleep();
|
||||
system.GetFifo().GpuMaySleep();
|
||||
|
||||
const u64 time = Common::Timer::NowUs();
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "Core/HW/Sram.h"
|
||||
#include "Core/HW/VideoInterface.h"
|
||||
#include "VideoCommon/CommandProcessor.h"
|
||||
#include "VideoCommon/Fifo.h"
|
||||
|
||||
namespace Core
|
||||
{
|
||||
@@ -35,6 +36,7 @@ struct System::Impl
|
||||
DVDInterface::DVDInterfaceState m_dvd_interface_state;
|
||||
DVDThread::DVDThreadState m_dvd_thread_state;
|
||||
ExpansionInterface::ExpansionInterfaceState m_expansion_interface_state;
|
||||
Fifo::FifoManager m_fifo;
|
||||
Memory::MemoryManager m_memory;
|
||||
MemoryInterface::MemoryInterfaceState m_memory_interface_state;
|
||||
SerialInterface::SerialInterfaceState m_serial_interface_state;
|
||||
@@ -120,6 +122,11 @@ ExpansionInterface::ExpansionInterfaceState& System::GetExpansionInterfaceState(
|
||||
return m_impl->m_expansion_interface_state;
|
||||
}
|
||||
|
||||
Fifo::FifoManager& System::GetFifo() const
|
||||
{
|
||||
return m_impl->m_fifo;
|
||||
}
|
||||
|
||||
Memory::MemoryManager& System::GetMemory() const
|
||||
{
|
||||
return m_impl->m_memory;
|
||||
|
||||
@@ -36,6 +36,10 @@ namespace ExpansionInterface
|
||||
{
|
||||
class ExpansionInterfaceState;
|
||||
};
|
||||
namespace Fifo
|
||||
{
|
||||
class FifoManager;
|
||||
}
|
||||
namespace Memory
|
||||
{
|
||||
class MemoryManager;
|
||||
@@ -94,6 +98,7 @@ public:
|
||||
DVDInterface::DVDInterfaceState& GetDVDInterfaceState() const;
|
||||
DVDThread::DVDThreadState& GetDVDThreadState() const;
|
||||
ExpansionInterface::ExpansionInterfaceState& GetExpansionInterfaceState() const;
|
||||
Fifo::FifoManager& GetFifo() const;
|
||||
Memory::MemoryManager& GetMemory() const;
|
||||
MemoryInterface::MemoryInterfaceState& GetMemoryInterfaceState() const;
|
||||
SerialInterface::SerialInterfaceState& GetSerialInterfaceState() const;
|
||||
|
||||
@@ -114,9 +114,10 @@ static void RunWithGPUThreadInactive(std::function<void()> f)
|
||||
// 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;
|
||||
Fifo::PauseAndLock(true, was_running);
|
||||
auto& fifo = Core::System::GetInstance().GetFifo();
|
||||
fifo.PauseAndLock(true, was_running);
|
||||
f();
|
||||
Fifo::PauseAndLock(false, was_running);
|
||||
fifo.PauseAndLock(false, was_running);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include "Core/System.h"
|
||||
#include "VideoCommon/Fifo.h"
|
||||
#include "VideoCommon/RenderBase.h"
|
||||
#include "VideoCommon/Statistics.h"
|
||||
@@ -90,7 +91,8 @@ void AsyncRequests::PushEvent(const AsyncRequests::Event& event, bool blocking)
|
||||
|
||||
m_queue.push(event);
|
||||
|
||||
Fifo::RunGpu();
|
||||
auto& system = Core::System::GetInstance();
|
||||
system.GetFifo().RunGpu();
|
||||
if (blocking)
|
||||
{
|
||||
m_cond.wait(lock, [this] { return m_queue.empty(); });
|
||||
@@ -159,7 +161,7 @@ void AsyncRequests::HandleEvent(const AsyncRequests::Event& e)
|
||||
break;
|
||||
|
||||
case Event::FIFO_RESET:
|
||||
Fifo::ResetVideoBuffer();
|
||||
Core::System::GetInstance().GetFifo().ResetVideoBuffer();
|
||||
break;
|
||||
|
||||
case Event::PERF_QUERY:
|
||||
|
||||
@@ -179,14 +179,17 @@ static void BPWritten(const BPCmd& bp, int cycles_into_future)
|
||||
switch (bp.newvalue & 0xFF)
|
||||
{
|
||||
case 0x02:
|
||||
{
|
||||
INCSTAT(g_stats.this_frame.num_draw_done);
|
||||
g_texture_cache->FlushEFBCopies();
|
||||
g_framebuffer_manager->InvalidatePeekCache(false);
|
||||
g_framebuffer_manager->RefreshPeekCache();
|
||||
if (!Fifo::UseDeterministicGPUThread())
|
||||
auto& system = Core::System::GetInstance();
|
||||
if (!system.GetFifo().UseDeterministicGPUThread())
|
||||
PixelEngine::SetFinish(cycles_into_future); // may generate interrupt
|
||||
DEBUG_LOG_FMT(VIDEO, "GXSetDrawDone SetPEFinish (value: {:#04X})", bp.newvalue & 0xFFFF);
|
||||
return;
|
||||
}
|
||||
|
||||
default:
|
||||
WARN_LOG_FMT(VIDEO, "GXSetDrawDone ??? (value {:#04X})", bp.newvalue & 0xFFFF);
|
||||
@@ -194,23 +197,29 @@ static void BPWritten(const BPCmd& bp, int cycles_into_future)
|
||||
}
|
||||
return;
|
||||
case BPMEM_PE_TOKEN_ID: // Pixel Engine Token ID
|
||||
{
|
||||
INCSTAT(g_stats.this_frame.num_token);
|
||||
g_texture_cache->FlushEFBCopies();
|
||||
g_framebuffer_manager->InvalidatePeekCache(false);
|
||||
g_framebuffer_manager->RefreshPeekCache();
|
||||
if (!Fifo::UseDeterministicGPUThread())
|
||||
auto& system = Core::System::GetInstance();
|
||||
if (!system.GetFifo().UseDeterministicGPUThread())
|
||||
PixelEngine::SetToken(static_cast<u16>(bp.newvalue & 0xFFFF), false, cycles_into_future);
|
||||
DEBUG_LOG_FMT(VIDEO, "SetPEToken {:#06X}", bp.newvalue & 0xFFFF);
|
||||
return;
|
||||
}
|
||||
case BPMEM_PE_TOKEN_INT_ID: // Pixel Engine Interrupt Token ID
|
||||
{
|
||||
INCSTAT(g_stats.this_frame.num_token_int);
|
||||
g_texture_cache->FlushEFBCopies();
|
||||
g_framebuffer_manager->InvalidatePeekCache(false);
|
||||
g_framebuffer_manager->RefreshPeekCache();
|
||||
if (!Fifo::UseDeterministicGPUThread())
|
||||
auto& system = Core::System::GetInstance();
|
||||
if (!system.GetFifo().UseDeterministicGPUThread())
|
||||
PixelEngine::SetToken(static_cast<u16>(bp.newvalue & 0xFFFF), true, cycles_into_future);
|
||||
DEBUG_LOG_FMT(VIDEO, "SetPEToken + INT {:#06X}", bp.newvalue & 0xFFFF);
|
||||
return;
|
||||
}
|
||||
|
||||
// ------------------------
|
||||
// EFB copy command. This copies a rectangle from the EFB to either RAM in a texture format or to
|
||||
|
||||
@@ -223,8 +223,8 @@ void CommandProcessorManager::RegisterMMIO(Core::System& system, MMIO::Mapping*
|
||||
|
||||
mmio->Register(base | STATUS_REGISTER, MMIO::ComplexRead<u16>([](Core::System& system, u32) {
|
||||
auto& cp = system.GetCommandProcessor();
|
||||
Fifo::SyncGPUForRegisterAccess();
|
||||
cp.SetCpStatusRegister();
|
||||
system.GetFifo().SyncGPUForRegisterAccess();
|
||||
cp.SetCpStatusRegister(system);
|
||||
return cp.m_cp_status_reg.Hex;
|
||||
}),
|
||||
MMIO::InvalidWrite<u16>());
|
||||
@@ -234,8 +234,8 @@ void CommandProcessorManager::RegisterMMIO(Core::System& system, MMIO::Mapping*
|
||||
auto& cp = system.GetCommandProcessor();
|
||||
UCPCtrlReg tmp(val);
|
||||
cp.m_cp_ctrl_reg.Hex = tmp.Hex;
|
||||
cp.SetCpControlRegister();
|
||||
Fifo::RunGpu();
|
||||
cp.SetCpControlRegister(system);
|
||||
system.GetFifo().RunGpu();
|
||||
}));
|
||||
|
||||
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);
|
||||
cp.m_cp_clear_reg.Hex = tmp.Hex;
|
||||
cp.SetCpClearRegister();
|
||||
Fifo::RunGpu();
|
||||
system.GetFifo().RunGpu();
|
||||
}));
|
||||
|
||||
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) {
|
||||
const auto& fifo = system.GetCommandProcessor().GetFifo();
|
||||
Fifo::SyncGPUForRegisterAccess();
|
||||
system.GetFifo().SyncGPUForRegisterAccess();
|
||||
if (fifo.CPWritePointer.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) {
|
||||
const auto& fifo = system.GetCommandProcessor().GetFifo();
|
||||
Fifo::SyncGPUForRegisterAccess();
|
||||
system.GetFifo().SyncGPUForRegisterAccess();
|
||||
return fifo.CPReadWriteDistance.load(std::memory_order_relaxed) >> 16;
|
||||
});
|
||||
}
|
||||
mmio->Register(base | FIFO_RW_DISTANCE_HI, fifo_rw_distance_hi_r,
|
||||
MMIO::ComplexWrite<u16>([WMASK_HI_RESTRICT](Core::System& system, u32, u16 val) {
|
||||
auto& fifo = system.GetCommandProcessor().GetFifo();
|
||||
Fifo::SyncGPUForRegisterAccess();
|
||||
system.GetFifo().SyncGPUForRegisterAccess();
|
||||
WriteHigh(fifo.CPReadWriteDistance, val & WMASK_HI_RESTRICT);
|
||||
Fifo::RunGpu();
|
||||
system.GetFifo().RunGpu();
|
||||
}));
|
||||
|
||||
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) {
|
||||
auto& fifo = system.GetCommandProcessor().GetFifo();
|
||||
Fifo::SyncGPUForRegisterAccess();
|
||||
system.GetFifo().SyncGPUForRegisterAccess();
|
||||
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) {
|
||||
auto& fifo = sys.GetCommandProcessor().GetFifo();
|
||||
Fifo::SyncGPUForRegisterAccess();
|
||||
sys.GetFifo().SyncGPUForRegisterAccess();
|
||||
WriteHigh(fifo.CPReadPointer, val & WMASK_HI_RESTRICT);
|
||||
fifo.SafeCPReadPointer.store(fifo.CPReadPointer.load(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) {
|
||||
const auto& fifo = system.GetCommandProcessor().GetFifo();
|
||||
Fifo::SyncGPUForRegisterAccess();
|
||||
system.GetFifo().SyncGPUForRegisterAccess();
|
||||
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) {
|
||||
auto& fifo = sys.GetCommandProcessor().GetFifo();
|
||||
Fifo::SyncGPUForRegisterAccess();
|
||||
sys.GetFifo().SyncGPUForRegisterAccess();
|
||||
WriteHigh(fifo.CPReadPointer, val & WMASK_HI_RESTRICT);
|
||||
});
|
||||
}
|
||||
@@ -366,7 +366,7 @@ void CommandProcessorManager::GatherPipeBursted(Core::System& system)
|
||||
// if we aren't linked, we don't care about gather pipe data
|
||||
if (!m_cp_ctrl_reg.GPLinkEnable)
|
||||
{
|
||||
if (IsOnThread(system) && !Fifo::UseDeterministicGPUThread())
|
||||
if (IsOnThread(system) && !system.GetFifo().UseDeterministicGPUThread())
|
||||
{
|
||||
// In multibuffer mode is not allowed write in the same FIFO attached to the GPU.
|
||||
// Fix Pokemon XD in DC mode.
|
||||
@@ -374,10 +374,10 @@ void CommandProcessorManager::GatherPipeBursted(Core::System& system)
|
||||
(ProcessorInterface::Fifo_CPUBase == fifo.CPBase.load(std::memory_order_relaxed)) &&
|
||||
fifo.CPReadWriteDistance.load(std::memory_order_relaxed) > 0)
|
||||
{
|
||||
Fifo::FlushGpu();
|
||||
system.GetFifo().FlushGpu();
|
||||
}
|
||||
}
|
||||
Fifo::RunGpu();
|
||||
system.GetFifo().RunGpu();
|
||||
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::RunGpu();
|
||||
system.GetFifo().RunGpu();
|
||||
|
||||
ASSERT_MSG(COMMANDPROCESSOR,
|
||||
fifo.CPReadWriteDistance.load(std::memory_order_relaxed) <=
|
||||
@@ -442,12 +442,12 @@ void CommandProcessorManager::UpdateInterrupts(Core::System& system, u64 userdat
|
||||
}
|
||||
system.GetCoreTiming().ForceExceptionCheck(0);
|
||||
m_interrupt_waiting.Clear();
|
||||
Fifo::RunGpu();
|
||||
system.GetFifo().RunGpu();
|
||||
}
|
||||
|
||||
void CommandProcessorManager::UpdateInterruptsFromVideoBackend(Core::System& system, u64 userdata)
|
||||
{
|
||||
if (!Fifo::UseDeterministicGPUThread())
|
||||
if (!system.GetFifo().UseDeterministicGPUThread())
|
||||
{
|
||||
system.GetCoreTiming().ScheduleEvent(0, m_event_type_update_interrupts, userdata,
|
||||
CoreTiming::FromThread::NON_CPU);
|
||||
@@ -573,7 +573,7 @@ void CommandProcessorManager::SetCPStatusFromCPU(Core::System& system)
|
||||
}
|
||||
}
|
||||
|
||||
void CommandProcessorManager::SetCpStatusRegister()
|
||||
void CommandProcessorManager::SetCpStatusRegister(Core::System& system)
|
||||
{
|
||||
const auto& fifo = m_fifo;
|
||||
|
||||
@@ -583,7 +583,7 @@ void CommandProcessorManager::SetCpStatusRegister()
|
||||
(fifo.CPReadPointer.load(std::memory_order_relaxed) ==
|
||||
fifo.CPWritePointer.load(std::memory_order_relaxed));
|
||||
m_cp_status_reg.CommandIdle = !fifo.CPReadWriteDistance.load(std::memory_order_relaxed) ||
|
||||
Fifo::AtBreakpoint() ||
|
||||
system.GetFifo().AtBreakpoint() ||
|
||||
!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.OverflowHiWatermark = fifo.bFF_HiWatermark.load(std::memory_order_relaxed);
|
||||
@@ -597,7 +597,7 @@ void CommandProcessorManager::SetCpStatusRegister()
|
||||
m_cp_status_reg.UnderflowLoWatermark ? "ON" : "OFF");
|
||||
}
|
||||
|
||||
void CommandProcessorManager::SetCpControlRegister()
|
||||
void CommandProcessorManager::SetCpControlRegister(Core::System& system)
|
||||
{
|
||||
auto& fifo = m_fifo;
|
||||
|
||||
@@ -610,7 +610,7 @@ void CommandProcessorManager::SetCpControlRegister()
|
||||
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::FlushGpu();
|
||||
system.GetFifo().FlushGpu();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -174,8 +174,8 @@ public:
|
||||
bool IsInterruptWaiting() const;
|
||||
|
||||
void SetCpClearRegister();
|
||||
void SetCpControlRegister();
|
||||
void SetCpStatusRegister();
|
||||
void SetCpControlRegister(Core::System& system);
|
||||
void SetCpStatusRegister(Core::System& system);
|
||||
|
||||
void HandleUnknownOpcode(u8 cmd_byte, const u8* buffer, bool preprocess);
|
||||
|
||||
|
||||
+173
-216
File diff suppressed because it is too large
Load Diff
+102
-23
@@ -3,21 +3,28 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <cstddef>
|
||||
#include <optional>
|
||||
|
||||
#include "Common/BlockingLoop.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/Event.h"
|
||||
#include "Common/Flag.h"
|
||||
|
||||
class PointerWrap;
|
||||
|
||||
namespace Core
|
||||
{
|
||||
class System;
|
||||
}
|
||||
namespace CoreTiming
|
||||
{
|
||||
struct EventType;
|
||||
}
|
||||
|
||||
namespace Fifo
|
||||
{
|
||||
void Init();
|
||||
void Shutdown();
|
||||
void Prepare(); // Must be called from the CPU thread.
|
||||
void DoState(PointerWrap& f);
|
||||
void PauseAndLock(bool doLock, bool unpauseOnUnlock);
|
||||
void UpdateWantDeterminism(bool want);
|
||||
bool UseDeterministicGPUThread();
|
||||
|
||||
// Used for diagnostics.
|
||||
enum class SyncGPUReason
|
||||
{
|
||||
@@ -29,23 +36,95 @@ enum class SyncGPUReason
|
||||
Swap,
|
||||
AuxSpace,
|
||||
};
|
||||
// In deterministic GPU thread mode this waits for the GPU to be done with pending work.
|
||||
void SyncGPU(SyncGPUReason reason, bool may_move_read_ptr = true);
|
||||
|
||||
// In single core mode, this runs the GPU for a single slice.
|
||||
// In dual core mode, this synchronizes with the GPU thread.
|
||||
void SyncGPUForRegisterAccess();
|
||||
class FifoManager final
|
||||
{
|
||||
public:
|
||||
FifoManager();
|
||||
FifoManager(const FifoManager& other) = delete;
|
||||
FifoManager(FifoManager&& other) = delete;
|
||||
FifoManager& operator=(const FifoManager& other) = delete;
|
||||
FifoManager& operator=(FifoManager&& other) = delete;
|
||||
~FifoManager();
|
||||
|
||||
void PushFifoAuxBuffer(const void* ptr, size_t size);
|
||||
void* PopFifoAuxBuffer(size_t size);
|
||||
void Init();
|
||||
void Shutdown();
|
||||
void Prepare(); // Must be called from the CPU thread.
|
||||
void DoState(PointerWrap& f);
|
||||
void PauseAndLock(bool doLock, bool unpauseOnUnlock);
|
||||
void UpdateWantDeterminism(bool want);
|
||||
bool UseDeterministicGPUThread() const { return m_use_deterministic_gpu_thread; }
|
||||
|
||||
void FlushGpu();
|
||||
void RunGpu();
|
||||
void GpuMaySleep();
|
||||
void RunGpuLoop();
|
||||
void ExitGpuLoop();
|
||||
void EmulatorState(bool running);
|
||||
bool AtBreakpoint();
|
||||
void ResetVideoBuffer();
|
||||
// In deterministic GPU thread mode this waits for the GPU to be done with pending work.
|
||||
void SyncGPU(SyncGPUReason reason, bool may_move_read_ptr = true);
|
||||
|
||||
// In single core mode, this runs the GPU for a single slice.
|
||||
// In dual core mode, this synchronizes with the GPU thread.
|
||||
void SyncGPUForRegisterAccess();
|
||||
|
||||
void PushFifoAuxBuffer(const void* ptr, size_t size);
|
||||
void* PopFifoAuxBuffer(size_t size);
|
||||
|
||||
void FlushGpu();
|
||||
void RunGpu();
|
||||
void GpuMaySleep();
|
||||
void RunGpuLoop();
|
||||
void ExitGpuLoop();
|
||||
void EmulatorState(bool running);
|
||||
bool AtBreakpoint() const;
|
||||
void ResetVideoBuffer();
|
||||
|
||||
private:
|
||||
void RefreshConfig();
|
||||
void ReadDataFromFifo(u32 readPtr);
|
||||
void ReadDataFromFifoOnCPU(u32 readPtr);
|
||||
int RunGpuOnCpu(int ticks);
|
||||
int WaitForGpuThread(int ticks);
|
||||
static void SyncGPUCallback(Core::System& system, u64 ticks, s64 cyclesLate);
|
||||
|
||||
static constexpr u32 FIFO_SIZE = 2 * 1024 * 1024;
|
||||
|
||||
Common::BlockingLoop m_gpu_mainloop;
|
||||
|
||||
Common::Flag m_emu_running_state;
|
||||
|
||||
// Most of this array is unlikely to be faulted in...
|
||||
u8 m_fifo_aux_data[FIFO_SIZE]{};
|
||||
u8* m_fifo_aux_write_ptr = nullptr;
|
||||
u8* m_fifo_aux_read_ptr = nullptr;
|
||||
|
||||
// This could be in SConfig, but it depends on multiple settings
|
||||
// and can change at runtime.
|
||||
bool m_use_deterministic_gpu_thread = false;
|
||||
|
||||
CoreTiming::EventType* m_event_sync_gpu = nullptr;
|
||||
|
||||
// STATE_TO_SAVE
|
||||
u8* m_video_buffer = nullptr;
|
||||
u8* m_video_buffer_read_ptr = nullptr;
|
||||
std::atomic<u8*> m_video_buffer_write_ptr = nullptr;
|
||||
std::atomic<u8*> m_video_buffer_seen_ptr = nullptr;
|
||||
u8* m_video_buffer_pp_read_ptr = nullptr;
|
||||
// The read_ptr is always owned by the GPU thread. In normal mode, so is the
|
||||
// write_ptr, despite it being atomic. In deterministic GPU thread mode,
|
||||
// things get a bit more complicated:
|
||||
// - The seen_ptr is written by the GPU thread, and points to what it's already
|
||||
// processed as much of as possible - in the case of a partial command which
|
||||
// caused it to stop, not the same as the read ptr. It's written by the GPU,
|
||||
// under the lock, and updating the cond.
|
||||
// - The write_ptr is written by the CPU thread after it copies data from the
|
||||
// FIFO. Maybe someday it will be under the lock. For now, because RunGpuLoop
|
||||
// polls, it's just atomic.
|
||||
// - The pp_read_ptr is the CPU preprocessing version of the read_ptr.
|
||||
|
||||
std::atomic<int> m_sync_ticks = 0;
|
||||
bool m_syncing_suspended = false;
|
||||
Common::Event m_sync_wakeup_event;
|
||||
|
||||
std::optional<size_t> m_config_callback_id = std::nullopt;
|
||||
bool m_config_sync_gpu = false;
|
||||
int m_config_sync_gpu_max_distance = 0;
|
||||
int m_config_sync_gpu_min_distance = 0;
|
||||
float m_config_sync_gpu_overclock = 0.0f;
|
||||
};
|
||||
} // namespace Fifo
|
||||
|
||||
@@ -151,13 +151,14 @@ public:
|
||||
{
|
||||
m_in_display_list = true;
|
||||
|
||||
auto& system = Core::System::GetInstance();
|
||||
|
||||
if constexpr (is_preprocess)
|
||||
{
|
||||
auto& system = Core::System::GetInstance();
|
||||
auto& memory = system.GetMemory();
|
||||
const u8* const start_address = memory.GetPointer(address);
|
||||
|
||||
Fifo::PushFifoAuxBuffer(start_address, size);
|
||||
system.GetFifo().PushFifoAuxBuffer(start_address, size);
|
||||
|
||||
if (start_address != nullptr)
|
||||
{
|
||||
@@ -168,13 +169,13 @@ public:
|
||||
{
|
||||
const u8* start_address;
|
||||
|
||||
if (Fifo::UseDeterministicGPUThread())
|
||||
auto& fifo = system.GetFifo();
|
||||
if (fifo.UseDeterministicGPUThread())
|
||||
{
|
||||
start_address = static_cast<u8*>(Fifo::PopFifoAuxBuffer(size));
|
||||
start_address = static_cast<u8*>(fifo.PopFifoAuxBuffer(size));
|
||||
}
|
||||
else
|
||||
{
|
||||
auto& system = Core::System::GetInstance();
|
||||
auto& memory = system.GetMemory();
|
||||
start_address = memory.GetPointer(address);
|
||||
}
|
||||
|
||||
@@ -333,7 +333,8 @@ static void RaiseEvent(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 (!Core::System::GetInstance().IsDualCoreMode() || Fifo::UseDeterministicGPUThread())
|
||||
auto& system = Core::System::GetInstance();
|
||||
if (!system.IsDualCoreMode() || system.GetFifo().UseDeterministicGPUThread())
|
||||
{
|
||||
from = CoreTiming::FromThread::CPU;
|
||||
|
||||
|
||||
@@ -83,7 +83,8 @@ std::string VideoBackendBase::BadShaderFilename(const char* shader_stage, int co
|
||||
|
||||
void VideoBackendBase::Video_ExitLoop()
|
||||
{
|
||||
Fifo::ExitGpuLoop();
|
||||
auto& system = Core::System::GetInstance();
|
||||
system.GetFifo().ExitGpuLoop();
|
||||
}
|
||||
|
||||
// Run from the CPU thread (from VideoInterface.cpp)
|
||||
@@ -92,7 +93,8 @@ void VideoBackendBase::Video_OutputXFB(u32 xfb_addr, u32 fb_width, u32 fb_stride
|
||||
{
|
||||
if (m_initialized && g_renderer && !g_ActiveConfig.bImmediateXFB)
|
||||
{
|
||||
Fifo::SyncGPU(Fifo::SyncGPUReason::Swap);
|
||||
auto& system = Core::System::GetInstance();
|
||||
system.GetFifo().SyncGPU(Fifo::SyncGPUReason::Swap);
|
||||
|
||||
AsyncRequests::Event e;
|
||||
e.time = ticks;
|
||||
@@ -147,7 +149,8 @@ u32 VideoBackendBase::Video_GetQueryResult(PerfQueryType type)
|
||||
return 0;
|
||||
}
|
||||
|
||||
Fifo::SyncGPU(Fifo::SyncGPUReason::PerfQuery);
|
||||
auto& system = Core::System::GetInstance();
|
||||
system.GetFifo().SyncGPU(Fifo::SyncGPUReason::PerfQuery);
|
||||
|
||||
AsyncRequests::Event e;
|
||||
e.time = 0;
|
||||
@@ -185,7 +188,8 @@ u16 VideoBackendBase::Video_GetBoundingBox(int index)
|
||||
warn_once = false;
|
||||
}
|
||||
|
||||
Fifo::SyncGPU(Fifo::SyncGPUReason::BBox);
|
||||
auto& system = Core::System::GetInstance();
|
||||
system.GetFifo().SyncGPU(Fifo::SyncGPUReason::BBox);
|
||||
|
||||
AsyncRequests::Event e;
|
||||
u16 result;
|
||||
@@ -291,7 +295,8 @@ void VideoBackendBase::PopulateBackendInfoFromUI()
|
||||
|
||||
void VideoBackendBase::DoState(PointerWrap& p)
|
||||
{
|
||||
if (!Core::System::GetInstance().IsDualCoreMode())
|
||||
auto& system = Core::System::GetInstance();
|
||||
if (!system.IsDualCoreMode())
|
||||
{
|
||||
VideoCommon_DoState(p);
|
||||
return;
|
||||
@@ -304,7 +309,7 @@ void VideoBackendBase::DoState(PointerWrap& p)
|
||||
|
||||
// Let the GPU thread sleep after loading the state, so we're not spinning if paused after loading
|
||||
// a state. The next GP burst will wake it up again.
|
||||
Fifo::GpuMaySleep();
|
||||
system.GetFifo().GpuMaySleep();
|
||||
}
|
||||
|
||||
void VideoBackendBase::InitializeShared()
|
||||
@@ -319,7 +324,7 @@ void VideoBackendBase::InitializeShared()
|
||||
auto& system = Core::System::GetInstance();
|
||||
auto& command_processor = system.GetCommandProcessor();
|
||||
command_processor.Init(system);
|
||||
Fifo::Init();
|
||||
system.GetFifo().Init();
|
||||
PixelEngine::Init();
|
||||
BPInit();
|
||||
VertexLoaderManager::Init();
|
||||
@@ -336,6 +341,7 @@ void VideoBackendBase::ShutdownShared()
|
||||
{
|
||||
m_initialized = false;
|
||||
|
||||
auto& system = Core::System::GetInstance();
|
||||
VertexLoaderManager::Clear();
|
||||
Fifo::Shutdown();
|
||||
system.GetFifo().Shutdown();
|
||||
}
|
||||
|
||||
@@ -60,10 +60,10 @@ void VideoCommon_DoState(PointerWrap& p)
|
||||
p.DoMarker("TMEM");
|
||||
|
||||
// FIFO
|
||||
Fifo::DoState(p);
|
||||
auto& system = Core::System::GetInstance();
|
||||
system.GetFifo().DoState(p);
|
||||
p.DoMarker("Fifo");
|
||||
|
||||
auto& system = Core::System::GetInstance();
|
||||
auto& command_processor = system.GetCommandProcessor();
|
||||
command_processor.DoState(p);
|
||||
p.DoMarker("CommandProcessor");
|
||||
|
||||
@@ -257,13 +257,14 @@ void LoadIndexedXF(CPArray array, u32 index, u16 address, u8 size)
|
||||
|
||||
u32* currData = (u32*)(&xfmem) + address;
|
||||
u32* newData;
|
||||
if (Fifo::UseDeterministicGPUThread())
|
||||
auto& system = Core::System::GetInstance();
|
||||
auto& fifo = system.GetFifo();
|
||||
if (fifo.UseDeterministicGPUThread())
|
||||
{
|
||||
newData = (u32*)Fifo::PopFifoAuxBuffer(size * sizeof(u32));
|
||||
newData = (u32*)fifo.PopFifoAuxBuffer(size * sizeof(u32));
|
||||
}
|
||||
else
|
||||
{
|
||||
auto& system = Core::System::GetInstance();
|
||||
auto& memory = system.GetMemory();
|
||||
newData = (u32*)memory.GetPointer(g_main_cp_state.array_bases[array] +
|
||||
g_main_cp_state.array_strides[array] * index);
|
||||
@@ -293,7 +294,7 @@ void PreprocessIndexedXF(CPArray array, u32 index, u16 address, u8 size)
|
||||
g_preprocess_cp_state.array_strides[array] * index);
|
||||
|
||||
const size_t buf_size = size * sizeof(u32);
|
||||
Fifo::PushFifoAuxBuffer(new_data, buf_size);
|
||||
system.GetFifo().PushFifoAuxBuffer(new_data, buf_size);
|
||||
}
|
||||
|
||||
std::pair<std::string, std::string> GetXFRegInfo(u32 address, u32 value)
|
||||
|
||||
Reference in New Issue
Block a user