Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions core/libs/prx/libSceAgcDriver/tests/execution/D16Memory.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#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 <cstdint>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>

namespace {

using AgcDriver::Graphics::Require;
using ShaderRecompiler::ShaderStage;

constexpr std::uint32_t Threads = 32;
constexpr std::uint32_t InputBytes = 16;
constexpr std::uint32_t Results = 16;
alignas(256) std::array<std::uint8_t, Threads * InputBytes> Input{};
alignas(256) std::array<std::uint32_t, Threads * Results> Output{};

alignas(256) constexpr std::array<std::uint32_t, 107> D16Code{
0x34020084, 0x34060086, 0xbe880300, 0x8709ff01, 0x0000ffff, 0x7e1402ff, 0xabcdabcd, 0x7e1602ff,
0xabcdabcd, 0x7e1802ff, 0xabcdabcd, 0x7e1a02ff, 0xabcdabcd, 0x7e1c02ff, 0xabcdabcd, 0x7e1e02ff,
0xabcdabcd, 0x7e2002ff, 0xabcdabcd, 0x7e2202ff, 0xabcdabcd, 0x7e2402ff, 0xabcdabcd, 0x7e2602ff,
0xabcdabcd, 0x7e2802ff, 0xabcdabcd, 0x7e2a02ff, 0xabcdabcd, 0xe0801001, 0x80000a01, 0xe0841002,
0x80000a01, 0xe0881003, 0x80000b01, 0xe08c1005, 0x80000b01, 0xe0901006, 0x80000c01, 0xe0941008,
0x80000c01, 0xdc808001, 0x0d080001, 0xdc848002, 0x0d080001, 0xdc888003, 0x0e080001, 0xdc8c8005,
0x0e080001, 0xdc908006, 0x0f080001, 0xdc948008, 0x0f080001, 0x34040082, 0xbf8c3f70, 0xe0301000,
0x80000401, 0xbf8c3f70, 0xd8340000, 0x00000402, 0xbf8cc07f, 0xda880001, 0x10000002, 0xda8c0002,
0x10000002, 0xda900003, 0x11000002, 0xda940001, 0x11000002, 0xda980002, 0x12000002, 0xda9c0000,
0x12000002, 0xbf8cc07f, 0x7e2602ff, 0x80c1a2b3, 0xe0641028, 0x80011303, 0xe06c102c, 0x80011303,
0xda800001, 0x00001302, 0xbf8cc07f, 0xd8d80000, 0x14000002, 0xbf8c0070, 0xe0701000, 0x80010a03,
0xe0701004, 0x80010b03, 0xe0701008, 0x80010c03, 0xe070100c, 0x80010d03, 0xe0701010, 0x80010e03,
0xe0701014, 0x80010f03, 0xe0701018, 0x80011003, 0xe070101c, 0x80011103, 0xe0701020, 0x80011203,
0xe0701024, 0x80011403, 0xbf810000,
};

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};
}

void Run(AgcDriver::VulkanDevice& device) {
for (std::uint32_t i = 0; i < Input.size(); ++i) Input[i] = static_cast<std::uint8_t>(i * 37u + 0x81u);
Output.fill(0xdeadbeefu);
std::vector<std::uint32_t> userData(8, 0u);
const auto input = BufferDescriptor(Input.data(), static_cast<std::uint32_t>(Input.size()));
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(D16Code);
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}, 4u * Threads, {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();
}

std::string Hex(std::uint32_t value) {
char text[16];
std::snprintf(text, sizeof(text), "0x%08x", value);
return text;
}

