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

Open
opened 2026-11-26 05:16:17 +00:00 by github-bot · 2 comments
Owner

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

A buffer descriptor that a program makes raw before a byte access (the pattern Tracer::made_raw follows, as the FidelityFX upscaler's compiler emits) escapes the waterfall proof when its dwords were read from the first lane.

Where.

  • Tracer::descriptor traces the words the raw descriptor was made from, the made_raw swap.
  • When those words are v_readfirstlane_b32 results, classify → per_lane traces them as each lane's own descriptor (Source::Fetched).
  • first_lane_words decides whether track must prove a waterfall loop. It looks at the access's own SGPRs instead, where dwords 1-3 are the results of s_and_b32, s_mul_i32 and s_or_b32. It finds no first-lane reads, so no proof runs and nothing is refused.

Input (wave32):

global_load_dwordx4 v[4:7], v1, s[4:5]      ; each lane loads its own V# (v1 = (lane & 1) * 32)
v_readfirstlane_b32 s12..s15, v4..v7
s_bfe_u32 s16, s13, 0xe0010 ; s_max_u32 s16, s16, 1
s_and_b32 s13, s13, 0xc000ffff ; s_and_b32 s15, s15, 0xcfffffff
s_mul_i32 s14, s14, s16 ; s_or_b32 s15, s15, 0x30000000
buffer_load_dword v12, v16, s[12:15], 0 offen

No waterfall loop surrounds the access.

What happens on main 13f91ca. track returns Fetched, so each lane reads through its own descriptor. In a GPU run of that program under vkd3d-proton, odd lanes read the second buffer: [100, 201, 102, 203, ...].

Expected. One descriptor serves the whole wave:

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

Every lane reads lane 0's buffer, [100, 101, 102, ...]. As for any first-lane read outside a waterfall loop, the translation should refuse it ("a descriptor read from the first lane outside a waterfall loop", as in a_first_lane_read_outside_a_loop_is_no_waterfall).

Found by reading the code and checked with synthetic programs; I have no in-game observation. No game data. Analysis assisted by Claude Code.

**@⁠BastienRodz** on GitHub · 2026-11-25 22:46 UTC · [original](https://github.com/Marvisak/VIctory/issues/2867) A buffer descriptor that a program makes raw before a byte access (the pattern `Tracer::made_raw` follows, as the FidelityFX upscaler's compiler emits) escapes the waterfall proof when its dwords were read from the first lane. **Where.** - `Tracer::descriptor` traces the words the raw descriptor was made from, the `made_raw` swap. - When those words are `v_readfirstlane_b32` results, `classify` → `per_lane` traces them as each lane's own descriptor (`Source::Fetched`). - `first_lane_words` decides whether `track` must prove a waterfall loop. It looks at the access's own SGPRs instead, where dwords 1-3 are the results of `s_and_b32`, `s_mul_i32` and `s_or_b32`. It finds no first-lane reads, so no proof runs and nothing is refused. **Input** (wave32): ``` global_load_dwordx4 v[4:7], v1, s[4:5] ; each lane loads its own V# (v1 = (lane & 1) * 32) v_readfirstlane_b32 s12..s15, v4..v7 s_bfe_u32 s16, s13, 0xe0010 ; s_max_u32 s16, s16, 1 s_and_b32 s13, s13, 0xc000ffff ; s_and_b32 s15, s15, 0xcfffffff s_mul_i32 s14, s14, s16 ; s_or_b32 s15, s15, 0x30000000 buffer_load_dword v12, v16, s[12:15], 0 offen ``` No waterfall loop surrounds the access. **What happens on main 13f91ca.** `track` returns `Fetched`, so each lane reads through its own descriptor. In a GPU run of that program under vkd3d-proton, odd lanes read the second buffer: `[100, 201, 102, 203, ...]`. **Expected.** One descriptor serves the whole wave: - RDNA2 ISA, V_READFIRSTLANE_B32: "Copy one VGPR value to one SGPR ... Lane# = FindFirst1fromLSB(exec)". - RDNA2 ISA, buffer instructions: "All VM operations use a buffer resource constant (V#) which is a 128-bit value in SGPRs". Every lane reads lane 0's buffer, `[100, 101, 102, ...]`. As for any first-lane read outside a waterfall loop, the translation should refuse it ("a descriptor read from the first lane outside a waterfall loop", as in `a_first_lane_read_outside_a_loop_is_no_waterfall`). Found by reading the code and checked with synthetic programs; I have no in-game observation. No game data. Analysis assisted by Claude Code.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:16:17 +00:00
Author
Owner

@⁠rezioliver-collab on GitHub · 2026-11-25 23:11 UTC · original

On Wave64, #2869 accepted the raw buffer descriptor when the waterfall loop updated all 64 bits of EXEC. It rejected both the loop that updated only EXEC_LO and the shader with no loop. On main, the resource tracker classified the descriptor as Source::Fetched in all three cases without proving any of the comparisons or first-lane reads.

Synthetic Wave64 case main (842b0cb7) #2869 (dee92f59)
Full-width retry (s_xor_b64) Accepted Accepted. The tracker proved both 64-bit comparisons and all four v_readfirstlane_b32 results.
Low-half retry (s_xor_b32 on EXEC_LO) Accepted Rejected with a waterfall loop whose retry does not keep the lanes still waiting
No loop (s_cbranch_execnz replaced with s_nop) Accepted Rejected with a descriptor read from the first lane outside a waterfall loop

I ran a native victory-shader integration test on an Apple M1 (macOS 14.7, Rust 1.98.1). The test built the IR for a synthetic Wave64 compute shader and ran the CPU resource tracker with structured lane analysis. The shader read four descriptor words from the first active lane and converted the descriptor to raw form before buffer_load_dword. Each negative case changed a single instruction. Both rejections pointed to the same buffer load at byte offset 0x6c. Applying the PR commit to the tested main revision gave the same three results as the PR head.

**@⁠rezioliver-collab** on GitHub · 2026-11-25 23:11 UTC · [original](https://github.com/Marvisak/VIctory/issues/2867#issuecomment-7177255706) **On Wave64, #2869 accepted the raw buffer descriptor when the waterfall loop updated all 64 bits of `EXEC`. It rejected both the loop that updated only `EXEC_LO` and the shader with no loop.** On `main`, the resource tracker classified the descriptor as `Source::Fetched` in all three cases without proving any of the comparisons or first-lane reads. | Synthetic Wave64 case | `main` (`842b0cb7`) | #2869 (`dee92f59`) | |---|---|---| | Full-width retry (`s_xor_b64`) | Accepted | Accepted. The tracker proved both 64-bit comparisons and all four `v_readfirstlane_b32` results. | | Low-half retry (`s_xor_b32` on `EXEC_LO`) | Accepted | Rejected with `a waterfall loop whose retry does not keep the lanes still waiting` | | No loop (`s_cbranch_execnz` replaced with `s_nop`) | Accepted | Rejected with `a descriptor read from the first lane outside a waterfall loop` | I ran a native `victory-shader` integration test on an Apple M1 (macOS 14.7, Rust 1.98.1). The test built the IR for a synthetic Wave64 compute shader and ran the CPU resource tracker with structured lane analysis. The shader read four descriptor words from the first active lane and converted the descriptor to raw form before `buffer_load_dword`. Each negative case changed a single instruction. Both rejections pointed to the same buffer load at byte offset `0x6c`. Applying the PR commit to the tested `main` revision gave the same three results as the PR head.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 00:43 UTC · original

Automated triage for the maintainers.

Confirmed on main (63bcca4). In crates/victory-shader/src/resource.rs, Tracer::first_lane_words checks the access's own descriptor SGPRs for v_readfirstlane_b32 origins, while the descriptor itself is traced through Tracer::made_raw from the words before the s_and/s_mul/s_or rewrite. When dwords 1-3 are those rewritten values, first_lane_words returns None, so the waterfall proof in track never runs. The Wave64 comparison above (main vs. #2869) agrees.

Open pull request #2869 addresses this.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 00:43 UTC · [original](https://github.com/Marvisak/VIctory/issues/2867#issuecomment-7179056585) <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-25T23:11:55Z at=2026-11-26T00:59:00Z --> Automated triage for the maintainers. Confirmed on `main` (63bcca4). In `crates/victory-shader/src/resource.rs`, `Tracer::first_lane_words` checks the access's own descriptor SGPRs for `v_readfirstlane_b32` origins, while the descriptor itself is traced through `Tracer::made_raw` from the words before the `s_and`/`s_mul`/`s_or` rewrite. When dwords 1-3 are those rewritten values, `first_lane_words` returns `None`, so the waterfall proof in `track` never runs. The Wave64 comparison above (main vs. #2869) agrees. Open pull request #2869 addresses this. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
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#2867
No description provided.