Recompiler: round normalized buffer loads to nearest f32 #1830

Open
gloger2003 wants to merge 1 commit from upstream-pr/1840 into main
gloger2003 commented 2026-11-24 21:38:41 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gloger2003 on 2026-11-24T21:38:41Z.


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.
<!-- greyfinch-sync:ivall/xcl:issue:5480770910 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1840). Originally posted by [gloger2003](https://github.com/gloger2003) on 2026-11-24T21:38:41Z. --- 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.
upipibi commented 2026-11-24 23:08:34 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by upipibi on 2026-11-24T22:50:39Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7146709905 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1840#issuecomment-7146709905). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-24T22:50:39Z. --- 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.
DavidM1911 commented 2026-11-25 01:11:03 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T01:03:39Z.


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!

<!-- greyfinch-sync:ivall/xcl:comment:7149164941 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1840#issuecomment-7149164941). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T01:03:39Z. --- 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!
github-actions[bot] commented 2026-11-28 08:01:13 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-28T08:01:13Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7236308942 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1840#issuecomment-7236308942). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-28T08:01:13Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 06:57:12 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T06:57:12Z.


Triage (#1607) – head 41c88ea

No other PR changes how normalized buffer loads round.
#1423 (same issue #1414) also edits fmt_comp in emit.rs, but for the channels a format lacks, so the two will conflict without duplicating each other. #683 changes the f32 -> UNORM/SNORM conversion, the other direction.
No problems found in fmt_norm_f32 (HLSL and direct DXIL). It is used only when the destination is f32; D16 loads keep the old division.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7303473616 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1840#issuecomment-7303473616). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T06:57:12Z. --- **Triage (#1607)** – head 41c88ea No other PR changes how normalized buffer loads round. #1423 (same issue #1414) also edits `fmt_comp` in `emit.rs`, but for the channels a format lacks, so the two will conflict without duplicating each other. #683 changes the f32 -> UNORM/SNORM conversion, the other direction. No problems found in `fmt_norm_f32` (HLSL and direct DXIL). It is used only when the destination is f32; D16 loads keep the old division. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1840:upstream-pr/1840'
git switch 'upstream-pr/1840'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/1840'
git switch 'upstream-pr/1840'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1840'
git switch 'upstream-pr/1840'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1840'
git switch 'main'
git merge --squash 'upstream-pr/1840'
git switch 'main'
git merge --ff-only 'upstream-pr/1840'
git switch 'main'
git merge 'upstream-pr/1840'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!1830
No description provided.