Recompiler: round normalized f32 conversions once (#659) #678
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/683"
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 ilyaux on 2026-11-24T03:27:55Z.
Fixes #659. Avoid rounding an FP32 product to a halfway value before converting it to UNORM/SNORM.
The runtime fix and first two regression tests are @acaracargo's existing proposal, carried from f4c03b5 and 0bca2d7. This PR adds independent packed-format coverage and native Windows validation. acaracargo is credited as a co-author in the commit.
What is in it
emit.rs: round the significand/scale product once with integer arithmetic, preserving clamps and NaN handling.tests.rs: the original two regressions plus eight packed UNORM/SNORM formats, with 64 boundary/edge vectors and different values per channel.Tested
Head:
02fd1b03c357e5cb4457ca56fd343202de1d3736(clean tree), based onmain91f9a5e9f03156ea82dc55a18f7704862da7a5db. Windows 11 Home 26300, Ryzen AI 7 350, Rust 1.98.1 MSVC, debug, DXC/DXIL 1.8.2502.11.XCL_ADAPTER=nvidia:cargo build --workspace --locked;cargo test --workspace --no-fail-fast --locked -- --test-threads=4:695 passed, 0 failed, 41 ignored. Two
SKIPPED: no wave64tests are included in that passed count:gpu_geometry_wave32_prefix_count_over_a_maskandgpu_wave32_program_in_wave64_hardware. All three normalization regressions and the synthetic-title end-to-end test ran and passed.XCL_ADAPTER=radeon,XCL_REQUIRE_GPU=wave64:cargo test -p xcl --lib gpu_pknorm_f32_rounds_once -- --nocapture;cargo test -p xcl --lib norm_formats_round_once -- --nocapture;cargo test -p xcl --lib gpu_wave32_program_in_wave64_hardware -- --nocapture:3 normalization tests + 1 wave64 control passed, 0 failed/ignored/skipped.
maindd2ae9a, keeping tests but removing the runtime fix: 41 pknorm and 54 typed-store mismatches. The added packed-format test also fails (11_11_10_UNORM, got 6291458, expected 6291457).git diff --checkpassed.Regression run
Pending: matched
scripts/smoke.ps1runs on main and this PR's clean head. No complete retail title was available locally, so no smoke blocks were generated. Keeping this PR draft until that validation is available.Not tested
Retail gameplay/performance, real console rounding, Intel GPUs, and the full suite on AMD.
XCL_SAMPLE_*was unset, so opt-in real-game-data paths were not exercised.AI use
Imported from ivall/xcl. Originally posted by acaracargo on 2026-11-24T04:04:37Z.
Thanks for extending my fix and for the attribution! I was actually preparing to open the original branch as a draft PR.
I've also completed local retail regression runs, and @requiemsnkrp offered independent smoke testing on #659.
Let's coordinate so we don't end up with duplicate PRs. I'm happy to help validate this version and get the fix merged.
Imported from ivall/xcl. Originally posted by ItsMrDubey on 2026-11-24T04:57:29Z.
Test report for
02fd1b03c357e5cb4457ca56fd343202de1d3736(this PR's head)Tested
stable-x86_64-pc-windows-msvc), debug; DXC 1.9.2602.17 from Windows SDK 10.0.2610016 test binaries: 694 passed, 1 failed, 41 ignored. Same machine,
main64b3f3559: 700 passed, 1 failed, 41 ignored.This PR's tests:
gpu::recomp::tests::gpu_buffer_store_norm_formats_round_once: okgpu::recomp::tests::gpu_pknorm_f32_rounds_once: okgpu::recomp::tests::gpu_packed_norm_formats_round_once: okFailures:
hle::kernelx::tests::xmem_virtual_query_marks_cpu_readable_memoryfails on this machine on every run, on this PR's head and onmain64b3f3559alike (5 of 5 reruns onmain), so it is not from this PR. #650 fixes it here.16 test binaries instead of
main's 17 because this branch predatestests/sparse_reinit.rs; nothing crashed.SKIPPED (no wave64 on this GPU):
gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.AI use: Claude Code (Claude Opus 5.5) ran the builds and tests and wrote this report from their output.
Imported from ivall/xcl. Originally posted by Anon64 on 2026-11-24T06:43:12Z.
Regression runs for this PR's head
02fd1b0and for its basemain91f9a5e, on a retail title (same title, 60 s each), made withscripts/smoke.ps1(release, clean tree at each commit) and pasted unedited, for Regression run.main:
this PR:
Tested
Not tested
Report written with Claude Code (Claude Opus 5.5) from runs on this machine.
Imported from ivall/xcl. Originally posted by KENAJBBY on 2026-11-24T09:31:09Z.
Native RDNA2 (
gfx1036): every double-rounding input, and no MODE dependenceThis extends @luckyteagirl's 13-input native check on #659 to the whole problem set. I ran
v_cvt_pknorm_u16_f32andv_cvt_pknorm_i16_f32on raw f32 bits on an RDNA2 GPU. The inputs were every f32 in (0, 1) whose binary32 product with the scale is exactly k + 0.5: 65,536 inputs for 65535 and 32,768 for 32767, each also negated for SNORM16. On top of that came 20,000 random bit patterns and 26 special values. Both halves were checked, withsrc0andsrc1holding different inputs.main'sround(f * scale)(CPU model)v_cvt_pknorm_u16_f32v_cvt_pknorm_i16_f32The result was 0 in each of 11 MODE values: f32 round RNE / +inf / −inf / RTZ, f32 and f16 denormals flushed or kept, DX10_CLAMP 0/1 and IEEE 0/1. Each mode was set with
s_setreg_b32and read back withs_getreg_b32. The round mode does not apply here: these conversions always round to nearest even.The special inputs give the same result in all 1024 values of MODE[9:0], and every one matches this PR's helpers:
0x00000001,0x80000001,0x007FFFFF),0x00800000, 2^-170x00000x00000x3F7FFFFF0xFFFF0x7FFF0xBF7FFFFF0x00000x80010x7F8000110x00000x00000x8000/0x00000x4000/0xC0000x37C000C0(#659's example)0x00010x00010x38400180/0xB84001800x0003/0x00000x0001/0xFFFF@Kadthicu's negative SNORM16 case on #659,
-0x38400180, gives0xFFFF(−1) on the hardware, as they computed. So it is a valid vector forgpu_buffer_store_norm_formats_round_once, if the store path rounds like the ALU instruction (not measured, see below).Tested
gfx1036, RDNA2), driver 32.0.21030.2001, AMD OpenCL3652.0 (PAL,LC), native wave64; Windows 11 Pro 26200.s_setreg_b32 hwreg(HW_REG_MODE, 0, 10), reads it back withs_getreg_b32(checked against the requested value in every run), runs the instruction and restores MODE. Reference: this PR'scvt_norm_u16_f32/cvt_norm_i16_f32transcribed to Python with exact rational arithmetic.Not tested
buffer_store_format_*) and the f16-sourcev_cvt_pknorm_*_f16on the hardware.AI use
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T12:06:19Z.
Verification on RTX 3060 Ti (Windows 11): merge conflict with current
main— needs a rebase before it can be tested.Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-29T07:42:18Z.
Nothing has happened on this PR for 3 days, so it is marked
staleand will be closed in 4 days. A push or a comment takes the mark off: rebase it ontomainif it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T03:56:39Z.
Triage (#1607) – head
02fd1b0No open or merged PR rounds the f32 -> UNORM/SNORM encodes once. #1840 (normalized buffer loads to f32) and #2030 (D16 image reads) cover the decode direction, so they do not overlap with
fmt_encode/v_cvt_pknorm_*_f32here.The diff looks correct:
norm_f32_magrounds the exact 24x32-bit product to nearest even, and the GPU tests compare against a reference. Rebase note: main'sfmt_encodehas changed since this branch was cut.fc5a8efmade a 2-bit SNORM component round a half away from zero, and this PR's SNORM path (norm_f32_mag, nearest even) would drop that rule if the conflict is resolved by taking this side.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by Kadthicu on 2026-12-01T05:19:40Z.
I rebased PR #683 onto main (
d0832e6) and tested local commit 1b24f22 on Windows 11 with an RTX 3060 12 GB. The commit has not been pushed yet.The rebase preserves half-away-from-zero rounding for 2-bit SNORM and rounds the exact product once, ties to even, for the other normalized FP32 conversions. All four targeted GPU tests passed on both HLSL and direct DXIL. The workspace build passed. The full suite reported 2,892 passed, 1 failed, and 51 ignored, with 29 skip messages. The sole failure, console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk, also reproduced on clean main.
Both 60-second smoke runs completed without crashes or GPU device removals. main: 1,003 frames, 15,970 MB peak commit. Local rebased commit: 935 frames, 15,893 MB peak commit.
AI use: OpenAI Codex assisted with the rebase, implementation, and test runs.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.