Shaders: lower align instructions through bounded shifts #3691
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3691"
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 Ingenioeren on 2026-11-28T07:27:30Z.
v_alignbit_b32andv_alignbyte_b32currently mask the complementary shift, then compare/select away the high word when the shift is zero. Split that high-word shift into(a << 1) << (31 - sh): both individual shifts stay below 32, and together discard every bit at zero. This removes two written DXIL instructions from each dynamic-input form while preserving the existing shift masking.Synthetic shader counts, including the same root-constant loads and live UAV store:
v_alignbit_b32v_alignbyte_b32The count regression fails on the original lowering at
[26, 27]and passes at[24, 25]. The execution test uses an independent 64-bit concatenation reference: 18,432 inputs x two opcodes x four destinations x full/partial EXEC = 294,912 cases per adapter and revision. RX 6750 XT and WARP both match every result before and after, with no adapter differences. It covers every effective shift, ignored shift bits, single-bit/complemented sources, unsigned edge values, deterministic random inputs, all source/destination overlaps, and preservation of inactive destinations. Emitted DXIL validates with the local validator.Validation (Windows, main
63bcca4):cargo test -p victory-shader --locked --offline align_ -- --nocapture: tests-only control 1 passed / 1 expected count failure; final 2 passed.cargo test -p victory-shader --locked --offline --no-fail-fast: baseline 300 passed / 2 failed / 3 ignored; final 302 passed / the same 2 failed / 3 ignored. Both failures are the existing local PSV validator mismatches inrectangles_get_their_fourth_cornerandelements_sharing_a_row_keep_their_order. Integration tests: 3 passed / 1 ignored on both; doc tests: 0.cargo clippy -p victory-shader --locked --offline --all-targets --all-features -- -D warnings: passes before and after.cargo run -p xtask --locked --offline -- policy --staged: passes before (0 changed files) and after (3 changed files).git diff --check: clean. Main already has formatting deviations; all three changed files retain exactly those deviations, with the added code formatted.The test-only written-instruction counter is identical to #3600 and the subsequent lowering PRs; keep one copy when integrating. #2020 addresses the separate source-modifier handling of these opcodes; this change leaves that handling alone. Closed #1379's smaller hardware test is already in main.
The measured gain is written DXIL size (7.7% / 7.4% for these synthetic shaders). GPU timing, Linux/RADV, graphics/mesh and game behavior were not tested. No game files were used.
AI assistance: prepared with OpenAI Codex, reviewed by Ingenioeren.
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-28T07:54:49Z.
Independent software WARP verification (
1127bv,VICTORY_WARP=1+VICTORY_D3D12_WARP=1, no physical GPU touched):origin/main63bcca43c6a00a758510398fa43096ce7e4f7df0, PR head63b43325d7699b25e1db1a7a9040d26a3f462b20, clean merge tree1925dcc31cd8e514b560856cd32a1de8d945dc08(git diff --checkclean).d3d10warp.dll10.0.26100.9818,dxil.dll1.8.2502.11(DXIL validation active).main63bcca43(cargo test -p victory-shader --locked --offline align_ -- --nocapture): 1 passed / 1 failed —align_instructions_use_bounded_shiftsfailed as expected at[26, 27]vs[24, 25];align_matches_concatenation_with_overlapping_destinations_and_execpassed all 294,912 cases (0 mismatches).#3691targeted checks:cargo test -p victory-shader --locked --offline align_ -- --nocapture: 2 passed / 0 failed (align 0x14e: 24,align 0x14f: 25; 294,912 WARP cases, 0 mismatches).cargo test -p victory-shader --locked --offline --features diagnostics align_ -- --nocapture: 2 passed / 0 failed (same counts and 0 mismatches).victory-shadersuite (cargo test -p victory-shader --locked --offline --no-fail-fast -- --nocapture):main63bcca43: unit 298 passed / 4 failed / 3 ignored; integration 3 passed / 0 failed / 1 ignored; doc-tests 0.#3691: unit 300 passed / 4 failed / 3 ignored; integration 3 passed / 0 failed / 1 ignored; doc-tests 0.VICTORY_WARP=1(emit::synthetic_tests::{a_mask_joined_with_data_at_a_uniform_loop_is_its_number, permutes_mask_high_address_bits_and_divergent_branches, permutes_read_the_lane_named_and_zero_from_lanes_left_out}require wave-32 pipelines unsupported by WARP;gathers_at_a_level_match_the_hardwarediffers on WARP). Zero PSV validator failures withdxil.dll 1.8.2502.11.cargo clippy -p victory-shader --locked --offline --all-targets --all-features -- -D warnings: pass.cargo clippy -p victory-shader --locked --offline --all-targets -- -D warnings: pass.cargo run -p xtask --locked --offline -- policy(191 files ok) and-- policy --staged(3 files ok): pass.crates/victory-shader/src/emit/lower.rs:521,458B (< 524,288B limit; 2,830 B headroom).(a << 1) << (31 - sh)keeps both shift counts in[0, 31], cleanly handlessh=0((a << 1) << 31 == 0),sh=31,sh>=32masking (sh & 31forv_alignbit_b32,(sh & 3) << 3forv_alignbyte_b32), inactive lanes / EXEC preservation, and source/destination overlaps.#2020source-modifier handling is untouched. Test-onlywritten_instructionshelper overlaps with#3600/#3688(keep one copy when integrating).AI disclosure: independent verification assisted by Gemini 4 Neon.
Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-28T15:51:53Z.
Hardware run: RX 5700 XT (Navi 10, RDNA1, 32–64 lanes, driver 32.0.21045.29003, Windows 11 26200), head
63b4332on63bcca4.align_matches_concatenation_with_overlapping_destinations_and_execpasses. All 16 rows ofv_alignbit_b32andv_alignbyte_b32(18,432 inputs each, overlapping destinations and partial EXEC) have zero mismatches on the card and on WARP.align_instructions_use_bounded_shiftspasses.victory-shader --lib --features host: 304 passed, 0 failed, 3 ignored.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.