Skip to content

Shaders: one lane of a whole-wave section's value, read after the section - #3402

Open
Lyrnc wants to merge 1 commit into
Marvisak:mainfrom
Lyrnc:fix/wave-section-lane-read
Open

Lyrnc wants to merge 1 commit into
Marvisak:mainfrom
Lyrnc:fix/wave-section-lane-read

Conversation

@Lyrnc

@Lyrnc Lyrnc commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

What was refused

Three wave64 compute programs of the title's FidelityFX upscaler DLL (amd_fidelityfx_upscaler_xbox.dll):
17af85f170e66f30, 477b52e73ddeb6f2, 8b437ab61d8008fe. On main they stop earlier, at
a lane mask read as data (fixed by #3401); past that, each stops at
a whole-wave section step the simulation does not follow, at its final store.

Each ends with a wave OR reduction of the form the console compiler writes for wave64 (as this PR's test
writes it):

    s_or_saveexec_b64   s[14:15], -1
    v_cndmask_b32       v7, 0, v6, s[14:15]
    v_or_b32            v7, v7, v7 quad_perm:[1,0,3,2]
    v_or_b32            v7, v7, v7 quad_perm:[2,3,0,1]
    v_or_b32            v7, v7, v7 row_half_mirror
    v_or_b32            v7, v7, v7 row_mirror
    v_permlanex16_b32   v3, v7, 0, 0
    v_or_b32            v7, v3, v7          ; each half holds its own 32 lanes' OR
    v_readlane_b32      s16, v7, 0
    v_or_b32            v7, s16, v7         ; the high half now holds the whole wave's
    s_mov_b64           exec, s[14:15]
    v_readlane_b32      s16, v7, 63         ; read after the section

The section simulation lowers a value that leaves the section only where every lane agrees on one shape.
Here the low half holds its own lanes' OR and the high half the whole wave's, so v7 had no shape, and the
read at lane 63 after the section was refused.

What changed

  • emit/wave.rs: Section::lanes keeps, for a value whose lanes differ, what each lane holds where that does not
    depend on the lane reading it: a reduction over all lanes, a constant, a uniform value (never a lane's own value
    of a VGPR). Values with one shape are unchanged.
  • emit/lower.rs: a v_readlane_b32 at a constant lane, outside the section, of such a value is lowered by that
    lane's shape (shape(), the same lowering as a section value with one shape). A lane without one (here lane 0,
    which holds only the low half's OR) is still refused.

Tests

  • wave::tests::a_wave64_reduction_finished_in_the_high_half_is_known_per_lane (no GPU): the sequence above;
    lanes 32-63 are the reduction over the wave, lanes 0-31 have no lane-independent shape, the value no shape.
  • crosslane_tests::whole_wave_section_read_at_one_lane_after_it_on_gpu (wave32, 32 lanes, hardware adapter):
    the same idea within one wave32: rows reduced with DPP, row 0's result (lane 0) ORed in, so only row 1 holds the
    whole wave's, read at lane 31 after EXEC is restored; under a branch on three of four lanes, on 1 << lane, so
    the answer (0x77777777) differs from a dropped row (half of it) and from counting inactive lanes (0xFFFFFFFF).
  • crosslane_tests::wave64_section_read_at_lane_63_after_it: the wave64 sequence above under a branch on the lanes
    with lane & 2 == 0, on 1 << (lane >> 1): 0x55555555 (a dropped half gives 0x5555 or 0x55550000, inactive
    lanes counted 0xFFFFFFFF). Lowered and validated everywhere, run where the host has 64-lane waves.

Results:

  • RTX 5080 (the default adapter): all three pass; the wave64 test is lowered and validated (no 64-lane waves on
    NVIDIA).
  • AMD Radeon iGPU (RDNA2 gfx1036, picked with a local adapter filter that is not part of this PR): all three pass,
    the wave64 program dispatched on 64-lane waves.
  • With main's wave.rs and lower.rs the two GPU tests fail at lowering with
    a whole-wave section step the simulation does not follow.
  • RDNA2 hardware (gfx1036 through a hardware oracle running hand-written GFX10 assembly, 64 rows): both test
    sequences run natively give 0x77777777 (wave32, read at lane 31) and 0x55555555 (wave64, read at lane 63) in
    every running lane: 0 differences from the tests' expected values.
  • cargo clippy -p victory-shader --lib --tests -- -D warnings: clean. cargo xtask policy: 191 files ok.
  • cargo test -p victory-shader --lib -- --test-threads=1 on the RTX 5080, skipping
    heap_direct_texture_reads_mark_their_heap_index (it kills the test process here, as Shader tests: heap_direct_texture_reads_mark_their_heap_index kills the test process on a real GPU (RTX 5070, main 67e8ae1) #2571 reports): 301 passed,
    3 failed, 3 ignored; the three (stride_tests::a_heap_buffer_read_* twice,
    synthetic_tests::gathers_at_a_level_match_the_hardware) fail the same way on main 63bcca4 here.

Census (offline, the title's shader pack, exe and DLLs)

translate --list --validate over shaders.rpf, the executable, XboxBvhBuilder.dll and
amd_fidelityfx_upscaler_xbox.dll, validator dxc 1.9.2609 dxil.dll, compared program by program:

main 63bcca4 this branch this branch + #3401
compute programs validated 1,985 1,985 1,989
all programs validated 24,937 24,937 24,941

Both this and #3401 append tests at the end of emit/crosslane_tests.rs; whichever merges
second has a trivial conflict there (keep both blocks; git takes the closing brace as shared, so check it).

Not tested

  • No live run (the title's own upscaler runs only in Series S mode without VICTORY_FIDELITYFX_DIR; the game was
    not started).
  • The three programs declare a wave size of 64: NVIDIA hosts refuse their pipelines whatever this change does.

AI use: Claude Code (Claude Opus 5.5) found the refusal in the offline census, wrote the change, the tests and
this text, and ran the checks on our machine; Lyrnc reviews what goes out. No game data is included (hashes,
counts and error text only; the sequence above is the test's, written by hand).

🤖 Generated with Claude Code

…tion

A whole-wave section's value leaves it lowered only where every lane
agrees on one shape. The wave64 OR (and the like) reductions the console
compiler writes reduce each half with DPP and v_permlanex16_b32, then
read lane 0 and combine it into every lane, so that only the high half
holds the whole wave's result; the program restores EXEC and reads lane
63 with v_readlane_b32. The lanes of that value differ, so it had no
shape and the read was refused ("a whole-wave section step the
simulation does not follow"). Three compute passes of the title's
FidelityFX upscaler end so.

The simulation now also keeps, for a value whose lanes differ, what each
lane holds where that does not depend on the lane reading it (a
reduction over all lanes, a constant, a uniform value; never a lane's
own value). A v_readlane_b32 of such a value at a constant lane, outside
the section, is lowered by that lane's shape.

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

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

LGTM — verified on RTX 5090 and VICTORY_WARP=1 (Windows / D3D12) against origin/main (63bcca4).

  • Tracking per-lane results of a whole-wave section so a subsequent single-lane read (including lane 63 of a wave64 reduction) lowers accurately passes cleanly on both RTX 5090 and WARP.
  • cargo test -p victory-shader --lib emit::wave:: -- --test-threads=1: 8 passed, 0 failed (a_wave64_reduction_finished_in_the_high_half_is_known_per_lane).
  • cargo test -p victory-shader --lib emit::crosslane_tests:: -- --test-threads=1: 7 passed, 0 failed on RTX 5090 and 7 passed, 0 failed on VICTORY_WARP=1 (whole_wave_section_read_at_one_lane_after_it_on_gpu, wave64_section_read_at_lane_63_after_it).
  • 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).

@Aniseto

Aniseto commented Nov 26, 2026

Copy link
Copy Markdown

Ran the whole-wave-section tests at d1158c9 on an NVIDIA Blackwell desktop part:

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, Rust 1.98.1 (pinned by rust-toolchain.toml), MSVC 14.44.35207, DXC 1.9.2609.5 (shared env), debug build.

cargo test -p victory-shader --lib -- whole_wave_section_read_at_one_lane_after_it_on_gpu a_wave64_reduction_finished_in_the_high_half_is_known_per_lane --test-threads=1
2 passed; 0 failed; 0 ignored; 0 measured; 306 filtered out      (exit 0)

Both pass: the wave32 fixture ran a dispatch on the real 32-lane adapter, and the wave64 reduction test passed at translation level. I did not run wave64_section_read_at_lane_63_after_it, which needs a 64-lane host. The PR has no comments yet; the author tested on an RTX 5080, so this adds a second NVIDIA datapoint on driver 32.0.16.2124.

Not tested: the wave64 GPU dispatch, the title's FidelityFX shaders, a paired smoke run, the full workspace suite, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

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

Tracking per-lane Shape in Section::lanes for whole-wave Wave64 split-half reductions is a very clean idea, and both new tests pass validation (with Wave32 GPU readback passing on RTX 5090, 48/48 tests green).

However, there is one P1 regression in how section_lane materializes the read shape:

  • Unlike shapes — which calls self.shape(sh) immediately at section_inst (crates/victory-shader/src/emit/lower.rs:1162) while self.cur is still in the section's block — section_lanes defers calling self.shape(shape) until the v_readlane_b32 consumer (lower.rs:6682-6686).
  • If there is a divergent branch between the whole-wave section and the v_readlane_b32 (for example, the section computes an all-lane Op::Or reduction 0xFFFFFFFF before an even-lane branch, and v_readlane_b32 s15, v7, 31 executes inside that even-lane branch), self.shape(shape) emits waveActiveBit at the divergent branch block (self.cur), which only sees the even lanes and silently returns 0x55555555 instead of 0xFFFFFFFF.

Materializing (and caching) the needed section_lanes shapes eagerly at section_inst (just like shapes) — or rejecting deferred reads across divergent control flow — would close this cleanly.

Non-blocking notes:

  • P1 (pre-existing): v_readfirstlane_b32 (lower.rs:6715) does not consult section_lanes and can pick host lane 0 when restored EXEC excludes lane 0.
  • P2: dynamic/SGPR lane indices, out-of-range indices (>= wave_size), and values flowing through a non-trivial VGPR phi before v_readlane_b32 miss section_lanes and fall back to Val::Missing.

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor

Following up on the Wave64 runtime check, I combined this exact head d1158c9 with #3401 at d9ed313. The tested merge resolves the shared test-file conflict and adds a regression for the ordered pair.

The regression runs the two patterns in a single synthetic shader. The first true comparison is in lane 63 on iteration 2 of a bounded poll. The shader then performs the whole-wave OR and reads lane 63 after restoring EXEC. Readback must contain 0x55555557 in the 32 participating lanes and the original sentinel 7 in the other 32.

With the identical fixture, #3402 alone stops at a lane mask read as data and #3401 alone stops at a whole-wave section step the simulation does not follow. The combined branch validated and dispatched the Wave64 shader in three fresh WARP 1.0.22 processes, with all 64 words matching each time. The cross-lane and wave suites reported 18 passed. This WARP runtime skipped Wave32 dispatches. Strict clippy with default and all features and the 192-file asset-policy check passed.

The merge retains both parent commits and both sets of tests. It moves the mask-SCC helpers to keep lower.rs below the size limit. Maintainers can use the composition when ordering the two PRs. If folding the new regression into another commit, please retain the Git author or add Co-authored-by: andrewpozdnakov7-jpg.

@andrewpozdnakov7-jpg

andrewpozdnakov7-jpg commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

@Lyrnc f9e2015 is directly on d1158c9. It materializes only the statically requested lane values while lowering the whole-wave section, then reuses them at the later read.

I reproduced the review case on app-local WARP. An all-lane OR followed by a read inside an even-lane branch returned 0x55555555 in 16 lanes. On the follow-up all 16 readers return 0xFFFFFFFF and the other 16 retain the old destination. The original branched case and the Wave64 lane-63 test also passed. Strict shader Clippy passed in both configurations.

If you take the patch, please retain Git authorship when cherry-picking or rebasing. If folded into another commit, please add Co-authored-by: andrewpozdnakov7-jpg <andrewpozdnakov7-jpg@users.noreply.github.com>.

AI-assisted with Codex. Synthetic shaders only.

I also resolved the test-file overlap and the shader file-size limit in c75cc68, which combines the two reviewed follow-ups. Both SCC regressions and both section-lane tests passed in the combined app-local WARP build.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants