Shaders: a descriptor read from the first lane but picked, joined or copied back before a waterfall loop is traced as each lane's own #2829

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

@⁠BastienRodz on GitHub · 2026-11-25 21:38 UTC · original

resource::Tracer::classify traces every v_readfirstlane_b32 result as "the dwords each lane holds". That holds only for the reads that a waterfall loop at the access compares, the ones track proves through first_lane_words. Reads that reach classify any other way get the same per-lane treatment with nothing proving it. The per-lane descriptors came in with #307 and #566.

Shape 1: read, copied back to VGPRs, then a waterfall loop.

v_readfirstlane_b32 s24, v4 ; ... for v4..v11
v_mov_b32 v4, s24           ; ... back into v4..v11
<the usual waterfall loop over v4..v11>
  • On the console, every lane now holds the first lane's descriptor (V_READFIRSTLANE_B32: "Copy one VGPR value to one SGPR ... Lane# = FindFirst1fromLSB(exec)"; V_MOV_B32: "D.u = S0.u").
  • On main 13f91ca the image traces to Fetched { load: (0, 5) }, and each lane samples with its own entry. In a run on vkd3d-proton with entry (v0 & 1) << 5, the result alternates [1.0, 2.0, 1.0, 2.0, ...]. The console would give the first lane's value, 1.0, in all 32 lanes.

Shape 2: picked by s_cselect (or joined at an SGPR phi) after the read.

  • All lanes set v4..v7 to the buffer at 0x20.
  • Lanes 16 and up then overwrite them under EXEC with the buffer at 0x0.
  • EXEC is restored, then v_readfirstlane s[12:15], then s_cselect_b64 s[12:15], s[12:15], s[28:31].
  • Finally a buffer_load that only lanes 16 and up run.

Main traces this to Select { [Loaded 0x0, Loaded 0x20] }. The first lane is lane 0, which holds 0x20, so the console reads 0x20 whatever SCC is. Main checks that the dwords agree only in the lanes that access the descriptor, not in the lanes that run the read.

