Shaders: zero-extend unsigned 24-bit operands with one mask #3632
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3632"
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-28T00:40:25Z.
The unsigned 24-bit multiply forms zero-extend each operand with a left shift followed by a logical right shift. Masking with
0x00FF_FFFFdoes the same work in one instruction. Share the operand extension between the multiply, high-product and multiply-add arms; signed forms keep their arithmetic shifts, and the MAD addend remains a full dword.v_mul_u32_u24(VOP2 and VOP3)v_mul_hi_u32_u24(VOP2 and VOP3)v_mad_u32_u24These are emitted DXIL instruction counts for a shader with runtime inputs and a UAV result, including setup and terminators. The corresponding signed forms remain at 21, 25 and 24. GPU execution time was not benchmarked.
Validation on Windows, RX 6750 XT and WARP, based on
63bcca4:cargo test --locked --offline -p victory-shader unsigned_24_bit_operands_use_one_mask_each -- --nocapture: failed with tests alone on the old lowering (21/25/24 against 19/23/22 budgets); passes with the mask lowering.cargo test --locked --offline -p victory-shader multiplies_of_24_bits_ignore_the_upper_byte -- --nocapture: passes before and after. Ten synthetic signed/unsigned instruction encodings each run 4,580 inputs per adapter, with zero CPU-reference mismatches or hardware/WARP disagreements. Cases cover 24-bit sign boundaries, nonzero upper bytes, maximum products and full-width wrapping addends.cargo test --locked --offline -p victory-shader 24_bit -- --nocapture: 3 passed.cargo test --locked --offline -p victory-shader: baseline 300 passed / 2 failed / 3 ignored; final 302 passed / the same 2 failed / 3 ignored. Both failures (emit::rect::tests::rectangles_get_their_fourth_cornerandemit::tests::elements_sharing_a_row_keep_their_order) report the same localdxil.dllPipeline State Validation mismatch on both revisions.cargo test --locked --offline -p victory-shader --test resource_tracking: 3 passed / 1 ignored.cargo test --locked --offline -p victory-shader --doc: no doc tests, passed.cargo clippy --locked --offline -p victory-shader --all-targets -- -D warnings: passes before and after the production change.cargo fmt --check: fails on existing formatting differences on main; comparing the changed files with main found identical rustfmt deviations and none in the new test file.cargo run --locked --offline -p xtask -- policy --staged: passes, 4 files.lower.rsshrinks from 520,563 to 520,384 bytes.The test-only instruction counter matches #3600 exactly and is also shared by the other open instruction-count PRs. #3007 changes the high-product implementation; this change only shortens its operand extension, and the count budgets allow that further reduction. #2926 separately fixes clamping in the low-product/MAD arms; whichever lands second will need a small rebase in those arms. No duplicate optimization was found in the open/merged PR search.
No game files, game shaders or game run were used. Other GPUs and Linux/Wine were not tested.
AI assistance: prepared with OpenAI Codex, reviewed by Ingenioeren.
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T00:53:07Z.
I resolved the overlap between
e34a9afand #29263b60f1bon63bcca4. The merge keeps #2926's MUL/MAD route and reuses yourextend24helper there and in MUL_HI. Unsigned operands use the mask. Signed operands keep their sign extension, and the MAD addend remains a full dword. Integration branch0e22c83With #2926's test alone on
e34a9af, the first clamped shader was refused withinteger output modifiers. The merged code matched the wide-integer reference in all 96 signed/unsigned MUL/MAD cases, with clamp on and off. The 10 arithmetic encodings in the upper-byte test also matched the reference for all 4,580 inputs each. I forced both harness passes to app-local WARP 1.0.22 with Agility 1.620.2 and DXIL validation.The unsigned unclamped DXIL counts still match 19 for MUL, 23 for MUL_HI and 22 for MAD. The signed counts still match 21, 25 and 24. I got 36 VALU, 35 semantics and 34 lowerer tests passing, with one semantics test ignored. Strict all-feature shader Clippy passed. The branch preserves both PR commits. AI-assisted with Codex.
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-28T00:55:39Z.
WARP-only independent verification of #3632 (no GPU used)
Claim: https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7231226055
Revisions: PR head
e34a9af93fe616a7a019d744c0d525ff6a80de7d(still that SHA) on base63bcca43c6a00a758510398fa43096ce7e4f7df0. The merge-base is63bcca43, so it merges cleanly (fast-forward).Setup: Windows 11,
VICTORY_WARP=1andVICTORY_D3D12_WARP=1, so no hardware adapter.VICTORY_DXILpointed at the Windows SDK 10.0.26100dxil.dll(1.8.2502.11). The WARP used was the OSd3d10warp.dll10.0.26100.9818. I could not find a separate "1.0.22" WARP package on this machine, so that exact version was not used. Separate target dir,-j 4on every cargo command.Base
63bcca43:cargo test --locked -p victory-shadergives lib 298 passed / 4 failed / 3 ignored. The failures aresynthetic_tests::{a_mask_joined_with_data_at_a_uniform_loop_is_its_number, gathers_at_a_level_match_the_hardware, permutes_mask_high_address_bits_and_divergent_branches, permutes_read_the_lane_named_and_zero_from_lanes_left_out}. They report "no pipeline for a wave of 32" and a gather mismatch, which are WARP limits on this machine. They are unrelated to 24-bit ops.lower.rsis 520,563 bytes.Control on base (PR test changes only, no
extend24change):unsigned_24_bit_operands_use_one_mask_eachFAILS. Counts are 21/21, 25/25, 24 against budgets 19, 23, 22 (signed forms stay at 21, 25, 24).multiplies_of_24_bits_ignore_the_upper_bytePASSES. Behaviour is unchanged on base, as expected for a pure optimisation.Merged
63bcca43+e34a9af9:--no-fail-fast: lib 300 passed / 4 failed / 3 ignored. The failures are the same 4 as base. The two new tests account for the +2. The other targets passed:resource_tracking3 passed / 1 ignored, doc tests 0.unsigned_24_bit_operands_use_one_mask_eachpasses. Counts are[(19,19),(19,19),(23,23),(23,23),(21,21),(21,21),(25,25),(25,25),(22,22),(24,24)].multiplies_of_24_bits_ignore_the_upper_bytepasses under WARP +dxil.dllvalidation.cargo test --locked -p victory-shader --test resource_tracking: 3 passed / 1 ignored.cargo test --locked -p victory-shader --doc: ok, 0 tests.cargo clippy --locked -p victory-shader --all-targets -- -D warnings: clean.cargo run --locked -p xtask -- policy --staged(merged diff staged): "asset policy: 4 files ok".lower.rs: 520,563 -> 520,384 bytes (-179), as expected.Diff review (all hunks in
bitcode.rs,lower.rs,u24_tests.rs,semantics_tests.rs): no defects found.extend24signed isshl 8; ashr 8, which is identical to the old signed path. Unsigned isand 0x00FFFFFF, which equals the oldshl 8; lshr 8zero-extension.v_mul_i32_i24,v_mul_hi_i32_i24,v_mad_i32_i24) keep the arithmetic extension. Unsigned forms (v_mul_u32_u24,v_mul_hi_u32_u24,v_mad_u32_u24) get the mask.v_mad_*addenddis still added as a full dword, unextended. The test uses full-width addends (0x80000000, u32::MAX).mul_histill receives the extended values with the correct signedness.written_instructionsis#[cfg(test)]. It counts live phis and body instructions in the layout plus one terminator per block, which matches whatwriteemits. The test comments say the same.semantics_testsoracle masks to 24 bits, sign-extends only for the signed forms, and usesi64products. That is correct for the mul, mul_hi and mad cases. It covers VOP2 and VOP3 encodings and edge values.lower_valuwas madepub(super)for the new test module. That is a test-only change.mul24.rs,lower.rs) and #3007 (bitcode.rs,lower.rs) are both open and touch the same arms or the same file. A small rebase is likely for whichever lands second. No logical conflict.AI-assisted: Claude Sonnet 5.5. No game files, dumps, install paths, shader names or retail hashes were used or are included.
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T12:45:42Z.
I updated the combined branch for your exact
e34a9afand #29263b60f1bwith #37317c6f908in integration commit3b693c3. It resolves the overlap in the existing 24-bit lowering module. Unsigned operands still use one mask, and the clamped forms still use the wide calculation. The unclamped MAD forms now emitUMadorIMad.The same minimal fixtures now emit 21 unsigned and 23 signed MAD instructions, down from 22 and 24 in the earlier combined tree. Each multiply and high-multiply count stays at its previous budget. WARP with Agility 1.620.2 passed 34 lowerer, 36 VALU and 36 semantics tests, with one existing ignored test. The clamped regression and all 726 generated full-width addend cases per MAD opcode passed. Strict all-feature shader Clippy and the asset policy passed.
@Ingenioeren, this branch is ready for merge coordination with #2926 and #3731. Please retain the original Git authors when rebasing or cherry-picking. If folding my changes into another commit, please add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.AI-assisted with OpenAI Codex.
Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-29T20:27:48Z.
NVIDIA full-suite run, to go with the reports above by andrewpozdnakov7-jpg, oni-swr, since none of them names a GPU run. Tested exact head
e34a9af(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: 868 passed, 0 failed, 10 ignored.unsigned_24_bit_operands_use_one_mask_each,multiplies_of_24_bits_ignore_the_upper_byte.--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
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.