Shaders: float inline constants in 64-bit operands are doubles #91

Closed
github-bot wants to merge 0 commits from github-bot/gh-91 into main AGit
Owner

@⁠murillojndem on GitHub · 2026-12-01 10:41 UTC · original
amd/inline-float-constants-64bit → main · +100 −15 · 3 files · 1 commits · closed without merging

What

In a 64-bit operand, the float inline constants (codes 240 to 248: 0.5, -0.5, 1.0, -1.0, 2.0, -2.0, 4.0, -4.0 and 1/(2 pi)) were read as the bits of the 32-bit float:

  • src64 (the 64-bit shifts, the addend of v_mad_u64_u32) and src64_dwords (v_cmp_* and v_cmpx_* of i64 and u64) zero-extended them, so v_cmp_eq_u64 s20, 1.0, v[1:2] compared with 0x00000000_3f800000;
  • the scalar reader of 64-bit sources (half: s_mov_b64, s_cselect_b64 and the other SOP operations on 64-bit sources) gave the float's bits as the low dword and their sign as the high one.

LLVM's AMDGPU backend reads these codes as doubles in any 64-bit operand: its disassembler decodes them with getInlineImmVal64 for the 64-bit integer operand types as well as for the float ones (decodeImmOperands, getInlineImmVal64).

Change

emit/lower.rs: src64, src64_dwords and half take the double's bits from one table, inline_f64, which f64_pair uses too. For 1/(2 pi) the table has LLVM's value, 0x3fc45f306dc9c882. f64_pair computed 1.0 / TAU, 0x3fc45f306dc9c883; its one reader, v_cvt_f32_f64, gives the same float for both. TRANSLATOR_VERSION goes from 4 to 5.

Tests

New test emit::valu_tests::inline_float_constants_read_as_doubles_in_64_bit_operands: both dwords of each of the nine constants through v_lshrrev_b64 by 0 and through s_mov_b64, and v_cmp_eq_u64 against 1.0. It lists every mismatch before it fails. Its expected values are LLVM's reading, so it checks the translation, not the console.

On main 5d91fde the translated programs give the old reading in 38 of the 39 cases, on an RX 7900 XT (driver 32.0.32015.7029) and on WARP, for example v_lshrrev_b64 of constant 240, dword 1: 0x00000000, want 0x3fe00000. With this branch the test passes on both.

Also run:

  • victory-shader --lib on WARP: 310 passed, 4 failed, 4 ignored (main: 309, 4, 4). The four failures are the same on main: three fail PSV0 validation with the SDK 10.0.22621 dxil.dll on this PC, and a_lane_mask_joined_with_a_number_is_read_as_the_number_it_is is a hardware-only test that VICTORY_WARP=1 sends to WARP.
  • victory-shader --lib on the RX 7900 XT (and WARP, through the same harness): 311 passed, 3 failed, 4 ignored (main: 310, 3, 4). The three failures are the PSV0 ones.
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings, with and without --all-features: clean.
  • cargo test -p xtask: repository_passes_policy passes. documented_switches_are_read fails, the same way as on main (VICTORY_NAME in README.md).