Expected. The same rule main already applies to a first-lane read at the access without a waterfall loop: such a read is one lane's, so a descriptor that can differ between lanes is refused ("a descriptor read from the first lane outside a waterfall loop").

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 21:38 UTC · [original](https://github.com/Marvisak/VIctory/issues/2829) `resource::Tracer::classify` traces every `v_readfirstlane_b32` result as "the dwords each lane holds". That holds only for the reads that a waterfall loop at the access compares, the ones `track` proves through `first_lane_words`. Reads that reach `classify` any other way get the same per-lane treatment with nothing proving it. The per-lane descriptors came in with #307 and #566. **Shape 1: read, copied back to VGPRs, then a waterfall loop.** ``` v_readfirstlane_b32 s24, v4 ; ... for v4..v11 v_mov_b32 v4, s24 ; ... back into v4..v11 <the usual waterfall loop over v4..v11> ``` - On the console, every lane now holds the first lane's descriptor (V_READFIRSTLANE_B32: "Copy one VGPR value to one SGPR ... Lane# = FindFirst1fromLSB(exec)"; V_MOV_B32: "D.u = S0.u"). - On main 13f91ca the image traces to `Fetched { load: (0, 5) }`, and each lane samples with its own entry. In a run on vkd3d-proton with entry `(v0 & 1) << 5`, the result alternates `[1.0, 2.0, 1.0, 2.0, ...]`. The console would give the first lane's value, `1.0`, in all 32 lanes. **Shape 2: picked by `s_cselect` (or joined at an SGPR phi) after the read.** - All lanes set `v4..v7` to the buffer at 0x20. - Lanes 16 and up then overwrite them under EXEC with the buffer at 0x0. - EXEC is restored, then `v_readfirstlane s[12:15]`, then `s_cselect_b64 s[12:15], s[12:15], s[28:31]`. - Finally a `buffer_load` that only lanes 16 and up run. Main traces this to `Select { [Loaded 0x0, Loaded 0x20] }`. The first lane is lane 0, which holds 0x20, so the console reads 0x20 whatever SCC is. Main checks that the dwords agree only in the lanes that access the descriptor, not in the lanes that run the read. **Expected.** The same rule main already applies to a first-lane read at the access without a waterfall loop: such a read is one lane's, so a descriptor that can differ between lanes is refused ("a descriptor read from the first lane outside a waterfall loop"). 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:15:16 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 21:46 UTC · original · edited 2026-11-26 00:45 UTC

Automated triage for the maintainers.

Confirmed by reading main (63bcca4). In crates/victory-shader/src/resource.rs, Tracer::classify sends any words that are all v_readfirstlane_b32 results (first_lane_source) to per_lane, without condition. track proves only the reads that first_lane_words finds directly at an access, through Tracer::waterfall. Reads that reach classify through select/phi, or through a copy back into VGPRs, therefore become per-lane descriptors with nothing proving it, and the refusal "a descriptor read from the first lane outside a waterfall loop" is never reached for them.

The per-lane path came in with #307 and #566 (both merged). Open PR #2831 addresses this issue; per the comparison above it also refuses masked writes that put the identical descriptor back, which the PR's review should weigh.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 21:46 UTC · [original](https://github.com/Marvisak/VIctory/issues/2829#issuecomment-7175519688) · edited 2026-11-26 00:45 UTC <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-25T22:09:53Z at=2026-11-26T01:07:30Z --> Automated triage for the maintainers. Confirmed by reading `main` (63bcca4). In `crates/victory-shader/src/resource.rs`, `Tracer::classify` sends any words that are all `v_readfirstlane_b32` results (`first_lane_source`) to `per_lane`, without condition. `track` proves only the reads that `first_lane_words` finds directly at an access, through `Tracer::waterfall`. Reads that reach `classify` through `select`/`phi`, or through a copy back into VGPRs, therefore become per-lane descriptors with nothing proving it, and the refusal "a descriptor read from the first lane outside a waterfall loop" is never reached for them. The per-lane path came in with #307 and #566 (both merged). Open PR #2831 addresses this issue; per the comparison above it also refuses masked writes that put the identical descriptor back, which the PR's review should weigh. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

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

I reproduced the SGPR phi variant of shape 2 on an Apple M1. #2831 correctly rejects the case where lanes hold different descriptors. It also rejects a masked write that copies the identical descriptor back, even from the exact same source registers.

All 32 lanes initially hold the descriptor at table offset 0x20. Each phi(read, copy) below lists the table offsets traced on the first-lane and scalar-copy paths, respectively.

Write by lanes 16–31 before restoring full EXEC main (4a53da72) #2831 (74169903)
Overwrite with the descriptor at 0x00 Accepted, incorrect phi(0x00, 0x20) Rejected
No overwrite Accepted, phi(0x20, 0x20) Accepted, phi(0x20, 0x20)
Rewrite with a separate load from the same offset 0x20 Accepted, phi(0x20, 0x20) Rejected
Rewrite from the same s[28:31] registers used for the initial write Accepted, phi(0x20, 0x20) Rejected

I ran a native CPU-side victory-shader integration test on macOS 14.7 with Rust 1.98.1, using synthetic GFX10 Wave32 compute shaders. A scalar branch keeps the four v_readfirstlane_b32 results on one path and copies s[28:31] on the other. The test checked that buffer_load_dword consumes four two-input SGPR phis, one for each of s12 through s15, then checked the resource tracker's result.

In the first row, lane 0 still holds 0x20 when v_readfirstlane_b32 runs with full EXEC. Only the later buffer load is restricted to lanes 16–31, so both scalar paths should give 0x20. All three rejections on #2831 occurred at the buffer load (0x78) with a per-lane descriptor written where some lanes may keep the old one. Applying #2831 to the tested main commit gave the same four results as the PR head.

**@⁠rezioliver-collab** on GitHub · 2026-11-25 22:09 UTC · [original](https://github.com/Marvisak/VIctory/issues/2829#issuecomment-7176017227) I reproduced the SGPR phi variant of shape 2 on an Apple M1. **#2831 correctly rejects the case where lanes hold different descriptors. It also rejects a masked write that copies the identical descriptor back, even from the exact same source registers.** All 32 lanes initially hold the descriptor at table offset `0x20`. Each `phi(read, copy)` below lists the table offsets traced on the first-lane and scalar-copy paths, respectively. | Write by lanes 16–31 before restoring full EXEC | main (`4a53da72`) | #2831 (`74169903`) | |---|---|---| | Overwrite with the descriptor at `0x00` | Accepted, incorrect `phi(0x00, 0x20)` | Rejected | | No overwrite | Accepted, `phi(0x20, 0x20)` | Accepted, `phi(0x20, 0x20)` | | Rewrite with a separate load from the same offset `0x20` | Accepted, `phi(0x20, 0x20)` | Rejected | | Rewrite from the same `s[28:31]` registers used for the initial write | Accepted, `phi(0x20, 0x20)` | Rejected | I ran a native CPU-side `victory-shader` integration test on macOS 14.7 with Rust 1.98.1, using synthetic GFX10 Wave32 compute shaders. A scalar branch keeps the four `v_readfirstlane_b32` results on one path and copies `s[28:31]` on the other. The test checked that `buffer_load_dword` consumes four two-input SGPR phis, one for each of `s12` through `s15`, then checked the resource tracker's result. In the first row, lane 0 still holds `0x20` when `v_readfirstlane_b32` runs with full `EXEC`. Only the later buffer load is restricted to lanes 16–31, so both scalar paths should give `0x20`. All three rejections on #2831 occurred at the buffer load (`0x78`) with `a per-lane descriptor written where some lanes may keep the old one`. Applying #2831 to the tested main commit gave the same four results as the PR head.
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#2829
No description provided.