Shaders: lower 64-bit shifts without INT64 #2131

Closed
scoresby13 wants to merge 1 commit from upstream-pr/2133 into main
scoresby13 commented 2026-11-25 05:46:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by scoresby13 on 2026-11-25T05:46:56Z.


Summary

Lowers all six 64-bit scalar and vector shift instructions (s_lshl_b64, s_lshr_b64, s_ashr_i64, v_lshlrev_b64, v_lshrrev_b64, v_ashrrev_i64) in victory-shader using pure 32-bit DXIL operations on (lo, hi) dwords (shift64 + src64_dwords), removing flags::INT64 (SFI0 bit 0x8000 / Int64ShaderOps) from shaders that use 64-bit shifts.

Claimed on #1633.

Details

  • Masks shift counts with sh = shift & 31, wide = (shift & 32) != 0, and inv = 31 - sh, computing cross-dword carries via (lo >> 1) >> inv (Shl) and (hi << 1) << inv (LShr/AShr) so every 32-bit DXIL shift stays in 0..=31.
  • Preserves 64-bit operand modifier checks, inline constant and _i64 literal sign-extension, and scalar SCC updates.
  • Adds CPU-only SFI0 validation (shifts_64_bit_need_no_int64) and GPU/WARP tests (v_shift_64_matches_rdna2_without_int64, s_shift_64_matches_rdna2_without_int64) covering 126 (value, shift) pairs per instruction plus inline -1 and literal -100 cases.

Testing

  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings (passed)
  • cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings (passed)
  • cargo xtask policy (asset policy: 182 files ok)
  • cargo test -p victory-shader --locked shift -- --nocapture (4 passed, 0 failed)
  • cargo test -p victory-shader --locked signed_64_bit_operands_sign_extend_their_literal -- --nocapture (1 passed, 0 failed)

No game data was used. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6598115221 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2133). Originally posted by [scoresby13](https://github.com/scoresby13) on 2026-11-25T05:46:56Z. --- ## Summary Lowers all six 64-bit scalar and vector shift instructions (`s_lshl_b64`, `s_lshr_b64`, `s_ashr_i64`, `v_lshlrev_b64`, `v_lshrrev_b64`, `v_ashrrev_i64`) in `victory-shader` using pure 32-bit DXIL operations on `(lo, hi)` dwords (`shift64` + `src64_dwords`), removing `flags::INT64` (`SFI0` bit `0x8000` / `Int64ShaderOps`) from shaders that use 64-bit shifts. Claimed on #1633. ## Details - Masks shift counts with `sh = shift & 31`, `wide = (shift & 32) != 0`, and `inv = 31 - sh`, computing cross-dword carries via `(lo >> 1) >> inv` (`Shl`) and `(hi << 1) << inv` (`LShr`/`AShr`) so every 32-bit DXIL shift stays in `0..=31`. - Preserves 64-bit operand modifier checks, inline constant and `_i64` literal sign-extension, and scalar `SCC` updates. - Adds CPU-only `SFI0` validation (`shifts_64_bit_need_no_int64`) and GPU/WARP tests (`v_shift_64_matches_rdna2_without_int64`, `s_shift_64_matches_rdna2_without_int64`) covering 126 `(value, shift)` pairs per instruction plus inline `-1` and literal `-100` cases. ## Testing - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` (passed) - `cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings` (passed) - `cargo xtask policy` (`asset policy: 182 files ok`) - `cargo test -p victory-shader --locked shift -- --nocapture` (4 passed, 0 failed) - `cargo test -p victory-shader --locked signed_64_bit_operands_sign_extend_their_literal -- --nocapture` (1 passed, 0 failed) No game data was used. AI-assisted.
catminou4 commented 2026-11-25 07:02:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T06:40:59Z.

Review: APPROVED


Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, cargo test -p victory-shader --locked.

145 passed / 0 failed / 2 ignored. 64-bit shifts lowered without INT64 (+1 test) — shift lowering for 64-bit values in 32-bit DXIL; relates to #2104's wqm and the no-INT64 cluster.

<!-- greyfinch-sync:Marvisak/VIctory:review:6052992150 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2133#pullrequestreview-6052992150). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T06:40:59Z. **Review:** APPROVED --- Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, `cargo test -p victory-shader --locked`. 145 passed / 0 failed / 2 ignored. 64-bit shifts lowered without INT64 (+1 test) — shift lowering for 64-bit values in 32-bit DXIL; relates to #2104's wqm and the no-INT64 cluster.
DenRakEiw commented 2026-11-25 07:02:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T06:46:03Z.

Review: APPROVED


Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, with dxil.dll validator):

  • cargo test -p victory-shader --lib shift — 4 passed, 0 failed on both RTX 5090 hardware and VICTORY_D3D12_WARP=1 (verifying 64-bit shifts without INT64)
  • cargo clippy -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean pure-32-bit DXIL lowering of 64-bit shifts without INT64, verified end-to-end on hardware and WARP. Looks great.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6053037923 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2133#pullrequestreview-6053037923). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T06:46:03Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, with `dxil.dll` validator): - `cargo test -p victory-shader --lib shift` — **4 passed, 0 failed** on both RTX 5090 hardware and `VICTORY_D3D12_WARP=1` (verifying 64-bit shifts without `INT64`) - `cargo clippy -p victory-shader --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean pure-32-bit DXIL lowering of 64-bit shifts without `INT64`, verified end-to-end on hardware and WARP. Looks great. AI-assisted (Gemini 4 Neon).
