From 5a257bee527299a1ed7f63756e942191d652711a Mon Sep 17 00:00:00 2001 From: Dean Galvin Date: Tue, 29 Sep 2026 07:36:53 +1300 Subject: [PATCH] feat(recompiler): conditional debug branches translate as never taken S_CBRANCH_CDBGSYS, S_CBRANCH_CDBGUSER, S_CBRANCH_CDBGSYS_OR_USER and S_CBRANCH_CDBGSYS_AND_USER (SOPP 0x17-0x1a) branch only while a debugger sets the conditional debug bits in the wave's status, which never happens on a retail console, so they decode to one no-op opcode. --- .../prx/libSceAgcDriver/tests/Graphics.cpp | 24 +++++++++++++++++++ .../include/RdnaDecoder/RdnaOpcode.hpp | 1 + .../RdnaDecoder/src/RdnaScalarOpDecoder.cpp | 6 ++++- .../Translation/src/ScalarInstructions.cpp | 2 ++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp b/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp index dacf921c2..8a1ea8586 100644 --- a/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/Graphics.cpp @@ -1142,6 +1142,29 @@ void validationTests() { } +bool recompilesDebugBranch(std::uint32_t opcode) { + auto queue = makeState(); + queue.context[0x1b3] = 0x2u; + queue.context[0x1b4] = 0x2u; + const auto pixel = AgcDriver::Graphics::DecodePixelStageInfo(queue.context, true, 0xe4u); + const std::array code{0xbf800000u | (opcode << 16u) | 1u, 0xf800180fu, 0x00000000u, 0xbf810000u}; + ShaderRecompiler::RecompileRequest request{}; + request.shader = {ShaderRecompiler::ShaderStage::Fragment, 0x30000u, code, 0, {}}; + request.context.waveSize = 64; + request.context.pixel = pixel; + request.target.vulkanVersion = 0x00401000u; + request.target.spirvVersion = 0x00010300u; + request.target.subgroupSize = 64; + request.target.fragmentShaderBarycentricEnabled = true; + request.layout.pushConstantSizeBytes = 128; + request.useCache = false; + return !ShaderRecompiler::Recompile(request).spirv.Words().empty(); +} + +void debugBranchTests() { + for (const auto opcode : {0x17u, 0x18u, 0x19u, 0x1au}) Require(recompilesDebugBranch(opcode), "a conditional debug branch did not recompile"); +} + int main() { try { { @@ -1173,6 +1196,7 @@ int main() { InitialContextTests(); pushConstantTests(); resourceTests(); + debugBranchTests(); validationTests(); rectListTests(); mock = MockVulkan{}; diff --git a/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp b/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp index 70329c435..07e912edb 100644 --- a/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp +++ b/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp @@ -577,6 +577,7 @@ enum class RdnaOpcode : std::uint16_t { STtracedata, SInstPrefetch, SClause, + SCbranchCdbg, Exp, Count }; diff --git a/core/shader/recompiler/RdnaDecoder/src/RdnaScalarOpDecoder.cpp b/core/shader/recompiler/RdnaDecoder/src/RdnaScalarOpDecoder.cpp index 3bff0baac..c0ef5f362 100644 --- a/core/shader/recompiler/RdnaDecoder/src/RdnaScalarOpDecoder.cpp +++ b/core/shader/recompiler/RdnaDecoder/src/RdnaScalarOpDecoder.cpp @@ -175,6 +175,10 @@ RdnaOpcode decodeSoppOpcode(std::uint32_t opcode) { case 0x10u: return RdnaOpcode::SSendmsg; case 0x12u: return RdnaOpcode::STrap; case 0x16u: return RdnaOpcode::STtracedata; + case 0x17u: + case 0x18u: + case 0x19u: + case 0x1au: return RdnaOpcode::SCbranchCdbg; case 0x20u: return RdnaOpcode::SInstPrefetch; case 0x21u: return RdnaOpcode::SClause; case 0x23u: return RdnaOpcode::SWaitcntDepctr; @@ -193,7 +197,7 @@ bool isSoppWaitOpcode(RdnaOpcode opcode) { return opcode == RdnaOpcode::SNop || opcode == RdnaOpcode::SWaitcnt || opcode == RdnaOpcode::SWaitcntDepctr || opcode == RdnaOpcode::SSleep || opcode == RdnaOpcode::SSetprio || opcode == RdnaOpcode::SSendmsg || opcode == RdnaOpcode::STrap || opcode == RdnaOpcode::STtracedata || opcode == RdnaOpcode::SInstPrefetch || - opcode == RdnaOpcode::SClause; + opcode == RdnaOpcode::SClause || opcode == RdnaOpcode::SCbranchCdbg; } std::uint32_t scalarDestinationDwordCount(RdnaOpcode opcode) { diff --git a/core/shader/recompiler/Translation/src/ScalarInstructions.cpp b/core/shader/recompiler/Translation/src/ScalarInstructions.cpp index 1d9e9380e..6fbaf52c5 100644 --- a/core/shader/recompiler/Translation/src/ScalarInstructions.cpp +++ b/core/shader/recompiler/Translation/src/ScalarInstructions.cpp @@ -318,6 +318,8 @@ bool TranslationContext::emitScalar(const RdnaInstruction& inst) { case RdnaOpcode::SInstPrefetch: sInstPrefetch(); return true; + case RdnaOpcode::SCbranchCdbg: + return true; case RdnaOpcode::SBranch: case RdnaOpcode::SCbranchScc0: case RdnaOpcode::SCbranchScc1: