Skip to content

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

Open
BastienRodz wants to merge 1 commit into
Marvisak:mainfrom
BastienRodz:shader/made-raw-first-lane-waterfall
Open

BastienRodz wants to merge 1 commit into
Marvisak:mainfrom
BastienRodz:shader/made-raw-first-lane-waterfall

Conversation

@BastienRodz

Copy link
Copy Markdown
Contributor

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

… waterfall

`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 <noreply@anthropic.com>

@kotekompotek kotekompotek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Owner

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

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 26, 2026

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shaders: a buffer descriptor made raw from first-lane reads skips the waterfall proof and is traced as each lane's own

6 participants