Recompiler: round normalized buffer loads to nearest f32 #1840

Open
github-bot wants to merge 1 commit from github-bot/gh-1840 into main AGit
Owner

@⁠gloger2003 on GitHub · 2026-11-24 21:38 UTC · original
gloger2003:fix/normalized-buffer-load-rounding → main · +223 −32 · 3 files · 1 commits · draft

Part of #1414. Normalized buffer loads with f32 output now construct the rounded UNORM or SNORM result from the repeating binary expansion of the component magnitude. The conversion uses the leading 24 significant bits and the rounding bit. The odd denominator rules out a midpoint for interior values.

What is in it

  • emit.rs and lower_mem.rs implement the same integer rounding in HLSL/DXC and direct DXIL, including the two-bit fractions and the signed lower clamp.
  • tests.rs checks representative values for the 20 normalized layouts and all 256 UNORM8 input values. This commit consolidates the earlier UNORM8 fix and the remaining formats.

Tested

  • Radeon RX 7800 XT (driver 32.0.32029.2010), Ryzen 7 5700X, Windows 11 build 26300.9974, Rust 1.100.0 MSVC, DXC 1.9.2602.17. Debug tests and release title runs.
  • On the earlier UNORM8 candidate dd16cc6, the expanded GPU test reported 163 differences in 17 formats in each backend. On this commit, gpu_normalized_buffer_formats_round_to_nearest_f32 and gpu_typed_buffer passed in each backend with XCL_DIRECT_DXIL=0 and =1.
  • An independent integer-rational check matched the algorithm to nearest-even f32 for all 137,736 unsigned and signed raw inputs across supported component widths.
  • cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 --show-output: 893 passed, 0 failed, 42 ignored. The heap-window fallback test skipped in the default suite and passed separately with heap windows enabled.

Regression run
Minecraft Preview. Both release runs used the same 1x MSAA profile.

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: AMD Radeon RX 7800 XT
title: Xbox-Series-1.18.3064.0
seconds: 30
exit: 0x0
frames shown: 1629 (PresentX 1629)
presents per 2 s (last 3): 120 120 120
device removals: 0
crashes: 0
peak commit: 3379 MB
xcl-smoke v1
commit: 41c88ea1bd746be4d063395b0a2fd171d90ebbb3
gpu: AMD Radeon RX 7800 XT
title: Xbox-Series-1.18.3064.0
seconds: 30
exit: 0x0
frames shown: 1584 (PresentX 1584)
presents per 2 s (last 3): 120 120 120
device removals: 0
crashes: 0
peak commit: 3391 MB

Not tested

  • Other graphics adapters and titles. The game comparison covers startup and menu rendering.

AI use

  • OpenAI Codex (GPT-6.2 Sol, high reasoning effort, Fast mode) drafted and reviewed the rounding algorithm, wrote the change and tests, ran validation, and drafted this description.
