Shaders: lower v_cvt_pk_u8_f32 byte insertion to one Bfi #3592
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!3592
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3592"
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 19:38 UTC · original
Ingenioeren:perf/v_cvt_pk_u8_f32-dxil→main· +143 −10 · 3 files · 1 commits · openv_cvt_pk_u8_f32now replaces its destination byte with one DXILBfi, after shifting the byte selector left by three. This removes five emitted instructions while retaining the existing float conversion.63bcca4)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 exactly8 * (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 at63bcca4and an explicitly shared Cargo target directory (--target-dir).emit::rect::tests::rectangles_get_their_fourth_cornerandemit::tests::elements_sharing_a_row_keep_their_order. Both are localdxil.dllrejections 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 --checkpassed.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
@andrewpozdnakov7-jpg on GitHub · 2026-11-27 19:53 UTC · original
I combined #3592
9a62538and #356489caff6on63bcca4. The integration retains one DXIL instruction counter and both sets of tests. Integration branch2e6bc29I passed the output of
v_cvt_pk_u8_f32intov_msad_u8in 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.
@cloph-dsp on GitHub · 2026-11-27 19:56 UTC · original
Independent CPU-only verification on Windows / Rust 1.100.0 / MSVC.
9a62538b36471f454cb76012adf68bcebc8dcf95, merge base63bcca43c6a00a758510398fa43096ce7e4f7df0.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.git grep -F -c <name>on base63bcca43→ exit 1 / 0 hits for both test names; both present on the PR head.git diff --check 63bcca43 HEAD→ exit 0.vector_byte_pack_matches_cpu_referenceneeds 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 toucheslower.rs.@kilolimaVI on GitHub · 2026-11-27 21:05 UTC · original
Verified on AMD Radeon 780M (RDNA3), Windows 11, head
9a62538.63bcca4+ this PR'svalu_tests.rs):vector_byte_pack_matches_cpu_referencealready passes, so behaviour is unchanged by the switch to oneBfi.vector_byte_pack3/3 passed, 5 of 5 runs.victory-shader+victory-gpu --features diagnostics): 554 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.