Shaders: lower dynamic v_perm_b32 without requiring INT64 #423
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!423
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/423/head"
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?
@pedrofort on GitHub · 2026-11-24 03:13 UTC · original
<head></head>pedrofort:shader-perm-no-int64→main· +94 −13 · 1 files · 1 commits · merged 2026-11-24 08:13 UTCProblem
The dynamic-selector lowering of
v_perm_b32combines two 32-bit operands into a 64-bit integer, unnecessarily declaring the INT64 shader capability.The generated shift can also exceed the integer width for selector values above seven, even though subsequent selects replace those intermediate results.
Implementation
Select the source dword using selector bit 2.
Select the byte within that dword using selector bits 0–1.
Keep shift amounts within the valid 32-bit range.
Preserve the existing handling of sign replication and constant-byte selectors.
Leave constant-selector lowering unchanged.
Verification
Apple M5, macOS arm64, Rust 1.98.1, base commit
Test | Before | After -- | -- | -- Constant selector without INT64 | PASS | PASS Dynamic selector without INT64 | FAIL | PASS Full shader unit test suite | — | 58 passed, 0 failedd2a4bae.The regression tests inspect the SFI0 feature flags of emitted DXIL containers.
A separate CPU arithmetic model comparison matched 1,048,576 cases, covering all 256 byte selectors across 4,096 deterministic operand pairs.
Library Clippy with
-D warnings: clean.Asset policy: 151 files OK.
git diff --check: clean.Limitations
The arithmetic comparison verifies the proposed algorithm, while the Rust regression tests verify emitted feature flags. GPU execution and DXIL validation on Windows have not been performed.
All inputs are synthetic. No game assets were used.
AI-assisted implementation and test preparation (ChatGPT), with tests executed locally on Apple Silicon.
@pedrofort on GitHub · 2026-11-24 03:42 UTC · original
Additional GPU validation on Apple M5 using Metal Shader Converter 4.0.3.
Compared the original and patched dynamic v_perm_b32 lowering using two synthetic pixel shaders covering all 256 selector values in each output byte.
Both implementations produced 1,024/1,024 matching pixels per operand set, with zero channel error and byte-identical GPU readbacks.
The patched version removes the INT64 feature requirement while preserving the tested GPU results.
Metal API and GPU validation were enabled. No game assets were used.