Recompiler: f32 to UNORM / SNORM conversions round twice instead of once #659
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl#659
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@acaracargo on GitHub · 2026-11-24 02:59 UTC · original
The f32-to-UNORM/SNORM conversions round the product to f32 before applying
round(). When the exact product is just below or above a halfway value and the multiplication rounds it to exactly halfway, the final result can be off by one.For example,
v_cvt_pknorm_u16_f32(2.2888533e-5)returns 2 instead of 1.A CPU search found 32,640 affected f32 inputs for UNORM16 and 16,128 for SNORM16 in [0, 1). #80 addressed the equivalent problem for f16 sources.
The same issue also occurs when packing typed buffer stores into UNORM/SNORM formats, including RGBA8.
A proposed fix uses integer arithmetic to multiply the significand by the scale and round only once, preserving the existing clamps and NaN handling.
Test results
The proposed fix and regression tests are available here:
https://github.com/acaracargo/xcl/tree/fork/pknorm-f32-exact
Latest tested commit:
0bca2d7.No retail game regression run is available on this machine, so I'm reporting this as an issue rather than opening a runtime PR. Console rounding behavior has not been independently verified.
AI use
Claude Code (Claude Opus 5.5) identified the issue, implemented the proposed fix and ran the tests. ChatGPT assisted with drafting this report.
@requiemsnkrp on GitHub · 2026-11-24 03:05 UTC · original
@acaracargo same offer as on #658: I have the retail title. If you open the PR from your branch, I'll make the two
scripts/smoke.ps1runs (your head commit and themainit is based on) and post thexcl-smokeblocks there for you to paste into Regression run.pr_check.pyreads them from the description.Written with Claude Code (Claude Opus 5.5).
@acaracargo on GitHub · 2026-11-24 03:09 UTC · original
Thanks, that would be really helpful! I'll open the PR after checking the current branch and let you know when it's ready for the smoke runs.
@requiemsnkrp
@NAbobo101 on GitHub · 2026-11-24 03:21 UTC · original
Independent check of the proposed fix on NVIDIA Blackwell with DXC 1.8:
acaracargo/xclfork/pknorm-f32-exactat0bca2d7bbb7715c3cad9d65d0301421452239930, tested as is (merges cleanly ontomaindd2ae9a). For the PR's own Regression run, the blocks requiemsnkrp offered are the ones to paste; these are only data points.Tested
x86_64-pc-windows-msvc; DXC 1.8.2502.11 (Windows SDK 10.0.26100); tests in debug, runs in release.cargo test --workspace --no-fail-fast -- --test-threads=4on0bca2d7: 686 passed, 0 failed, 41 ignored; SKIPPED (no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.gpu_pknorm_f32_rounds_onceandgpu_buffer_store_norm_formats_round_oncepass. Withemit.rsput back to9ce2070(tests kept) both fail: the buffer-store test on 54 cases (23 UNORM16, 13 SNORM16, 8 UNORM8, 10 SNORM8 – the same counts as on the RTX 4060 with DXC 1.9), the pknorm test on 15v_cvt_pknorm_u16_f32and 26v_cvt_pknorm_i16_f32results, e.g.v_cvt_pknorm_u16_f32(2.2888533e-5) = 0x00020002, want 0x00010001.scripts/smoke.ps1, 60 s, two runs each:maindd2ae9a1489 / 1519 frames, peak commit 14432 / 14416 MB;0bca2d71447 / 1467 frames (97 %), 14580 / 14575 MB; no crash and no device removal in any run.Not tested
v_cvt_pknorm_*_f32or norm-format typed buffer stores in the first 60 s: the runs show no regression, not an improvement.AI use
@acaracargo on GitHub · 2026-11-24 03:37 UTC · original
Thanks for the independent verification! Great to see the same 54 buffer-store failures reproduced on Blackwell with DXC 1.8, and that both regression tests pass with the fix. The retail smoke results are also very helpful.
@luckyteagirl on GitHub · 2026-11-24 05:59 UTC · original
Native RDNA2 packed-normal rounding check
I ran
v_cvt_pknorm_u16_f32andv_cvt_pknorm_i16_f32directly on a Radeon RX 6800M (gfx1031), Windows 11 build 26200, display driver30.0.13002.13003, and AMD OpenCL3302.6 (PAL,LC). The kernel supplied the same f32 input to both source operands and checked both destination halves. Four work-items per case agreed.I compared against CPU models that multiply the exact value of the input f32 by 65535 or 32767, then round to nearest even. The two-step model first rounds the product to f32. Hardware matched single rounding for all six distinct UNORM16 and seven distinct SNORM16 inputs where the models differed in this probe.
0x37C000C00x00010x00010x00020x3B0080810x00810x00810x00800x384001800x00010x00010x00020xBF00FE020xBF810xBF810xBF82At exactly
0.5, both instructions gave0x8000(UNORM16) or0x4000(SNORM16), consistent with ties to even.Not tested
Typed buffer stores, the proposed XCL patch, other GPUs, and console hardware.
AI use
OpenAI Codex (GPT-6 family, exact model variant unavailable) wrote and ran the probe and drafted this report.
@Kadthicu on GitHub · 2026-11-24 08:34 UTC · original
Could we add
-f32::from_bits(0x3840_0180)togpu_buffer_store_norm_formats_round_once? It covers a negative SNORM16 double-rounding case. The exact product rounds to-1(0xffff), while rounding the product to f32 first gives-1.5, which rounds to-2(0xfffe). Checked the diff and arithmetic with Codex (GPT-6). No GPU run.