From 7b3687d79c16e4e102fa8151625e22c3ece10f50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 15 Dec 2024 10:49:49 +0100 Subject: [PATCH] Replace a fiddly callback with a global bool (which later won't be global) --- GPU/Debugger/Breakpoints.cpp | 37 +++++++++++++++++------------------- GPU/Debugger/Breakpoints.h | 5 ++++- GPU/Debugger/Debugger.cpp | 16 +--------------- 3 files changed, 22 insertions(+), 36 deletions(-) diff --git a/GPU/Debugger/Breakpoints.cpp b/GPU/Debugger/Breakpoints.cpp index e4e521404b..debc260bba 100644 --- a/GPU/Debugger/Breakpoints.cpp +++ b/GPU/Debugger/Breakpoints.cpp @@ -29,9 +29,6 @@ namespace GPUBreakpoints { -static void NothingToDo(bool) { -} - struct BreakpointInfo { bool isConditional = false; PostfixExpression expression; @@ -48,7 +45,6 @@ static std::set breakRenderTargets; static size_t breakPCsCount = 0; static size_t breakTexturesCount = 0; static size_t breakRenderTargetsCount = 0; -static std::function notifyBreakpoints = &NothingToDo; // If these are set, the above are also, but they should be temporary. static bool breakCmdsTemp[256]; @@ -57,6 +53,8 @@ static std::set breakTexturesTemp; static std::set breakRenderTargetsTemp; static bool textureChangeTemp = false; +bool g_hasBreakpoints; + static u32 lastTexture = 0xFFFFFFFF; // These are commands we run before breaking on a texture. @@ -76,8 +74,7 @@ const static u8 textureRelatedCmds[] = { }; static std::vector nonTextureCmds; -void Init(void (*hasBreakpoints)(bool flag)) { - notifyBreakpoints = hasBreakpoints; +void Init() { ClearAllBreakpoints(); nonTextureCmds.clear(); @@ -350,7 +347,7 @@ void AddAddressBreakpoint(u32 addr, bool temp) { } breakPCsCount = breakPCs.size(); - notifyBreakpoints(true); + g_hasBreakpoints = true; } void AddCmdBreakpoint(u8 cmd, bool temp) { @@ -369,7 +366,7 @@ void AddCmdBreakpoint(u8 cmd, bool temp) { breakCmdsInfo[cmd].isConditional = false; } } - notifyBreakpoints(true); + g_hasBreakpoints = true; } void AddTextureBreakpoint(u32 addr, bool temp) { @@ -386,7 +383,7 @@ void AddTextureBreakpoint(u32 addr, bool temp) { } breakTexturesCount = breakTextures.size(); - notifyBreakpoints(true); + g_hasBreakpoints = true; } void AddRenderTargetBreakpoint(u32 addr, bool temp) { @@ -405,19 +402,19 @@ void AddRenderTargetBreakpoint(u32 addr, bool temp) { } breakRenderTargetsCount = breakRenderTargets.size(); - notifyBreakpoints(true); + g_hasBreakpoints = true; } void AddTextureChangeTempBreakpoint() { textureChangeTemp = true; - notifyBreakpoints(true); + g_hasBreakpoints = true; } void AddAnyTempBreakpoint() { for (int i = 0; i < 256; ++i) { AddCmdBreakpoint(i, true); } - notifyBreakpoints(true); + g_hasBreakpoints = true; } void RemoveAddressBreakpoint(u32 addr) { @@ -427,7 +424,7 @@ void RemoveAddressBreakpoint(u32 addr) { breakPCs.erase(addr); breakPCsCount = breakPCs.size(); - notifyBreakpoints(HasAnyBreakpoints()); + g_hasBreakpoints = HasAnyBreakpoints(); } void RemoveCmdBreakpoint(u8 cmd) { @@ -435,7 +432,7 @@ void RemoveCmdBreakpoint(u8 cmd) { breakCmdsTemp[cmd] = false; breakCmds[cmd] = false; - notifyBreakpoints(HasAnyBreakpoints()); + g_hasBreakpoints = HasAnyBreakpoints(); } void RemoveTextureBreakpoint(u32 addr) { @@ -445,7 +442,7 @@ void RemoveTextureBreakpoint(u32 addr) { breakTextures.erase(addr); breakTexturesCount = breakTextures.size(); - notifyBreakpoints(HasAnyBreakpoints()); + g_hasBreakpoints = HasAnyBreakpoints(); } void RemoveRenderTargetBreakpoint(u32 addr) { @@ -457,14 +454,14 @@ void RemoveRenderTargetBreakpoint(u32 addr) { breakRenderTargets.erase(addr); breakRenderTargetsCount = breakRenderTargets.size(); - notifyBreakpoints(HasAnyBreakpoints()); + g_hasBreakpoints = HasAnyBreakpoints(); } void RemoveTextureChangeTempBreakpoint() { std::lock_guard guard(breaksLock); textureChangeTemp = false; - notifyBreakpoints(HasAnyBreakpoints()); + g_hasBreakpoints = HasAnyBreakpoints(); } static bool SetupCond(BreakpointInfo &bp, const std::string &expression, std::string *error) { @@ -548,7 +545,7 @@ void ClearAllBreakpoints() { breakRenderTargetsCount = breakRenderTargets.size(); textureChangeTemp = false; - notifyBreakpoints(false); + g_hasBreakpoints = false; } void ClearTempBreakpoints() { @@ -581,7 +578,7 @@ void ClearTempBreakpoints() { breakRenderTargetsCount = breakRenderTargets.size(); textureChangeTemp = false; - notifyBreakpoints(HasAnyBreakpoints()); + g_hasBreakpoints = HasAnyBreakpoints(); } -}; +} // namespace diff --git a/GPU/Debugger/Breakpoints.h b/GPU/Debugger/Breakpoints.h index cdb3215abf..90bf5df083 100644 --- a/GPU/Debugger/Breakpoints.h +++ b/GPU/Debugger/Breakpoints.h @@ -21,7 +21,10 @@ #include "Common/CommonTypes.h" namespace GPUBreakpoints { - void Init(void (*hasBreakpoints)(bool flag)); + +extern bool g_hasBreakpoints; + + void Init(); bool IsBreakpoint(u32 pc, u32 op); diff --git a/GPU/Debugger/Debugger.cpp b/GPU/Debugger/Debugger.cpp index fdad58cda1..740f47e612 100644 --- a/GPU/Debugger/Debugger.cpp +++ b/GPU/Debugger/Debugger.cpp @@ -27,10 +27,8 @@ namespace GPUDebug { static bool active = false; -static bool inited = false; static BreakNext breakNext = BreakNext::NONE; static int breakAtCount = -1; -static bool hasBreakpoints = false; static int primsLastFrame = 0; static int primsThisFrame = 0; @@ -60,18 +58,7 @@ const char *BreakNextToString(BreakNext next) { } } -static void Init() { - if (!inited) { - GPUBreakpoints::Init([](bool flag) { - hasBreakpoints = flag; - }); - inited = true; - } -} - void SetActive(bool flag) { - Init(); - active = flag; if (!active) { breakNext = BreakNext::NONE; @@ -82,7 +69,6 @@ void SetActive(bool flag) { /* active = false; breakAtCount = -1; - hasBreakpoints = false; thisFlipNum = 0; g_primAfterDraw = false; lastStepTime = -1.0f; @@ -166,7 +152,7 @@ NotifyResult NotifyCommand(u32 pc) { isBreakpoint = true; } else if (breakNext == BreakNext::COUNT) { isBreakpoint = primsThisFrame == breakAtCount; - } else if (hasBreakpoints) { + } else if (GPUBreakpoints::g_hasBreakpoints) { isBreakpoint = GPUBreakpoints::IsBreakpoint(pc, op); }