Shaders/spill: reject hybrid root layouts and s16+ hardware-initialized SGPR overlap #629

Open
github-bot wants to merge 1 commit from github-bot/gh-629 into main AGit
Owner

@⁠AscilCH on GitHub · 2026-11-25 03:26 UTC · original
AscilCH:fix/shader-spill-hybrid-layout-and-system-sgpr-clash → main · +69 −15 · 1 files · 1 commits · open

Problem

Two bugs in crates/victory-shader/src/spill.rs:

  1. Subtraction underflow on hybrid root layouts: spilled() only filtered layout entries with user_data >= registers before checking min == Some(16). If a compute shader declared both in-register root parameters (user_data < 16) and spilled entries starting at 16, is_spilled() returned true, and emit/lower.rs:2539 computed u32::from(rp.user_data) + dword - 16, panicking with subtraction underflow in debug builds (or wrapping in release).
  2. Silent SV_GroupID / system SGPR clobbering at s16+: spilled() never verified cs.initialized_sgprs() <= 16, and user_data() reused pre-existing p.inputs entries for Reg::S(16+). If user_sgprs plus system SGPRs (TGID_X/Y/Z, GroupInfo, or scratch wave offset) reached s16, rewritten spilled index 16 silently aliased and overwrote SV_GroupID in lowering.

Fix

  • Require registers >= 2 and u32::from(cs.initialized_sgprs()) <= FIRST (16) in spill::spilled().
  • Collect all layout entries with sgprs > 0 and require min == Some(FIRST) so hybrid layouts with any entry below 16 are rejected cleanly.
  • Track synthetic spilled-parameter Values in a dedicated spilled_inputs map instead of reusing pre-existing p.inputs entries, and use checked arithmetic on spilled dword offsets.
  • Add synthetic unit tests hybrid_layout_with_register_and_spilled_params_is_rejected and system_sgpr_reaching_s16_is_rejected.

Verification

  • cargo test -p victory-shader --locked spill::tests: 5 passed, 0 failed
  • cargo xtask policy: 169 files ok
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean

(AI-assisted; synthetic unit tests only, no game data.)

**@⁠AscilCH** on GitHub · 2026-11-25 03:26 UTC · [original](https://github.com/fxceless/victory-fork/pull/629) `AscilCH:fix/shader-spill-hybrid-layout-and-system-sgpr-clash` → `main` · +69 −15 · 1 files · 1 commits · open ## Problem Two bugs in `crates/victory-shader/src/spill.rs`: 1. **Subtraction underflow on hybrid root layouts**: `spilled()` only filtered layout entries with `user_data >= registers` before checking `min == Some(16)`. If a compute shader declared both in-register root parameters (`user_data < 16`) and spilled entries starting at `16`, `is_spilled()` returned `true`, and `emit/lower.rs:2539` computed `u32::from(rp.user_data) + dword - 16`, panicking with subtraction underflow in debug builds (or wrapping in release). 2. **Silent `SV_GroupID` / system SGPR clobbering at `s16+`**: `spilled()` never verified `cs.initialized_sgprs() <= 16`, and `user_data()` reused pre-existing `p.inputs` entries for `Reg::S(16+)`. If `user_sgprs` plus system SGPRs (`TGID_X/Y/Z`, `GroupInfo`, or scratch wave offset) reached `s16`, rewritten spilled index 16 silently aliased and overwrote `SV_GroupID` in lowering. ## Fix - Require `registers >= 2` and `u32::from(cs.initialized_sgprs()) <= FIRST` (`16`) in `spill::spilled()`. - Collect all layout entries with `sgprs > 0` and require `min == Some(FIRST)` so hybrid layouts with any entry below 16 are rejected cleanly. - Track synthetic spilled-parameter `Value`s in a dedicated `spilled_inputs` map instead of reusing pre-existing `p.inputs` entries, and use checked arithmetic on spilled dword offsets. - Add synthetic unit tests `hybrid_layout_with_register_and_spilled_params_is_rejected` and `system_sgpr_reaching_s16_is_rejected`. ## Verification - `cargo test -p victory-shader --locked spill::tests`: 5 passed, 0 failed - `cargo xtask policy`: 169 files ok - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: clean *(AI-assisted; synthetic unit tests only, no game data.)*
Two bugs in `spill::spilled()` and `spill::user_data()`:
1. `spilled()` filtered only entries with `user_data >= registers` before checking
   `min == Some(16)`, allowing hybrid layouts with both register parameters
   (`user_data < 16`) and spilled parameters (`user_data >= 16`) to pass
   `is_spilled()`. Lowering then computed `rp.user_data + dword - 16`, causing
   subtraction underflow.
2. `spilled()` never checked `cs.initialized_sgprs() <= 16`, and `user_data()`
   reused pre-existing `p.inputs` entries at `Reg::S(16+)`. If `user_sgprs` +
   system SGPRs (`TGID_X/Y/Z`, `GroupInfo`, or scratch wave offset) reached
   `s16`, rewritten spilled index 16 silently aliased and clobbered `SV_GroupID`.

Require `cs.initialized_sgprs() <= 16` and require every layout entry with
`sgprs > 0` to start at `user_data >= 16`, track synthetic spilled inputs in a
dedicated map (and use checked arithmetic on spilled offsets), and add
synthetic unit tests.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:47:44 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/629/head:github-bot/gh-629'
git switch 'github-bot/gh-629'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-629'
git switch 'github-bot/gh-629'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-629'
git switch 'github-bot/gh-629'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-629'
git switch 'main'
git merge --squash 'github-bot/gh-629'
git switch 'main'
git merge --ff-only 'github-bot/gh-629'
git switch 'main'
git merge 'github-bot/gh-629'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.