VideoCommon/CommandProcessor: Refactor to class, move to Core::System.

This commit is contained in:
Admiral H. Curtiss
2022-11-29 08:15:01 +01:00
parent 44f8b8c100
commit 6941d2e7e6
11 changed files with 271 additions and 198 deletions
+3 -1
View File
@@ -13,6 +13,7 @@
#include "Core/HW/ProcessorInterface.h"
#include "Core/PowerPC/JitInterface.h"
#include "Core/PowerPC/PowerPC.h"
#include "Core/System.h"
#include "VideoCommon/CommandProcessor.h"
namespace GPFifo
@@ -103,7 +104,8 @@ void UpdateGatherPipe()
ProcessorInterface::Fifo_CPUWritePointer += GATHER_PIPE_SIZE;
}
CommandProcessor::GatherPipeBursted();
auto& system = Core::System::GetInstance();
system.GetCommandProcessor().GatherPipeBursted(system);
}
// move back the spill bytes
+2 -1
View File
@@ -130,7 +130,8 @@ static void InitMMIO(bool is_wii)
{
mmio_mapping = std::make_unique<MMIO::Mapping>();
CommandProcessor::RegisterMMIO(mmio_mapping.get(), 0x0C000000);
auto& system = Core::System::GetInstance();
system.GetCommandProcessor().RegisterMMIO(system, mmio_mapping.get(), 0x0C000000);
PixelEngine::RegisterMMIO(mmio_mapping.get(), 0x0C001000);
VideoInterface::RegisterMMIO(mmio_mapping.get(), 0x0C002000);
ProcessorInterface::RegisterMMIO(mmio_mapping.get(), 0x0C003000);
+7
View File
@@ -17,6 +17,7 @@
#include "Core/HW/SI/SI.h"
#include "Core/HW/Sram.h"
#include "Core/HW/VideoInterface.h"
#include "VideoCommon/CommandProcessor.h"
namespace Core
{
@@ -28,6 +29,7 @@ struct System::Impl
AudioInterface::AudioInterfaceState m_audio_interface_state;
CoreTiming::CoreTimingManager m_core_timing;
CommandProcessor::CommandProcessorManager m_command_processor;
DSP::DSPState m_dsp_state;
DVDInterface::DVDInterfaceState m_dvd_interface_state;
DVDThread::DVDThreadState m_dvd_thread_state;
@@ -91,6 +93,11 @@ CoreTiming::CoreTimingManager& System::GetCoreTiming() const
return m_impl->m_core_timing;
}
CommandProcessor::CommandProcessorManager& System::GetCommandProcessor() const
{
return m_impl->m_command_processor;
}
DSP::DSPState& System::GetDSPState() const
{
return m_impl->m_dsp_state;
+5
View File
@@ -12,6 +12,10 @@ namespace AudioInterface
{
class AudioInterfaceState;
};
namespace CommandProcessor
{
class CommandProcessorManager;
}
namespace CoreTiming
{
class CoreTimingManager;
@@ -81,6 +85,7 @@ public:
AudioInterface::AudioInterfaceState& GetAudioInterfaceState() const;
CoreTiming::CoreTimingManager& GetCoreTiming() const;
CommandProcessor::CommandProcessorManager& GetCommandProcessor() const;
DSP::DSPState& GetDSPState() const;
DVDInterface::DVDInterfaceState& GetDVDInterfaceState() const;
DVDThread::DVDThreadState& GetDVDThreadState() const;
File diff suppressed because it is too large Load Diff
+73 -40
View File
@@ -6,48 +6,53 @@
#include <atomic>
#include "Common/CommonTypes.h"
#include "Common/Flag.h"
class PointerWrap;
namespace MMIO
{
class Mapping;
}
namespace Core
{
class System;
}
namespace CoreTiming
{
struct EventType;
}
namespace CommandProcessor
{
struct SCPFifoStruct
{
// fifo registers
std::atomic<u32> CPBase;
std::atomic<u32> CPEnd;
std::atomic<u32> CPBase = 0;
std::atomic<u32> CPEnd = 0;
u32 CPHiWatermark = 0;
u32 CPLoWatermark = 0;
std::atomic<u32> CPReadWriteDistance;
std::atomic<u32> CPWritePointer;
std::atomic<u32> CPReadPointer;
std::atomic<u32> CPBreakpoint;
std::atomic<u32> SafeCPReadPointer;
std::atomic<u32> CPReadWriteDistance = 0;
std::atomic<u32> CPWritePointer = 0;
std::atomic<u32> CPReadPointer = 0;
std::atomic<u32> CPBreakpoint = 0;
std::atomic<u32> SafeCPReadPointer = 0;
std::atomic<u32> bFF_GPLinkEnable;
std::atomic<u32> bFF_GPReadEnable;
std::atomic<u32> bFF_BPEnable;
std::atomic<u32> bFF_BPInt;
std::atomic<u32> bFF_Breakpoint;
std::atomic<u32> bFF_GPLinkEnable = 0;
std::atomic<u32> bFF_GPReadEnable = 0;
std::atomic<u32> bFF_BPEnable = 0;
std::atomic<u32> bFF_BPInt = 0;
std::atomic<u32> bFF_Breakpoint = 0;
std::atomic<u32> bFF_LoWatermarkInt;
std::atomic<u32> bFF_HiWatermarkInt;
std::atomic<u32> bFF_LoWatermarkInt = 0;
std::atomic<u32> bFF_HiWatermarkInt = 0;
std::atomic<u32> bFF_LoWatermark;
std::atomic<u32> bFF_HiWatermark;
std::atomic<u32> bFF_LoWatermark = 0;
std::atomic<u32> bFF_HiWatermark = 0;
void Init();
void DoState(PointerWrap& p);
};
// This one is shared between gfx thread and emulator thread.
// It is only used by the Fifo and by the CommandProcessor.
extern SCPFifoStruct fifo;
// internal hardware addresses
enum
{
@@ -150,26 +155,54 @@ union UCPClearReg
UCPClearReg(u16 _hex) { Hex = _hex; }
};
// Init
void Init();
void DoState(PointerWrap& p);
void RegisterMMIO(MMIO::Mapping* mmio, u32 base);
void SetCPStatusFromGPU();
void SetCPStatusFromCPU();
void GatherPipeBursted();
void UpdateInterrupts(u64 userdata);
void UpdateInterruptsFromVideoBackend(u64 userdata);
bool IsInterruptWaiting();
void SetCpClearRegister();
void SetCpControlRegister();
void SetCpStatusRegister();
void HandleUnknownOpcode(u8 cmd_byte, const u8* buffer, bool preprocess);
u32 GetPhysicalAddressMask();
class CommandProcessorManager
{
public:
void Init(Core::System& system);
void DoState(PointerWrap& p);
void RegisterMMIO(Core::System& system, MMIO::Mapping* mmio, u32 base);
void SetCPStatusFromGPU(Core::System& system);
void SetCPStatusFromCPU(Core::System& system);
void GatherPipeBursted(Core::System& system);
void UpdateInterrupts(Core::System& system, u64 userdata);
void UpdateInterruptsFromVideoBackend(Core::System& system, u64 userdata);
bool IsInterruptWaiting() const;
void SetCpClearRegister();
void SetCpControlRegister();
void SetCpStatusRegister();
void HandleUnknownOpcode(u8 cmd_byte, const u8* buffer, bool preprocess);
// This one is shared between gfx thread and emulator thread.
// It is only used by the Fifo and by the CommandProcessor.
SCPFifoStruct& GetFifo() { return m_fifo; }
private:
SCPFifoStruct m_fifo;
CoreTiming::EventType* m_event_type_update_interrupts = nullptr;
// STATE_TO_SAVE
UCPStatusReg m_cp_status_reg;
UCPCtrlReg m_cp_ctrl_reg;
UCPClearReg m_cp_clear_reg;
u16 m_bbox_left = 0;
u16 m_bbox_top = 0;
u16 m_bbox_right = 0;
u16 m_bbox_bottom = 0;
u16 m_token_reg = 0;
Common::Flag m_interrupt_set;
Common::Flag m_interrupt_waiting;
bool m_is_fifo_error_seen = false;
};
} // namespace CommandProcessor
+18 -8
View File
@@ -163,8 +163,12 @@ void Shutdown()
// Created to allow for self shutdown.
void ExitGpuLoop()
{
auto& system = Core::System::GetInstance();
auto& command_processor = system.GetCommandProcessor();
auto& fifo = command_processor.GetFifo();
// This should break the wait loop in CPU thread
CommandProcessor::fifo.bFF_GPReadEnable.store(0, std::memory_order_relaxed);
fifo.bFF_GPReadEnable.store(0, std::memory_order_relaxed);
FlushGpu();
// Terminate GPU thread loop
@@ -347,11 +351,13 @@ void RunGpuLoop()
}
else
{
CommandProcessor::SCPFifoStruct& fifo = CommandProcessor::fifo;
CommandProcessor::SetCPStatusFromGPU();
auto& system = Core::System::GetInstance();
auto& command_processor = system.GetCommandProcessor();
auto& fifo = command_processor.GetFifo();
command_processor.SetCPStatusFromGPU(system);
// check if we are able to run this buffer
while (!CommandProcessor::IsInterruptWaiting() &&
while (!command_processor.IsInterruptWaiting() &&
fifo.bFF_GPReadEnable.load(std::memory_order_relaxed) &&
fifo.CPReadWriteDistance.load(std::memory_order_relaxed) && !AtBreakpoint())
{
@@ -387,7 +393,7 @@ void RunGpuLoop()
std::memory_order_relaxed);
}
CommandProcessor::SetCPStatusFromGPU();
command_processor.SetCPStatusFromGPU(system);
if (s_config_sync_gpu)
{
@@ -440,7 +446,9 @@ void GpuMaySleep()
bool AtBreakpoint()
{
CommandProcessor::SCPFifoStruct& fifo = CommandProcessor::fifo;
auto& system = Core::System::GetInstance();
auto& command_processor = system.GetCommandProcessor();
const auto& fifo = command_processor.GetFifo();
return fifo.bFF_BPEnable.load(std::memory_order_relaxed) &&
(fifo.CPReadPointer.load(std::memory_order_relaxed) ==
fifo.CPBreakpoint.load(std::memory_order_relaxed));
@@ -471,7 +479,9 @@ void RunGpu()
static int RunGpuOnCpu(int ticks)
{
CommandProcessor::SCPFifoStruct& fifo = CommandProcessor::fifo;
auto& system = Core::System::GetInstance();
auto& command_processor = system.GetCommandProcessor();
auto& fifo = command_processor.GetFifo();
bool reset_simd_state = false;
int available_ticks = int(ticks * s_config_sync_gpu_overclock) + s_sync_ticks.load();
while (fifo.bFF_GPReadEnable.load(std::memory_order_relaxed) &&
@@ -512,7 +522,7 @@ static int RunGpuOnCpu(int ticks)
fifo.CPReadWriteDistance.fetch_sub(GPFifo::GATHER_PIPE_SIZE, std::memory_order_relaxed);
}
CommandProcessor::SetCPStatusFromGPU();
command_processor.SetCPStatusFromGPU(system);
if (reset_simd_state)
{
+3 -1
View File
@@ -18,6 +18,7 @@
#include "Common/Logging/Log.h"
#include "Core/FifoPlayer/FifoRecorder.h"
#include "Core/HW/Memmap.h"
#include "Core/System.h"
#include "VideoCommon/BPMemory.h"
#include "VideoCommon/CPMemory.h"
#include "VideoCommon/CommandProcessor.h"
@@ -207,7 +208,8 @@ public:
}
else
{
CommandProcessor::HandleUnknownOpcode(opcode, data, is_preprocess);
Core::System::GetInstance().GetCommandProcessor().HandleUnknownOpcode(opcode, data,
is_preprocess);
m_cycles += 1;
}
}
+6 -3
View File
@@ -51,6 +51,7 @@
#include "Core/HW/VideoInterface.h"
#include "Core/Host.h"
#include "Core/Movie.h"
#include "Core/System.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
@@ -1007,9 +1008,11 @@ void Renderer::CheckFifoRecording()
RecordVideoMemory();
}
FifoRecorder::GetInstance().EndFrame(
CommandProcessor::fifo.CPBase.load(std::memory_order_relaxed),
CommandProcessor::fifo.CPEnd.load(std::memory_order_relaxed));
auto& system = Core::System::GetInstance();
auto& command_processor = system.GetCommandProcessor();
const auto& fifo = command_processor.GetFifo();
FifoRecorder::GetInstance().EndFrame(fifo.CPBase.load(std::memory_order_relaxed),
fifo.CPEnd.load(std::memory_order_relaxed));
}
void Renderer::RecordVideoMemory()
+3 -1
View File
@@ -316,7 +316,9 @@ void VideoBackendBase::InitializeShared()
// do not initialize again for the config window
m_initialized = true;
CommandProcessor::Init();
auto& system = Core::System::GetInstance();
auto& command_processor = system.GetCommandProcessor();
command_processor.Init(system);
Fifo::Init();
PixelEngine::Init();
BPInit();
+4 -1
View File
@@ -6,6 +6,7 @@
#include <cstring>
#include "Common/ChunkFile.h"
#include "Core/System.h"
#include "VideoCommon/BPMemory.h"
#include "VideoCommon/CPMemory.h"
#include "VideoCommon/CommandProcessor.h"
@@ -62,7 +63,9 @@ void VideoCommon_DoState(PointerWrap& p)
Fifo::DoState(p);
p.DoMarker("Fifo");
CommandProcessor::DoState(p);
auto& system = Core::System::GetInstance();
auto& command_processor = system.GetCommandProcessor();
command_processor.DoState(p);
p.DoMarker("CommandProcessor");
PixelEngine::DoState(p);