feat(shader): decode s_setkill as s_endpgm #821

Closed
ebosido444-ai wants to merge 2 commits from upstream-pr/821 into main
ebosido444-ai commented 2026-10-06 07:11:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ebosido444-ai on 2026-10-06T07:11:53Z.


What

s_setkill (SOPP 0x0b) makes shaders die at translation today (unsupported SOPP opcode). Measured on RDNA2 hardware (gfx1035, same SOPP encodings) by adriadam10: s_setkill with ANY immediate ends the wave exactly like s_endpgm — a store before it is visible, nothing after it runs — so this decodes it as SEndpgm. Program slicing, CFG terminators and the SPIR-V path are shared with s_endpgm by construction, and S_SETKILL is credited in tools/progress.py through the existing OPCODE_VARIANTS seam of SEndpgm, the s_endpgm_saved pattern from #436. Shader progress: 1125 to 1126 out of 1166.

s_sethalt, s_sendmsghalt and s_code_end are deliberately not implemented and keep throwing as on main: the measurement shows halt freezes the wave until a debugger or trap handler resumes it (no Vulkan equivalent — discard or termination would pretend a plausible result where main is explicit), s_sendmsghalt halts after its message the same way, and s_code_end padding never reaches translation (DecodeRdnaProgram stops at s_endpgm) while executing it hangs the wave. All three are recorded in the updated docs/dev/TechnicalDebt.md entry with the measurement and ISA references. No shared path changes — one decode row that is a no-op for every other opcode.

Tested

