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

Open
BastienRodz wants to merge 1 commit from upstream-pr/2869 into main
BastienRodz commented 2026-11-25 22:46:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by BastienRodz on 2026-11-25T22:46:58Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:issue:6615312660 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2869). Originally posted by [BastienRodz](https://github.com/BastienRodz) on 2026-11-25T22:46:58Z. --- ## 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)
kotekompotek commented 2026-11-25 23:05:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T22:50:23Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066063531 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2869#pullrequestreview-6066063531). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T22:50:23Z. **Review:** COMMENTED --- 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.
BastienRodz commented 2026-11-25 23:06:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by BastienRodz on 2026-11-25T22:51:17Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7176864317 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2869#issuecomment-7176864317). Originally posted by [BastienRodz](https://github.com/BastienRodz) on 2026-11-25T22:51:17Z. --- 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.
fuzeofficlal commented 2026-11-25 23:06:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T22:54:27Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7176924460 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2869#issuecomment-7176924460). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T22:54:27Z. --- 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.
cloph-dsp commented 2026-11-25 23:06:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-25T23:04:54Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177124294 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2869#issuecomment-7177124294). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-25T23:04:54Z. --- 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).
Marvisak commented 2026-11-26 05:04:09 +00:00 (Migrated from github.com)

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


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7182578245 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2869#issuecomment-7182578245). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T04:25:11Z. --- <!-- 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)_
Dukestar69 commented 2026-11-26 10:04:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T09:50:09Z.

Review: APPROVED


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

<!-- greyfinch-sync:Marvisak/VIctory:review:6071857487 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2869#pullrequestreview-6071857487). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T09:50:09Z. **Review:** APPROVED --- 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).
fuzeofficlal commented 2026-11-26 12:05:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T11:18:44Z.

Review: APPROVED


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

<!-- greyfinch-sync:Marvisak/VIctory:review:6073237124 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2869#pullrequestreview-6073237124). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T11:18:44Z. **Review:** APPROVED --- 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 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/2869:upstream-pr/2869'
git switch 'upstream-pr/2869'

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