sinan-cmyk commented 2026-11-25 09:06:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T08:24:53Z.


Offline measurement on a retail dump

Result: no count change against main.

I merged head 670c441f onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7156995717 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2133#issuecomment-7156995717). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T08:24:53Z. --- ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head 670c441f onto `main` 940d32f (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 23,918 on `main`, 23,918 with this PR. No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Marvisak commented 2026-11-25 11:05:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T10:49:11Z.


Automated triage for the maintainers.

Merge candidate. This lowers s_lshl/lshr/ashr_b64 and v_lshlrev/lshrrev/ashrrev_b64 on 32-bit dword pairs (Lower::shift64, src64_dwords), so these shaders no longer need Int64ShaderOps. That follows the earlier v_perm_b32 and v_sad changes in main. I checked the arithmetic:

  • Every 32-bit shift amount stays in 0..=31.
  • The carry (lo >> 1) >> (31 - sh) / (hi << 1) << (31 - sh) is 0 at sh == 0.
  • When bit 5 is set the result selects the other dword, with sign fill for ashr.
  • The operands are sign-extended the same way as src64.

CI passes, and the offline count on the retail shaders is unchanged. One optional cleanup: src64 could build on src64_dwords so the operand rules live in one place.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7160215239 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2133#issuecomment-7160215239). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T10:49:11Z. --- <!-- victory-triage v1 head=670c441fc9e96b56ea4734f2b2ec9ae9cf97235a verdict=merge-candidate at=2026-11-25T10:48:53Z --> Automated triage for the maintainers. Merge candidate. This lowers `s_lshl/lshr/ashr_b64` and `v_lshlrev/lshrrev/ashrrev_b64` on 32-bit dword pairs (`Lower::shift64`, `src64_dwords`), so these shaders no longer need `Int64ShaderOps`. That follows the earlier v_perm_b32 and v_sad changes in main. I checked the arithmetic: - Every 32-bit shift amount stays in 0..=31. - The carry `(lo >> 1) >> (31 - sh)` / `(hi << 1) << (31 - sh)` is 0 at `sh == 0`. - When bit 5 is set the result selects the other dword, with sign fill for `ashr`. - The operands are sign-extended the same way as `src64`. CI passes, and the offline count on the retail shaders is unchanged. One optional cleanup: `src64` could build on `src64_dwords` so the operand rules live in one place. --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync closed this pull request 2026-11-25 23:03:52 +00:00
Marvisak commented 2026-11-25 23:05:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:05:53Z.


Automated triage for the maintainers, second look (a review against current main, with builds and tests where they could change the verdict).

Closing because it adds no capability the project needs. The arithmetic is right and the tests pass on hardware and WARP. But the title needs Int64 on the host anyway (64-bit compares, 64-bit image atomics, and flags::INT64 is set in four other places), and every SM 6.6 host has it. Merging would retranslate about 9,800 title sites, turning each native 64-bit shift into about ten 32-bit operations, and add a near-copy of src64. If the project ever decides that emitted DXIL must avoid Int64, this is a correct starting point.

If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7175931851 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2133#issuecomment-7175931851). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T22:05:53Z. --- Automated triage for the maintainers, second look (a review against current `main`, with builds and tests where they could change the verdict). Closing because it adds no capability the project needs. The arithmetic is right and the tests pass on hardware and WARP. But the title needs Int64 on the host anyway (64-bit compares, 64-bit image atomics, and `flags::INT64` is set in four other places), and every SM 6.6 host has it. Merging would retranslate about 9,800 title sites, turning each native 64-bit shift into about ten 32-bit operations, and add a near-copy of `src64`. If the project ever decides that emitted DXIL must avoid Int64, this is a correct starting point. If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!2131
No description provided.