Skip to content

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

Open
Ingenioeren wants to merge 1 commit into
Marvisak:mainfrom
Ingenioeren:perf/scalar-extract-dxil
Open

Ingenioeren wants to merge 1 commit into
Marvisak:mainfrom
Ingenioeren:perf/scalar-extract-dxil

Conversation

@Ingenioeren

Copy link
Copy Markdown
Contributor

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.

@oni-swr

oni-swr commented Nov 28, 2026

Copy link
Copy Markdown

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 Shaders: zero-extend unsigned 24-bit operands with one mask #3632 and Shaders: lower SAD differences through UMax and UMin #3640 are clean. Shaders: lower v_bfe_u32/v_bfe_i32 to one Ubfe/Ibfe #2954 and Shaders: lower v_msad_u8 to Msad and a wrapping add #3564 conflict at the instruction-count test insertion in lower.rs.

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants