From 527c8e46a8b531c84d2e54770644a855fe82f6d6 Mon Sep 17 00:00:00 2001 From: Michon <231849@buas.nl> Date: Sun, 4 Oct 2026 11:44:10 +0200 Subject: [PATCH] fix(shader): v_mov_b32 SDWA writes byte destinations v_mov_b32 accepted SDWA destination selectors for the words only; a byte destination (dst_sel BYTE_0..3) threw 'VOP1 SDWA destination selector is not supported'. The write itself already handles bytes and every dst_unused mode (TranslationContext::writeRawU32). GTA V aborted during boot on such a move (dst_sel BYTE_0, dst_unused UNUSED_PRESERVE) in one of its eboot compute shaders. The error now names the selector, opcode and pc. The SDWA destination execution test covers BYTE_0 and BYTE_2 with UNUSED_PRESERVE and BYTE_1 with UNUSED_PAD. Co-Authored-By: Claude Opus 5.5 (1M context) --- .../tests/execution/SdwaDestination.cpp | 15 +++++++++++---- .../RdnaDecoder/src/RdnaVectorOpDecoder.cpp | 6 ++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/core/libs/prx/libSceAgcDriver/tests/execution/SdwaDestination.cpp b/core/libs/prx/libSceAgcDriver/tests/execution/SdwaDestination.cpp index 991ad47d8..029da07e4 100644 --- a/core/libs/prx/libSceAgcDriver/tests/execution/SdwaDestination.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/execution/SdwaDestination.cpp @@ -22,13 +22,16 @@ constexpr std::uint32_t Garbage = 0xabcd1234u; alignas(256) std::array Input{}; alignas(256) std::array Output{}; -alignas(256) constexpr std::array SdwaCode{ +alignas(256) constexpr std::array SdwaCode{ 0x34020082, 0x34060083, 0xe0302000, 0x80000401, 0xe0302004, 0x80000501, 0xe0302008, 0x80000601, 0x7e1402ff, 0xabcd1234, 0x7e1602ff, 0xabcd1234, 0x7e1802ff, 0xabcd1234, 0x7e1a02ff, 0xabcd1234, - 0x7e1c02ff, 0xabcd1234, 0x7e1e02ff, 0xabcd1234, 0xbf8c3f70, 0x7e1414f9, 0x00060604, 0x7e161504, + 0x7e1c02ff, 0xabcd1234, 0x7e1e02ff, 0xabcd1234, 0x7e2002ff, 0xabcd1234, 0x7e2202ff, 0xabcd1234, + 0x7e2402ff, 0xabcd1234, 0xbf8c3f70, 0x7e1414f9, 0x00060604, 0x7e161504, 0x7e1814f9, 0x00061505, 0x7e1a14f9, 0x00060604, 0x7e1c14f9, 0x00060605, 0xd746000d, 0x0435210e, - 0x641e0cf9, 0x05040606, 0xe0702000, 0x80010a03, 0xe0702004, 0x80010b03, 0xe0702008, 0x80010c03, - 0xe070200c, 0x80010d03, 0xe0702010, 0x80010f03, 0xbf810000, + 0x641e0cf9, 0x05040606, 0x7e2002f9, 0x00061004, 0x7e2202f9, 0x00061204, 0x7e2402f9, 0x00060104, + 0xe0702000, 0x80010a03, 0xe0702004, 0x80010b03, 0xe0702008, 0x80010c03, + 0xe070200c, 0x80010d03, 0xe0702010, 0x80010f03, 0xe0702014, 0x80011003, 0xe0702018, 0x80011103, + 0xe070201c, 0x80011203, 0xbf810000, }; float Quarter(std::uint32_t index) { @@ -99,6 +102,10 @@ void Check() { Require(out[2] == ((b << 16u) | (Garbage & 0xffffu)), where(2) + ", expected " + Hex((b << 16u) | (Garbage & 0xffffu)) + ": dst_sel:WORD_1 dst_unused:UNUSED_PRESERVE must keep the low half"); Require(out[3] == (a | (b << 16u)), where(3) + ", expected " + Hex(a | (b << 16u)) + ": two padded conversions packed with v_lshl_add_u32"); Require(out[4] == sum, where(4) + ", expected " + Hex(sum) + ": v_add_f16_sdwa dst_sel:DWORD dst_unused:UNUSED_PAD must zero the high half"); + const auto low = in[0] & 0xffu; + Require(out[5] == ((Garbage & 0xffffff00u) | low), where(5) + ", expected " + Hex((Garbage & 0xffffff00u) | low) + ": v_mov_b32_sdwa dst_sel:BYTE_0 dst_unused:UNUSED_PRESERVE must keep the other bytes"); + Require(out[6] == ((Garbage & 0xff00ffffu) | (low << 16u)), where(6) + ", expected " + Hex((Garbage & 0xff00ffffu) | (low << 16u)) + ": v_mov_b32_sdwa dst_sel:BYTE_2 dst_unused:UNUSED_PRESERVE must keep the other bytes"); + Require(out[7] == (low << 8u), where(7) + ", expected " + Hex(low << 8u) + ": v_mov_b32_sdwa dst_sel:BYTE_1 dst_unused:UNUSED_PAD must zero the other bytes"); } } diff --git a/core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp b/core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp index ab452dd00..80ee12863 100644 --- a/core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp +++ b/core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp @@ -958,7 +958,7 @@ struct Vop1SdwaRule { }; constexpr Vop1SdwaRule vop1SdwaRules[] = { - {RdnaOpcode::VMovB32, sdwaSelAll(), sdwaSelWords(), sdwaSelWords() | sdwaSelFull(), false}, + {RdnaOpcode::VMovB32, sdwaSelAll(), sdwaSelBytes() | sdwaSelWords(), sdwaSelWords() | sdwaSelFull(), false}, {RdnaOpcode::VCvtF32U32, sdwaSelAll(), 0, 0, false}, {RdnaOpcode::VCvtF32I32, sdwaSelAll(), 0, 0, false}, {RdnaOpcode::VCvtF32Ubyte0, sdwaSelAll(), 0, 0, false}, @@ -1030,7 +1030,9 @@ void validateVop1Sdwa(const RdnaInstruction& instruction, std::uint32_t destinat throw std::invalid_argument("VOP1 SDWA output modifiers are not supported"); } if (!isVop1SdwaDestinationSupported(instruction.op, destinationSelector, destinationUnused, sourceSelector)) { - throw std::invalid_argument("VOP1 SDWA destination selector is not supported"); + char text[128]; + std::snprintf(text, sizeof(text), "VOP1 SDWA destination selector %u (unused %u, source selector %u) of opcode 0x%x at pc 0x%x is not supported", destinationSelector, destinationUnused, sourceSelector, instruction.opcodeId, instruction.programCounter); + throw std::invalid_argument(text); } if (!isVop1SdwaSourceSupported(instruction.op, sourceSelector, sourceNegate, sourceAbsolute)) { char text[96];