Shaders: lower v_cvt_pk_u8_f32 byte insertion to one Bfi #3592

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

@⁠Ingenioeren on GitHub · 2026-11-27 19:38 UTC · original
Ingenioeren:perf/v_cvt_pk_u8_f32-dxil → main · +143 −10 · 3 files · 1 commits · open

v_cvt_pk_u8_f32 now replaces its destination byte with one DXIL Bfi, after shifting the byte selector left by three. This removes five emitted instructions while retaining the existing float conversion.

Synthetic compute shader Main (63bcca4) This change
One operation, three runtime inputs, one UAV store 30 25
Byte selection and insertion alone 7 2

The complete shader emits 16.7% fewer DXIL instructions. The count includes live setup instructions, the store and terminators; it uses the same test-only Module::written_instructions() helper as #2954, #3007, #3525 and #3564. Its copy can be deduplicated when those changes land.

Bfi(8, src1 << 3, byte, src2) reads only the low five offset bits, making the effective offset exactly 8 * (src1 & 3), even when high selector bits are set. The converted value is already in 0..255, so it replaces precisely the selected byte and preserves the other three. See the DXIL Bfi specification. Source-0 abs/neg still use the existing float-source path. Integer-source abs/neg, clamp and output scaling retain their existing rejection behavior, with a regression test.

Open-PR checks searched every candidate opcode and the relevant DXIL names using gh pr list --repo Marvisak/VIctory --state open --search ..., plus byte-insertion and Bfi combinations. No open PR covers this insertion optimization. #1841 changes the preceding rounding-mode handling and leaves insertion unchanged; its diff was checked. The excluded operations in #2020, #1398, #3528, #3525, #3564, #2954, #3007 and #2893 were left outside this change.

Validation used only synthetic shaders:

  • cargo test --locked --offline -p victory-shader vector_byte_pack_instruction_count -- --nocapture: first failed on the unchanged main lowering, reporting 30 against the 25-instruction assertion; passes after implementation, reporting 25.
  • cargo test --locked --offline -p victory-shader vector_byte_pack_matches_cpu_reference -- --nocapture: passed on the main lowering, with 4,272 inputs for each of four source-0 abs/neg combinations on each backend (17,088 cases per backend). The patched run also passed in the full suite below, using the same 17,088 cases per backend. The CPU reference widens to f64, rounds ties to even, converts to a saturated byte and replaces one element in a byte array. Cases cover every byte rounding tie and neighboring floats, signed zero, subnormals, infinities, signed quiet/signaling NaNs, saturation boundaries, high selector bits and preservation of untouched bytes.
  • cargo test --locked --offline -p victory-shader vector_byte_pack_keeps_unsupported_modifiers_rejected -- --nocapture: 1 passed.
  • cargo test --locked --offline -p victory-shader: main had 300 passed, 2 failed, 3 ignored; this branch had 303 passed, 2 failed, 3 ignored. The main run used a detached worktree at 63bcca4 and an explicitly shared Cargo target directory (--target-dir).
  • Known main failures: emit::rect::tests::rectangles_get_their_fourth_corner and emit::tests::elements_sharing_a_row_keep_their_order. Both are local dxil.dll rejections of the Pipeline State Validation container part. The branch reproduces exactly the same two failures. No tests were weakened or newly ignored.
  • cargo test --locked --offline -p victory-shader --test resource_tracking: 3 passed, 0 failed, 1 ignored. Run separately because the full command stops at the existing library failures.
  • cargo test --locked --offline -p victory-shader --doc: passed, 0 doctests.
  • cargo clippy --locked --offline -p victory-shader --all-targets -- -D warnings: passed.
  • cargo fmt --check: fails on clean main and this branch with the same 925 pre-existing diff blocks. The proposed additions/deletions grouped by file are identical after ignoring locations and context. This patch introduces no additional formatting proposals. git diff --cached --check passed.
  • cargo run --locked --offline -p xtask -- policy --staged: passed, asset policy: 3 files ok.

Execution coverage is limited to AMD Radeon RX 6750 XT (driver 32.0.21045.29003) and Microsoft WARP, with local DXIL validation. No other hardware was tested. No game was launched, no game files were accessed, and no game-derived content was used. The original GFX10 instruction was not executed natively. GPU execution time, driver-generated native instruction counts and game performance were not measured; the demonstrated gain is emitted DXIL instruction count.

AI assistance: prepared with OpenAI Codex under Claude Code's direction, reviewed by Ingenioeren.

🤖 Generated with Claude Code

