|
|
|
@@ -0,0 +1,188 @@
|
|
|
|
|
#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, 50> Code{
|
|
|
|
|
0x34020084, 0x34060086, 0xe0381000, 0x80000401, 0xbf8c3f70, 0x4a140af9, 0x06012604, 0x7e160307,
|
|
|
|
|
0x4c160af9, 0x030c3504, 0x4e180af9, 0x0a062804, 0x7d8a0c80, 0x501a0af9, 0x05062404, 0xd501000e,
|
|
|
|
|
0x01a90280, 0x7e1e0307, 0x7d8a0c80, 0x521e0af9, 0x06023304, 0xd5010010, 0x01a90280, 0x7d8a0c80,
|
|
|
|
|
0x54220af9, 0x04082604, 0xd5010012, 0x01a90280, 0x12260af9, 0x0d062d04, 0x16280af9, 0x06062604,
|
|
|
|
|
0x142a0af9, 0x06062604, 0x262c0af9, 0x01062604, 0x7e2e0307, 0x302e0af9, 0x06003404, 0x3c300af9,
|
|
|
|
|
0x06062604, 0xe0781000, 0x80010a03, 0xe0781010, 0x80010e03, 0xe0781020, 0x80011203, 0xe0781030,
|
|
|
|
|
0x80011603, 0xbf810000,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
constexpr std::uint32_t Rows[32][4] = {
|
|
|
|
|
{0x00000000u, 0x00000000u, 0x00010000u, 0x51bb9a4eu},
|
|
|
|
|
{0x007fffffu, 0xfd503aeeu, 0x00000000u, 0x00008000u},
|
|
|
|
|
{0x00000001u, 0x219db754u, 0x00000000u, 0xfdf13c3fu},
|
|
|
|
|
{0x00008000u, 0xfffffffeu, 0x000000ffu, 0x7f7f7f7fu},
|
|
|
|
|
{0x00010000u, 0x80000001u, 0x00007fffu, 0x00008000u},
|
|
|
|
|
{0xfffffffeu, 0x00000000u, 0x00008000u, 0x7fffffffu},
|
|
|
|
|
{0x00000000u, 0x00000002u, 0x00000000u, 0x00008000u},
|
|
|
|
|
{0x00000000u, 0x00010000u, 0x00000000u, 0xe5224648u},
|
|
|
|
|
{0x00010000u, 0x00000000u, 0x00007fffu, 0x80000000u},
|
|
|
|
|
{0x0013fd86u, 0x08ce4bd3u, 0xa671bed2u, 0xffff0000u},
|
|
|
|
|
{0x00ffffffu, 0x00000002u, 0x00000000u, 0xa8d118f0u},
|
|
|
|
|
{0xffff0000u, 0xffff0000u, 0x007fffffu, 0x8bc63fd0u},
|
|
|
|
|
{0xfffffffeu, 0x00ff00ffu, 0x00000000u, 0x00000002u},
|
|
|
|
|
{0x00000000u, 0x00000000u, 0x7f7f7f7fu, 0x00ff00ffu},
|
|
|
|
|
{0x00000000u, 0x00000000u, 0x93552cc2u, 0xffffffffu},
|
|
|
|
|
{0x00000000u, 0x00000000u, 0xccaf1cddu, 0xf37566c1u},
|
|
|
|
|
{0x00000000u, 0x00000000u, 0xffffffffu, 0x0000ffffu},
|
|
|
|
|
{0x00000000u, 0x00000000u, 0xffffffffu, 0x12345678u},
|
|
|
|
|
{0x00000000u, 0x00000001u, 0x00ffffffu, 0x33869405u},
|
|
|
|
|
{0x00000000u, 0x00000001u, 0xff00ff00u, 0x202be01bu},
|
|
|
|
|
{0x00000000u, 0x00000002u, 0x4c31a5c3u, 0x5534d12cu},
|
|
|
|
|
{0x00000000u, 0x00000002u, 0x7ba28771u, 0x007fffffu},
|
|
|
|
|
{0x00000000u, 0x00000002u, 0x7fffffffu, 0xb8cf0c88u},
|
|
|
|
|
{0x00000000u, 0x00000002u, 0xf6340ef5u, 0xcf296973u},
|
|
|
|
|
{0x00000000u, 0x00000002u, 0xffff0000u, 0xffffffffu},
|
|
|
|
|
{0x00000000u, 0x0000007fu, 0x0000ffffu, 0x8d2cc93bu},
|
|
|
|
|
{0x00000000u, 0x0000007fu, 0x121b4baau, 0x00000002u},
|
|
|
|
|
{0x00000000u, 0x0000007fu, 0x12345678u, 0x00ff00ffu},
|
|
|
|
|
{0x00000000u, 0x0000007fu, 0x7f7f7f7fu, 0x000000ffu},
|
|
|
|
|
{0x00000000u, 0x00000080u, 0x00000001u, 0x00010000u},
|
|
|
|
|
{0x00000000u, 0x00000080u, 0x0000ffffu, 0x00ff00ffu},
|
|
|
|
|
{0x00000000u, 0x00000080u, 0x0000ffffu, 0x80000000u}
|
|
|
|
|
};
|
|
|
|
|
constexpr std::uint32_t Expected[32][15] = {
|
|
|
|
|
{0x00000000u, 0x00009a4eu, 0x00000000u, 0x00000001u, 0x00000000u, 0x00bb9a4eu, 0x00000001u, 0x00000000u, 0x00000001u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x51bb0000u, 0xffffffffu},
|
|
|
|
|
{0xfd503bedu, 0xff028000u, 0x00000000u, 0x0000fd4fu, 0x00000000u, 0x00008000u, 0x00000001u, 0x00000000u, 0x00000001u, 0x00000000u, 0xffffffffu, 0x0000281du, 0x0000003au, 0x0000ffffu, 0x02d03aeeu},
|
|
|
|
|
{0x219db754u, 0x00003c3fu, 0xffffff9cu, 0x0000219eu, 0x00000000u, 0x00f13c3fu, 0x00000001u, 0x0000b753u, 0x00000000u, 0x219d0000u, 0x009db754u, 0xffffffffu, 0x00000001u, 0xfdf1dbaau, 0xde6248aau},
|
|
|
|
|
{0xffffffffu, 0x7f017f7fu, 0xffffffffu, 0x00008000u, 0x00000000u, 0x007f7f7fu, 0x00000001u, 0x0000fffdu, 0x00000000u, 0x80000000u, 0xffffffffu, 0xffffffffu, 0x000000ffu, 0x7f7ffffeu, 0x00008001u},
|
|
|
|
|
{0x80000001u, 0x00008000u, 0x00000000u, 0x00008001u, 0x00000000u, 0x00008000u, 0x00000001u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00010000u, 0x00000000u, 0x00000000u, 0x00000001u, 0x7ffefffeu},
|
|
|
|
|
{0x000000ffu, 0xfffeffffu, 0x00000000u, 0x0000ffffu, 0x00000000u, 0xfeffffffu, 0x00000000u, 0x00000000u, 0x00000001u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x7fff0000u, 0x00000001u},
|
|
|
|
|
{0x00000002u, 0x00008000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00008000u, 0x00000001u, 0x00000002u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000002u, 0xfffffffdu},
|
|
|
|
|
{0x00010000u, 0x00004648u, 0x00000001u, 0x00000001u, 0x00000000u, 0x00224648u, 0x00000001u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xe5220000u, 0xfffeffffu},
|
|
|
|
|
{0x00000000u, 0x00000000u, 0x00000000u, 0x00000001u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000001u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x80000000u, 0xfffeffffu},
|
|
|
|
|
{0x08ce4cd0u, 0xfd7e0000u, 0x00000048u, 0x00000655u, 0x00000000u, 0x00ff0000u, 0x00000001u, 0x00000000u, 0x00000001u, 0xffff0000u, 0xffffffffu, 0xfffffc1eu, 0x0000004bu, 0xffff392fu, 0xf72249aau},
|
|
|
|
|
{0x00000101u, 0xffff18f0u, 0x00000000u, 0x0000ffffu, 0x00000000u, 0xfdd118f0u, 0x00000000u, 0x00000000u, 0x00000001u, 0x00000000u, 0x01fffffeu, 0xffffffffu, 0x00000000u, 0xa8d10000u, 0xff000002u},
|
|
|
|
|
{0xffff0000u, 0x00003fd0u, 0xffffffffu, 0x0000ffffu, 0x00000001u, 0x00c63fd0u, 0x00000001u, 0x00000000u, 0x00000001u, 0x00000000u, 0xffffffffu, 0x00000001u, 0x00000000u, 0x8bc60000u, 0xffffffffu},
|
|
|
|
|
{0x00ff01feu, 0xfffe0002u, 0x00000001u, 0x0000ffffu, 0x00000001u, 0x00000002u, 0x00000001u, 0x00000000u, 0x00000001u, 0xfe020000u, 0xffffffffu, 0x00000000u, 0x00000000u, 0x00000000u, 0x00ff00feu},
|
|
|
|
|
{0x00000000u, 0x000000ffu, 0x00000000u, 0x00000001u, 0x00000000u, 0x00ff00ffu, 0x00000001u, 0x00000000u, 0x00000001u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00ff0000u, 0xffffffffu},
|
|
|
|
|
{0x00000000u, 0x0000ffffu, 0x00000000u, 0x00000001u, 0x00000000u, 0x00ffffffu, 0x00000001u, 0x00000000u, 0x00000001u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xffff0000u, 0xffffffffu},
|
|
|
|
|
{0x00000000u, 0x000066c1u, 0x00000000u, 0x00000001u, 0x00000000u, 0x007566c1u, 0x00000001u, 0x00000000u, 0x00000001u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xf3750000u, 0xffffffffu},
|
|
|
|
|
{0x00000000u, 0x0000ffffu, 0x00000000u, 0x00000001u, 0x00000000u, 0x0000ffffu, 0x00000001u, 0x00000000u, 0x00000001u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xffffffffu},
|
|
|
|
|
{0x00000000u, 0x00005678u, 0x00000000u, 0x00000001u, 0x00000000u, 0x00345678u, 0x00000001u, 0x00000000u, 0x00000001u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x12340000u, 0xffffffffu},
|
|
|
|
|
{0x00000001u, 0x00009405u, 0x00000000u, 0x00000001u, 0x00000000u, 0x00869405u, 0x00000001u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x33860001u, 0xfffffffeu},
|
|
|
|
|
{0x00000001u, 0x0000e01bu, 0x00000000u, 0x00000001u, 0x00000000u, 0x002be01bu, 0x00000001u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x202b0001u, 0xfffffffeu},
|
|
|
|
|
{0x00000002u, 0x0000d12cu, 0x00000000u, 0x00000001u, 0x00000000u, 0x0034d12cu, 0x00000001u, 0x00000001u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x55340002u, 0xfffffffdu},
|
|
|
|
|
{0x00000002u, 0x0000ffffu, 0x00000000u, 0x00000001u, 0x00000000u, 0x007fffffu, 0x00000001u, 0x00000001u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x007f0002u, 0xfffffffdu},
|
|
|
|
|
{0x00000002u, 0x00000c88u, 0x00000000u, 0x00000001u, 0x00000000u, 0x00cf0c88u, 0x00000001u, 0x00000001u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xb8cf0002u, 0xfffffffdu},
|
|
|
|
|
{0x00000002u, 0x00006973u, 0x00000000u, 0x00000001u, 0x00000000u, 0x00296973u, 0x00000001u, 0x00000001u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xcf290002u, 0xfffffffdu},
|
|
|
|
|
{0x00000002u, 0x0000ffffu, 0x00000000u, 0x00000001u, 0x00000000u, 0x00ffffffu, 0x00000001u, 0x00000001u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xffff0002u, 0xfffffffdu},
|
|
|
|
|
{0x0000007fu, 0x0000c93bu, 0x00000000u, 0x00000001u, 0x00000000u, 0x002cc93bu, 0x00000001u, 0x0000007eu, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x8d2c007fu, 0xffffff80u},
|
|
|
|
|
{0x0000007fu, 0x00000002u, 0x00000000u, 0x00000001u, 0x00000000u, 0x00000002u, 0x00000001u, 0x0000007eu, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x0000007fu, 0xffffff80u},
|
|
|
|
|
{0x0000007fu, 0x000000ffu, 0x00000000u, 0x00000001u, 0x00000000u, 0x00ff00ffu, 0x00000001u, 0x0000007eu, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00ff007fu, 0xffffff80u},
|
|
|
|
|
{0x0000007fu, 0x000000ffu, 0x00000000u, 0x00000001u, 0x00000000u, 0x000000ffu, 0x00000001u, 0x0000007eu, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x0000007fu, 0xffffff80u},
|
|
|
|
|
{0x00000080u, 0x00000000u, 0x00000000u, 0x00000001u, 0x00000000u, 0x00010000u, 0x00000001u, 0x0000007fu, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00010080u, 0xffffff7fu},
|
|
|
|
|
{0x00000080u, 0x000000ffu, 0x00000000u, 0x00000001u, 0x00000000u, 0x00ff00ffu, 0x00000001u, 0x0000007fu, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00ff0080u, 0xffffff7fu},
|
|
|
|
|
{0x00000080u, 0x00000000u, 0x00000000u, 0x00000001u, 0x00000000u, 0x00000000u, 0x00000001u, 0x0000007fu, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x80000080u, 0xffffff7fu}
|
|
|
|
|
};
|
|
|
|
|
constexpr const char* Names[15] = {
|
|
|
|
|
"add_nc_u32",
|
|
|
|
|
"sub_nc_u32",
|
|
|
|
|
"subrev_nc_u32",
|
|
|
|
|
"add_co_ci_u32",
|
|
|
|
|
"add_co_ci_u32 carry",
|
|
|
|
|
"sub_co_ci_u32",
|
|
|
|
|
"sub_co_ci_u32 carry",
|
|
|
|
|
"subrev_co_ci_u32",
|
|
|
|
|
"subrev_co_ci_u32 carry",
|
|
|
|
|
"mul_i32_i24",
|
|
|
|
|
"mul_u32_u24",
|
|
|
|
|
"mul_hi_i32_i24",
|
|
|
|
|
"min_u32",
|
|
|
|
|
"ashrrev_i32",
|
|
|
|
|
"xnor_b32",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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("sdwa integer 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<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 < 15; ++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("sdwa integer clamp tests passed");
|
|
|
|
|
return 0;
|
|
|
|
|
} catch (const std::exception& error) {
|
|
|
|
|
std::cerr << error.what() << '\n';
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|