Shaders: keep spilled compute root parameters from claiming s16+ system SGPRs #3038

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

@⁠fuzeofficlal on GitHub · 2026-11-26 04:36 UTC · original
fuzeofficlal:fix/cs-spilled-root-param-of → main · +195 −0 · 1 files · 1 commits · open

Summary

In compute shaders (HwStage::Cs), hardware provides at most 16 user SGPRs (s0..s15); root parameters with user_data >= 16 spill to memory (loaded via s[0:1]), while s16+ hold system inputs (SV_GroupID, GroupInfo).

spill_loads, spilled_param, and param_word in crates/victory-shader/src/resource.rs already exclude user_data >= 16 for HwStage::Cs, but Tracer::param_of did not:

fn param_of(&self, reg: Reg) -> Option<(usize, u32)> {
    let Reg::S(code) = reg else { return None };
    self.layout.iter().enumerate().find_map(|(i, p)| {
        let first = self.stage.user_sgpr(p.user_data);
        ...

When a compute shader has any spilled root parameter (user_data >= 16) and reads s16+, Tracer::param_of falsely maps the system SGPR to that spilled root parameter. Depending on how s16+ is used, this either:

  1. Causes Lower::inputs / Lower::get to replace SV_GroupID with user_data[16+], or
  2. Causes resource tracking to reject valid dynamic offsets (e.g. s_load / global_load indexed by SV_GroupID) with "an offset from a root parameter".

Fix

  • Return None early in Tracer::param_of when self.stage == HwStage::Cs && code >= 16.
  • Add unit tests in crates/victory-shader/src/resource.rs:
    • compute_spilled_params_do_not_claim_system_sgprs: verifies track() accepts s16 as a dynamic s_load offset alongside a spilled root parameter at user_data = 16, without mapping s16 into r.params.
    • compute_group_id_in_s16_survives_spilled_root_constants: verifies full emit() + DXIL validation keeps s16 lowered as Input::GroupId(0) and never pulls spilled user_data[16] into shader.user_data unless loaded from s[0:1].

Verification

  • cargo test --locked -p victory-shader --lib resource::tests (37 passed)
  • cargo test --locked -p victory-shader --test resource_tracking (3 passed)
  • cargo clippy --locked -p victory-shader --all-targets -- -D warnings (clean)
  • cargo xtask policy (191 files ok)
**@⁠fuzeofficlal** on GitHub · 2026-11-26 04:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/3038) `fuzeofficlal:fix/cs-spilled-root-param-of` → `main` · +195 −0 · 1 files · 1 commits · open ### Summary In compute shaders (`HwStage::Cs`), hardware provides at most 16 user SGPRs (`s0..s15`); root parameters with `user_data >= 16` spill to memory (loaded via `s[0:1]`), while `s16+` hold system inputs (`SV_GroupID`, `GroupInfo`). `spill_loads`, `spilled_param`, and `param_word` in `crates/victory-shader/src/resource.rs` already exclude `user_data >= 16` for `HwStage::Cs`, but `Tracer::param_of` did not: ```rust fn param_of(&self, reg: Reg) -> Option<(usize, u32)> { let Reg::S(code) = reg else { return None }; self.layout.iter().enumerate().find_map(|(i, p)| { let first = self.stage.user_sgpr(p.user_data); ... ``` When a compute shader has any spilled root parameter (`user_data >= 16`) and reads `s16+`, `Tracer::param_of` falsely maps the system SGPR to that spilled root parameter. Depending on how `s16+` is used, this either: 1. Causes `Lower::inputs` / `Lower::get` to replace `SV_GroupID` with `user_data[16+]`, or 2. Causes resource tracking to reject valid dynamic offsets (e.g. `s_load` / `global_load` indexed by `SV_GroupID`) with `"an offset from a root parameter"`. ### Fix - Return `None` early in `Tracer::param_of` when `self.stage == HwStage::Cs && code >= 16`. - Add unit tests in `crates/victory-shader/src/resource.rs`: - `compute_spilled_params_do_not_claim_system_sgprs`: verifies `track()` accepts `s16` as a dynamic `s_load` offset alongside a spilled root parameter at `user_data = 16`, without mapping `s16` into `r.params`. - `compute_group_id_in_s16_survives_spilled_root_constants`: verifies full `emit()` + DXIL validation keeps `s16` lowered as `Input::GroupId(0)` and never pulls spilled `user_data[16]` into `shader.user_data` unless loaded from `s[0:1]`. ### Verification - `cargo test --locked -p victory-shader --lib resource::tests` (37 passed) - `cargo test --locked -p victory-shader --test resource_tracking` (3 passed) - `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` (clean) - `cargo xtask policy` (191 files ok)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:27:13 +00:00
Author
Owner

@⁠pawrenity on GitHub · 2026-11-26 05:04 UTC · original

VERIFY-3038: verified aed7e97 on NVIDIA GeForce RTX 4070, Windows 11 (plus WARP where the tests use it).

Review (reading). The new guard in Tracer::param_of (crates/victory-shader/src/resource.rs:635) makes it agree with the three compute-spill paths beside it: spill_loads, spilled_param and param_word already treat user_data >= 16 on HwStage::Cs as memory reached through s[0:1], never as SGPRs. Without the guard, a Cs parameter at user_data >= 16 matched s16+ because HwStage::Cs.user_sgpr(i) == i. track() (line 172) and param_value (line 528) are its only callers, and both now leave s16+ to the system inputs (ComputeIo::system_sgprs). I found no defects.

Regression check. I put the PR's test hunk alone on origin/main 63bcca4, with the 6-line guard taken out. Both new tests fail for the reasons the description gives:

  • compute_spilled_params_do_not_claim_system_sgprs: track returns Unsupported { what: "an offset from a root parameter" }
  • compute_group_id_in_s16_survives_spilled_root_constants: panics on "s16 must not be claimed by the spilled root constant"

At head:

  • cargo test --locked -p victory-shader --lib resource::: 37 passed, 0 failed. Both new tests pass, including their DXIL validation step (dxil.dll from Windows Kits 10.0.26100.0).
  • cargo test --locked -p victory-shader --test resource_tracking: 3 passed, 1 ignored.
  • cargo test --locked -p victory-shader --lib (one test skipped because it crashes the process on NVIDIA): 300 passed, 3 failed. The 3 (stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride, stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, synthetic_tests::gathers_at_a_level_match_the_hardware) also fail on main on this card.
  • cargo clippy --locked -p victory-shader --all-targets -- -D warnings: clean.
  • A trial merge onto current origin/main 63bcca4 is clean.

Not checked: whether any title shader is affected (no shader pack here).

AI-assisted (Claude Code).

**@⁠pawrenity** on GitHub · 2026-11-26 05:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/3038#issuecomment-7183151031) VERIFY-3038: verified `aed7e97` on NVIDIA GeForce RTX 4070, Windows 11 (plus WARP where the tests use it). **Review (reading).** The new guard in `Tracer::param_of` (`crates/victory-shader/src/resource.rs:635`) makes it agree with the three compute-spill paths beside it: `spill_loads`, `spilled_param` and `param_word` already treat `user_data >= 16` on `HwStage::Cs` as memory reached through `s[0:1]`, never as SGPRs. Without the guard, a `Cs` parameter at `user_data >= 16` matched `s16+` because `HwStage::Cs.user_sgpr(i) == i`. `track()` (line 172) and `param_value` (line 528) are its only callers, and both now leave `s16+` to the system inputs (`ComputeIo::system_sgprs`). I found no defects. **Regression check.** I put the PR's test hunk alone on `origin/main` `63bcca4`, with the 6-line guard taken out. Both new tests fail for the reasons the description gives: - `compute_spilled_params_do_not_claim_system_sgprs`: `track` returns `Unsupported { what: "an offset from a root parameter" }` - `compute_group_id_in_s16_survives_spilled_root_constants`: panics on "s16 must not be claimed by the spilled root constant" **At head:** - `cargo test --locked -p victory-shader --lib resource::`: 37 passed, 0 failed. Both new tests pass, including their DXIL validation step (`dxil.dll` from Windows Kits 10.0.26100.0). - `cargo test --locked -p victory-shader --test resource_tracking`: 3 passed, 1 ignored. - `cargo test --locked -p victory-shader --lib` (one test skipped because it crashes the process on NVIDIA): 300 passed, 3 failed. The 3 (`stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride`, `stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`, `synthetic_tests::gathers_at_a_level_match_the_hardware`) also fail on main on this card. - `cargo clippy --locked -p victory-shader --all-targets -- -D warnings`: clean. - A trial merge onto current `origin/main` `63bcca4` is clean. Not checked: whether any title shader is affected (no shader pack here). AI-assisted (Claude Code).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 06:14 UTC · original

Automated triage for the maintainers.

Tracer::param_of in crates/victory-shader/src/resource.rs now returns None for s16+ on HwStage::Cs. This makes it agree with what main already does for compute programs in spill_loads, spilled_param and param_word: parameters at user_data >= 16 are read from memory through s[0:1], never from SGPRs. Without the guard, HwStage::Cs.user_sgpr(i) == i let a spilled parameter claim a system SGPR such as the group ID that ComputeIo::system_sgprs places after the user SGPRs. I checked param_of's callers (track and param_value). Both now leave s16+ to the system inputs.

The two new tests check what should happen, not only what the code currently does: the group ID is raised as Input::GroupId(0), and user_data[16] appears only when it is loaded through s[0:1]. I found no repo-rule issues. CI: check passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 06:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/3038#issuecomment-7184228665) <!-- victory-triage v1 head=aed7e97f54304740a4f25f042cdb756910c1d643 verdict=merge-candidate at=2026-11-26T06:18:00Z --> Automated triage for the maintainers. `Tracer::param_of` in `crates/victory-shader/src/resource.rs` now returns `None` for `s16+` on `HwStage::Cs`. This makes it agree with what `main` already does for compute programs in `spill_loads`, `spilled_param` and `param_word`: parameters at `user_data >= 16` are read from memory through `s[0:1]`, never from SGPRs. Without the guard, `HwStage::Cs.user_sgpr(i) == i` let a spilled parameter claim a system SGPR such as the group ID that `ComputeIo::system_sgprs` places after the user SGPRs. I checked `param_of`'s callers (`track` and `param_value`). Both now leave `s16+` to the system inputs. The two new tests check what should happen, not only what the code currently does: the group ID is raised as `Input::GroupId(0)`, and `user_data[16]` appears only when it is loaded through `s[0:1]`. I found no repo-rule issues. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request can be merged automatically.
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/3038/head:github-bot/gh-3038'
git switch 'github-bot/gh-3038'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3038'
git switch 'github-bot/gh-3038'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3038'
git switch 'github-bot/gh-3038'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3038'
git switch 'main'
git merge --squash 'github-bot/gh-3038'
git switch 'main'
git merge --ff-only 'github-bot/gh-3038'
git switch 'main'
git merge 'github-bot/gh-3038'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3038
No description provided.