Skip to content

Shaders: dwords read from the first lane outside a waterfall's own reads are one lane's (#2829) - #2831

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

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

Conversation

@BastienRodz

Copy link
Copy Markdown
Contributor

What's wrong

Tracer::classify traced every v_readfirstlane_b32 result as the dwords each lane holds. That is right only for the reads that a waterfall loop at the access compares, which track proves (first_lane_words). Reads that reach classify another way were never proven:

  • Copied back to VGPRs before a loop (v_readfirstlane_b32 s24, v4; v_mov_b32 v4, s24). Every lane now holds the first lane's descriptor, yet the image traced to Fetched and each lane sampled its own entry. In a vkd3d-proton run with entry (v0 & 1) << 5, the lanes read [1.0, 2.0, 1.0, 2.0, ...] where the console gives 1.0 in all of them.
  • Picked by s_cselect or joined at an SGPR phi after the read. The dwords only had to agree in the lanes that access the descriptor, but the first lane can be another one. In the test, lane 0 kept its old VGPRs while the accessing lanes overwrote theirs under EXEC.

RDNA2 ISA, V_READFIRSTLANE_B32: "Copy one VGPR value to one SGPR ... Lane# = FindFirst1fromLSB(exec) (Lane# = 0 if exec is zero). Ignores exec mask for the access."

What the fix does

  • descriptor traces the access's own first-lane reads as before: the reads the waterfall proof covers.
  • classify now handles any other first-lane read differently. It traces the read over the lanes that run it, the reach of its block. A source that can differ between lanes is refused with the existing "a descriptor read from the first lane outside a waterfall loop", the same rule main already applies to a first-lane read at the access with no waterfall loop.
  • New helpers: Tracer::first_lanes, and Source::per_lane (whether lanes may hold different descriptors).

Tests

New resource::tests::first_lane_reads_no_waterfall_loop_proves_are_not_each_lanes_own covers both shapes.

  • With resource.rs from main it fails ("not refused: ... Fetched { load: (0, 5) }").
  • With the fix both shapes are refused.

Other runs, all under Wine and vkd3d-proton:

  • All 34 resource::tests pass, as do the 5 GPU waterfall_tests (lanes sampling their own texture, nested arms, v_cmpx-narrowed loops).
  • The whole victory-shader lib was run one test per process, on this head and on main with only the new test added. The results are identical except for that 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: semantics and hardware comparisons, 64-bit image atomics, stub_pipeline_is_created, and a few synthetic DPP or gather tests.
  • cargo clippy --workspace --all-targets --locked -- -D warnings is clean.

Not tested

Fixes #2829

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

🤖 Generated with Claude Code

…ads are one lane's

`Tracer::classify` traced every `v_readfirstlane_b32` result as the
dwords each lane holds. That is right only for the reads a waterfall
loop at the access compares, which `track` proves. Reads reached another
way were never proven:

- copied back to VGPRs before a loop (`v_readfirstlane_b32 s24, v4`,
  `v_mov_b32 v4, s24`): a per-lane source (a `global_load` entry) came
  out as each lane's own, though every lane holds the first lane's;
- picked by `s_cselect` or joined at an SGPR phi: the dwords had to be
  the same only in the lanes that access the descriptor, but the first
  lane may be another (lane 0 kept its old VGPRs, the accessing lanes
  overwrote theirs under EXEC).

RDNA2 ISA, V_READFIRSTLANE_B32: "Copy one VGPR value to one SGPR ...
Lane# = FindFirst1fromLSB(exec)".

The access's own reads are now traced in `descriptor` as before. Others
must give the same descriptor in every lane that runs the reads (the
reach of their block); a per-lane source is refused as "a descriptor
read from the first lane outside a waterfall loop".

Test: `first_lane_reads_no_waterfall_loop_proves_are_not_each_lanes_own`
(both shapes; on main the first traces to `Fetched`, the second to
`Select` of the first and second buffers).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@BastienRodz

Copy link
Copy Markdown
Contributor Author

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

  • victory-shader lib: 271 passed, 0 failed, 3 ignored, including resource::tests::first_lane_reads_no_waterfall_loop_proves_are_not_each_lanes_own and every waterfall_tests GPU test.
  • Every other crate in the workspace: no failures.

@fuzeofficlal

Copy link
Copy Markdown
Contributor

Verified 74169903 on Windows 11 (RTX 5090 + WARP + Windows SDK 10.0.26100.0 dxil.dll):

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

Sound tightening for #2829: dwords that are all readfirstlane results defined in one block only carry that block's lanes in 'runs', and a per-lane result outside a proven waterfall now refuses instead of treating a uniform broadcast as each lane's own descriptor. Conservative in the right direction. LGTM.

@Machad3x

Copy link
Copy Markdown

Hardware result: tested at head 7416990. One host: RTX 3080 Ti, driver 621.24, Windows 11, a fork stacking open PRs, Series X mode. Cherry-picked together with #332 and #2816: the shader tests pass apart from one failure the stack had before, and one 7-minute run in play had no device removal. Window scene medians 670 ms a frame and 307 ms GPU step (694 and 331 without the three; one run each).

Ran with AI assistance (Claude Code).

@cloph-dsp

Copy link
Copy Markdown

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

  • git diff --check against merge-base 13f91ca is clean; 1 file, +114/-5.
  • Negative control: resource::tests::first_lane_reads_no_waterfall_loop_proves_are_not_each_lanes_own is absent from the base commit.
  • cargo test --locked -p victory-shader --lib -- resource::tests::first_lane_reads_no_waterfall_loop_proves_are_not_each_lanes_own --exact --quiet -> 1 passed (273 filtered out).
  • cargo test --locked -p victory-shader --lib -- resource::tests --quiet -> 34 passed, 0 failed.
  • Full victory-shader lib was not run: known base-line Wine/hardware failures are unrelated to this change.

AI-assisted (Hy4 flash).

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

On main, Tracer::classify (crates/victory-shader/src/resource.rs) traced any v_readfirstlane_b32 descriptor dwords as each lane's own. That is only proven for the reads a waterfall loop at the access compares. Reads copied back to VGPRs, or picked or joined after the read, came out as per-lane Fetched even though every lane holds one lane's value.

The PR changes two things:

  • descriptor keeps the proven per-lane path for reads at the access (the new first_lanes helper).
  • classify now traces other first-lane reads over the reach of their block. A source that can differ between lanes (Source::per_lane) is refused with the message main already uses.

The cited ISA wording backs this. The new test covers both shapes, and others confirmed passes on WARP, an RTX 5090 and vkd3d-proton.

The trade-off: affected programs now get a refusal instead of wrong sampling, and how many title shaders hit this is not measured. A run over a shader dump would settle that.

Verdict: merge candidate (a recommendation to look, not an approval). CI: passing.


Generated by Claude Code

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

Tested merged onto origin/main (63bcca4) on Windows 11 x64:

  • cargo test -p victory-shader --lib resource::tests: 36 passed, 0 failed (including new first_lane_reads_no_waterfall_loop_proves_are_not_each_lanes_own).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

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 and verified 74169903 against origin/main (63bcca43; clean three-way git merge-tree preserving main's Tracer::sum cache):

  • Moving non-waterfall v_readfirstlane_b32 classification to carry block reach (crates/victory-shader/src/resource.rs:1107-1141) cleanly catches the copy-back and s_cselect paths targeted by #2829 while continuing to reject partial first-lane descriptors.
  • Local verification: xtask policy (184 files ok), cargo clippy -p victory-shader --all-targets -- -D warnings (default and --all-features) clean, resource::tests (34 passed), emit::lower::tests (27 passed), and emit::waterfall_tests (5 passed on both RTX 5090 and WARP).

Note for merge ordering: the pre-existing made_raw mismatch where descriptor unwraps self.made_raw(&words) (resource.rs:1084-1088) while first_lane_words (resource.rs:1516-1526) inspects the raw operands is addressed orthogonally in #2869; a three-way merge of #2831 + #2869 applies cleanly with zero conflicts so both paths share words() once both land.

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor

I reproduced the same-register masked rewrite from #2829 using this PR’s s_cselect fixture. The only input change is that the four masked v_mov_b32 instructions copy from s[28:31] again. On 7416990 the added case returns a per-lane descriptor written where some lanes may keep the old one.

The optional follow-up applies directly to 7416990. When a lane can skip a plain VGPR move, it accepts the move if the previous definition in the same block copies the same value and is proved to execute in every relevant lane. The new case now traces both arms of the select to table offset 0x20. The existing cases where lanes really hold different descriptor words still refuse with the original errors. Separate loads from the same address remain distinct.

  • Exact PR head plus the follow-up: 34 resource tests, 5 WARP waterfall tests, strict shader Clippy passed.
  • Combined with current upstream 63bcca4: 36 resource tests, 5 WARP waterfall tests, policy check passed.

Follow-up commit acfb0eb. If you take it, please retain its Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <andrewpozdnakov7-jpg@users.noreply.github.com> if folding it into another commit.

AI-assisted with Codex.

@BastienRodz

Copy link
Copy Markdown
Contributor Author

Thanks for reproducing the masked-rewrite case and sharing acfb0eb!

I'd rather keep #2831 minimal on 74169903 — it already has the merge-candidate triage verdict and several independent reviews/runs on this head, and changing the head would reset those for a relaxation of a conservative refusal on a synthetic redundant-move shape. It would make a clean separate follow-up PR on top once #2831 lands (especially if any title shader hits this pattern).

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 descriptor read from the first lane but picked, joined or copied back before a waterfall loop is traced as each lane's own

8 participants