Shaders: lower v_bfe_u32/v_bfe_i32 to one Ubfe/Ibfe #2954

Open
github-bot wants to merge 1 commit from github-bot/gh-2954 into main AGit
Owner

@⁠Ingenioeren on GitHub · 2026-11-26 01:27 UTC · original
Ingenioeren:perf/vector-bitfield-extract → main · +59 −6 · 3 files · 1 commits · open

What

Lower v_bfe_i32 and v_bfe_u32 to one DXIL Ibfe or Ubfe call 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 Ibfe and logically for Ubfe, which gives the same sign or zero extension as the previous lowering. The operands and results are 32-bit integers. DXIL specification

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

Synthetic shader origin/main (63bcca4) Branch Reduction
v_bfe_i32 34 19 44.1%
v_bfe_u32 27 19 29.6%

How tested

  • cargo test --locked --offline -p victory-shader vector_bitfield_extract_instruction_count -- --nocapture measured 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 -- --nocapture passed 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-shader added one passing test on the branch, from 300 to 301. Both runs had the same two local dxil.dll validation failures and three ignored tests.
  • cargo test --locked --offline -p victory-shader --test resource_tracking passed three tests with one ignored on both revisions.
  • cargo clippy -p victory-shader --locked --offline --all-targets passed.
  • cargo run -p xtask -- policy --staged passed 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.

**@⁠Ingenioeren** on GitHub · 2026-11-26 01:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/2954) `Ingenioeren:perf/vector-bitfield-extract` → `main` · +59 −6 · 3 files · 1 commits · open ## What Lower `v_bfe_i32` and `v_bfe_u32` to one DXIL `Ibfe` or `Ubfe` call 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 `Ibfe` and logically for `Ubfe`, which gives the same sign or zero extension as the previous lowering. The operands and results are 32-bit integers. [DXIL specification](https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#ibfe) Each 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. | Synthetic shader | `origin/main` (`63bcca4`) | Branch | Reduction | | --- | ---: | ---: | ---: | | `v_bfe_i32` | 34 | 19 | 44.1% | | `v_bfe_u32` | 27 | 19 | 29.6% | ## How tested - `cargo test --locked --offline -p victory-shader vector_bitfield_extract_instruction_count -- --nocapture` measured 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 -- --nocapture` passed 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-shader` added one passing test on the branch, from 300 to 301. Both runs had the same two local `dxil.dll` validation failures and three ignored tests. - `cargo test --locked --offline -p victory-shader --test resource_tracking` passed three tests with one ignored on both revisions. - `cargo clippy -p victory-shader --locked --offline --all-targets` passed. - `cargo run -p xtask -- policy --staged` passed 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:18:31 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-26 01:51 UTC · original

Independent test report for eb73a3ab7995695a56d8239104623460c7250ce9, with the exact parent 63bcca43c6a00a758510398fa43096ce7e4f7df0 as the control. Claim: #1633.

Setup: Windows 11 Pro 10.0.26200, Rust 1.98.1. Validator is VICTORY_DXIL = Windows SDK 10.0.26100 x64 dxil.dll 1.8.2502.11; it loaded, since the test that unwraps Validator::load passed. Environment had VICTORY_D3D12_WARP=1 and VICTORY_WARP=1, so the "hardware" slot of run_cases also opens WARP. A probe confirmed that Host::new(false) and Host::new(true) are both Microsoft 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.

Parent with test-only changes Head
v_bfe_u32 27 19
v_bfe_i32 34 19

These 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_rdna2 passes on the head, and on the parent with the PR's extended cases applied, so outputs are identical across both revisions.
  • My local probe (uncommitted) runs v_bfe_u32 and v_bfe_i32 through 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).
    • Inputs: 6 sources (including 0x80000000, 0x7fffffff, 0xffffffff and 1) × 38 offsets (0–31, 32, 33, 63, 0xffffffff, 0x8000001f, 0xffffffe0) × 15 widths (0, 1, 2, 4, 15–17, 30–33, 37, 63, 0xffffffe1, 0xffffffff).
    • That is 3420 cases per op. Every result matched, on both revisions, for both ops.

Full suite: cargo test -j 4 --locked -p victory-shader --lib -- --test-threads=1

Passed Failed Ignored
Head 299 4 3
Parent 298 4 3

The same 4 synthetic_tests fail on both revisions:

  • a_mask_joined_with_data_at_a_uniform_loop_is_its_number
  • gathers_at_a_level_match_the_hardware
  • permutes_mask_high_address_bits_and_divergent_branches
  • permutes_read_the_lane_named_and_zero_from_lanes_left_out

