feat(shader): decode the s_endpgm variants, s_round_mode and SMEM probe/discard #436

Merged
adriadam10 merged 2 commits from upstream-pr/436 into main 2026-10-05 02:47:42 +00:00
adriadam10 commented 2026-10-03 07:01:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-03T07:01:47Z.


What

Seven scalar opcodes threw at decode ("unsupported SOPP opcode", "SMEM opcode is not supported"). Found by the ISA
coverage sweep.

  • s_endpgm_saved (SOPP 0x1b) and s_endpgm_ordered_ps_done (SOPP 0x1e) decode to SEndpgm, so the decoder and
    the control flow graph treat them as program ends. Checked on an RDNA2 GPU: a store placed after either one never runs.
  • s_atc_probe, s_atc_probe_buffer, s_dcache_discard, s_dcache_discard_x2 (SMEM 0x26-0x29) go through the
    same path as s_dcache_inv/s_dcache_wb and translate to no-ops. On hardware the probes do nothing visible to
    the following code (the RDNA2 iGPU used here does not have the discards). The discards only drop dirty scalar
    cache lines, and scalar stores are not supported, so there is nothing to drop.
  • s_round_mode (SOPP 0x24) is a no-op like the s_setreg_b32 MODE writes on main, and is listed in
    TechnicalDebt. On hardware it does change float rounding (s_round_mode 0x3 makes 1.0 + 0x1.8p-24 give
    1.0 instead of 0x1.000002p+0). SPIR-V only has per-entry-point rounding modes, so it can't be followed
    at runtime.

Left out on purpose: s_setkill ends the wave on hardware even with 0, s_sethalt 1 halts it for a debugger,
and s_code_end hangs the wave if it runs (it is padding after the program end). These are debugger and padding
encodings that game code doesn't run.

Tested

  • New execution tests ScalarProgramEnd and ScalarProgramEndSaved (32 lanes). Each one runs all four SMEM ops
    and s_round_mode, then stores in + 1 and hits one of the two end variants. Two never-taken branches put a
    block right after the end that would overwrite the result, and another one past it; both must stay unwritten.
  • Both fail on main (decode throws). They pass on Linux with RADV and lavapipe.
  • Negative checks: decoding either end variant as s_nop fails ("store before the end is 0x00000bad"). Removing
    the s_atc_probe or s_dcache_discard_x2 decode, or the s_round_mode translation, fails at recompile.
  • Full Release build + ctest: 127/127.

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:4724763492 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/436). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-03T07:01:47Z. --- ### What Seven scalar opcodes threw at decode ("unsupported SOPP opcode", "SMEM opcode is not supported"). Found by the ISA coverage sweep. - `s_endpgm_saved` (SOPP 0x1b) and `s_endpgm_ordered_ps_done` (SOPP 0x1e) decode to `SEndpgm`, so the decoder and the control flow graph treat them as program ends. Checked on an RDNA2 GPU: a store placed after either one never runs. - `s_atc_probe`, `s_atc_probe_buffer`, `s_dcache_discard`, `s_dcache_discard_x2` (SMEM 0x26-0x29) go through the same path as `s_dcache_inv`/`s_dcache_wb` and translate to no-ops. On hardware the probes do nothing visible to the following code (the RDNA2 iGPU used here does not have the discards). The discards only drop dirty scalar cache lines, and scalar stores are not supported, so there is nothing to drop. - `s_round_mode` (SOPP 0x24) is a no-op like the `s_setreg_b32` MODE writes on `main`, and is listed in TechnicalDebt. On hardware it does change float rounding (`s_round_mode 0x3` makes `1.0 + 0x1.8p-24` give `1.0` instead of `0x1.000002p+0`). SPIR-V only has per-entry-point rounding modes, so it can't be followed at runtime. Left out on purpose: `s_setkill` ends the wave on hardware even with 0, `s_sethalt 1` halts it for a debugger, and `s_code_end` hangs the wave if it runs (it is padding after the program end). These are debugger and padding encodings that game code doesn't run. ### Tested - New execution tests `ScalarProgramEnd` and `ScalarProgramEndSaved` (32 lanes). Each one runs all four SMEM ops and `s_round_mode`, then stores `in + 1` and hits one of the two end variants. Two never-taken branches put a block right after the end that would overwrite the result, and another one past it; both must stay unwritten. - Both fail on `main` (decode throws). They pass on Linux with RADV and lavapipe. - Negative checks: decoding either end variant as `s_nop` fails ("store before the end is 0x00000bad"). Removing the `s_atc_probe` or `s_dcache_discard_x2` decode, or the `s_round_mode` translation, fails at recompile. - Full Release build + `ctest`: 127/127. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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
github-actions[bot] commented 2026-10-03 07:02:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-03T07:02:10Z.


