diff --git a/core/libs/prx/libSceAgcDriver/tests/execution/Vop3MadClamp.cpp b/core/libs/prx/libSceAgcDriver/tests/execution/Vop3MadClamp.cpp new file mode 100644 index 000000000..53aef39dc --- /dev/null +++ b/core/libs/prx/libSceAgcDriver/tests/execution/Vop3MadClamp.cpp @@ -0,0 +1,167 @@ +#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 +#include +#include + +namespace { + +using AgcDriver::Graphics::Require; +using ShaderRecompiler::ShaderStage; + +constexpr std::uint32_t Threads = 32; +constexpr std::uint32_t Inputs = 4; +constexpr std::uint32_t Results = 16; +alignas(256) std::array Input{}; +alignas(256) std::array Output{}; + +alignas(256) constexpr std::array Code{ + 0x34020084, 0x34060086, 0xe0381000, 0x80000401, 0xbf8c3f70, 0xd577880a, 0x041a0b04, 0xd501000c, + 0x00210280, 0xd576880d, 0x041a0b04, 0xd501000f, 0x00210280, 0xe0701000, 0x80010a03, 0xe0701004, + 0x80010b03, 0xe0701008, 0x80010c03, 0xe070100c, 0x80010d03, 0xe0701010, 0x80010e03, 0xe0701014, + 0x80010f03, 0xbf810000, +}; + +constexpr std::uint32_t Rows[32][4] = { + {0x00000001u, 0x00000001u, 0xfffffffeu, 0xffffffffu}, + {0x00000001u, 0x00000001u, 0xffffffffu, 0xffffffffu}, + {0x00000002u, 0x00000001u, 0xfffffffeu, 0xffffffffu}, + {0x00000001u, 0x00000001u, 0xfffffffeu, 0x7fffffffu}, + {0x00000001u, 0x00000001u, 0xffffffffu, 0x7fffffffu}, + {0x00000001u, 0xffffffffu, 0x00000001u, 0x80000000u}, + {0x00000001u, 0xffffffffu, 0x00000000u, 0x80000000u}, + {0x00000002u, 0xffffffffu, 0x00000001u, 0x80000000u}, + {0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u}, + {0xffffffffu, 0xffffffffu, 0x00000000u, 0x00000000u}, + {0x80000000u, 0x80000000u, 0x00000000u, 0x40000000u}, + {0x80000000u, 0x80000000u, 0xffffffffu, 0x3fffffffu}, + {0x7fffffffu, 0x80000000u, 0x00000000u, 0xc0000000u}, + {0x7fffffffu, 0x80000000u, 0xffffffffu, 0xbfffffffu}, + {0x7fffffffu, 0x7fffffffu, 0xffffffffu, 0x7fffffffu}, + {0xffffffffu, 0xffffffffu, 0xffffffffu, 0xffffffffu}, + {0x00000000u, 0x00000000u, 0xffffffffu, 0x7fffffffu}, + {0x00000000u, 0x00000000u, 0x00000000u, 0x80000000u}, + {0x00000000u, 0x80000000u, 0x00000000u, 0x00000000u}, + {0x00000001u, 0x80000000u, 0x00000000u, 0x00000000u}, + {0x00000001u, 0x80000000u, 0xffffffffu, 0xffffffffu}, + {0x80000000u, 0x00000000u, 0x00000000u, 0x00000000u}, + {0x80000000u, 0x00000000u, 0xffffffffu, 0xffffffffu}, + {0x80000000u, 0x00000001u, 0x00000000u, 0x00000000u}, + {0x80000000u, 0x00000001u, 0xffffffffu, 0xffffffffu}, + {0x80000000u, 0x00000001u, 0x00000000u, 0x80000000u}, + {0x80000000u, 0x80000000u, 0x00000000u, 0x80000000u}, + {0x80000000u, 0x80000001u, 0x00000000u, 0xc0000000u}, + {0x80000001u, 0xffffffffu, 0xffffffffu, 0x7fffffffu}, + {0xfffffffeu, 0xfffffffeu, 0x00000000u, 0x40000000u}, + {0x3ceb3ffdu, 0x97b75092u, 0x8b529b4au, 0x21636369u}, + {0x5eb561a4u, 0xea7b5bf5u, 0x9a9a80fdu, 0x795b929eu} +}; +constexpr std::uint32_t Expected[32][6] = { + {0xffffffffu, 0xffffffffu, 0x00000001u, 0xffffffffu, 0xffffffffu, 0x00000000u}, + {0x00000000u, 0x00000000u, 0x00000000u, 0xffffffffu, 0xffffffffu, 0x00000001u}, + {0x00000000u, 0x00000000u, 0x00000000u, 0xffffffffu, 0xffffffffu, 0x00000001u}, + {0xffffffffu, 0x7fffffffu, 0x00000000u, 0xffffffffu, 0x7fffffffu, 0x00000000u}, + {0xffffffffu, 0x7fffffffu, 0x00000000u, 0x00000000u, 0x80000000u, 0x00000000u}, + {0x00000000u, 0x80000000u, 0x00000001u, 0x00000000u, 0x80000001u, 0x00000000u}, + {0x00000000u, 0x80000000u, 0x00000001u, 0xffffffffu, 0x80000000u, 0x00000000u}, + {0x00000000u, 0x80000000u, 0x00000001u, 0xffffffffu, 0x80000001u, 0x00000000u}, + {0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u}, + {0x00000001u, 0x00000000u, 0x00000000u, 0x00000001u, 0xfffffffeu, 0x00000000u}, + {0xffffffffu, 0x7fffffffu, 0x00000000u, 0x00000000u, 0x80000000u, 0x00000000u}, + {0xffffffffu, 0x7fffffffu, 0x00000000u, 0xffffffffu, 0x7fffffffu, 0x00000000u}, + {0x80000000u, 0x80000000u, 0x00000001u, 0x80000000u, 0xffffffffu, 0x00000000u}, + {0x7fffffffu, 0x80000000u, 0x00000001u, 0x7fffffffu, 0xffffffffu, 0x00000000u}, + {0xffffffffu, 0x7fffffffu, 0x00000000u, 0x00000000u, 0xbfffffffu, 0x00000000u}, + {0x00000000u, 0x00000000u, 0x00000000u, 0xffffffffu, 0xffffffffu, 0x00000001u}, + {0xffffffffu, 0x7fffffffu, 0x00000000u, 0xffffffffu, 0x7fffffffu, 0x00000000u}, + {0x00000000u, 0x80000000u, 0x00000001u, 0x00000000u, 0x80000000u, 0x00000000u}, + {0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u}, + {0x80000000u, 0xffffffffu, 0x00000001u, 0x80000000u, 0x00000000u, 0x00000000u}, + {0x7fffffffu, 0xffffffffu, 0x00000001u, 0xffffffffu, 0xffffffffu, 0x00000001u}, + {0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u}, + {0xffffffffu, 0xffffffffu, 0x00000001u, 0xffffffffu, 0xffffffffu, 0x00000000u}, + {0x80000000u, 0xffffffffu, 0x00000001u, 0x80000000u, 0x00000000u, 0x00000000u}, + {0x7fffffffu, 0xffffffffu, 0x00000001u, 0xffffffffu, 0xffffffffu, 0x00000001u}, + {0x00000000u, 0x80000000u, 0x00000001u, 0x80000000u, 0x80000000u, 0x00000000u}, + {0x00000000u, 0xc0000000u, 0x00000001u, 0x00000000u, 0xc0000000u, 0x00000000u}, + {0x80000000u, 0xffffffffu, 0x00000001u, 0xffffffffu, 0xffffffffu, 0x00000001u}, + {0xffffffffu, 0x7fffffffu, 0x00000000u, 0xffffffffu, 0xffffffffu, 0x00000001u}, + {0x00000004u, 0x40000000u, 0x00000000u, 0xffffffffu, 0xffffffffu, 0x00000001u}, + {0xc6572994u, 0x08928581u, 0x00000000u, 0xc6572994u, 0x457dc57eu, 0x00000000u}, + {0x89b23ef1u, 0x71659f65u, 0x00000000u, 0x89b23ef1u, 0xd01b0109u, 0x00000000u} +}; +constexpr const char* Names[6] = {"i64 clamp lo", "i64 clamp hi", "i64 clamp carry", "u64 clamp lo", "u64 clamp hi", "u64 clamp carry"}; + +void Fill(std::uint32_t tid, std::uint32_t* words) { + std::copy(std::begin(Rows[tid]), std::end(Rows[tid]), words); +} + +std::array BufferDescriptor(const void* data, std::uint32_t bytes) { + const auto address = reinterpret_cast(data); + return {static_cast(address), static_cast((address >> 32u) & 0xffffu), bytes, 0x01016facu}; +} + +std::string Hex(std::uint32_t value) { + char text[16]; + std::snprintf(text, sizeof(text), "0x%08x", value); + return text; +} + +void Expect(std::uint32_t tid, std::uint32_t actual, std::uint32_t expected, const char* name) { + Require(actual == expected, std::string("vop3 mad clamp: lane ") + std::to_string(tid) + " " + name + " is " + Hex(actual) + ", expected " + Hex(expected)); +} + +void Run(AgcDriver::VulkanDevice& device) { + for (std::uint32_t tid = 0; tid < Threads; ++tid) Fill(tid, &Input[tid * Inputs]); + Output.fill(0xdeadbeefu); + std::vector userData(8, 0u); + const auto input = BufferDescriptor(Input.data(), static_cast(Input.size() * 4u)); + const auto output = BufferDescriptor(Output.data(), static_cast(Output.size() * 4u)); + std::copy(input.begin(), input.end(), userData.begin()); + std::copy(output.begin(), output.end(), userData.begin() + 4); + const std::span code(Code); + const std::array memory{{{reinterpret_cast(code.data()), std::as_bytes(code)}}}; + const ShaderRecompiler::ShaderComputeStageInfo compute{{Threads, 1, 1}, 0u, {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 std::uint32_t* in = &Input[tid * Inputs]; + const std::uint32_t* out = &Output[tid * Results]; + for (std::uint32_t i = 0; i < 6; ++i) Expect(tid, out[i], Expected[tid][i], Names[i]); + } +} + +} + +int main() { + try { + const auto device = OpenVulkanTestDevice(); + if (!device) return VulkanTestSkipped; + Run(*device); + Check(); + std::puts("vop3 mad clamp tests passed"); + return 0; + } catch (const std::exception& error) { + std::cerr << error.what() << '\n'; + return 1; + } +} diff --git a/core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp b/core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp index e0eed4775..2be243dec 100644 --- a/core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp +++ b/core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp @@ -1948,7 +1948,7 @@ void checkNativeVop3Modifiers(RdnaOpcode opcode, bool permlane, bool carryInOut, } if (carryInOut || scalarDst) { const bool floatCompare = scalarDst && isVopcFloatCompareOpcode(opcode); - if (clamp != 0u || omod != 0u || (neg != 0u && !floatCompare && opcode != RdnaOpcode::VDivScaleF32 && opcode != RdnaOpcode::VDivScaleF64)) { + if ((clamp != 0u && !isVop3BMadU64Opcode(opcode)) || omod != 0u || (neg != 0u && !floatCompare && opcode != RdnaOpcode::VDivScaleF32 && opcode != RdnaOpcode::VDivScaleF64)) { throw std::invalid_argument("VOP3 source modifiers are not implemented"); } return; @@ -2191,7 +2191,7 @@ RdnaInstruction DecodeRdnaVop3(std::uint32_t programCounter, std::span