mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
Merge pull request #474 from adriadam10/feat/div-f64
feat(shader): implement v_div_scale_f64, v_div_fmas_f64 and v_div_fixup_f64
This commit is contained in:
@@ -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 <algorithm>
|
||||
#include <array>
|
||||
#include <bit>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
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<std::uint32_t, Threads * Inputs> Input{};
|
||||
alignas(256) std::array<std::uint32_t, Threads * Results> Output{};
|
||||
|
||||
alignas(256) constexpr std::array<std::uint32_t, 36> 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<std::uint32_t, 4> BufferDescriptor(const void* data, std::uint32_t bytes) {
|
||||
const auto address = reinterpret_cast<std::uintptr_t>(data);
|
||||
return {static_cast<std::uint32_t>(address), static_cast<std::uint32_t>((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<std::uint32_t> userData(8, 0u);
|
||||
const auto input = BufferDescriptor(Input.data(), static_cast<std::uint32_t>(Input.size() * 4u));
|
||||
const auto output = BufferDescriptor(Output.data(), static_cast<std::uint32_t>(Output.size() * 4u));
|
||||
std::copy(input.begin(), input.end(), userData.begin());
|
||||
std::copy(output.begin(), output.end(), userData.begin() + 4);
|
||||
const std::span<const std::uint32_t> code(Code);
|
||||
const std::array<ShaderRecompiler::MemoryRegion, 1> memory{{{reinterpret_cast<std::uintptr_t>(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<std::uintptr_t>(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<std::uintptr_t>(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;
|
||||
}
|
||||
}
|
||||
@@ -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 <algorithm>
|
||||
#include <array>
|
||||
#include <bit>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
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<std::uint32_t, Threads * Inputs> Input{};
|
||||
alignas(256) std::array<std::uint32_t, Threads * Results> Output{};
|
||||
|
||||
alignas(256) constexpr std::array<std::uint32_t, 38> 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<std::uint32_t, 4> BufferDescriptor(const void* data, std::uint32_t bytes) {
|
||||
const auto address = reinterpret_cast<std::uintptr_t>(data);
|
||||
return {static_cast<std::uint32_t>(address), static_cast<std::uint32_t>((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<std::uint32_t> userData(8, 0u);
|
||||
const auto input = BufferDescriptor(Input.data(), static_cast<std::uint32_t>(Input.size() * 4u));
|
||||
const auto output = BufferDescriptor(Output.data(), static_cast<std::uint32_t>(Output.size() * 4u));
|
||||
std::copy(input.begin(), input.end(), userData.begin());
|
||||
std::copy(output.begin(), output.end(), userData.begin() + 4);
|
||||
const std::span<const std::uint32_t> code(Code);
|
||||
const std::array<ShaderRecompiler::MemoryRegion, 1> memory{{{reinterpret_cast<std::uintptr_t>(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<std::uintptr_t>(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<std::uintptr_t>(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;
|
||||
}
|
||||
}
|
||||
+1
@@ -248,6 +248,7 @@ enum class IrOpcode : std::uint16_t {
|
||||
FPAdd64,
|
||||
FPMul64,
|
||||
FPFma64,
|
||||
FPFmaScale64,
|
||||
FPMin64,
|
||||
FPMax64,
|
||||
FPSaturate64,
|
||||
|
||||
@@ -289,6 +289,7 @@ constexpr std::array<OpcodeMeta, static_cast<std::size_t>(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),
|
||||
|
||||
@@ -416,6 +416,9 @@ enum class RdnaOpcode : std::uint16_t {
|
||||
VRsqF64,
|
||||
VSqrtF64,
|
||||
VTrigPreopF64,
|
||||
VDivScaleF64,
|
||||
VDivFmasF64,
|
||||
VDivFixupF64,
|
||||
VCvtPknormI16F32,
|
||||
VCvtPknormU16F32,
|
||||
VCvtPkU16U32,
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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<const std
|
||||
instruction.source1 = DecodeRdnaScalarSource(src1, programCounter);
|
||||
instruction.source2 = DecodeRdnaScalarSource(src2, programCounter);
|
||||
instruction.sourceCount = 3;
|
||||
if (instruction.op == RdnaOpcode::VDivScaleF32) {
|
||||
if (instruction.op == RdnaOpcode::VDivScaleF32 || instruction.op == RdnaOpcode::VDivScaleF64) {
|
||||
applyNativeVop3SourceModifiers(instruction, 0u, neg);
|
||||
}
|
||||
ReadRdnaLiteralOperands(code, wordIndex, instruction);
|
||||
|
||||
@@ -182,6 +182,7 @@ std::uint32_t EmitFPFract32(SpirvEmitterState& state, std::uint32_t arg0);
|
||||
std::uint32_t EmitFPAdd64(SpirvEmitterState& state, std::uint32_t arg0, std::uint32_t arg1);
|
||||
std::uint32_t EmitFPMul64(SpirvEmitterState& state, std::uint32_t arg0, std::uint32_t arg1);
|
||||
std::uint32_t EmitFPFma64(SpirvEmitterState& state, std::uint32_t arg0, std::uint32_t arg1, std::uint32_t arg2);
|
||||
std::uint32_t EmitFPFmaScale64(SpirvEmitterState& state, std::uint32_t arg0, std::uint32_t arg1, std::uint32_t arg2, std::uint32_t arg3);
|
||||
std::uint32_t EmitFPMin64(SpirvEmitterState& state, std::uint32_t arg0, std::uint32_t arg1);
|
||||
std::uint32_t EmitFPMax64(SpirvEmitterState& state, std::uint32_t arg0, std::uint32_t arg1);
|
||||
std::uint32_t EmitFPSaturate64(SpirvEmitterState& state, std::uint32_t arg0);
|
||||
|
||||
@@ -197,17 +197,7 @@ std::uint32_t AddRoundToOdd(SpirvEmitterState& state, std::uint32_t lhs, std::ui
|
||||
return ToF64(state, Join(state, SelectBits(state, inexact, odd, rounded)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::uint32_t EmitFPAdd64(SpirvEmitterState& state, std::uint32_t arg0, std::uint32_t arg1) {
|
||||
return NanResult(state, Exact(state, spv::OpFAdd, ToF64(state, arg0), ToF64(state, arg1)), {arg0, arg1});
|
||||
}
|
||||
|
||||
std::uint32_t EmitFPMul64(SpirvEmitterState& state, std::uint32_t arg0, std::uint32_t arg1) {
|
||||
return NanResult(state, Exact(state, spv::OpFMul, ToF64(state, arg0), ToF64(state, arg1)), {arg0, arg1});
|
||||
}
|
||||
|
||||
std::uint32_t EmitFPFma64(SpirvEmitterState& state, std::uint32_t arg0, std::uint32_t arg1, std::uint32_t arg2) {
|
||||
std::uint32_t FusedMultiplyAdd(SpirvEmitterState& state, std::uint32_t arg0, std::uint32_t arg1, std::uint32_t arg2, std::uint32_t scale) {
|
||||
const auto a = Classify(state, arg0);
|
||||
const auto b = Classify(state, arg1);
|
||||
const auto c = Classify(state, arg2);
|
||||
@@ -237,11 +227,14 @@ std::uint32_t EmitFPFma64(SpirvEmitterState& state, std::uint32_t arg0, std::uin
|
||||
const auto exact = TwoProduct(state, ToF64(state, Join(state, WithExponent(state, a.bits, ConstantU32(state, 1023u)))), ToF64(state, Join(state, WithExponent(state, b.bits, ConstantU32(state, 1023u)))));
|
||||
const auto sum = TwoSum(state, ToF64(state, Join(state, scaledC)), exact.high);
|
||||
const auto scaled = Exact(state, spv::OpFAdd, sum.high, AddRoundToOdd(state, sum.low, exact.low));
|
||||
const auto half = Binary(state, spv::OpSDiv, TypeI32(state), product, ConstantI32(state, 2));
|
||||
const auto rescaled = Exact(state, spv::OpFMul, Exact(state, spv::OpFMul, scaled, PowerOfTwo(state, half)), PowerOfTwo(state, Binary(state, spv::OpISub, TypeI32(state), product, half)));
|
||||
const auto finite = SelectBits(state, far, c.bits, Split(state, FromF64(state, rescaled)));
|
||||
const auto power = PowerOfTwo(state, scale);
|
||||
const auto total = Glsl(state, TypeI32(state), GLSLstd450SClamp, Binary(state, spv::OpIAdd, TypeI32(state), product, scale), ConstantI32(state, -2044), ConstantI32(state, 2046));
|
||||
const auto half = Binary(state, spv::OpSDiv, TypeI32(state), total, ConstantI32(state, 2));
|
||||
const auto rescaled = Exact(state, spv::OpFMul, Exact(state, spv::OpFMul, scaled, PowerOfTwo(state, half)), PowerOfTwo(state, Binary(state, spv::OpISub, TypeI32(state), total, half)));
|
||||
const auto farValue = Split(state, FromF64(state, Exact(state, spv::OpFMul, ToF64(state, arg2), power)));
|
||||
const auto finite = SelectBits(state, far, farValue, Split(state, FromF64(state, rescaled)));
|
||||
|
||||
auto fallback = Split(state, FromF64(state, Exact(state, spv::OpFAdd, Exact(state, spv::OpFMul, ToF64(state, arg0), ToF64(state, arg1)), ToF64(state, arg2))));
|
||||
auto fallback = Split(state, FromF64(state, Exact(state, spv::OpFMul, Exact(state, spv::OpFAdd, Exact(state, spv::OpFMul, ToF64(state, arg0), ToF64(state, arg1)), ToF64(state, arg2)), power)));
|
||||
const auto finiteProduct = Binary(state, spv::OpLogicalAnd, TypeBool(state), Unary(state, spv::OpLogicalNot, TypeBool(state), isField(exponentA, 0x7ffu)), Unary(state, spv::OpLogicalNot, TypeBool(state), isField(exponentB, 0x7ffu)));
|
||||
fallback = SelectBits(state, Binary(state, spv::OpLogicalAnd, TypeBool(state), c.infinite, finiteProduct), c.bits, fallback);
|
||||
fallback = SelectBits(state, Classify(state, Join(state, fallback)).nan, {ConstantU32(state, 0u), ConstantU32(state, 0xfff80000u)}, fallback);
|
||||
@@ -255,6 +248,24 @@ std::uint32_t EmitFPFma64(SpirvEmitterState& state, std::uint32_t arg0, std::uin
|
||||
return Join(state, result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::uint32_t EmitFPAdd64(SpirvEmitterState& state, std::uint32_t arg0, std::uint32_t arg1) {
|
||||
return NanResult(state, Exact(state, spv::OpFAdd, ToF64(state, arg0), ToF64(state, arg1)), {arg0, arg1});
|
||||
}
|
||||
|
||||
std::uint32_t EmitFPMul64(SpirvEmitterState& state, std::uint32_t arg0, std::uint32_t arg1) {
|
||||
return NanResult(state, Exact(state, spv::OpFMul, ToF64(state, arg0), ToF64(state, arg1)), {arg0, arg1});
|
||||
}
|
||||
|
||||
std::uint32_t EmitFPFma64(SpirvEmitterState& state, std::uint32_t arg0, std::uint32_t arg1, std::uint32_t arg2) {
|
||||
return FusedMultiplyAdd(state, arg0, arg1, arg2, ConstantI32(state, 0));
|
||||
}
|
||||
|
||||
std::uint32_t EmitFPFmaScale64(SpirvEmitterState& state, std::uint32_t arg0, std::uint32_t arg1, std::uint32_t arg2, std::uint32_t arg3) {
|
||||
return FusedMultiplyAdd(state, arg0, arg1, arg2, Unary(state, spv::OpBitcast, TypeI32(state), arg3));
|
||||
}
|
||||
|
||||
std::uint32_t EmitFPMin64(SpirvEmitterState& state, std::uint32_t arg0, std::uint32_t arg1) {
|
||||
return MinMax(state, arg0, arg1, false);
|
||||
}
|
||||
|
||||
@@ -422,6 +422,7 @@ void EmitDirectInstruction(SpirvValueEmitContext& ctx, const IrValue& inst) {
|
||||
case IrOpcode::FPAdd64: return Invoke(EmitFPAdd64, ctx, inst);
|
||||
case IrOpcode::FPMul64: return Invoke(EmitFPMul64, ctx, inst);
|
||||
case IrOpcode::FPFma64: return Invoke(EmitFPFma64, ctx, inst);
|
||||
case IrOpcode::FPFmaScale64: return Invoke(EmitFPFmaScale64, ctx, inst);
|
||||
case IrOpcode::FPMin64: return Invoke(EmitFPMin64, ctx, inst);
|
||||
case IrOpcode::FPMax64: return Invoke(EmitFPMax64, ctx, inst);
|
||||
case IrOpcode::FPSaturate64: return Invoke(EmitFPSaturate64, ctx, inst);
|
||||
|
||||
@@ -172,6 +172,9 @@ private:
|
||||
bool vMulLegacyF32(const RdnaInstruction& inst, bool accumulate);
|
||||
void emitFloat16ClassCompare(const RdnaInstruction& inst, bool cmpx);
|
||||
bool float64Operation(const RdnaInstruction& inst, IrOpcode opcode);
|
||||
bool vDivScaleF64(const RdnaInstruction& inst);
|
||||
bool vDivFmasF64(const RdnaInstruction& inst);
|
||||
bool vDivFixupF64(const RdnaInstruction& inst);
|
||||
bool vDot2cF32F16(const RdnaInstruction& inst);
|
||||
bool vDot2F32F16(const RdnaInstruction& inst);
|
||||
bool vCubeidF32(const RdnaInstruction& inst);
|
||||
|
||||
@@ -31,4 +31,108 @@ bool TranslationContext::float64Operation(const RdnaInstruction& inst, IrOpcode
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TranslationContext::vDivScaleF64(const RdnaInstruction& inst) {
|
||||
const auto value = readF64Bits(sourceAt(inst, 0u));
|
||||
const auto denominator = readF64Bits(sourceAt(inst, 1u));
|
||||
const auto numerator = readF64Bits(sourceAt(inst, 2u));
|
||||
const auto exponent = [&](IrU32 high) {
|
||||
return IrU32(ir.Emit(IrOpcode::BitFieldUExtract, IrType::U32, {&high.Value(), &ir.Constant(20u), &ir.Constant(11u)}));
|
||||
};
|
||||
const IrU32 denominatorExponent = exponent(denominator[1]);
|
||||
const IrU32 numeratorExponent = exponent(numerator[1]);
|
||||
const IrU32 difference(ir.ISub(numeratorExponent.Value(), denominatorExponent.Value()));
|
||||
const IrU1 nearMax(ir.Emit(IrOpcode::SGreaterThanEqual32, IrType::U1, {&difference.Value(), &ir.Constant(768u)}));
|
||||
const IrU1 nearMin(ir.Emit(IrOpcode::SLessThanEqual32, IrType::U1, {&difference.Value(), &ir.Constant(static_cast<std::uint32_t>(-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<std::uint32_t>(-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<IrU32, 2>& 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<IrU32, 2> 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<std::uint32_t>(-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<IrU32, 2>& word) { return IrU1(ir.INotEqual(word[0].Value(), ir.Constant(0u))); };
|
||||
const auto isNan = [&](const std::array<IrU32, 2>& 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<IrU32, 2>& 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<IrU32, 2>& 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<IrU32, 2> zero{IrU32(ir.Constant(0u)), sign};
|
||||
const std::array<IrU32, 2> infinity{IrU32(ir.Constant(0u)), IrU32(ir.BitwiseOr(sign.Value(), ir.Constant(0x7ff00000u)))};
|
||||
const std::array<IrU32, 2> defaultNan{IrU32(ir.Constant(0u)), IrU32(ir.Constant(0xfff80000u))};
|
||||
const auto quiet = [&](const std::array<IrU32, 2>& word) {
|
||||
return std::array<IrU32, 2>{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<std::uint32_t>(-1075))}));
|
||||
std::array<IrU32, 2> result{quotient[0], IrU32(ir.BitwiseOr(sign.Value(), magnitude(quotient[1]).Value()))};
|
||||
const auto choose = [&](IrU1 condition, const std::array<IrU32, 2>& 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user