Shaders emit fewer DXIL instructions for scalar bitfield masks #3528

Open
github-bot wants to merge 1 commit from github-bot/gh-3528 into main AGit
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-27 14:26 UTC · original
andrewpozdnakov7-jpg:codex2/scalar-bitfield-mask-bfi → main · +52 −8 · 2 files · 1 commits · open

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.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-27 14:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/3528) `andrewpozdnakov7-jpg:codex2/scalar-bitfield-mask-bfi` → `main` · +52 −8 · 2 files · 1 commits · open 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://git.gtahub.st/github/Marvisak--VIctory/issues/1633) 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 14:31:07 +00:00
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-27 14:30 UTC · original

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.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-27 14:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/3528#issuecomment-7220873170) 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.
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-27 14:49 UTC · original

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.
**@⁠cloph-dsp** on GitHub · 2026-11-27 14:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/3528#issuecomment-7221275738) 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.
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-27 20:01 UTC · original

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.
**@⁠futurepro62** on GitHub · 2026-11-27 20:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/3528#issuecomment-7227101946) 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 can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3528/head:github-bot/gh-3528'
git switch 'github-bot/gh-3528'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3528'
git switch 'github-bot/gh-3528'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3528'
git switch 'github-bot/gh-3528'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3528'
git switch 'main'
git merge --squash 'github-bot/gh-3528'
git switch 'main'
git merge --ff-only 'github-bot/gh-3528'
git switch 'main'
git merge 'github-bot/gh-3528'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3528
No description provided.