Shaders: honor v_permlanex16 EXEC/FI/BOUND_CTRL and 64-bit masks in wave sections #3393
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3393"
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 Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T21:45:42Z.
Summary
Fixes two soundness bugs in whole-wave section simulation (
crates/victory-shader/src/emit/wave.rs) that silently miscompiled valid RDNA2 shaders into wrong DXIL wave operations:v_permlanex16_b32inactive source handling under narrowedEXEC:simulate()previously reada[other | pick]unconditionally, ignoring both the current simulatedexecmask and the VOP3op_selflags (op_sel[0] = FI,op_sel[1] = BOUND_CTRL). Under a narrowed constantEXECmask (for examples_mov_b32 exec_lo, 0xFFFF_0000in prefix-sum sequences), reading an inactive source lane withFI=0must preserve the destination lane (BOUND_CTRL=0) or produce0(BOUND_CTRL=1) rather than fetching the inactive lane and miscompiling intoWavePrefixSum.Wave64 64-bit mask tracking and wave-width matching:
sections()andsimulate()previously accepted 32-bitsaveexec/s_and_b32/ partialEXEC_LOrestores in Wave64 programs and tracked only the low 32-bit SGPR SSA value of saved and derived masks. In Wave64, a 32-bitsaveexecleavesEXEC_HIuntouched, a partials_mov_b32 exec_lo, s0does not restoreEXEC_HI, and overwriting the high dword of a 64-bit mask beforev_cndmask_b32orEXECrestore was ignored — silently lowering partial-wave reductions into full 64-laneWaveActive*operations.Changes
crates/victory-shader/src/emit/wave.rs:s_or_saveexec_*/s_nand_saveexec_*ands_and_b*to match the program's wave width (_b64for Wave64,_b32for Wave32).(lo, hi)SSA mask pairs (Mask = (Value, Value)) for section start,EXECrestore detection,s_andmask derivation, andv_cndmask_b32mask checks.v_permlanex16_b32source-lane activity withexec,op_sel[0](FI), andop_sel[1](BOUND_CTRL) per the RDNA2 ISA (fi || exec >> src & 1 != 0fetchesa[src]; otherwisebound_ctrlyields0and!bound_ctrlclears the lane's write bit to preserveold[l]).v_permlanex16_b32under narrowedEXEC(FI=0/BC=0,FI=0/BC=1,FI=1, active source lane) and Wave64 mask high-half clobbering, 32-bits_and_b32, wrong-widthsaveexec, and partialEXEC_LO/ clobbered-high-half restores.Verification
63bcca43before the fix and pass 20/20 rounds after the fix (including D3D12 compute execution of theFI=1prefix sum).rustfmt --check --edition 2024 crates/victory-shader/src/emit/wave.rspassed.cargo test -p victory-shader --lib --locked emit::wave::tests(default and--all-features),emit::lower::tests,emit::flow_tests,emit::diff_tests, and--docpassed.cargo clippy --workspace --all-targets --locked -- -D warningsand--all-featurespassed with zero warnings.cargo test -p xtask --locked policy::tests::repository_passes_policypassed.Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T21:47:17Z.
Review: APPROVED
LGTM — verified on Windows against
origin/main(63bcca4).v_permlanex16EXEC/FI/BOUND_CTRLsemantics and tracking full 64-bit masks in wave64 sections closes real whole-wave simulation soundness gaps cleanly.cargo test -p victory-shader --lib emit::wave:: -- --test-threads=1: 10 passed, 0 failed (includingv_permlanex16_honors_exec_fi_and_bound_ctrl,wave64_whole_wave_section_tracks_full_64bit_masks_and_width, andend_to_end_permlanex16_and_wave64_high_mask_do_not_miscompile).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).
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T22:11:39Z.
I exercised the end-to-end test on
09046e7and made pipeline creation failures visible when the test has a capable D3D12 device. Test-only follow-up42fc8dbalso adds readbacks for bothBOUND_CTRLvalues withFI=1and the intact Wave64 reduction. The DXIL validator checks each positive shader before dispatch.Three app-local WARP runs read the exact prefix sums from 1 through 528 in all 32 lanes for each
FI=1variant. The intact Wave64 case read 2080 in all 64 lanes. BothFI=0forms under narrowed EXEC and the clobbered Wave64 mask still fail translation in the same fixture. The affected wave, lowering, semantics and IR tests had 86 passed and one ignored. Strict Clippy in both configurations and the asset policy check passed.@fuzeofficlal, the stronger fixture is ready to take if you want to keep all three positive readbacks in the PR. Please retain the Git author or use
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>if folding it into another commit.Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T22:49:33Z.
Thanks @andrewpozdnakov7-jpg — cherry-picked
42fc8db5onto this branch as9be9a097(preserving your commit authorship, with only the 1-linerustfmt --edition 2024wrap onlet host = ...atwave.rs:1402).Verified locally:
rustfmt --edition 2024 --check crates/victory-shader/src/emit/wave.rs: cleancargo clippy --locked -p victory-shader --all-targets -- -D warnings&xtaskasset policy: cleancargo test --locked -p victory-shader --lib emit::wave::on RTX 5090 (VICTORY_WARP=0,WaveLaneCount=32..32: bothFI=1BOUND_CTRL={0,1}readbacks pass all 32 lanes; Wave64 validates DXIL and skips readback cleanly) and WARP (VICTORY_WARP=1,lanes=4..4: all 3 validate DXIL cleanly).Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-27T07:36:47Z.
NVIDIA full-suite run, to go with the reports above by Dukestar69, andrewpozdnakov7-jpg, since none of them names a GPU run. Tested exact head
9be9a09(on its base63bcca4).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 869 passed, 0 failed, 10 ignored.v_permlanex16_honors_exec_fi_and_bound_ctrl,wave64_whole_wave_section_tracks_full_64bit_masks_and_width,end_to_end_permlanex16_and_wave64_high_mask_do_not_miscompile.--skipleaves out tests that fail on main63bcca4on this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#2571), so without the skip the rest of that crate never reports;dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-27T13:52:08Z.
AMD run: RX 5700 XT (RDNA1, 32–64 lanes, native Wave64 and FP64), driver 32.0.21045.29003, Windows 11 26200, Rust 1.98.1, debug. The head was merged onto
main63bcca4and run on the native adapter (VICTORY_WARPunset), no game files. Head9be9a09. The RTX 5070 Ti run above is 32-lane only, and the end-to-end test skips its Wave64 readback on a card that can't run Wave64.end_to_end_permlanex16_and_wave64_high_mask_do_not_miscompile:Wave32 FI=1 BOUND_CTRL=0andFI=1 BOUND_CTRL=1read back all 32 lanes, andWave64 intact reduction: read back all 64 lanes, so the 64-bit high-mask case ran on native Wave64 and passed.v_permlanex16_honors_exec_fi_and_bound_ctrlandwave64_whole_wave_section_tracks_full_64bit_masks_and_widthpass.victory-shadersuite (--features host): 305 passed, 0 failed, 3 ignored.cargo clippy -p victory-shader --all-targets --features host -- -D warnings: clean.AI use: Claude Code (Claude Opus 5.5).
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.