void Check() {
constexpr std::array<const char*, 12> names{
"buffer_load_ubyte_d16(_hi)", "buffer_load_sbyte_d16(_hi)", "buffer_load_short_d16(_hi)",
"global_load_ubyte_d16(_hi)", "global_load_sbyte_d16(_hi)", "global_load_short_d16(_hi)",
"ds_read_u8_d16(_hi)", "ds_read_i8_d16(_hi)", "ds_read_u16_d16(_hi)", "ds_write_b8_d16_hi",
"buffer_store_byte_d16_hi", "buffer_store_short_d16_hi",
};
for (std::uint32_t tid = 0; tid < Threads; ++tid) {
const std::uint8_t* in = &Input[tid * InputBytes];
const auto u8 = [&](std::uint32_t at) { return static_cast<std::uint32_t>(in[at]); };
const auto i8 = [&](std::uint32_t at) { return static_cast<std::uint32_t>(static_cast<std::int16_t>(static_cast<std::int8_t>(in[at]))) & 0xffffu; };
const auto u16 = [&](std::uint32_t at) { return u8(at) | (u8(at + 1u) << 8u); };
const std::uint32_t loads[3] = {u8(1) | (u8(2) << 16u), i8(3) | (i8(5) << 16u), u16(6) | (u16(8) << 16u)};
std::uint32_t dword = 0;
std::memcpy(&dword, in, 4);
const std::uint32_t written = (dword & 0xffff00ffu) | (0xc1u << 8u);
std::array<std::uint32_t, 12> expected{
loads[0], loads[1], loads[2], loads[0], loads[1], loads[2],
u8(1) | (u8(2) << 16u), i8(3) | (i8(1) << 16u), u16(2) | (u16(0) << 16u), written,
0xdeadbec1u, 0xdead80c1u,
};
const auto* out = &Output[tid * Results];
for (std::uint32_t j = 0; j < expected.size(); ++j) {
Require(out[j] == expected[j], std::string("d16 memory: lane ") + std::to_string(tid) + " " + names[j] + " is " + Hex(out[j]) + ", expected " + Hex(expected[j]));
}
}
}

}

int main() {
try {
const auto device = OpenVulkanTestDevice();
if (!device) return VulkanTestSkipped;
Run(*device);
Check();
std::puts("d16 memory tests passed");
return 0;
} catch (const std::exception& error) {
std::cerr << error.what() << '\n';
return 1;
}
}
176 changes: 176 additions & 0 deletions core/libs/prx/libSceAgcDriver/tests/execution/FormatD16.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
#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, 101> Code{
0x34020084, 0x34060086, 0xbe900300, 0xbe910301, 0xbe920302, 0xbe9303ff, 0x01001244, 0x7e1402ff,
0xdead0000, 0x7e1602ff, 0xdead0000, 0x7e1802ff, 0xdead0000, 0x7e1a02ff, 0xdead0000, 0x7e1c02ff,
0xdead0000, 0x7e1e02ff, 0xdead0000, 0x7e2002ff, 0xdead0000, 0x7e2202ff, 0xdead0000, 0x7e2402ff,
0xdead0000, 0x7e2602ff, 0xdead0000, 0x7e2802ff, 0xbeefbeef, 0x7e2a02ff, 0xbeefbeef, 0x7e2c02ff,
0xbeefbeef, 0x7e2e02ff, 0xbeefbeef, 0x7e3002ff, 0xbeefbeef, 0x7e3202ff, 0xbeefbeef, 0xe8081000,
0x80200a01, 0xe8101000, 0x80200b01, 0xe8381008, 0x80200c01, 0xe8401008, 0x80200d01, 0xe8481008,
0x80200e01, 0xe8501008, 0x80200f01, 0xe8301000, 0x80201001, 0xe8b01004, 0x80201101, 0xe8a01004,
0x80201201, 0xe8a81004, 0x80201301, 0xe8711000, 0x80201401, 0xe9e2100c, 0x80201501, 0xe0981004,
0x80001701, 0xe20c100c, 0x80041801, 0xbf8c3f70, 0xe0701000, 0x80010a03, 0xe0701004, 0x80010b03,
0xe0701008, 0x80010c03, 0xe070100c, 0x80010d03, 0xe0701010, 0x80010e03, 0xe0701014, 0x80010f03,
0xe0701018, 0x80011003, 0xe070101c, 0x80011103, 0xe0701020, 0x80011203, 0xe0701024, 0x80011303,
0xe0701028, 0x80011403, 0xe070102c, 0x80011503, 0xe0701030, 0x80011603, 0xe0701034, 0x80011703,
0xe0701038, 0x80011803, 0xe070103c, 0x80011903, 0xbf810000,
};

