shader: mesh programs read zero from SGPRs no hardware loads (#415) #420

Closed
github-bot wants to merge 1 commit from github-bot/gh-416 into main AGit
Owner

@⁠tiagonogueiraa-bit on GitHub · 2026-11-27 17:26 UTC · original
tiagonogueiraa-bit:shader-ngg-uninitialized-sgprs → main · +31 −0 · 3 files · 1 commits · closed without merging

Refs #419

Shape. 66 guessed mesh-style (NGG) vertex programs were refused as "a hardware SGPR input". Each reads an SGPR far above anything the hardware loads, before any write, on some path: s72, s77 or s79 in the ones I traced (a temporary instrument, not committed). Their layout ends at user data 15, the inferred heap. These are spill and temporary registers. For compute and pixel, Io::initialized_sgprs already makes such reads 0 ("a register holds what the last wave left"), but mesh programs had no count, so every such read was refused.

Change. Io::initialized_sgprs is Some(40) for StageIo::Ms. A mesh program has eight system SGPRs, then its user SGPRs from s8, and at most 32 of those: LLVM's AMDGPU::getMaxNumUserSGPRs returns 32 on GFX9 and later, and SPI_SHADER_PGM_RSRC2_GS's user SGPR count with USER_SGPR_MSB holds no more. So nothing the hardware loads sits at s40 or above. Reads below s40 that no root parameter covers stay refused. The bound is a hardware limit, not a guess at this title's layout.

By-output corpus sweep. 26,849 containers from my own runs (Series S, boot to the story load), native host options, main b998bb6 against this head:

Stage Gained Lost Changed Other reason now
vertex 66 0 0 0
pixel 0 0 0 0
compute 0 0 0 0

Conversion. All 66 gained translations convert with Apple's Metal Shader Converter 4.0 beta 3: 66 converted, 0 failed.

Test. emit::graphics::tests::a_mesh_program_reads_zero_from_an_sgpr_no_hardware_loads. A mesh program moving s72 or s40 into its position translates. One moving s39 is still refused as "a hardware SGPR input". On main the s72 case is refused.

Checks.

  • cargo test -p victory-shader -p victory-hle -p victory -p victory-gpu -p victory-metal -p xtask: 1054 passed, 0 failed, 11 ignored.
  • Windows clippy -D warnings: clean.
  • cargo xtask policy: ok.

docs/native-host.md has a bullet next to the other mesh-program notes. @⁠Olima34, for the board.

**@⁠tiagonogueiraa-bit** on GitHub · 2026-11-27 17:26 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/416) `tiagonogueiraa-bit:shader-ngg-uninitialized-sgprs` → `main` · +31 −0 · 3 files · 1 commits · closed without merging Refs #419 **Shape.** 66 guessed mesh-style (NGG) vertex programs were refused as "a hardware SGPR input". Each reads an SGPR far above anything the hardware loads, before any write, on some path: s72, s77 or s79 in the ones I traced (a temporary instrument, not committed). Their layout ends at user data 15, the inferred heap. These are spill and temporary registers. For compute and pixel, `Io::initialized_sgprs` already makes such reads 0 ("a register holds what the last wave left"), but mesh programs had no count, so every such read was refused. **Change.** `Io::initialized_sgprs` is `Some(40)` for `StageIo::Ms`. A mesh program has eight system SGPRs, then its user SGPRs from s8, and at most 32 of those: LLVM's `AMDGPU::getMaxNumUserSGPRs` returns 32 on GFX9 and later, and `SPI_SHADER_PGM_RSRC2_GS`'s user SGPR count with `USER_SGPR_MSB` holds no more. So nothing the hardware loads sits at s40 or above. Reads below s40 that no root parameter covers stay refused. The bound is a hardware limit, not a guess at this title's layout. **By-output corpus sweep.** 26,849 containers from my own runs (Series S, boot to the story load), native host options, main `b998bb6` against this head: | Stage | Gained | Lost | Changed | Other reason now | |---|---|---|---|---| | vertex | 66 | 0 | 0 | 0 | | pixel | 0 | 0 | 0 | 0 | | compute | 0 | 0 | 0 | 0 | **Conversion.** All 66 gained translations convert with Apple's Metal Shader Converter 4.0 beta 3: 66 converted, 0 failed. **Test.** `emit::graphics::tests::a_mesh_program_reads_zero_from_an_sgpr_no_hardware_loads`. A mesh program moving s72 or s40 into its position translates. One moving s39 is still refused as "a hardware SGPR input". On main the s72 case is refused. **Checks.** - `cargo test -p victory-shader -p victory-hle -p victory -p victory-gpu -p victory-metal -p xtask`: 1054 passed, 0 failed, 11 ignored. - Windows clippy `-D warnings`: clean. - `cargo xtask policy`: ok. `docs/native-host.md` has a bullet next to the other mesh-program notes. @⁠Olima34, for the board.
A mesh (NGG) program has eight system SGPRs, then its user SGPRs from
s8, and at most 32 of those (LLVM's AMDGPU::getMaxNumUserSGPRs on GFX9
and later). Io::initialized_sgprs is now 40 for mesh programs, so a
read of s40 or above before any write reads 0, as it already does above
compute's and pixel's counts. The title's NGG vertex programs read spill
registers such as s72 that way, and were refused as "a hardware SGPR
input". Reads below s40 that no root parameter covers stay refused.

