Shaders: a float inline constant in a 64-bit operand is the f64 value #1558
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1559"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by default-cybe on 2026-11-24T19:10:34Z.
What
resource::inline64(code)gives the value of an inline constant in a 64-bit operand: integers 128..208 sign-extended, floats 240..248 as f64 bit patterns (0.5, -0.5, 1, -1, 2, -2, 4, -4, and 0x3FC45F30_6DC9C882 for 1/(2 pi)). The SALU 64-bithalfclosure inemit/lower.rsandsrc64now use it.Why
Per LLVM, a 64-bit source reads codes 240..248 as doubles (LLVM's
AMDGPUDisassembler::decodeFPImmedpicksgetInlineImmVal64for any 64-bit-wide operand). We took the f32 bits frominline()for the low dword and filled the high dword with the f32's sign (half) or with zero (src64, which sent 240..248 to the zero-extending arm). So:s_mov_b64 s[12:13], 1.0gave0x00000000_3f800000, not0x3ff00000_00000000s_mov_b64 s[12:13], 1/(2pi)gave low dword0x3e22f983, not0x6dc9c882s_mov_b64 s[12:13], -1.0gave high dword0xffffffff, not0xbff00000v_lshrrev_b64 v[0:1], 32, -1.0gave0, not0xbff00000v_cmp_eq_u64against a float constant compared the wrong valueThis reaches every user of
half(s_mov_b64, s_cselect_b64, s_and/or/xor/... b64, s_lshl/lshr_b64, s_ashr_i64, s_bcnt1_i32_b64, s_ff1_i32_b64, s_cmpu64) and ofsrc64(v_lshlrev/lshrrev_b64, v_ashrrev_i64, v_cmp_u64/i64). Inline integers behave as before.Tested
Windows 11 x64, RTX 5070 (driver 32.0.16.1088) and WARP, on
mainffe310eplus this commit:emit::valu_tests::inline_float_constant_in_a_64_bit_operand_is_the_f64_value. It builds 1-thread GFX10 compute shaders withbuild_valu_cs:s_mov_b64(both dwords) for each of codes 240..248, 192 and 208, ands_and_b64 -1, c,v_lshrrev_b64 32, candv_cmp_eq_u64 c, v[1:2]for codes 243 (-1.0), 248 (1/(2 pi)) and 208 (-16). It runs them withrun_caseson the hardware adapter and on WARP. Onmainit fails with 48 mismatches (24 float checks x 2 devices; the integer codes pass). With the fix it passes on both. The expected values follow LLVM's table; this does not measure AMD hardware.cargo test --workspace: 343 passed, 0 failed, 6 ignored.cargo xtask policy:asset policy: 154 files ok.cargo clippy --workspace --all-targets --all-features --locked -- -D warnings(the CI command): clean.rustfmt --edition 2024 --check crates/victory-shader/src/emit/valu_tests.rs: clean.cargo fmt --check -p victory-shaderreports diffs inlower.rsandresource.rsthat are already onmain; none are in the lines this commit changes.Not tested
acce0c0on a Radeon 660M (RDNA2, RADV under Proton). That run checks the emitted DXIL on a second GPU; the expected values still come from LLVM's table.wave.rsconstant()(whole-wave simulation of EXEC writes) is not changed. It still treats 240..248 as f32 values; #646 rewrites that function and makes it refuse float constants ons_mov_b64.Overlap
src64arm and thehalfclosure (signed 64-bit literals). The two conflict textually; whichever lands second needs a small rebase.constant()refusing float constants ons_mov_b64) is next to this but touches a different file.v_cvt_f32_f64viasrc64) would get the right f64 value for a float constant with this change.v_cvt_f32_f64) and #1262 (double arithmetic, stacked on #416) each add their own f64 reader that maps codes 240..248 to doubles. They do not changehalforsrc64; if one lands first, its reader andresource::inline64could share one table.AI use
Written with Conclave (model
cliproxy/claude-opus-5-5), which also ran the commands listed under Tested on my machine, before and after the change. The behaviour comes from public sources (LLVM AMDGPU disassembler).Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T19:20:50Z.
Review: APPROVED
Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (
ffe310e),cargo test -p victory-shader --locked→ 96. Execution/valu tests are#[cfg(all(test, windows))]and were not run here.resource::inline64matches LLVMgetInlineImmVal64: codes 240-248 are the f64 values (248 = 1/(2π) = 0x3FC45F306DC9C882), integers sign-extend throughinline(). Bothhalf()(per-dword of a 64-bit operand) andsrc64()now use it, sov_lshrrev_b64/v_cmp_eq_u64/s_and_b64with float inline constants get the f64 bits instead of a sign-extended i32. This also confirms theConst(193..=208) → hi = 0xFFFFFFFFpath I flagged on #1469 is correct (negative integers sign-extend). The valu test covers all nine float codes plus integer sign-extension across four instruction shapes (Windows-only here).Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:42:36Z.
Automated triage for the maintainers. Closing because another open pull request covers the same change.
See #1577. Float inline constants in 64-bit operands as f64 bits. #1577 contains this change line for line and also follows the constants in resource tracking and s_mov_b64.
If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.
Pull request closed