diff --git a/core/libs/prx/libSceAgcDriver/CMakeLists.txt b/core/libs/prx/libSceAgcDriver/CMakeLists.txt index aa9532b25..0e0164af0 100644 --- a/core/libs/prx/libSceAgcDriver/CMakeLists.txt +++ b/core/libs/prx/libSceAgcDriver/CMakeLists.txt @@ -221,6 +221,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) @@ -413,7 +418,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 new file mode 100644 index 000000000..a5b5c0243 --- /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, 0x7e000000, 0x7e003600, 0x7e008200, 0x4a080881, + 0xd5800000, 0x00000000, 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 0f76c74ca..f65a7f223 100644 --- a/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp +++ b/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp @@ -261,6 +261,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 5696a630b..f8f84fcc0 100644 --- a/core/shader/recompiler/RdnaDecoder/src/RdnaOpcode.cpp +++ b/core/shader/recompiler/RdnaDecoder/src/RdnaOpcode.cpp @@ -209,6 +209,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 4587c519d..b2e403665 100644 --- a/core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp +++ b/core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp @@ -120,6 +120,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}, @@ -140,6 +141,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}, @@ -182,6 +184,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}, @@ -202,6 +205,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}, @@ -613,6 +617,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; } @@ -1801,7 +1809,7 @@ RdnaInstruction DecodeRdnaVop1(std::uint32_t programCounter, std::span