Shaders: lower scalar bit-field extracts through Ibfe and Ubfe #3637

Open
Ingenioeren wants to merge 1 commit from upstream-pr/3637 into main
Ingenioeren commented 2026-11-28 01:12:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Ingenioeren on 2026-11-28T01:12:03Z.


Scalar s_bfe_u32 and s_bfe_i32 currently emit a shift/mask sequence, with another sign-extension sequence for the signed form. Use DXIL Ubfe/Ibfe for widths below 32 and select a logical/arithmetic right shift for widths 32�127. The scalar instruction's seven-bit width, ignored control bits, zero-width result, and SCC stay the same. DXIL bit-field semantics.

The synthetic count shader reads two runtime root constants and stores the result to a UAV. Counts include live emitted instructions and terminators:

Scalar operation main 63bcca4 This branch Reduction
s_bfe_u32 26 23 11.5%
s_bfe_i32 33 23 30.3%

Validation:

  • cargo test --locked --offline -p victory-shader scalar_bitfield_extract -- --nocapture --test-threads=1: the instruction-count regression failed before the lowering change ([26, 33] versus [23, 23]) and passed after. The new semantic test passed before and after on RX 6750 XT and WARP: 32,768 inputs per form, every offset 0�31 and width 0�127, clean/dirty ignored bits, and both result and SCC, with zero model mismatches or adapter differences.
  • cargo test --locked --offline -p victory-shader: baseline 300 passed / 2 failed / 3 ignored; branch 302 passed / the same 2 failed / 3 ignored. Both local validator failures are emit::rect::tests::rectangles_get_their_fourth_corner and emit::tests::elements_sharing_a_row_keep_their_order (Pipeline State Validation mismatch).
  • cargo test --locked --offline -p victory-shader --test resource_tracking: 3 passed, 1 ignored.
  • cargo clippy --locked --offline -p victory-shader --all-targets -- -D warnings: passed.
  • cargo run --locked --offline -p xtask -- policy --staged: all 3 staged files passed.
  • cargo fmt --check retains existing main formatting differences; comparison against main found no new formatting deviations in any changed file. git diff --check passed.

The test-only instruction counter is identical to the one in #3632 and the earlier shader performance PRs. #2954 optimizes the vector BFE forms; this change touches the scalar caller and adds a separate helper, leaving the vector lowering unchanged. No game files, game launch, or game-performance measurement; these are DXIL instruction counts.

AI assistance: prepared with OpenAI Codex, reviewed by Ingenioeren.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5535250671 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3637). Originally posted by [Ingenioeren](https://github.com/Ingenioeren) on 2026-11-28T01:12:03Z. --- Scalar `s_bfe_u32` and `s_bfe_i32` currently emit a shift/mask sequence, with another sign-extension sequence for the signed form. Use DXIL `Ubfe`/`Ibfe` for widths below 32 and select a logical/arithmetic right shift for widths 32�127. The scalar instruction's seven-bit width, ignored control bits, zero-width result, and SCC stay the same. [DXIL bit-field semantics](https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#ibfe). The synthetic count shader reads two runtime root constants and stores the result to a UAV. Counts include live emitted instructions and terminators: | Scalar operation | main `63bcca4` | This branch | Reduction | | --- | ---: | ---: | ---: | | `s_bfe_u32` | 26 | 23 | 11.5% | | `s_bfe_i32` | 33 | 23 | 30.3% | Validation: - `cargo test --locked --offline -p victory-shader scalar_bitfield_extract -- --nocapture --test-threads=1`: the instruction-count regression failed before the lowering change (`[26, 33]` versus `[23, 23]`) and passed after. The new semantic test passed before and after on RX 6750 XT and WARP: 32,768 inputs per form, every offset 0�31 and width 0�127, clean/dirty ignored bits, and both result and SCC, with zero model mismatches or adapter differences. - `cargo test --locked --offline -p victory-shader`: baseline 300 passed / 2 failed / 3 ignored; branch 302 passed / the same 2 failed / 3 ignored. Both local validator failures are `emit::rect::tests::rectangles_get_their_fourth_corner` and `emit::tests::elements_sharing_a_row_keep_their_order` (`Pipeline State Validation` mismatch). - `cargo test --locked --offline -p victory-shader --test resource_tracking`: 3 passed, 1 ignored. - `cargo clippy --locked --offline -p victory-shader --all-targets -- -D warnings`: passed. - `cargo run --locked --offline -p xtask -- policy --staged`: all 3 staged files passed. - `cargo fmt --check` retains existing main formatting differences; comparison against main found no new formatting deviations in any changed file. `git diff --check` passed. The test-only instruction counter is identical to the one in #3632 and the earlier shader performance PRs. #2954 optimizes the vector BFE forms; this change touches the scalar caller and adds a separate helper, leaving the vector lowering unchanged. No game files, game launch, or game-performance measurement; these are DXIL instruction counts. AI assistance: prepared with OpenAI Codex, reviewed by Ingenioeren.
oni-swr commented 2026-11-28 02:31:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-28T02:31:54Z.


Independent WARP verification for #3637 by Codex (gpt-6.2-sol).

  • Base 63bcca43c6a00a758510398fa43096ce7e4f7df0 and PR head 8d45f077a20616923f5142836be52c8e0247b3bb merge cleanly to tree de3e689480f9e328033a9862182ce0355a3293f1.
  • WARP only, with both WARP switches set. The test process loaded d3d10warp.dll 10.0.26100.9818 and SDK dxil.dll 1.8.2502.11.
  • Base control kept both new tests and reverted only the scalar lowering call. The instruction-count test failed as expected at [26, 33] against [23, 23]. Both tests passed on the merged tree at [23, 23]. The model test covered 32,768 inputs per signedness with zero result or SCC mismatches on either revision.
  • Unit tests (passed / failed / ignored) went from 298 / 4 / 3 to 300 / 4 / 3, with the same three wave32 pipeline failures and one gather mismatch. Standalone resource tracking was 3 / 0 / 1 on both, and doctests were 0 / 0 / 0. Merged Clippy with -D warnings and staged asset policy passed. lower.rs grew from 520,563 to 522,096 bytes, leaving 2,192 under the 524,288 limit.
  • Reviewed every hunk in bitcode.rs, lower.rs, and semantics_tests.rs. The test counter follows the writer's live layout and counts each terminator. Widths 32–127 take the arithmetic or logical shift by offset & 31, width zero yields zero, unused control bits are ignored, and SCC remains result != 0. All four neighboring PRs share the counter scaffolding. Pairwise merges with #3632 and #3640 are clean. #2954 and #3564 conflict at the instruction-count test insertion in lower.rs.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7232424447 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3637#issuecomment-7232424447). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-28T02:31:54Z. --- Independent WARP verification for #3637 by Codex (gpt-6.2-sol). - Base `63bcca43c6a00a758510398fa43096ce7e4f7df0` and PR head `8d45f077a20616923f5142836be52c8e0247b3bb` merge cleanly to tree `de3e689480f9e328033a9862182ce0355a3293f1`. - WARP only, with both WARP switches set. The test process loaded `d3d10warp.dll` `10.0.26100.9818` and SDK `dxil.dll` `1.8.2502.11`. - Base control kept both new tests and reverted only the scalar lowering call. The instruction-count test failed as expected at `[26, 33]` against `[23, 23]`. Both tests passed on the merged tree at `[23, 23]`. The model test covered 32,768 inputs per signedness with zero result or SCC mismatches on either revision. - Unit tests (passed / failed / ignored) went from **298 / 4 / 3** to **300 / 4 / 3**, with the same three wave32 pipeline failures and one gather mismatch. Standalone resource tracking was **3 / 0 / 1** on both, and doctests were **0 / 0 / 0**. Merged Clippy with `-D warnings` and staged asset policy passed. `lower.rs` grew from **520,563** to **522,096** bytes, leaving **2,192** under the **524,288** limit. - Reviewed every hunk in `bitcode.rs`, `lower.rs`, and `semantics_tests.rs`. The test counter follows the writer's live layout and counts each terminator. Widths 32–127 take the arithmetic or logical shift by `offset & 31`, width zero yields zero, unused control bits are ignored, and SCC remains `result != 0`. All four neighboring PRs share the counter scaffolding. Pairwise merges with #3632 and #3640 are clean. #2954 and #3564 conflict at the instruction-count test insertion in `lower.rs`.
Dukestar69 commented 2026-11-28 02:49:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-28T02:49:28Z.

Review: APPROVED


LGTM — verified on Windows (RTX 5090 + WARP):

  • cargo test -p victory-shader --lib scalar_bitfield_extract_all_widths_and_offsets passed on RTX 5090 and under VICTORY_WARP=1
  • cargo test -p victory-shader --lib bfe (bfe_signed_and_unsigned_match_rdna2) passed on RTX 5090 and under VICTORY_WARP=1
  • cargo clippy -p victory-shader --all-targets -- -D warnings passed with 0 warnings
  • cargo xtask policy passed (191 files ok)

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6095264261 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3637#pullrequestreview-6095264261). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-28T02:49:28Z. **Review:** APPROVED --- LGTM — verified on Windows (RTX 5090 + WARP): - `cargo test -p victory-shader --lib scalar_bitfield_extract_all_widths_and_offsets` passed on RTX 5090 and under `VICTORY_WARP=1` - `cargo test -p victory-shader --lib bfe` (`bfe_signed_and_unsigned_match_rdna2`) passed on RTX 5090 and under `VICTORY_WARP=1` - `cargo clippy -p victory-shader --all-targets -- -D warnings` passed with 0 warnings - `cargo xtask policy` passed (`191 files ok`) Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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/3637:upstream-pr/3637'
git switch 'upstream-pr/3637'

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/3637'
git switch 'upstream-pr/3637'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3637'
git switch 'upstream-pr/3637'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3637'
git switch 'main'
git merge --squash 'upstream-pr/3637'
git switch 'main'
git merge --ff-only 'upstream-pr/3637'
git switch 'main'
git merge 'upstream-pr/3637'
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!3637
No description provided.