Repository navigation
Shaders: float inline constants in 64-bit operands are doubles - #206
Open
murillojndem wants to merge 1 commit into
Open
murillojndem wants to merge 1 commit into
murillojndem wants to merge 1 commit into
Conversation
Codes 240..248 in a 64-bit operand were read as the f32 bits: src64 zero-extended them (v_cmp_eq_u64 with 1.0 compared with 0x3f800000) and the scalar 64-bit reader sign-extended them. LLVM's AMDGPU disassembler decodes them with its f64 table for the INT64 operand types, and its code generator encodes 64-bit integers that way. Both readers and f64_pair now take one table, inline_f64, with LLVM's 1/(2 pi), 0x3fc45f306dc9c882 (1.0 / TAU gives 0x3fc45f306dc9c883; v_cvt_f32_f64, the only reader of f64_pair, rounds both to the same float). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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. The vector reader,
src64(v_cmp_*_{i64,u64},v_lshlrev_b64and the other 64-bit shifts, the addend ofv_mad_u64_u32), zero-extended them:v_cmp_eq_u64 s20, 1.0, v[1:2]compared with 0x00000000_3f800000. The scalar reader (s_mov_b64,s_cselect_b64, the 64-bit bit operations, shifts and compares) put those bits in the low dword and their sign in the high one, so the two readers also disagreed with each other on the negative constants.LLVM's AMDGPU backend reads them as doubles in any 64-bit operand. Its disassembler decodes codes 240 to 248 with
getInlineImmVal64forOPERAND_REG_IMM_INT64andOPERAND_REG_INLINE_C_INT64as well as for the FP64 types (decodeImmOperands), and the 64-bit scalar and vector sources have that type (SSrc_b64, VSrc_b64). Its code generator emits a 64-bit integer with those bits as the constant:SIInstrInfo::isInlineConstantchecks the INT64 types withisInlinableLiteral64(SIInstrInfo.cpp).Both readers now take the double's bits from one table,
inline_f64, whichf64_pairuses too. For 1/(2 pi) the table has LLVM's value, 0x3fc45f306dc9c882 (getInlineImmVal64).f64_paircomputed1.0 / TAU, which is 0x3fc45f306dc9c883. Its only reader isv_cvt_f32_f64, which gives 0x3e22f983 for both, so that part changes no result today.Test
inline_float_constants_read_as_doubles_in_64_bit_operandsreads both dwords of each of the nine constants throughv_lshrrev_b64by 0 and throughs_mov_b64, and runsv_cmp_eq_u64against 1.0. The expected patterns are written out in the test. It lists every mismatch before it fails.Results on
4ad8692, on WARP:mainwith the new test: 38 of the 39 cases are wrong, every dword read through either reader and two of the three compares. For examplev_lshrrev_b64 of constant 242, dword 1: 0x00000000, want 0x3ff00000ands_mov_b64 of constant 241, dword 1: 0xffffffff, want 0xbfe00000.recttests fail PSV0 validation with the SDK 10.0.22621dxil.dll, and threevalu_testsfail pipeline creation on WARP only.s_mov_b64cases).cargo clippy -p victory-shader --all-targets --locked -- -D warningsis clean with and without--all-features,cargo xtask policypasses, and rustfmt reports nothing new in the two files.The test checks the lowering against LLVM's reading of these operands. It does not check the console, and it was not run on AMD or NVIDIA hardware. How often the game's shaders use a float constant in a 64-bit operand was not measured.
Claude (Anthropic) wrote the change and the test and ran the verification.
Generated with Claude Code