From 37a894a55896e5f7ec54fbab60e2b1fb2eff5404 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 3 Jun 2017 00:09:58 -0700 Subject: [PATCH] GE Debugger: Record memcpy/memset too. --- GPU/Debugger/Record.cpp | 37 +++++++++++++++++++++++++++++++++++++ GPU/Debugger/Record.h | 3 +++ GPU/GPUCommon.cpp | 3 +++ GPU/Software/SoftGpu.cpp | 4 ++++ 4 files changed, 47 insertions(+) diff --git a/GPU/Debugger/Record.cpp b/GPU/Debugger/Record.cpp index 20d47ec7bc..c492378cd0 100644 --- a/GPU/Debugger/Record.cpp +++ b/GPU/Debugger/Record.cpp @@ -44,6 +44,9 @@ enum class CommandType : u8 { INDICES = 3, CLUT = 4, TRANSFERSRC = 5, + MEMSET = 6, + MEMCPYDEST = 7, + MEMCPYDATA = 8, TEXTURE0 = 0x10, TEXTURE1 = 0x11, @@ -362,6 +365,40 @@ void NotifyCommand(u32 pc) { } } +void NotifyMemcpy(u32 dest, u32 src, u32 sz) { + if (Memory::IsVRAMAddress(dest)) { + FlushRegisters(); + Command cmd{CommandType::MEMCPYDEST, sizeof(dest), (u32)pushbuf.size()}; + pushbuf.resize(pushbuf.size() + sizeof(dest)); + memcpy(pushbuf.data() + cmd.ptr, &dest, sizeof(dest)); + + sz = Memory::ValidSize(dest, sz); + EmitCommandWithRAM(CommandType::MEMCPYDATA, Memory::GetPointer(dest), sz); + } +} + +void NotifyMemset(u32 dest, int v, u32 sz) { + struct MemsetCommand { + u32 dest; + int value; + u32 sz; + }; + + if (Memory::IsVRAMAddress(dest)) { + sz = Memory::ValidSize(dest, sz); + MemsetCommand data{dest, v, sz}; + + FlushRegisters(); + Command cmd{CommandType::MEMSET, sizeof(data), (u32)pushbuf.size()}; + pushbuf.resize(pushbuf.size() + sizeof(data)); + memcpy(pushbuf.data() + cmd.ptr, &data, sizeof(data)); + } +} + +void NotifyUpload(u32 dest, u32 sz) { + NotifyMemcpy(dest, dest, sz); +} + void NotifyFrame() { if (active) { active = false; diff --git a/GPU/Debugger/Record.h b/GPU/Debugger/Record.h index 3d5ea36b5c..9803671ecb 100644 --- a/GPU/Debugger/Record.h +++ b/GPU/Debugger/Record.h @@ -24,6 +24,9 @@ namespace GPURecord { bool IsActive(); void NotifyCommand(u32 pc); +void NotifyMemcpy(u32 dest, u32 src, u32 sz); +void NotifyMemset(u32 dest, int v, u32 sz); +void NotifyUpload(u32 dest, u32 sz); void NotifyFrame(); }; diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index e409584d11..8cf869e62f 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -2347,6 +2347,7 @@ bool GPUCommon::PerformMemoryCopy(u32 dest, u32 src, int size) { } InvalidateCache(dest, size, GPU_INVALIDATE_HINT); + GPURecord::NotifyMemcpy(dest, src, size); return false; } @@ -2371,6 +2372,7 @@ bool GPUCommon::PerformMemorySet(u32 dest, u8 v, int size) { // Or perhaps a texture, let's invalidate. InvalidateCache(dest, size, GPU_INVALIDATE_HINT); + GPURecord::NotifyMemset(dest, v, size); return false; } @@ -2387,6 +2389,7 @@ bool GPUCommon::PerformMemoryUpload(u32 dest, int size) { // Cheat a bit to force an upload of the framebuffer. // VRAM + 0x00400000 is simply a VRAM mirror. if (Memory::IsVRAMAddress(dest)) { + GPURecord::NotifyUpload(dest, size); return PerformMemoryCopy(dest, dest ^ 0x00400000, size); } return false; diff --git a/GPU/Software/SoftGpu.cpp b/GPU/Software/SoftGpu.cpp index 28a5a03e96..0a08068a2b 100644 --- a/GPU/Software/SoftGpu.cpp +++ b/GPU/Software/SoftGpu.cpp @@ -37,6 +37,7 @@ #include "GPU/Software/TransformUnit.h" #include "GPU/Common/DrawEngineCommon.h" #include "GPU/Common/FramebufferCommon.h" +#include "GPU/Debugger/Record.h" const int FB_WIDTH = 480; const int FB_HEIGHT = 272; @@ -876,6 +877,7 @@ bool SoftGPU::PerformMemoryCopy(u32 dest, u32 src, int size) { // Nothing to update. InvalidateCache(dest, size, GPU_INVALIDATE_HINT); + GPURecord::NotifyMemcpy(dest, src, size); // Let's just be safe. framebufferDirty_ = true; return false; @@ -885,6 +887,7 @@ bool SoftGPU::PerformMemorySet(u32 dest, u8 v, int size) { // Nothing to update. InvalidateCache(dest, size, GPU_INVALIDATE_HINT); + GPURecord::NotifyMemset(dest, v, size); // Let's just be safe. framebufferDirty_ = true; return false; @@ -901,6 +904,7 @@ bool SoftGPU::PerformMemoryUpload(u32 dest, int size) { // Nothing to update. InvalidateCache(dest, size, GPU_INVALIDATE_HINT); + GPURecord::NotifyUpload(dest, size); return false; }