Shaders: lower dynamic v_perm_b32 sign fills once per instruction #3600
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3600"
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?
Imported from Marvisak/VIctory. Originally posted by Ingenioeren on 2026-11-27T20:10:36Z.
Dynamic
v_perm_b32now packs its four sign-fill bytes once and reuses the existing byte-index shift to select them. Previously, each of the four output bytes rebuilt all four sign fills and selected between them separately.The one-thread synthetic shader drops from 158 to 107 emitted DXIL instructions: 51 fewer (32.3%), including its root-constant loads, UAV store, and block terminators. The test counter follows the bitcode writer's reachable-block and live-instruction plan. The test-only counter uses the same helper as #3592/#3564/#3525 so the PRs merge cleanly.
Candidate measurements (same synthetic shader harness; alternative prototypes discarded):
v_bfi_b32v_sad_u8v_perm_b32(chosen)No open PR changes the
v_perm_b32lowering (checked against the open PR list).Bit identity follows by partitioning each unsigned selector byte: 0-7 use the existing ordinary-byte path; 8-11 index packed bytes that are FF exactly when the corresponding source bit (src1 bit 15/31, then src0 bit 15/31) is set; 12 remains zero; 13-255 remain FF. The four packed fields do not overlap. Arithmetic shifts replicate the intended bit, all shifts have defined amounts below 32, and dynamic shifts remain
(selector & 3) * 8. All operands remain raw integer bits, including bit patterns representing NaNs or denormals. Literal/inline-constant selector lowering is untouched.Validation commands:
63bcca4: 300 passed, 2 failed, 3 ignored.dxil.dllPSV validation errors:emit::rect::tests::rectangles_get_their_fourth_cornerandemit::tests::elements_sharing_a_row_keep_their_order.Not tested: game shaders or game behavior, native GPU instruction counts, runtime performance, other adapters/operating systems, or an exhaustive enumeration of all 96 input bits. The three existing ignored tests were not enabled. The full command stops at the two unit-test failures, so integration/doc tests are not reached by that command.
AI assistance: prepared with OpenAI Codex under Claude Code's direction, reviewed by Ingenioeren.
🤖 Generated with Claude Code
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-27T20:49:14Z.
Independent verification (Windows 11 Pro 26200, D3D12 WARP software adapter only, dxil.dll 1.8.2502.11 from SDK 26100).
6f771e68against base main63bcca43(both unchanged when tested).cargo test -p victory-shader --lib: head 300 passed / 4 failed / 3 ignored; base 298 passed / 4 failed / 3 ignored. The same 4 wave-op tests (synthetic_testsgathers/permutes/mask-at-loop) fail on both, so they predate this PR; no new failures. The 2 new tests pass on head. Our 4 failures differ from the 2 listed in the PR body, so the failing set depends on the environment.v_perm_b32_dynamic_instruction_countfails with 158 vs expected 107. That confirms 158 -> 107 emitted DXIL instructions (-51).v_perm_b32_dynamic_selectors_match_byte_referencepasses on base too (4352 cases matched on both backends the harness reports), so it guards results rather than size, as intended.cargo clippy -p victory-shader --all-targets -- -D warningson head: clean.(sel & 3) * 8indexes those bytes correctly. Selectors 0-7 take the ordinary path (sel < 8, unsigned), 8-11 take the packed fill, 12 gives 0x00, and 13 and up give 0xFF. The AShr shifts are 31 and the Shl is 16, so all amounts are defined.lower.rsis 522,080 bytes (limit 524,288). main + #3597 + #3602 + #3587 + #3600 merges textually clean to 523,671 bytes, which is 617 bytes under the limit. #3608 is based on main, not on this PR, so it does not stack.Not tested: game shaders, native GPU, other adapters.
AI-assisted (Claude Sonnet 5.5)
Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-28T00:24:27Z.
Hardware run on AMD, since the report so far is WARP only: RX 5700 XT (Navi 10, RDNA1, driver 32.0.21045.29003, Windows 11 26200), head
6f771e6on63bcca4.v_perm_b32_dynamic_selectors_match_byte_referencepasses:v_perm_b32: hardware: 4352 cases matched.victory-shader --lib --features host: 304 passed, 0 failed, 3 ignored.AI use: Claude Code (Claude Opus 5.5).
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.