diff --git a/core/libs/prx/libSceAgcDriver/tests/execution/Vop1Vop2Integer.cpp b/core/libs/prx/libSceAgcDriver/tests/execution/Vop1Vop2Integer.cpp new file mode 100644 index 000000000..773fd3e38 --- /dev/null +++ b/core/libs/prx/libSceAgcDriver/tests/execution/Vop1Vop2Integer.cpp @@ -0,0 +1,173 @@ +#include "prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp" +#include "prx/libSceAgcDriver/Graphics/include/Draw.hpp" +#include "Recompiler.hpp" +#include "VulkanTestDevice.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { + +using AgcDriver::Graphics::Require; +using ShaderRecompiler::ShaderStage; + +constexpr std::uint32_t Threads = 32; +constexpr std::uint32_t Inputs = 4; +constexpr std::uint32_t Results = 64; +alignas(256) std::array Input{}; +alignas(256) std::array Output{}; + +alignas(256) constexpr std::array Code{ + 0x34020084, 0x34060088, 0xe0381000, 0x80000401, 0xbf8c3f70, 0x7e146f04, 0x7e167104, 0x7e187304, + 0x7e1a7504, 0x7e1c7704, 0x7e1e0d04, 0x7e200b04, 0x7e220f04, 0x7e241104, 0x7e261904, 0x7e281b04, + 0x7e2a1d04, 0x7e2ca304, 0x7e2ea104, 0x7e30a504, 0x7e32a704, 0x12340b04, 0x14360b04, 0x16380b04, + 0x183a0b04, 0x223c0b04, 0x243e0b04, 0x26400b04, 0x28420b04, 0x2c440b04, 0x30460b04, 0x34480b04, + 0x364a0b04, 0x384c0b04, 0x3a4e0b04, 0x3c500b04, 0x4a520b04, 0x4c540b04, 0x4e560b04, 0x36100c81, + 0x7d8a1080, 0x02580b04, 0x36100c81, 0x7d8a1080, 0x505a0b04, 0xd501002e, 0x01a90280, 0x36100c81, + 0x7d8a1080, 0x525e0b04, 0xd5010030, 0x01a90280, 0x36100c81, 0x7d8a1080, 0x54620b04, 0xd5010032, + 0x01a90280, 0xe0781000, 0x80010a03, 0xe0781010, 0x80010e03, 0xe0781020, 0x80011203, 0xe0781030, + 0x80011603, 0xe0781040, 0x80011a03, 0xe0781050, 0x80011e03, 0xe0781060, 0x80012203, 0xe0781070, + 0x80012603, 0xe0781080, 0x80012a03, 0xe0781090, 0x80012e03, 0xe07810a0, 0x80013203, 0xbf810000, +}; + +constexpr std::uint32_t Rows[32][4] = { + {0x3effffffu, 0x00000005u, 0x00000001u, 0x00000000u}, + {0xbeffffffu, 0x80000000u, 0x00000000u, 0x00000000u}, + {0x4b000001u, 0x7fffffffu, 0x00000001u, 0x00000000u}, + {0xcb000001u, 0x00000021u, 0x00000000u, 0x00000000u}, + {0x4affffffu, 0x00ffffffu, 0x00000001u, 0x00000000u}, + {0xbf000000u, 0xff800000u, 0x00000000u, 0x00000000u}, + {0x7fc00000u, 0x00800000u, 0x00000001u, 0x00000000u}, + {0xffc00000u, 0x00000020u, 0x00000000u, 0x00000000u}, + {0x7f800001u, 0xffffffffu, 0x00000001u, 0x00000000u}, + {0xff800001u, 0x00000000u, 0x00000001u, 0x00000000u}, + {0x4effffffu, 0x00000001u, 0x00000000u, 0x00000000u}, + {0xcf000000u, 0x80000001u, 0x00000001u, 0x00000000u}, + {0xbf000001u, 0x00800000u, 0x00000000u, 0x00000000u}, + {0xaf000000u, 0x00007fffu, 0x00000001u, 0x00000000u}, + {0x00000000u, 0x00000000u, 0xbf000000u, 0x00000003u}, + {0x58457b3au, 0xa7913051u, 0xfffffffeu, 0xcf000000u}, + {0x80000000u, 0x00000000u, 0xad489bceu, 0x96fc31a0u}, + {0xfffffffeu, 0x00000001u, 0x80000000u, 0xffffffffu}, + {0x39a77c00u, 0xc0200000u, 0x0000fc00u, 0x4f800000u}, + {0x5c90a958u, 0x00ffffffu, 0x3e7d1bfbu, 0x4f000000u}, + {0xffff890bu, 0x72158370u, 0x00003c00u, 0x58d5563du}, + {0x14a0f9e7u, 0x00003800u, 0x00008000u, 0xdd2e1609u}, + {0x83f73f16u, 0xa7abe1c2u, 0x0dd27a65u, 0x0000bc00u}, + {0x2607679du, 0xf4998d7cu, 0x7fc00000u, 0x80000001u}, + {0xdd02de92u, 0xbfc00000u, 0x007fffffu, 0x3f000000u}, + {0x3d932289u, 0x31dec4f4u, 0x3606defcu, 0x9abcdef0u}, + {0x5dbe3023u, 0x00008000u, 0x3836e865u, 0x18189af4u}, + {0xffff5884u, 0x12345678u, 0x4effffffu, 0x6eb4fff8u}, + {0x33061fbcu, 0xd1cee715u, 0x0000001fu, 0xc17a4f81u}, + {0x75b00b15u, 0x00008001u, 0xc5acb068u, 0x0000bc00u}, + {0xffffffffu, 0x0000001fu, 0x0000fbffu, 0xfffffffeu}, + {0x953f48f1u, 0x93bd04cfu, 0x0000000fu, 0x0becd7b0u} +}; +constexpr std::uint32_t Expected[32][41] = { + {0xc1000000u, 0xffffff7cu, 0x00000002u, 0x00000000u, 0x00000002u, 0x4e7c0000u, 0x4e7c0000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xbd800000u, 0x0000bc00u, 0x00007c00u, 0x00000000u, 0x00000000u, 0xfffffffbu, 0xffffffffu, 0x04fffffbu, 0x00000000u, 0x00000005u, 0x3effffffu, 0x00000005u, 0x3effffffu, 0x00000000u, 0x00000000u, 0x80000000u, 0x00000005u, 0x3effffffu, 0x3efffffau, 0xc1000005u, 0x3f000004u, 0x3efffffau, 0xc1000006u, 0x00000005u, 0x3f000005u, 0x00000000u, 0x3efffff9u, 0x00000000u, 0xc1000005u, 0x00000001u}, + {0x41000000u, 0xffffff7du, 0x00000000u, 0x00000000u, 0x00000001u, 0x4f3f0000u, 0xce820000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xffffffffu, 0xbd800000u, 0x0000bc00u, 0x00007c00u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x80000000u, 0xbeffffffu, 0x80000000u, 0xbeffffffu, 0x00000001u, 0xffffffffu, 0x00000000u, 0x80000000u, 0xbeffffffu, 0x3effffffu, 0xc1000000u, 0x3effffffu, 0x3effffffu, 0xc1000001u, 0xbeffffffu, 0x3effffffu, 0x00000001u, 0x3effffffu, 0x00000000u, 0xc1000001u, 0x00000001u}, + {0xb4fffffeu, 0x800000d2u, 0x00000001u, 0x00000000u, 0x00000001u, 0x4e960000u, 0x4e960000u, 0x00800001u, 0x00800001u, 0x00800001u, 0x00800001u, 0x3d800000u, 0x00003c00u, 0x00003c00u, 0x00000000u, 0x00000000u, 0xffffffffu, 0xffffffffu, 0x00ffffffu, 0x00000000u, 0x4b000001u, 0x7fffffffu, 0x4b000001u, 0x7fffffffu, 0x3fffffffu, 0x3fffffffu, 0xfffffffeu, 0x4b000001u, 0x7fffffffu, 0x34fffffeu, 0xcb000001u, 0xcb000000u, 0xcb000002u, 0x34fffffeu, 0x7fffffffu, 0xcb000001u, 0x00000000u, 0xcb000001u, 0x00000001u, 0x34fffffdu, 0x00000000u}, + {0x34fffffeu, 0x800000d3u, 0x00000000u, 0x00000000u, 0x00000002u, 0x4f4b0000u, 0xce540000u, 0x00000000u, 0xff7fffffu, 0xff7fffffu, 0xff7fffffu, 0x3d800000u, 0x00003c00u, 0x00003c00u, 0x00000000u, 0x00000000u, 0x00000021u, 0x00000000u, 0x00000021u, 0x00000000u, 0xcb000001u, 0x00000021u, 0x00000021u, 0xcb000001u, 0x00000010u, 0x00000010u, 0x00000042u, 0x00000001u, 0xcb000021u, 0xcb000020u, 0x34ffffdfu, 0xcb000022u, 0xcaffffe0u, 0x35000020u, 0xcb000001u, 0xcb000022u, 0x00000000u, 0xcaffffe0u, 0x00000000u, 0x35000020u, 0x00000001u}, + {0xb5000000u, 0xffffff52u, 0x00000001u, 0x00000000u, 0x00000001u, 0x4e960000u, 0x4e960000u, 0x007fffffu, 0x007fffffu, 0x00800000u, 0x007fffffu, 0xbd800000u, 0x0000bc00u, 0x00007c00u, 0x00000000u, 0x00000000u, 0x00000001u, 0x00000000u, 0xfe000001u, 0x0000ffffu, 0x00ffffffu, 0x4affffffu, 0x00ffffffu, 0x4affffffu, 0x00000000u, 0x00000000u, 0x80000000u, 0x00ffffffu, 0x4affffffu, 0x4a000000u, 0xb5ffffffu, 0x4bfffffeu, 0x4a000000u, 0xb6000000u, 0x00ffffffu, 0x4bffffffu, 0x00000000u, 0x49ffffffu, 0x00000000u, 0xb5ffffffu, 0x00000001u}, + {0x40ffffffu, 0x000000fdu, 0x00000000u, 0x00000018u, 0x00000001u, 0x4f3f0000u, 0xce820000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xffffffffu, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xbf000000u, 0xff800000u, 0xbf000000u, 0xff800000u, 0xff800000u, 0xff800000u, 0xff800000u, 0xbf000000u, 0xff800000u, 0x40800000u, 0xbf7fffffu, 0xbe800000u, 0xbf800000u, 0x40800000u, 0xbf000000u, 0xbe800000u, 0x00000001u, 0xbf800000u, 0x00000001u, 0x40800000u, 0x00000000u}, + {0x803fffffu, 0x000003feu, 0x00000001u, 0x00000016u, 0x00000001u, 0x4eff8000u, 0x4eff8000u, 0x00000000u, 0x00000000u, 0x7fffffffu, 0x7fffffffu, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00002000u, 0x00000000u, 0x00006000u, 0x00800000u, 0x7fc00000u, 0x00800000u, 0x7fc00000u, 0x00800000u, 0x00800000u, 0x00800000u, 0x00800000u, 0x7fc00000u, 0x7f400000u, 0x80bfffffu, 0x80400000u, 0x7f400000u, 0x80c00000u, 0x00800000u, 0x80400001u, 0x00000000u, 0x7f3fffffu, 0x00000000u, 0x80bfffffu, 0x00000001u}, + {0x003fffffu, 0x000003ffu, 0x00000000u, 0x00000016u, 0x0000000au, 0x4f7fc000u, 0xca800000u, 0x00000000u, 0x00000000u, 0x80000000u, 0x80000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xf8000000u, 0xffffffffu, 0x18000000u, 0x00000000u, 0xffc00000u, 0x00000020u, 0x00000020u, 0xffc00000u, 0x00000020u, 0x00000020u, 0x00000020u, 0x00000000u, 0xffc00020u, 0xffc00020u, 0x003fffdfu, 0xffc00020u, 0xffbfffe0u, 0x00400020u, 0xffc00000u, 0xffc00020u, 0x00000000u, 0xffbfffe0u, 0x00000000u, 0x00400020u, 0x00000001u}, + {0x807ffffeu, 0x800001feu, 0x00000001u, 0x00000000u, 0x00000001u, 0x4eff0000u, 0x4eff0000u, 0x00000000u, 0x00000000u, 0x7fffffffu, 0x7fffffffu, 0x3d800000u, 0x00003c00u, 0x00003c00u, 0x00000000u, 0x00000000u, 0x007fffffu, 0x00000000u, 0x007fffffu, 0x00008000u, 0xffffffffu, 0x7f800001u, 0x7f800001u, 0xffffffffu, 0x7fffffffu, 0xffffffffu, 0xfffffffeu, 0x7f800001u, 0xffffffffu, 0x807ffffeu, 0x7f800001u, 0x7f800000u, 0x7f800002u, 0x807ffffeu, 0xffffffffu, 0x7f800001u, 0x00000001u, 0x7f800001u, 0x00000001u, 0x807ffffdu, 0x00000000u}, + {0x007ffffeu, 0x800001ffu, 0x00000000u, 0x00000000u, 0x00000009u, 0x4f7f8000u, 0xcafffffeu, 0x00000000u, 0x00000000u, 0x80000000u, 0x80000000u, 0x3d800000u, 0x00003c00u, 0x00003c00u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xff800001u, 0x00000000u, 0x00000000u, 0xff800001u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xff800001u, 0xff800001u, 0x007ffffeu, 0xff800001u, 0xff800001u, 0x007fffffu, 0x00000000u, 0xff800002u, 0x00000000u, 0xff800000u, 0x00000000u, 0x007ffffeu, 0x00000001u}, + {0xb1000000u, 0xffffff72u, 0x00000001u, 0x00000000u, 0x00000001u, 0x4e9e0000u, 0x4e9e0000u, 0x7fffff80u, 0x7fffff80u, 0x7fffff80u, 0x7fffff80u, 0xbd800000u, 0x0000bc00u, 0x00007c00u, 0x00000000u, 0x00000000u, 0xffffffffu, 0xffffffffu, 0x00ffffffu, 0x00000000u, 0x00000001u, 0x4effffffu, 0x00000001u, 0x4effffffu, 0x00000000u, 0x00000000u, 0x80000000u, 0x00000001u, 0x4effffffu, 0x4efffffeu, 0xb1000001u, 0x4f000000u, 0x4efffffeu, 0xb1000002u, 0x4effffffu, 0x4f000000u, 0x00000000u, 0x4efffffeu, 0x00000000u, 0xb1000002u, 0x00000001u}, + {0x30ffffffu, 0x000000f3u, 0x00000000u, 0x00000018u, 0x00000002u, 0x4f4f0000u, 0xce440000u, 0x00000000u, 0x80000000u, 0x80000000u, 0x80000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x80000001u, 0xcf000000u, 0x80000001u, 0xcf000000u, 0x80000001u, 0x80000001u, 0x80000001u, 0x80000000u, 0xcf000001u, 0x4f000001u, 0xb0fffffeu, 0x4f000001u, 0x4effffffu, 0xb1000001u, 0x80000001u, 0x4f000002u, 0x00000001u, 0x4efffffeu, 0x00000000u, 0xb1000000u, 0x00000001u}, + {0x40fffffeu, 0x800000fdu, 0x00000000u, 0x00000000u, 0x00000001u, 0x4f3f0000u, 0xce820000u, 0x00000000u, 0x00000000u, 0xffffffffu, 0xffffffffu, 0x3d800000u, 0x00003c00u, 0x00003c00u, 0x00000000u, 0x00000000u, 0xff800000u, 0xffffffffu, 0x00800000u, 0x00000000u, 0xbf000001u, 0x00800000u, 0x00800000u, 0xbf000001u, 0x00400000u, 0x00400000u, 0x01000000u, 0x00000000u, 0xbf800001u, 0xbf800001u, 0x407ffffeu, 0xbf800001u, 0xbe800001u, 0x417fffffu, 0xbf000001u, 0xbf800001u, 0x00000000u, 0xbe800001u, 0x00000000u, 0x417fffffu, 0x00000001u}, + {0x50ffffffu, 0x000000f5u, 0x00000000u, 0x00000018u, 0x00000001u, 0x4f2f0000u, 0xcea20000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xffffffffu, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xaf000000u, 0x00007fffu, 0x00007fffu, 0xaf000000u, 0x00007fffu, 0x00007fffu, 0x00007fffu, 0x00000000u, 0xaf007fffu, 0xaf007fffu, 0x50ff8000u, 0xaf007fffu, 0xaeff8001u, 0x51007fffu, 0x00007fffu, 0xaf008000u, 0x00000000u, 0xaeff8000u, 0x00000000u, 0x51007ffeu, 0x00000001u}, + {0xffffffffu, 0x00000000u, 0xffffffffu, 0xffffffffu, 0xffffffffu, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xffffffffu, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u}, + {0xa7ba84c5u, 0x5cdea21au, 0x00000001u, 0x00000001u, 0x00000001u, 0x4eb08af6u, 0x4eb08af6u, 0xffffffffu, 0x7fffffffu, 0x7fffffffu, 0x7fffffffu, 0xbec00000u, 0x000077b4u, 0x000077b4u, 0x0000e740u, 0x00007fffu, 0xaef0dd5au, 0xffffe1ecu, 0xe8f0dd5au, 0x00002767u, 0xa7913051u, 0x58457b3au, 0x58457b3au, 0xa7913051u, 0x00000029u, 0xffffffe9u, 0x44000000u, 0x00013010u, 0xffd57b7bu, 0xffd44b6bu, 0x002bb494u, 0xffd6ab8bu, 0xb0b44ae9u, 0x4f4bb517u, 0x58457b3au, 0xffd6ab8bu, 0x00000000u, 0xb0b44ae9u, 0x00000001u, 0x4f4bb517u, 0x00000000u}, + {0x7fffffffu, 0x00000001u, 0x00000000u, 0x0000001fu, 0x00000001u, 0x4f000000u, 0xcf000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x80000000u, 0x00000000u, 0x00000000u, 0x80000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x80000000u, 0x80000000u, 0x7fffffffu, 0x80000000u, 0x80000000u, 0x80000000u, 0x80000000u, 0x80000000u, 0x00000000u, 0x80000000u, 0x00000000u, 0x80000000u, 0x00000001u}, + {0x00000001u, 0x7fffffffu, 0x00000000u, 0x00000001u, 0x0000001fu, 0x4f800000u, 0xc0000000u, 0x00000000u, 0x00000000u, 0x80000000u, 0x80000000u, 0xbe000000u, 0x0000c000u, 0x00007c00u, 0x00000000u, 0x00000000u, 0xfffffffeu, 0xffffffffu, 0x00fffffeu, 0x00000000u, 0xfffffffeu, 0x00000001u, 0x00000001u, 0xfffffffeu, 0x00000000u, 0x00000000u, 0x40000000u, 0x00000000u, 0xffffffffu, 0xffffffffu, 0x00000000u, 0xffffffffu, 0xfffffffdu, 0x00000003u, 0xfffffffeu, 0xffffffffu, 0x00000000u, 0xfffffffdu, 0x00000000u, 0x00000003u, 0x00000001u}, + {0xc65883ffu, 0x003ee59cu, 0x00000002u, 0x0000000au, 0x00000002u, 0x4e669df0u, 0x4e669df0u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x000077c0u, 0x000077c0u, 0x0000ffffu, 0x00007fffu, 0x80000000u, 0xfffff4efu, 0x80000000u, 0x000014efu, 0xc0200000u, 0x39a77c00u, 0x39a77c00u, 0xc0200000u, 0xc0200000u, 0xc0200000u, 0xc0200000u, 0x00200000u, 0xf9a77c00u, 0xf9877c00u, 0x067883ffu, 0xf9c77c00u, 0x79877c00u, 0x86788400u, 0x39a77c00u, 0xf9c77c00u, 0x00000000u, 0x79877c00u, 0x00000001u, 0x86788400u, 0x00000000u}, + {0xa36f56a7u, 0x1a95093au, 0x00000001u, 0x00000003u, 0x00000001u, 0x4eb92153u, 0x4eb92153u, 0xffffffffu, 0x7fffffffu, 0x7fffffffu, 0x7fffffffu, 0xbf000000u, 0x0000f56au, 0x0000794bu, 0x00000000u, 0x00000000u, 0x006f56a8u, 0x00000000u, 0x576f56a8u, 0x000090a9u, 0x00ffffffu, 0x5c90a958u, 0x00ffffffu, 0x5c90a958u, 0x00000000u, 0x00000000u, 0xff000000u, 0x0090a958u, 0x5cffffffu, 0x5c6f56a7u, 0xa390a958u, 0x5d90a957u, 0x5b90a959u, 0xa46f56a7u, 0x00ffffffu, 0x5d90a958u, 0x00000000u, 0x5b90a958u, 0x00000000u, 0xa46f56a6u, 0x00000001u}, + {0x000076f4u, 0xd091ffffu, 0x00000000u, 0x00000000u, 0x00000011u, 0x4f7fff89u, 0xc6edea00u, 0x00000000u, 0x00000000u, 0x80000000u, 0x80000000u, 0xbea00000u, 0x0000f76fu, 0x00007848u, 0x00000000u, 0x00000000u, 0x00d395d0u, 0xfffffff6u, 0x70d395d0u, 0x00001579u, 0xffff890bu, 0x72158370u, 0x72158370u, 0xffff890bu, 0x000e42b0u, 0x000e42b0u, 0xac1b8000u, 0x72158100u, 0xffff8b7bu, 0x8dea0a7bu, 0x7215f584u, 0x72150c7bu, 0x8dea059bu, 0x7215fa65u, 0xffff890bu, 0x72150c7bu, 0x00000001u, 0x8dea059bu, 0x00000000u, 0x7215fa65u, 0x00000001u}, + {0xeb5f0618u, 0xe79f0528u, 0x00000003u, 0x00000000u, 0x00000003u, 0x4da507cfu, 0x4da507cfu, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0x3ee00000u, 0x0000e619u, 0x00007bcfu, 0x00000000u, 0x00008000u, 0x36aa8800u, 0xffffffebu, 0x36aa8800u, 0x00000023u, 0x00003800u, 0x14a0f9e7u, 0x00003800u, 0x14a0f9e7u, 0x00000070u, 0x00000070u, 0x001c0000u, 0x00003800u, 0x14a0f9e7u, 0x14a0c1e7u, 0xeb5f3e18u, 0x14a131e7u, 0x14a0c1e7u, 0xeb5f3e19u, 0x14a0f9e7u, 0x14a131e7u, 0x00000000u, 0x14a0c1e7u, 0x00000000u, 0xeb5f3e19u, 0x00000001u}, + {0x7c08c0e9u, 0x68fcefc1u, 0x00000000u, 0x00000001u, 0x00000001u, 0x4f03f73fu, 0xcef81182u, 0x00000000u, 0x00000000u, 0x00000000u, 0xffffffffu, 0x3ec00000u, 0x000073e3u, 0x000073e3u, 0x00000001u, 0x00000001u, 0x558224acu, 0x000002e0u, 0x2d8224acu, 0x0000a601u, 0x83f73f16u, 0xa7abe1c2u, 0x83f73f16u, 0xa7abe1c2u, 0x0000029eu, 0xfffffe9eu, 0x70800000u, 0x83a32102u, 0xa7ffffd6u, 0x245cded4u, 0xdba3212bu, 0x2ba320d8u, 0xdc4b5d54u, 0x23b4a2acu, 0xa7abe1c2u, 0x2ba320d9u, 0x00000001u, 0xdc4b5d53u, 0x00000001u, 0x23b4a2abu, 0x00000000u}, + {0xd9f89862u, 0xb9e6e064u, 0x00000002u, 0x00000000u, 0x00000002u, 0x4e181d9eu, 0x4e181d9eu, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xbe400000u, 0x0000767au, 0x0000767au, 0x0000079du, 0x0000079du, 0x677ca90cu, 0xfffffd09u, 0x047ca90cu, 0x00000471u, 0xf4998d7cu, 0x2607679du, 0x2607679du, 0xf4998d7cu, 0x00000007u, 0xffffffffu, 0x80000000u, 0x2401051cu, 0xf69feffdu, 0xd29eeae1u, 0x2d61151eu, 0x1aa0f519u, 0x316dda21u, 0xce9225dfu, 0x2607679du, 0x1aa0f519u, 0x00000001u, 0x316dda21u, 0x00000001u, 0xce9225dfu, 0x00000000u}, + {0x22fd216du, 0x497b40bbu, 0x00000000u, 0x00000001u, 0x00000002u, 0x4f5d02dfu, 0xce0bf486u, 0x00000000u, 0x80000000u, 0x80000000u, 0x80000000u, 0x3e000000u, 0x0000f02eu, 0x00007af5u, 0x00000000u, 0x0000fe5cu, 0x5b800000u, 0xffffff48u, 0xed800000u, 0x00000226u, 0xbfc00000u, 0xdd02de92u, 0xbfc00000u, 0xdd02de92u, 0x00002ff0u, 0xffffeff0u, 0x00000000u, 0x9d000000u, 0xffc2de92u, 0x62c2de92u, 0x9d3d216du, 0x9cc2de92u, 0x1d42de92u, 0xe2bd216eu, 0xbfc00000u, 0x9cc2de93u, 0x00000001u, 0x1d42de91u, 0x00000000u, 0xe2bd216du, 0x00000001u}, + {0xc26cdd76u, 0x9144c9bcu, 0x00000002u, 0x00000000u, 0x00000002u, 0x4e764c8au, 0x4e764c8au, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xbee00000u, 0x00007051u, 0x00007051u, 0x00000000u, 0x00000000u, 0xa87bce94u, 0x00000e21u, 0x257bce94u, 0x00008009u, 0x31dec4f4u, 0x3d932289u, 0x31dec4f4u, 0x3d932289u, 0x0018ef62u, 0x0018ef62u, 0xbd89e800u, 0x31920080u, 0x3ddfe6fdu, 0x0c4de67du, 0xf3b21982u, 0x6f71e77du, 0x0bb45d95u, 0xf44ba26bu, 0x3d932289u, 0x6f71e77du, 0x00000000u, 0x0bb45d95u, 0x00000000u, 0xf44ba26bu, 0x00000001u}, + {0xa241cfdcu, 0xc40c7dbau, 0x00000001u, 0x00000000u, 0x00000001u, 0x4ebb7c60u, 0x4ebb7c60u, 0xffffffffu, 0x7fffffffu, 0x7fffffffu, 0x7fffffffu, 0x3e400000u, 0x00007204u, 0x00007204u, 0x00000000u, 0x00000000u, 0x18118000u, 0xffffffdfu, 0x18118000u, 0x0000005fu, 0x00008000u, 0x5dbe3023u, 0x00008000u, 0x5dbe3023u, 0x00001000u, 0x00001000u, 0x00040000u, 0x00000000u, 0x5dbeb023u, 0x5dbeb023u, 0xa2414fdcu, 0x5dbeb023u, 0x5dbdb023u, 0xa2424fddu, 0x00008000u, 0x5dbeb024u, 0x00000000u, 0x5dbdb022u, 0x00000000u, 0xa2424fdcu, 0x00000001u}, + {0x0000a77bu, 0x211affffu, 0x00000000u, 0x00000002u, 0x00000010u, 0x4f7fff59u, 0xc7277c00u, 0x00000000u, 0x00000000u, 0x80000000u, 0x80000000u, 0x3e800000u, 0x00007588u, 0x00007588u, 0x00000090u, 0x00000090u, 0xc23dd5e0u, 0xffffffddu, 0x3a3dd5e0u, 0x00003434u, 0xffff5884u, 0x12345678u, 0x12345678u, 0xffff5884u, 0x01234567u, 0x01234567u, 0x23456780u, 0x12345000u, 0xffff5efcu, 0xedcb0efcu, 0x1234f103u, 0x1233aefcu, 0xedcb020cu, 0x1234fdf4u, 0x12345678u, 0x1233aefdu, 0x00000001u, 0xedcb020bu, 0x00000000u, 0x1234fdf3u, 0x00000001u}, + {0xccf9e043u, 0x3df860ccu, 0x00000002u, 0x00000002u, 0x00000002u, 0x4e4c187fu, 0x4e4c187fu, 0x00000000u, 0x00000000u, 0x00000000u, 0x00000000u, 0xbe800000u, 0x00006fefu, 0x00006fefu, 0x00000000u, 0x00000000u, 0x546b3e6cu, 0xfffffed3u, 0x106b3e6cu, 0x000004f3u, 0xd1cee715u, 0x33061fbcu, 0x33061fbcu, 0xd1cee715u, 0x0000000du, 0xfffffffdu, 0x50000000u, 0x11060714u, 0xf3ceffbdu, 0xe2c8f8a9u, 0x1d370756u, 0x04d506d1u, 0x613738a7u, 0x9ec8c759u, 0xd1cee715u, 0x04d506d2u, 0x00000001u, 0x613738a6u, 0x00000001u, 0x9ec8c758u, 0x00000000u}, + {0x8a4ff4eau, 0xa8d00daeu, 0x00000001u, 0x00000000u, 0x00000001u, 0x4eeb6016u, 0x4eeb6016u, 0xffffffffu, 0x7fffffffu, 0x7fffffffu, 0x7fffffffu, 0x3ea00000u, 0x0000698au, 0x0000698au, 0x00000000u, 0x00000000u, 0x053a8b15u, 0xffffffd8u, 0x063a8b15u, 0x00000058u, 0x00008001u, 0x75b00b15u, 0x00008001u, 0x75b00b15u, 0x00000000u, 0x00000000u, 0x00200000u, 0x00000001u, 0x75b08b15u, 0x75b08b14u, 0x8a4f74ebu, 0x75b08b16u, 0x75af8b14u, 0x8a5074ecu, 0x75b00b15u, 0x75b08b16u, 0x00000000u, 0x75af8b14u, 0x00000000u, 0x8a5074ecu, 0x00000001u}, + {0x00000000u, 0xffffffffu, 0x00000000u, 0x00000000u, 0xffffffffu, 0x4f800000u, 0xbf800000u, 0x00000000u, 0x00000000u, 0x80000000u, 0x80000000u, 0xbd800000u, 0x0000bc00u, 0x00007c00u, 0x00000000u, 0x00000000u, 0xffffffe1u, 0xffffffffu, 0x1effffe1u, 0x00000000u, 0xffffffffu, 0x0000001fu, 0x0000001fu, 0xffffffffu, 0x00000000u, 0x00000000u, 0x80000000u, 0x0000001fu, 0xffffffffu, 0xffffffe0u, 0x0000001fu, 0x0000001eu, 0xffffffe0u, 0x00000020u, 0x0000001fu, 0x0000001fu, 0x00000001u, 0xffffffdfu, 0x00000000u, 0x0000001fu, 0x00000001u}, + {0x6ac0b70eu, 0x8f12fca9u, 0x00000000u, 0x00000000u, 0x00000001u, 0x4f153f49u, 0xced5816eu, 0x00000000u, 0x00000000u, 0x00000000u, 0xffffffffu, 0x3d800000u, 0x0000748fu, 0x0000748fu, 0x00000009u, 0x00000009u, 0x193cbedfu, 0xffffef71u, 0x0a3cbedfu, 0x00002ebau, 0x93bd04cfu, 0x953f48f1u, 0x93bd04cfu, 0x953f48f1u, 0x000049deu, 0xffffc9deu, 0x099e0000u, 0x913d00c1u, 0x97bf4cffu, 0x06824c3eu, 0xf97db3c1u, 0x28fc4dc0u, 0x01824422u, 0xfe7dbbdeu, 0x93bd04cfu, 0x28fc4dc1u, 0x00000001u, 0x01824421u, 0x00000000u, 0xfe7dbbddu, 0x00000001u} +}; +constexpr const char* Names[41] = {"not_b32", "bfrev_b32", "ffbh_u32", "ffbl_b32", "ffbh_i32", "cvt_f32_u32", "cvt_f32_i32", "cvt_u32_f32", "cvt_i32_f32", "cvt_rpi_i32_f32", "cvt_flr_i32_f32", "cvt_off_f32_i4", "cvt_f16_i16", "cvt_f16_u16", "cvt_u16_f16", "cvt_i16_f16", "mul_i32_i24", "mul_hi_i32_i24", "mul_u32_u24", "mul_hi_u32_u24", "min_i32", "max_i32", "min_u32", "max_u32", "lshrrev_b32", "ashrrev_i32", "lshlrev_b32", "and_b32", "or_b32", "xor_b32", "xnor_b32", "add_nc_u32", "sub_nc_u32", "subrev_nc_u32", "cndmask_b32", "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"}; + +void Fill(std::uint32_t tid, std::uint32_t* words) { + std::copy(std::begin(Rows[tid]), std::end(Rows[tid]), words); +} + +std::array BufferDescriptor(const void* data, std::uint32_t bytes) { + const auto address = reinterpret_cast(data); + return {static_cast(address), static_cast((address >> 32u) & 0xffffu), bytes, 0x01016facu}; +} + +std::string Hex(std::uint32_t value) { + char text[16]; + std::snprintf(text, sizeof(text), "0x%08x", value); + return text; +} + +void Expect(std::uint32_t tid, std::uint32_t actual, std::uint32_t expected, const char* name) { + Require(actual == expected, std::string("vop1 vop2 integer: lane ") + std::to_string(tid) + " " + name + " is " + Hex(actual) + ", expected " + Hex(expected)); +} + +void Run(AgcDriver::VulkanDevice& device) { + for (std::uint32_t tid = 0; tid < Threads; ++tid) Fill(tid, &Input[tid * Inputs]); + Output.fill(0xdeadbeefu); + std::vector userData(8, 0u); + const auto input = BufferDescriptor(Input.data(), static_cast(Input.size() * 4u)); + const auto output = BufferDescriptor(Output.data(), static_cast(Output.size() * 4u)); + std::copy(input.begin(), input.end(), userData.begin()); + std::copy(output.begin(), output.end(), userData.begin() + 4); + const std::span code(Code); + const std::array memory{{{reinterpret_cast(code.data()), std::as_bytes(code)}}}; + const ShaderRecompiler::ShaderComputeStageInfo compute{{Threads, 1, 1}, 0u, {false, false, false}, false, 1}; + ShaderRecompiler::RecompileRequest request{ + {ShaderStage::Compute, reinterpret_cast(code.data()), code, 0, {}}, + {32, 0, userData, compute, std::nullopt, std::nullopt, memory}, + device.Target(), + {0, 0, 0, 128} + }; + request.useCache = false; + const auto result = ShaderRecompiler::Recompile(request); + device.Dispatch(result, 1, 1, 1, {}, reinterpret_cast(code.data())); + device.WaitIdle(); +} + +void Check() { + for (std::uint32_t tid = 0; tid < Threads; ++tid) { + const std::uint32_t* in = &Input[tid * Inputs]; + const std::uint32_t* out = &Output[tid * Results]; + for (std::uint32_t i = 0; i < 41; ++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("vop1 vop2 integer tests passed"); + return 0; + } catch (const std::exception& error) { + std::cerr << error.what() << '\n'; + return 1; + } +} diff --git a/core/shader/recompiler/Translation/include/Translation/TranslationContext.hpp b/core/shader/recompiler/Translation/include/Translation/TranslationContext.hpp index 4be3e2626..3187613c7 100644 --- a/core/shader/recompiler/Translation/include/Translation/TranslationContext.hpp +++ b/core/shader/recompiler/Translation/include/Translation/TranslationContext.hpp @@ -116,6 +116,7 @@ private: IrF32 selectF32(IrU1 condition, IrF32 trueValue, IrF32 falseValue); IrU32 convertF32ToU32Saturated(IrF32 value, float upperBound, float safeUpper, std::uint32_t highResult); IrU32 convertF32ToI32Saturated(IrF32 value, float lowerBound, float upperBound, float safeUpper, std::uint32_t lowerResult, std::uint32_t upperResult); + IrU32 convertFlooredF32ToI32(IrF32 source, IrF32 floored); IrU32 packU16Lanes(IrU32 low, IrU32 high); void emitCompareResult(const RdnaInstruction& inst, IrU1 value, bool scalar, bool cmpx); void emitCompareConstant(const RdnaInstruction& inst, bool value, bool scalar, bool cmpx); diff --git a/core/shader/recompiler/Translation/src/ConvertInstructions.cpp b/core/shader/recompiler/Translation/src/ConvertInstructions.cpp index 0a03104de..f560ca699 100644 --- a/core/shader/recompiler/Translation/src/ConvertInstructions.cpp +++ b/core/shader/recompiler/Translation/src/ConvertInstructions.cpp @@ -104,18 +104,29 @@ void TranslationContext::vCvt16F16(const RdnaInstruction& inst, bool signedValue write16Bits(inst.destination, convertF32ToU32Saturated(value, 65536.0f, 65535.0f, 0xffffu)); } +IrU32 TranslationContext::convertFlooredF32ToI32(IrF32 source, IrF32 floored) { + const IrU32 converted = convertF32ToI32Saturated(floored, -2147483648.0f, 2147483648.0f, 2147483520.0f, 0x80000000u, 0x7fffffffu); + const IrU1 nan(ir.Emit(IrOpcode::FPIsNan32, IrType::U1, {&source.Value()})); + const IrU32 sign(ir.ShiftRightLogical(ir.BitCastU32(source.Value()), ir.Constant(31u))); + const IrU32 nanResult(ir.IAdd(ir.Constant(0x7fffffffu), sign.Value())); + return IrU32(ir.Select(nan.Value(), nanResult.Value(), converted.Value())); +} + void TranslationContext::vCvtRpiI32F32(const RdnaInstruction& inst) { const IrF32 source(*readOperand(sourceAt(inst, 0u), IrType::F32)); - const IrF32 biased(ir.Emit(IrOpcode::FPAdd32, IrType::F32, {&source.Value(), &ir.ConstantF32(0.5f)})); - const IrF32 rounded(ir.Emit(IrOpcode::FPFloor32, IrType::F32, {&biased.Value()})); - const IrU32 result = convertF32ToI32Saturated(rounded, -2147483648.0f, 2147483648.0f, 2147483520.0f, 0x80000000u, 0x7fffffffu); + const IrF32 floored(ir.Emit(IrOpcode::FPFloor32, IrType::F32, {&source.Value()})); + const IrF32 fraction(ir.Emit(IrOpcode::FPSub32, IrType::F32, {&source.Value(), &floored.Value()})); + const IrU1 roundUp(ir.Emit(IrOpcode::FPOrdGreaterThanEqual32, IrType::U1, {&fraction.Value(), &ir.ConstantF32(0.5f)})); + const IrF32 increment = selectF32(roundUp, IrF32(ir.ConstantF32(1.0f)), IrF32(ir.ConstantF32(0.0f))); + const IrF32 rounded(ir.Emit(IrOpcode::FPAdd32, IrType::F32, {&floored.Value(), &increment.Value()})); + const IrU32 result = convertFlooredF32ToI32(source, rounded); writeOperand(inst.destination, &result.Value()); } void TranslationContext::vCvtFlrI32F32(const RdnaInstruction& inst) { const IrF32 source(*readOperand(sourceAt(inst, 0u), IrType::F32)); const IrF32 rounded(ir.Emit(IrOpcode::FPFloor32, IrType::F32, {&source.Value()})); - const IrU32 result = convertF32ToI32Saturated(rounded, -2147483648.0f, 2147483648.0f, 2147483520.0f, 0x80000000u, 0x7fffffffu); + const IrU32 result = convertFlooredF32ToI32(source, rounded); writeOperand(inst.destination, &result.Value()); }