From d7d36193db7dce8068c22fe1e975412b7135f4d3 Mon Sep 17 00:00:00 2001 From: DotDebian Date: Fri, 2 Oct 2026 17:50:53 +0200 Subject: [PATCH] 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) {