Skip to content

Shaders: lower v_bfi_b32 with three bit operations - #3681

Open
Ingenioeren wants to merge 1 commit into
Marvisak:mainfrom
Ingenioeren:perf/bfi-three-ops
Open

Ingenioeren wants to merge 1 commit into
Marvisak:mainfrom
Ingenioeren:perf/bfi-three-ops

Conversation

@Ingenioeren

Copy link
Copy Markdown
Contributor

v_bfi_b32 selects bits from src1 where src0's mask is set, and src2 otherwise. Emit b ^ ((a ^ b) & m), reducing the bit-select expression from four operations to three.

A synthetic shader with three dynamic root constants and a live UAV store emits 21 DXIL instructions instead of 22. This measures emitted instructions; GPU time and frame rate were not measured.

The count regression uses a v_xor3_b32 shader with the same setup as a control. With only the tests added to main 63bcca4, BFI emits 22 instructions against the control's 20 and the regression fails. With this change, BFI emits 21 and the regression passes.

The execution test uses an independent per-bit CPU model, single-bit and complemented masks, alternating patterns, all eight truth-table combinations at every bit position, edge dwords and deterministic random inputs. All 11,752 inputs run with a separate destination and with each source as the destination, with both full and narrowed EXEC: 94,016 results per adapter per revision. Both lowerings match the model on the RX 6750 XT and WARP, with zero adapter differences.

Validation on Windows, Rust 1.98.1, synthetic shaders only:

  • cargo test --locked --offline -p victory-shader bfi_selects -- --nocapture: original lowering with tests 1 passed / 1 expected count failure; final 2 passed.
  • cargo test --locked --offline -p victory-shader --no-fail-fast: 302 passed / 2 failed / 3 ignored; the recorded unmodified-main baseline at 63bcca4 is 300 passed / the same 2 failed / 3 ignored. The failures are rectangles_get_their_fourth_corner and elements_sharing_a_row_keep_their_order, both rejected by this PC's local dxil.dll with a Pipeline State Validation mismatch. Integration: 3 passed / 1 ignored; doc tests: 0.
  • cargo clippy --locked --offline -p victory-shader --all-targets --all-features -- -D warnings: passed before and after the lowering change.
  • cargo run --locked --offline -p xtask -- policy --staged: passed before and after, 3 files.
  • git diff --cached --check: passed. Rustfmt comparisons against main show identical pre-existing deviations in all three changed files. lower.rs is 521,423 bytes, below the 524,288-byte policy limit.

The test-only instruction counter is identical to the one in #3600/#3632/#3637/#3640. Those PRs optimize other instructions; this change retains the existing source reads and guarded destination write.

Not tested: Linux/RADV, other hardware, or game rendering/performance. No game files were used. This does not establish a fix for device removal or the integer-min/max compiler hang reported on #3027.

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

@ColorMeBoom

Copy link
Copy Markdown

Hardware run: RX 5700 XT (Navi 10, RDNA1, 32–64 lanes, driver 32.0.21045.29003, Windows 11 26200), head e91577e on 63bcca4.

  • bfi_selects_bits_with_three_operations and bfi_selects_each_bit_with_overlapping_destinations_and_exec pass. All 8 forms, including those where the destination overlaps a source and those under a partial EXEC, have 11,752 inputs with model mismatches ["hardware 0", "warp 0"], hardware/warp differ on 0.
  • Full victory-shader --lib --features host: 304 passed, 0 failed, 3 ignored.

AI use: Claude Code (Claude Opus 5.5).

@cloph-dsp

Copy link
Copy Markdown

Independent local verification (Windows, Rust 1.100.0/MSVC, no game data):

  • PR Shaders: lower v_bfi_b32 with three bit operations #3681 at head e91577e7884be4d9b6de824f256b8d089bedc4cc, base/parent 63bcca43c6a00a758510398fa43096ce7e4f7df0.
  • cargo test --locked -p victory-shader --lib -- emit::lower::tests::bfi_selects_bits_with_three_operations --exact --test-threads=1 --quiet → 1 passed, 0 failed, 306 filtered, exit 0.
  • git grep -F for the test name on the base returned no match (test is new on this PR); git diff --check 63bcca4 HEAD clean (3 files, +122/-5).
  • Used a per-worktree CARGO_TARGET_DIR (never shared) with CARGO_BUILD_JOBS=2.
  • Only the named synthetic test was replayed (the other newly added test and the full workspace suite were not run); clippy was not run locally.
  • GPU/driver: N/A (CPU-only synthetic VOP3 instruction lowering). No game data, assets, extracted shaders, DRM or decrypt involved.

AI-assisted (Hy4 flash).

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