Progress report (ebf29f8 → 36c2fa4)

📈 GPU shader instructions: 87.56% (+0.25%, +3 implemented instructions)

✅ 3 implemented
Encoding Name
SMEM S_ATC_PROBE
SMEM S_ATC_PROBE_BUFFER
SOPP S_ROUND_MODE
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5966582034 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/436#issuecomment-5966582034). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-03T07:02:10Z. --- <!-- progress-report --> ### Progress report (ebf29f8 → 36c2fa4) 📈 **GPU shader instructions**: 87.56% (+0.25%, +3 implemented instructions) <details> <summary>✅ 3 implemented</summary> | Encoding | Name | | - | - | | SMEM | `S_ATC_PROBE` | | SMEM | `S_ATC_PROBE_BUFFER` | | SOPP | `S_ROUND_MODE` | </details>
oneandonlydean commented 2026-10-04 05:44:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T05:44:44Z.


Thanks, the two end variants and the four SMEM ops look right to me (encodings checked with llvm-mc for gfx1013, and since scalar stores aren't supported the discards really have nothing to drop).

The one part I can't merge as is: s_round_mode becomes a silent no-op for every mode and is listed under silent stubs. CONTRIBUTING keeps silent stubs to UI-only behaviour that unblocks a title, and your own measurement shows mode 3 changes results. Mode 0 is round to nearest even everywhere, which is what the recompiler already assumes, so could it translate s_round_mode 0 as a no-op and throw for any other immediate? Then the TechnicalDebt line isn't needed.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5977033434 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/436#issuecomment-5977033434). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T05:44:44Z. --- Thanks, the two end variants and the four SMEM ops look right to me (encodings checked with llvm-mc for gfx1013, and since scalar stores aren't supported the discards really have nothing to drop). The one part I can't merge as is: `s_round_mode` becomes a silent no-op for every mode and is listed under silent stubs. CONTRIBUTING keeps silent stubs to UI-only behaviour that unblocks a title, and your own measurement shows mode 3 changes results. Mode 0 is round to nearest even everywhere, which is what the recompiler already assumes, so could it translate `s_round_mode 0` as a no-op and throw for any other immediate? Then the TechnicalDebt line isn't needed.
adriadam10 commented 2026-10-04 06:30:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T06:30:32Z.


Thanks for checking the encodings. Done, rebased onto main:

  • s_round_mode 0 is a no-op and any other immediate throws, so the TechnicalDebt line is gone.
  • The two program-end tests no longer use s_round_mode 3 (it is now s_nop 0, same word count), and ScalarProgramEnd checks that s_round_mode 3 is refused. That check fails if the guard is removed.

Both pass on RADV and lavapipe.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5977327388 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/436#issuecomment-5977327388). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-04T06:30:32Z. --- Thanks for checking the encodings. Done, rebased onto main: - `s_round_mode 0` is a no-op and any other immediate throws, so the TechnicalDebt line is gone. - The two program-end tests no longer use `s_round_mode 3` (it is now `s_nop 0`, same word count), and `ScalarProgramEnd` checks that `s_round_mode 3` is refused. That check fails if the guard is removed. Both pass on RADV and lavapipe.
oneandonlydean commented 2026-10-04 22:38:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T22:38:02Z.


Thanks. s_round_mode 0 (round to nearest even for both f32 and f16/f64) as a no-op and a throw for any other immediate is what I had in mind, and with the TechnicalDebt line gone and ScalarProgramEnd checking that s_round_mode 3 is refused, the guard is covered. agc_driver_scalar_program_end and agc_driver_scalar_program_end_saved pass on my NVIDIA machine on current main, and fail on main's code.

Small heads-up: #264 adds s_denorm_mode (SOPP 0x25) right next to s_round_mode (0x24) in RdnaScalarOpDecoder.cpp and ScalarInstructions.cpp, so whichever of the two lands second needs a one-line rebase. Otherwise ready to merge from my side.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5985219348 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/436#issuecomment-5985219348). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T22:38:02Z. --- Thanks. `s_round_mode 0` (round to nearest even for both f32 and f16/f64) as a no-op and a throw for any other immediate is what I had in mind, and with the TechnicalDebt line gone and `ScalarProgramEnd` checking that `s_round_mode 3` is refused, the guard is covered. `agc_driver_scalar_program_end` and `agc_driver_scalar_program_end_saved` pass on my NVIDIA machine on current main, and fail on main's code. Small heads-up: #264 adds `s_denorm_mode` (SOPP 0x25) right next to `s_round_mode` (0x24) in `RdnaScalarOpDecoder.cpp` and `ScalarInstructions.cpp`, so whichever of the two lands second needs a one-line rebase. Otherwise ready to merge from my side.
oneandonlydean commented 2026-10-05 01:18:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T01:18:07Z.


#264 is on main now, so this needs the small rebase I mentioned: s_denorm_mode (0x25) sits right next to s_round_mode (0x24) in RdnaScalarOpDecoder.cpp (the opcode table and the SOPP list) and in ScalarInstructions.cpp, and keeping both sides in all three spots works. Ready to merge from my side after that.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5986479245 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/436#issuecomment-5986479245). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T01:18:07Z. --- #264 is on main now, so this needs the small rebase I mentioned: `s_denorm_mode` (0x25) sits right next to `s_round_mode` (0x24) in `RdnaScalarOpDecoder.cpp` (the opcode table and the SOPP list) and in `ScalarInstructions.cpp`, and keeping both sides in all three spots works. Ready to merge from my side after that.
adriadam10 commented 2026-10-05 01:35:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T01:35:32Z.


Rebased on current main as you described: s_round_mode (0x24) and #264's s_denorm_mode (0x25) both kept in the SOPP opcode table, the SOPP wait list and ScalarInstructions.cpp. Both commits otherwise unchanged; agc_driver_scalar_program_end{,_saved} and the full ctest pass on RADV (only the known agc_driver_pixel_helper_lanes).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5986621187 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/436#issuecomment-5986621187). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-05T01:35:32Z. --- Rebased on current main as you described: `s_round_mode` (0x24) and #264's `s_denorm_mode` (0x25) both kept in the SOPP opcode table, the SOPP wait list and `ScalarInstructions.cpp`. Both commits otherwise unchanged; `agc_driver_scalar_program_end{,_saved}` and the full ctest pass on RADV (only the known `agc_driver_pixel_helper_lanes`).
oneandonlydean commented 2026-10-05 02:47:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T02:47:02Z.


Thanks, the rebase is right: s_round_mode (0x24) and s_denorm_mode (0x25) are both in the SOPP table and the wait list, and in ScalarInstructions.cpp s_round_mode still accepts only round to nearest even while s_denorm_mode keeps main's throw. Both commits are otherwise unchanged. agc_driver_scalar_program_end and agc_driver_scalar_program_end_saved pass here on the merged branch, and PPSA21564 has none of these instructions. Ready to merge from my side.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5987226967 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/436#issuecomment-5987226967). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T02:47:02Z. --- Thanks, the rebase is right: `s_round_mode` (0x24) and `s_denorm_mode` (0x25) are both in the SOPP table and the wait list, and in `ScalarInstructions.cpp` `s_round_mode` still accepts only round to nearest even while `s_denorm_mode` keeps main's throw. Both commits are otherwise unchanged. `agc_driver_scalar_program_end` and `agc_driver_scalar_program_end_saved` pass here on the merged branch, and PPSA21564 has none of these instructions. Ready to merge from my side.
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!436
No description provided.