diff --git a/core/libs/prx/libSceAgcDriver/tests/execution/ScalarGetreg.cpp b/core/libs/prx/libSceAgcDriver/tests/execution/ScalarGetreg.cpp new file mode 100644 index 000000000..b580923c1 --- /dev/null +++ b/core/libs/prx/libSceAgcDriver/tests/execution/ScalarGetreg.cpp @@ -0,0 +1,102 @@ +#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 + +namespace { + +using AgcDriver::Graphics::Require; +using ShaderRecompiler::ShaderStage; + +constexpr std::uint32_t Threads = 32; +constexpr std::uint32_t Results = 16; +alignas(256) std::array Output{}; + +alignas(256) constexpr std::array Code{ + 0x34060086, 0xbe9403ff, 0x55555555, 0xbe9503ff, 0x55555555, 0xb9141801, 0xb9150881, 0x7e140214, + 0x7e160215, 0xe0701000, 0x80010a03, 0xe0701004, 0x80010b03, 0xbf810000, +}; + +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; +} + +ShaderRecompiler::RecompileRequest Request(AgcDriver::VulkanDevice& device, std::span code, std::span userData, std::span memory) { + 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; + return request; +} + +void ExpectRefused(AgcDriver::VulkanDevice& device, std::uint32_t word, const char* what) { + alignas(256) const std::array code{word, 0xbf810000u}; + const std::array memory{{{reinterpret_cast(code.data()), std::as_bytes(std::span(code))}}}; + const std::vector userData(8, 0u); + std::string refusal; + try { + static_cast(ShaderRecompiler::Recompile(Request(device, code, userData, memory))); + } catch (const std::exception& error) { + refusal = error.what(); + } + Require(refusal.find("only the MODE round mode fields are modeled") != std::string::npos, std::string("s_getreg_b32 reading ") + what + " was not refused"); +} + +void Run(AgcDriver::VulkanDevice& device) { + Output.fill(0xdeadbeefu); + std::vector userData(8, 0u); + const auto output = BufferDescriptor(Output.data(), static_cast(Output.size() * 4u)); + 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 auto result = ShaderRecompiler::Recompile(Request(device, code, userData, memory)); + device.Dispatch(result, 1, 1, 1, {}, reinterpret_cast(code.data())); + device.WaitIdle(); +} + +void Check() { + constexpr std::array names{"hwreg(MODE, 0, 4)", "hwreg(MODE, 2, 2)"}; + for (std::uint32_t tid = 0; tid < Threads; ++tid) { + for (std::uint32_t index = 0; index < names.size(); ++index) { + const std::uint32_t actual = Output[tid * Results + index]; + Require(actual == 0u, std::string("s_getreg_b32: lane ") + std::to_string(tid) + " " + names[index] + " is " + Hex(actual) + ", expected 0x00000000"); + } + } +} + +} + +int main() { + try { + const auto device = OpenVulkanTestDevice(); + if (!device) return VulkanTestSkipped; + Run(*device); + Check(); + ExpectRefused(*device, 0xb9141901u, "the MODE denormal fields"); + ExpectRefused(*device, 0xb914f804u, "HW_ID"); + std::puts("s_getreg_b32 tests passed"); + return 0; + } catch (const std::exception& error) { + std::cerr << error.what() << '\n'; + return 1; + } +} diff --git a/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp b/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp index 5ed43f202..28177fce9 100644 --- a/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp +++ b/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp @@ -897,6 +897,7 @@ enum class RdnaOpcode : std::uint16_t { VInterpMovF32, SWaitcntDepctr, SSendmsg, + SGetregB32, SSetregB32, SSetregImm32B32, SCmovkI32, diff --git a/core/shader/recompiler/RdnaDecoder/src/RdnaScalarOpDecoder.cpp b/core/shader/recompiler/RdnaDecoder/src/RdnaScalarOpDecoder.cpp index 15afeecfd..04f82bdcc 100644 --- a/core/shader/recompiler/RdnaDecoder/src/RdnaScalarOpDecoder.cpp +++ b/core/shader/recompiler/RdnaDecoder/src/RdnaScalarOpDecoder.cpp @@ -175,6 +175,7 @@ RdnaOpcode decodeSopkOpcode(std::uint32_t opcode) { case 0x0eu: return RdnaOpcode::SCmpLeU32; case 0x0fu: return RdnaOpcode::SAddI32; case 0x10u: return RdnaOpcode::SMulkI32; + case 0x12u: return RdnaOpcode::SGetregB32; case 0x13u: return RdnaOpcode::SSetregB32; case 0x15u: return RdnaOpcode::SSetregImm32B32; case 0x17u: return RdnaOpcode::SWaitcnt; @@ -417,6 +418,11 @@ RdnaInstruction DecodeRdnaSopk(std::uint32_t programCounter, std::span> 6u) & 0x1fu; + const std::uint32_t size = ((field >> 11u) & 0x1fu) + 1u; + if ((field & 0x3fu) != 1u || offset + size > 4u) { + throw std::runtime_error("s_getreg_b32 at pc " + std::to_string(inst.programCounter) + " reads hardware register " + std::to_string(field & 0x3fu) + " bits " + std::to_string(offset) + ".." + std::to_string(offset + size - 1u) + ": only the MODE round mode fields are modeled"); + } + writeRawU32(inst.destination, IrU32(ir.Constant(0u))); + return true; + } case RdnaOpcode::SCmovkI32: { const IrU32 previous = readU32(inst.destination); writeRawU32(inst.destination, IrU32(ir.Select(ir.GetScc(), ir.Constant(inst.source0.value), previous.Value())));