Shaders emit fewer DXIL instructions for scalar bitfield masks #3528

Open
andrewpozdnakov7-jpg wants to merge 1 commit from upstream-pr/3528 into main
andrewpozdnakov7-jpg commented 2026-11-27 14:26:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T14:26:51Z.


Lower the scalar s_bfm_b32 mask with one DXIL Bfi when an operand is dynamic. With two known operands, compute the mask before emitting DXIL. Both operations use the low five bits for width and offset. The code uses the same documented primitive as the vector work in #3525. RDNA 2 SOP2 reference · DXIL Bfi

dxc -dumpbin on synthetic scalar shaders from main 63bcca4 and this change produced these complete entry-point counts and container sizes.

Fixture Instructions, main → patched Bytes, main → patched
One runtime mask 51 → 47 2472 → 2524
Chain of 16 runtime masks 126 → 62 2848 → 2748
One constant mask 51 → 46 2480 → 2460

The single runtime case pays for the additional Bfi declaration. The multi-mask and immediate cases produce smaller containers. The immediate fixture uses the (12, 12) mask from the project's descriptor-analysis test. Fixture on main

The runtime regression covers 4,096 width, offset, high-bit and prior SCC combinations, plus both SCC inputs to the immediate mask. The exact mask and SCC agree with the reference on app-local WARP 1.0.22. Coordination comment

The shader semantics suite passed 35 tests with one existing ignored test, and all 33 lowering tests passed. Strict shader Clippy in both feature configurations and the asset check passed.

Please retain the Git author if cherry-picking or rebasing. If folding it in, add Co-authored-by: andrewpozdnakov7-jpg <[email protected]>. AI-assisted. Synthetic shaders only.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5528263275 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3528). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T14:26:51Z. --- Lower the scalar `s_bfm_b32` mask with one DXIL `Bfi` when an operand is dynamic. With two known operands, compute the mask before emitting DXIL. Both operations use the low five bits for width and offset. The code uses the same documented primitive as the vector work in #3525. [RDNA 2 SOP2 reference](https://docs.amd.com/v/u/en-US/rdna2-shader-instruction-set-architecture) · [DXIL Bfi](https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#bfi) `dxc -dumpbin` on synthetic scalar shaders from `main` `63bcca4` and this change produced these complete entry-point counts and container sizes. | Fixture | Instructions, main → patched | Bytes, main → patched | | --- | ---: | ---: | | One runtime mask | 51 → 47 | 2472 → 2524 | | Chain of 16 runtime masks | 126 → 62 | 2848 → 2748 | | One constant mask | 51 → 46 | 2480 → 2460 | The single runtime case pays for the additional Bfi declaration. The multi-mask and immediate cases produce smaller containers. The immediate fixture uses the `(12, 12)` mask from the project's descriptor-analysis test. [Fixture on main](https://github.com/Marvisak/VIctory/blob/63bcca43c6a00a758510398fa43096ce7e4f7df0/crates/victory-shader/src/resource.rs#L2498) The runtime regression covers 4,096 width, offset, high-bit and prior SCC combinations, plus both SCC inputs to the immediate mask. The exact mask and SCC agree with the reference on app-local WARP 1.0.22. [Coordination comment](https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7220524280) The shader semantics suite passed 35 tests with one existing ignored test, and all 33 lowering tests passed. Strict shader Clippy in both feature configurations and the asset check passed. Please retain the Git author if cherry-picking or rebasing. If folding it in, add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>`. AI-assisted. Synthetic shaders only.
andrewpozdnakov7-jpg commented 2026-11-27 14:30:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T14:30:38Z.


Windows CI passed on e0385720cc01d42b32be99bfe360f641914de054, including both Clippy configurations and the workspace tests. Exact-head CI

