Shaders: float inline constants in 64-bit operands are doubles #91
No reviewers
Labels
No labels
accessibility
bug
crash
documentation
duplicate
enhancement
good first issue
graphics
help wanted
invalid
needs logs
performance
question
rdna2
rdna3
rdna4
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/eikkapine--victory-amd!91
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-91"
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?
@murillojndem on GitHub · 2026-12-01 10:41 UTC · original
amd/inline-float-constants-64bit→main· +100 −15 · 3 files · 1 commits · closed without mergingWhat
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 ofv_mad_u64_u32) andsrc64_dwords(v_cmp_*andv_cmpx_*of i64 and u64) zero-extended them, sov_cmp_eq_u64 s20, 1.0, v[1:2]compared with0x00000000_3f800000;half:s_mov_b64,s_cselect_b64and 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
getInlineImmVal64for the 64-bit integer operand types as well as for the float ones (decodeImmOperands, getInlineImmVal64).Change
emit/lower.rs:src64,src64_dwordsandhalftake the double's bits from one table,inline_f64, whichf64_pairuses too. For 1/(2 pi) the table has LLVM's value,0x3fc45f306dc9c882.f64_paircomputed1.0 / TAU,0x3fc45f306dc9c883; its one reader,v_cvt_f32_f64, gives the same float for both.TRANSLATOR_VERSIONgoes 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 throughv_lshrrev_b64by 0 and throughs_mov_b64, andv_cmp_eq_u64against 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
5d91fdethe 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 examplev_lshrrev_b64 of constant 240, dword 1: 0x00000000, want 0x3fe00000. With this branch the test passes on both.Also run:
victory-shader --libon 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.22621dxil.dllon this PC, anda_lane_mask_joined_with_a_number_is_read_as_the_number_it_isis a hardware-only test thatVICTORY_WARP=1sends to WARP.victory-shader --libon 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_policypasses.documented_switches_are_readfails, the same way as on main (VICTORY_NAMEin README.md).Limits
victory-shaderonly. My checkout leaves outcrates/victory-formats/src/bcpack-tables.bin, so I did not build-p victoryor run the workspace clippy.The same change is open as DexNom/VIctory#206. This tree also needed
src64_dwords, which came with upstream cc7ec2a.Generated with Claude Code
Pull request closed