Skip to content
Permalink
Browse files
Merge pull request #11334 from AdmiralCurtiss/globals-fifo
VideoCommon/Fifo: Refactor to class, move to Core::System.
  • Loading branch information
lioncash committed Dec 10, 2022
2 parents 128c23d + ceae424 commit 54e01c6
Show file tree
Hide file tree
Showing 18 changed files with 391 additions and 320 deletions.
@@ -277,15 +277,17 @@ 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 ----");

// Stop the CPU
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(system);

// 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(system);

// 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(system, 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(system, 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(system);
}

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 @@ class System
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,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.)

const bool was_running = Core::GetState() == Core::State::Running;
Fifo::PauseAndLock(true, was_running);
auto& system = Core::System::GetInstance();
auto& fifo = system.GetFifo();
fifo.PauseAndLock(system, true, was_running);
f();
Fifo::PauseAndLock(false, was_running);
fifo.PauseAndLock(system, 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(system);
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,38 +179,47 @@ 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);
return;
}
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(system);
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(system);
}));

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(system);
}));

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(system);
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(system);
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(system);
WriteHigh(fifo.CPReadWriteDistance, val & WMASK_HI_RESTRICT);
Fifo::RunGpu();
system.GetFifo().RunGpu(system);
}));

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(system);
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(sys);
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(system);
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(sys);
WriteHigh(fifo.CPReadPointer, val & WMASK_HI_RESTRICT);
});
}
@@ -366,18 +366,18 @@ 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.
if ((ProcessorInterface::Fifo_CPUEnd == fifo.CPEnd.load(std::memory_order_relaxed)) &&
(ProcessorInterface::Fifo_CPUBase == fifo.CPBase.load(std::memory_order_relaxed)) &&
fifo.CPReadWriteDistance.load(std::memory_order_relaxed) > 0)
{
Fifo::FlushGpu();
system.GetFifo().FlushGpu(system);
}
}
Fifo::RunGpu();
system.GetFifo().RunGpu(system);
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(system);

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(system);
}

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() ||
Fifo::AtBreakpoint(system) ||
!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(system);
}
else
{

0 comments on commit 54e01c6

Please sign in to comment.