Shaders: lower dynamic v_perm_b32 without requiring INT64 #423

Manually merged
github merged 1 commit from gh-pr/423/head into gh-pr/423/base 2026-11-26 04:03:21 +00:00
Owner

@⁠pedrofort on GitHub · 2026-11-24 03:13 UTC · original
pedrofort:shader-perm-no-int64 → main · +94 −13 · 1 files · 1 commits · merged 2026-11-24 08:13 UTC

<head></head>

Problem

The dynamic-selector lowering of v_perm_b32 combines 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 d2a4bae.

Test | Before | After -- | -- | -- Constant selector without INT64 | PASS | PASS Dynamic selector without INT64 | FAIL | PASS Full shader unit test suite | — | 58 passed, 0 failed

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:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/423) `pedrofort:shader-perm-no-int64` → `main` · +94 −13 · 1 files · 1 commits · merged 2026-11-24 08:13 UTC <head></head><h2 style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-style: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>Problem</span></h2><p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>The dynamic-selector lowering of<span class="Apple-converted-space"> </span></span><code><span>v_perm_b32</span></code><span><span class="Apple-converted-space"> </span>combines two 32-bit operands into a 64-bit integer, unnecessarily declaring the INT64 shader capability.</span></p><p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>The generated shift can also exceed the integer width for selector values above seven, even though subsequent selects replace those intermediate results.</span></p><h2 style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-style: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>Implementation</span></h2><ul style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><li><p><span>Select the source dword using selector bit 2.</span></p></li><li><p><span>Select the byte within that dword using selector bits 0–1.</span></p></li><li><p><span>Keep shift amounts within the valid 32-bit range.</span></p></li><li><p><span>Preserve the existing handling of sign replication and constant-byte selectors.</span></p></li><li><p><span>Leave constant-selector lowering unchanged.</span></p></li></ul><h2 style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-style: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>Verification</span></h2><p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>Apple M5, macOS arm64, Rust 1.98.1, base commit<span class="Apple-converted-space"> </span></span><code><span>d2a4bae</span></code><span>.</span></p> Test | Before | After -- | -- | -- Constant selector without INT64 | PASS | PASS Dynamic selector without INT64 | FAIL | PASS Full shader unit test suite | — | 58 passed, 0 failed <p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>The regression tests inspect the SFI0 feature flags of emitted DXIL containers.</span></p><p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>A separate CPU arithmetic model comparison matched 1,048,576 cases, covering all 256 byte selectors across 4,096 deterministic operand pairs.</span></p><ul style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><li><p><span>Library Clippy with<span class="Apple-converted-space"> </span></span><code><span>-D warnings</span></code><span>: clean.</span></p></li><li><p><span>Asset policy: 151 files OK.</span></p></li><li><p><code><span>git diff --check</span></code><span>: clean.</span></p></li></ul><h2 style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-style: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>Limitations</span></h2><p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>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.</span></p><p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>All inputs are synthetic. No game assets were used.</span></p><p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>AI-assisted implementation and test preparation (ChatGPT), with tests executed locally on Apple Silicon.</span></p>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:03:19 +00:00
github manually merged commit d5704aaac6 into gh-pr/423/base 2026-11-26 04:03:21 +00:00
Author
Owner

@⁠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.

**@⁠pedrofort** on GitHub · 2026-11-24 03:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/423#issuecomment-7121339109) 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.
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!423
No description provided.