Limits

  • I built and tested victory-shader only. My checkout leaves out crates/victory-formats/src/bcpack-tables.bin, so I did not build -p victory or run the workspace clippy.
  • No in-game run and no fps numbers.
  • The reading follows LLVM; nobody here checked it on console hardware.
  • No environment switch: it is a decoding fix. I can put it behind a switch if you prefer.
  • Other translator PRs bump the version too (#72 goes to 6, #90 to 5). Whichever lands later needs the next number.

The same change is open as DexNom/VIctory#206. This tree also needed src64_dwords, which came with upstream cc7ec2a.

Generated with Claude Code

**@⁠murillojndem** on GitHub · 2026-12-01 10:41 UTC · [original](https://github.com/eikkapine/victory-amd/pull/91) `amd/inline-float-constants-64bit` → `main` · +100 −15 · 3 files · 1 commits · closed without merging ## What In a 64-bit operand, the float inline constants (codes 240 to 248: 0.5, -0.5, 1.0, -1.0, 2.0, -2.0, 4.0, -4.0 and 1/(2 pi)) were read as the bits of the 32-bit float: - `src64` (the 64-bit shifts, the addend of `v_mad_u64_u32`) and `src64_dwords` (`v_cmp_*` and `v_cmpx_*` of i64 and u64) zero-extended them, so `v_cmp_eq_u64 s20, 1.0, v[1:2]` compared with `0x00000000_3f800000`; - the scalar reader of 64-bit sources (`half`: `s_mov_b64`, `s_cselect_b64` and the other SOP operations on 64-bit sources) gave the float's bits as the low dword and their sign as the high one. LLVM's AMDGPU backend reads these codes as doubles in any 64-bit operand: its disassembler decodes them with `getInlineImmVal64` for the 64-bit integer operand types as well as for the float ones ([decodeImmOperands](https://github.com/llvm/llvm-project/blob/91204ae1822388457d713a235a00a13eca2a2e2d/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp#L723-L730), [getInlineImmVal64](https://github.com/llvm/llvm-project/blob/91204ae1822388457d713a235a00a13eca2a2e2d/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp#L1949-L1972)). ## Change `emit/lower.rs`: `src64`, `src64_dwords` and `half` take the double's bits from one table, `inline_f64`, which `f64_pair` uses too. For 1/(2 pi) the table has LLVM's value, `0x3fc45f306dc9c882`. `f64_pair` computed `1.0 / TAU`, `0x3fc45f306dc9c883`; its one reader, `v_cvt_f32_f64`, gives the same float for both. `TRANSLATOR_VERSION` goes from 4 to 5. ## Tests New test `emit::valu_tests::inline_float_constants_read_as_doubles_in_64_bit_operands`: both dwords of each of the nine constants through `v_lshrrev_b64` by 0 and through `s_mov_b64`, and `v_cmp_eq_u64` against 1.0. It lists every mismatch before it fails. Its expected values are LLVM's reading, so it checks the translation, not the console. On main 5d91fde the translated programs give the old reading in 38 of the 39 cases, on an RX 7900 XT (driver 32.0.32015.7029) and on WARP, for example `v_lshrrev_b64 of constant 240, dword 1: 0x00000000, want 0x3fe00000`. With this branch the test passes on both. Also run: - `victory-shader --lib` on WARP: 310 passed, 4 failed, 4 ignored (main: 309, 4, 4). The four failures are the same on main: three fail PSV0 validation with the SDK 10.0.22621 `dxil.dll` on this PC, and `a_lane_mask_joined_with_a_number_is_read_as_the_number_it_is` is a hardware-only test that `VICTORY_WARP=1` sends to WARP. - `victory-shader --lib` on the RX 7900 XT (and WARP, through the same harness): 311 passed, 3 failed, 4 ignored (main: 310, 3, 4). The three failures are the PSV0 ones. - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`, with and without `--all-features`: clean. - `cargo test -p xtask`: `repository_passes_policy` passes. `documented_switches_are_read` fails, the same way as on main (`VICTORY_NAME` in README.md). ## Limits - I built and tested `victory-shader` only. My checkout leaves out `crates/victory-formats/src/bcpack-tables.bin`, so I did not build `-p victory` or run the workspace clippy. - No in-game run and no fps numbers. - The reading follows LLVM; nobody here checked it on console hardware. - No environment switch: it is a decoding fix. I can put it behind a switch if you prefer. - Other translator PRs bump the version too (#72 goes to 6, #90 to 5). Whichever lands later needs the next number. The same change is open as DexNom/VIctory#206. This tree also needed `src64_dwords`, which came with upstream cc7ec2a. Generated with [Claude Code](https://claude.com/claude-code)
In a 64-bit operand, the float inline constants (codes 240 to 248: 0.5,
-0.5, 1.0, -1.0, 2.0, -2.0, 4.0, -4.0 and 1/(2 pi)) were read as the
bits of the 32-bit float:
- src64 (the 64-bit shifts, the addend of v_mad_u64_u32) and
  src64_dwords (v_cmp_* and v_cmpx_* of i64 and u64) zero-extended
  them, so v_cmp_eq_u64 s20, 1.0, v[1:2] compared with
  0x00000000_3f800000;
- the scalar reader of 64-bit sources (`half`: s_mov_b64, s_cselect_b64
  and the other SOP operations on 64-bit sources) gave the float's bits
  as the low dword and their sign as the high one.

LLVM's AMDGPU backend reads them as doubles in any 64-bit operand: its
disassembler decodes codes 240 to 248 with getInlineImmVal64 for the
64-bit integer operand types as well as for the float ones. src64,
src64_dwords and `half` now take the double's bits from one table,
inline_f64, which f64_pair uses too. For 1/(2 pi) the table has LLVM's
value, 0x3fc45f306dc9c882. f64_pair computed 1.0 / TAU,
0x3fc45f306dc9c883; its one reader, v_cvt_f32_f64, gives the same float
for both.

Test inline_float_constants_read_as_doubles_in_64_bit_operands reads
both dwords of each of the nine constants through v_lshrrev_b64 by 0
and through s_mov_b64, and runs v_cmp_eq_u64 against 1.0. Its expected
values are LLVM's reading, so it checks the translation, not the
console. Without the change the translated programs give the old
reading in 38 of its 39 cases, on an RX 7900 XT and on WARP.

TRANSLATOR_VERSION 4 -> 5, since programs with such operands translate
differently.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 10:44:15 +00:00
github-bot closed this pull request 2026-12-01 18:59:36 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.