They are hardware-labelled checks ("no pipeline for a wave of 32", and gather texel expectations). VICTORY_WARP=1 forces 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:

  • #2893 carries the same written_instructions helper in bitcode.rs, as the PR notes. #2943 also touches bitcode.rs, lower.rs and valu_tests.rs. I did not test any merge combinations.
  • WARP only. No hardware GPU and no title run.

This is an independent test only, not a review. Prepared with Claude Code (Claude Opus 5.5).

**@⁠oni-swr** on GitHub · 2026-11-26 01:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2954#issuecomment-7180201876) Independent test report for `eb73a3ab7995695a56d8239104623460c7250ce9`, with the exact parent `63bcca43c6a00a758510398fa43096ce7e4f7df0` as the control. Claim: #1633. **Setup:** Windows 11 Pro 10.0.26200, Rust 1.98.1. Validator is `VICTORY_DXIL` = Windows SDK 10.0.26100 x64 `dxil.dll` 1.8.2502.11; it loaded, since the test that unwraps `Validator::load` passed. Environment had `VICTORY_D3D12_WARP=1` and `VICTORY_WARP=1`, so the "hardware" slot of `run_cases` also opens WARP. A probe confirmed that `Host::new(false)` and `Host::new(true)` are both `Microsoft 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. | | Parent with test-only changes | Head | |---|---:|---:| | `v_bfe_u32` | 27 | 19 | | `v_bfe_i32` | 34 | 19 | These 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_rdna2` passes on the head, and on the parent with the PR's extended cases applied, so outputs are identical across both revisions. - My local probe (uncommitted) runs `v_bfe_u32` and `v_bfe_i32` through 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). - Inputs: 6 sources (including 0x80000000, 0x7fffffff, 0xffffffff and 1) × 38 offsets (0–31, 32, 33, 63, 0xffffffff, 0x8000001f, 0xffffffe0) × 15 widths (0, 1, 2, 4, 15–17, 30–33, 37, 63, 0xffffffe1, 0xffffffff). - That is 3420 cases per op. Every result matched, on both revisions, for both ops. **Full suite:** `cargo test -j 4 --locked -p victory-shader --lib -- --test-threads=1` | | Passed | Failed | Ignored | |---|---:|---:|---:| | Head | 299 | 4 | 3 | | Parent | 298 | 4 | 3 | The same 4 `synthetic_tests` fail on both revisions: - `a_mask_joined_with_data_at_a_uniform_loop_is_its_number` - `gathers_at_a_level_match_the_hardware` - `permutes_mask_high_address_bits_and_divergent_branches` - `permutes_read_the_lane_named_and_zero_from_lanes_left_out` They are hardware-labelled checks ("no pipeline for a wave of 32", and gather texel expectations). `VICTORY_WARP=1` forces 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:** - #2893 carries the same `written_instructions` helper in `bitcode.rs`, as the PR notes. #2943 also touches `bitcode.rs`, `lower.rs` and `valu_tests.rs`. I did not test any merge combinations. - WARP only. No hardware GPU and no title run. This is an independent test only, not a review. Prepared with Claude Code (Claude Opus 5.5).
Author
Owner

