Shaders: lower v_bfe_u32/v_bfe_i32 to one Ubfe/Ibfe #2954
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!2954
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2954"
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-26 01:27 UTC · original
Ingenioeren:perf/vector-bitfield-extract→main· +59 −6 · 3 files · 1 commits · openWhat
Lower
v_bfe_i32andv_bfe_u32to one DXILIbfeorUbfecall per vector instruction. Add an instruction-count regression test and extend the existing synthetic GPU test.Why
The DXIL operations use the low five bits of both width and offset and produce zero for width zero. When a field reaches or crosses bit 31, DXIL shifts the source right arithmetically for
Ibfeand logically forUbfe, which gives the same sign or zero extension as the previous lowering. The operands and results are 32-bit integers. DXIL specificationEach synthetic shader takes three runtime inputs and stores one result to a UAV. The count includes emitted setup, live instructions, and terminators. The counter is the same test-only helper as in #2893, so whichever PR lands second can drop its copy.
origin/main(63bcca4)v_bfe_i32v_bfe_u32How tested
cargo test --locked --offline -p victory-shader vector_bitfield_extract_instruction_count -- --nocapturemeasured the counts above. On main, I applied the test-only changes and recorded the baseline before adding the 19-instruction budget.cargo test --locked --offline -p victory-shader bfe_signed_and_unsigned_match_rdna2 -- --nocapturepassed on the hardware GPU and WARP on both revisions with identical expected output bits. Cases include masked offset and width, zero width, and fields ending at or crossing bit 31.cargo test --locked --offline -p victory-shaderadded one passing test on the branch, from 300 to 301. Both runs had the same two localdxil.dllvalidation failures and three ignored tests.cargo test --locked --offline -p victory-shader --test resource_trackingpassed three tests with one ignored on both revisions.cargo clippy -p victory-shader --locked --offline --all-targetspassed.cargo run -p xtask -- policy --stagedpassed for all three staged files.All shader inputs were synthesized in test code. No game files, game launch, hardware game run, or game performance benchmark.
AI assistance: prepared with OpenAI Codex under Claude Code's direction, reviewed by Ingenioeren.
@oni-swr on GitHub · 2026-11-26 01:51 UTC · original
Independent test report for
eb73a3ab7995695a56d8239104623460c7250ce9, with the exact parent63bcca43c6a00a758510398fa43096ce7e4f7df0as the control. Claim: #1633.Setup: Windows 11 Pro 10.0.26200, Rust 1.98.1. Validator is
VICTORY_DXIL= Windows SDK 10.0.26100 x64dxil.dll1.8.2502.11; it loaded, since the test that unwrapsValidator::loadpassed. Environment hadVICTORY_D3D12_WARP=1andVICTORY_WARP=1, so the "hardware" slot ofrun_casesalso opens WARP. A probe confirmed thatHost::new(false)andHost::new(true)are bothMicrosoft Basic Render Driver(vendor 0x1414, device 0x8c,DXGI_ADAPTER_FLAG_SOFTWARE). Nothing ran on a physical GPU. All inputs were synthetic.Instruction count:
cargo test -j 4 --locked -p victory-shader --lib -- vector_bitfield_extract_instruction_count. To read both values, I printed them locally instead of asserting.v_bfe_u32v_bfe_i32These match the PR table. With the assert left in, the parent fails on
v_bfe_u32: left 27, right 19.Bit extraction boundaries:
bfe_signed_and_unsigned_match_rdna2passes on the head, and on the parent with the PR's extended cases applied, so outputs are identical across both revisions.v_bfe_u32andv_bfe_i32through WARP readback and compares them with a CPU model of the semantics the existing tests encode. The model takes the low five bits of offset and width, returns 0 for width 0, and when the field reaches or crosses bit 31 it zero-extends (u32) or arithmetic-shifts (i32).Full suite:
cargo test -j 4 --locked -p victory-shader --lib -- --test-threads=1The same 4
synthetic_testsfail on both revisions:a_mask_joined_with_data_at_a_uniform_loop_is_its_numbergathers_at_a_level_match_the_hardwarepermutes_mask_high_address_bits_and_divergent_branchespermutes_read_the_lane_named_and_zero_from_lanes_left_outThey are hardware-labelled checks ("no pipeline for a wave of 32", and gather texel expectations).
VICTORY_WARP=1forces them onto WARP, so they are an artifact of my setup, not this PR.Lint and policy:
cargo clippy -j 4 --locked -p victory-shader --all-targets -- -D warnings: clean.cargo run -j 4 -p xtask -- policy: 191 files ok.Overlap and limits:
written_instructionshelper inbitcode.rs, as the PR notes. #2943 also touchesbitcode.rs,lower.rsandvalu_tests.rs. I did not test any merge combinations.This is an independent test only, not a review. Prepared with Claude Code (Claude Opus 5.5).
@Marvisak on GitHub · 2026-11-26 05:39 UTC · original
Automated triage for the maintainers.
Merge candidate. In
Lower::valu_op(crates/victory-shader/src/emit/lower.rs),v_bfe_u32/v_bfe_i32now lower to DXILUbfe/Ibfe(ops 52/51,width, offset, value) instead of main's open-codedLower::bfe;s_bfe_*still use the helper. I checked that the two agree. Both use only the low five bits of offset and width and give 0 for width 0. For a field that runs past bit 31, main's arithmetic shift, mask and sign-extend gives the same result asIbfe's plain shift. The extendedbfe_signed_and_unsigned_match_rdna2cases (offset and width above 31, fields ending at bit 31) run through the host compiler and pass, alongside main's existing cases.One note:
vector_bitfield_extract_instruction_countasserts an exact count of 19 written instructions. That pins today's surrounding codegen, so unrelated lowering changes may have to update it. A bound (for example<=) would be less brittle. This is not a blocker. #2893 adds the same test-onlywritten_instructionshelper inbitcode.rs, so whichever lands second drops its copy.CI: passing (
check).Recommending a look, not approving.
Generated by Claude Code
@Dukestar69 on GitHub · 2026-11-26 02:02 UTC · original · approved these changes
Tested merged onto
origin/main(63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP,dxil.dllvalidator active):cargo test -p victory-shader --lib emit::valu_tests::bfe_signed_and_unsigned_match_rdna2: 1 passed, 0 failed (RTX 5090 hardware + WARP, including the new edge cases for 5-bit offset/width masking and bit-31 boundary).cargo test -p victory-shader --lib emit::lower::tests::vector_bitfield_extract_instruction_count: 1 passed, 0 failed (19 DXIL instructions for bothv_bfe_u32andv_bfe_i32).cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Lowering
v_bfe_u32/v_bfe_i32directly to DXILtertiary.i32Ubfe(52) /Ibfe(51) matches RDNA2's 5-bit offset/width semantics and shrinks the generated DXIL cleanly.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@fuzeofficlal on GitHub · 2026-11-26 02:05 UTC · original · reviewed
Reviewed and verified against
main(63bcca43) on Windows 11 (RTX 5090 + WARP +dxil.dll,VICTORY_D3D12_DEBUG=1) — clean and ready to merge:v_bfe_u32/v_bfe_i32(crates/victory-shader/src/emit/lower.rs:7531-7537) to a singledx.op.tertiary.i32(Ubfe52/Ibfe51, args&[w, off, a]) matches RDNA2 5-bitoff[4:0]/w[4:0]masking semantics (includingwidth == 0/32->0,offset >= 32, andoffset + width > 32sign extension from bit 31), while properly keepingself.bfe(...)for 7-bit-width scalars_bfe_{u32,i32}(lower.rs:3944).63bcca43,emit/lower.rsgrows to 521,372 B (+809 B, 2,916 B under524,288 B).Local verification:
bfe_signed_and_unsigned_match_rdna2+vector_bitfield_extract_instruction_count+emit::lower::tests: 34/34 passed on both RTX 5090 and WARP (dxil.dll+DEBUG=1)emit::semantics_tests::integers_match_the_hardware: 1/1 passedcargo clippy --all-targets -- -D warnings+cargo xtask policy(192 files ok): 0 warnings@kotekompotek on GitHub · 2026-11-26 02:19 UTC · original · reviewed
Verified: DXIL Ibfe(51)/Ubfe(52) already apply the 5-bit width/offset masks, so the old m31 pre-mask plus composite expansion was redundant. Opcode mapping is right (signed→51, unsigned→52) and the rewritten hardware test now discriminates arg order — e.g. (0xffffffff, off 0, width 31) expects 0x7fffffff, which a swapped (width,value) order could not produce — plus the exact instruction-count anchor (19) pins the single-op lowering.
@wwwwwwww3333333 on GitHub · 2026-11-26 08:40 UTC · original
AMD hardware run of
eb73a3a. RX 6750 XT (RDNA2), driver 32.0.21045.29003, Windows 11, Rust 1.98.1, on main63bcca4.cargo test -p victory-shader --lib -- bfe_signed_and_unsigned vector_bitfield_extract --test-threads=1: 2 passed, 0 failed, sobfe_signed_and_unsigned_match_rdna2agrees with the hardware adapter and the count test holds.The whole
victory-shadersuite with--test-threads=1: 303 passed, 0 failed, 3 ignored (main on this machine: 302 passed, 0 failed).Unit tests only, no game files.
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.