feat(shader): implement s_cmovk_i32, s_version and s_setreg_imm32_b32

s_cmovk_i32 writes the sign-extended 16-bit immediate when SCC is set.
s_version is a no-op marker. s_setreg_imm32_b32 takes its value from a
literal dword and is ignored like s_setreg_b32; both are now listed as
silent stubs in TechnicalDebt.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Adrià Franch
2026-10-02 08:52:42 +02:00
parent 870bdd814f
commit f994cc6ab7
7 changed files with 132 additions and 1 deletions
@@ -0,0 +1,98 @@
#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, 31> Code{
0x34060086, 0xbe9403ff, 0x11111111, 0xbe9503ff, 0x22222222, 0xbe9703ff, 0x33333333, 0xbf068080,
0xb1148001, 0xbf068180, 0xb1157fff, 0xbf068080, 0xb1171234, 0xb0801234, 0xba801801, 0x0000000f,
0xbe9603ff, 0x44444444, 0x7e140214, 0x7e160215, 0x7e180216, 0x7e1a0217, 0xe0701000, 0x80010a03,
0xe0701004, 0x80010b03, 0xe0701008, 0x80010c03, 0xe070100c, 0x80010d03, 0xbf810000,
};
constexpr std::uint32_t Expected[4] = {0xffff8001u, 0x22222222u, 0x44444444u, 0x00001234u};
constexpr const char* Names[4] = {"cmovk_taken", "cmovk_not_taken", "after_setreg_imm32", "cmovk_positive"};
void Fill(std::uint32_t, std::uint32_t*) {}
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 sopk misc: 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 < 4; ++index) Expect(tid, out[index], Expected[index], Names[index]);
}
}
}
int main() {
try {
const auto device = OpenVulkanTestDevice();
if (!device) return VulkanTestSkipped;
Run(*device);
Check();
std::puts("scalar sopk misc tests passed");
return 0;
} catch (const std::exception& error) {
std::cerr << error.what() << '\n';
return 1;
}
}
@@ -801,6 +801,9 @@ enum class RdnaOpcode : std::uint16_t {
SWaitcntDepctr,
SSendmsg,
SSetregB32,
SSetregImm32B32,
SCmovkI32,
SVersion,
SSleep,
SWakeup,
STrap,
@@ -19,6 +19,7 @@ bool IsScalarAluOpcode(RdnaOpcode opcode) {
case RdnaOpcode::SMovB32:
case RdnaOpcode::SMovB64:
case RdnaOpcode::SMovkI32:
case RdnaOpcode::SCmovkI32:
case RdnaOpcode::SAddI32:
case RdnaOpcode::SAddU32:
case RdnaOpcode::SSubI32:
@@ -159,6 +159,8 @@ RdnaOpcode decodeSopcOpcode(std::uint32_t opcode) {
RdnaOpcode decodeSopkOpcode(std::uint32_t opcode) {
switch (opcode) {
case 0x00u: return RdnaOpcode::SMovkI32;
case 0x01u: return RdnaOpcode::SVersion;
case 0x02u: return RdnaOpcode::SCmovkI32;
case 0x03u: return RdnaOpcode::SCmpEqI32;
case 0x04u: return RdnaOpcode::SCmpLgI32;
case 0x05u: return RdnaOpcode::SCmpGtI32;
@@ -174,6 +176,7 @@ RdnaOpcode decodeSopkOpcode(std::uint32_t opcode) {
case 0x0fu: return RdnaOpcode::SAddI32;
case 0x10u: return RdnaOpcode::SMulkI32;
case 0x13u: return RdnaOpcode::SSetregB32;
case 0x15u: return RdnaOpcode::SSetregImm32B32;
case 0x17u: return RdnaOpcode::SWaitcnt;
case 0x18u: return RdnaOpcode::SWaitcnt;
case 0x19u: return RdnaOpcode::SWaitcnt;
@@ -382,7 +385,20 @@ RdnaInstruction DecodeRdnaSopk(std::uint32_t programCounter, std::span<const std
instruction.sourceCount = 1;
SetRdnaRawWords(instruction, code, wordIndex, 1);
if (instruction.op == RdnaOpcode::SMovkI32) {
if (instruction.op == RdnaOpcode::SVersion) {
instruction.destination.kind = RdnaOperandKind::Null;
instruction.sourceCount = 0;
return instruction;
}
if (instruction.op == RdnaOpcode::SSetregImm32B32) {
instruction.destination.kind = RdnaOperandKind::Null;
instruction.source1 = instruction.source0;
instruction.source0 = DecodeRdnaScalarSource(0xffu, programCounter);
instruction.sourceCount = 2;
ReadRdnaLiteralOperands(code, wordIndex, instruction);
return instruction;
}
if (instruction.op == RdnaOpcode::SMovkI32 || instruction.op == RdnaOpcode::SCmovkI32) {
instruction.destination = DecodeRdnaScalarDestination(scalarRegister, programCounter);
return instruction;
}
@@ -309,6 +309,11 @@ EmbeddedFetchPlan EmbeddedVertexFetchAnalyzer::Analyze(const RdnaProgram& progra
dst.constant = inst.source0.value;
}
break;
case RdnaOpcode::SCmovkI32:
if (isScalarOperand(inst.destination)) {
clearScalarRange(sgprs, inst.destination, 1u);
}
break;
default:
if (isScalarLoad(inst.op)) {
if (isScalarOperand(inst.source0) && scalarSlot(inst.source0) < sgprs.size() && sgprs[scalarSlot(inst.source0)].kind == SgprValueKind::AttributeTable) {
@@ -51,8 +51,15 @@ bool TranslationContext::emitScalar(const RdnaInstruction& inst) {
scalarSelect64(inst, inst.destination);
return true;
case RdnaOpcode::SSetregB32:
case RdnaOpcode::SSetregImm32B32:
case RdnaOpcode::SVersion:
emitControlNop();
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())));
return true;
}
case RdnaOpcode::SWaitcnt:
emitWaitcnt();
return true;
+1
View File
@@ -16,6 +16,7 @@ Throughout the project, every function at every stage either **does exactly what
- [libSceHmd](../../core/libs/prx/libSceHmd/Export.cpp) implements only the disconnected-headset path: initialization succeeds, device queries report `NotDetected`, and opening a device returns `DeviceDisconnected`. Headset support, tracking, rendering and additional HMD exports are not implemented; SDK-level ABI compatibility and in-game behaviour remain unverified.
- [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 [ignores `s_setreg_b32` and `s_setreg_imm32_b32`](../../core/shader/recompiler/Translation/src/ScalarInstructions.cpp): writes to MODE (float rounding and denormal controls) and the other hardware registers have no effect.
- The shader recompiler [skips baryctric coordinates](../../core/shader/recompiler/Recompiler.cpp) (is not even passed to SpirvTargetOptions at row 212).
- [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.