Shaders: a lane mask written a dword at a time keeps its high dword #3402
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3402"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Lyrnc on 2026-11-29T22:50:31Z.
No issue filed: found while checking wave64 programs on a host of 32-lane waves against a wave64 card with hand-written programs.
What it changes
What was wrong. On a host of 32-lane waves, a wave64 lane mask that is a number, not an EXEC or VALU result, becomes an opaque atom named by its low dword (
Atom::Opaque), and lowering took the high dword from the instruction that wrote the low one (pair_high). The compiler writes a 64-bit constant mask as twos_mov_b32. There the low dword's instruction writes no high dword, and lanes 32-63 took the low dword's bits. With EXEC set from such a pair:v_mbcnt_hi_u32_b32ands_bcnt1_i32_b64of EXEC counted the low dword twice;v_cndmask_b32on the pair picked by the low dword.A mask whose halves are equal (alternate lanes) came out right by chance.
What this does.
structureexports, for such pairs, the high dword each low dword is read with (Structured::opaque_highs, wave64 only; none for a low dword that is split or read with two different high dwords), andpair_hightakes it where the low dword's own instruction has no high dword. Every other pair is lowered as before. A low dword read with two high dwords still takes the low dword's bits; the comment instructure.rssays so.This is in the plain lowering of wave64 programs for 32-lane hosts, not in
crate::fold: the measured programs took the first form, with no retry. Folding being off by default on main (5c262d7b,05d1c564) does not change where it applies.Rebased onto main
7995b81basae160865(the commit is unchanged; none of the three files has changed on main since829188e9).Credit: no code from other pull requests.
How it was tested
emit::emitfor a host of 32-lane waves (every form it tries), run on the RTX 5080 and on the Radeon as a 32-lane host, and all 16 outputs of all 64 lanes are compared. The harness is local (emit::fw64_local_tests, not in this branch):VICTORY_ADAPTER=nvidia|radeon LOCAL_FW64_HOSTWAVE=32 LOCAL_FW64_OUT=<file> VICTORY_WAVE_WHY=1 <test exe> --ignored --exact --nocapture --test-threads=1 emit::fw64_local_tests::<local_fw64_wave_wide|local_fw64x_wave_wide|local_nx_cases>.829188e9): 156 exact, 51 differ, 12 refused, the same on both cards. Of the five programs that set EXEC from twos_mov_b32and then read it (v_readfirstlane_b32,v_mbcnt,s_bcnt1_i32_b64,s_ff1_i32_b64, a write under it), 4 differ (upper half, lane 40, a sparse mask, lanes 31-32); alternate lanes is exact.a_lane_mask_written_a_dword_at_a_time_keeps_its_high_dword(masks: upper half, lane 40, sparse, lanes 31-32, alternate lanes; a write,v_mbcntands_bcnt1of EXEC and av_cndmask_b32on the pair; the DXIL validated when a validator is found): passes on both cards. The same test on829188e9fails on both (mask 0xffffffff00000000, lane 32).cargo testpassed for the crates it touches: yes, apart from 3 tests that fail on main in the same way. Onae160865(main7995b81b+ this commit), RTX 5080:cargo test -p victory-shader --lib -- --test-threads=6: 460 passed, 3 failed, 9 ignored. The new test passes. The 3 failures areemit::barycentric_tests::first_half_values_render_on_hardware_and_warp,emit::rect::tests::rectangles_are_drawn_wholeandemit::rect::tests::the_rectangle_stage_is_a_geometry_shader, all withContainer part 'Pipeline State Validation' does not match expected for modulefrom the local DXIL validator. The same 3 fail the same way on main7995b81bwithout this change.cargo check -p victory-gpu: passes.cargo clippy -p victory-shader --all-targets -- -D warnings: fails on main's own code (unused importsPAIR_MEETINGSinemit/lower/analysis.rs:6andanalysis::lane_regionsinemit/lower.rs:594,while_immutable_conditioninemit/lower/analysis.rs:467,too_many_argumentsinnative.rs:1655). None is on a line this change touches.829188e9base) plus a two-linemodfor the local harness, built withcargo test -j 6 -p victory-shader --lib --no-run, then the test binary:VICTORY_ADAPTER=nvidia|radeon <exe> --exact --nocapture --test-threads=1 emit::wave64_tests::a_lane_mask_written_a_dword_at_a_time_keeps_its_high_dword: 1 passed on each card; on829188e9with the test added, 1 failed on each card;<exe> --test-threads=4 structure emit::wave64_tests emit::folded_tests emit::lower fold:: emit::crosslane_tests(RTX 5080): 114 passed, 0 failed, 1 ignored; on829188e9with the new test added, 113 passed, 1 failed (the new test).829188e9, whose copies of these files main still has; only thecargo testrun above is on main); Series S; cards other than the RTX 5080 and the gfx1036.Checked for overlap
console_laneandlane_bitwithhalves) is on main already. Same symptom, another cause: here the lane index is right and the high dword's value was wrong.lower.rs(scalar splits, first-lane reads,v_writelane, mask phis through loops); nothing on the high dword of a pair, no shared hunks.folded(), the order inemit_strict), not this lowering; no shared files.structure.rs,Lanes::join: joins fed by a scalar load are taken as data. Next to this change's function but other lines. Such joins land in the same non-derived set (other) thatopaque_highsis taken from; the two were not tested together.v_cndmask_b32masks intersected withpartial_activeon 32-lane hosts, about lanes past the dispatch count; other lines oflower.rs, not the high dword.AI use
Claude Code (Claude Opus 5.5) found the cause with the oracle programs, wrote the change, the test and the oracle programs, ran the measurements and wrote this description. No code from other authors.
🤖 Generated with Claude Code
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by nick0451 on 2026-11-30T01:51:11Z.
Exact translation check, with no game run: the title's shaders (game folder: 26,599 containers, 26,180 programs, 25,789 with emitted DXIL hashes),
victory translate --listwithVICTORY_HOST_WAVE=32, main41adb551(v2026.11.29.05) against this PR merged onto it.Result: the output is the same for every program. All 25,789 output hashes match main, nothing fails to translate, and the summary counts are unchanged. So this title doesn't hit the pattern this PR changes, and the PR changes nothing for it, which also means no risk of a regression there. The fix may still matter for other titles or for the hand-written cases in the PR's tests.
(RTX 3090 host. The listing doesn't depend on the card, only on
VICTORY_HOST_WAVE.)🤖 Generated with Claude Code
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by dyshay on 2026-11-30T03:12:06Z.
Merged into our fork's integration branch for testing (dyshay/VIctory-NVIDIA, branch
janus-prs). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with--profile diag --features diagnostics. A run on an RTX 4090 is queued (Series S with ray tracing, DLSS Quality). Frame times will follow here.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Lyrnc on 2026-11-30T18:59:10Z.
@nick0451, thanks. So no program of this title writes a lane mask a dword at a time and then uses its high half the way this PR handles: every output hash matches main. That makes this PR a correctness fix with no effect on this title's translations, and no risk to them. The case was found and tested with hand-written programs, checked against gfx1036 in wave64 (the test in the PR).
The branch is rebased onto main
84bd61e2(v2026.11.30.02) and force-pushed (now2a8ed4f6). The only conflict was inwave64_tests.rs, where main and this branch both add tests at the end; both are kept.lower.rsandstructure.rsapplied unchanged.Checks on
2a8ed4f6(Windows 11, rustc 1.98.1, its own target dir):cargo check -p victory-shaderpasses.cargo test -p victory-shader --lib -- wave64_tests: 48 passed,a_lane_mask_written_a_dword_at_a_time_keeps_its_high_dwordamong them (it dispatches on this PC's RTX 5080).@dyshay, the head changed, so janus-prs needs the new one.
AI use: Claude Code (Claude Opus 5.5) did the rebase, ran the tests and wrote this reply.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.