Shaders: lower v_bfm_b32 to one Bfi #3525
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3525
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3525"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Ingenioeren on GitHub · 2026-11-27 14:08 UTC · original
Ingenioeren:perf/v_bfm_b32-dxil-bfi→main· +69 −6 · 3 files · 1 commits · openWhat
Lower
v_bfm_b32to one DXILBficall instead of two masks, two shifts, and a subtraction. Add an instruction-count regression test and a synthetic GPU behavior test.Why
DXIL
Bfi(width, offset, ~0, 0)produces(((1 << (width & 31)) - 1) << (offset & 31)) & 0xffffffff, exactly the mask built by the previous lowering. Width zero produces zero; fields crossing bit 31 truncate to the low dword. All operands and the result remain 32-bit integers. DXIL specificationThe synthetic shader takes two runtime inputs and stores one result to a UAV. The count includes emitted setup, live instructions, and terminators. The test-only counter is the same helper used in #2954 and #2893, so whichever PR lands later can drop its copy.
origin/main(63bcca4)v_bfm_b32The instruction's own lowering goes from five DXIL instructions to one (80% fewer).
Fetched
originbefore surveying. Open-PR checks includedgh pr list --repo Marvisak/VIctory --state open --search "v_bfm_b32" --limit 20(no matches), the requested"Shaders: lower"search with limit 50, and broaderbfm/Bfisearches. None proposes this optimization; #1395 concerns scalar 64-bit bitfields. Freshorigin/mainstill has the five-operation vector mask lowering. This does not change any of the instructions in #3027, #3007, #2954, #2943, #2924, or #2893.How tested
cargo test --locked --offline -p victory-shader vector_bitfield_mask -- --nocapture: two tests passed on both revisions. On main, applied only the test changes and recorded 21 instructions before adding the 17-instruction assertion. The branch reports 17.dxil.dlland executes 2,078 cases on each of the hardware GPU and WARP on both revisions, with identical expected output bits. It covers all 1,024 effective width/offset pairs, the same pairs with ignored high bits set, zero and wrapped widths, signed/unsigned extremes, and fields ending at or crossing bit 31. The independent CPU reference uses 64-bit arithmetic followed by truncation.cargo test --locked --offline -p victory-shader: main had 300 passed, 2 failed, 3 ignored; branch had 302 passed, 2 failed, 3 ignored. Both expected failures areemit::rect::tests::rectangles_get_their_fourth_cornerandemit::tests::elements_sharing_a_row_keep_their_order; the local validator rejects their Pipeline State Validation container parts.cargo test --locked --offline -p victory-shader --test resource_tracking: branch had 3 passed, 1 ignored. Run separately because the full command stops after the existing library failures.cargo clippy --locked --offline -p victory-shader --all-targets -- -D warnings: passed.cargo fmt --check: fails on clean main and the branch with the same 925 pre-existing diff blocks. The outputs are identical after removing line numbers; this change adds no formatting differences.git diff --cached --checkpassed.cargo run --locked --offline -p xtask -- policy --staged: passed,asset policy: 3 files ok.What was not tested
No hardware run on a real game, game launch, game files, or game performance benchmark. All shader inputs were synthesized in test code. The measured gain is translated DXIL instruction count, not a measured runtime speedup.
AI assistance: prepared with OpenAI Codex under Claude Code's direction, reviewed by Ingenioeren.
🤖 Generated with Claude Code
@cloph-dsp on GitHub · 2026-11-27 14:33 UTC · original
Independent CPU-only verification on Windows / Rust 1.100.0 / MSVC.
4461e440c463989cfae59a318d57d589927fb7e8, merge base63bcca43c6a00a758510398fa43096ce7e4f7df0.cargo test --locked -p victory-shader --lib -- emit::lower::tests::vector_bitfield_mask_instruction_count --exact --test-threads=1 --quiettest result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 306 filtered out, exit 0.git grep -F -c vector_bitfield_mask_instruction_count 63bcca43 -- .→ exit 1 / 0 hits (test genuinely new); present on PR head.git diff --check 63bcca43 HEAD→ exit 0.vector_bitfield_mask_matches_rdna2test and the full crate suite were not run.@andrewpozdnakov7-jpg on GitHub · 2026-11-27 14:38 UTC · original
The current heads
4461e44(#3525) ande038572(#3528) merge cleanly. I measured the two together and prepared integration follow-up845f9dd, which shares the scalar mask lowering with the vector opcode and folds a mask when both operands are known.For the synthetic vector mask with inline operands
(12, 12), the combined baseline emits 13 instructions and 2064 bytes. The shared helper emits 12 instructions and 1988 bytes. The dynamic vector fixture still emits 17 instructions. Four new inline readbacks cover ordinary fields, a zero-width mask, and operands that wrap at 32. The original 2,078 vector cases and 4,098 scalar mask/SCC cases also pass on app-local WARP 1.0.22.All 34 lowering, 36 VALU, and 35 semantics tests passed, with one existing ignored semantics test. Both strict shader Clippy configurations and the asset check passed. This is available for the authors when bringing the two branches together. Please retain Git authorship for the contributing commits, or add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>if folding my follow-up in. AI-assisted. Synthetic shaders only.@kilolimaVI on GitHub · 2026-11-27 17:42 UTC · original · reviewed
Verified on AMD hardware, head
4461e44: Windows 11, Radeon 780M (RDNA3 iGPU), toolchain 1.98.1.vector_bitfield_mask_matches_rdna2(2,078 width/offset cases, hardware + WARP in one run) andvector_bitfield_mask_instruction_count: pass; 0/10 failures over 10 runs. So the RDNA3 driver'sBfigives the shifted-mask result for every case, including zero width, wrapped counts and fields crossing bit 31.cargo test -p victory-shaderon the 780M: 304 passed, 0 failed.AI-assisted (Claude).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.