shader: store 16-bit float components of formatted buffer stores like the hardware #1588
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!1588
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1588/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 08:47 UTC · original
Nawid3333:shader/packed-float-buffer-stores→main· +68 −9 · 3 files · 5 commits · closed without mergingMerged with main. Since
59d8256bmain encodes the 11- and 10-bit float components of formatted buffer stores itself, so I dropped this PR's 11/10-bit encoder; it now only changes the 16-bit components.These still go through
PackHalf2x16, so the stored value depends on the host's driver: AMD's compiles it to a round-toward-zero pack (my comment in #1575).BufferStoreFormatXyzwFloat16ConvertsComponentsexpects the round-to-nearest word0xc0003c04for0x3f807e63; on the RX 9070 XT and the Ryzen 7600X iGPU main stores0xc0003c03, so the test fails there.Change: the 16-bit branch of
EncodeFormattedStoreComponentuses yourEmitF32BitsToF16RtzBits(9f88043e, renamed in59d8256b) for everything except NaNs. Nativergba16fstores on the RX 9070 XT (RDNA4) and the iGPU (RDNA2) keep a NaN's top 10 mantissa bits (1 if those are 0) and do not quiet signaling NaNs, while the helper sets the quiet bit, so NaNs get their own select.Tests
BufferStoreFormatXyzwFloat16RoundsTowardZero(BUFFER_STORE_FORMAT_XYZW) stores 32 inputs (zeros of both signs, rounding midpoints, the largest values and beyond, infinities, quiet and signaling NaNs, denormals) and expects the words native stores wrote on both GPUs.BufferStoreFormatXyzwFloat16ConvertsComponentsnow expects0xc0003c03, the word both GPUs store natively, and forbidsPackHalf2x16instead of requiring it.GpuSelectedFormattedRgba16Store(inCheckGpuSelectedFormattedRecordStore) stores the same input and now expects0xc0003c03too; it passes on both GPUs in wave32 and wave64.0x7c6ecomes out as0x7e6e,0x7c01and0xfc01as0x7e00and0xfe00).rgba16fstores, for all 2^32 f32 inputs and their negations: 0 differences on both GPUs. A copy of your helper alone differs in exactly the 8,388,606 signaling NaNs.shader_cfg_tests(not run by CI): its formatted half-float store check requiredPackHalf2x16; it now requires its absence and the f16 infinity constant. The binary passes.ba079bbc.If you'd like this done differently, tell me and I'll change it.
Written with Claude Code (AI): it wrote the change and ran the tests and measurements on my PC (drivers 26.10.1 and 25.10.42, Windows 11).
🤖 Generated with Claude Code
@coderabbitai[bot] on GitHub · 2026-10-17 08:52 UTC · original · edited 2026-10-28 20:50 UTC
Walkthrough
Formatted 16-bit float stores now convert input bits directly. NaNs retain their sign and top payload bits, with a nonzero payload. Other values use the existing round-toward-zero conversion. Compute tests cover rounding boundaries, finite-value clamping, infinities, NaNs, and subnormals. SPIR-V tests now reject
PackHalf2x16and require%uint_31744.Suggested reviewers:
claxten10Priority:
Normal
Change: Bug fix
Merge Risk:
Moderate · up to
ba079D16 formatted stores can write zero instead of float16 data, corrupting buffer or image contents. Fix this 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 with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 1 files. (2 skipped: 2 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.@coderabbitai[bot] on GitHub · 2026-10-17 12:51 UTC · original · edited 2026-10-17 13:09 UTC
On
tests/ShaderRecompilerComputeTests.cppline 48350 (outdated):🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Keep the float16-only selector limited to float16 stores.
If a developer runs
--buffer-float16-store-only, these lines also run the 11/11/10 and 10/11/11 packed-float cases. A packed-float failure can then interrupt a focused float16 check. Remove these two calls from this selector; the cases remain available through--buffer-format-store-onlyandMakeCases().✅ Confirmed as addressed by @Nawid3333
@coderabbitai[bot] on GitHub · 2026-10-17 12:51 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
8b4ba350-fd51-41e6-a971-f1e81a27fa66📥 Commits
Reviewing files that changed from the base of the PR and between 10ce2846db6dc2c8412e442302f0d58181ac9e17 and
b8d4b3c272.📒 Files selected for processing: 4
src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterMemoryHelpers.cpptests/ShaderRecompilerComputeTests.cpptests/shaderCfgTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.
@Nawid3333 on GitHub · 2026-10-17 13:09 UTC · original
On
tests/ShaderRecompilerComputeTests.cppline 48350 (outdated):Agreed, done in
e18c0e2f:--buffer-float16-store-onlynow runs only the two 16-bit float cases, and the 11- and 10-bit cases stay in--buffer-format-store-only.@coderabbitai[bot] on GitHub · 2026-10-17 13:09 UTC · original
On
tests/ShaderRecompilerComputeTests.cppline 48350 (outdated):@Nawid3333 Thanks for the fix in
e18c0e2f. The selector split addresses this finding.If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
✅ Review thread resolved.
You are interacting with an AI system.
@NeySlim on GitHub · 2026-10-17 23:09 UTC · original
RADV data point: Radeon 8060S (RDNA 3.5), Mesa 26.2.4, against
763d3be3. On main the 11- and 10-bit tests fail here too (26 words each). The 16-bit side differs from your GPUs: the inputs ofBufferStoreFormatXyzwFloat16RoundsTowardZeroandConvertsComponentsare literals, Mesa folds thePackHalf2x16at compile time (no f16 convert in the ISA) and rounds to nearest, so on mainConvertsComponentspasses with the old0xc0003c04andRoundsTowardZerogets e.g.0x3c013c04instead of0x3c003c03. With the PR all four pass and the rest of the suite is unchanged.@Nawid3333 on GitHub · 2026-10-18 04:15 UTC · original
I pushed one more commit, a test fix I had missed:
GpuSelectedFormattedRgba16Store(inCheckGpuSelectedFormattedRecordStore, part of the full test run) stores the same input0x3f807e63asBufferStoreFormatXyzwFloat16ConvertsComponentsand still expected the round-to-nearest half0x3c04. With this PR the store rounds toward zero, so it now expects0x3c03, likeConvertsComponents. My per-case test runner didn't cover that check before. On my RX 9070 XT and Ryzen 7600X iGPU it passes in both subgroup modes with this fix together with #1603; without #1603 it still fails there for a different reason, two words written past the end of the buffer, which #1603 fixes.Written with Claude Code (AI): it found the missed expectation and ran the check on my PC; I read this comment before posting it.
@NeySlim on GitHub · 2026-10-18 10:53 UTC · original
Checked on RADV against
37df7f32. With this PR alone the four tests pass andGpuSelectedFormattedRgba16Storenow gets the expected0xc0003c03, but it still fails because the record right after the range is written (0xc0003c03 0x34003800over the neighboring words), which is the #1595 issue. With #1603 merged on top it passes along with the four tests, and the rest of the suite matches #1603 alone.@ -544,3 +556,4 @@EmitF32BitsToF16RtzBits(state, data));}return data;}@coderabbitai[bot] on GitHub · 2026-10-28 19:27 UTC · original · edited 2026-10-28 19:50 UTC
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 3823
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 42883
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 32778
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 30963
Widen D16 float sources before encoding.
When a D16 formatted store uses a 16-bit float component,
datacontains raw f16 bits. The new 16-bit float branch runs before the existing f16-to-f32 conversion and passes those bits toEmitF32BitsToF16RtzBits, which interprets them as f32 bits. For example, f161.0(0x3c00) is treated as an f32 bit pattern and can encode as zero instead of0x3c00.Suggested fix
Committable suggestion
@coderabbitai[bot] on GitHub · 2026-10-28 19:27 UTC · original · reviewed
Actionable comments posted: 1
6ba9927f-433a-4ae9-bffc-42da8f518fb1Reviewing files that changed from the base of the PR and between
6697e56443andba079bbc70.src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemoryHelpers.cpptests/ShaderRecompilerComputeTests.cpptests/shaderCfgTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
@ -544,3 +556,4 @@EmitF32BitsToF16RtzBits(state, data));}return data;}@Nawid3333 on GitHub · 2026-10-28 19:50 UTC · original
D16 data is widened before this branch: the
if (data_bits == 16u)block above (line 495) turns 16-bit float data into f32 bits withEmitF16BitsToF32(line 501), and the 16-bit float branch (line 540) comes after it, as thePackHalf2x16branch did on main. SoEmitF32BitsToF16RtzBitsonly ever gets f32 bits here.BufferStoreFormatD16XFloat16andBufferStoreFormatD16HiXFloat16store f16 -2.0 (0xc000) through this path and pass with this change on the RX 9070 XT, with native and with 32-wide subgroups.@ -544,3 +556,4 @@EmitF32BitsToF16RtzBits(state, data));}return data;}@coderabbitai[bot] on GitHub · 2026-10-28 19:51 UTC · original
@Nawid3333 You are correct. I misread the branch order.
The supplied file confirms that
if (data_bits == 16u)widens float data withEmitF16BitsToF32before the 16-bit float encoding branch. Thus,EmitF32BitsToF16RtzBitsreceives f32 bits on this path.My suggested change would convert the data a second time and is incorrect. I withdraw this finding. No code change is needed.
✏️ Learnings added
✅ Review thread resolved.
You are interacting with an AI system.
Pull request closed