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

Open
fuzeofficlal wants to merge 1 commit from upstream-pr/3038 into main
fuzeofficlal commented 2026-11-26 04:36:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T04:36:32Z.


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)
<!-- greyfinch-sync:Marvisak/VIctory:issue:6619601395 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3038). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T04:36:32Z. --- ### 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)
kotekompotek commented 2026-11-26 05:04:00 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T04:40:53Z.

Review: APPROVED


LGTM — correct hardware fact (CS user data ends at s15; s16+ are system inputs). The test is precise: s16 stays unmapped while the spilled param still resolves through its memory load.

<!-- greyfinch-sync:Marvisak/VIctory:review:6068636905 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3038#pullrequestreview-6068636905). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T04:40:53Z. **Review:** APPROVED --- LGTM — correct hardware fact (CS user data ends at s15; s16+ are system inputs). The test is precise: s16 stays unmapped while the spilled param still resolves through its memory load.
pawrenity commented 2026-11-26 05:04:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pawrenity on 2026-11-26T05:04:07Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7183151031 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3038#issuecomment-7183151031). Originally posted by [pawrenity](https://github.com/pawrenity) on 2026-11-26T05:04:07Z. --- 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).
fyernald commented 2026-11-26 06:03:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fyernald on 2026-11-26T05:13:10Z.

Review: APPROVED


The two new tests check the translation (tracking, user_data, DXIL validation) but never run the shader, so I dispatched both of compute_group_id_in_s16_survives_spilled_root_constants's programs on an RTX 3080 (driver 617.42), Windows 10 22H2. Same NativePrograms, 8 groups, spilled constant (user_data[16]) = 1000, a 12-dword raw UAV at heap index 0. Base is main 63bcca4 + #486 (Agility opt-in). Windows 10 has no SM 6.6 WARP here, so these are hardware results only.

program expected UAV[0..8] main this PR (aed7e97)
s16 + user_data[16] 1000, 1001, …, 1007 all 0 1000, 1001, …, 1007
s16 alone 0, 1, …, 7 all 0 0, 1, …, 7

On main the "s16 alone" shader's user_data already includes {index: 16, root: Constants}, and nothing lands in the UAV. That's consistent with every group reading s16 as the spilled 1000 and storing past the buffer. With the PR, user_data has only the table and each group writes its own id.

Also on the PR, with #2596 so the suite gets past the #2571 crash: resource:: 37 passed, and the full victory-shader --lib run gives 300 passed, 4 failed, 3 ignored. The 4 are the NVIDIA failures that fail on the same base without this PR (the two stride_tests heap-buffer tests, gathers_at_a_level_match_the_hardware, pops_wait_loop_exits_immediately_for_inactive_lanes). The extra 2 passes are your new tests.

A dispatch like this might be worth keeping in the test, since it's the only thing that checks the group id reaches the shader.

<!-- greyfinch-sync:Marvisak/VIctory:review:6068875442 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3038#pullrequestreview-6068875442). Originally posted by [fyernald](https://github.com/fyernald) on 2026-11-26T05:13:10Z. **Review:** APPROVED --- The two new tests check the translation (tracking, `user_data`, DXIL validation) but never run the shader, so I dispatched both of `compute_group_id_in_s16_survives_spilled_root_constants`'s programs on an RTX 3080 (driver 617.42), Windows 10 22H2. Same `NativeProgram`s, 8 groups, spilled constant (`user_data[16]`) = 1000, a 12-dword raw UAV at heap index 0. Base is `main` `63bcca4` + #486 (Agility opt-in). Windows 10 has no SM 6.6 WARP here, so these are hardware results only. | program | expected UAV[0..8] | `main` | this PR (`aed7e97`) | |---|---|---|---| | `s16 + user_data[16]` | 1000, 1001, …, 1007 | all 0 | 1000, 1001, …, 1007 | | `s16` alone | 0, 1, …, 7 | all 0 | 0, 1, …, 7 | On `main` the "s16 alone" shader's `user_data` already includes `{index: 16, root: Constants}`, and nothing lands in the UAV. That's consistent with every group reading `s16` as the spilled 1000 and storing past the buffer. With the PR, `user_data` has only the table and each group writes its own id. Also on the PR, with #2596 so the suite gets past the #2571 crash: `resource::` 37 passed, and the full `victory-shader --lib` run gives 300 passed, 4 failed, 3 ignored. The 4 are the NVIDIA failures that fail on the same base without this PR (the two `stride_tests` heap-buffer tests, `gathers_at_a_level_match_the_hardware`, `pops_wait_loop_exits_immediately_for_inactive_lanes`). The extra 2 passes are your new tests. A dispatch like this might be worth keeping in the test, since it's the only thing that checks the group id reaches the shader.
Dukestar69 commented 2026-11-26 07:01:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T06:47:42Z.

Review: APPROVED


Tested locally merged onto origin/main (63bcca4) on Windows 11 x64:

  • Diff review: Returning None from Tracer::param_of when self.stage == HwStage::Cs && code >= 16 ensures spilled compute root parameters (user_data >= 16) never falsely claim s16+ system SGPRs (SV_GroupID, group info).
  • cargo test -p victory-shader resource::tests: 37 passed, 0 failed (including compute_spilled_params_do_not_claim_system_sgprs and compute_group_id_in_s16_survives_spilled_root_constants).
  • cargo test -p victory-shader --test resource_tracking: 3 passed, 0 failed.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6069666399 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3038#pullrequestreview-6069666399). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T06:47:42Z. **Review:** APPROVED --- Tested locally merged onto `origin/main` (`63bcca4`) on Windows 11 x64: - Diff review: Returning `None` from `Tracer::param_of` when `self.stage == HwStage::Cs && code >= 16` ensures spilled compute root parameters (`user_data >= 16`) never falsely claim `s16+` system SGPRs (`SV_GroupID`, group info). - `cargo test -p victory-shader resource::tests`: 37 passed, 0 failed (including `compute_spilled_params_do_not_claim_system_sgprs` and `compute_group_id_in_s16_survives_spilled_root_constants`). - `cargo test -p victory-shader --test resource_tracking`: 3 passed, 0 failed. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Marvisak commented 2026-11-26 07:01:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T06:14:19Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7184228665 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3038#issuecomment-7184228665). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T06:14:19Z. --- <!-- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3038:upstream-pr/3038'
git switch 'upstream-pr/3038'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3038'
git switch 'upstream-pr/3038'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3038'
git switch 'upstream-pr/3038'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3038'
git switch 'main'
git merge --squash 'upstream-pr/3038'
git switch 'main'
git merge --ff-only 'upstream-pr/3038'
git switch 'main'
git merge 'upstream-pr/3038'
git push origin 'main'
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
Marvisak/VIctory!3036
No description provided.