From 146795c9cbdd6c62c0a5e8c324b4496eaf604726 Mon Sep 17 00:00:00 2001 From: DotDebian Date: Fri, 2 Oct 2026 18:10:07 +0200 Subject: [PATCH] feat(shader): decode s_wakeup as a no-op s_wakeup (SOPP 0x03) threw "unsupported SOPP opcode 3" in the decoder. It pings the other waves of the thread group so they leave s_sleep early. s_sleep already translates to nothing, so no wave is ever asleep and the ping has nothing to wake: s_wakeup translates like s_sleep. It carries no operand. Co-Authored-By: Claude Opus 5.5 --- .../tests/execution/WaveSleep.cpp | 78 +++++++++++++++++++ .../include/RdnaDecoder/RdnaOpcode.hpp | 1 + .../RdnaDecoder/src/RdnaScalarOpDecoder.cpp | 1 + .../Translation/src/ScalarInstructions.cpp | 1 + 4 files changed, 81 insertions(+) create mode 100644 core/libs/prx/libSceAgcDriver/tests/execution/WaveSleep.cpp diff --git a/core/libs/prx/libSceAgcDriver/tests/execution/WaveSleep.cpp b/core/libs/prx/libSceAgcDriver/tests/execution/WaveSleep.cpp new file mode 100644 index 000000000..2dc63c57c --- /dev/null +++ b/core/libs/prx/libSceAgcDriver/tests/execution/WaveSleep.cpp @@ -0,0 +1,78 @@ +#include "prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp" +#include "prx/libSceAgcDriver/Graphics/include/Draw.hpp" +#include "Recompiler.hpp" +#include "VulkanTestDevice.hpp" +#include +#include +#include +#include +#include +#include +#include + +namespace { + +using AgcDriver::Graphics::Require; +using ShaderRecompiler::ShaderStage; + +constexpr std::uint32_t Threads = 64; +constexpr std::uint32_t Stride = 4; +alignas(256) std::array Input{}; +alignas(256) std::array Output{}; + +alignas(256) constexpr std::array WaveSleepCode{ + 0x34020082, 0xbf830000, 0xe0302000, 0x80000401, 0xbf8c3f70, 0xbf8e0001, + 0xbf830000, 0x4a080881, 0xbf830000, 0xe0702000, 0x80010401, 0xbf810000, +}; + +std::array BufferDescriptor(const void* data, std::uint32_t count) { + const auto address = reinterpret_cast(data); + return {static_cast(address), static_cast((address >> 32u) & 0xffffu) | (4u << 16u), count, 0x01016facu}; +} + +void Run(AgcDriver::VulkanDevice& device) { + for (std::uint32_t tid = 0; tid < Threads; ++tid) Input[tid * Stride] = tid * 0x01010101u + 7u; + Output.fill(0xdeadbeefu); + std::vector userData(8, 0u); + const auto input = BufferDescriptor(Input.data(), static_cast(Input.size())); + const auto output = BufferDescriptor(Output.data(), static_cast(Output.size())); + std::copy(input.begin(), input.end(), userData.begin()); + std::copy(output.begin(), output.end(), userData.begin() + 4); + const std::span code(WaveSleepCode); + const std::array memory{{{reinterpret_cast(code.data()), std::as_bytes(code)}}}; + const ShaderRecompiler::ShaderComputeStageInfo compute{{Threads, 1, 1}, 0, {false, false, false}, false, 1}; + ShaderRecompiler::RecompileRequest request{ + {ShaderStage::Compute, reinterpret_cast(code.data()), code, 0, {}}, + {32, 0, userData, compute, std::nullopt, std::nullopt, memory}, + device.Target(), + {0, 0, 0, 128} + }; + request.useCache = false; + const auto result = ShaderRecompiler::Recompile(request); + device.Dispatch(result, 1, 1, 1, {}, reinterpret_cast(code.data())); + device.WaitIdle(); +} + +void Check() { + for (std::uint32_t tid = 0; tid < Threads; ++tid) { + const auto expected = Input[tid * Stride] + 1u; + const auto actual = Output[tid * Stride]; + Require(actual == expected, "wave sleep: thread " + std::to_string(tid) + " is " + std::to_string(actual) + ", expected " + std::to_string(expected)); + } +} + +} + +int main() { + try { + const auto device = OpenVulkanTestDevice(); + if (!device) return VulkanTestSkipped; + Run(*device); + Check(); + std::puts("wave sleep tests passed"); + return 0; + } catch (const std::exception& error) { + std::cerr << error.what() << '\n'; + return 1; + } +} diff --git a/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp b/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp index a1e040990..71781ac0b 100644 --- a/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp +++ b/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp @@ -663,6 +663,7 @@ enum class RdnaOpcode : std::uint16_t { SSendmsg, SSetregB32, SSleep, + SWakeup, STrap, STtracedata, SInstPrefetch, diff --git a/core/shader/recompiler/RdnaDecoder/src/RdnaScalarOpDecoder.cpp b/core/shader/recompiler/RdnaDecoder/src/RdnaScalarOpDecoder.cpp index a48ae2d81..9a21dff2b 100644 --- a/core/shader/recompiler/RdnaDecoder/src/RdnaScalarOpDecoder.cpp +++ b/core/shader/recompiler/RdnaDecoder/src/RdnaScalarOpDecoder.cpp @@ -179,6 +179,7 @@ RdnaOpcode decodeSoppOpcode(std::uint32_t opcode) { case 0x00u: return RdnaOpcode::SNop; case 0x01u: return RdnaOpcode::SEndpgm; case 0x02u: return RdnaOpcode::SBranch; + case 0x03u: return RdnaOpcode::SWakeup; case 0x04u: return RdnaOpcode::SCbranchScc0; case 0x05u: return RdnaOpcode::SCbranchScc1; case 0x06u: return RdnaOpcode::SCbranchVccz; diff --git a/core/shader/recompiler/Translation/src/ScalarInstructions.cpp b/core/shader/recompiler/Translation/src/ScalarInstructions.cpp index f4ae67ec0..021fa031f 100644 --- a/core/shader/recompiler/Translation/src/ScalarInstructions.cpp +++ b/core/shader/recompiler/Translation/src/ScalarInstructions.cpp @@ -347,6 +347,7 @@ bool TranslationContext::emitScalar(const RdnaInstruction& inst) { return packB16(inst, true, true); case RdnaOpcode::SNop: case RdnaOpcode::SSleep: + case RdnaOpcode::SWakeup: case RdnaOpcode::SSetprio: case RdnaOpcode::STrap: case RdnaOpcode::SClause: