feat(shader): decode s_setkill as s_endpgm #771

Merged
Kikoarl merged 2 commits from upstream-pr/771 into main 2026-10-07 06:50:36 +00:00
Kikoarl commented 2026-10-05 22:47:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-05T22:47:47Z.


What

Decode s_setkill (SOPP opcode 0x0b) as SEndpgm.

Per hardware measurement on real RDNA 2 hardware (gfx1035) by adriadam10, s_setkill with any immediate ends the wave identically to s_endpgm (a store before it is visible, and nothing past it runs). Decoding directly as SEndpgm shares CFG terminators, program slicing, and SPIR-V emission with s_endpgm by construction, matching the s_endpgm_saved pattern from #436.

s_sethalt, s_sendmsghalt, and s_code_end are deliberately left throwing as on main: halt freezes the wave until a debugger or trap handler resumes it (unrepresentable in SPIR-V), s_sendmsghalt halts similarly, and s_code_end is excluded from program decoding while executing it hangs the wave. All three are documented in docs/dev/TechnicalDebt.md.

Credited in tools/progress.py under OPCODE_VARIANTS["SEndpgm"].

Tested

  • Linux x86_64 tmpfs RAM disk build.
  • Execution test in core/libs/prx/libSceAgcDriver/tests/execution/ScalarProgramEnd.cpp parameterised and verified with SetkillCode kernel, confirming stores before s_setkill are visible and stores after it do not execute.
  • tools/progress.py confirms positive progress delta (+1 shader instruction).

Checklist

  • Based on current main; no other open PR implements the same functions
  • 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 (attach them to this PR)
  • 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:4751678811 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/771). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-05T22:47:47Z. --- ### What Decode `s_setkill` (SOPP opcode `0x0b`) as `SEndpgm`. Per hardware measurement on real RDNA 2 hardware (gfx1035) by adriadam10, `s_setkill` with any immediate ends the wave identically to `s_endpgm` (a store before it is visible, and nothing past it runs). Decoding directly as `SEndpgm` shares CFG terminators, program slicing, and SPIR-V emission with `s_endpgm` by construction, matching the `s_endpgm_saved` pattern from #436. `s_sethalt`, `s_sendmsghalt`, and `s_code_end` are deliberately left throwing as on `main`: halt freezes the wave until a debugger or trap handler resumes it (unrepresentable in SPIR-V), `s_sendmsghalt` halts similarly, and `s_code_end` is excluded from program decoding while executing it hangs the wave. All three are documented in `docs/dev/TechnicalDebt.md`. Credited in `tools/progress.py` under `OPCODE_VARIANTS["SEndpgm"]`. ### Tested - Linux x86_64 tmpfs RAM disk build. - Execution test in `core/libs/prx/libSceAgcDriver/tests/execution/ScalarProgramEnd.cpp` parameterised and verified with `SetkillCode` kernel, confirming stores before `s_setkill` are visible and stores after it do not execute. - `tools/progress.py` confirms positive progress delta (+1 shader instruction). ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [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 (attach them to this PR) - [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
oneandonlydean commented 2026-10-05 23:37:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T23:37:35Z.


Thanks. The SOPP opcode numbers match the RDNA2 ISA (0x0b s_setkill, 0x0d s_sethalt, 0x11 s_sendmsghalt, 0x1f s_code_end), and treating s_code_end as the end of the program in the decoder and graph builder is fine, since it only marks padding after the last instruction.

The other three now translate to a no-op (or a plain sendmsg), though, while on main they throw:

  • s_setkill 1 stops the wave, and s_sethalt 1 halts it until the host resumes it. As a no-op the wave keeps running, so any stores or exports after them still happen.
  • s_sendmsghalt sends the message and then halts. The halt is dropped.

The project's rule is that unimplemented behaviour throws, or is listed as a silent stub in docs/dev/TechnicalDebt.md. As with #766, if no title needs these yet, I'd keep the decoding and make the translation throw for s_setkill/s_sethalt with a non-zero immediate and for s_sendmsghalt (the immediate-0 forms are genuine no-ops). Otherwise please add a TechnicalDebt entry that says the halt/kill is ignored. Then scalar_control_flow would check the throw instead of ControlNop.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6005563319 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/771#issuecomment-6005563319). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T23:37:35Z. --- Thanks. The SOPP opcode numbers match the RDNA2 ISA (0x0b `s_setkill`, 0x0d `s_sethalt`, 0x11 `s_sendmsghalt`, 0x1f `s_code_end`), and treating `s_code_end` as the end of the program in the decoder and graph builder is fine, since it only marks padding after the last instruction. The other three now translate to a no-op (or a plain `sendmsg`), though, while on main they throw: - `s_setkill 1` stops the wave, and `s_sethalt 1` halts it until the host resumes it. As a no-op the wave keeps running, so any stores or exports after them still happen. - `s_sendmsghalt` sends the message and then halts. The halt is dropped. The project's rule is that unimplemented behaviour throws, or is listed as a silent stub in `docs/dev/TechnicalDebt.md`. As with #766, if no title needs these yet, I'd keep the decoding and make the translation throw for `s_setkill`/`s_sethalt` with a non-zero immediate and for `s_sendmsghalt` (the immediate-0 forms are genuine no-ops). Otherwise please add a TechnicalDebt entry that says the halt/kill is ignored. Then `scalar_control_flow` would check the throw instead of `ControlNop`.
Kikoarl commented 2026-10-06 05:11:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-06T05:11:55Z.


Thanks for the review. I've updated the PR accordingly:

  • s_setkill and s_sethalt with immediate 0 remain no-ops, while non-zero forms now throw.
  • s_sendmsghalt now throws since the halt is not yet modelled.
  • Updated the unit tests in scalar_control_flow to verify both the immediate 0 no-op behavior and the throw paths.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6009789129 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/771#issuecomment-6009789129). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-06T05:11:55Z. --- Thanks for the review. I've updated the PR accordingly: - `s_setkill` and `s_sethalt` with immediate 0 remain no-ops, while non-zero forms now throw. - `s_sendmsghalt` now throws since the halt is not yet modelled. - Updated the unit tests in `scalar_control_flow` to verify both the immediate 0 no-op behavior and the throw paths.
adriadam10 commented 2026-10-06 07:56:25 +00:00 (Migrated from github.com)

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


I measured these on RDNA2 hardware (gfx1035, same SOPP encodings as gfx1013): a 32-lane compute kernel that stores, runs the instruction, then overwrites. Two of the lowerings here don't match it:

  1. s_setkill 0 ends the wave, like s_endpgm. The store before it is visible and nothing after it runs, for s_setkill 0 and s_setkill 1 alike. Here s_setkill 0 is a no-op, so the code after it keeps running. Both values translate exactly as SEndpgm (as s_endpgm_saved/s_endpgm_ordered_ps_done in #436).
  2. s_code_end hangs the wave if it is executed (the kernel never completes). Here, when control flow reaches it, it becomes a Return terminator, so the shader ends quietly where main throws. The padding past s_endpgm never reached translation anyway, since DecodeRdnaProgram stops there when no branch goes past it. Throwing when it is reached keeps it exact.

The rest matches what I measured: s_sethalt 0 lets execution continue, and s_sethalt 1 hangs the kernel, so throwing is right; s_sendmsghalt throwing is right too.

The test only checks decoding and the IR shape (ControlNop present). An execution test under tests/execution/ would have caught point 1: run a store, the instruction, then a second store, and check which ones land.

Same findings posted on #821, which implements the same four opcodes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6011936450 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/771#issuecomment-6011936450). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-06T07:56:25Z. --- I measured these on RDNA2 hardware (gfx1035, same SOPP encodings as gfx1013): a 32-lane compute kernel that stores, runs the instruction, then overwrites. Two of the lowerings here don't match it: 1. **`s_setkill 0` ends the wave, like `s_endpgm`.** The store before it is visible and nothing after it runs, for `s_setkill 0` and `s_setkill 1` alike. Here `s_setkill 0` is a no-op, so the code after it keeps running. Both values translate exactly as `SEndpgm` (as `s_endpgm_saved`/`s_endpgm_ordered_ps_done` in #436). 2. **`s_code_end` hangs the wave if it is executed** (the kernel never completes). Here, when control flow reaches it, it becomes a `Return` terminator, so the shader ends quietly where `main` throws. The padding past `s_endpgm` never reached translation anyway, since `DecodeRdnaProgram` stops there when no branch goes past it. Throwing when it is reached keeps it exact. The rest matches what I measured: `s_sethalt 0` lets execution continue, and `s_sethalt 1` hangs the kernel, so throwing is right; `s_sendmsghalt` throwing is right too. The test only checks decoding and the IR shape (`ControlNop` present). An execution test under `tests/execution/` would have caught point 1: run a store, the instruction, then a second store, and check which ones land. Same findings posted on #821, which implements the same four opcodes.
oneandonlydean commented 2026-10-06 09:27:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-06T09:27:49Z.


Thanks, that covers everything I asked. Non-zero s_setkill/s_sethalt and s_sendmsghalt now throw, the immediate-0 forms stay no-ops, and scalar_control_flow tests both cases. s_code_end ending the program in the decoder and graph builder is fine as before.

The PR now conflicts with main in core/libs/prx/libSceAgcDriver/CMakeLists.txt. Main added the scalar_scratch_load test block right after scalar_bitcount64, which is where scalar_control_flow goes. Could you rebase? Keep both blocks one after the other, each with its own if(WIN32) ... endif().

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6013354470 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/771#issuecomment-6013354470). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-06T09:27:49Z. --- Thanks, that covers everything I asked. Non-zero `s_setkill`/`s_sethalt` and `s_sendmsghalt` now throw, the immediate-0 forms stay no-ops, and `scalar_control_flow` tests both cases. `s_code_end` ending the program in the decoder and graph builder is fine as before. The PR now conflicts with main in `core/libs/prx/libSceAgcDriver/CMakeLists.txt`. Main added the `scalar_scratch_load` test block right after `scalar_bitcount64`, which is where `scalar_control_flow` goes. Could you rebase? Keep both blocks one after the other, each with its own `if(WIN32) ... endif()`.
Kikoarl commented 2026-10-06 13:26:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-06T13:26:33Z.


@oneandonlydean Rebased onto current main and resolved the conflict in CMakeLists.txt, keeping both scalar_scratch_load and scalar_control_flow blocks sequential with their respective if(WIN32) checks. Local tests pass cleanly.

@adriadam10 Thanks for taking the time to test on real RDNA2 hardware. Very interesting and valuable insights on s_setkill and s_code_end. We can definitely refine s_setkill to lower as SEndpgm in a follow-up PR once this baseline is merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6017284723 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/771#issuecomment-6017284723). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-06T13:26:33Z. --- @oneandonlydean Rebased onto current `main` and resolved the conflict in `CMakeLists.txt`, keeping both `scalar_scratch_load` and `scalar_control_flow` blocks sequential with their respective `if(WIN32)` checks. Local tests pass cleanly. @adriadam10 Thanks for taking the time to test on real RDNA2 hardware. Very interesting and valuable insights on `s_setkill` and `s_code_end`. We can definitely refine `s_setkill` to lower as `SEndpgm` in a follow-up PR once this baseline is merged.
github-actions[bot] commented 2026-10-06 15:13:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-06T15:13:32Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#821 docs/dev/TechnicalDebt.md L46
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6019321912 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/771#issuecomment-6019321912). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-06T15:13:32Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #821 | `docs/dev/TechnicalDebt.md` [L46](https://github.com/boykopovar/AnyPS5/blob/8a126b7b881e1dfc6275b2282491a96892fe690c/docs/dev/TechnicalDebt.md#L46) | | |
Kikoarl commented 2026-10-06 15:42:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-06T15:42:09Z.


Updated per @adriadam10's hardware measurements on real RDNA2 hardware:

  • s_setkill is decoded directly as SEndpgm (ending the wave identically to s_endpgm regardless of immediate).
  • Parameterised ScalarProgramEnd.cpp and added the SetkillCode execution test verifying that stores before s_setkill land and stores after it do not execute.
  • s_sethalt, s_sendmsghalt, and s_code_end deliberately remain throwing as on main and documented in docs/dev/TechnicalDebt.md.
  • Credited under OPCODE_VARIANTS["SEndpgm"] in tools/progress.py.
  • Rebased cleanly on latest main, with both Linux and Windows CI tests passing green.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6019888120 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/771#issuecomment-6019888120). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-06T15:42:09Z. --- Updated per @adriadam10's hardware measurements on real RDNA2 hardware: - `s_setkill` is decoded directly as `SEndpgm` (ending the wave identically to `s_endpgm` regardless of immediate). - Parameterised `ScalarProgramEnd.cpp` and added the `SetkillCode` execution test verifying that stores before `s_setkill` land and stores after it do not execute. - `s_sethalt`, `s_sendmsghalt`, and `s_code_end` deliberately remain throwing as on `main` and documented in `docs/dev/TechnicalDebt.md`. - Credited under `OPCODE_VARIANTS["SEndpgm"]` in `tools/progress.py`. - Rebased cleanly on latest `main`, with both Linux and Windows CI tests passing green.
adriadam10 commented 2026-10-07 06:41:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T06:41:20Z.


Checked the decoder change against our gfx1035 measurement (s_setkill 0 and 1 end the wave), build + full ctest on current main (RADV), and that scalar_program_end fails without the change.

Added one commit on your branch:

  • docs/dev/TechnicalDebt.md: trimmed the s_setkill entry to the measured behaviour and the one unverified point (the KILL status bit). I dropped the GCN3 section reference (that's a different ISA) and the s_sethalt/s_sendmsghalt/s_code_end part: those still throw exactly as on main, so there's no new technical debt to record for them.

Merging once CI is green on the new head.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6032499177 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/771#issuecomment-6032499177). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-07T06:41:20Z. --- Checked the decoder change against our gfx1035 measurement (`s_setkill` 0 and 1 end the wave), build + full ctest on current `main` (RADV), and that `scalar_program_end` fails without the change. Added one commit on your branch: - `docs/dev/TechnicalDebt.md`: trimmed the `s_setkill` entry to the measured behaviour and the one unverified point (the KILL status bit). I dropped the GCN3 section reference (that's a different ISA) and the `s_sethalt`/`s_sendmsghalt`/`s_code_end` part: those still throw exactly as on `main`, so there's no new technical debt to record for them. Merging once CI is green on the new head.
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!771
No description provided.