diff --git a/core/libs/prx/libSceAgcDriver/tests/execution/F64Division.cpp b/core/libs/prx/libSceAgcDriver/tests/execution/F64Division.cpp new file mode 100644 index 000000000..634a3ed4e --- /dev/null +++ b/core/libs/prx/libSceAgcDriver/tests/execution/F64Division.cpp @@ -0,0 +1,172 @@ +#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, 0xd56e6a0a, 0x041a0904, 0xd5010018, + 0x01a90280, 0xd56e6a0c, 0x041a0906, 0xd5010019, 0x01a90480, 0x38303318, 0xbeea03c1, 0xd570000e, + 0x04120d04, 0xd5700010, 0x041a0d04, 0xd5600012, 0x04120d04, 0xd5600014, 0x041a0906, 0xd5600016, + 0x041a08ff, 0x7ff80000, 0x7e320280, 0xe0781000, 0x80010a03, 0xe0781010, 0x80010e03, 0xe0781020, + 0x80011203, 0xe0781030, 0x80011603, 0xbf810000, +}; + +constexpr std::uint32_t Rows[32][4] = { + {0x00000001u, 0x7ff00000u, 0x00000000u, 0x3ff00000u}, + {0x00000000u, 0x7ff40000u, 0x00000000u, 0x3ff00000u}, + {0xe61541b6u, 0xcdde1df6u, 0x652b0ed7u, 0xfddc36e5u}, + {0xc3d4a267u, 0x03d31de5u, 0x08426379u, 0xb3cb953cu}, + {0xceb52fc3u, 0xb3648a3fu, 0xd8fe4338u, 0x8367c969u}, + {0x131c99fcu, 0x7f65f30fu, 0x888c6e8bu, 0xcf72c7f8u}, + {0x00000000u, 0x7fd00000u, 0x00000000u, 0x3ca00000u}, + {0xffffffffu, 0x7fefffffu, 0x00000000u, 0x3ca00000u}, + {0x00000000u, 0x7fd00000u, 0xffffffffu, 0x7fefffffu}, + {0x00000000u, 0x7fc00000u, 0xffffffffu, 0x7fefffffu}, + {0x00000000u, 0x00100000u, 0x00000000u, 0x03500000u}, + {0x00000000u, 0x00100000u, 0x00000000u, 0x03600000u}, + {0x8a41dfb1u, 0xbffc3c7cu, 0xffffffffu, 0x7fefffffu}, + {0x00000000u, 0x7ff00000u, 0x00000000u, 0x80000000u}, + {0x00000000u, 0xfff00000u, 0x00000000u, 0x7ff00000u}, + {0x00000000u, 0x00000000u, 0x00000000u, 0xfff00000u}, + {0x00000000u, 0x80000000u, 0x00000000u, 0x00000000u}, + {0x00000000u, 0xbff00000u, 0x00000000u, 0xfff00000u}, + {0x00000000u, 0x7ff00000u, 0xffffffffu, 0x7fefffffu}, + {0x00000001u, 0xfff80000u, 0x00000000u, 0x7ff80000u}, + {0x00000000u, 0x00000000u, 0x00000001u, 0xfff80000u}, + {0x00000000u, 0x3ff00000u, 0x00000000u, 0x00000000u}, + {0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u}, + {0x00000000u, 0x00000000u, 0x00000000u, 0x80000000u}, + {0x00000000u, 0x00000000u, 0x00000000u, 0x3ff00000u}, + {0x00000000u, 0x00000000u, 0x00000000u, 0xbff00000u}, + {0x00000000u, 0x00000000u, 0x00000000u, 0x00100000u}, + {0x00000000u, 0x00000000u, 0xffffffffu, 0x7fefffffu}, + {0x00000000u, 0x00000000u, 0xffffffffu, 0xffefffffu}, + {0x00000000u, 0x00000000u, 0x00000000u, 0x7ff00000u}, + {0x00000000u, 0x00000000u, 0x00000000u, 0x7ff80000u}, + {0x00000000u, 0x00000000u, 0x00000001u, 0x7ff00000u} +}; +constexpr std::uint32_t Expected[32][16] = { + {0x00000001u, 0x7ff00000u, 0x00000000u, 0x3ff00000u, 0x00000001u, 0x7ff80000u, 0x00000001u, 0x7ff80000u, 0x00000001u, 0x7ff80000u, 0x00000001u, 0x7ff80000u, 0x00000001u, 0x7ff80000u, 0x00000003u, 0x00000000u}, + {0x00000000u, 0x7ff40000u, 0x00000000u, 0x3ff00000u, 0x00000000u, 0x7ffc0000u, 0x00000000u, 0x7ffc0000u, 0x00000000u, 0x7ffc0000u, 0x00000000u, 0x7ffc0000u, 0x00000000u, 0x7ffc0000u, 0x00000003u, 0x00000000u}, + {0xe61541b6u, 0xd5de1df6u, 0x652b0ed7u, 0xfddc36e5u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x7ff00000u, 0xe61541b6u, 0x4dde1df6u, 0x652b0ed7u, 0x7ddc36e5u, 0x00000000u, 0x7ff00000u, 0x00000003u, 0x00000000u}, + {0xc3d4a267u, 0x03d31de5u, 0x08426379u, 0xb3cb953cu, 0x00000000u, 0x00000000u, 0x08426379u, 0xabcb953cu, 0xc3d4a267u, 0x83d31de5u, 0x08426379u, 0xb3cb953cu, 0x00000000u, 0xfff00000u, 0x00000000u, 0x00000000u}, + {0xceb52fc3u, 0xb3648a3fu, 0xd8fe4338u, 0x8b67c969u, 0xceb52fc3u, 0xab648a3fu, 0x00000000u, 0x80000000u, 0xceb52fc3u, 0x33648a3fu, 0xd8fe4338u, 0x0367c969u, 0x00000000u, 0x7ff00000u, 0x00000003u, 0x00000000u}, + {0x131c99fcu, 0x7f65f30fu, 0x888c6e8bu, 0xcf72c7f8u, 0x00000000u, 0xfff00000u, 0x00000000u, 0xfff00000u, 0x131c99fcu, 0xff65f30fu, 0x888c6e8bu, 0xcf72c7f8u, 0x00000000u, 0xfff00000u, 0x00000000u, 0x00000000u}, + {0x00000000u, 0x77d00000u, 0x00000000u, 0x3ca00000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x74800000u, 0x00000000u, 0x7fd00000u, 0x00000000u, 0x3ca00000u, 0x00000000u, 0x7ff00000u, 0x00000003u, 0x00000000u}, + {0xffffffffu, 0x77efffffu, 0x00000000u, 0x3ca00000u, 0x00000000u, 0x7ff00000u, 0xffffffffu, 0x749fffffu, 0xffffffffu, 0x7fefffffu, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000003u, 0x00000000u}, + {0x00000000u, 0x77d00000u, 0xffffffffu, 0x77efffffu, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x7fd00000u, 0xffffffffu, 0x7fefffffu, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x00000000u}, + {0x00000000u, 0x7fc00000u, 0xffffffffu, 0x7fefffffu, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x7fc00000u, 0xffffffffu, 0x7fefffffu, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x00000000u}, + {0x00000000u, 0x08100000u, 0x00000000u, 0x0b500000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00100000u, 0x00000000u, 0x03500000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x00000000u}, + {0x00000000u, 0x00100000u, 0x00000000u, 0x03600000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00100000u, 0x00000000u, 0x03600000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x00000000u}, + {0x8a41dfb1u, 0xc7fc3c7cu, 0xffffffffu, 0x7fefffffu, 0x8a41dfb0u, 0xf7fc3c7cu, 0x00000000u, 0xfff00000u, 0x8a41dfb1u, 0xbffc3c7cu, 0xffffffffu, 0xffefffffu, 0x00000000u, 0xfff00000u, 0x00000003u, 0x00000000u}, + {0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0xfff00000u, 0x00000000u, 0x80000000u, 0x00000000u, 0x80000000u, 0x00000003u, 0x00000000u}, + {0x00000000u, 0xfff00000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0xfff00000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x00000000u}, + {0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x80000000u, 0x00000000u, 0xfff00000u, 0x00000000u, 0xfff00000u, 0x00000003u, 0x00000000u}, + {0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x80000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x00000000u}, + {0x00000000u, 0xc7f00000u, 0x00000000u, 0xfff00000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x7ff00000u, 0x00000003u, 0x00000000u}, + {0x00000000u, 0x7ff00000u, 0xffffffffu, 0x77efffffu, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u}, + {0x00000001u, 0xfff80000u, 0x00000000u, 0x7ff80000u, 0x00000001u, 0xfff80000u, 0x00000001u, 0xfff80000u, 0x00000001u, 0xfff80000u, 0x00000000u, 0x7ff80000u, 0x00000000u, 0x7ff80000u, 0x00000000u, 0x00000000u}, + {0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000001u, 0xfff80000u, 0x00000001u, 0xfff80000u, 0x00000001u, 0xfff80000u, 0x00000001u, 0xfff80000u, 0x00000001u, 0xfff80000u, 0x00000003u, 0x00000000u}, + {0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x37f00000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000003u, 0x00000000u}, + {0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x00000000u}, + {0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x80000000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x00000000u}, + {0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x37f00000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x7ff00000u, 0x00000003u, 0x00000000u}, + {0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xb7f00000u, 0x00000000u, 0x80000000u, 0x00000000u, 0xfff00000u, 0x00000000u, 0xfff00000u, 0x00000003u, 0x00000000u}, + {0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x00000000u}, + {0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x7ff00000u, 0x00000003u, 0x00000000u}, + {0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xfff00000u, 0x00000000u, 0x80000000u, 0x00000000u, 0xfff00000u, 0x00000000u, 0xfff00000u, 0x00000003u, 0x00000000u}, + {0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x7ff00000u, 0x00000003u, 0x00000000u}, + {0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x7ff80000u, 0x00000000u, 0x7ff80000u, 0x00000000u, 0x7ff80000u, 0x00000000u, 0x7ff80000u, 0x00000000u, 0x7ff80000u, 0x00000003u, 0x00000000u}, + {0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000001u, 0x7ff80000u, 0x00000001u, 0x7ff80000u, 0x00000001u, 0x7ff80000u, 0x00000001u, 0x7ff80000u, 0x00000001u, 0x7ff80000u, 0x00000003u, 0x00000000u} +}; +constexpr const char* Names[7] = {"div_scale denominator", "div_scale numerator", "div_fmas a*b+a", "div_fmas a*b+b", "div_fixup a", "div_fixup b", "div_fixup nan"}; + +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("f64 division: 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 < 7; ++i) { + Expect(tid, out[2 * i], Expected[tid][2 * i], Names[i]); + Expect(tid, out[2 * i + 1], Expected[tid][2 * i + 1], Names[i]); + } + Expect(tid, out[14], Expected[tid][14], "div_scale vcc"); + } +} + +} + +int main() { + try { + const auto device = OpenVulkanTestDevice(); + if (!device) return VulkanTestSkipped; + Run(*device); + Check(); + std::puts("f64 division tests passed"); + return 0; + } catch (const std::exception& error) { + std::cerr << error.what() << '\n'; + return 1; + } +} diff --git a/core/libs/prx/libSceAgcDriver/tests/execution/F64DivisionModifiers.cpp b/core/libs/prx/libSceAgcDriver/tests/execution/F64DivisionModifiers.cpp new file mode 100644 index 000000000..645f47a10 --- /dev/null +++ b/core/libs/prx/libSceAgcDriver/tests/execution/F64DivisionModifiers.cpp @@ -0,0 +1,172 @@ +#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, 0xd56e6a0a, 0x641a0904, 0xd5010018, + 0x01a90280, 0xd56e6a0c, 0x841a0906, 0xd5010019, 0x01a90480, 0x38303318, 0xbeea03c1, 0xd570060e, + 0xa4120d04, 0xd5700010, 0x04120d06, 0xbeea0380, 0xd5700012, 0x041a0d04, 0xd5600514, 0x64120d04, + 0x36320881, 0x7d8a3280, 0xd5700016, 0x041a0906, 0x7e320280, 0xe0781000, 0x80010a03, 0xe0781010, + 0x80010e03, 0xe0781020, 0x80011203, 0xe0781030, 0x80011603, 0xbf810000, +}; + +constexpr std::uint32_t Rows[32][4] = { + {0x00000001u, 0x7ff00000u, 0x00000000u, 0x3ff00000u}, + {0x00000000u, 0x7ff40000u, 0x00000000u, 0x3ff00000u}, + {0xe61541b6u, 0xcdde1df6u, 0x652b0ed7u, 0xfddc36e5u}, + {0xc3d4a267u, 0x03d31de5u, 0x08426379u, 0xb3cb953cu}, + {0xceb52fc3u, 0xb3648a3fu, 0xd8fe4338u, 0x8367c969u}, + {0x131c99fcu, 0x7f65f30fu, 0x888c6e8bu, 0xcf72c7f8u}, + {0x00000000u, 0x7fd00000u, 0x00000000u, 0x3ca00000u}, + {0xffffffffu, 0x7fefffffu, 0x00000000u, 0x3ca00000u}, + {0x00000000u, 0x7fd00000u, 0xffffffffu, 0x7fefffffu}, + {0x00000000u, 0x7fc00000u, 0xffffffffu, 0x7fefffffu}, + {0x00000000u, 0x00100000u, 0x00000000u, 0x03500000u}, + {0x00000000u, 0x00100000u, 0x00000000u, 0x03600000u}, + {0x00000000u, 0x7ff00000u, 0x00000001u, 0xfff80000u}, + {0xffffffffu, 0xffefffffu, 0x00000000u, 0x00000000u}, + {0x00000000u, 0xfff00000u, 0x00000000u, 0x7ff00000u}, + {0x00000000u, 0x00000000u, 0x00000000u, 0xfff00000u}, + {0x00000000u, 0x80000000u, 0x00000000u, 0x3ff00000u}, + {0x00000000u, 0x00100000u, 0x00000000u, 0x80000000u}, + {0x00000001u, 0xfff80000u, 0x00000000u, 0x7ff80000u}, + {0x00000000u, 0x3ff00000u, 0x00000000u, 0xfff00000u}, + {0x00000000u, 0xbff00000u, 0xffffffffu, 0x7fefffffu}, + {0xb0894f5au, 0x80834975u, 0x4c867062u, 0x0376ec15u}, + {0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u}, + {0x00000000u, 0x00000000u, 0x00000000u, 0x80000000u}, + {0x00000000u, 0x00000000u, 0x00000000u, 0x3ff00000u}, + {0x00000000u, 0x00000000u, 0x00000000u, 0xbff00000u}, + {0x00000000u, 0x00000000u, 0x00000000u, 0x00100000u}, + {0x00000000u, 0x00000000u, 0xffffffffu, 0x7fefffffu}, + {0x00000000u, 0x00000000u, 0xffffffffu, 0xffefffffu}, + {0x00000000u, 0x00000000u, 0x00000000u, 0x7ff00000u}, + {0x00000000u, 0x00000000u, 0x00000000u, 0x7ff80000u}, + {0x00000000u, 0x00000000u, 0x00000001u, 0xfff80000u} +}; +constexpr std::uint32_t Expected[32][16] = { + {0x00000001u, 0xfff00000u, 0x00000000u, 0x3ff00000u, 0x00000001u, 0xfff80000u, 0x00000001u, 0x7ff80000u, 0x00000001u, 0x7ff80000u, 0x00000001u, 0x7ff80000u, 0x00000001u, 0x7ff80000u, 0x00000003u, 0x00000000u}, + {0x00000000u, 0xfff40000u, 0x00000000u, 0x3ff00000u, 0x00000000u, 0xfffc0000u, 0x00000000u, 0x7ffc0000u, 0x00000000u, 0x7ffc0000u, 0x00000000u, 0x7ffc0000u, 0x00000000u, 0x7ffc0000u, 0x00000003u, 0x00000000u}, + {0xe61541b6u, 0x55de1df6u, 0x652b0ed7u, 0xfddc36e5u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x7ff00000u, 0xe61541b6u, 0x4dde1df6u, 0x00000000u, 0x7ff00000u, 0x00000003u, 0x00000000u}, + {0xc3d4a267u, 0x83d31de5u, 0x08426379u, 0xb3cb953cu, 0x00000000u, 0x80000000u, 0x456d9116u, 0x1fa7c68du, 0x08426379u, 0xb3cb953cu, 0xc3d4a267u, 0x03d31de5u, 0x08426379u, 0xabcb953cu, 0x00000000u, 0x00000000u}, + {0xceb52fc3u, 0x33648a3fu, 0xd8fe4338u, 0x8b67c969u, 0xceb52fc3u, 0xab648a3fu, 0xceb52fc3u, 0xab648a3fu, 0xd8fe4338u, 0x8367c969u, 0xceb52fc3u, 0x33648a3fu, 0x00000000u, 0x80000000u, 0x00000003u, 0x00000000u}, + {0x131c99fcu, 0xff65f30fu, 0x888c6e8bu, 0xcf72c7f8u, 0x00000000u, 0xfff00000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0xfff00000u, 0x131c99fcu, 0x7f65f30fu, 0x00000000u, 0xfff00000u, 0x00000000u, 0x00000000u}, + {0x00000000u, 0xf7d00000u, 0x00000000u, 0x3ca00000u, 0x00000000u, 0xfff00000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x7c800000u, 0x00000000u, 0xffd00000u, 0x00000000u, 0x7c800000u, 0x00000003u, 0x00000000u}, + {0xffffffffu, 0xf7efffffu, 0x00000000u, 0x3ca00000u, 0x00000000u, 0xfff00000u, 0x00000000u, 0x7ff00000u, 0xffffffffu, 0x7c9fffffu, 0xffffffffu, 0xffefffffu, 0xffffffffu, 0x749fffffu, 0x00000003u, 0x00000000u}, + {0x00000000u, 0xf7d00000u, 0xffffffffu, 0x77efffffu, 0x00000000u, 0xfff00000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0xffd00000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x00000000u}, + {0x00000000u, 0xffc00000u, 0xffffffffu, 0x7fefffffu, 0x00000000u, 0xfff00000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0xffc00000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x00000000u}, + {0x00000000u, 0x88100000u, 0x00000000u, 0x0b500000u, 0x00000000u, 0x80000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x03500000u, 0x00000000u, 0x80100000u, 0x00000000u, 0x03500000u, 0x00000000u, 0x00000000u}, + {0x00000000u, 0x80100000u, 0x00000000u, 0x03600000u, 0x00000000u, 0x80000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x03600000u, 0x00000000u, 0x80100000u, 0x00000000u, 0x03600000u, 0x00000000u, 0x00000000u}, + {0x00000000u, 0xfff00000u, 0x00000001u, 0xfff80000u, 0x00000001u, 0x7ff80000u, 0x00000001u, 0xfff80000u, 0x00000001u, 0xfff80000u, 0x00000001u, 0x7ff80000u, 0x00000001u, 0xfff80000u, 0x00000000u, 0x00000000u}, + {0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0xfff00000u, 0x00000000u, 0xfff00000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xfff00000u, 0x00000000u, 0x00000000u, 0x00000003u, 0x00000000u}, + {0x00000000u, 0x7ff00000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x00000000u}, + {0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xfff80000u, 0x00000003u, 0x00000000u}, + {0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x37f00000u, 0x00000000u, 0x3ff00000u, 0x00000000u, 0x80000000u, 0x00000000u, 0x3ff00000u, 0x00000003u, 0x00000000u}, + {0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x80000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x80000000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x80000000u, 0x00000000u, 0x00000000u}, + {0x00000001u, 0x7ff80000u, 0x00000000u, 0x7ff80000u, 0x00000001u, 0x7ff80000u, 0x00000000u, 0x7ff80000u, 0x00000001u, 0xfff80000u, 0x00000001u, 0x7ff80000u, 0x00000000u, 0x7ff80000u, 0x00000000u, 0x00000000u}, + {0x00000000u, 0xc7f00000u, 0x00000000u, 0xfff00000u, 0x00000000u, 0xfff00000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0xfff00000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xfff00000u, 0x00000003u, 0x00000000u}, + {0x00000000u, 0x47f00000u, 0xffffffffu, 0x7fefffffu, 0xffffffffu, 0x77efffffu, 0x00000000u, 0x7ff00000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xbff00000u, 0x00000000u, 0x00000000u, 0x00000003u, 0x00000000u}, + {0xb0894f5au, 0x00834975u, 0x4c867062u, 0x0376ec15u, 0x00000000u, 0x80000000u, 0x00000000u, 0x80000000u, 0x4c867062u, 0x0376ec15u, 0xb0894f5au, 0x80834975u, 0x4c867062u, 0x0376ec15u, 0x00000000u, 0x00000000u}, + {0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x80000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u}, + {0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x80000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x80000000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x80000000u, 0x00000000u, 0x00000000u}, + {0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x80000000u, 0x00000000u, 0x37f00000u, 0x00000000u, 0x3ff00000u, 0x00000000u, 0x80000000u, 0x00000000u, 0x3ff00000u, 0x00000003u, 0x00000000u}, + {0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x80000000u, 0x00000000u, 0x37f00000u, 0x00000000u, 0xbff00000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xbff00000u, 0x00000003u, 0x00000000u}, + {0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x80000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00100000u, 0x00000000u, 0x80000000u, 0x00000000u, 0x00100000u, 0x00000000u, 0x00000000u}, + {0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x80000000u, 0x00000000u, 0x7ff00000u, 0xffffffffu, 0x7fefffffu, 0x00000000u, 0x80000000u, 0xffffffffu, 0x7fefffffu, 0x00000003u, 0x00000000u}, + {0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x80000000u, 0x00000000u, 0x7ff00000u, 0xffffffffu, 0xffefffffu, 0x00000000u, 0x00000000u, 0xffffffffu, 0xffefffffu, 0x00000003u, 0x00000000u}, + {0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x7ff00000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x80000000u, 0x00000000u, 0xfff80000u, 0x00000003u, 0x00000000u}, + {0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x7ff80000u, 0x00000000u, 0x7ff80000u, 0x00000000u, 0x7ff80000u, 0x00000000u, 0xfff80000u, 0x00000000u, 0x7ff80000u, 0x00000003u, 0x00000000u}, + {0x00000000u, 0xfff80000u, 0x00000000u, 0xfff80000u, 0x00000001u, 0x7ff80000u, 0x00000001u, 0xfff80000u, 0x00000001u, 0xfff80000u, 0x00000001u, 0x7ff80000u, 0x00000001u, 0xfff80000u, 0x00000003u, 0x00000000u} +}; +constexpr const char* Names[7] = {"div_scale -a", "div_scale -b", "div_fmas modifiers", "div_fmas b*b+a", "div_fmas vcc 0", "div_fixup modifiers", "div_fmas vcc per lane"}; + +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("f64 division modifiers: 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 < 7; ++i) { + Expect(tid, out[2 * i], Expected[tid][2 * i], Names[i]); + Expect(tid, out[2 * i + 1], Expected[tid][2 * i + 1], Names[i]); + } + Expect(tid, out[14], Expected[tid][14], "div_scale vcc"); + } +} + +} + +int main() { + try { + const auto device = OpenVulkanTestDevice(); + if (!device) return VulkanTestSkipped; + Run(*device); + Check(); + std::puts("f64 division modifiers tests passed"); + return 0; + } catch (const std::exception& error) { + std::cerr << error.what() << '\n'; + return 1; + } +} diff --git a/core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrOpcode.hpp b/core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrOpcode.hpp index d5057d62f..1abea8a98 100644 --- a/core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrOpcode.hpp +++ b/core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrOpcode.hpp @@ -248,6 +248,7 @@ enum class IrOpcode : std::uint16_t { FPAdd64, FPMul64, FPFma64, + FPFmaScale64, FPMin64, FPMax64, FPSaturate64, diff --git a/core/shader/recompiler/IntermediateRepresentation/src/IrOpcode.cpp b/core/shader/recompiler/IntermediateRepresentation/src/IrOpcode.cpp index 6ff239e77..158279a36 100644 --- a/core/shader/recompiler/IntermediateRepresentation/src/IrOpcode.cpp +++ b/core/shader/recompiler/IntermediateRepresentation/src/IrOpcode.cpp @@ -289,6 +289,7 @@ constexpr std::array(IrOpcode::Count)> Meta makeMeta("FPAdd64", U64, U64, U64), makeMeta("FPMul64", U64, U64, U64), makeMeta("FPFma64", U64, U64, U64, U64), + makeMeta("FPFmaScale64", U64, U64, U64, U64, U32), makeMeta("FPMin64", U64, U64, U64), makeMeta("FPMax64", U64, U64, U64), makeMeta("FPSaturate64", U64, U64), diff --git a/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp b/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp index 306cc3024..0c0d6b6de 100644 --- a/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp +++ b/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp @@ -416,6 +416,9 @@ enum class RdnaOpcode : std::uint16_t { VRsqF64, VSqrtF64, VTrigPreopF64, + VDivScaleF64, + VDivFmasF64, + VDivFixupF64, VCvtPknormI16F32, VCvtPknormU16F32, VCvtPkU16U32, diff --git a/core/shader/recompiler/RdnaDecoder/src/RdnaOpcode.cpp b/core/shader/recompiler/RdnaDecoder/src/RdnaOpcode.cpp index b2c35b4fd..99ac177cf 100644 --- a/core/shader/recompiler/RdnaDecoder/src/RdnaOpcode.cpp +++ b/core/shader/recompiler/RdnaDecoder/src/RdnaOpcode.cpp @@ -367,6 +367,9 @@ bool IsVectorAluOpcode(RdnaOpcode opcode) { case RdnaOpcode::VRsqF64: case RdnaOpcode::VSqrtF64: case RdnaOpcode::VTrigPreopF64: + case RdnaOpcode::VDivScaleF64: + case RdnaOpcode::VDivFmasF64: + case RdnaOpcode::VDivFixupF64: case RdnaOpcode::VCvtPknormI16F32: case RdnaOpcode::VCvtPknormU16F32: case RdnaOpcode::VCvtPkU16U32: diff --git a/core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp b/core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp index 6ff681866..b7a805e07 100644 --- a/core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp +++ b/core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp @@ -559,6 +559,9 @@ constexpr VectorOpcodeInfo vop3Opcodes[] = { {0x16du, RdnaOpcode::VDivScaleF32}, {0x16fu, RdnaOpcode::VDivFmasF32}, {0x174u, RdnaOpcode::VTrigPreopF64}, + {0x160u, RdnaOpcode::VDivFixupF64}, + {0x16eu, RdnaOpcode::VDivScaleF64}, + {0x170u, RdnaOpcode::VDivFmasF64}, {0x363u, RdnaOpcode::VBfmB32}, {0x364u, RdnaOpcode::VBcntU32B32}, {0x365u, RdnaOpcode::VMbcntLoU32B32}, @@ -691,7 +694,7 @@ bool isVop3BCarryOutOpcode(RdnaOpcode opcode) { } bool isVop3BMadU64Opcode(RdnaOpcode opcode) { - return opcode == RdnaOpcode::VMadU64U32 || opcode == RdnaOpcode::VMadI64I32 || opcode == RdnaOpcode::VDivScaleF32; + return opcode == RdnaOpcode::VMadU64U32 || opcode == RdnaOpcode::VMadI64I32 || opcode == RdnaOpcode::VDivScaleF32 || opcode == RdnaOpcode::VDivScaleF64; } bool isPermlaneOpcode(RdnaOpcode opcode) { @@ -1795,6 +1798,8 @@ bool supportsNativeVop3SourceModifiers(RdnaOpcode opcode) { case RdnaOpcode::VDivFixupF32: case RdnaOpcode::VLdexpF32: case RdnaOpcode::VFmaF64: + case RdnaOpcode::VDivFmasF64: + case RdnaOpcode::VDivFixupF64: case RdnaOpcode::VAddF64: case RdnaOpcode::VMulF64: case RdnaOpcode::VMinF64: @@ -1867,7 +1872,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)) { + if (clamp != 0u || omod != 0u || (neg != 0u && !floatCompare && opcode != RdnaOpcode::VDivScaleF32 && opcode != RdnaOpcode::VDivScaleF64)) { throw std::invalid_argument("VOP3 source modifiers are not implemented"); } return; @@ -2147,7 +2152,7 @@ RdnaInstruction DecodeRdnaVop3(std::uint32_t programCounter, std::span(-768))})); + const IrU1 denominatorDenormal(ir.IEqual(denominatorExponent.Value(), ir.Constant(0u))); + const IrU1 denominatorHuge(ir.Emit(IrOpcode::UGreaterThanEqual32, IrType::U1, {&denominatorExponent.Value(), &ir.Constant(2045u)})); + const IrU1 numeratorTiny(ir.Emit(IrOpcode::ULessThanEqual32, IrType::U1, {&numeratorExponent.Value(), &ir.Constant(53u)})); + const IrU1 isDenominator(ir.LogicalAnd(ir.IEqual(value[0].Value(), denominator[0].Value()), ir.IEqual(value[1].Value(), denominator[1].Value()))); + const IrU1 notNearMax(ir.LogicalNot(nearMax.Value())); + const IrU1 notDenormal(ir.LogicalNot(denominatorDenormal.Value())); + const IrU1 normalRange(ir.LogicalAnd(notNearMax.Value(), notDenormal.Value())); + const IrU1 belowHuge(ir.LogicalAnd(normalRange.Value(), ir.LogicalNot(denominatorHuge.Value()))); + const IrU1 scaleUp(ir.LogicalOr( + ir.LogicalOr(ir.LogicalAnd(nearMax.Value(), isDenominator.Value()), ir.LogicalAnd(notNearMax.Value(), denominatorDenormal.Value())), + ir.LogicalAnd(belowHuge.Value(), ir.LogicalOr(ir.LogicalAnd(nearMin.Value(), ir.LogicalNot(isDenominator.Value())), + ir.LogicalAnd(ir.LogicalNot(nearMin.Value()), numeratorTiny.Value()))))); + const IrU1 scaleDown(ir.LogicalAnd(ir.LogicalAnd(normalRange.Value(), denominatorHuge.Value()), + ir.LogicalOr(ir.LogicalNot(nearMin.Value()), isDenominator.Value()))); + IrValue& bits = ir.ConstructU64(value[0].Value(), value[1].Value()); + IrValue& power = ir.Select(scaleUp.Value(), ir.Constant(128u), ir.Constant(static_cast(-128))); + IrValue& scaled = ir.Emit(IrOpcode::FPLdexp64, IrType::U64, {&bits, &power}); + const auto magnitude = [&](IrU32 high) { return IrU32(ir.BitwiseAnd(high.Value(), ir.Constant(0x7fffffffu))); }; + const IrU1 valueNan(ir.LogicalOr(ir.UGreaterThan(magnitude(value[1]).Value(), ir.Constant(0x7ff00000u)), + ir.LogicalAnd(ir.IEqual(magnitude(value[1]).Value(), ir.Constant(0x7ff00000u)), ir.INotEqual(value[0].Value(), ir.Constant(0u))))); + const IrU1 rescale(ir.LogicalAnd(ir.LogicalOr(scaleUp.Value(), scaleDown.Value()), ir.LogicalNot(valueNan.Value()))); + const auto isZero = [&](const std::array& word) { + return IrU1(ir.IEqual(ir.BitwiseOr(magnitude(word[1]).Value(), word[0].Value()), ir.Constant(0u))); + }; + const IrU1 zero(ir.LogicalOr(isZero(denominator).Value(), isZero(numerator).Value())); + std::array result{IrU32(ir.CompositeExtract(scaled, 0u)), IrU32(ir.CompositeExtract(scaled, 1u))}; + result[0] = IrU32(ir.Select(rescale.Value(), result[0].Value(), value[0].Value())); + result[1] = IrU32(ir.Select(rescale.Value(), result[1].Value(), value[1].Value())); + result[0] = IrU32(ir.Select(zero.Value(), ir.Constant(0u), result[0].Value())); + result[1] = IrU32(ir.Select(zero.Value(), ir.Constant(0xfff80000u), result[1].Value())); + writeOperand(inst.destination, &ir.ConstructU64(result[0].Value(), result[1].Value())); + writeMask(inst.destination2, IrU1(ir.LogicalOr(nearMax.Value(), ir.LogicalAnd(notDenormal.Value(), nearMin.Value())))); + return true; +} + +bool TranslationContext::vDivFmasF64(const RdnaInstruction& inst) { + RdnaOperand vcc{}; + vcc.kind = RdnaOperandKind::VccLo; + const IrU1 scale = readMask(vcc); + const auto addend = readF64Bits(sourceAt(inst, 2u)); + IrValue& addendExponent = ir.Emit(IrOpcode::BitFieldUExtract, IrType::U32, {&addend[1].Value(), &ir.Constant(20u), &ir.Constant(11u)}); + const IrU1 up(ir.Emit(IrOpcode::UGreaterThanEqual32, IrType::U1, {&addendExponent, &ir.Constant(1024u)})); + IrValue& power = ir.Select(scale.Value(), ir.Select(up.Value(), ir.Constant(128u), ir.Constant(static_cast(-128))), ir.Constant(0u)); + IrValue& result = ir.Emit(IrOpcode::FPFmaScale64, IrType::U64, + {&readF64(sourceAt(inst, 0u)).Value(), &readF64(sourceAt(inst, 1u)).Value(), &ir.ConstructU64(addend[0].Value(), addend[1].Value()), &power}); + writeOperand(inst.destination, &result); + return true; +} + +bool TranslationContext::vDivFixupF64(const RdnaInstruction& inst) { + const auto quotient = readF64Bits(sourceAt(inst, 0u)); + const auto denominator = readF64Bits(sourceAt(inst, 1u)); + const auto numerator = readF64Bits(sourceAt(inst, 2u)); + const auto magnitude = [&](IrU32 high) { return IrU32(ir.BitwiseAnd(high.Value(), ir.Constant(0x7fffffffu))); }; + const auto lowNonzero = [&](const std::array& word) { return IrU1(ir.INotEqual(word[0].Value(), ir.Constant(0u))); }; + const auto isNan = [&](const std::array& word) { + return IrU1(ir.LogicalOr(ir.UGreaterThan(magnitude(word[1]).Value(), ir.Constant(0x7ff00000u)), + ir.LogicalAnd(ir.IEqual(magnitude(word[1]).Value(), ir.Constant(0x7ff00000u)), lowNonzero(word).Value()))); + }; + const auto isInf = [&](const std::array& word) { + return IrU1(ir.LogicalAnd(ir.IEqual(magnitude(word[1]).Value(), ir.Constant(0x7ff00000u)), ir.LogicalNot(lowNonzero(word).Value()))); + }; + const auto isZero = [&](const std::array& word) { + return IrU1(ir.IEqual(ir.BitwiseOr(magnitude(word[1]).Value(), word[0].Value()), ir.Constant(0u))); + }; + const auto exponent = [&](IrU32 high) { + return IrU32(ir.Emit(IrOpcode::BitFieldUExtract, IrType::U32, {&high.Value(), &ir.Constant(20u), &ir.Constant(11u)})); + }; + const IrU32 sign(ir.BitwiseAnd(ir.BitwiseXor(denominator[1].Value(), numerator[1].Value()), ir.Constant(0x80000000u))); + const std::array zero{IrU32(ir.Constant(0u)), sign}; + const std::array infinity{IrU32(ir.Constant(0u)), IrU32(ir.BitwiseOr(sign.Value(), ir.Constant(0x7ff00000u)))}; + const std::array defaultNan{IrU32(ir.Constant(0u)), IrU32(ir.Constant(0xfff80000u))}; + const auto quiet = [&](const std::array& word) { + return std::array{word[0], IrU32(ir.BitwiseOr(word[1].Value(), ir.Constant(0x00080000u)))}; + }; + const IrU32 difference(ir.ISub(exponent(numerator[1]).Value(), exponent(denominator[1]).Value())); + const IrU1 underflow(ir.Emit(IrOpcode::SLessThan32, IrType::U1, {&difference.Value(), &ir.Constant(static_cast(-1075))})); + std::array result{quotient[0], IrU32(ir.BitwiseOr(sign.Value(), magnitude(quotient[1]).Value()))}; + const auto choose = [&](IrU1 condition, const std::array& word) { + result = {IrU32(ir.Select(condition.Value(), word[0].Value(), result[0].Value())), IrU32(ir.Select(condition.Value(), word[1].Value(), result[1].Value()))}; + }; + choose(isNan(quotient), infinity); + choose(underflow, zero); + choose(IrU1(ir.LogicalOr(isInf(denominator).Value(), isZero(numerator).Value())), zero); + choose(IrU1(ir.LogicalOr(isZero(denominator).Value(), isInf(numerator).Value())), infinity); + choose(IrU1(ir.LogicalOr(ir.LogicalAnd(isZero(denominator).Value(), isZero(numerator).Value()), ir.LogicalAnd(isInf(denominator).Value(), isInf(numerator).Value()))), defaultNan); + choose(isNan(denominator), quiet(denominator)); + choose(isNan(numerator), quiet(numerator)); + writeOperand(inst.destination, &ir.ConstructU64(result[0].Value(), result[1].Value())); + return true; +} + } diff --git a/core/shader/recompiler/Translation/src/VectorInstructions.cpp b/core/shader/recompiler/Translation/src/VectorInstructions.cpp index faa87f21e..de7772fe5 100644 --- a/core/shader/recompiler/Translation/src/VectorInstructions.cpp +++ b/core/shader/recompiler/Translation/src/VectorInstructions.cpp @@ -940,6 +940,12 @@ bool TranslationContext::emitVector(const RdnaInstruction& inst) { return vDivFmasF32(inst); case RdnaOpcode::VDivFixupF32: return vDivFixupF32(inst); + case RdnaOpcode::VDivScaleF64: + return vDivScaleF64(inst); + case RdnaOpcode::VDivFmasF64: + return vDivFmasF64(inst); + case RdnaOpcode::VDivFixupF64: + return vDivFixupF64(inst); case RdnaOpcode::VLdexpF32: return floatBinary(inst, IrOpcode::FPLdexp, false); case RdnaOpcode::VMacF32: