Shaders: ignore pre-loop table loads when proving waterfall offsets #1253

Open
mgunes1311-lab wants to merge 7 commits from upstream-pr/1253 into main
mgunes1311-lab commented 2026-11-24 16:49:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mgunes1311-lab on 2026-11-24T16:49:04Z.


Summary

Fixes resource::track so a uniform s_load_dwordx4 executed in an earlier basic block with an offset derived from v_readfirstlane_b32 does not get recorded in a later waterfall loop block's offset_at read set and cause the waterfall proof to fail.

Root Cause

In resource::track, when an instruction inside basic block b consumes a Source::Loaded { load, .. } descriptor whose scalar load ran in an earlier block (load.0 != b) and whose dynamic offset came from v_readfirstlane_b32, track pushed that pre-loop first-lane read into offset_at[b].1. Tracker::waterfall(block, accesses, reads) requires every read in reads to reside inside block (read.0 == block) and feed that loop's v_cmp_eq_* waterfall mask, so including a pre-loop first-lane read from block 0 rejected a valid waterfall loop in block 1 (for example, when a shader loads a uniform sampler once before the loop and waterfalls a per-lane texture table offset inside the loop).

Changes

  • crates/victory-shader/src/resource.rs:
    • Only attribute a Source::Loaded descriptor's first_lane_source to offset_at[b] when the scalar load itself ran earlier in the same block (load.0 == b && load.1 < i).
    • Deduplicate loads alongside reads before extending out.waterfall.loads.
    • Add pre_loop_first_lane_waterfall and unit test a_first_lane_load_before_a_waterfall_loop_stays_uniform.
  • crates/victory-shader/src/emit/waterfall_tests.rs:
    • Extend lanes_sample_the_entry_their_offset_names_in_the_console_waterfall to execute pre_loop_first_lane_waterfall end-to-end on DXIL (wave_ops == true, nonuniform_handles == 1).

Verification

  • cargo test -p victory-shader --locked waterfall
  • cargo clippy -p victory-shader --all-targets --all-features -- -D warnings
  • cargo run -p xtask -- policy