constexpr std::uint32_t Rows[32][4] = {
{0x000000ffu, 0x7f800000u, 0x0000ffffu, 0x73cf256du},
{0x00000080u, 0xff800000u, 0x00008000u, 0xdda1494cu},
{0x0000007fu, 0x7fc00000u, 0x00007fffu, 0x8f4d3e27u},
{0x00000000u, 0x7f800001u, 0x0000ffafu, 0xdb5b5fabu},
{0x81ff7f01u, 0xffc12345u, 0x00007ff7u, 0xec99108du},
{0xc7fde805u, 0x7fa00000u, 0x00008009u, 0x7734d7c1u},
{0x73ab4876u, 0x00000001u, 0x0000fffdu, 0x8201e2bdu},
{0xdae44550u, 0x33000001u, 0x00000001u, 0x965eda32u},
{0x309d6b79u, 0x387fc000u, 0x2f45e678u, 0xcdcc6929u},
{0x830c71c2u, 0x477ff000u, 0x79cb9e86u, 0xa13ffe79u},
{0x9d2c67edu, 0x47800000u, 0xcb008853u, 0x2fa91425u},
{0x18187993u, 0xc77fefffu, 0x7253edc6u, 0x4dabb481u},
{0x244caf9cu, 0x3f800000u, 0x17362f25u, 0x89e7d15fu},
{0xcf44dd3fu, 0xbf800000u, 0xe3eff9c0u, 0xb1852f27u},
{0xa26b7f62u, 0x80000000u, 0x0ab8ab67u, 0x986e86cbu},
{0xfb710734u, 0x3fc00000u, 0x656abd72u, 0xf6fa5db8u},
{0x73f778aau, 0xa7677796u, 0xbd299753u, 0x9d95847eu},
{0xa66b0d38u, 0x28518867u, 0x9f8558a6u, 0x03d71684u},
{0xd4ea65d0u, 0x8743feb6u, 0x102b938bu, 0x0f3ebdd3u},
{0x09208a65u, 0x30b17d0bu, 0xe12b2b8fu, 0x3deffa38u},
{0x99809225u, 0x07b37e14u, 0xc7321cc0u, 0x76c468aeu},
{0x5387f613u, 0x70c6a5b8u, 0x97491e23u, 0xd7a94dedu},
{0x320094eau, 0x84e55160u, 0x3bd03346u, 0xa3ea284du},
{0x4b4d8474u, 0x7ff12229u, 0x012d0ea6u, 0xa9964aefu},
{0x15c1d2dfu, 0x75139237u, 0xa7a11490u, 0x4735af1cu},
{0x6822a6b2u, 0xff666589u, 0x8d1fe1dau, 0xfee5a5b2u},
{0xee82ec3fu, 0xd7185ddau, 0x154cd2aau, 0xb53302fcu},
{0x4105cca7u, 0x50b601fcu, 0xc20ba2c2u, 0x3acb6266u},
{0x834c687au, 0x49fe85b0u, 0x079dd25au, 0x11fa2ac0u},
{0x902a174fu, 0xc42b7170u, 0x1ba1192eu, 0x66809a11u},
{0x1b98fbe4u, 0xd8b9b45cu, 0x4a789cb3u, 0x62f28d1au},
{0x111b8aaau, 0xf542441du, 0x0452ef05u, 0xd8e94b15u},
};
constexpr std::uint32_t Expected[32][16] = {
{0xdead3c00u, 0xdeada008u, 0xdead3c00u, 0xdead8200u, 0xdead7bffu, 0xdeadbc00u, 0xdeadffffu, 0xdead7c00u, 0xdeadffffu, 0xdead7fffu, 0x00003c00u, 0x0025006du, 0xbeef00cfu, 0x7c00beefu, 0x000036d7u, 0x3c003c00u},
{0xdead3804u, 0xdeadbc00u, 0xdead3800u, 0xdeadbc00u, 0xdead7800u, 0xdeadf800u, 0xdeadff80u, 0xdeadfc00u, 0xdeadffffu, 0xdead8000u, 0x00003804u, 0x0049004cu, 0xbeef00a1u, 0xfc00beefu, 0x000034c5u, 0x3c003c00u},
{0xdead37f8u, 0xdead3c00u, 0xdead3800u, 0xdead3c00u, 0xdead7800u, 0xdead7800u, 0xdead007fu, 0xdead7e00u, 0xdeadffffu, 0xdead7fffu, 0x000037f8u, 0x003e0027u, 0xbeef004du, 0x7e00beefu, 0x000030e5u, 0x3c003c00u},
{0xdead0000u, 0xdead0000u, 0xdead3bfdu, 0xdead9910u, 0xdead7bfdu, 0xdeadd510u, 0xdead0000u, 0xdead7c01u, 0xdeadffffu, 0xdead7fffu, 0x00000000u, 0x005f00abu, 0xbeef005bu, 0x7c01beefu, 0x0000395du, 0x3c003c00u},
{0xdead1c04u, 0xdead2008u, 0xdead37ffu, 0xdead3bffu, 0xdead77ffu, 0xdead77ffu, 0xdead0001u, 0xdeadfe09u, 0xdeadffffu, 0xdead8000u, 0x37f81c04u, 0x0010008du, 0xbeef0099u, 0xfe09beefu, 0x0000386cu, 0x3c003c00u},
{0xdead2505u, 0xdead290au, 0xdead3800u, 0xdeadbbffu, 0xdead7800u, 0xdeadf7ffu, 0xdead0005u, 0xdead7d00u, 0xdeadffffu, 0xdead7fffu, 0x3b472505u, 0x00d700c1u, 0xbeef0034u, 0x7d00beefu, 0x00003a0eu, 0x3c003c00u},
{0xdead3767u, 0xdead3b6fu, 0xdead3c00u, 0xdead8600u, 0xdead7bffu, 0xdeadc200u, 0xdead0076u, 0xdead0000u, 0xdead0001u, 0xdead0001u, 0x34853767u, 0x00e200bdu, 0xbeef0001u, 0x0000beefu, 0x000039eeu, 0x3c003c00u},
{0xdead3505u, 0xdead390au, 0xdead0100u, 0xdead0200u, 0xdead3c00u, 0xdead3c00u, 0xdead0050u, 0xdead0000u, 0xdeadffffu, 0xdead7fffu, 0x34543505u, 0x00da0032u, 0xbeef005eu, 0x0000beefu, 0x00003246u, 0x3c003c00u},
{0xdead3798u, 0xdead3b9fu, 0xdead3b34u, 0xdeadb262u, 0xdead7b34u, 0xdeadee62u, 0xdead0079u, 0xdead03ffu, 0xdeadffffu, 0xdead7fffu, 0x36b73798u, 0x00690029u, 0xbeef00ccu, 0x03ffbeefu, 0x00003125u, 0x3c003c00u},
{0xdead3a16u, 0xdeadb7d0u, 0xdead38f4u, 0xdeadba18u, 0xdead78f4u, 0xdeadf618u, 0xdeadffc2u, 0xdead7bffu, 0xdeadffffu, 0xdead7fffu, 0x37173a16u, 0x00fe0079u, 0xbeef003fu, 0x7bffbeefu, 0x00003798u, 0x3c003c00u},
{0xdead3b6fu, 0xdeadb0cau, 0xdead3843u, 0xdeadbb7bu, 0xdead7843u, 0xdeadf77bu, 0xdeadffedu, 0xdead7bffu, 0xdeadffffu, 0xdead7fffu, 0x36763b6fu, 0x00140025u, 0xbeef00a9u, 0x7bffbeefu, 0x000030a5u, 0x3c003c00u},
{0xdead389du, 0xdeadbadeu, 0xdead3b6eu, 0xdeadb08fu, 0xdead7b6eu, 0xdeadec8eu, 0xdeadff93u, 0xdeadfbffu, 0xdeadffffu, 0xdead8000u, 0x3798389du, 0x00b40081u, 0xbeef00abu, 0xfbffbeefu, 0x0000380cu, 0x3c003c00u},
{0xdead38e5u, 0xdeadba4du, 0xdead31e5u, 0xdead35e5u, 0xdead71e5u, 0xdead71e5u, 0xdeadff9cu, 0xdead3c00u, 0xdeadffffu, 0xdead7fffu, 0x397d38e5u, 0x00d1005fu, 0xbeef00e7u, 0x3c00beefu, 0x000035f6u, 0x3c003c00u},
{0xdead33e8u, 0xdead37f0u, 0xdead3bceu, 0xdeadaa40u, 0xdead7bceu, 0xdeade640u, 0xdead003fu, 0xdeadbc00u, 0xdeadffffu, 0xdead8000u, 0x3aef33e8u, 0x002f0027u, 0xbeef0085u, 0xbc00beefu, 0x000030e5u, 0x3c003c00u},
{0xdead3626u, 0xdead3a2cu, 0xdead395bu, 0xdeadb94au, 0xdead795bu, 0xdeadf54au, 0xdead0062u, 0xdead8000u, 0xdeadffffu, 0xdead8000u, 0x37f83626u, 0x008600cbu, 0xbeef006eu, 0x8000beefu, 0x00003a5eu, 0x3c003c00u},
{0xdead3287u, 0xdead368du, 0xdead39ecu, 0xdeadb829u, 0xdead79ecu, 0xdeadf429u, 0xdead0034u, 0xdead3e00u, 0xdeadffffu, 0xdead7fffu, 0x27073287u, 0x005d00b8u, 0xbeef00fau, 0x3e00beefu, 0x000039c6u, 0x3c003c00u},
{0xdead3955u, 0xdeadb96bu, 0xdead38bbu, 0xdeadba8bu, 0xdead78bbu, 0xdeadf68bu, 0xdeadffaau, 0xdead8000u, 0xdeadffffu, 0xdead8000u, 0x37883955u, 0x0084007eu, 0xbeef0095u, 0x8000beefu, 0x000037e8u, 0x3c003c00u},
{0xdead3307u, 0xdead370eu, 0xdead358au, 0xdead398au, 0xdead758au, 0xdead758au, 0xdead0038u, 0xdead0000u, 0xdeadffffu, 0xdead7fffu, 0x2a873307u, 0x00160084u, 0xbeef00d7u, 0x0000beefu, 0x00003824u, 0x3c003c00u},
{0xdead3a87u, 0xdeadb60cu, 0xdead389cu, 0xdeadbac7u, 0xdead789cu, 0xdeadf6c7u, 0xdeadffd0u, 0xdead8000u, 0xdeadffffu, 0xdead8000u, 0x36563a87u, 0x00bd00d3u, 0xbeef003eu, 0x8000beefu, 0x00003a9fu, 0x3c003c00u},
{0xdead3656u, 0xdead3a5du, 0xdead3172u, 0xdead3572u, 0xdead7172u, 0xdead7172u, 0xdead0065u, 0xdead0000u, 0xdeadffffu, 0xdead7fffu, 0x38543656u, 0x00fa0038u, 0xbeef00efu, 0x0000beefu, 0x00003307u, 0x3c003c00u},
{0xdead30a5u, 0xdead34a9u, 0xdead2f30u, 0xdead3330u, 0xdead6f30u, 0xdead6f30u, 0xdead0025u, 0xdead0000u, 0xdeadffffu, 0xdead7fffu, 0x389530a5u, 0x006800aeu, 0xbeef00c4u, 0x0000beefu, 0x00003975u, 0x3c003c00u},
{0xdead2cc5u, 0xdead30cau, 0xdead2f89u, 0xdead3389u, 0xdead6f89u, 0xdead6f89u, 0xdead0013u, 0xdead7bffu, 0xdeadffffu, 0xdead7fffu, 0x3bb82cc5u, 0x004d00edu, 0xbeef00a9u, 0x7bffbeefu, 0x00003b6fu, 0x3c003c00u},
{0xdead3b57u, 0xdeadb18bu, 0xdead3269u, 0xdead3669u, 0xdead7269u, 0xdead7269u, 0xdeadffeau, 0xdead8000u, 0xdeadffffu, 0xdead8000u, 0x38a53b57u, 0x0028004du, 0xbeef00eau, 0x8000beefu, 0x000034d5u, 0x3c003c00u},
{0xdead3747u, 0xdead3b4fu, 0xdead2b53u, 0xdead2f53u, 0xdead6b53u, 0xdead6b53u, 0xdead0074u, 0xdead7f89u, 0xdeadffffu, 0xdead7fffu, 0x38243747u, 0x004a00efu, 0xbeef0096u, 0x7f89beefu, 0x00003b7fu, 0x3c003c00u},
{0xdead3affu, 0xdeadb428u, 0xdead2d24u, 0xdead3124u, 0xdead6d24u, 0xdead6d24u, 0xdeadffdfu, 0xdead7bffu, 0xdeadffffu, 0xdead7fffu, 0x3a973affu, 0x00af001cu, 0xbeef0035u, 0x7bffbeefu, 0x00002f07u, 0x3c003c00u},
{0xdead3996u, 0xdeadb8eau, 0xdead3b0fu, 0xdeadb38au, 0xdead7b0fu, 0xdeadef8au, 0xdeadffb2u, 0xdeadfbffu, 0xdeadffffu, 0xdead8000u, 0x39353996u, 0x00a500b2u, 0xbeef00e5u, 0xfbffbeefu, 0x00003996u, 0x3c003c00u},
{0xdead33e8u, 0xdead37f0u, 0xdead3a95u, 0xdeadb5abu, 0xdead7a95u, 0xdeadf1abu, 0xdead003fu, 0xdeadfbffu, 0xdeadffffu, 0xdead8000u, 0x3b6733e8u, 0x000200fcu, 0xbeef0033u, 0xfbffbeefu, 0x00003be8u, 0x3c003c00u},
{0xdead393du, 0xdeadb99bu, 0xdead3916u, 0xdeadb9d4u, 0xdead7916u, 0xdeadf5d4u, 0xdeadffa7u, 0xdead7bffu, 0xdeadffffu, 0xdead7fffu, 0x3a66393du, 0x00620066u, 0xbeef00cbu, 0x7bffbeefu, 0x00003666u, 0x3c003c00u},
{0xdead37a8u, 0xdead3bafu, 0xdead3a93u, 0xdeadb5b5u, 0xdead7a93u, 0xdeadf1b5u, 0xdead007au, 0xdead7bffu, 0xdeadffffu, 0xdead7fffu, 0x368737a8u, 0x002a00c0u, 0xbeef00fau, 0x7bffbeefu, 0x00003a06u, 0x3c003c00u},
{0xdead34f5u, 0xdead38fau, 0xdead2e4cu, 0xdead324cu, 0xdead6e4cu, 0xdead6e4cu, 0xdead004fu, 0xdeade15bu, 0xdeadffffu, 0xdead8000u, 0x2dc634f5u, 0x009a0011u, 0xbeef0080u, 0xe15bbeefu, 0x00002c44u, 0x3c003c00u},
{0xdead3b27u, 0xdeadb30eu, 0xdead38e6u, 0xdeadba35u, 0xdead78e6u, 0xdeadf635u, 0xdeadffe4u, 0xdeadfbffu, 0xdeadffffu, 0xdead8000u, 0x3be03b27u, 0x008d001au, 0xbeef00f2u, 0xfbffbeefu, 0x00002e87u, 0x3c003c00u},
{0xdead3955u, 0xdeadb96bu, 0xdead3b78u, 0xdeadb03fu, 0xdead7b78u, 0xdeadec3fu, 0xdeadffaau, 0xdeadfbffu, 0xdeadffffu, 0xdead8000u, 0x38543955u, 0x004b0015u, 0xbeef00e9u, 0xfbffbeefu, 0x00002d45u, 0x3c003c00u},
};
constexpr const char* Names[16] = {"8unorm", "8snorm", "16unorm", "16snorm", "16uscaled", "16sscaled", "8sint", "32float", "32uint", "32sint", "xy_8_8unorm", "xyz_lo", "xyz_hi", "hi_x_32float", "xyzw_lo", "xyzw_hi"};

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("format d16: 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 index = 0; index < 16; ++index) Expect(tid, out[index], Expected[tid][index], Names[index]);
}
}

}

int main() {
try {
const auto device = OpenVulkanTestDevice();
if (!device) return VulkanTestSkipped;
Run(*device);
Check();
std::puts("format d16 tests passed");
return 0;
} catch (const std::exception& error) {
std::cerr << error.what() << '\n';
return 1;
}
}
Loading
Loading