feat(shader): decode the s_endpgm variants, s_round_mode and SMEM probe/discard

s_endpgm_saved and s_endpgm_ordered_ps_done end the wave like s_endpgm
(checked on an RDNA2 GPU: nothing after them runs), so they decode to
SEndpgm and the control flow graph treats them as terminators.
s_atc_probe, s_atc_probe_buffer and s_dcache_discard(_x2) have no visible
effect and translate to no-ops like the other scalar cache controls.
s_round_mode is ignored like s_setreg MODE writes; listed in TechnicalDebt.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Adrià Franch
2026-10-03 09:00:00 +02:00
parent 70596d78eb
commit 69e2d801d1
8 changed files with 211 additions and 1 deletions
@@ -0,0 +1,96 @@
#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, 30> Code{
0x34020084, 0x34060086, 0xe0301000, 0x80000401, 0xbf8c3f70, 0xbfa40003, 0xf4980000, 0xfa000000,
0xf49c0000, 0xfa000000, 0xf4a00000, 0xfa000000, 0xf4a40000, 0xfa000000, 0xbfa40000, 0x4a0a0881,
0x7e0c02ff, 0x00000bad, 0xbf060000, 0xbf840007, 0xbf840003, 0xe0701000, 0x80010503, 0xbf9e0000,
0xe0701000, 0x80010603, 0xbf9b0000, 0xe0701004, 0x80010603, 0xbf810000,
};
void Fill(std::uint32_t tid, std::uint32_t* words) { words[0] = tid * 0x01010101u + 7u; }
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("scalar program end: 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];
Expect(tid, out[0], in[0] + 1u, "store before the end");
Expect(tid, out[1], 0xdeadbeefu, "nothing past the end");
}
}
}
int main() {
try {
const auto device = OpenVulkanTestDevice();
if (!device) return VulkanTestSkipped;
Run(*device);
Check();
std::puts("scalar program end tests passed");
return 0;
} catch (const std::exception& error) {
std::cerr << error.what() << '\n';
return 1;
}
}
@@ -0,0 +1,96 @@
#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, 30> Code{
0x34020084, 0x34060086, 0xe0301000, 0x80000401, 0xbf8c3f70, 0xbfa40003, 0xf4980000, 0xfa000000,
0xf49c0000, 0xfa000000, 0xf4a00000, 0xfa000000, 0xf4a40000, 0xfa000000, 0xbfa40000, 0x4a0a0881,
0x7e0c02ff, 0x00000bad, 0xbf060000, 0xbf840007, 0xbf840003, 0xe0701000, 0x80010503, 0xbf9b0000,
0xe0701000, 0x80010603, 0xbf9e0000, 0xe0701004, 0x80010603, 0xbf810000,
};
void Fill(std::uint32_t tid, std::uint32_t* words) { words[0] = tid * 0x01010101u + 7u; }
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("scalar program end saved: 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];
Expect(tid, out[0], in[0] + 1u, "store before the end");
Expect(tid, out[1], 0xdeadbeefu, "nothing past the end");
}
}
}
int main() {
try {
const auto device = OpenVulkanTestDevice();
if (!device) return VulkanTestSkipped;
Run(*device);
Check();
std::puts("scalar program end saved tests passed");
return 0;
} catch (const std::exception& error) {
std::cerr << error.what() << '\n';
return 1;
}
}
@@ -950,11 +950,16 @@ enum class RdnaOpcode : std::uint16_t {
SIncperflevel,
SDecperflevel,
SWaitIdle,
SRoundMode,
SGl1Inv,
SDcacheInv,
SDcacheWb,
SMemtime,
SMemrealtime,
SAtcProbe,
SAtcProbeBuffer,
SDcacheDiscard,
SDcacheDiscardX2,
BufferGl0Inv,
BufferGl1Inv,
SDenormMode,
@@ -563,6 +563,10 @@ RdnaOpcode cacheControlOpcode(RdnaInstructionFamily family, std::uint32_t opcode
case 0x1fu: return RdnaOpcode::SGl1Inv;
case 0x20u: return RdnaOpcode::SDcacheInv;
case 0x21u: return RdnaOpcode::SDcacheWb;
case 0x26u: return RdnaOpcode::SAtcProbe;
case 0x27u: return RdnaOpcode::SAtcProbeBuffer;
case 0x28u: return RdnaOpcode::SDcacheDiscard;
case 0x29u: return RdnaOpcode::SDcacheDiscardX2;
default: return RdnaOpcode::Invalid;
}
}
@@ -214,10 +214,13 @@ RdnaOpcode decodeSoppOpcode(std::uint32_t opcode) {
case 0x18u:
case 0x19u:
case 0x1au: return RdnaOpcode::SCbranchCdbg;
case 0x1bu:
case 0x1eu: return RdnaOpcode::SEndpgm;
case 0x20u: return RdnaOpcode::SInstPrefetch;
case 0x21u: return RdnaOpcode::SClause;
case 0x22u: return RdnaOpcode::SWaitIdle;
case 0x23u: return RdnaOpcode::SWaitcntDepctr;
case 0x24u: return RdnaOpcode::SRoundMode;
case 0x25u: return RdnaOpcode::SDenormMode;
case 0x28u: return RdnaOpcode::STtracedata;
default: throw std::invalid_argument("unsupported SOPP opcode " + std::to_string(opcode));
@@ -237,7 +240,7 @@ bool isSoppWaitOpcode(RdnaOpcode opcode) {
opcode == RdnaOpcode::STrap || opcode == RdnaOpcode::STtracedata || opcode == RdnaOpcode::SInstPrefetch ||
opcode == RdnaOpcode::SClause || opcode == RdnaOpcode::SCbranchCdbg || opcode == RdnaOpcode::SIcacheInv ||
opcode == RdnaOpcode::SIncperflevel || opcode == RdnaOpcode::SDecperflevel || opcode == RdnaOpcode::SWaitIdle ||
opcode == RdnaOpcode::SDenormMode;
opcode == RdnaOpcode::SRoundMode || opcode == RdnaOpcode::SDenormMode;
}
std::uint32_t scalarDestinationDwordCount(RdnaOpcode opcode) {
@@ -14,6 +14,10 @@ bool TranslationContext::emitMemory(const RdnaInstruction& inst) {
case RdnaOpcode::SGl1Inv:
case RdnaOpcode::SDcacheInv:
case RdnaOpcode::SDcacheWb:
case RdnaOpcode::SAtcProbe:
case RdnaOpcode::SAtcProbeBuffer:
case RdnaOpcode::SDcacheDiscard:
case RdnaOpcode::SDcacheDiscardX2:
case RdnaOpcode::BufferGl0Inv:
case RdnaOpcode::BufferGl1Inv:
emitControlNop();
@@ -405,6 +405,7 @@ bool TranslationContext::emitScalar(const RdnaInstruction& inst) {
case RdnaOpcode::SIcacheInv:
case RdnaOpcode::SIncperflevel:
case RdnaOpcode::SDecperflevel:
case RdnaOpcode::SRoundMode:
emitControlNop();
return true;
case RdnaOpcode::SDenormMode:
+1
View File
@@ -19,6 +19,7 @@ Throughout the project, every function at every stage either **does exactly what
- [libSceNpCommerce](../../core/libs/prx/libSceNpCommerce/Export.cpp) - the PS Store icon show/hide calls do nothing
- [sceVideoOutOpen](../../core/libs/prx/libSceVideoOut/src/Output.cpp) validates the priority and CPU affinity that the open param requests for the VideoOut service thread but does not apply them: the port's present and vblank threads are host threads, and guest priorities and affinities do not reach host scheduling
- The shader recompiler [skips baryctric coordinates](../../core/shader/recompiler/Recompiler.cpp) (is not even passed to SpirvTargetOptions at row 212).
- The shader recompiler [ignores `s_round_mode`](../../core/shader/recompiler/Translation/src/ScalarInstructions.cpp): float operations keep rounding to nearest even after it selects another rounding mode.
- [libSceAvPlayer](../../core/libs/prx/libSceAvPlayer/Export.cpp): `sceAvPlayerSetLogCallback` accepts a callback that is never called, as the player produces no log messages, and `sceAvPlayerSetAvailableBandwidth` has no effect, as it governs HLS sources, which `sceAvPlayerAddSource` does not implement.
- [sceAvPlayerSetTrickSpeed](../../core/libs/prx/libSceAvPlayer/src/Source.cpp) (libSceAvPlayer) with a negative speed runs the clock backwards but delivers no frames; when a forward speed is set again, playback resumes from the rewound time.