diff --git a/core/kyty/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp b/core/kyty/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp index babc2ddfa43..7a3fbb1c33e 100644 --- a/core/kyty/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp +++ b/core/kyty/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp @@ -2559,9 +2559,17 @@ uint32_t EmitAppendConsume(ValueEmitContext& ctx, const IR::Inst& inst) { Binary(state, spv::OpINotEqual, TypeBool(state), count, ConstantU32(state, 0)), bounds)); const auto atomic = EmitValueOrZeroIfCondition(state, condition, [&]() { + const auto pointer = EmitMemoryElementPointer(state, access, index); const auto value = state.builder.AllocateId(); + if (mem.kind == IR::ResourceKind::Lds && PrivateLdsStorage(state)) { + state.builder.AddFunction(spv::OpLoad, TypeU32(state), value, pointer); + state.builder.AddFunction( + spv::OpStore, pointer, + Binary(state, append ? spv::OpIAdd : spv::OpISub, TypeU32(state), value, count)); + return value; + } state.builder.AddFunction(append ? spv::OpAtomicIAdd : spv::OpAtomicISub, TypeU32(state), - value, EmitMemoryElementPointer(state, access, index), + value, pointer, ConstantU32(state, mem.kind == IR::ResourceKind::Gds ? spv::ScopeDevice : spv::ScopeWorkgroup), diff --git a/core/libs/prx/libSceAgcDriver/KytyShim/fuzz/ShaderRecompilerRun.hpp b/core/libs/prx/libSceAgcDriver/KytyShim/fuzz/ShaderRecompilerRun.hpp index 11ba566d62c..6d89fb02e6e 100644 --- a/core/libs/prx/libSceAgcDriver/KytyShim/fuzz/ShaderRecompilerRun.hpp +++ b/core/libs/prx/libSceAgcDriver/KytyShim/fuzz/ShaderRecompilerRun.hpp @@ -71,7 +71,9 @@ inline void ReportInvalid(const std::string& message, std::span } } -inline void Run(std::span original, uint8_t mode, uint8_t shape, std::string* refusal = nullptr) { +inline void Run(std::span original, uint8_t mode, uint8_t shape, + std::string* refusal = nullptr, bool* emitted = nullptr) { + if (emitted != nullptr) *emitted = false; static const auto profile = Profile(); std::vector storage(original.begin(), original.end()); if (std::getenv("KYTY_FUZZ_PAD") != nullptr) storage.resize(original.size() + 16u, 0u); @@ -134,6 +136,7 @@ inline void Run(std::span original, uint8_t mode, uint8_t shape, } if (!IR::ResourceSpecializationFits(translated.program, specialization)) return; auto compiled = Recompiler::CompileProgram(std::move(translated), options, specialization, 0); + if (emitted != nullptr) *emitted = !compiled.spirv.empty(); const char* policy = std::getenv("KYTY_FUZZ_SPIRV"); if (!compiled.spirv.empty() && policy != nullptr && std::strcmp(policy, "off") != 0 && policy[0] != 0) { std::string message; diff --git a/core/libs/prx/libSceAgcDriver/KytyShim/tests/RecompilerRobustness.cpp b/core/libs/prx/libSceAgcDriver/KytyShim/tests/RecompilerRobustness.cpp index ad06d263f04..ec9201f7d7f 100644 --- a/core/libs/prx/libSceAgcDriver/KytyShim/tests/RecompilerRobustness.cpp +++ b/core/libs/prx/libSceAgcDriver/KytyShim/tests/RecompilerRobustness.cpp @@ -14,9 +14,15 @@ struct Case { uint8_t mode; uint8_t shape; std::vector words; + bool requires_spirv = false; }; const std::vector Cases = { + {"lds-append-in-a-vertex-shader", 0x03, 0x00, {0xd8f80000u, 0u, 0xbf810000u}, true}, + {"lds-consume-in-a-vertex-shader", 0x03, 0x00, {0xd8f40000u, 0u, 0xbf810000u}, true}, + {"lds-append-in-a-pixel-shader", 0x04, 0x00, {0xd8f80000u, 0u, 0xbf810000u}, true}, + {"lds-append-in-a-compute-shader", 0x02, 0x00, {0xd8f80000u, 0u, 0xbf810000u}, true}, + {"lds-consume-in-a-compute-shader", 0x02, 0x00, {0xd8f40000u, 0u, 0xbf810000u}, true}, {"branch-target-outside-the-program", 0x00, 0x00, {0xbf827fffu, 0xbf810000u}}, {"stale-lane-spill-after-read-lane-elimination", 0x32, 0x00, {0xd7610014u, 0x0201e205u, 0xbf810000u}}, {"backward-branch-before-the-program", 0x00, 0x00, {0xbf828000u, 0xbf810000u}}, @@ -146,7 +152,12 @@ int main(int argc, char** argv) { for (const auto& entry: Cases) { if (argc >= 2 && std::string_view(argv[1]) != entry.name) continue; found = true; - KytyFuzz::Run(entry.words, entry.mode, entry.shape); + bool emitted = false; + KytyFuzz::Run(entry.words, entry.mode, entry.shape, nullptr, &emitted); + if (entry.requires_spirv && !emitted) { + std::printf("%s: FAILED, did not emit SPIR-V\n", entry.name); + return 1; + } std::printf("%s: ok\n", entry.name); } for (const auto& entry: Refusals) { diff --git a/docs/dev/debt/changes/fix-kyty-private-lds-append-consume.md b/docs/dev/debt/changes/fix-kyty-private-lds-append-consume.md new file mode 100644 index 00000000000..4f61f8365a3 --- /dev/null +++ b/docs/dev/debt/changes/fix-kyty-private-lds-append-consume.md @@ -0,0 +1,5 @@ +# kyty + +## add Functional + +- [DS_APPEND and DS_CONSUME in vertex and pixel shaders](../../../core/kyty/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp) use per-invocation LDS, so their update is a load, addition or subtraction, and store. The console behavior of these instructions outside a compute workgroup is unmeasured. Closes when: compared with a PS5 shader or hardware oracle.