**@⁠Ingenioeren** on GitHub · 2026-11-27 19:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/3592) `Ingenioeren:perf/v_cvt_pk_u8_f32-dxil` → `main` · +143 −10 · 3 files · 1 commits · open `v_cvt_pk_u8_f32` now replaces its destination byte with one DXIL `Bfi`, after shifting the byte selector left by three. This removes five emitted instructions while retaining the existing float conversion. | Synthetic compute shader | Main (`63bcca4`) | This change | | --- | ---: | ---: | | One operation, three runtime inputs, one UAV store | 30 | 25 | | Byte selection and insertion alone | 7 | 2 | The complete shader emits 16.7% fewer DXIL instructions. The count includes live setup instructions, the store and terminators; it uses the same test-only `Module::written_instructions()` helper as #2954, #3007, #3525 and #3564. Its copy can be deduplicated when those changes land. `Bfi(8, src1 << 3, byte, src2)` reads only the low five offset bits, making the effective offset exactly `8 * (src1 & 3)`, even when high selector bits are set. The converted value is already in 0..255, so it replaces precisely the selected byte and preserves the other three. See the [DXIL Bfi specification](https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#bfi). Source-0 abs/neg still use the existing float-source path. Integer-source abs/neg, clamp and output scaling retain their existing rejection behavior, with a regression test. Open-PR checks searched every candidate opcode and the relevant DXIL names using `gh pr list --repo Marvisak/VIctory --state open --search ...`, plus byte-insertion and Bfi combinations. No open PR covers this insertion optimization. #1841 changes the preceding rounding-mode handling and leaves insertion unchanged; its diff was checked. The excluded operations in #2020, #1398, #3528, #3525, #3564, #2954, #3007 and #2893 were left outside this change. Validation used only synthetic shaders: - `cargo test --locked --offline -p victory-shader vector_byte_pack_instruction_count -- --nocapture`: first failed on the unchanged main lowering, reporting 30 against the 25-instruction assertion; passes after implementation, reporting 25. - `cargo test --locked --offline -p victory-shader vector_byte_pack_matches_cpu_reference -- --nocapture`: passed on the main lowering, with 4,272 inputs for each of four source-0 abs/neg combinations on each backend (17,088 cases per backend). The patched run also passed in the full suite below, using the same 17,088 cases per backend. The CPU reference widens to f64, rounds ties to even, converts to a saturated byte and replaces one element in a byte array. Cases cover every byte rounding tie and neighboring floats, signed zero, subnormals, infinities, signed quiet/signaling NaNs, saturation boundaries, high selector bits and preservation of untouched bytes. - `cargo test --locked --offline -p victory-shader vector_byte_pack_keeps_unsupported_modifiers_rejected -- --nocapture`: 1 passed. - `cargo test --locked --offline -p victory-shader`: main had 300 passed, 2 failed, 3 ignored; this branch had 303 passed, 2 failed, 3 ignored. The main run used a detached worktree at `63bcca4` and an explicitly shared Cargo target directory (`--target-dir`). - Known main failures: `emit::rect::tests::rectangles_get_their_fourth_corner` and `emit::tests::elements_sharing_a_row_keep_their_order`. Both are local `dxil.dll` rejections of the Pipeline State Validation container part. The branch reproduces exactly the same two failures. No tests were weakened or newly ignored. - `cargo test --locked --offline -p victory-shader --test resource_tracking`: 3 passed, 0 failed, 1 ignored. Run separately because the full command stops at the existing library failures. - `cargo test --locked --offline -p victory-shader --doc`: passed, 0 doctests. - `cargo clippy --locked --offline -p victory-shader --all-targets -- -D warnings`: passed. - `cargo fmt --check`: fails on clean main and this branch with the same 925 pre-existing diff blocks. The proposed additions/deletions grouped by file are identical after ignoring locations and context. This patch introduces no additional formatting proposals. `git diff --cached --check` passed. - `cargo run --locked --offline -p xtask -- policy --staged`: passed, `asset policy: 3 files ok`. Execution coverage is limited to AMD Radeon RX 6750 XT (driver 32.0.21045.29003) and Microsoft WARP, with local DXIL validation. No other hardware was tested. No game was launched, no game files were accessed, and no game-derived content was used. The original GFX10 instruction was not executed natively. GPU execution time, driver-generated native instruction counts and game performance were not measured; the demonstrated gain is emitted DXIL instruction count. AI assistance: prepared with OpenAI Codex under Claude Code's direction, reviewed by Ingenioeren. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 19:40:42 +00:00
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-27 19:53 UTC · original

I combined #3592 9a62538 and #3564 89caff6 on 63bcca4. The integration retains one DXIL instruction counter and both sets of tests. Integration branch 2e6bc29

I passed the output of v_cvt_pk_u8_f32 into v_msad_u8 in a single synthetic compute shader. The 1,024-case matrix varies the float, all four byte positions with and without high selector bits, and all 16 reference masks. With WARP 1.0.22 forced for both harness paths, main and the combined branch each matched the CPU byte-array reference in all 2,048 readbacks. In each run, 1,576 readbacks exercised accumulator wrap. The combined shader advertised MSAD in SFI0.

