shader: read float inline constants on 64-bit operands as f64 bits #1576
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1576
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1576/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?
@Nawid3333 on GitHub · 2026-10-17 00:18 UTC · original
Nawid3333:shader/inline-float-constants-64bit→main· +37 −7 · 2 files · 1 commits · merged 2026-10-17 03:21 UTCA float inline constant (0.5, 1.0, 2.0, 4.0, their negatives, 1/(2π)) read by a 64-bit operand is the f64 bit pattern, for integer B64 opcodes as well as F64 ones.
ReadU32Pairreturned{f32 bits, 0}, so only F64-typed reads had the right value.s_mov_b64 s[0:1], 1.0gave 0x3f800000 instead of 0x3ff0000000000000, and so did the 64-bit SALU logic ops,S_CSELECT_B64,S_CMP_*_U64,V_LSHRREV_B64andV_CMP_*_U64with such a constant.Evidence:
INT64operands withgetInlineImmVal64(242 isbit_cast<uint64_t>(1.0)).0x3fe0000000000000ul >> lanebecomesv_lshrrev_b64 v[n:n+1], v0, 0.5, and likewise for 1.0, 2.0, -4.0 and 1/(2π) (0x3fc45f306dc9c882). The shifted results read back right. A 64-bit compare with 0x3ff0000000000000 uses 1.0 too (v_cmp_eq_u64on the RX 9070 XT,v_cmp_eq_i64on the iGPU).Change: the f64 conversion moves from the F64 path of
ReadOperandintoReadU32Pair, so every 64-bit read through it gets it.Test:
ScalarVector64BitFloatInlineConstants:s_mov_b64of 1.0 and of 1/(2π);s_or_b64with 0.5;v_lshrrev_b64of 2.0;s_cmp_eq_u64of a register holding 0x3ff0000000000000 against 1.0.Before the change it fails on both GPUs (f32 bits); after it passes, also with 32-wide subgroups.
Based on TheCruZ's 284deab28 (#1219, closed on 10-10). This version leaves
ReadMaskreading throughReadU32Pair, so B64 mask instructions get the 64-bit value in wave32 too. (VALU lane-mask operands such asv_cndmask's take registers only in LLVM,SSrc_i1.)If you'd like this done differently, tell me and I'll change it.
Written with Claude Code (AI): it wrote the change and the test and ran them on my PC (driver 26.8.1, Windows 11). I reviewed the diff and this description before opening the PR.
🤖 Generated with Claude Code
A float inline constant (240-248) read by a 64-bit operand is the f64 bit pattern for integer B64 opcodes too: AMD's compilers emit v_lshrrev_b64 v[4:5], v0, 1.0 for 0x3ff0000000000000 >> lane. ReadU32Pair returned {f32 bits, 0}, so only F64-typed reads had the right value. Based on TheCruZ's 284deab28 (closed #1219). Co-Authored-By: Claude Opus 5.5 <[email protected]>@coderabbitai[bot] on GitHub · 2026-10-17 00:24 UTC · original
📝 Walkthrough
Float inline constant conversion now occurs in
ReadU32Pair, which returns the low and high words of the F64 value. The existing explicit F64 bit pattern for0x3e22f983remains. A registered compute test covers inline constants in scalar and vector 64-bit operations.Suggested reviewers:
nmzik,thecruzPriority: ➖ Normal
Change: Bug fix
Merge Risk: 🔵 Low · up to
148e8Float-inline constants used as masks can select the wrong lanes. Preserve their raw bits in the mask path before merging.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files. (1 skipped: 1 too large.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment
@coderabbitai helpto get the list of available commands.@ -491,0 +488,4 @@: std::bit_cast<uint64_t>(static_cast<double>(std::bit_cast<float>(operand.value)));return {IR::U32(IR::Value(static_cast<uint32_t>(bits))),IR::U32(IR::Value(static_cast<uint32_t>(bits >> 32u)))};}@coderabbitai[bot] on GitHub · 2026-10-17 00:24 UTC · original · edited 2026-10-17 00:45 UTC
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 9955
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 16733
Use the raw f32 pair for float-inline masks.
ReadMaskpasses float-inline constants toThreadBitthrough the new f64 projection. For0.5f(0x3f000000), lane 24 reads1from the raw f32 word but0from the converted pair{0, 0x3fe00000}in a wave32.V_CNDMASK_B32andS_U64_MASKcan therefore produce different per-lane results.Keep the f64 projection in
ReadU32Pairfor 64-bit data operands. Use the raw f32 word whenReadMaskhandles a float-inline constant.Suggested fix
@coderabbitai[bot] on GitHub · 2026-10-17 00:24 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
f235f97a-5c44-4c92-b9bf-f4520cb8dd75📥 Commits
Reviewing files that changed from the base of the PR and between
42bb0da520and148e8b6fae.📒 Files selected for processing: 2
src/graphics/shader/recompiler/frontend/translate/Translate.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
@ -491,0 +488,4 @@: std::bit_cast<uint64_t>(static_cast<double>(std::bit_cast<float>(operand.value)));return {IR::U32(IR::Value(static_cast<uint32_t>(bits))),IR::U32(IR::Value(static_cast<uint32_t>(bits >> 32u)))};}@Nawid3333 on GitHub · 2026-10-17 00:45 UTC · original
I'll keep
ReadMaskonReadU32Pair. The instructions that read a constant throughReadMaskare 64-bit SALU ops (S_U64_MASK,S_CSELECT_B64, the 64-bitS_*_SAVEEXEC), so the constant is a 64-bit operand and the hardware reads its f64 pattern. With an EXEC or VCC operand,S_U64_MASKalso computes the scalar it writes from this per-lane mask (WriteMask(inst.dst, invocation_result, true)). With the raw f32 word,s_and_b64 exec, exec, 0.5would give EXEC the f32 pattern. Without EXEC/VCC, the scalar comes fromReadU32Pairand only the mask provenance fromReadMask, and the two would disagree.The VALU lane-mask operands (
v_cndmask_b32's mask, the carry-in) are SGPRs: the RDNA2 guide says "In VOP3 the VCC source may be a scalar GPR specified in S2", and LLVM's operand for them (SSrc_i1,decodeBoolReg) takes registers only. So a float inline constant doesn't occur there.@ -491,0 +488,4 @@: std::bit_cast<uint64_t>(static_cast<double>(std::bit_cast<float>(operand.value)));return {IR::U32(IR::Value(static_cast<uint32_t>(bits))),IR::U32(IR::Value(static_cast<uint32_t>(bits >> 32u)))};}@coderabbitai[bot] on GitHub · 2026-10-17 00:46 UTC · original
@Nawid3333 You're right. I withdraw this finding.
ReadMaskmust use the same 64-bit pattern asReadU32Pairfor these SALU constant operands. My raw-f32 exception would make the scalar value and its per-lane mask disagree. MyV_CNDMASK_B32example also assumed a float-inline mask source that its register-only operand does not permit.Thanks for the clarification. No change is needed here.
✏️ Learnings added
✅ Review thread resolved.
You are interacting with an AI system.