Windows 11: core/libs/tests/ScalarSetkill.cpp (registered as scalar_setkill beside scalar_saveexec) checks decode identity with SEndpgm for immediates 0, 1 and 0xFFFF and that translation takes the SEndpgm path; scoped CMake/CTest suite (winlibs GCC 15.2.0 per BUILD.md): scalar_setkill, scalar_saveexec, scalar_bitcount64, guest_rtc — 4/4 passed. After the alias there is no distinct instruction left to execute, so this argues covered-by-existing instead of adding to tests/execution/ (#765 precedent). tools/progress.py: shaders 1125 -> 1126 out of 1166.

Checklist

  • Based on current main; #771 implements the same four opcodes with rows the hardware measurement rules out and is CONFLICTING with main — disposition discussed with adriadam10 in the thread; one open PR per function will hold either way
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4755426820 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/821). Originally posted by [ebosido444-ai](https://github.com/ebosido444-ai) on 2026-10-06T07:11:53Z. --- ### What `s_setkill` (SOPP 0x0b) makes shaders die at translation today (`unsupported SOPP opcode`). Measured on RDNA2 hardware (gfx1035, same SOPP encodings) by adriadam10: `s_setkill` with ANY immediate ends the wave exactly like `s_endpgm` — a store before it is visible, nothing after it runs — so this decodes it as `SEndpgm`. Program slicing, CFG terminators and the SPIR-V path are shared with `s_endpgm` by construction, and `S_SETKILL` is credited in `tools/progress.py` through the existing `OPCODE_VARIANTS` seam of `SEndpgm`, the `s_endpgm_saved` pattern from #436. Shader progress: 1125 to 1126 out of 1166. `s_sethalt`, `s_sendmsghalt` and `s_code_end` are deliberately not implemented and keep throwing as on main: the measurement shows halt freezes the wave until a debugger or trap handler resumes it (no Vulkan equivalent — discard or termination would pretend a plausible result where `main` is explicit), `s_sendmsghalt` halts after its message the same way, and `s_code_end` padding never reaches translation (`DecodeRdnaProgram` stops at `s_endpgm`) while executing it hangs the wave. All three are recorded in the updated `docs/dev/TechnicalDebt.md` entry with the measurement and ISA references. No shared path changes — one decode row that is a no-op for every other opcode. ### Tested Windows 11: `core/libs/tests/ScalarSetkill.cpp` (registered as `scalar_setkill` beside `scalar_saveexec`) checks decode identity with `SEndpgm` for immediates 0, 1 and 0xFFFF and that translation takes the `SEndpgm` path; scoped CMake/CTest suite (winlibs GCC 15.2.0 per BUILD.md): `scalar_setkill`, `scalar_saveexec`, `scalar_bitcount64`, `guest_rtc` — 4/4 passed. After the alias there is no distinct instruction left to execute, so this argues covered-by-existing instead of adding to `tests/execution/` (#765 precedent). `tools/progress.py`: shaders 1125 -> 1126 out of 1166. ### Checklist - [x] Based on current `main`; #771 implements the same four opcodes with rows the hardware measurement rules out and is CONFLICTING with main — disposition discussed with adriadam10 in the thread; one open PR per function will hold either way - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
adriadam10 commented 2026-10-06 07:56:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-06T07:56:24Z.


Thanks for picking these up. I measured them on RDNA2 hardware (gfx1035, same SOPP encodings as gfx1013) when I did #436, and left them out on purpose. Some of the lowerings here don't match what the hardware does:

  1. s_setkill ends the wave for any immediate, including 0. A store before it is visible and nothing after it runs, for s_setkill 0, s_setkill 1 and s_endpgm alike (compute kernel on the GPU, 32 lanes, store, then the instruction, then an overwrite). In this PR s_setkill 0 is a no-op, so the code after it keeps running, and s_setkill 1 is a per-invocation kill instead of the end of the wave. The exact translation is the same as s_endpgm (as s_endpgm_saved/s_endpgm_ordered_ps_done in #436).
  2. s_sethalt 1 and s_sendmsghalt don't kill the wave: s_sethalt 1 halts it on hardware (the dispatch never completes), and per the ISA s_sendmsghalt halts it after the message, until a debugger or the trap handler resumes it. Turning them into a discard gives a plausible result where main throws, which is what TechnicalDebt's "exactly what it should or throws" rules out.
  3. EmitDiscard emits OpKill in every stage. OpKill is only valid in the Fragment execution model, so a compute or vertex shader with s_setkill 1, s_sethalt 1 or s_sendmsghalt produces an invalid SPIR-V module. The existing kill path (EmitKillIfPixelValidMaskInactive) is only reached from pixel shaders.
  4. The test only checks that translation doesn't throw. It doesn't run anything, so it can't tell a discard from an end of program or a no-op. An execution test under tests/execution/ would.
  5. s_code_end: DecodeRdnaProgram already stops at s_endpgm when no branch goes past it, so the padding never reached translation. Executing it hangs the wave on hardware, so throwing (as main does) is already exact.

#771 implements the same four opcodes (CONTRIBUTING: one open PR per function), so one of the two will need to give way. I'd suggest keeping s_sethalt/s_sendmsghalt/s_code_end throwing, and decoding s_setkill as SEndpgm.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6011936139 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/821#issuecomment-6011936139). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-06T07:56:24Z. --- Thanks for picking these up. I measured them on RDNA2 hardware (gfx1035, same SOPP encodings as gfx1013) when I did #436, and left them out on purpose. Some of the lowerings here don't match what the hardware does: 1. **`s_setkill` ends the wave for any immediate, including 0.** A store before it is visible and nothing after it runs, for `s_setkill 0`, `s_setkill 1` and `s_endpgm` alike (compute kernel on the GPU, 32 lanes, store, then the instruction, then an overwrite). In this PR `s_setkill 0` is a no-op, so the code after it keeps running, and `s_setkill 1` is a per-invocation kill instead of the end of the wave. The exact translation is the same as `s_endpgm` (as `s_endpgm_saved`/`s_endpgm_ordered_ps_done` in #436). 2. **`s_sethalt 1` and `s_sendmsghalt` don't kill the wave**: `s_sethalt 1` halts it on hardware (the dispatch never completes), and per the ISA `s_sendmsghalt` halts it after the message, until a debugger or the trap handler resumes it. Turning them into a discard gives a plausible result where `main` throws, which is what TechnicalDebt's "exactly what it should or throws" rules out. 3. **`EmitDiscard` emits `OpKill` in every stage.** `OpKill` is only valid in the Fragment execution model, so a compute or vertex shader with `s_setkill 1`, `s_sethalt 1` or `s_sendmsghalt` produces an invalid SPIR-V module. The existing kill path (`EmitKillIfPixelValidMaskInactive`) is only reached from pixel shaders. 4. **The test only checks that translation doesn't throw.** It doesn't run anything, so it can't tell a discard from an end of program or a no-op. An execution test under `tests/execution/` would. 5. `s_code_end`: `DecodeRdnaProgram` already stops at `s_endpgm` when no branch goes past it, so the padding never reached translation. Executing it hangs the wave on hardware, so throwing (as `main` does) is already exact. #771 implements the same four opcodes (CONTRIBUTING: one open PR per function), so one of the two will need to give way. I'd suggest keeping `s_sethalt`/`s_sendmsghalt`/`s_code_end` throwing, and decoding `s_setkill` as `SEndpgm`.
ebosido444-ai commented 2026-10-06 08:01:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ebosido444-ai on 2026-10-06T08:01:41Z.


Measured beats read — all five points accepted, thanks for the gfx1035 data. Reworking to your suggested shape, pushed shortly: s_setkill decodes as SEndpgm for any immediate (credited through progress.py OPCODE_VARIANTS, the s_endpgm_saved pattern from #436), s_sethalt/s_sendmsghalt/s_code_end stay unimplemented and throw as on main, and the OpKill discard path is removed entirely — point 3 stands regardless, that module would have been invalid outside Fragment. On point 4: after the alias there is no distinct instruction left to execute, so the test checks decode identity with SEndpgm including the program-slicing and terminator paths and argues covered-by-existing rather than duplicating the execution harness (#765 precedent) — say if you want the store/overwrite execution probe anyway. On #771: happy to yield this to Kikoarl reworked to your shape if you prefer that attribution; note its current rows make s_setkill 0/s_sethalt 0 no-ops, which your measurement rules out, and it is CONFLICTING with main. One open PR per function will hold either way.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6012011410 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/821#issuecomment-6012011410). Originally posted by [ebosido444-ai](https://github.com/ebosido444-ai) on 2026-10-06T08:01:41Z. --- Measured beats read — all five points accepted, thanks for the gfx1035 data. Reworking to your suggested shape, pushed shortly: `s_setkill` decodes as `SEndpgm` for any immediate (credited through progress.py `OPCODE_VARIANTS`, the `s_endpgm_saved` pattern from #436), `s_sethalt`/`s_sendmsghalt`/`s_code_end` stay unimplemented and throw as on main, and the `OpKill` discard path is removed entirely — point 3 stands regardless, that module would have been invalid outside Fragment. On point 4: after the alias there is no distinct instruction left to execute, so the test checks decode identity with `SEndpgm` including the program-slicing and terminator paths and argues covered-by-existing rather than duplicating the execution harness (#765 precedent) — say if you want the store/overwrite execution probe anyway. On #771: happy to yield this to Kikoarl reworked to your shape if you prefer that attribution; note its current rows make `s_setkill 0`/`s_sethalt 0` no-ops, which your measurement rules out, and it is CONFLICTING with main. One open PR per function will hold either way.
adriadam10 commented 2026-10-06 08:57:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-06T08:57:10Z.


Thanks, this matches what I measured. Yes to the execution probe: it's ready, and you're welcome to take it. It reuses tests/execution/ScalarProgramEnd.cpp (the #436 test) with a second kernel. Lanes store before s_setkill 0 and again on a path that ends with s_setkill 1, and the kernel checks that nothing past either one is written. The shape and the expected results are those of the hardware run (gfx1035). It passes on RADV and lavapipe, takes 0 s cold on CI's lavapipe (Mesa 25.2.8), and fails with unsupported SOPP opcode 11 without the decoder line. With it, core/libs/tests/ScalarSetkill.cpp and its CMake block could go: decoding is covered by the execution path.

patch
diff --git a/core/libs/prx/libSceAgcDriver/tests/execution/ScalarProgramEnd.cpp b/core/libs/prx/libSceAgcDriver/tests/execution/ScalarProgramEnd.cpp
index a4362f4c..335a99a9 100644
--- a/core/libs/prx/libSceAgcDriver/tests/execution/ScalarProgramEnd.cpp
+++ b/core/libs/prx/libSceAgcDriver/tests/execution/ScalarProgramEnd.cpp
@@ -30,6 +30,11 @@ alignas(256) constexpr std::array<std::uint32_t, 30> Code{
     0xe0701000, 0x80010603, 0xbf9b0000, 0xe0701004, 0x80010603, 0xbf810000,
 };
 
+alignas(256) constexpr std::array<std::uint32_t, 20> SetkillCode{
+    0x34020084, 0x34060086, 0xe0301000, 0x80000401, 0xbf8c3f70, 0x4a0a0881, 0x7e0c02ff, 0x00000bad, 0xbf060000, 0xbf840007,
+    0xbf840003, 0xe0701000, 0x80010503, 0xbf8b0000, 0xe0701000, 0x80010603, 0xbf8b0001, 0xe0701004, 0x80010603, 0xbf810000,
+};
+
 alignas(256) constexpr std::array<std::uint32_t, 2> RoundTowardZeroCode{0xbfa40003, 0xbf810000};
 
 void Fill(std::uint32_t tid, std::uint32_t* words) { words[0] = tid * 0x01010101u + 7u; }
@@ -74,7 +79,7 @@ void ExpectRefused(AgcDriver::VulkanDevice& device) {
     Require(refused, "scalar program end: s_round_mode 3 was translated");
 }
 
-void Run(AgcDriver::VulkanDevice& device) {
+void Run(AgcDriver::VulkanDevice& device, std::span<const std::uint32_t> code) {
     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);
@@ -82,7 +87,6 @@ void Run(AgcDriver::VulkanDevice& device) {
     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 auto result = ShaderRecompiler::Recompile(Request(device, code, userData, memory));
     device.Dispatch(result, 1, 1, 1, {}, reinterpret_cast<std::uintptr_t>(code.data()));
@@ -104,7 +108,9 @@ int main() {
     try {
         const auto device = OpenVulkanTestDevice();
         if (!device) return VulkanTestSkipped;
-        Run(*device);
+        Run(*device, Code);
+        Check();
+        Run(*device, SetkillCode);
         Check();
         ExpectRefused(*device);
         std::puts("scalar program end tests passed");
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6012866440 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/821#issuecomment-6012866440). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-06T08:57:10Z. --- Thanks, this matches what I measured. Yes to the execution probe: it's ready, and you're welcome to take it. It reuses `tests/execution/ScalarProgramEnd.cpp` (the #436 test) with a second kernel. Lanes store before `s_setkill 0` and again on a path that ends with `s_setkill 1`, and the kernel checks that nothing past either one is written. The shape and the expected results are those of the hardware run (gfx1035). It passes on RADV and lavapipe, takes 0 s cold on CI's lavapipe (Mesa 25.2.8), and fails with `unsupported SOPP opcode 11` without the decoder line. With it, `core/libs/tests/ScalarSetkill.cpp` and its CMake block could go: decoding is covered by the execution path. <details><summary>patch</summary> ```diff diff --git a/core/libs/prx/libSceAgcDriver/tests/execution/ScalarProgramEnd.cpp b/core/libs/prx/libSceAgcDriver/tests/execution/ScalarProgramEnd.cpp index a4362f4c..335a99a9 100644 --- a/core/libs/prx/libSceAgcDriver/tests/execution/ScalarProgramEnd.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/execution/ScalarProgramEnd.cpp @@ -30,6 +30,11 @@ alignas(256) constexpr std::array<std::uint32_t, 30> Code{ 0xe0701000, 0x80010603, 0xbf9b0000, 0xe0701004, 0x80010603, 0xbf810000, }; +alignas(256) constexpr std::array<std::uint32_t, 20> SetkillCode{ + 0x34020084, 0x34060086, 0xe0301000, 0x80000401, 0xbf8c3f70, 0x4a0a0881, 0x7e0c02ff, 0x00000bad, 0xbf060000, 0xbf840007, + 0xbf840003, 0xe0701000, 0x80010503, 0xbf8b0000, 0xe0701000, 0x80010603, 0xbf8b0001, 0xe0701004, 0x80010603, 0xbf810000, +}; + alignas(256) constexpr std::array<std::uint32_t, 2> RoundTowardZeroCode{0xbfa40003, 0xbf810000}; void Fill(std::uint32_t tid, std::uint32_t* words) { words[0] = tid * 0x01010101u + 7u; } @@ -74,7 +79,7 @@ void ExpectRefused(AgcDriver::VulkanDevice& device) { Require(refused, "scalar program end: s_round_mode 3 was translated"); } -void Run(AgcDriver::VulkanDevice& device) { +void Run(AgcDriver::VulkanDevice& device, std::span<const std::uint32_t> code) { 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); @@ -82,7 +87,6 @@ void Run(AgcDriver::VulkanDevice& device) { 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 auto result = ShaderRecompiler::Recompile(Request(device, code, userData, memory)); device.Dispatch(result, 1, 1, 1, {}, reinterpret_cast<std::uintptr_t>(code.data())); @@ -104,7 +108,9 @@ int main() { try { const auto device = OpenVulkanTestDevice(); if (!device) return VulkanTestSkipped; - Run(*device); + Run(*device, Code); + Check(); + Run(*device, SetkillCode); Check(); ExpectRefused(*device); std::puts("scalar program end tests passed"); ``` </details>
ebosido444-ai commented 2026-10-06 09:50:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ebosido444-ai on 2026-10-06T09:50:33Z.


Took the probe exactly as you provided it (744b61f5): ScalarProgramEnd.cpp gains the SetkillCode kernel and the Run(code) parameterisation, and per your note core/libs/tests/ScalarSetkill.cpp plus its CMake block are deleted — the execution path covers decoding and fails with unsupported SOPP opcode 11 without the decoder line. Your RADV/lavapipe/CI runs stand as the test evidence in the body; I could not improve on them. Thank you for the measurement work and the patch.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6013714457 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/821#issuecomment-6013714457). Originally posted by [ebosido444-ai](https://github.com/ebosido444-ai) on 2026-10-06T09:50:33Z. --- Took the probe exactly as you provided it (744b61f5): ScalarProgramEnd.cpp gains the SetkillCode kernel and the Run(code) parameterisation, and per your note core/libs/tests/ScalarSetkill.cpp plus its CMake block are deleted — the execution path covers decoding and fails with unsupported SOPP opcode 11 without the decoder line. Your RADV/lavapipe/CI runs stand as the test evidence in the body; I could not improve on them. Thank you for the measurement work and the patch.
adriadam10 commented 2026-10-07 07:27:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T07:27:13Z.


Thanks for reworking this to match the hardware measurement. The same change landed on main with #771 (c8e4a17f8): s_setkill decodes as SEndpgm, the SetkillCode kernel is in ScalarProgramEnd.cpp, the TechnicalDebt entry is there, and S_SETKILL is credited in progress.py. Apart from a blank line in CMakeLists and the TechnicalDebt wording, this PR's diff is identical to what's on main now, so I'm closing it as a duplicate. s_sethalt, s_sendmsghalt and s_code_end still throw on main, which is the state this PR wanted for them too.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6033120449 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/821#issuecomment-6033120449). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-07T07:27:13Z. --- Thanks for reworking this to match the hardware measurement. The same change landed on `main` with #771 (c8e4a17f8): `s_setkill` decodes as `SEndpgm`, the `SetkillCode` kernel is in `ScalarProgramEnd.cpp`, the TechnicalDebt entry is there, and `S_SETKILL` is credited in `progress.py`. Apart from a blank line in CMakeLists and the TechnicalDebt wording, this PR's diff is identical to what's on `main` now, so I'm closing it as a duplicate. `s_sethalt`, `s_sendmsghalt` and `s_code_end` still throw on `main`, which is the state this PR wanted for them too.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!821
No description provided.