From e8e5518c04b433e7dac88851c33c43f0e274f6d3 Mon Sep 17 00:00:00 2001 From: DotDebian Date: Fri, 2 Oct 2026 17:23:09 +0200 Subject: [PATCH 1/2] feat(shader): decode v_pipeflush and v_clrexcp as no-ops v_pipeflush (VOP1 0x1b) and v_clrexcp (VOP1 0x41) threw in the decoder, as did their VOP3 forms. SPIR-V has no ALU pipeline to flush, and the recompiler keeps no exception flags for v_clrexcp to clear, so both translate like v_nop, which emits nothing. Neither has operands: they decode with a null destination and no sources. The VOP3 form of v_nop decoded a destination and a source it does not have and now takes the same path. Co-Authored-By: Claude Opus 5.5 --- .../tests/execution/Vop1Control.cpp | 78 +++++++++++++++++++ .../include/RdnaDecoder/RdnaOpcode.hpp | 2 + .../recompiler/RdnaDecoder/src/RdnaOpcode.cpp | 2 + .../RdnaDecoder/src/RdnaVectorOpDecoder.cpp | 15 +++- .../Translation/src/VectorInstructions.cpp | 2 + 5 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 core/libs/prx/libSceAgcDriver/tests/execution/Vop1Control.cpp diff --git a/core/libs/prx/libSceAgcDriver/tests/execution/Vop1Control.cpp b/core/libs/prx/libSceAgcDriver/tests/execution/Vop1Control.cpp new file mode 100644 index 000000000..e0a4e8e04 --- /dev/null +++ b/core/libs/prx/libSceAgcDriver/tests/execution/Vop1Control.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 Vop1ControlCode{ + 0x34020082, 0xe0302000, 0x80000401, 0xbf8c3f70, 0x7e003600, 0x7e008200, 0x4a080881, + 0xd59b0000, 0x00000000, 0xd5c10000, 0x00000000, 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(Vop1ControlCode); + 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, "vop1 control: 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("vop1 control 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..d78542a44 100644 --- a/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp +++ b/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp @@ -220,6 +220,8 @@ enum class RdnaOpcode : std::uint16_t { SCmpEqU64, SCmpLgU64, VNop, + VPipeflush, + VClrexcp, VMovrelsB32, VPermlane16B32, VPermlanex16B32, diff --git a/core/shader/recompiler/RdnaDecoder/src/RdnaOpcode.cpp b/core/shader/recompiler/RdnaDecoder/src/RdnaOpcode.cpp index fcf4df05b..56f09af59 100644 --- a/core/shader/recompiler/RdnaDecoder/src/RdnaOpcode.cpp +++ b/core/shader/recompiler/RdnaDecoder/src/RdnaOpcode.cpp @@ -193,6 +193,8 @@ bool IsVectorAluOpcode(RdnaOpcode opcode) { case RdnaOpcode::VWritelaneB32: case RdnaOpcode::VMovreldB32: case RdnaOpcode::VNop: + case RdnaOpcode::VPipeflush: + case RdnaOpcode::VClrexcp: case RdnaOpcode::VMovrelsB32: case RdnaOpcode::VPermlane16B32: case RdnaOpcode::VPermlanex16B32: diff --git a/core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp b/core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp index 5b664ec8b..0db22db46 100644 --- a/core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp +++ b/core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp @@ -117,6 +117,7 @@ constexpr VectorOpcodeInfo vop1Opcodes[] = { {0x12u, RdnaOpcode::VCvtF32Ubyte1}, {0x13u, RdnaOpcode::VCvtF32Ubyte2}, {0x14u, RdnaOpcode::VCvtF32Ubyte3}, + {0x1bu, RdnaOpcode::VPipeflush}, {0x2au, RdnaOpcode::VRcpF32}, {0x20u, RdnaOpcode::VFractF32}, {0x21u, RdnaOpcode::VTruncF32}, @@ -137,6 +138,7 @@ constexpr VectorOpcodeInfo vop1Opcodes[] = { {0x3bu, RdnaOpcode::VFfbhI32}, {0x3fu, RdnaOpcode::VFrexpExpI32F32}, {0x40u, RdnaOpcode::VFrexpMantF32}, + {0x41u, RdnaOpcode::VClrexcp}, {0x42u, RdnaOpcode::VMovreldB32}, {0x43u, RdnaOpcode::VMovrelsB32}, {0x50u, RdnaOpcode::VCvtF16U16}, @@ -174,6 +176,7 @@ constexpr VectorOpcodeInfo vop3EncodedVop1Opcodes[] = { {0x12u, RdnaOpcode::VCvtF32Ubyte1}, {0x13u, RdnaOpcode::VCvtF32Ubyte2}, {0x14u, RdnaOpcode::VCvtF32Ubyte3}, + {0x1bu, RdnaOpcode::VPipeflush}, {0x2au, RdnaOpcode::VRcpF32}, {0x20u, RdnaOpcode::VFractF32}, {0x21u, RdnaOpcode::VTruncF32}, @@ -194,6 +197,7 @@ constexpr VectorOpcodeInfo vop3EncodedVop1Opcodes[] = { {0x3bu, RdnaOpcode::VFfbhI32}, {0x3fu, RdnaOpcode::VFrexpExpI32F32}, {0x40u, RdnaOpcode::VFrexpMantF32}, + {0x41u, RdnaOpcode::VClrexcp}, {0x42u, RdnaOpcode::VMovreldB32}, {0x43u, RdnaOpcode::VMovrelsB32}, {0x50u, RdnaOpcode::VCvtF16U16}, @@ -555,6 +559,10 @@ RdnaOpcode lookupVintrpOpcode(std::uint32_t opcode) { } } +bool isVop1WithoutOperands(RdnaOpcode opcode) { + return opcode == RdnaOpcode::VNop || opcode == RdnaOpcode::VPipeflush || opcode == RdnaOpcode::VClrexcp; +} + bool usesScalarDestination(RdnaOpcode opcode) { return opcode == RdnaOpcode::VReadfirstlaneB32 || opcode == RdnaOpcode::VReadlaneB32; } @@ -1653,7 +1661,7 @@ RdnaInstruction DecodeRdnaVop1(std::uint32_t programCounter, std::span Date: Fri, 2 Oct 2026 17:50:53 +0200 Subject: [PATCH 2/2] test(shader): cover the operand-less decoding of v_nop, v_pipeflush and v_clrexcp The VOP3 form of v_nop now decodes without operands, and no test looked at it. agc_vop1_control_decode decodes the three instructions in VOP1 and VOP3 form and checks the opcode, the length, the null destination and the absence of sources. agc_driver_vop1_control also runs v_nop in both forms. Co-Authored-By: Claude Opus 5.5 --- core/libs/prx/libSceAgcDriver/CMakeLists.txt | 7 +++- .../tests/Vop1ControlDecode.cpp | 42 +++++++++++++++++++ .../tests/execution/Vop1Control.cpp | 6 +-- 3 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 core/libs/prx/libSceAgcDriver/tests/Vop1ControlDecode.cpp diff --git a/core/libs/prx/libSceAgcDriver/CMakeLists.txt b/core/libs/prx/libSceAgcDriver/CMakeLists.txt index cd4a431dc..dc2eda021 100644 --- a/core/libs/prx/libSceAgcDriver/CMakeLists.txt +++ b/core/libs/prx/libSceAgcDriver/CMakeLists.txt @@ -220,6 +220,11 @@ target_link_libraries(agc_dpp_write_tests PRIVATE shader_recompiler_agc_driver l set_target_properties(agc_dpp_write_tests PROPERTIES CXX_EXTENSIONS OFF) configure_windows_unwind(agc_dpp_write_tests) +add_test_executable(agc_vop1_control_decode_tests EXCLUDE_FROM_ALL tests/Vop1ControlDecode.cpp) +target_link_libraries(agc_vop1_control_decode_tests PRIVATE shader_recompiler_agc_driver libc) +set_target_properties(agc_vop1_control_decode_tests PROPERTIES CXX_EXTENSIONS OFF) +configure_windows_unwind(agc_vop1_control_decode_tests) + add_test_executable(agc_shader_disk_cache_tests EXCLUDE_FROM_ALL tests/ShaderDiskCache.cpp) target_include_directories(agc_shader_disk_cache_tests PRIVATE ${LIBS_INCLUDE_DIR}) target_link_libraries(agc_shader_disk_cache_tests PRIVATE shader_recompiler_agc_driver libc) @@ -411,7 +416,7 @@ foreach(agcExecutionTestSource IN LISTS agcExecutionTestSources) endforeach() if(BUILD_TESTING) - foreach(agcTest IN ITEMS agc_driver_tests agc_shader_memory_tests agc_structurizer_tests agc_dpp_write_tests agc_shader_disk_cache_tests agc_shader_control_flow_tests agc_driver_flip_tests agc_driver_pm4_tests agc_driver_graphics_tests ${agcExecutionTests}) + foreach(agcTest IN ITEMS agc_driver_tests agc_shader_memory_tests agc_structurizer_tests agc_dpp_write_tests agc_vop1_control_decode_tests agc_shader_disk_cache_tests agc_shader_control_flow_tests agc_driver_flip_tests agc_driver_pm4_tests agc_driver_graphics_tests ${agcExecutionTests}) string(REGEX REPLACE "_tests$" "" agcTestName "${agcTest}") set_target_properties(${agcTest} PROPERTIES EXCLUDE_FROM_ALL OFF) add_test(NAME ${agcTestName} COMMAND ${agcTest}) diff --git a/core/libs/prx/libSceAgcDriver/tests/Vop1ControlDecode.cpp b/core/libs/prx/libSceAgcDriver/tests/Vop1ControlDecode.cpp new file mode 100644 index 000000000..373ae8e5b --- /dev/null +++ b/core/libs/prx/libSceAgcDriver/tests/Vop1ControlDecode.cpp @@ -0,0 +1,42 @@ +#include "RdnaDecoder/RdnaInstructionDecoder.hpp" +#include +#include +#include +#include + +using namespace ShaderRecompiler; + +int main() { + const std::vector code{ + 0x7e000000u, 0x7e003600u, 0x7e008200u, + 0xd5800000u, 0x00000000u, 0xd59b0000u, 0x00000000u, 0xd5c10000u, 0x00000000u, + 0xbf810000u, + }; + constexpr std::array expected{ + RdnaOpcode::VNop, RdnaOpcode::VPipeflush, RdnaOpcode::VClrexcp, + RdnaOpcode::VNop, RdnaOpcode::VPipeflush, RdnaOpcode::VClrexcp, + }; + try { + const auto decoded = RdnaInstructionDecoder{}.Decode(code); + if (decoded.instructions.size() != expected.size() + 1u) { + std::fprintf(stderr, "decoded %zu instructions, expected %zu\n", decoded.instructions.size(), expected.size() + 1u); + return 1; + } + for (std::size_t index = 0; index < expected.size(); ++index) { + const auto& instruction = decoded.instructions[index]; + const auto wordCount = index < 3u ? 1u : 2u; + if (instruction.op != expected[index] || instruction.wordCount != wordCount) { + std::fprintf(stderr, "instruction %zu decodes to the wrong opcode or length\n", index); + return 1; + } + if (instruction.destination.kind != RdnaOperandKind::Null || instruction.sourceCount != 0u) { + std::fprintf(stderr, "instruction %zu decodes with operands\n", index); + return 1; + } + } + return 0; + } catch (const std::exception& error) { + std::fprintf(stderr, "%s\n", error.what()); + } + return 1; +} diff --git a/core/libs/prx/libSceAgcDriver/tests/execution/Vop1Control.cpp b/core/libs/prx/libSceAgcDriver/tests/execution/Vop1Control.cpp index e0a4e8e04..a5b5c0243 100644 --- a/core/libs/prx/libSceAgcDriver/tests/execution/Vop1Control.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/execution/Vop1Control.cpp @@ -20,9 +20,9 @@ constexpr std::uint32_t Stride = 4; alignas(256) std::array Input{}; alignas(256) std::array Output{}; -alignas(256) constexpr std::array Vop1ControlCode{ - 0x34020082, 0xe0302000, 0x80000401, 0xbf8c3f70, 0x7e003600, 0x7e008200, 0x4a080881, - 0xd59b0000, 0x00000000, 0xd5c10000, 0x00000000, 0xe0702000, 0x80010401, 0xbf810000, +alignas(256) constexpr std::array Vop1ControlCode{ + 0x34020082, 0xe0302000, 0x80000401, 0xbf8c3f70, 0x7e000000, 0x7e003600, 0x7e008200, 0x4a080881, + 0xd5800000, 0x00000000, 0xd59b0000, 0x00000000, 0xd5c10000, 0x00000000, 0xe0702000, 0x80010401, 0xbf810000, }; std::array BufferDescriptor(const void* data, std::uint32_t count) {