mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
fix(shader): translate s_setreg_imm32_b32 only for round to nearest even in MODE
Any other field or value throws. The existing s_setreg_b32 no-op is recorded under Functional technical debt instead of silent stubs. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -25,11 +25,13 @@ 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,
|
||||
0xb1148001, 0xbf068180, 0xb1157fff, 0xbf068080, 0xb1171234, 0xb0801234, 0xba801801, 0x00000000,
|
||||
0xbe9603ff, 0x44444444, 0x7e140214, 0x7e160215, 0x7e180216, 0x7e1a0217, 0xe0701000, 0x80010a03,
|
||||
0xe0701004, 0x80010b03, 0xe0701008, 0x80010c03, 0xe070100c, 0x80010d03, 0xbf810000,
|
||||
};
|
||||
|
||||
alignas(256) constexpr std::array<std::uint32_t, 3> RoundTowardZeroCode{0xba801801, 0x0000000f, 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"};
|
||||
|
||||
@@ -50,6 +52,31 @@ void Expect(std::uint32_t tid, std::uint32_t actual, std::uint32_t expected, con
|
||||
Require(actual == expected, std::string("scalar sopk misc: lane ") + std::to_string(tid) + " " + name + " is " + Hex(actual) + ", expected " + Hex(expected));
|
||||
}
|
||||
|
||||
ShaderRecompiler::RecompileRequest Request(AgcDriver::VulkanDevice& device, std::span<const std::uint32_t> code, std::span<const std::uint32_t> userData, std::span<const ShaderRecompiler::MemoryRegion> memory) {
|
||||
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;
|
||||
return request;
|
||||
}
|
||||
|
||||
void ExpectRefused(AgcDriver::VulkanDevice& device) {
|
||||
const std::span<const std::uint32_t> code(RoundTowardZeroCode);
|
||||
const std::array<ShaderRecompiler::MemoryRegion, 1> memory{{{reinterpret_cast<std::uintptr_t>(code.data()), std::as_bytes(code)}}};
|
||||
const std::vector<std::uint32_t> userData(8, 0u);
|
||||
bool refused = false;
|
||||
try {
|
||||
ShaderRecompiler::Recompile(Request(device, code, userData, memory));
|
||||
} catch (const std::exception&) {
|
||||
refused = true;
|
||||
}
|
||||
Require(refused, "scalar sopk misc: s_setreg_imm32_b32 writing round toward zero to MODE was translated");
|
||||
}
|
||||
|
||||
void Run(AgcDriver::VulkanDevice& device) {
|
||||
for (std::uint32_t tid = 0; tid < Threads; ++tid) Fill(tid, &Input[tid * Inputs]);
|
||||
Output.fill(0xdeadbeefu);
|
||||
@@ -60,15 +87,7 @@ void Run(AgcDriver::VulkanDevice& device) {
|
||||
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);
|
||||
const auto result = ShaderRecompiler::Recompile(Request(device, code, userData, memory));
|
||||
device.Dispatch(result, 1, 1, 1, {}, reinterpret_cast<std::uintptr_t>(code.data()));
|
||||
device.WaitIdle();
|
||||
}
|
||||
@@ -89,6 +108,7 @@ int main() {
|
||||
if (!device) return VulkanTestSkipped;
|
||||
Run(*device);
|
||||
Check();
|
||||
ExpectRefused(*device);
|
||||
std::puts("scalar sopk misc tests passed");
|
||||
return 0;
|
||||
} catch (const std::exception& error) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "Translation/ScalarInstructions.hpp"
|
||||
#include "Translation/TranslationContext.hpp"
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
namespace ShaderRecompiler {
|
||||
|
||||
@@ -51,10 +52,20 @@ 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::SSetregImm32B32: {
|
||||
const std::uint32_t field = inst.source1.value;
|
||||
const std::uint32_t offset = (field >> 6u) & 0x1fu;
|
||||
const std::uint32_t size = ((field >> 11u) & 0x1fu) + 1u;
|
||||
const std::uint64_t written = static_cast<std::uint64_t>(inst.source0.value) & ((std::uint64_t{1} << size) - 1u);
|
||||
if ((field & 0x3fu) != 1u || offset + size > 4u || written != 0u) {
|
||||
throw std::runtime_error("s_setreg_imm32_b32 at pc " + std::to_string(inst.programCounter) + " writes a hardware register field other than round to nearest even in MODE");
|
||||
}
|
||||
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())));
|
||||
|
||||
@@ -16,7 +16,6 @@ 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.
|
||||
@@ -52,6 +51,7 @@ Throughout the project, every function at every stage either **does exactly what
|
||||
|
||||
### Functional
|
||||
|
||||
- The shader recompiler [ignores `s_setreg_b32`](../../core/shader/recompiler/Translation/src/ScalarInstructions.cpp): writes to MODE (float rounding and denormal controls) and the other hardware registers have no effect.
|
||||
- [Shader recompilation](../../core/shader/recompiler/Recompiler.cpp) currently occurs right before it was transferred to Vulkan with caching, but should be moved to the [relinker](../../core/relinker/main.cpp) stage. For this purpose, [shader/recompiler](../../core/shader/recompiler) was written completely independently from [libs/prx](../../core/libs/prx).
|
||||
- The executable file that [relinker](../../core/relinker/elfpatcher/src/windows/WindowsPeWriter.cpp) generates opens the console when launched, which is inconvenient for playability.
|
||||
- [libSceJpegEnc](../../core/libs/prx/libSceJpegEnc/Export.cpp) encodes 4:2:2 sampling requests with 4:2:0 chroma subsampling, and grayscale requests as a 3-component JPEG with neutral chroma instead of a single-component one: the [JPEG encoder](../../core/Decoder/Jpeg/src/Jpeg.cpp) (stb) only produces 3-component 4:2:0 and 4:4:4 images.
|
||||
|
||||
Reference in New Issue
Block a user