shader: lower 64-bit shifts without INT64 #3200

Open
Jackster wants to merge 1 commit from upstream-pr/3202 into main
Jackster commented 2026-11-26 12:28:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T12:28:19Z.


Summary

Lower the six RDNA2 64-bit shift opcodes using pairs of 32-bit DXIL values. Shaders that use these shifts can run without the SFI0 INT64 feature when they have no other 64-bit integer operations.

The lowering preserves RDNA2’s six-bit shift count and arithmetic sign extension. Counts of 32–63 shift across dwords, and counts of 64 or more wrap modulo 64. Every emitted 32-bit shift uses an in-range count.

Validation

  • Synthetic tests keep both result dwords live and verify that SFI0 INT64 stays clear for all six opcodes.
  • Runtime tests compare both dwords against a 64-bit CPU reference on a hardware GPU and WARP.
  • The full workspace test suite, both strict Clippy configurations, and the repository asset-policy check passed.

NEW-66. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6626647502 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3202). Originally posted by [Jackster](https://github.com/Jackster) on 2026-11-26T12:28:19Z. --- ## Summary Lower the six RDNA2 64-bit shift opcodes using pairs of 32-bit DXIL values. Shaders that use these shifts can run without the SFI0 INT64 feature when they have no other 64-bit integer operations. The lowering preserves RDNA2’s six-bit shift count and arithmetic sign extension. Counts of 32–63 shift across dwords, and counts of 64 or more wrap modulo 64. Every emitted 32-bit shift uses an in-range count. ## Validation - Synthetic tests keep both result dwords live and verify that SFI0 INT64 stays clear for all six opcodes. - Runtime tests compare both dwords against a 64-bit CPU reference on a hardware GPU and WARP. - The full workspace test suite, both strict Clippy configurations, and the repository asset-policy check passed. NEW-66. AI-assisted.
Dukestar69 commented 2026-11-26 12:50:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T12:50:09Z.

Review: APPROVED


Verified on RTX 5090 & WARP against origin/main (63bcca4):

  • cargo test -p victory-shader --lib bit_shifts -- --test-threads=1: 3/3 passed on RTX 5090 and WARP (scalar_64_bit_shifts_need_no_int64, vector_64_bit_shifts_need_no_int64, sixty_four_bit_shifts_count_to_six_bits).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 192 files ok.

Cleanly lowers 64-bit scalar and vector shifts using 32-bit operations without requiring the DXIL INT64 feature flag.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6074412312 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3202#pullrequestreview-6074412312). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T12:50:09Z. **Review:** APPROVED --- Verified on RTX 5090 & WARP against `origin/main` (`63bcca4`): - `cargo test -p victory-shader --lib bit_shifts -- --test-threads=1`: 3/3 passed on RTX 5090 and WARP (`scalar_64_bit_shifts_need_no_int64`, `vector_64_bit_shifts_need_no_int64`, `sixty_four_bit_shifts_count_to_six_bits`). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 192 files ok. Cleanly lowers 64-bit scalar and vector shifts using 32-bit operations without requiring the DXIL INT64 feature flag. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
cloph-dsp commented 2026-11-26 13:04:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-26T12:43:01Z.


Independent local verification of head 6344a95 on Windows 11, Rust 1.100.0/MSVC:

  • cargo test --locked -p victory-shader --lib -- emit::lower::tests::scalar_64_bit_shifts_need_no_int64 --exact — 1 passed, 0 failed.
  • cargo test --locked -p victory-shader --lib -- emit::lower::tests::vector_64_bit_shifts_need_no_int64 --exact — 1 passed, 0 failed.
  • git diff --check origin/main HEAD — clean.

Worktree-local CARGO_TARGET_DIR; synthetic GFX10 word streams only, no game assets or DRM material used. AI-assisted (Hy4 flash). GPU/driver N/A (CPU-side lowering tests only).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7192366030 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3202#issuecomment-7192366030). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-26T12:43:01Z. --- Independent local verification of head `6344a95` on Windows 11, Rust 1.100.0/MSVC: - `cargo test --locked -p victory-shader --lib -- emit::lower::tests::scalar_64_bit_shifts_need_no_int64 --exact` — 1 passed, 0 failed. - `cargo test --locked -p victory-shader --lib -- emit::lower::tests::vector_64_bit_shifts_need_no_int64 --exact` — 1 passed, 0 failed. - `git diff --check origin/main HEAD` — clean. Worktree-local `CARGO_TARGET_DIR`; synthetic GFX10 word streams only, no game assets or DRM material used. AI-assisted (Hy4 flash). GPU/driver N/A (CPU-side lowering tests only).
oni-swr commented 2026-11-26 14:01:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-26T13:06:50Z.


WARP test report (claim: #1633)

  • Head: 6344a9580c4ecd23ea474db122ea874c6486e686, base: origin/main 63bcca43c6 (head sits directly on it, no merge needed)
  • Backend: WARP (VICTORY_D3D12_WARP=1). Windows 11, Rust per rust-toolchain.toml, cargo test --locked -p victory-shader --lib -- --test-threads=1, VICTORY_D3D12_WARP=1 and VICTORY_WARP=1 (the shader tests only honour the latter, so every device in the run was WARP; no physical GPU). Validator: Windows SDK 10.0.26100 dxil.dll. Synthetic word streams only, no game data.
  • victory-shader suite: 301 passed, 4 failed, 3 ignored. New tests scalar_64_bit_shifts_need_no_int64, vector_64_bit_shifts_need_no_int64 and sixty_four_bit_shifts_count_to_six_bits all pass; none skipped (WARP runs the 64-bit-shift GPU test).
  • Control (main alone): suite 298 passed, 4 failed, 3 ignored. The same 4 fail on main and on the PR, so they are not caused by it (synthetic_tests: a_mask_joined_with_data_at_a_uniform_loop_is_its_number, gathers_at_a_level_match_the_hardware, permutes_mask_high_address_bits_and_divergent_branches, permutes_read_the_lane_named_and_zero_from_lanes_left_out). With the PR's tests applied to main alone, the two SFI0 INT64 tests fail (main sets INT64) and sixty_four_bit_shifts_count_to_six_bits passes.
  • Review: no defect found. I traced shift64 for Shl/LShr/AShr at counts 0, 1, 31, 32, 33, 63 and past 63 (the cnt == 0 and >= 32 selects are right, the complementary shift stays in range). Note that WARP evidently runs the old INT64 form correctly, so the behaviour test cannot show a regression there; the SFI0 tests are the guard for this change. 11 other tests print a skip message and pass (no console/PC compiler, no wave-of-32/64 pipeline); none touch this change.
  • cloph-dsp's earlier report on this head (12:43 UTC) predates the claim and covers only the two SFI0 tests; this adds the behaviour test and the full suite.

AI use: Claude Code (Claude Sonnet 5.5), coordinated by Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7192892963 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3202#issuecomment-7192892963). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-26T13:06:50Z. --- **WARP test report (claim: #1633)** - Head: `6344a9580c4ecd23ea474db122ea874c6486e686`, base: `origin/main` 63bcca43c6a0 (head sits directly on it, no merge needed) - Backend: WARP (VICTORY_D3D12_WARP=1). Windows 11, Rust per `rust-toolchain.toml`, `cargo test --locked -p victory-shader --lib -- --test-threads=1`, `VICTORY_D3D12_WARP=1` and `VICTORY_WARP=1` (the shader tests only honour the latter, so every device in the run was WARP; no physical GPU). Validator: Windows SDK 10.0.26100 `dxil.dll`. Synthetic word streams only, no game data. - `victory-shader` suite: **301 passed, 4 failed, 3 ignored**. New tests `scalar_64_bit_shifts_need_no_int64`, `vector_64_bit_shifts_need_no_int64` and `sixty_four_bit_shifts_count_to_six_bits` all pass; none skipped (WARP runs the 64-bit-shift GPU test). - Control (`main` alone): suite 298 passed, 4 failed, 3 ignored. The same 4 fail on main and on the PR, so they are not caused by it (`synthetic_tests`: `a_mask_joined_with_data_at_a_uniform_loop_is_its_number`, `gathers_at_a_level_match_the_hardware`, `permutes_mask_high_address_bits_and_divergent_branches`, `permutes_read_the_lane_named_and_zero_from_lanes_left_out`). With the PR's tests applied to main alone, the two SFI0 INT64 tests **fail** (main sets INT64) and `sixty_four_bit_shifts_count_to_six_bits` **passes**. - Review: no defect found. I traced `shift64` for Shl/LShr/AShr at counts 0, 1, 31, 32, 33, 63 and past 63 (the `cnt == 0` and `>= 32` selects are right, the complementary shift stays in range). Note that WARP evidently runs the old INT64 form correctly, so the behaviour test cannot show a regression there; the SFI0 tests are the guard for this change. 11 other tests print a skip message and pass (no console/PC compiler, no wave-of-32/64 pipeline); none touch this change. - cloph-dsp's earlier report on this head (12:43 UTC) predates the claim and covers only the two SFI0 tests; this adds the behaviour test and the full suite. AI use: Claude Code (Claude Sonnet 5.5), coordinated by Claude Code (Claude Opus 5.5).
Lyrnc commented 2026-11-26 17:21:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Lyrnc on 2026-11-26T17:21:53Z.


Checked 6344a95 on RDNA2 hardware for all six 64-bit shifts, using the same instruction words on both sides.

  • Hardware: Radeon iGPU (Ryzen 7 9800X3D), gfx1036 / RDNA2, driver 32.0.21042.62. A HIP kernel (assembled by the driver's amd_comgr) runs the shifts in two forms:

    • VOP3: v_lshlrev_b64, v_lshrrev_b64 and v_ashrrev_i64.
    • SOP2: s_lshl_b64, s_lshr_b64 and s_ashr_i64, with SCC read back through s_cselect_b32. On the hardware side each row fills a whole wave, and its operands come in through v_readfirstlane.

    There are 158 rows:

    • every count from 0 to 127 on random values, with the sign bit set for odd counts;
    • counts such as 0x100, 0x13f, 0x80000020, 0xffffffc1 and 0xffffffff, each with both sign patterns;
    • a few fixed edges.

    That gives 2,370 results (low dword, high dword, and SCC).

  • Translator: the same words through a local copy of the build_valu_cs harness (a local test, not part of this PR). I ran it on main 63bcca4 and on the PR merged onto it, on the RTX 5080 (610.88) and on the same Radeon (picked with a local adapter-name filter in hardware_adapter).

Host branch matches the hardware bit for bit other differences
Radeon gfx1036 main 2,370 0
Radeon gfx1036 #3202 2,370 0
RTX 5080 main 2,370 0
RTX 5080 #3202 2,370 0

So the 32-bit lowering gives the same results as main's 64-bit shifts and as the hardware:

  • Only count bits 5:0 are used, so a count of 0x13f shifts by 63.
  • The arithmetic shift fills with the sign.
  • SCC is set when the scalar result is nonzero.

I didn't check the SFI0 INT64 bit, because your tests cover it.

No game data was used.

AI use: Claude Code (Claude Opus 5.5) wrote the probe and the comparison and ran them on the GPUs above; the numbers come from those runs.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7198889730 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3202#issuecomment-7198889730). Originally posted by [Lyrnc](https://github.com/Lyrnc) on 2026-11-26T17:21:53Z. --- Checked `6344a95` on RDNA2 hardware for all six 64-bit shifts, using the same instruction words on both sides. - **Hardware:** Radeon iGPU (Ryzen 7 9800X3D), gfx1036 / RDNA2, driver 32.0.21042.62. A HIP kernel (assembled by the driver's amd_comgr) runs the shifts in two forms: - VOP3: `v_lshlrev_b64`, `v_lshrrev_b64` and `v_ashrrev_i64`. - SOP2: `s_lshl_b64`, `s_lshr_b64` and `s_ashr_i64`, with SCC read back through `s_cselect_b32`. On the hardware side each row fills a whole wave, and its operands come in through `v_readfirstlane`. There are 158 rows: - every count from 0 to 127 on random values, with the sign bit set for odd counts; - counts such as `0x100`, `0x13f`, `0x80000020`, `0xffffffc1` and `0xffffffff`, each with both sign patterns; - a few fixed edges. That gives 2,370 results (low dword, high dword, and SCC). - **Translator:** the same words through a local copy of the `build_valu_cs` harness (a local test, not part of this PR). I ran it on `main` 63bcca4 and on the PR merged onto it, on the RTX 5080 (610.88) and on the same Radeon (picked with a local adapter-name filter in `hardware_adapter`). | Host | branch | matches the hardware bit for bit | other differences | |---|---|---|---| | Radeon gfx1036 | main | 2,370 | 0 | | Radeon gfx1036 | #3202 | 2,370 | **0** | | RTX 5080 | main | 2,370 | 0 | | RTX 5080 | #3202 | 2,370 | **0** | So the 32-bit lowering gives the same results as main's 64-bit shifts and as the hardware: - Only count bits 5:0 are used, so a count of `0x13f` shifts by 63. - The arithmetic shift fills with the sign. - SCC is set when the scalar result is nonzero. I didn't check the SFI0 INT64 bit, because your tests cover it. No game data was used. AI use: Claude Code (Claude Opus 5.5) wrote the probe and the comparison and ran them on the GPUs above; the numbers come from those runs.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3202:upstream-pr/3202'
git switch 'upstream-pr/3202'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3202'
git switch 'upstream-pr/3202'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3202'
git switch 'upstream-pr/3202'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3202'
git switch 'main'
git merge --squash 'upstream-pr/3202'
git switch 'main'
git merge --ff-only 'upstream-pr/3202'
git switch 'main'
git merge 'upstream-pr/3202'
git push origin 'main'
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!3200
No description provided.