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

Open
github-bot wants to merge 7 commits from github-bot/gh-1253 into main AGit
Owner

@⁠mgunes1311-lab on GitHub · 2026-11-24 16:49 UTC · original
mgunes1311-lab:shader-waterfall-scaled-offset → main · +59 −9 · 2 files · 7 commits · open

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
**@⁠mgunes1311-lab** on GitHub · 2026-11-24 16:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/1253) `mgunes1311-lab:shader-waterfall-scaled-offset` → `main` · +59 −9 · 2 files · 7 commits · open ### 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`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:25:10 +00:00
Author
Owner

@⁠pablogonz12 on GitHub · 2026-11-24 17:16 UTC · original

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.

**@⁠pablogonz12** on GitHub · 2026-11-24 17:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/1253#issuecomment-7138944950) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:27 UTC · original · edited 2026-11-25 18:41 UTC

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

**@⁠Marvisak** on GitHub · 2026-11-25 01:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/1253#issuecomment-7149563818) · edited 2026-11-25 18:41 UTC <!-- 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)_
Author
Owner

@⁠mgunes1311-lab on GitHub · 2026-11-25 17:27 UTC · original

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.

**@⁠mgunes1311-lab** on GitHub · 2026-11-25 17:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/1253#issuecomment-7169532240) 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 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/1253/head:github-bot/gh-1253'
git switch 'github-bot/gh-1253'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1253'
git switch 'github-bot/gh-1253'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1253'
git switch 'github-bot/gh-1253'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1253'
git switch 'main'
git merge --squash 'github-bot/gh-1253'
git switch 'main'
git merge --ff-only 'github-bot/gh-1253'
git switch 'main'
git merge 'github-bot/gh-1253'
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!1253
No description provided.