Shaders: lower dynamic v_perm_b32 without requiring INT64 #423
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/423"
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 pedrofort on 2026-11-24T03:13:37Z.
<head></head>
Problem
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.
Imported from Marvisak/VIctory. Originally posted by towiice on 2026-11-24T03:21:27Z.
Review: COMMENTED
Tested PR head
d5704aaon Windows 11 x64 build 10.0.26300 (26H2), NVIDIA GeForce GTX 1650 SUPER (driver 610.88), Rust 1.100.0 (stable-x86_64-pc-windows-gnullvm):cargo test -p victory-shader -- --test-threads=4: 71 passed, 0 failed (7.43 s).All
victory-shadertests (including the new dynamicv_perm_b32lowering) pass cleanly.Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T06:33:13Z.
Review: APPROVED
Tested
d5704aaon Windows 11, RTX 5070, MSVC:cargo test --workspace --no-fail-fastpasses (266 passed, 0 failed).victory translate <title exe> --validate --pipelinesgives the same counts before and after: 12 of 12 programs emitted, 12 validated, 12 pipelines.src1and 4–7 bytes ofsrc0(sel & 4chooses the dword,sel & 3the byte), which is what(src0 << 32 | src1) >> (sel * 8)gave.words.iter()\n.flat_map, wrappedresource::track(args).AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by pedrofort on 2026-11-24T03:42:04Z.
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.