Merge pull request #504 from adriadam10/feat/vop3-opsel-16

fix(shader): VOP3 op_sel on v_alignbit/alignbyte_b32 and 16-bit max3/min3/med3
This commit is contained in:
Dean
2026-10-05 21:32:13 +13:00
committed by GitHub
4 changed files with 409 additions and 8 deletions
@@ -0,0 +1,190 @@
#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, 62> Code{
0x34020084, 0x34060086, 0xe0381000, 0x80000401, 0xbf8c3f70, 0x7e140307, 0xd54e000a, 0x041a0b04,
0x7e160307, 0xd54e080b, 0x041a0b04, 0x7e180307, 0xd54e100c, 0x041a0b04, 0x7e1a0307, 0xd54e180d,
0x041a0b04, 0x7e1c0307, 0xd54e200e, 0x041a0b04, 0x7e1e0307, 0xd54e400f, 0x041a0b04, 0x7e200307,
0xd54e4810, 0x041a0b04, 0x7e220307, 0xd54e7811, 0x041a0b04, 0x7e240307, 0xd54f0012, 0x041a0b04,
0x7e260307, 0xd54f0813, 0x041a0b04, 0x7e280307, 0xd54f1014, 0x041a0b04, 0x7e2a0307, 0xd54f1815,
0x041a0b04, 0x7e2c0307, 0xd54f2016, 0x041a0b04, 0x7e2e0307, 0xd54f4017, 0x041a0b04, 0x7e300307,
0xd54f5018, 0x041a0b04, 0x7e320307, 0xd54f7819, 0x041a0b04, 0xe0781000, 0x80010a03, 0xe0781010,
0x80010e03, 0xe0781020, 0x80011203, 0xe0781030, 0x80011603, 0xbf810000,
};
constexpr std::uint32_t Rows[32][4] = {
{0xc0001234u, 0x73ab4876u, 0x04082408u, 0x7253edc6u},
{0x05b4d756u, 0xedccc000u, 0x1f210011u, 0x24aa1734u},
{0x8000fffeu, 0xad0ee1e7u, 0x00ffffffu, 0x80018000u},
{0xdc8cf93au, 0xe3653b50u, 0x21030300u, 0xffff0002u},
{0x400000ffu, 0xfffe4000u, 0xff001101u, 0x80018000u},
{0xf8800b51u, 0xfffe4000u, 0x20018024u, 0x7ffffffeu},
{0x80017fffu, 0x8000edccu, 0x031f0180u, 0xb63f2c62u},
{0xc0001234u, 0x80010002u, 0x01203f03u, 0x0001fffeu},
{0x89e7d15fu, 0x986e86cbu, 0x01010300u, 0x30b17d0bu},
{0x8001fffeu, 0x97491e23u, 0x0300241fu, 0x800000ffu},
{0x00011234u, 0x7fffc000u, 0x3f040300u, 0x1b98fbe4u},
{0xf542441du, 0x00007fffu, 0x03803f3fu, 0x7fff00ffu},
{0x80000001u, 0x03e0d681u, 0x00041007u, 0xc000fffeu},
{0x2d7c5048u, 0x728a6fcfu, 0x3f043f80u, 0x00007fffu},
{0xedccc000u, 0xff769e37u, 0x0701043fu, 0x36971e1bu},
{0x8001edccu, 0x62dc08d6u, 0x2100100fu, 0x5f27ff08u},
{0xf589d99au, 0xddd4a054u, 0x0f10101fu, 0x2891dd3cu},
{0xafdd8733u, 0x6be49ee7u, 0x3f101101u, 0xedccffffu},
{0x4b1e943eu, 0x205bc308u, 0x000f0f11u, 0xffff8000u},
{0x3fc2a908u, 0x482ea760u, 0xff072103u, 0xfb019df4u},
{0x00000000u, 0x40008001u, 0x24030001u, 0x80004000u},
{0x00010001u, 0x8bcce7cdu, 0x03212007u, 0x0001fffeu},
{0x0000c000u, 0xedcc0000u, 0x0303003fu, 0x000100ffu},
{0x4000ffffu, 0x40004000u, 0x0003ffffu, 0x0001edccu},
{0xc0000002u, 0xa8f51ac5u, 0x0f113f20u, 0xa2592b9du},
{0xe1594dc4u, 0x95468325u, 0x01212407u, 0xb6125e0cu},
{0xfffefffeu, 0xffff7fffu, 0x20ff2024u, 0x131e2d48u},
{0x80004000u, 0x4f1c9ce2u, 0x0fff3f07u, 0x065479e4u},
{0xc77d357fu, 0x000100ffu, 0x0f032104u, 0x33080a1du},
{0xc0000000u, 0x88ebd524u, 0x08211110u, 0x64bd7a63u},
{0x4000ffffu, 0x2141c6d1u, 0xff203f00u, 0x53935c55u},
{0xb8d0c65du, 0x369a9ad7u, 0x0011201fu, 0x5937c1f0u}
};
constexpr std::uint32_t Expected[32][16] = {
{0x3473ab48u, 0x473ab487u, 0x3473ab48u, 0x473ab487u, 0x3473ab48u, 0xab480000u, 0xb4870000u, 0xb4870000u, 0x73ab4876u, 0x73ab4876u, 0x73ab4876u, 0x73ab4876u, 0x73ab4876u, 0x48760000u, 0x48760000u, 0x48760000u},
{0x6bab76e6u, 0xedccc000u, 0x76e66000u, 0x0b69aeadu, 0x6bab76e6u, 0x76e60000u, 0xc0000000u, 0xaead0000u, 0x56edccc0u, 0xedccc000u, 0x56edccc0u, 0xb4d756edu, 0x56edccc0u, 0xccc00000u, 0xccc00000u, 0x56ed0000u},
{0x0001fffdu, 0x0001fffdu, 0x0001fffdu, 0xad0ee1e7u, 0x0001fffdu, 0xfffd0000u, 0xfffd0000u, 0xe1e70000u, 0x00fffeadu, 0x00fffeadu, 0x00fffeadu, 0xad0ee1e7u, 0x00fffeadu, 0xfead0000u, 0xfead0000u, 0xe1e70000u},
{0xe3653b50u, 0x5c6ca76au, 0x5c6ca76au, 0x71b29da8u, 0xe3653b50u, 0x3b500000u, 0xa76a0000u, 0x9da80000u, 0xe3653b50u, 0x8cf93ae3u, 0x8cf93ae3u, 0x3ae3653bu, 0xe3653b50u, 0x3b500000u, 0x3ae30000u, 0x653b0000u},
{0xffff2000u, 0x007fffffu, 0xfffe4000u, 0x800001ffu, 0xffff2000u, 0x20000000u, 0xffff0000u, 0x01ff0000u, 0xfffffe40u, 0xfffffe40u, 0xfffe4000u, 0x0000ffffu, 0xfffffe40u, 0xfe400000u, 0x40000000u, 0xffff0000u},
{0x1fffe400u, 0xfffe4000u, 0xffff2000u, 0xfffe4000u, 0x1fffe400u, 0xe4000000u, 0x40000000u, 0x40000000u, 0xfffe4000u, 0xfffe4000u, 0x51fffe40u, 0xfffe4000u, 0xfffe4000u, 0x40000000u, 0xfe400000u, 0x40000000u},
{0x8000edccu, 0xc00076e6u, 0x0002ffffu, 0xf0001db9u, 0x8000edccu, 0xedcc0000u, 0x76e60000u, 0x1db90000u, 0x8000edccu, 0xff8000edu, 0x017fff80u, 0x017fff80u, 0x8000edccu, 0xedcc0000u, 0xff800000u, 0xff800000u},
{0x90002000u, 0x80002469u, 0x80010002u, 0x40008001u, 0x90002000u, 0x20000000u, 0x24690000u, 0x80010000u, 0x00123480u, 0x00123480u, 0x80010002u, 0x34800100u, 0x00123480u, 0x34800000u, 0x00020000u, 0x01000000u},
{0x986e86cbu, 0xf30dd0d9u, 0xcc374365u, 0xcc374365u, 0x986e86cbu, 0x86cb0000u, 0xd0d90000u, 0x43650000u, 0x986e86cbu, 0xe7d15f98u, 0x5f986e86u, 0x5f986e86u, 0x986e86cbu, 0x86cb0000u, 0x6e860000u, 0x6e860000u},
{0x0003fffdu, 0xe97491e2u, 0x97491e23u, 0xd2e923c4u, 0x0003fffdu, 0xfffd0000u, 0x91e20000u, 0x23c40000u, 0x01fffe97u, 0x97491e23u, 0x97491e23u, 0x01fffe97u, 0x01fffe97u, 0xfe970000u, 0x1e230000u, 0xfe970000u},
{0x7fffc000u, 0x8ffff800u, 0x47fffc00u, 0x00022468u, 0x7fffc000u, 0xc0000000u, 0xf8000000u, 0x24680000u, 0x7fffc000u, 0x0112347fu, 0x7fffc000u, 0x0112347fu, 0x7fffc000u, 0xc0000000u, 0xc0000000u, 0x347f0000u},
{0xea84883au, 0xea84883au, 0x00007fffu, 0xa0000fffu, 0xea84883au, 0x883a0000u, 0x883a0000u, 0x0fff0000u, 0x42441d00u, 0x42441d00u, 0x00007fffu, 0x42441d00u, 0x42441d00u, 0x1d000000u, 0x7fff0000u, 0x1d000000u},
{0x0207c1adu, 0x000103e0u, 0x103e0d68u, 0x03e0d681u, 0x0207c1adu, 0xc1ad0000u, 0x03e00000u, 0xd6810000u, 0x00000103u, 0x03e0d681u, 0x03e0d681u, 0x03e0d681u, 0x00000103u, 0x01030000u, 0xd6810000u, 0xd6810000u},
{0x728a6fcfu, 0x5af8a090u, 0x8728a6fcu, 0x5af8a090u, 0x728a6fcfu, 0x6fcf0000u, 0xa0900000u, 0xa0900000u, 0x728a6fcfu, 0x7c504872u, 0x728a6fcfu, 0x7c504872u, 0x728a6fcfu, 0x6fcf0000u, 0x6fcf0000u, 0x48720000u},
{0xdb998001u, 0x0ff769e3u, 0x7fbb4f1bu, 0x01feed3cu, 0xdb998001u, 0x80010000u, 0x69e30000u, 0xed3c0000u, 0xccc000ffu, 0xff769e37u, 0x00ff769eu, 0xccc000ffu, 0xccc000ffu, 0x00ff0000u, 0x769e0000u, 0x00ff0000u},
{0xdb98c5b8u, 0xedcc62dcu, 0x62dc08d6u, 0x316e046bu, 0xdb98c5b8u, 0xc5b80000u, 0x62dc0000u, 0x046b0000u, 0x01edcc62u, 0x62dc08d6u, 0x62dc08d6u, 0xcc62dc08u, 0x01edcc62u, 0xcc620000u, 0x08d60000u, 0xdc080000u},
{0xeb13b335u, 0xd99addd4u, 0xd99addd4u, 0xb335bba9u, 0xeb13b335u, 0xb3350000u, 0xddd40000u, 0xbba90000u, 0x89d99addu, 0xddd4a054u, 0xddd4a054u, 0x89d99addu, 0x89d99addu, 0x9add0000u, 0xa0540000u, 0x9add0000u},
{0xb5f24f73u, 0xc399b5f2u, 0x87336be4u, 0x5fbb0e66u, 0xb5f24f73u, 0x4f730000u, 0xb5f20000u, 0x0e660000u, 0x336be49eu, 0x336be49eu, 0x6be49ee7u, 0xdd87336bu, 0x336be49eu, 0xe49e0000u, 0x9ee70000u, 0x336b0000u},
{0x4a1f102du, 0x287c40b7u, 0x287c40b7u, 0x205bc308u, 0x4a1f102du, 0x102d0000u, 0x40b70000u, 0xc3080000u, 0x3e205bc3u, 0x1e943e20u, 0x1e943e20u, 0x205bc308u, 0x3e205bc3u, 0x5bc30000u, 0x3e200000u, 0xc3080000u},
{0x0905d4ecu, 0x241753b0u, 0x10905d4eu, 0x7f855210u, 0x0905d4ecu, 0xd4ec0000u, 0x53b00000u, 0x52100000u, 0xc2a90848u, 0x08482ea7u, 0xc2a90848u, 0xc2a90848u, 0xc2a90848u, 0x08480000u, 0x08480000u, 0x08480000u},
{0x20004000u, 0x40008001u, 0x08001000u, 0x04000800u, 0x20004000u, 0x40000000u, 0x80010000u, 0x08000000u, 0x00400080u, 0x40008001u, 0x00000040u, 0x40008001u, 0x00400080u, 0x00800000u, 0x00400000u, 0x80010000u},
{0x031799cfu, 0x8bcce7cdu, 0xc5e673e6u, 0x31799cf9u, 0x031799cfu, 0x99cf0000u, 0xe7cd0000u, 0x9cf90000u, 0x0100018bu, 0x8bcce7cdu, 0x018bcce7u, 0x0100018bu, 0x0100018bu, 0x018b0000u, 0xcce70000u, 0x018b0000u},
{0x00018001u, 0xedcc0000u, 0x1db98000u, 0x1db98000u, 0x00018001u, 0x80010000u, 0x00000000u, 0x80000000u, 0x00c000edu, 0xedcc0000u, 0x00c000edu, 0x00c000edu, 0x00c000edu, 0x00ed0000u, 0x00ed0000u, 0x00ed0000u},
{0x8001fffeu, 0x8001fffeu, 0xe8000800u, 0x40004000u, 0x8001fffeu, 0xfffe0000u, 0xfffe0000u, 0x40000000u, 0x00ffff40u, 0x00ffff40u, 0x00ffff40u, 0x40004000u, 0x00ffff40u, 0xff400000u, 0xff400000u, 0x40000000u},
{0xa8f51ac5u, 0x80000005u, 0x0001547au, 0x000551eau, 0xa8f51ac5u, 0x1ac50000u, 0x00050000u, 0x51ea0000u, 0xa8f51ac5u, 0x000002a8u, 0x02a8f51au, 0x000002a8u, 0xa8f51ac5u, 0x1ac50000u, 0xf51a0000u, 0x02a80000u},
{0x892a8d06u, 0x49546832u, 0x4aa34192u, 0x4aa34192u, 0x892a8d06u, 0x8d060000u, 0x68320000u, 0x41920000u, 0x594dc495u, 0x95468325u, 0xc4954683u, 0xc4954683u, 0x594dc495u, 0xc4950000u, 0x46830000u, 0x46830000u},
{0xeffff7ffu, 0xffff7fffu, 0xfffdfffdu, 0xffff7fffu, 0xeffff7ffu, 0xf7ff0000u, 0x7fff0000u, 0x7fff0000u, 0xffff7fffu, 0xffff7fffu, 0xfefffeffu, 0xffff7fffu, 0xffff7fffu, 0x7fff0000u, 0xfeff0000u, 0x7fff0000u},
{0x009e3939u, 0x00008000u, 0x00008000u, 0x80009e39u, 0x009e3939u, 0x39390000u, 0x80000000u, 0x9e390000u, 0x0040004fu, 0x0040004fu, 0x0040004fu, 0x0040004fu, 0x0040004fu, 0x004f0000u, 0x004f0000u, 0x004f0000u},
{0xf000100fu, 0x8000807fu, 0xe000201fu, 0x6afe0002u, 0xf000100fu, 0x100f0000u, 0x807f0000u, 0x00020000u, 0x000100ffu, 0x7f000100u, 0x7d357f00u, 0x7d357f00u, 0x000100ffu, 0x00ff0000u, 0x7f000000u, 0x7f000000u},
{0x000088ebu, 0x00004475u, 0x4475ea92u, 0x0088ebd5u, 0x000088ebu, 0x88eb0000u, 0x44750000u, 0xebd50000u, 0x88ebd524u, 0x0088ebd5u, 0x0088ebd5u, 0x88ebd524u, 0x88ebd524u, 0xd5240000u, 0xebd50000u, 0xd5240000u},
{0x2141c6d1u, 0x8001fffeu, 0x2141c6d1u, 0x8001fffeu, 0x2141c6d1u, 0xc6d10000u, 0xfffe0000u, 0xfffe0000u, 0x2141c6d1u, 0x00ffff21u, 0x2141c6d1u, 0x00ffff21u, 0x2141c6d1u, 0xc6d10000u, 0xc6d10000u, 0xff210000u},
{0x71a18cbau, 0x369a9ad7u, 0x632e9b4du, 0x369a9ad7u, 0x71a18cbau, 0x8cba0000u, 0x9ad70000u, 0x9ad70000u, 0xd0c65d36u, 0x369a9ad7u, 0x5d369a9au, 0x369a9ad7u, 0xd0c65d36u, 0x5d360000u, 0x9a9a0000u, 0x9ad70000u}
};
constexpr const char* Names[16] = {
"v_alignbit_b32 v10, v4, v5, v6 op_sel:[0,0,0,0]",
"v_alignbit_b32 v11, v4, v5, v6 op_sel:[1,0,0,0]",
"v_alignbit_b32 v12, v4, v5, v6 op_sel:[0,1,0,0]",
"v_alignbit_b32 v13, v4, v5, v6 op_sel:[1,1,0,0]",
"v_alignbit_b32 v14, v4, v5, v6 op_sel:[0,0,1,0]",
"v_alignbit_b32 v15, v4, v5, v6 op_sel:[0,0,0,1]",
"v_alignbit_b32 v16, v4, v5, v6 op_sel:[1,0,0,1]",
"v_alignbit_b32 v17, v4, v5, v6 op_sel:[1,1,1,1]",
"v_alignbyte_b32 v18, v4, v5, v6 op_sel:[0,0,0,0]",
"v_alignbyte_b32 v19, v4, v5, v6 op_sel:[1,0,0,0]",
"v_alignbyte_b32 v20, v4, v5, v6 op_sel:[0,1,0,0]",
"v_alignbyte_b32 v21, v4, v5, v6 op_sel:[1,1,0,0]",
"v_alignbyte_b32 v22, v4, v5, v6 op_sel:[0,0,1,0]",
"v_alignbyte_b32 v23, v4, v5, v6 op_sel:[0,0,0,1]",
"v_alignbyte_b32 v24, v4, v5, v6 op_sel:[0,1,0,1]",
"v_alignbyte_b32 v25, v4, v5, v6 op_sel:[1,1,1,1]",
};
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("vop3 align op sel: 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 < 16; ++i) {
Expect(tid, out[i], Expected[tid][i], Names[i]);
}
}
}
}
int main() {
try {
const auto device = OpenVulkanTestDevice();
if (!device) return VulkanTestSkipped;
Run(*device);
Check();
std::puts("vop3 align op sel tests passed");
return 0;
} catch (const std::exception& error) {
std::cerr << error.what() << '\n';
return 1;
}
}
@@ -0,0 +1,190 @@
#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, 62> Code{
0x34020084, 0x34060086, 0xe0381000, 0x80000401, 0xbf8c3f70, 0x7e140307, 0xd755280a, 0x041a0b04,
0x7e160307, 0xd756500b, 0x041a0b04, 0x7e180307, 0xd752180c, 0x041a0b04, 0x7e1a0307, 0xd753600d,
0x041a0b04, 0x7e1c0307, 0xd759380e, 0x041a0b04, 0x7e1e0307, 0xd759000f, 0x041a0b04, 0x7e200307,
0xd7564810, 0x041a0b04, 0x7e220307, 0xd7527011, 0x041a0b04, 0x7e240307, 0xd7583012, 0x041a0b04,
0x7e260307, 0xd7554013, 0x041a0b04, 0x7e280307, 0xd7530814, 0x041a0b04, 0x7e2a0307, 0xd7595815,
0x041a0b04, 0x7e2c0307, 0xd7560016, 0x041a0b04, 0x7e2e0307, 0xd7520017, 0x041a0b04, 0x7e300307,
0xd7551018, 0x041a0b04, 0x7e320307, 0xd7596019, 0x041a0b04, 0xe0781000, 0x80010a03, 0xe0781010,
0x80010e03, 0xe0781020, 0x80011203, 0xe0781030, 0x80011603, 0xbf810000,
};
constexpr std::uint32_t Rows[32][4] = {
{0x4000fffeu, 0x1eede1dcu, 0xc1dc7ed2u, 0xffff7fffu},
{0xedccc000u, 0x00ff00ffu, 0x123400ffu, 0x00020002u},
{0x9fe407c8u, 0x40004000u, 0x40000001u, 0xedccffffu},
{0x00ff00ffu, 0x00ff00ffu, 0x80018001u, 0x12340001u},
{0xffff00ffu, 0x24f75609u, 0x0000edccu, 0xa1ae691du},
{0x40000000u, 0x75916032u, 0x00f77715u, 0x9e9c8053u},
{0x78bd5cc4u, 0x80010000u, 0x000000ffu, 0xc000edccu},
{0x123400ffu, 0x00011234u, 0x400000ffu, 0x4000c000u},
{0x00011234u, 0x7fff1234u, 0x12341234u, 0x00fffffeu},
{0x1234c000u, 0xc0000001u, 0x00021234u, 0x5eda0014u},
{0x12347fffu, 0x40e8d5edu, 0x00ff0002u, 0x67604bebu},
{0x00028001u, 0x00ff8001u, 0x00ff00ffu, 0x9b20386du},
{0x2027553bu, 0x12341234u, 0x7fff1234u, 0xffffffffu},
{0x00001234u, 0x12340000u, 0x024e6fa2u, 0x80252ce1u},
{0x49ff7159u, 0xffff8000u, 0xffff8000u, 0x80010002u},
{0xc0007fffu, 0x0000c000u, 0x00004000u, 0x80010001u},
{0x00ff0000u, 0x7fff0000u, 0x7cfc2ed5u, 0x8001edccu},
{0xc0007fffu, 0xedcc7fffu, 0x00021234u, 0xffff00ffu},
{0x00021234u, 0x0002edccu, 0x00000001u, 0x9138a73cu},
{0x3e2f6da7u, 0x00d72a89u, 0x0f50aef1u, 0x13022bdcu},
{0x00ff8000u, 0xfcbf3c4bu, 0x8001c000u, 0x5df76ae5u},
{0x00008001u, 0x8001edccu, 0x0001edccu, 0x5dd86332u},
{0xdf891833u, 0xbe5937f8u, 0xfffe1234u, 0x542edc5fu},
{0x0d9f3670u, 0x55502ea4u, 0x0002fffeu, 0xbcda0e3bu},
{0x00020001u, 0x7e9868d8u, 0xc67c9920u, 0xf336da84u},
{0xc000edccu, 0xfffe00ffu, 0x62aa0f64u, 0x80011234u},
{0x80001234u, 0x401b25b8u, 0x3b404f9du, 0x9ec28382u},
{0x0001ffffu, 0xdd91f71cu, 0xf13510b5u, 0x00020000u},
{0x40004000u, 0x7fff8001u, 0x22c35d87u, 0xc0000000u},
{0x2a18f40fu, 0x6bbd2914u, 0xc000fffeu, 0xedcc0002u},
{0xa7f488d4u, 0x00ff4000u, 0x000100ffu, 0xedccfffeu},
{0xfffefffeu, 0x7fff00ffu, 0x0002fffeu, 0xd816b1beu}
};
constexpr std::uint32_t Expected[32][16] = {
{0xffff4000u, 0xfffe7fffu, 0xffff1eedu, 0xc1dc7fffu, 0xffff4000u, 0xffffe1dcu, 0xe1dc7fffu, 0xc1dc7fffu, 0xfffffffeu, 0x7ed27fffu, 0xffff4000u, 0x40007fffu, 0xfffffffeu, 0xffffe1dcu, 0xffff7ed2u, 0xe1dc7fffu},
{0x00021234u, 0xc0000002u, 0x0002edccu, 0x00ff0002u, 0x00021234u, 0x000200ffu, 0xedcc0002u, 0xc0000002u, 0x000200ffu, 0x00ff0002u, 0x000200ffu, 0x00ff0002u, 0x0002c000u, 0x0002c000u, 0x000200ffu, 0x12340002u},
{0xedcc4000u, 0x4000ffffu, 0xedcc9fe4u, 0x07c8ffffu, 0xedcc4000u, 0xedcc07c8u, 0x9fe4ffffu, 0x07c8ffffu, 0xedcc4000u, 0x4000ffffu, 0xedcc0001u, 0x4000ffffu, 0xedcc4000u, 0xedcc0001u, 0xedcc4000u, 0x4000ffffu},
{0x123400ffu, 0x80010001u, 0x12348001u, 0x00ff0001u, 0x123400ffu, 0x123400ffu, 0x80010001u, 0x80010001u, 0x123400ffu, 0x00ff0001u, 0x123400ffu, 0x00ff0001u, 0x12348001u, 0x12348001u, 0x123400ffu, 0x00ff0001u},
{0xa1ae5609u, 0xedcc691du, 0xa1aeedccu, 0x0000691du, 0xa1ae24f7u, 0xa1ae5609u, 0xffff691du, 0x0000691du, 0xa1ae00ffu, 0x5609691du, 0xa1ae5609u, 0xedcc691du, 0xa1aeedccu, 0xa1aeedccu, 0xa1ae24f7u, 0x00ff691du},
{0x9e9c6032u, 0x77158053u, 0x9e9c4000u, 0x00008053u, 0x9e9c4000u, 0x9e9c6032u, 0x77158053u, 0x00008053u, 0x9e9c00f7u, 0x77158053u, 0x9e9c4000u, 0x75918053u, 0x9e9c7715u, 0x9e9c0000u, 0x9e9c7715u, 0x00f78053u},
{0xc00078bdu, 0x8001edccu, 0xc0008001u, 0x0000edccu, 0xc00078bdu, 0xc00000ffu, 0x78bdedccu, 0x8001edccu, 0xc0000000u, 0x5cc4edccu, 0xc0000000u, 0x78bdedccu, 0xc0005cc4u, 0xc0000000u, 0xc0005cc4u, 0x0000edccu},
{0x40004000u, 0x00ffc000u, 0x40000001u, 0x00ffc000u, 0x40001234u, 0x400000ffu, 0x1234c000u, 0x0001c000u, 0x400000ffu, 0x1234c000u, 0x400000ffu, 0x00ffc000u, 0x40001234u, 0x400000ffu, 0x400000ffu, 0x1234c000u},
{0x00ff1234u, 0x7ffffffeu, 0x00ff0001u, 0x1234fffeu, 0x00ff1234u, 0x00ff1234u, 0x1234fffeu, 0x1234fffeu, 0x00ff1234u, 0x1234fffeu, 0x00ff0001u, 0x1234fffeu, 0x00ff1234u, 0x00ff1234u, 0x00ff7fffu, 0x1234fffeu},
{0x5eda1234u, 0xc0000014u, 0x5edac000u, 0x00010014u, 0x5eda1234u, 0x5eda1234u, 0x12340014u, 0xc0000014u, 0x5edac000u, 0x12340014u, 0x5eda0001u, 0x12340014u, 0x5edac000u, 0x5edac000u, 0x5eda1234u, 0x00020014u},
{0x67601234u, 0x7fff4bebu, 0x67600002u, 0x00ff4bebu, 0x67601234u, 0x67607fffu, 0xd5ed4bebu, 0x00ff4bebu, 0x676040e8u, 0x7fff4bebu, 0x67600002u, 0x12344bebu, 0x6760d5edu, 0x6760d5edu, 0x67607fffu, 0x7fff4bebu},
{0x9b2000ffu, 0x8001386du, 0x9b200002u, 0x00ff386du, 0x9b2000ffu, 0x9b208001u, 0x8001386du, 0x8001386du, 0x9b2000ffu, 0x00ff386du, 0x9b200002u, 0x00ff386du, 0x9b208001u, 0x9b208001u, 0x9b2000ffu, 0x8001386du},
{0xffff7fffu, 0x553bffffu, 0xffff1234u, 0x1234ffffu, 0xffff2027u, 0xffff1234u, 0x2027ffffu, 0x1234ffffu, 0xffff553bu, 0x553bffffu, 0xffff1234u, 0x1234ffffu, 0xffff553bu, 0xffff1234u, 0xffff553bu, 0x553bffffu},
{0x8025024eu, 0x6fa22ce1u, 0x80250000u, 0x00002ce1u, 0x8025024eu, 0x80251234u, 0x6fa22ce1u, 0x024e2ce1u, 0x80251234u, 0x6fa22ce1u, 0x80250000u, 0x12342ce1u, 0x80256fa2u, 0x80250000u, 0x80256fa2u, 0x024e2ce1u},
{0x800149ffu, 0xffff0002u, 0x80018000u, 0x71590002u, 0x8001ffffu, 0x80018000u, 0x80000002u, 0xffff0002u, 0x8001ffffu, 0x71590002u, 0x800149ffu, 0x80000002u, 0x80018000u, 0x80018000u, 0x80017159u, 0x80000002u},
{0x80010000u, 0x7fff0001u, 0x8001c000u, 0x00000001u, 0x80010000u, 0x80017fffu, 0xc0000001u, 0x00000001u, 0x80010000u, 0x7fff0001u, 0x80014000u, 0x40000001u, 0x8001c000u, 0x8001c000u, 0x80017fffu, 0x7fff0001u},
{0x80017cfcu, 0x7fffedccu, 0x800100ffu, 0x0000edccu, 0x80017cfcu, 0x80010000u, 0x2ed5edccu, 0x0000edccu, 0x80017cfcu, 0x2ed5edccu, 0x80010000u, 0x2ed5edccu, 0x80012ed5u, 0x80010000u, 0x80017fffu, 0x0000edccu},
{0xffff7fffu, 0xedcc00ffu, 0xffffc000u, 0x000200ffu, 0xffffc000u, 0xffff7fffu, 0xc00000ffu, 0xedcc00ffu, 0xffff0002u, 0x7fff00ffu, 0xffff1234u, 0xc00000ffu, 0xffff7fffu, 0xffff1234u, 0xffff7fffu, 0x7fff00ffu},
{0x91380002u, 0x1234a73cu, 0x91380001u, 0x0000a73cu, 0x91380002u, 0x91381234u, 0xedcca73cu, 0x0000a73cu, 0x91380002u, 0x1234a73cu, 0x91380001u, 0x0002a73cu, 0x9138edccu, 0x9138edccu, 0x91381234u, 0x1234a73cu},
{0x13023e2fu, 0xaef12bdcu, 0x1302aef1u, 0x0f502bdcu, 0x13020f50u, 0x13026da7u, 0xaef12bdcu, 0x00d72bdcu, 0x13020f50u, 0x6da72bdcu, 0x13022a89u, 0x3e2f2bdcu, 0x1302aef1u, 0x1302aef1u, 0x13026da7u, 0x2a892bdcu},
{0x5df73c4bu, 0xfcbf6ae5u, 0x5df7c000u, 0x3c4b6ae5u, 0x5df78001u, 0x5df78000u, 0xc0006ae5u, 0x80006ae5u, 0x5df78001u, 0x3c4b6ae5u, 0x5df700ffu, 0xc0006ae5u, 0x5df7c000u, 0x5df78000u, 0x5df7fcbfu, 0x80006ae5u},
{0x5dd80001u, 0xedcc6332u, 0x5dd88001u, 0x00016332u, 0x5dd80001u, 0x5dd8edccu, 0xedcc6332u, 0x80016332u, 0x5dd88001u, 0xedcc6332u, 0x5dd80000u, 0x80016332u, 0x5dd8edccu, 0x5dd88001u, 0x5dd8edccu, 0x80016332u},
{0x542e37f8u, 0xbe59dc5fu, 0x542ebe59u, 0x1833dc5fu, 0x542edf89u, 0x542e1833u, 0xdf89dc5fu, 0xbe59dc5fu, 0x542efffeu, 0x37f8dc5fu, 0x542e1234u, 0xbe59dc5fu, 0x542e37f8u, 0x542e1234u, 0x542e1833u, 0x37f8dc5fu},
{0xbcda2ea4u, 0xfffe0e3bu, 0xbcdafffeu, 0x00020e3bu, 0xbcda0d9fu, 0xbcda3670u, 0xfffe0e3bu, 0x00020e3bu, 0xbcda3670u, 0x36700e3bu, 0xbcda0d9fu, 0x55500e3bu, 0xbcdafffeu, 0xbcdafffeu, 0xbcda5550u, 0x2ea40e3bu},
{0xf33668d8u, 0x9920da84u, 0xf3369920u, 0x0001da84u, 0xf3367e98u, 0xf33668d8u, 0x9920da84u, 0xc67cda84u, 0xf3360001u, 0x68d8da84u, 0xf3360002u, 0x7e98da84u, 0xf3369920u, 0xf3369920u, 0xf3367e98u, 0x68d8da84u},
{0x800162aau, 0xfffe1234u, 0x8001c000u, 0x00ff1234u, 0x8001c000u, 0x80010f64u, 0xc0001234u, 0xedcc1234u, 0x8001fffeu, 0x0f641234u, 0x800100ffu, 0xc0001234u, 0x8001edccu, 0x8001edccu, 0x80010f64u, 0x62aa1234u},
{0x9ec23b40u, 0x4f9d8382u, 0x9ec28000u, 0x12348382u, 0x9ec2401bu, 0x9ec225b8u, 0x80008382u, 0x12348382u, 0x9ec23b40u, 0x4f9d8382u, 0x9ec225b8u, 0x4f9d8382u, 0x9ec24f9du, 0x9ec21234u, 0x9ec24f9du, 0x25b88382u},
{0x00020001u, 0xffff0000u, 0x0002dd91u, 0xf1350000u, 0x0002dd91u, 0x0002f71cu, 0xf71c0000u, 0xdd910000u, 0x0002f135u, 0x10b50000u, 0x00020001u, 0x10b50000u, 0x0002ffffu, 0x0002f71cu, 0x000210b5u, 0xf71c0000u},
{0xc0004000u, 0x7fff0000u, 0xc0004000u, 0x22c30000u, 0xc0004000u, 0xc0005d87u, 0x80010000u, 0x22c30000u, 0xc0004000u, 0x5d870000u, 0xc0004000u, 0x5d870000u, 0xc0008001u, 0xc0008001u, 0xc0007fffu, 0x40000000u},
{0xedcc2a18u, 0xfffe0002u, 0xedccfffeu, 0x29140002u, 0xedcc6bbdu, 0xedccf40fu, 0xfffe0002u, 0xc0000002u, 0xedccf40fu, 0x29140002u, 0xedcc2914u, 0x6bbd0002u, 0xedccfffeu, 0xedccf40fu, 0xedcc6bbdu, 0xc0000002u},
{0xedcc4000u, 0x88d4fffeu, 0xedcca7f4u, 0x0001fffeu, 0xedcc00ffu, 0xedcc4000u, 0xa7f4fffeu, 0x88d4fffeu, 0xedcc0001u, 0x4000fffeu, 0xedcc00ffu, 0x00fffffeu, 0xedcc88d4u, 0xedcc88d4u, 0xedcc00ffu, 0x4000fffeu},
{0xd81600ffu, 0xfffeb1beu, 0xd816fffeu, 0x0002b1beu, 0xd8167fffu, 0xd816fffeu, 0xfffeb1beu, 0xfffeb1beu, 0xd8160002u, 0x00ffb1beu, 0xd81600ffu, 0xfffeb1beu, 0xd816fffeu, 0xd816fffeu, 0xd8167fffu, 0x00ffb1beu}
};
constexpr const char* Names[16] = {
"v_max3_i16 v10, v4, v5, v6 op_sel:[1,0,1,0]",
"v_max3_u16 v11, v4, v5, v6 op_sel:[0,1,0,1]",
"v_min3_i16 v12, v4, v5, v6 op_sel:[1,1,0,0]",
"v_min3_u16 v13, v4, v5, v6 op_sel:[0,0,1,1]",
"v_med3_u16 v14, v4, v5, v6 op_sel:[1,1,1,0]",
"v_med3_u16 v15, v4, v5, v6 op_sel:[0,0,0,0]",
"v_max3_u16 v16, v4, v5, v6 op_sel:[1,0,0,1]",
"v_min3_i16 v17, v4, v5, v6 op_sel:[0,1,1,1]",
"v_med3_i16 v18, v4, v5, v6 op_sel:[0,1,1,0]",
"v_max3_i16 v19, v4, v5, v6 op_sel:[0,0,0,1]",
"v_min3_u16 v20, v4, v5, v6 op_sel:[1,0,0,0]",
"v_med3_u16 v21, v4, v5, v6 op_sel:[1,1,0,1]",
"v_max3_u16 v22, v4, v5, v6 op_sel:[0,0,0,0]",
"v_min3_i16 v23, v4, v5, v6 op_sel:[0,0,0,0]",
"v_max3_i16 v24, v4, v5, v6 op_sel:[0,1,0,0]",
"v_med3_u16 v25, v4, v5, v6 op_sel:[0,0,1,1]",
};
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("vop3 integer16 ternary op sel: 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 < 16; ++i) {
Expect(tid, out[i], Expected[tid][i], Names[i]);
}
}
}
}
int main() {
try {
const auto device = OpenVulkanTestDevice();
if (!device) return VulkanTestSkipped;
Run(*device);
Check();
std::puts("vop3 integer16 ternary op sel tests passed");
return 0;
} catch (const std::exception& error) {
std::cerr << error.what() << '\n';
return 1;
}
}
@@ -747,8 +747,14 @@ bool isNativeVop3F16TernaryOpcode(RdnaOpcode opcode) {
}
bool isNativeVop3I16TernaryOpcode(RdnaOpcode opcode) {
return opcode == RdnaOpcode::VMed3I16 || opcode == RdnaOpcode::VMadU16 || opcode == RdnaOpcode::VMadI16 ||
opcode == RdnaOpcode::VMadU32U16 || opcode == RdnaOpcode::VMadI32I16;
return opcode == RdnaOpcode::VMed3I16 || opcode == RdnaOpcode::VMed3U16 || opcode == RdnaOpcode::VMax3I16 ||
opcode == RdnaOpcode::VMax3U16 || opcode == RdnaOpcode::VMin3I16 || opcode == RdnaOpcode::VMin3U16 ||
opcode == RdnaOpcode::VMadU16 || opcode == RdnaOpcode::VMadI16 || opcode == RdnaOpcode::VMadU32U16 ||
opcode == RdnaOpcode::VMadI32I16;
}
bool isNativeVop3AlignOpcode(RdnaOpcode opcode) {
return opcode == RdnaOpcode::VAlignbitB32 || opcode == RdnaOpcode::VAlignbyteB32;
}
bool usesSignedSaturateClamp(RdnaOpcode opcode) {
@@ -1811,6 +1817,16 @@ void applyNativeVop3I16TernarySelectors(RdnaInstruction& instruction, std::uint3
}
}
void applyNativeVop3AlignSelectors(RdnaInstruction& instruction, std::uint32_t opSel) {
if ((opSel & 0x3u) != 0u) {
instruction.source2.sdwaSel = opSel & 0x3u;
}
if ((opSel & 0x8u) != 0u) {
instruction.destination.sdwaSel = 5u;
instruction.destination.sdwaDstUnused = 0u;
}
}
void applyNativeVop3B16BinaryModifiers(RdnaInstruction& instruction, std::uint32_t opSel) {
instruction.source0.opSel = (opSel & 0x1u) != 0u;
instruction.source1.opSel = (opSel & 0x2u) != 0u;
@@ -1940,6 +1956,12 @@ void checkNativeVop3Modifiers(RdnaOpcode opcode, bool permlane, bool carryInOut,
}
return;
}
if (isNativeVop3AlignOpcode(opcode)) {
if (abs != 0u || clamp != 0u || omod != 0u || neg != 0u) {
throw std::invalid_argument("VOP3 source modifiers are not implemented");
}
return;
}
if (isNativeVop3B16BinaryOpcode(opcode)) {
if (abs != 0u || clamp != 0u || omod != 0u || neg != 0u) {
throw std::invalid_argument("VOP3 source modifiers are not implemented");
@@ -2263,6 +2285,8 @@ RdnaInstruction DecodeRdnaVop3(std::uint32_t programCounter, std::span<const std
applyNativeVop3TernaryModifiers(instruction, opSel, abs, neg);
} else if (isNativeVop3I16TernaryOpcode(instruction.op)) {
applyNativeVop3I16TernarySelectors(instruction, opSel);
} else if (isNativeVop3AlignOpcode(instruction.op)) {
applyNativeVop3AlignSelectors(instruction, opSel);
} else if (isNativeVop3B16BinaryOpcode(instruction.op)) {
applyNativeVop3B16BinaryModifiers(instruction, opSel);
} else if (instruction.op == RdnaOpcode::VPackB32F16) {
@@ -698,15 +698,12 @@ bool TranslationContext::vAlignbitB32(const RdnaInstruction& inst) {
bool TranslationContext::vAlignbyteB32(const RdnaInstruction& inst) {
const IrU32 hi = readU32(sourceAt(inst, 0u));
const IrU32 lo = readU32(sourceAt(inst, 1u));
const IrU32 byteOffset(ir.BitwiseAnd(readU32(sourceAt(inst, 2u)).Value(), ir.Constant(31u)));
const IrU32 byteOffset(ir.BitwiseAnd(readU32(sourceAt(inst, 2u)).Value(), ir.Constant(3u)));
const IrU32 bitOffset(ir.ShiftLeftLogical(byteOffset.Value(), ir.Constant(3u)));
const IrU64 concatenated(ir.ConstructU64(lo.Value(), hi.Value()));
const IrU32 maskedBitOffset(ir.BitwiseAnd(bitOffset.Value(), ir.Constant(63u)));
const IrU64 shifted(ir.Emit(IrOpcode::ShiftRightLogical64, IrType::U64, {&concatenated.Value(), &maskedBitOffset.Value()}));
const IrU1 inRange(ir.ULessThan(byteOffset.Value(), ir.Constant(8u)));
const IrU64 shifted(ir.Emit(IrOpcode::ShiftRightLogical64, IrType::U64, {&concatenated.Value(), &bitOffset.Value()}));
const std::array<IrU32, 2> extracted = extractU64(shifted);
const IrU32 result(ir.Select(inRange.Value(), extracted[0].Value(), ir.Constant(0u)));
writeOperand(inst.destination, &result.Value());
writeOperand(inst.destination, &extracted[0].Value());
return true;
}