Shaders: a buffer descriptor made raw from first-lane reads needs its waterfall (#2867) #2869

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

@⁠BastienRodz on GitHub · 2026-11-25 22:46 UTC · original
BastienRodz:shader/made-raw-first-lane-waterfall → main · +70 −10 · 1 files · 1 commits · open

What's wrong

Tracer::descriptor traces a buffer descriptor made raw before a byte access (made_raw, the FidelityFX compiler's pattern) through the words it was made from. When those words are v_readfirstlane_b32 results, classify → per_lane traces them as each lane's own descriptor (Source::Fetched).

first_lane_words, which decides whether track must prove a waterfall loop, looked at the access's own SGPRs instead. There, dwords 1-3 are the results of s_and_b32, s_mul_i32 and s_or_b32. It found no first-lane reads, so no proof ran and a first-lane read outside any loop went through as per-lane.

In a GPU run of such a program under vkd3d-proton (each lane loads the V# of entry (lane & 1)), odd lanes read the second buffer: [100, 201, 102, 203, ...]. The console gives lane 0's buffer to every lane: [100, 101, 102, ...].

RDNA2 ISA:

  • V_READFIRSTLANE_B32: "Copy one VGPR value to one SGPR ... Lane# = FindFirst1fromLSB(exec)".
  • Buffer instructions: "All VM operations use a buffer resource constant (V#) which is a 128-bit value in SGPRs".

What the fix does

The new Tracer::words gives the descriptor words that tracing follows, the made-raw swap included. descriptor and first_lane_words both use it, so track sees the first-lane reads the source is traced to.

The results:

  • Without a loop, the access is refused as "a descriptor read from the first lane outside a waterfall loop", like any other first-lane read (a_first_lane_read_outside_a_loop_is_no_waterfall).
  • Inside a real waterfall loop, the proof now runs: the loop is lowered in one pass with one non-uniform handle, each lane reading its own buffer.

Tests

New resource::tests::a_buffer_descriptor_made_raw_after_its_first_lane_read_needs_a_waterfall:

  • The looped program must prove 2 compares and 4 reads. On main it proves none: left: 0, right: 2.
  • The same program without its back edge must be refused. On main it traces to Fetched.

Results, under Wine with vkd3d-proton:

  • With the fix, resource::tests (36), emit::waterfall_tests (5, GPU) and emit::lower::tests (33) pass.
  • The whole victory-shader lib was run one test per process, with the fix and with only resource.rs reverted. The results are identical except for this test: 255 ok, 14 failed, 2 crashed and 3 ignored with the fix. The failures and crashes are the same host quirks on both builds.
  • cargo clippy --workspace --all-targets --locked -- -D warnings is clean.

It touches the same file as #2831 (first-lane reads reaching classify through a select, a phi or a copy back), and the two merge cleanly.

Not tested

  • On Windows hardware or WARP, and in game.
  • How many of the title's programs make a raw descriptor from first-lane reads without a waterfall loop.

Fixes #2867

No game data. Found and written with AI assistance (Claude Code), reviewed and run locally.

🤖 Generated with Claude Code

**@⁠BastienRodz** on GitHub · 2026-11-25 22:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/2869) `BastienRodz:shader/made-raw-first-lane-waterfall` → `main` · +70 −10 · 1 files · 1 commits · open ## What's wrong `Tracer::descriptor` traces a buffer descriptor made raw before a byte access (`made_raw`, the FidelityFX compiler's pattern) through the words it was made from. When those words are `v_readfirstlane_b32` results, `classify` → `per_lane` traces them as each lane's own descriptor (`Source::Fetched`). `first_lane_words`, which decides whether `track` must prove a waterfall loop, looked at the access's own SGPRs instead. There, dwords 1-3 are the results of `s_and_b32`, `s_mul_i32` and `s_or_b32`. It found no first-lane reads, so no proof ran and a first-lane read outside any loop went through as per-lane. In a GPU run of such a program under vkd3d-proton (each lane loads the V# of entry `(lane & 1)`), odd lanes read the second buffer: `[100, 201, 102, 203, ...]`. The console gives lane 0's buffer to every lane: `[100, 101, 102, ...]`. RDNA2 ISA: - V_READFIRSTLANE_B32: "Copy one VGPR value to one SGPR ... Lane# = FindFirst1fromLSB(exec)". - Buffer instructions: "All VM operations use a buffer resource constant (V#) which is a 128-bit value in SGPRs". ## What the fix does The new `Tracer::words` gives the descriptor words that tracing follows, the made-raw swap included. `descriptor` and `first_lane_words` both use it, so `track` sees the first-lane reads the source is traced to. The results: - Without a loop, the access is refused as "a descriptor read from the first lane outside a waterfall loop", like any other first-lane read (`a_first_lane_read_outside_a_loop_is_no_waterfall`). - Inside a real waterfall loop, the proof now runs: the loop is lowered in one pass with one non-uniform handle, each lane reading its own buffer. ## Tests New `resource::tests::a_buffer_descriptor_made_raw_after_its_first_lane_read_needs_a_waterfall`: - The looped program must prove 2 compares and 4 reads. On main it proves none: `left: 0, right: 2`. - The same program without its back edge must be refused. On main it traces to `Fetched`. Results, under Wine with vkd3d-proton: - With the fix, `resource::tests` (36), `emit::waterfall_tests` (5, GPU) and `emit::lower::tests` (33) pass. - The whole `victory-shader` lib was run one test per process, with the fix and with only `resource.rs` reverted. The results are identical except for this test: 255 ok, 14 failed, 2 crashed and 3 ignored with the fix. The failures and crashes are the same host quirks on both builds. - `cargo clippy --workspace --all-targets --locked -- -D warnings` is clean. It touches the same file as #2831 (first-lane reads reaching `classify` through a select, a phi or a copy back), and the two merge cleanly. ## Not tested - On Windows hardware or WARP, and in game. - How many of the title's programs make a raw descriptor from first-lane reads without a waterfall loop. Fixes #2867 No game data. Found and written with AI assistance (Claude Code), reviewed and run locally. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
`descriptor` traces a buffer descriptor made raw before a byte access
(stride cleared, records times stride, bounds in bytes) to the words it
was made from. When those are `v_readfirstlane_b32` results, `classify`
takes them as each lane's own. But `track` looked for first-lane reads in
the access's own SGPRs, where dwords 1-3 are the s_and/s_mul/s_or
results, so it found none and proved no waterfall loop. With no loop the
console uses the first lane's buffer in every lane, yet each lane read
its own.

`first_lane_words` now reads the same words as `descriptor` (the new
`words`). With no loop the access is refused, as other first-lane reads
are. Inside a waterfall loop the proof now holds and the loop runs in one
pass.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:16:20 +00:00
Author
Owner

@⁠BastienRodz on GitHub · 2026-11-25 22:51 UTC · original

Windows run of this head (dee92f5, on main 219878a) on windows-latest, WARP, cargo test --workspace --locked --no-fail-fast -- --test-threads=1: https://github.com/BastienRodz/VIctory/actions/runs/45716155770

  • victory-shader lib: 303 passed, 0 failed, 3 ignored, including resource::tests::a_buffer_descriptor_made_raw_after_its_first_lane_read_needs_a_waterfall and every waterfall_tests GPU test.
  • Every other crate in the workspace: no failures.
**@⁠BastienRodz** on GitHub · 2026-11-25 22:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2869#issuecomment-7176864317) Windows run of this head (`dee92f5`, on `main` `219878a`) on `windows-latest`, WARP, `cargo test --workspace --locked --no-fail-fast -- --test-threads=1`: https://github.com/BastienRodz/VIctory/actions/runs/45716155770 - `victory-shader` lib: 303 passed, 0 failed, 3 ignored, including `resource::tests::a_buffer_descriptor_made_raw_after_its_first_lane_read_needs_a_waterfall` and every `waterfall_tests` GPU test. - Every other crate in the workspace: no failures.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 22:54 UTC · original

Reviewed and verified dee92f59 on Windows 11 (RTX 5090 + WARP + dxil.dll) against main (842b0cb):

  • Extracting Tracer::words(inst, op) cleanly shares the made_raw unwrapping between Tracer::descriptor and first_lane_words, catching s_bfe/s_max/s_and/s_mul/s_or-rebuilt raw descriptors from v_readfirstlane_b32 while keeping !inst.name().contains("format") and all-4-words matching consistent.
  • Local checks: a_buffer_descriptor_made_raw_after_its_first_lane_read_needs_a_waterfall 1/1, resource::tests 36/36, emit::waterfall_tests 5/5 (RTX 5090 + WARP + dxil.dll), cargo clippy --locked -p victory-shader --all-targets -- -D warnings 0 warnings, cargo xtask policy (190 files ok; emit/lower.rs untouched at 520,563 bytes).

Looks clean and ready to merge.

**@⁠fuzeofficlal** on GitHub · 2026-11-25 22:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/2869#issuecomment-7176924460) Reviewed and verified `dee92f59` on Windows 11 (RTX 5090 + WARP + `dxil.dll`) against `main` (`842b0cb`): - Extracting `Tracer::words(inst, op)` cleanly shares the `made_raw` unwrapping between `Tracer::descriptor` and `first_lane_words`, catching `s_bfe`/`s_max`/`s_and`/`s_mul`/`s_or`-rebuilt raw descriptors from `v_readfirstlane_b32` while keeping `!inst.name().contains("format")` and all-4-words matching consistent. - Local checks: `a_buffer_descriptor_made_raw_after_its_first_lane_read_needs_a_waterfall` 1/1, `resource::tests` 36/36, `emit::waterfall_tests` 5/5 (RTX 5090 + WARP + `dxil.dll`), `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` 0 warnings, `cargo xtask policy` (`190 files ok`; `emit/lower.rs` untouched at `520,563` bytes). Looks clean and ready to merge.
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-25 23:04 UTC · original

Local verification on Windows / rustc 1.100.0 / MSVC, no game data, no GPU, no clippy/rustup.

  • cargo test --locked -p victory-shader resource::tests::a_buffer_descriptor_made_raw_after_its_first_lane_read_needs_a_waterfall --quiet -> 1 passed, 305 filtered out.
  • cargo test --locked -p victory-shader resource::tests --quiet -> 36 passed, 0 failed.
  • git diff --check against merge-base 219878a clean; the PR changes 1 file, +70/-10 (crates/victory-shader/src/resource.rs).
  • Negative control: the new test name is absent from the merge-base, so the coverage is new here.
  • The tracer words() helper is exercised with synthetic ISA word arrays only.

This is independent local verification, not a formal approval.

AI-assisted (Hy4 flash).

**@⁠cloph-dsp** on GitHub · 2026-11-25 23:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/2869#issuecomment-7177124294) Local verification on Windows / rustc 1.100.0 / MSVC, no game data, no GPU, no clippy/rustup. - `cargo test --locked -p victory-shader resource::tests::a_buffer_descriptor_made_raw_after_its_first_lane_read_needs_a_waterfall --quiet` -> 1 passed, 305 filtered out. - `cargo test --locked -p victory-shader resource::tests --quiet` -> 36 passed, 0 failed. - `git diff --check` against merge-base `219878a` clean; the PR changes 1 file, +70/-10 (`crates/victory-shader/src/resource.rs`). - Negative control: the new test name is absent from the merge-base, so the coverage is new here. - The tracer `words()` helper is exercised with synthetic ISA word arrays only. This is independent local verification, not a formal approval. AI-assisted (Hy4 flash).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 04:25 UTC · original

Automated triage for the maintainers.

Merge candidate. This adds Tracer::words so descriptor and first_lane_words both see the words a made-raw buffer descriptor is built from; before, track looked at the s_and/s_mul/s_or results, found no first-lane reads and skipped the waterfall proof while classify traced each lane's descriptor. made_raw returns the original v_readfirstlane_b32 words, so the loop's compares now match what track collects. The fix is backed by the ISA reference and the GPU run in the description, and the test checks both outcomes (looped form proven; without the back edge, refused).

CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 04:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/2869#issuecomment-7182578245) <!-- victory-triage v1 head=dee92f59ca8cfab46c438b55a6d0251d389a668d verdict=merge-candidate at=2026-11-26T04:25:04Z --> Automated triage for the maintainers. **Merge candidate.** This adds `Tracer::words` so `descriptor` and `first_lane_words` both see the words a made-raw buffer descriptor is built from; before, `track` looked at the `s_and`/`s_mul`/`s_or` results, found no first-lane reads and skipped the waterfall proof while `classify` traced each lane's descriptor. `made_raw` returns the original `v_readfirstlane_b32` words, so the loop's compares now match what `track` collects. The fix is backed by the ISA reference and the GPU run in the description, and the test checks both outcomes (looped form proven; without the back edge, refused). CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 22:50 UTC · original · reviewed

Consistent with #2831's model: a buffer descriptor made raw is traced through the RAW words everywhere else, so first_lane_words using words() (which applies made_raw) keeps the waterfall analysis on the same terms the classify path sees. Clean refactor. LGTM.

**@⁠kotekompotek** on GitHub · 2026-11-25 22:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/2869#pullrequestreview-6066063531) · **reviewed** Consistent with #2831's model: a buffer descriptor made raw is traced through the RAW words everywhere else, so first_lane_words using words() (which applies made_raw) keeps the waterfall analysis on the same terms the classify path sees. Clean refactor. LGTM.
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 09:50 UTC · original · approved these changes

Verified on RTX 5090 & WARP against origin/main (63bcca4):

  • cargo test -p victory-shader --lib resource::tests:: -- --test-threads=1: passed.
  • cargo test -p victory-shader --lib emit::waterfall_tests:: -- --test-threads=1: 5/5 passed on RTX 5090 and WARP.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly keeps waterfall resolution for raw buffer descriptors built from first-lane reads (#2867).

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

**@⁠Dukestar69** on GitHub · 2026-11-26 09:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/2869#pullrequestreview-6071857487) · **approved these changes** Verified on RTX 5090 & WARP against `origin/main` (`63bcca4`): - `cargo test -p victory-shader --lib resource::tests:: -- --test-threads=1`: passed. - `cargo test -p victory-shader --lib emit::waterfall_tests:: -- --test-threads=1`: 5/5 passed on RTX 5090 and WARP. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly keeps waterfall resolution for raw buffer descriptors built from first-lane reads (`#2867`). Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 11:18 UTC · original · approved these changes

Reviewed dee92f59 and verified on RTX 5090 and WARP (git merge-tree against origin/main 63bcca43 is clean): extracting Tracer::words cleanly keeps first_lane_words and Tracer::descriptor aligned on the same made_raw-unwrapped dwords, enforcing waterfall validation for raw buffer descriptors built from v_readfirstlane_b32 while preserving !inst.name().contains("format") and existing loop checks.

Verified locally on Windows 11 x64 (dee92f59):

  • cargo run --locked -p xtask -- policy (190 files ok) and cargo clippy --workspace --all-targets -- -D warnings (default and --all-features): clean.
  • resource::tests (36/36), emit::lower::tests (33/33), and emit::waterfall_tests (5/5 on both RTX 5090 and VICTORY_WARP=1): all passed.

One tiny comment note: at resource.rs:3546, removing only the back edge keeps the compare and EXEC narrowing in place, so the first matching lanes access the buffer while the remaining lanes lose their retry (NO_LOOP).

**@⁠fuzeofficlal** on GitHub · 2026-11-26 11:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2869#pullrequestreview-6073237124) · **approved these changes** Reviewed `dee92f59` and verified on RTX 5090 and WARP (`git merge-tree` against `origin/main` `63bcca43` is clean): extracting `Tracer::words` cleanly keeps `first_lane_words` and `Tracer::descriptor` aligned on the same `made_raw`-unwrapped dwords, enforcing waterfall validation for raw buffer descriptors built from `v_readfirstlane_b32` while preserving `!inst.name().contains("format")` and existing loop checks. Verified locally on Windows 11 x64 (`dee92f59`): - `cargo run --locked -p xtask -- policy` (`190 files ok`) and `cargo clippy --workspace --all-targets -- -D warnings` (default and `--all-features`): clean. - `resource::tests` (36/36), `emit::lower::tests` (33/33), and `emit::waterfall_tests` (5/5 on both RTX 5090 and `VICTORY_WARP=1`): all passed. One tiny comment note: at `resource.rs:3546`, removing only the back edge keeps the compare and EXEC narrowing in place, so the first matching lanes access the buffer while the remaining lanes lose their retry (`NO_LOOP`).
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/2869/head:github-bot/gh-2869'
git switch 'github-bot/gh-2869'

Merge

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