Shaders: lower dynamic v_perm_b32 sign fills once per instruction #3600
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!3600
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@Ingenioeren on GitHub · 2026-11-27 20:10 UTC · original
Ingenioeren:fix/perf-v-perm-b32-dxil→main· +109 −12 · 3 files · 1 commits · openDynamic
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
@oni-swr on GitHub · 2026-11-27 20:49 UTC · original
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)
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.