Shaders: a float inline constant in a 64-bit operand is the f64 value #1559
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1559
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1559/head"
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?
@default-cybe on GitHub · 2026-11-24 19:10 UTC · original
default-cybe:fix/inline-float-const-64bit-operand→main· +93 −9 · 3 files · 1 commits · closed without mergingWhat
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).@Marvisak on GitHub · 2026-11-25 00:42 UTC · original
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