Shaders: expand 64-bit inline constants as signed ints and binary64 floats #1577

Open
github-bot wants to merge 12 commits from github-bot/gh-1577 into main AGit
Owner

@⁠mgunes1311-lab on GitHub · 2026-11-24 19:24 UTC · original
mgunes1311-lab:shader-inline64-constants → main · +337 −42 · 4 files · 12 commits · open

Summary

On GFX10 (RDNA2), inline constant operands (128..=208 and 240..=248) expand to 64 bits according to operand width rather than zero- or sign-extending their 32-bit f32 patterns: integer inline constants (0..=64, -1..=-16) sign-extend to 64 bits, while the nine floating-point inline constants (0.5, -0.5, 1.0, -1.0, 2.0, -2.0, 4.0, -4.0, 1/(2*pi)) expand to their IEEE-754 binary64 bit patterns (0x3fe00000_00000000 through 0x3fc45f30_6dc9c882). LLVM's AMDGPU backend encodes any matching 64-bit integer, bitmask, or descriptor constant with these inline codes (getInlineImmVal64) to save a literal word.

Previously:

  • Lower::sop's 64-bit half helper read Operand::Const(240..=248) as a 32-bit f32 in the low dword and sign-extended its sign bit into the high dword (for example turning -1.0 into 0xffffffff_bf800000 instead of 0xbff00000_00000000, and 1.0 into 0x00000000_3f800000 instead of 0x3ff00000_00000000).
  • Lower::src64 only matched Operand::Const(128..=208), letting 240..=248 fall through to zero-extended 32-bit f32 values in 64-bit vector shifts and comparisons (v_lshlrev_b64, v_lshrrev_b64, v_ashrrev_i64, v_cmp_*_{u64,i64}).
  • structure::Lanes::operand rejected Operand::Const(240..=248) on both wave32 and wave64 scalar mask instructions (such as 2.0 for lane 30 / lane 62 or -2.0 for the top two lanes), degrading constant lane masks into Atom::Opaque.
  • resource copy/select propagation (copy_source for s_mov_b64 and Tracer::picked for s_cselect_b64 / s_cmov_b64) only followed 128..=208, missing constant sampler/descriptor words materialized with 64-bit inline floats (such as s_mov_b64 s[lo:hi], 2.0 for [0, 0x40000000]).

Changes

  • Add resource::inline64(code: u8) -> Option<u64> alongside resource::inline and use it in copy_source (s_mov_b64) and Tracer::picked (s_cselect_b64, s_cmov_b64).
  • Decode Operand::Const in structure::Lanes::operand via inline64 in wave64 and inline in wave32 so inline-float constant lane masks become Atom::Constant.
  • Use resource::inline64 in Lower::sop (half, before the 32-bit h == 0 fallback) and Lower::src64 so all 64-bit scalar and vector consumers see exact RDNA2 64-bit inline constants without requiring INT64 on 32-bit-pair scalar ops.
  • Add unit tests in resource and structure plus end-to-end DXIL-validated hardware GPU and WARP compute execution tests in emit::valu_tests covering 128..=208 and all nine 240..=248 constants across 64-bit scalar and vector instructions.

Verification

  • cargo test -p victory-shader --locked & --all-features (including hardware D3D12 SM 6.6 + WARP execution)
  • cargo clippy --workspace --all-targets --locked -- -D warnings & --all-features
  • RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --locked
  • cargo run -p xtask --locked -- policy --staged