All five original focused tests passed. The individual fixtures kept their 25- and 20-instruction DXIL counts. Strict shader Clippy and the asset policy passed. The extra composition fixture was local. AI-assisted with Codex.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-27 19:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/3592#issuecomment-7226974310) I combined #3592 `9a62538` and #3564 `89caff6` on `63bcca4`. The integration retains one DXIL instruction counter and both sets of tests. [Integration branch `2e6bc29`](https://github.com/andrewpozdnakov7-jpg/VIctory/tree/review/byte-insert-and-masked-sad) I passed the output of `v_cvt_pk_u8_f32` into `v_msad_u8` in a single synthetic compute shader. The 1,024-case matrix varies the float, all four byte positions with and without high selector bits, and all 16 reference masks. With WARP 1.0.22 forced for both harness paths, main and the combined branch each matched the CPU byte-array reference in all 2,048 readbacks. In each run, 1,576 readbacks exercised accumulator wrap. The combined shader advertised MSAD in SFI0. All five original focused tests passed. The individual fixtures kept their 25- and 20-instruction DXIL counts. Strict shader Clippy and the asset policy passed. The extra composition fixture was local. AI-assisted with Codex.
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-27 19:56 UTC · original

Independent CPU-only verification on Windows / Rust 1.100.0 / MSVC.

  • PR head: 9a62538b36471f454cb76012adf68bcebc8dcf95, merge base 63bcca43c6a00a758510398fa43096ce7e4f7df0.
  • Commands (both exit 0):
    • cargo test --locked -p victory-shader --lib -- emit::lower::tests::vector_byte_pack_instruction_count --exact --test-threads=1 --quiet → 1 passed; 0 failed; 307 filtered.
    • cargo test --locked -p victory-shader --lib -- emit::lower::tests::vector_byte_pack_keeps_unsupported_modifiers_rejected --exact --test-threads=1 --quiet → 1 passed; 0 failed; 307 filtered.
  • Negative controls: short-name git grep -F -c <name> on base 63bcca43 → exit 1 / 0 hits for both test names; both present on the PR head.
  • git diff --check 63bcca43 HEAD → exit 0.
  • Caveats: only the two synthetic pure-CPU lowering tests were replayed; the PR's third new test vector_byte_pack_matches_cpu_reference needs a GPU/WARP device and was not run. No full crate suite. An older claim about rounding modes for the same opcode (#2891) has different scope (instruction count vs rounding) but touches lower.rs.
  • GPU/driver: N/A (CPU-only tests). No game data, assets, extracted shaders or DRM involved.
  • AI-assisted: Hy4 flash.
**@⁠cloph-dsp** on GitHub · 2026-11-27 19:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/3592#issuecomment-7227022201) Independent CPU-only verification on Windows / Rust 1.100.0 / MSVC. - PR head: `9a62538b36471f454cb76012adf68bcebc8dcf95`, merge base `63bcca43c6a00a758510398fa43096ce7e4f7df0`. - Commands (both exit 0): - `cargo test --locked -p victory-shader --lib -- emit::lower::tests::vector_byte_pack_instruction_count --exact --test-threads=1 --quiet` → `1 passed; 0 failed; 307 filtered`. - `cargo test --locked -p victory-shader --lib -- emit::lower::tests::vector_byte_pack_keeps_unsupported_modifiers_rejected --exact --test-threads=1 --quiet` → `1 passed; 0 failed; 307 filtered`. - Negative controls: short-name `git grep -F -c <name>` on base `63bcca43` → exit 1 / 0 hits for both test names; both present on the PR head. - `git diff --check 63bcca43 HEAD` → exit 0. - Caveats: only the two synthetic pure-CPU lowering tests were replayed; the PR's third new test `vector_byte_pack_matches_cpu_reference` needs a GPU/WARP device and was not run. No full crate suite. An older claim about rounding modes for the same opcode (#2891) has different scope (instruction count vs rounding) but touches `lower.rs`. - GPU/driver: N/A (CPU-only tests). No game data, assets, extracted shaders or DRM involved. - AI-assisted: Hy4 flash.
Author
Owner

@⁠kilolimaVI on GitHub · 2026-11-27 21:05 UTC · original

Verified on AMD Radeon 780M (RDNA3), Windows 11, head 9a62538.

  • Before (main 63bcca4 + this PR's valu_tests.rs): vector_byte_pack_matches_cpu_reference already passes, so behaviour is unchanged by the switch to one Bfi.
  • After: vector_byte_pack 3/3 passed, 5 of 5 runs.
  • Full suite (victory-shader + victory-gpu --features diagnostics): 554 passed, 0 failed.

AI-assisted (Claude).

**@⁠kilolimaVI** on GitHub · 2026-11-27 21:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/3592#issuecomment-7228124692) Verified on AMD Radeon 780M (RDNA3), Windows 11, head 9a62538. - Before (main 63bcca4 + this PR's `valu_tests.rs`): `vector_byte_pack_matches_cpu_reference` already passes, so behaviour is unchanged by the switch to one `Bfi`. - After: `vector_byte_pack` 3/3 passed, 5 of 5 runs. - Full suite (`victory-shader` + `victory-gpu --features diagnostics`): 554 passed, 0 failed. AI-assisted (Claude).
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/3592/head:github-bot/gh-3592'
git switch 'github-bot/gh-3592'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3592'
git switch 'github-bot/gh-3592'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3592'
git switch 'github-bot/gh-3592'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3592'
git switch 'main'
git merge --squash 'github-bot/gh-3592'
git switch 'main'
git merge --ff-only 'github-bot/gh-3592'
git switch 'main'
git merge 'github-bot/gh-3592'
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!3592
No description provided.