Recompiler: f32 to UNORM / SNORM conversions round twice instead of once #654
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?
Imported from ivall/xcl. Originally posted by acaracargo on 2026-11-24T02:59:42Z.
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.
Imported from ivall/xcl. Originally posted by requiemsnkrp on 2026-11-24T03:05:40Z.
@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).
Imported from ivall/xcl. Originally posted by acaracargo on 2026-11-24T03:09:56Z.
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
Imported from ivall/xcl. Originally posted by NAbobo101 on 2026-11-24T03:21:48Z.
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
Imported from ivall/xcl. Originally posted by acaracargo on 2026-11-24T03:37:57Z.
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.
Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-24T05:59:34Z.
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.
Imported from ivall/xcl. Originally posted by Kadthicu on 2026-11-24T08:34:09Z.
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.upstream-sync referenced this issue2026-11-24 19:06:45 +00:00
upstream-sync referenced this issue2026-11-24 22:05:13 +00:00
Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-26T20:47:54Z.
Tested the requested negative halfway-adjacent case on RTX 5070 / driver 616.92, Ryzen 7 5700X3D, Windows build 26300.10075, Rust 1.100.0 MSVC debug, SDK DXC/DXIL 1.8.2502.11.
Used the proposed branch at
0bca2d7bbb7715c3cad9d65d0301421452239930, adding onlyxs.push(-f32::from_bits(0x3840_0180));togpu_buffer_store_norm_formats_round_once. With default translation and separate writable caches, rancargo test --locked -p xcl --lib gpu_buffer_store_norm_formats_round_once -- --test-threads=1 --nocapture.emit.rsfrom parentf4c03b5d666d6ad78f755dbba20762d8cb14c024with the identical extended fixture: test failed with 55 mismatches. The added input (0xb8400180) returned0xfffeinstead of0xffff; the other 54 mismatches were previously reported.The exact product is approximately -1.4999999986030161, so rounding to nearest gives -1. Not tested: the full suite, other GPUs, or a retail title.
AI use: OpenAI Codex with GPT-6.2 Astra ran the tests and reported results; Codex coordinated and prepared this summary.