From c3ceb9bf708827df404722dce05a68baec6dc44c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 25 Feb 2023 18:17:28 +0100 Subject: [PATCH] Move assorted debug functions and similar to GPUCommonHW --- GPU/GPUCommon.cpp | 77 --------------------------------------------- GPU/GPUCommon.h | 12 ------- GPU/GPUCommonHW.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++++ GPU/GPUCommonHW.h | 14 ++++++++- 4 files changed, 89 insertions(+), 90 deletions(-) diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index 09b4278c7e..562c93e52d 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -42,7 +42,6 @@ #include "Core/HW/Display.h" #include "Core/MemMapHelpers.h" #include "Core/Util/PPGeDraw.h" -#include "GPU/GPUCommonHW.h" #include "GPU/Common/DrawEngineCommon.h" #include "GPU/Common/FramebufferManagerCommon.h" #include "GPU/Common/SplineCommon.h" @@ -2011,21 +2010,6 @@ bool GPUCommon::PerformWriteColorFromMemory(u32 dest, int size) { return false; } -void GPUCommon::InvalidateCache(u32 addr, int size, GPUInvalidationType type) { - if (size > 0) - textureCache_->Invalidate(addr, size, type); - else - textureCache_->InvalidateAll(type); - - if (type != GPU_INVALIDATE_ALL && framebufferManager_->MayIntersectFramebuffer(addr)) { - // Vempire invalidates (with writeback) after drawing, but before blitting. - // TODO: Investigate whether we can get this to work some other way. - if (type == GPU_INVALIDATE_SAFE) { - framebufferManager_->UpdateFromMemory(addr, size); - } - } -} - void GPUCommon::PerformWriteFormattedFromMemory(u32 addr, int size, int frameWidth, GEBufferFormat format) { if (Memory::IsVRAMAddress(addr)) { framebufferManager_->PerformWriteFormattedFromMemory(addr, size, frameWidth, format); @@ -2042,36 +2026,6 @@ bool GPUCommon::PerformWriteStencilFromMemory(u32 dest, int size, WriteStencil f return false; } -bool GPUCommon::GetCurrentFramebuffer(GPUDebugBuffer &buffer, GPUDebugFramebufferType type, int maxRes) { - u32 fb_address = type == GPU_DBG_FRAMEBUF_RENDER ? (gstate.getFrameBufRawAddress() | 0x04000000) : framebufferManager_->DisplayFramebufAddr(); - int fb_stride = type == GPU_DBG_FRAMEBUF_RENDER ? gstate.FrameBufStride() : framebufferManager_->DisplayFramebufStride(); - GEBufferFormat format = type == GPU_DBG_FRAMEBUF_RENDER ? gstate_c.framebufFormat : framebufferManager_->DisplayFramebufFormat(); - return framebufferManager_->GetFramebuffer(fb_address, fb_stride, format, buffer, maxRes); -} - -bool GPUCommon::GetCurrentDepthbuffer(GPUDebugBuffer &buffer) { - u32 fb_address = gstate.getFrameBufRawAddress() | 0x04000000; - int fb_stride = gstate.FrameBufStride(); - - u32 z_address = gstate.getDepthBufRawAddress() | 0x04000000; - int z_stride = gstate.DepthBufStride(); - - return framebufferManager_->GetDepthbuffer(fb_address, fb_stride, z_address, z_stride, buffer); -} - -bool GPUCommon::GetCurrentStencilbuffer(GPUDebugBuffer &buffer) { - u32 fb_address = gstate.getFrameBufRawAddress() | 0x04000000; - int fb_stride = gstate.FrameBufStride(); - - return framebufferManager_->GetStencilbuffer(fb_address, fb_stride, buffer); -} - -bool GPUCommon::GetOutputFramebuffer(GPUDebugBuffer &buffer) { - // framebufferManager_ can be null here when taking screens in software rendering mode. - // TODO: Actually grab the framebuffer anyway. - return framebufferManager_ ? framebufferManager_->GetOutputFramebuffer(buffer) : false; -} - std::vector GPUCommon::GetFramebufferList() const { return framebufferManager_->GetFramebufferList(); } @@ -2081,17 +2035,6 @@ bool GPUCommon::GetCurrentSimpleVertices(int count, std::vector return drawEngineCommon_->GetCurrentSimpleVertices(count, vertices, indices); } -bool GPUCommon::GetCurrentClut(GPUDebugBuffer &buffer) { - return textureCache_->GetCurrentClutBuffer(buffer); -} - -bool GPUCommon::GetCurrentTexture(GPUDebugBuffer &buffer, int level, bool *isFramebuffer) { - if (!gstate.isTextureMapEnabled()) { - return false; - } - return textureCache_->GetCurrentTextureDebug(buffer, level, isFramebuffer); -} - bool GPUCommon::DescribeCodePtr(const u8 *ptr, std::string &name) { if (drawEngineCommon_->IsCodePtrVertexDecoder(ptr)) { name = "VertexDecoderJit"; @@ -2100,26 +2043,6 @@ bool GPUCommon::DescribeCodePtr(const u8 *ptr, std::string &name) { return false; } -bool GPUCommon::FramebufferDirty() { - VirtualFramebuffer *vfb = framebufferManager_->GetDisplayVFB(); - if (vfb) { - bool dirty = vfb->dirtyAfterDisplay; - vfb->dirtyAfterDisplay = false; - return dirty; - } - return true; -} - -bool GPUCommon::FramebufferReallyDirty() { - VirtualFramebuffer *vfb = framebufferManager_->GetDisplayVFB(); - if (vfb) { - bool dirty = vfb->reallyDirtyAfterDisplay; - vfb->reallyDirtyAfterDisplay = false; - return dirty; - } - return true; -} - void GPUCommon::UpdateUVScaleOffset() { #ifdef _M_SSE __m128i values = _mm_slli_epi32(_mm_load_si128((const __m128i *) & gstate.texscaleu), 8); diff --git a/GPU/GPUCommon.h b/GPU/GPUCommon.h index cb84369d93..0927339ab7 100644 --- a/GPU/GPUCommon.h +++ b/GPU/GPUCommon.h @@ -133,7 +133,6 @@ public: bool PerformReadbackToMemory(u32 dest, int size) override; bool PerformWriteColorFromMemory(u32 dest, int size) override; - void InvalidateCache(u32 addr, int size, GPUInvalidationType type) override; void PerformWriteFormattedFromMemory(u32 addr, int size, int width, GEBufferFormat format) override; bool PerformWriteStencilFromMemory(u32 dest, int size, WriteStencil flags) override; @@ -178,13 +177,7 @@ public: // From GPUDebugInterface. bool GetCurrentDisplayList(DisplayList &list) override; - bool GetCurrentFramebuffer(GPUDebugBuffer &buffer, GPUDebugFramebufferType type, int maxRes) override; - bool GetCurrentDepthbuffer(GPUDebugBuffer &buffer) override; - bool GetCurrentStencilbuffer(GPUDebugBuffer &buffer) override; - bool GetCurrentTexture(GPUDebugBuffer &buffer, int level, bool *isFramebuffer) override; - bool GetCurrentClut(GPUDebugBuffer &buffer) override; bool GetCurrentSimpleVertices(int count, std::vector &vertices, std::vector &indices) override; - bool GetOutputFramebuffer(GPUDebugBuffer &buffer) override; std::vector DebugGetShaderIDs(DebugShaderType shader) override { return std::vector(); }; std::string DebugGetShaderString(std::string id, DebugShaderType shader, DebugShaderStringType stringType) override { @@ -227,11 +220,6 @@ public: return -1; } - bool FramebufferDirty() override; - bool FramebufferReallyDirty() override; - - typedef void (GPUCommon::*CmdFunc)(u32 op, u32 diff); - void GetReportingInfo(std::string &primaryInfo, std::string &fullInfo) override { primaryInfo = reportingPrimaryInfo_; fullInfo = reportingFullInfo_; diff --git a/GPU/GPUCommonHW.cpp b/GPU/GPUCommonHW.cpp index 319ca86dcc..7bea5851be 100644 --- a/GPU/GPUCommonHW.cpp +++ b/GPU/GPUCommonHW.cpp @@ -648,6 +648,47 @@ std::string GPUCommonHW::DebugGetShaderString(std::string id, DebugShaderType ty } } +bool GPUCommonHW::GetCurrentFramebuffer(GPUDebugBuffer &buffer, GPUDebugFramebufferType type, int maxRes) { + u32 fb_address = type == GPU_DBG_FRAMEBUF_RENDER ? (gstate.getFrameBufRawAddress() | 0x04000000) : framebufferManager_->DisplayFramebufAddr(); + int fb_stride = type == GPU_DBG_FRAMEBUF_RENDER ? gstate.FrameBufStride() : framebufferManager_->DisplayFramebufStride(); + GEBufferFormat format = type == GPU_DBG_FRAMEBUF_RENDER ? gstate_c.framebufFormat : framebufferManager_->DisplayFramebufFormat(); + return framebufferManager_->GetFramebuffer(fb_address, fb_stride, format, buffer, maxRes); +} + +bool GPUCommonHW::GetCurrentDepthbuffer(GPUDebugBuffer &buffer) { + u32 fb_address = gstate.getFrameBufRawAddress() | 0x04000000; + int fb_stride = gstate.FrameBufStride(); + + u32 z_address = gstate.getDepthBufRawAddress() | 0x04000000; + int z_stride = gstate.DepthBufStride(); + + return framebufferManager_->GetDepthbuffer(fb_address, fb_stride, z_address, z_stride, buffer); +} + +bool GPUCommonHW::GetCurrentStencilbuffer(GPUDebugBuffer &buffer) { + u32 fb_address = gstate.getFrameBufRawAddress() | 0x04000000; + int fb_stride = gstate.FrameBufStride(); + + return framebufferManager_->GetStencilbuffer(fb_address, fb_stride, buffer); +} + +bool GPUCommonHW::GetOutputFramebuffer(GPUDebugBuffer &buffer) { + // framebufferManager_ can be null here when taking screens in software rendering mode. + // TODO: Actually grab the framebuffer anyway. + return framebufferManager_ ? framebufferManager_->GetOutputFramebuffer(buffer) : false; +} + +bool GPUCommonHW::GetCurrentClut(GPUDebugBuffer &buffer) { + return textureCache_->GetCurrentClutBuffer(buffer); +} + +bool GPUCommonHW::GetCurrentTexture(GPUDebugBuffer &buffer, int level, bool *isFramebuffer) { + if (!gstate.isTextureMapEnabled()) { + return false; + } + return textureCache_->GetCurrentTextureDebug(buffer, level, isFramebuffer); +} + void GPUCommonHW::CheckDepthUsage(VirtualFramebuffer *vfb) { if (!gstate_c.usingDepth) { bool isReadingDepth = false; @@ -673,6 +714,41 @@ void GPUCommonHW::CheckDepthUsage(VirtualFramebuffer *vfb) { } } +void GPUCommonHW::InvalidateCache(u32 addr, int size, GPUInvalidationType type) { + if (size > 0) + textureCache_->Invalidate(addr, size, type); + else + textureCache_->InvalidateAll(type); + + if (type != GPU_INVALIDATE_ALL && framebufferManager_->MayIntersectFramebuffer(addr)) { + // Vempire invalidates (with writeback) after drawing, but before blitting. + // TODO: Investigate whether we can get this to work some other way. + if (type == GPU_INVALIDATE_SAFE) { + framebufferManager_->UpdateFromMemory(addr, size); + } + } +} + +bool GPUCommonHW::FramebufferDirty() { + VirtualFramebuffer *vfb = framebufferManager_->GetDisplayVFB(); + if (vfb) { + bool dirty = vfb->dirtyAfterDisplay; + vfb->dirtyAfterDisplay = false; + return dirty; + } + return true; +} + +bool GPUCommonHW::FramebufferReallyDirty() { + VirtualFramebuffer *vfb = framebufferManager_->GetDisplayVFB(); + if (vfb) { + bool dirty = vfb->reallyDirtyAfterDisplay; + vfb->reallyDirtyAfterDisplay = false; + return dirty; + } + return true; +} + void GPUCommonHW::ExecuteOp(u32 op, u32 diff) { const u8 cmd = op >> 24; const CommandInfo info = cmdInfo_[cmd]; diff --git a/GPU/GPUCommonHW.h b/GPU/GPUCommonHW.h index 983712f48f..97276e0116 100644 --- a/GPU/GPUCommonHW.h +++ b/GPU/GPUCommonHW.h @@ -17,12 +17,24 @@ public: u32 CheckGPUFeatures() const override; - void SetDisplayFramebuffer(u32 framebuf, u32 stride, GEBufferFormat format) override; + // From GPUDebugInterface. + bool GetCurrentFramebuffer(GPUDebugBuffer &buffer, GPUDebugFramebufferType type, int maxRes) override; + bool GetCurrentDepthbuffer(GPUDebugBuffer &buffer) override; + bool GetCurrentStencilbuffer(GPUDebugBuffer &buffer) override; + bool GetOutputFramebuffer(GPUDebugBuffer &buffer) override; + bool GetCurrentTexture(GPUDebugBuffer &buffer, int level, bool *isFramebuffer) override; + bool GetCurrentClut(GPUDebugBuffer &buffer) override; // Using string because it's generic - makes no assumptions on the size of the shader IDs of this backend. std::vector DebugGetShaderIDs(DebugShaderType shader) override; std::string DebugGetShaderString(std::string id, DebugShaderType shader, DebugShaderStringType stringType) override; + void SetDisplayFramebuffer(u32 framebuf, u32 stride, GEBufferFormat format) override; + void InvalidateCache(u32 addr, int size, GPUInvalidationType type) override; + + bool FramebufferDirty() override; + bool FramebufferReallyDirty() override; + void Execute_VertexType(u32 op, u32 diff); void Execute_VertexTypeSkinning(u32 op, u32 diff);