**@⁠gloger2003** on GitHub · 2026-11-24 21:38 UTC · [original](https://github.com/xcl-dev/xcl/pull/1840) `gloger2003:fix/normalized-buffer-load-rounding` → `main` · +223 −32 · 3 files · 1 commits · draft Part of #1414. Normalized buffer loads with f32 output now construct the rounded UNORM or SNORM result from the repeating binary expansion of the component magnitude. The conversion uses the leading 24 significant bits and the rounding bit. The odd denominator rules out a midpoint for interior values. **What is in it** - `emit.rs` and `lower_mem.rs` implement the same integer rounding in HLSL/DXC and direct DXIL, including the two-bit fractions and the signed lower clamp. - `tests.rs` checks representative values for the 20 normalized layouts and all 256 UNORM8 input values. This commit consolidates the earlier UNORM8 fix and the remaining formats. **Tested** - Radeon RX 7800 XT (driver 32.0.32029.2010), Ryzen 7 5700X, Windows 11 build 26300.9974, Rust 1.100.0 MSVC, DXC 1.9.2602.17. Debug tests and release title runs. - On the earlier UNORM8 candidate `dd16cc6`, the expanded GPU test reported 163 differences in 17 formats in each backend. On this commit, `gpu_normalized_buffer_formats_round_to_nearest_f32` and `gpu_typed_buffer` passed in each backend with `XCL_DIRECT_DXIL=0` and `=1`. - An independent integer-rational check matched the algorithm to nearest-even f32 for all 137,736 unsigned and signed raw inputs across supported component widths. - `cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 --show-output`: 893 passed, 0 failed, 42 ignored. The heap-window fallback test skipped in the default suite and passed separately with heap windows enabled. **Regression run** Minecraft Preview. Both release runs used the same 1x MSAA profile. ``` xcl-smoke v1 commit: 4178e888c0b5be50a2887eda45cdb832763b68a4 gpu: AMD Radeon RX 7800 XT title: Xbox-Series-1.18.3064.0 seconds: 30 exit: 0x0 frames shown: 1629 (PresentX 1629) presents per 2 s (last 3): 120 120 120 device removals: 0 crashes: 0 peak commit: 3379 MB ``` ``` xcl-smoke v1 commit: 41c88ea1bd746be4d063395b0a2fd171d90ebbb3 gpu: AMD Radeon RX 7800 XT title: Xbox-Series-1.18.3064.0 seconds: 30 exit: 0x0 frames shown: 1584 (PresentX 1584) presents per 2 s (last 3): 120 120 120 device removals: 0 crashes: 0 peak commit: 3391 MB ``` **Not tested** - Other graphics adapters and titles. The game comparison covers startup and menu rendering. **AI use** - OpenAI Codex (GPT-6.2 Sol, high reasoning effort, Fast mode) drafted and reviewed the rounding algorithm, wrote the change and tests, ran validation, and drafted this description.
Form the correctly rounded float bits from the repeating binary expansion of each UNORM or SNORM magnitude. Handle the 2-bit fractions and signed endpoints explicitly. GPU tests cover all 20 normalized formats and every UNORM8 value.

Part of #1414

Assisted-by: OpenAI Codex (GPT-6.2 Sol)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:06:56 +00:00
Author
Owner

@⁠upipibi on GitHub · 2026-11-24 22:50 UTC · original

NVIDIA run: RTX 3070 8 GB, driver 616.56, Windows 11, debug, 41c88ea merged onto main 689f2db (clean).

  • gpu_typed_buffer_unorm8_rounds_to_nearest and gpu_normalized_buffer_formats_round_to_nearest_f32: pass, with and without XCL_DIRECT_DXIL=1.
  • Tests matching buffer / format: 43 passed, 0 failed.

AI-assisted (Claude Code). Synthetic tests only.

**@⁠upipibi** on GitHub · 2026-11-24 22:50 UTC · [original](https://github.com/xcl-dev/xcl/pull/1840#issuecomment-7146709905) NVIDIA run: RTX 3070 8 GB, driver 616.56, Windows 11, debug, `41c88ea` merged onto `main` `689f2db` (clean). - `gpu_typed_buffer_unorm8_rounds_to_nearest` and `gpu_normalized_buffer_formats_round_to_nearest_f32`: pass, with and without `XCL_DIRECT_DXIL=1`. - Tests matching `buffer` / `format`: 43 passed, 0 failed. AI-assisted (Claude Code). Synthetic tests only.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 01:03 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~23 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 01:03 UTC · [original](https://github.com/xcl-dev/xcl/pull/1840#issuecomment-7149164941) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~23 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1840/head:github-bot/gh-1840'
git switch 'github-bot/gh-1840'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1840'
git switch 'github-bot/gh-1840'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1840'
git switch 'github-bot/gh-1840'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1840'
git switch 'main'
git merge --squash 'github-bot/gh-1840'
git switch 'main'
git merge --ff-only 'github-bot/gh-1840'
git switch 'main'
git merge 'github-bot/gh-1840'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.