<!-- greyfinch-sync:Marvisak/VIctory:issue:6586894733 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1253). Originally posted by [mgunes1311-lab](https://github.com/mgunes1311-lab) on 2026-11-24T16:49:04Z. --- ### Summary Fixes `resource::track` so a uniform `s_load_dwordx4` executed in an earlier basic block with an offset derived from `v_readfirstlane_b32` does not get recorded in a later waterfall loop block's `offset_at` read set and cause the waterfall proof to fail. ### Root Cause In `resource::track`, when an instruction inside basic block `b` consumes a `Source::Loaded { load, .. }` descriptor whose scalar load ran in an earlier block (`load.0 != b`) and whose dynamic offset came from `v_readfirstlane_b32`, `track` pushed that pre-loop first-lane read into `offset_at[b].1`. `Tracker::waterfall(block, accesses, reads)` requires every read in `reads` to reside inside `block` (`read.0 == block`) and feed that loop's `v_cmp_eq_*` waterfall mask, so including a pre-loop first-lane read from block 0 rejected a valid waterfall loop in block 1 (for example, when a shader loads a uniform sampler once before the loop and waterfalls a per-lane texture table offset inside the loop). ### Changes - **`crates/victory-shader/src/resource.rs`:** - Only attribute a `Source::Loaded` descriptor's `first_lane_source` to `offset_at[b]` when the scalar load itself ran earlier in the same block (`load.0 == b && load.1 < i`). - Deduplicate `loads` alongside `reads` before extending `out.waterfall.loads`. - Add `pre_loop_first_lane_waterfall` and unit test `a_first_lane_load_before_a_waterfall_loop_stays_uniform`. - **`crates/victory-shader/src/emit/waterfall_tests.rs`:** - Extend `lanes_sample_the_entry_their_offset_names_in_the_console_waterfall` to execute `pre_loop_first_lane_waterfall` end-to-end on DXIL (`wave_ops == true`, `nonuniform_handles == 1`). ### Verification - `cargo test -p victory-shader --locked waterfall` - `cargo clippy -p victory-shader --all-targets --all-features -- -D warnings` - `cargo run -p xtask -- policy`
DenRakEiw commented 2026-11-24 17:04:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T16:56:53Z.

Review: APPROVED


Tested merged cleanly onto main (ffe310e) on Windows 11 x64 (Rust 1.98.1 MSVC):

  • cargo test -p victory-shader resource::: 32 passed, 0 failed
  • cargo clippy -p victory-shader --all-targets: 0 warnings
  • cargo xtask policy: ok

Clean tracking of scalar index arithmetic in waterfall table offsets. Approving.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6043698691 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1253#pullrequestreview-6043698691). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-24T16:56:53Z. **Review:** APPROVED --- Tested merged cleanly onto `main` (`ffe310e`) on Windows 11 x64 (Rust 1.98.1 MSVC): - `cargo test -p victory-shader resource::`: **32 passed, 0 failed** - `cargo clippy -p victory-shader --all-targets`: **0 warnings** - `cargo xtask policy`: ok Clean tracking of scalar index arithmetic in waterfall table offsets. Approving. AI-assisted (Gemini 4 Neon).
pablogonz12 commented 2026-11-24 18:05:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pablogonz12 on 2026-11-24T17:16:21Z.


Setup: Linux, RX 9070 XT, RADV (Mesa 26.3.1), dxil-spirv master, spirv-val 1.3. Your head folded onto a base of origin/main ffe310e plus #1017 (main's host build fails without it: E0425 host_resource), then the four-stage offline check over 768 programs (751-program world dump + 52-program BVH capture, 35 duplicate containers skipped).

translate valid SPIR-V RADV pipeline
base 666 / 768 656 656
your head 666 / 768 656 656

No program gained or lost and the failure table is identical to the base: nothing in this capture reaches the class, so this is a no-regression result only.

Not tested: in-game.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7138944950 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1253#issuecomment-7138944950). Originally posted by [pablogonz12](https://github.com/pablogonz12) on 2026-11-24T17:16:21Z. --- Setup: Linux, RX 9070 XT, RADV (Mesa 26.3.1), dxil-spirv master, spirv-val 1.3. Your head folded onto a base of origin/main `ffe310e` plus #1017 (main's host build fails without it: `E0425 host_resource`), then the four-stage offline check over 768 programs (751-program world dump + 52-program BVH capture, 35 duplicate containers skipped). | | translate | valid SPIR-V | RADV pipeline | |---|---|---|---| | base | 666 / 768 | 656 | 656 | | your head | 666 / 768 | 656 | 656 | No program gained or lost and the failure table is identical to the base: nothing in this capture reaches the class, so this is a no-regression result only. Not tested: in-game.
Marvisak commented 2026-11-25 02:06:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:27:17Z.


Automated triage for the maintainers.

Needs work (evidence only). In track (crates/victory-shader/src/resource.rs), a Source::Loaded descriptor's first-lane offset now counts toward a block's waterfall proof only if its table load ran earlier in that same block (load.0 == b && load.1 < i). waterfall.loads is also deduplicated. By my reading this is sound. A table load before the loop, with an offset from v_readfirstlane_b32, runs once and is uniform. On main, its read joins the in-loop proof, Tracker::waterfall rejects it, and the image that is waterfalled in the loop falls back to the first lane's entry. a_first_lane_load_before_a_waterfall_loop_stays_uniform and the extended lanes_sample_the_entry_their_offset_names_in_the_console_waterfall cover this on the GPU. The description now matches the diff, and the trailing-whitespace nit is fixed. CI: passing (check).

What is still open: there is no sign the title has this shape. The fixture is hand-written. The earlier 768-program offline check in this thread found no program that changed. Any of these would move it forward:

  • a captured program, named by hash or described by its shape (no bytes), that loads a descriptor before a waterfall loop with a first-lane offset;
  • a victory translate --validate --list comparison on current main showing which programs change.

Without that, the change is a correct-looking fix for a case not seen yet. Whether to take it on code reading alone is for the maintainer.

On your reply: thanks for the cleanup. A tester with a capture can supply the comparison, and that is all this needs.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149563818 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1253#issuecomment-7149563818). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:27:17Z. --- <!-- victory-triage v1 head=d303cce5cdfaad83027357c189c8166cba4bb9da verdict=needs-work at=2026-11-25T18:41:15Z --> Automated triage for the maintainers. **Needs work (evidence only).** In `track` (`crates/victory-shader/src/resource.rs`), a `Source::Loaded` descriptor's first-lane offset now counts toward a block's waterfall proof only if its table load ran earlier in that same block (`load.0 == b && load.1 < i`). `waterfall.loads` is also deduplicated. By my reading this is sound. A table load before the loop, with an offset from `v_readfirstlane_b32`, runs once and is uniform. On `main`, its read joins the in-loop proof, `Tracker::waterfall` rejects it, and the image that is waterfalled in the loop falls back to the first lane's entry. `a_first_lane_load_before_a_waterfall_loop_stays_uniform` and the extended `lanes_sample_the_entry_their_offset_names_in_the_console_waterfall` cover this on the GPU. The description now matches the diff, and the trailing-whitespace nit is fixed. CI: passing (`check`). What is still open: there is no sign the title has this shape. The fixture is hand-written. The earlier 768-program offline check in this thread found no program that changed. Any of these would move it forward: - a captured program, named by hash or described by its shape (no bytes), that loads a descriptor before a waterfall loop with a first-lane offset; - a `victory translate --validate --list` comparison on current `main` showing which programs change. Without that, the change is a correct-looking fix for a case not seen yet. Whether to take it on code reading alone is for the maintainer. On your reply: thanks for the cleanup. A tester with a capture can supply the comparison, and that is all this needs. --- _Generated by [Claude Code](https://claude.ai/code)_
catminou4 commented 2026-11-25 04:05:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T03:56:28Z.

Review: APPROVED


Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, cargo test -p victory-shader --locked.

147 passed / 0 failed / 2 ignored. Scalar index arithmetic followed in waterfall table offsets (+3 tests) — waterfall readback correctness; pairs with #1408's wave prefix sums.

<!-- greyfinch-sync:Marvisak/VIctory:review:6051643140 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1253#pullrequestreview-6051643140). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T03:56:28Z. **Review:** APPROVED --- Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, `cargo test -p victory-shader --locked`. 147 passed / 0 failed / 2 ignored. Scalar index arithmetic followed in waterfall table offsets (+3 tests) — waterfall readback correctness; pairs with #1408's wave prefix sums.
upstream-sync changed title from [PR #1253] Shaders: follow scalar index arithmetic in waterfall table offsets to [PR #1253] Shaders: ignore pre-loop table loads when proving waterfall offsets 2026-11-25 14:05:29 +00:00
mgunes1311-lab commented 2026-11-25 18:02:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mgunes1311-lab on 2026-11-25T17:27:31Z.


Updated:

  • Saved the rewritten PR description above so it matches the current two-file diff (no stale offset_reads / WATERFALL_SCALED_INDEX_WAVE32 text).
  • Removed the trailing-whitespace blank line before pre_loop_first_lane_waterfall in crates/victory-shader/src/resource.rs.

On title data: this was found by code inspection while auditing resource::track + Tracker::waterfall, and I don't have a local title shader capture to run victory translate --validate --list against — if a tester with a capture can check whether --validate --list changes on it, that would confirm whether any title shader hits this pre-loop v_readfirstlane_b32 + loop waterfall combination today.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7169532240 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1253#issuecomment-7169532240). Originally posted by [mgunes1311-lab](https://github.com/mgunes1311-lab) on 2026-11-25T17:27:31Z. --- Updated: - Saved the rewritten PR description above so it matches the current two-file diff (no stale `offset_reads` / `WATERFALL_SCALED_INDEX_WAVE32` text). - Removed the trailing-whitespace blank line before `pre_loop_first_lane_waterfall` in `crates/victory-shader/src/resource.rs`. On title data: this was found by code inspection while auditing `resource::track` + `Tracker::waterfall`, and I don't have a local title shader capture to run `victory translate --validate --list` against — if a tester with a capture can check whether `--validate --list` changes on it, that would confirm whether any title shader hits this pre-loop `v_readfirstlane_b32` + loop waterfall combination today.
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/1253:upstream-pr/1253'
git switch 'upstream-pr/1253'

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/1253'
git switch 'upstream-pr/1253'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1253'
git switch 'upstream-pr/1253'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1253'
git switch 'main'
git merge --squash 'upstream-pr/1253'
git switch 'main'
git merge --ff-only 'upstream-pr/1253'
git switch 'main'
git merge 'upstream-pr/1253'
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!1253
No description provided.