For an independent physical-adapter check, leave VICTORY_WARP unset and run cargo test --locked -p victory-shader --lib scalar_bitfield_mask_preserves_width_offset_and_scc -- --test-threads=1 --nocapture. The fixture checks the mask and preserved SCC for 4,098 inputs. The size table in the PR measures emitted DXIL.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7220873170 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3528#issuecomment-7220873170). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T14:30:38Z. --- Windows CI passed on `e0385720cc01d42b32be99bfe360f641914de054`, including both Clippy configurations and the workspace tests. [Exact-head CI](https://github.com/Marvisak/VIctory/actions/runs/46016019072/job/140563215977) For an independent physical-adapter check, leave `VICTORY_WARP` unset and run `cargo test --locked -p victory-shader --lib scalar_bitfield_mask_preserves_width_offset_and_scc -- --test-threads=1 --nocapture`. The fixture checks the mask and preserved SCC for 4,098 inputs. The size table in the PR measures emitted DXIL.
cloph-dsp commented 2026-11-27 14:49:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-27T14:49:32Z.


Independent CPU-only verification on Windows / Rust 1.100.0 / MSVC.

  • PR head: e0385720cc01d42b32be99bfe360f641914de054, merge base 63bcca43c6a00a758510398fa43096ce7e4f7df0.
  • Command: cargo test --locked -p victory-shader --lib -- emit::semantics_tests::scalar_bitfield_mask_preserves_width_offset_and_scc --exact --test-threads=1 --quiet
  • Result: test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 305 filtered out, exit 0.
  • Negative control: git grep -F -c scalar_bitfield_mask_preserves_width_offset_and_scc 63bcca43 -- . → exit 1 / 0 hits (test genuinely new); present on PR head.
  • git diff --check 63bcca43 HEAD → exit 0.
  • Caveat: only the named synthetic semantics test was replayed; the full crate suite and real DXIL output were not exercised.
  • GPU/driver: N/A (CPU-only test). No game data, assets, extracted shaders or DRM involved.
  • AI-assisted: Hy4 flash.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7221275738 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3528#issuecomment-7221275738). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-27T14:49:32Z. --- Independent CPU-only verification on Windows / Rust 1.100.0 / MSVC. - PR head: `e0385720cc01d42b32be99bfe360f641914de054`, merge base `63bcca43c6a00a758510398fa43096ce7e4f7df0`. - Command: `cargo test --locked -p victory-shader --lib -- emit::semantics_tests::scalar_bitfield_mask_preserves_width_offset_and_scc --exact --test-threads=1 --quiet` - Result: `test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 305 filtered out`, exit 0. - Negative control: `git grep -F -c scalar_bitfield_mask_preserves_width_offset_and_scc 63bcca43 -- .` → exit 1 / 0 hits (test genuinely new); present on PR head. - `git diff --check 63bcca43 HEAD` → exit 0. - Caveat: only the named synthetic semantics test was replayed; the full crate suite and real DXIL output were not exercised. - GPU/driver: N/A (CPU-only test). No game data, assets, extracted shaders or DRM involved. - AI-assisted: Hy4 flash.
futurepro62 commented 2026-11-27 20:01:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-27T20:01:38Z.


NVIDIA full-suite run, to go with the reports above by cloph-dsp, since none of them names a GPU run. Tested exact head e038572 (on its base 63bcca4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo 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: 867 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: scalar_bitfield_mask_preserves_width_offset_and_scc.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#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_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7227101946 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3528#issuecomment-7227101946). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-27T20:01:38Z. --- NVIDIA full-suite run, to go with the reports above by cloph-dsp, since none of them names a GPU run. Tested exact head `e038572` (on its base `63bcca4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo 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`: **867 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `scalar_bitfield_mask_preserves_width_offset_and_scc`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#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_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3528:upstream-pr/3528'
git switch 'upstream-pr/3528'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/3528'
git switch 'upstream-pr/3528'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3528'
git switch 'upstream-pr/3528'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3528'
git switch 'main'
git merge --squash 'upstream-pr/3528'
git switch 'main'
git merge --ff-only 'upstream-pr/3528'
git switch 'main'
git merge 'upstream-pr/3528'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!3528
No description provided.