Corpus sweep (26,849 shaders, main b998bb6): 66 vertex programs gained,
all of which convert with Apple's converter. No regressions, no changed
outputs.

Refs #415
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 17:39:03 +00:00
github-bot closed this pull request 2026-11-28 00:42:43 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-28 00:37 UTC · original

Thanks for this. Main already has the same change: 00c44adc makes mesh programs read s40 and up as zero, and it gains the same 66 programs. Merging this as well would add a second match arm for mesh programs that can never be reached, so I'm closing it as done. Thanks for the clear write-up and the test.

**@⁠LakshanSivakumar** on GitHub · 2026-11-28 00:37 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/416#issuecomment-7231062638) Thanks for this. Main already has the same change: 00c44adc makes mesh programs read s40 and up as zero, and it gains the same 66 programs. Merging this as well would add a second match arm for mesh programs that can never be reached, so I'm closing it as done. Thanks for the clear write-up and the test.
Author
Owner

@⁠Olima34 on GitHub · 2026-11-28 00:44 UTC · original · requested changes

Thanks @⁠tiagonogueiraa-bit, the rule is right, and the maintainer reached the same conclusion: main already has it. His 00c44adc ("shader: a mesh program reads SGPRs past its user data as zero", now on main through the preview merge) adds StageIo::Ms(_) => Some(40) to raise_graphics in crates/victory-shader/src/io.rs, with a docs note and a test in mask_tests.rs. GitHub still shows this PR as mergeable, but the merged code would have two identical StageIo::Ms(_) arms. That's an unreachable pattern, so Windows clippy (-D warnings) would fail, and the docs would describe the rule twice.

What's left that main doesn't have is your test's negative case: a read of s39 is still refused as "a hardware SGPR input". If you'd like to keep that, please merge current main into the branch, drop the io.rs arm and the docs bullet, and keep a_mesh_program_reads_zero_from_an_sgpr_no_hardware_loads (or fold its s39 assert into main's test). Otherwise the PR can be closed as already landed; that's the maintainer's call.

**@⁠Olima34** on GitHub · 2026-11-28 00:44 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/416#pullrequestreview-6094724561) · **requested changes** Thanks @⁠tiagonogueiraa-bit, the rule is right, and the maintainer reached the same conclusion: main already has it. His 00c44adc ("shader: a mesh program reads SGPRs past its user data as zero", now on main through the preview merge) adds `StageIo::Ms(_) => Some(40)` to `raise_graphics` in `crates/victory-shader/src/io.rs`, with a docs note and a test in `mask_tests.rs`. GitHub still shows this PR as mergeable, but the merged code would have two identical `StageIo::Ms(_)` arms. That's an unreachable pattern, so Windows clippy (`-D warnings`) would fail, and the docs would describe the rule twice. What's left that main doesn't have is your test's negative case: a read of s39 is still refused as "a hardware SGPR input". If you'd like to keep that, please merge current `main` into the branch, drop the `io.rs` arm and the docs bullet, and keep `a_mesh_program_reads_zero_from_an_sgpr_no_hardware_loads` (or fold its s39 assert into main's test). Otherwise the PR can be closed as already landed; that's the maintainer's call.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.