@⁠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_i32 now lower to DXIL Ubfe/Ibfe (ops 52/51, width, offset, value) instead of main's open-coded Lower::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 as Ibfe's plain shift. The extended bfe_signed_and_unsigned_match_rdna2 cases (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_count asserts 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-only written_instructions helper in bitcode.rs, so whichever lands second drops its copy.

CI: passing (check).

Recommending a look, not approving.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 05:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/2954#issuecomment-7183686860) <!-- victory-triage v1 head=eb73a3ab7995695a56d8239104623460c7250ce9 verdict=merge-candidate at=2026-11-26T05:39:18Z --> Automated triage for the maintainers. **Merge candidate.** In `Lower::valu_op` (`crates/victory-shader/src/emit/lower.rs`), `v_bfe_u32`/`v_bfe_i32` now lower to DXIL `Ubfe`/`Ibfe` (ops 52/51, `width, offset, value`) instead of main's open-coded `Lower::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 as `Ibfe`'s plain shift. The extended `bfe_signed_and_unsigned_match_rdna2` cases (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_count` asserts 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-only `written_instructions` helper in `bitcode.rs`, so whichever lands second drops its copy. CI: passing (`check`). Recommending a look, not approving. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠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.dll validator 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 both v_bfe_u32 and v_bfe_i32).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Lowering v_bfe_u32 / v_bfe_i32 directly to DXIL tertiary.i32 Ubfe (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).

**@⁠Dukestar69** on GitHub · 2026-11-26 02:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/2954#pullrequestreview-6067571260) · **approved these changes** Tested merged onto `origin/main` (`63bcca4`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP, `dxil.dll` validator 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 both `v_bfe_u32` and `v_bfe_i32`). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Lowering `v_bfe_u32` / `v_bfe_i32` directly to DXIL `tertiary.i32` `Ubfe` (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).
Author
Owner

@⁠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:

  • Lowering v_bfe_u32 / v_bfe_i32 (crates/victory-shader/src/emit/lower.rs:7531-7537) to a single dx.op.tertiary.i32 (Ubfe 52 / Ibfe 51, args &[w, off, a]) matches RDNA2 5-bit off[4:0] / w[4:0] masking semantics (including width == 0/32 -> 0, offset >= 32, and offset + width > 32 sign extension from bit 31), while properly keeping self.bfe(...) for 7-bit-width scalar s_bfe_{u32,i32} (lower.rs:3944).
  • Note on 512 KiB file-size cap: on 63bcca43, emit/lower.rs grows to 521,372 B (+809 B, 2,916 B under 524,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 passed
  • cargo clippy --all-targets -- -D warnings + cargo xtask policy (192 files ok): 0 warnings
**@⁠fuzeofficlal** on GitHub · 2026-11-26 02:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/2954#pullrequestreview-6067588764) · **reviewed** Reviewed and verified against `main` (`63bcca43`) on Windows 11 (RTX 5090 + WARP + `dxil.dll`, `VICTORY_D3D12_DEBUG=1`) — clean and ready to merge: - Lowering `v_bfe_u32` / `v_bfe_i32` (`crates/victory-shader/src/emit/lower.rs:7531-7537`) to a single `dx.op.tertiary.i32` (`Ubfe` `52` / `Ibfe` `51`, args `&[w, off, a]`) matches RDNA2 5-bit `off[4:0]` / `w[4:0]` masking semantics (including `width == 0`/`32` -> `0`, `offset >= 32`, and `offset + width > 32` sign extension from bit 31), while properly keeping `self.bfe(...)` for 7-bit-width scalar `s_bfe_{u32,i32}` (`lower.rs:3944`). - **Note on 512 KiB file-size cap**: on `63bcca43`, `emit/lower.rs` grows to **521,372 B** (`+809 B`, **2,916 B** under `524,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 passed** - `cargo clippy --all-targets -- -D warnings` + `cargo xtask policy` (`192 files ok`): 0 warnings
Author
Owner

@⁠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.

**@⁠kotekompotek** on GitHub · 2026-11-26 02:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2954#pullrequestreview-6067696050) · **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.
Author
Owner

@⁠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 main 63bcca4.

cargo test -p victory-shader --lib -- bfe_signed_and_unsigned vector_bitfield_extract --test-threads=1: 2 passed, 0 failed, so bfe_signed_and_unsigned_match_rdna2 agrees with the hardware adapter and the count test holds.

The whole victory-shader suite with --test-threads=1: 303 passed, 0 failed, 3 ignored (main on this machine: 302 passed, 0 failed).

Unit tests only, no game files.

**@⁠wwwwwwww3333333** on GitHub · 2026-11-26 08:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/2954#issuecomment-7186884419) AMD hardware run of eb73a3a. RX 6750 XT (RDNA2), driver 32.0.21045.29003, Windows 11, Rust 1.98.1, on main 63bcca4. `cargo test -p victory-shader --lib -- bfe_signed_and_unsigned vector_bitfield_extract --test-threads=1`: 2 passed, 0 failed, so `bfe_signed_and_unsigned_match_rdna2` agrees with the hardware adapter and the count test holds. The whole `victory-shader` suite with `--test-threads=1`: 303 passed, 0 failed, 3 ignored (main on this machine: 302 passed, 0 failed). Unit tests only, no game files.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2954/head:github-bot/gh-2954'
git switch 'github-bot/gh-2954'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2954'
git switch 'github-bot/gh-2954'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2954'
git switch 'github-bot/gh-2954'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2954'
git switch 'main'
git merge --squash 'github-bot/gh-2954'
git switch 'main'
git merge --ff-only 'github-bot/gh-2954'
git switch 'main'
git merge 'github-bot/gh-2954'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2954
No description provided.