**@⁠mgunes1311-lab** on GitHub · 2026-11-24 19:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/1577) `mgunes1311-lab:shader-inline64-constants` → `main` · +337 −42 · 4 files · 12 commits · open ## Summary On GFX10 (RDNA2), inline constant operands (`128..=208` and `240..=248`) expand to 64 bits according to operand width rather than zero- or sign-extending their 32-bit `f32` patterns: integer inline constants (`0..=64`, `-1..=-16`) sign-extend to 64 bits, while the nine floating-point inline constants (`0.5`, `-0.5`, `1.0`, `-1.0`, `2.0`, `-2.0`, `4.0`, `-4.0`, `1/(2*pi)`) expand to their IEEE-754 binary64 bit patterns (`0x3fe00000_00000000` through `0x3fc45f30_6dc9c882`). LLVM's AMDGPU backend encodes any matching 64-bit integer, bitmask, or descriptor constant with these inline codes (`getInlineImmVal64`) to save a literal word. Previously: - `Lower::sop`'s 64-bit `half` helper read `Operand::Const(240..=248)` as a 32-bit `f32` in the low dword and sign-extended its sign bit into the high dword (for example turning `-1.0` into `0xffffffff_bf800000` instead of `0xbff00000_00000000`, and `1.0` into `0x00000000_3f800000` instead of `0x3ff00000_00000000`). - `Lower::src64` only matched `Operand::Const(128..=208)`, letting `240..=248` fall through to zero-extended 32-bit `f32` values in 64-bit vector shifts and comparisons (`v_lshlrev_b64`, `v_lshrrev_b64`, `v_ashrrev_i64`, `v_cmp_*_{u64,i64}`). - `structure::Lanes::operand` rejected `Operand::Const(240..=248)` on both wave32 and wave64 scalar mask instructions (such as `2.0` for lane 30 / lane 62 or `-2.0` for the top two lanes), degrading constant lane masks into `Atom::Opaque`. - `resource` copy/select propagation (`copy_source` for `s_mov_b64` and `Tracer::picked` for `s_cselect_b64` / `s_cmov_b64`) only followed `128..=208`, missing constant sampler/descriptor words materialized with 64-bit inline floats (such as `s_mov_b64 s[lo:hi], 2.0` for `[0, 0x40000000]`). ## Changes - Add `resource::inline64(code: u8) -> Option<u64>` alongside `resource::inline` and use it in `copy_source` (`s_mov_b64`) and `Tracer::picked` (`s_cselect_b64`, `s_cmov_b64`). - Decode `Operand::Const` in `structure::Lanes::operand` via `inline64` in wave64 and `inline` in wave32 so inline-float constant lane masks become `Atom::Constant`. - Use `resource::inline64` in `Lower::sop` (`half`, before the 32-bit `h == 0` fallback) and `Lower::src64` so all 64-bit scalar and vector consumers see exact RDNA2 64-bit inline constants without requiring `INT64` on 32-bit-pair scalar ops. - Add unit tests in `resource` and `structure` plus end-to-end DXIL-validated hardware GPU and WARP compute execution tests in `emit::valu_tests` covering `128..=208` and all nine `240..=248` constants across 64-bit scalar and vector instructions. ## Verification - `cargo test -p victory-shader --locked` & `--all-features` (including hardware D3D12 SM 6.6 + WARP execution) - `cargo clippy --workspace --all-targets --locked -- -D warnings` & `--all-features` - `RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --locked` - `cargo run -p xtask --locked -- policy --staged`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:36:59 +00:00
Author
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-24 19:36 UTC · original

Verified commit 30ccd23 on Windows 11 / AMD Radeon RX 9060 XT (RDNA4, gfx1200, SM 6.6) + WARP:

  • cargo test -p victory-shader --lib: 125 passed, 0 failed, 1 ignored (including the new 64-bit inline constant GPU tests).

AI-assisted; synthetic tests only, no game files.

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 19:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/1577#issuecomment-7142345530) Verified commit `30ccd23` on **Windows 11 / AMD Radeon RX 9060 XT (RDNA4, `gfx1200`, SM 6.6)** + **WARP**: - `cargo test -p victory-shader --lib`: **125 passed, 0 failed, 1 ignored** (including the new 64-bit inline constant GPU tests). *AI-assisted; synthetic tests only, no game files.*
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:31 UTC · original · edited 2026-11-25 22:26 UTC

Automated triage for the maintainers.

Needs rebase. This PR no longer merges cleanly into main: main has moved since the last triage, and the branch now conflicts in crates/victory-shader/src/emit/valu_tests.rs. It will be reviewed again once it is rebased onto current main.

Previous verdict for this head: merge candidate.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/1577#issuecomment-7149640248) · edited 2026-11-25 22:26 UTC <!-- victory-triage v1 head=5a890daefccbfbe0388a3e81c2a86169f1a08450 verdict=needs-rebase at=2026-11-25T22:29:00Z --> Automated triage for the maintainers. **Needs rebase.** This PR no longer merges cleanly into `main`: `main` has moved since the last triage, and the branch now conflicts in `crates/victory-shader/src/emit/valu_tests.rs`. It will be reviewed again once it is rebased onto current `main`. Previous verdict for this head: merge candidate. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1577/head:github-bot/gh-1577'
git switch 'github-bot/gh-1577'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1577'
git switch 'github-bot/gh-1577'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1577'
git switch 'github-bot/gh-1577'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1577'
git switch 'main'
git merge --squash 'github-bot/gh-1577'
git switch 'main'
git merge --ff-only 'github-bot/gh-1577'
git switch 'main'
git merge 'github-bot/gh-1577'
git push origin 'main'
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!1577
No description provided.