Recompiler: round normalized D16 buffer loads exactly #2360

Closed
github-bot wants to merge 2 commits from gh-pr/2360/head into gh-pr/2360/base
Owner

@⁠mokkamokacaffe on GitHub · 2026-11-25 16:31 UTC · original
mokkamokacaffe:recomp/d16-normalized-buffer-rounding → main · +241 −13 · 2 files · 2 commits · closed without merging

Part of #2026.

D16 typed-buffer loads currently decode UNORM/SNORM source codes to binary32 and then use f32tof16. The intermediate binary32 rounding makes roughly half of the normalized codes one binary16 ULP too low. Convert the original integer code directly to binary16 so it is rounded once, to nearest-even.

This is the first split proposed in #2026. Image reads remain a separate follow-up.

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs: emit an integer-only normalized-code-to-binary16 conversion for HLSL buffer_load_format_d16_* and tbuffer_load_format_d16_* operations.
  • Avoid the HLSL-reserved snorm identifier in the generated helper; independent DXC runs on the original head exposed this as the cause of the broad shader-compilation failures.
  • crates/xcl/src/gpu/dxil/lower_mem.rs: emit the same conversion directly in DXIL while preserving destination selection, integer formats and hi_x behavior.
  • Add exhaustive CPU coverage for UNORM and SNORM widths 2, 7, 8, 10, 11, 15 and 16, including zero, signed saturation and binary16 normal/subnormal boundaries.

Tested

  • Linux x86-64, Rust 1.100.0, compile-only cross-check against x86_64-pc-windows-msvc:
    • cargo check -p xcl --lib --target x86_64-pc-windows-msvc: passed.
    • cargo check -p xcl --tests --target x86_64-pc-windows-msvc: passed.
    • A local lib.exe-compatible archive wrapper was used only to let the Windows-only libudis86-sys build script complete; no Windows binary was linked or run.
  • Independent exhaustive arithmetic harness: 203,528 UNORM/SNORM code-and-width cases matched a binary64 nearest-even reference, 0 mismatches.
  • git diff --check origin/main...HEAD: passed.
  • Rebased onto main at e1d84b7; the conflict in emit.rs retained both this PR's exhaustive D16 test and main's newer RLA shader tests.
  • Clean post-merge diff against main: only crates/xcl/src/gpu/recomp/emit.rs and crates/xcl/src/gpu/dxil/lower_mem.rs, 241 additions and 13 deletions; git diff --check origin/main...HEAD passed at 62ff8aed9394.

Regression run

main:

Pending: requires Windows, a D3D12 GPU and a real-title installation.

this PR:

Pending on clean head 62ff8aed9394: requires Windows, a D3D12 GPU and the same title and duration as the main run.

Not tested

  • The repository tests on Windows; the added Rust test was compiled but not executed here.
  • Post-fix HLSL compilation and Direct-DXIL validation with the Windows SDK. Independent tests of the previous head found that the generated HLSL used reserved identifier snorm; this is renamed to signed_norm at the current head and needs a clean rerun.
  • GPU output parity on AMD or NVIDIA hardware.
  • Paired scripts/smoke.ps1 retail-title runs.
  • D16 normalized image reads; those remain the second split of #2026.

AI use

  • OpenAI Codex (GPT-5) inspected #2026 and both buffer-format lowering paths, implemented the integer conversion and exhaustive regression test, performed the compile and arithmetic checks, reviewed the diff, and drafted this description.
**@⁠mokkamokacaffe** on GitHub · 2026-11-25 16:31 UTC · [original](https://github.com/xcl-dev/xcl/pull/2360) `mokkamokacaffe:recomp/d16-normalized-buffer-rounding` → `main` · +241 −13 · 2 files · 2 commits · closed without merging Part of #2026. D16 typed-buffer loads currently decode UNORM/SNORM source codes to binary32 and then use `f32tof16`. The intermediate binary32 rounding makes roughly half of the normalized codes one binary16 ULP too low. Convert the original integer code directly to binary16 so it is rounded once, to nearest-even. This is the first split proposed in #2026. Image reads remain a separate follow-up. **What is in it** - `crates/xcl/src/gpu/recomp/emit.rs`: emit an integer-only normalized-code-to-binary16 conversion for HLSL `buffer_load_format_d16_*` and `tbuffer_load_format_d16_*` operations. - Avoid the HLSL-reserved `snorm` identifier in the generated helper; independent DXC runs on the original head exposed this as the cause of the broad shader-compilation failures. - `crates/xcl/src/gpu/dxil/lower_mem.rs`: emit the same conversion directly in DXIL while preserving destination selection, integer formats and `hi_x` behavior. - Add exhaustive CPU coverage for UNORM and SNORM widths 2, 7, 8, 10, 11, 15 and 16, including zero, signed saturation and binary16 normal/subnormal boundaries. **Tested** - Linux x86-64, Rust 1.100.0, compile-only cross-check against `x86_64-pc-windows-msvc`: - `cargo check -p xcl --lib --target x86_64-pc-windows-msvc`: passed. - `cargo check -p xcl --tests --target x86_64-pc-windows-msvc`: passed. - A local `lib.exe`-compatible archive wrapper was used only to let the Windows-only `libudis86-sys` build script complete; no Windows binary was linked or run. - Independent exhaustive arithmetic harness: 203,528 UNORM/SNORM code-and-width cases matched a binary64 nearest-even reference, 0 mismatches. - `git diff --check origin/main...HEAD`: passed. - Rebased onto `main` at `e1d84b7`; the conflict in `emit.rs` retained both this PR's exhaustive D16 test and `main`'s newer RLA shader tests. - Clean post-merge diff against `main`: only `crates/xcl/src/gpu/recomp/emit.rs` and `crates/xcl/src/gpu/dxil/lower_mem.rs`, **241 additions and 13 deletions**; `git diff --check origin/main...HEAD` passed at `62ff8aed9394`. **Regression run** main: Pending: requires Windows, a D3D12 GPU and a real-title installation. this PR: Pending on clean head `62ff8aed9394`: requires Windows, a D3D12 GPU and the same title and duration as the main run. **Not tested** - The repository tests on Windows; the added Rust test was compiled but not executed here. - Post-fix HLSL compilation and Direct-DXIL validation with the Windows SDK. Independent tests of the previous head found that the generated HLSL used reserved identifier `snorm`; this is renamed to `signed_norm` at the current head and needs a clean rerun. - GPU output parity on AMD or NVIDIA hardware. - Paired `scripts/smoke.ps1` retail-title runs. - D16 normalized image reads; those remain the second split of #2026. **AI use** - OpenAI Codex (GPT-5) inspected #2026 and both buffer-format lowering paths, implemented the integer conversion and exhaustive regression test, performed the compile and arithmetic checks, reviewed the diff, and drafted this description.
Convert UNORM and SNORM source codes directly to binary16 so the intermediate binary32 decode cannot double-round the result. Cover every supported normalized code width exhaustively.

Part of #2026

Assisted-by: OpenAI Codex (GPT-5)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:28:52 +00:00
github-bot closed this pull request 2026-11-26 05:28:52 +00:00
Author
Owner

@⁠FIJI1299 on GitHub · 2026-11-25 17:33 UTC · original

Tested commit <647932f> on Windows with an NVIDIA GPU (wave32):

Environment

  • OS: Windows 11
  • GPU: NVIDIA GeForce RTX 5070 (12 GB VRAM, driver 621.35, wave32 only — no native wave64)
  • DXC: 1.8.2502.11 (Windows SDK 10.0.26100.0)

Results

  • Full library test suite (cargo test -p xcl --lib): 1060 passed, 147 failed, 26 ignored (including gpu::recomp::tests::buffer_format_d16_packs_and_unpacks_halves).
  • GPU tests skipped on this adapter: 4 (no wave64), 1 (cannot disable the driver cache (Windows Developer Mode is required): 0x887A002D).

Note

This branch appears to predate the wave32 / split-wave64 updates on main (current main skips 13 no wave64 tests on this adapter instead of 4), causing 124 tests in gpu::recomp::tests to fail on wave32-only NVIDIA hardware. Rebasing onto current main should allow re-testing on this GPU.

**@⁠FIJI1299** on GitHub · 2026-11-25 17:33 UTC · [original](https://github.com/xcl-dev/xcl/pull/2360#issuecomment-7169684344) Tested commit `<647932f>` on Windows with an NVIDIA GPU (`wave32`): ### Environment * **OS:** Windows 11 * **GPU:** NVIDIA GeForce RTX 5070 (12 GB VRAM, driver `621.35`, `wave32` only — no native `wave64`) * **DXC:** `1.8.2502.11` (Windows SDK `10.0.26100.0`) ### Results * **Full library test suite (`cargo test -p xcl --lib`):** **1060 passed, 147 failed, 26 ignored** (including `gpu::recomp::tests::buffer_format_d16_packs_and_unpacks_halves`). * **GPU tests skipped on this adapter:** `4 (no wave64)`, `1 (cannot disable the driver cache (Windows Developer Mode is required): 0x887A002D)`. ### Note This branch appears to predate the `wave32` / split-wave64 updates on `main` (current `main` skips 13 `no wave64` tests on this adapter instead of 4), causing 124 tests in `gpu::recomp::tests` to fail on `wave32`-only NVIDIA hardware. Rebasing onto current `main` should allow re-testing on this GPU.
Author
Owner

@⁠throny on GitHub · 2026-11-25 18:29 UTC · original

Two contributors checked independently and found that #2027 solves the same problem (for #2026) in a different way: #1607, group D102. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.

This is a hint from the community triage in #1607, not a maintainer decision.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

**@⁠throny** on GitHub · 2026-11-25 18:29 UTC · [original](https://github.com/xcl-dev/xcl/pull/2360#issuecomment-7170973961) <!-- xcl-1607-hint:D102 --> Two contributors checked independently and found that #2027 solves the same problem (for #2026) in a different way: #1607, group D102. You may want to compare them with the other author and agree on one, or say in the PR why both are needed. This is a hint from the community triage in #1607, not a maintainer decision. AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.
Author
Owner

@⁠SlopTart on GitHub · 2026-11-25 18:40 UTC · original

Tested: current PR head 647932fc merged onto current origin/main (clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo target x86_64-pc-windows-gnu run under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29, 1.9.2609.5 (01b62ad47)).

One red across the whole lane, and the cause is visible in every failure. The gpu_ suite at this head gives 40 passed; 108 failed with a cold shader cache (deterministic at --test-threads=1 and --test-threads=2). 106 of the failures print the same DXC compile error in the generated prelude:

dxc: hlsl.hlsl:437:47: error: modifiers must appear before type
uint norm_code_to_f16(uint code, uint w, bool snorm) {
                                              ^
dxc: hlsl.hlsl:439:29: error: expected expression
    uint period = w - (uint)snorm;

snorm is a reserved HLSL modifier keyword, so this pinned DXC refuses the parameter name. The helper sits in the shared translator prelude, so every program that embeds the prelude fails to compile, which is why the failure count is a large fraction of the suite rather than one test.

Standalone repro against the same pinned dxc.exe (extracted from the 2026-09-29 zip), no XCL involved:

uint norm_code_to_f16(uint code, uint w, bool snorm) {
    uint period = w - (uint)snorm;
    return period;
}

gives error: modifiers must appear before type at column 47 plus error: expected expression on (uint)snorm.

Observations around the new tests themselves:

  • targeted run of the new D16 tests at this head with a cold cache: 1 passed (that path does not compile the HLSL prelude), and the new D16 tests are not among the 106 failures.
  • an earlier run I left with a warm cache showed only 41 failures, so the pass count depends on how much compiled DXIL is still cached; the cold-cache number (108 failed) is the clean signal.

Renaming the parameter (anything that is not a modifier keyword) would restore the prelude compiles. The exact rounding behaviour of the change could not be judged on this lane because the HLSL backend does not compile at this head.

Not tested: retail titles (no title data on this lane, counts only). The post-rename rounding behaviour itself.

AI use: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.

**@⁠SlopTart** on GitHub · 2026-11-25 18:40 UTC · [original](https://github.com/xcl-dev/xcl/pull/2360#issuecomment-7171245773) **Tested**: current PR head `647932fc` merged onto current `origin/main` (clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo target `x86_64-pc-windows-gnu` run under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29, `1.9.2609.5 (01b62ad47)`). **One red across the whole lane, and the cause is visible in every failure.** The `gpu_` suite at this head gives `40 passed; 108 failed` with a cold shader cache (deterministic at `--test-threads=1` and `--test-threads=2`). 106 of the failures print the same DXC compile error in the generated prelude: ``` dxc: hlsl.hlsl:437:47: error: modifiers must appear before type uint norm_code_to_f16(uint code, uint w, bool snorm) { ^ dxc: hlsl.hlsl:439:29: error: expected expression uint period = w - (uint)snorm; ``` `snorm` is a reserved HLSL modifier keyword, so this pinned DXC refuses the parameter name. The helper sits in the shared translator prelude, so every program that embeds the prelude fails to compile, which is why the failure count is a large fraction of the suite rather than one test. Standalone repro against the same pinned `dxc.exe` (extracted from the 2026-09-29 zip), no XCL involved: ``` uint norm_code_to_f16(uint code, uint w, bool snorm) { uint period = w - (uint)snorm; return period; } ``` gives `error: modifiers must appear before type` at column 47 plus `error: expected expression` on `(uint)snorm`. Observations around the new tests themselves: - targeted run of the new D16 tests at this head with a cold cache: `1 passed` (that path does not compile the HLSL prelude), and the new D16 tests are not among the 106 failures. - an earlier run I left with a warm cache showed only 41 failures, so the pass count depends on how much compiled DXIL is still cached; the cold-cache number (108 failed) is the clean signal. Renaming the parameter (anything that is not a modifier keyword) would restore the prelude compiles. The exact rounding behaviour of the change could not be judged on this lane because the HLSL backend does not compile at this head. **Not tested**: retail titles (no title data on this lane, counts only). The post-rename rounding behaviour itself. **AI use**: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 18:56 UTC · original

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

  • cargo test -p xcl --lib: 143 real failures, deterministic (also fail --test-threads=1, 1064/143):

Every DXC compile of the generated HLSL prelude fails:

dxc: hlsl.hlsl:437:47: error: modifiers must appear before type
uint norm_code_to_f16(uint code, uint w, bool snorm) {
                                              ^
hlsl.hlsl:439:29: error: expected expression
    uint period = w - (uint)snorm;
hlsl.hlsl:440:25: error: expected expression
    bool negative = and(snorm, (code & (1u << (w - 1u))) != 0u);

The parameter name snorm collides with the HLSL snorm texture modifier keyword — rename it (e.g. signed_norm) and the whole suite should recover. Serious breakage, needs a fix before merge.

— Devin

**@⁠DavidM1911** on GitHub · 2026-11-25 18:56 UTC · [original](https://github.com/xcl-dev/xcl/pull/2360#issuecomment-7171604291) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: **143 real failures**, deterministic (also fail `--test-threads=1`, 1064/143): Every DXC compile of the generated HLSL prelude fails: ``` dxc: hlsl.hlsl:437:47: error: modifiers must appear before type uint norm_code_to_f16(uint code, uint w, bool snorm) { ^ hlsl.hlsl:439:29: error: expected expression uint period = w - (uint)snorm; hlsl.hlsl:440:25: error: expected expression bool negative = and(snorm, (code & (1u << (w - 1u))) != 0u); ``` The parameter name `snorm` collides with the HLSL `snorm` texture modifier keyword — rename it (e.g. `signed_norm`) and the whole suite should recover. Serious breakage, needs a fix before merge. — Devin
Author
Owner

@⁠mokkamokacaffe on GitHub · 2026-11-25 23:14 UTC · original

The updated head 62ff8aed resolves the merge conflict and the generated-HLSL failure by renaming the reserved snorm parameter to signed_norm.

After comparing this with #2027 and the RDNA2 measurements linked there, #2027 is the more complete implementation. Both PRs produce the intended single-rounding result for UNORM/SNORM codes, while #2027 also applies the measured truncation behavior to the other non-integer D16 channels and has GPU coverage for both the HLSL and Direct DXIL paths, exact-head NVIDIA validation, and paired smoke runs.

Closing this PR in favor of #2027 so testing and review remain focused there.

**@⁠mokkamokacaffe** on GitHub · 2026-11-25 23:14 UTC · [original](https://github.com/xcl-dev/xcl/pull/2360#issuecomment-7177304724) The updated head `62ff8aed` resolves the merge conflict and the generated-HLSL failure by renaming the reserved `snorm` parameter to `signed_norm`. After comparing this with #2027 and the RDNA2 measurements linked there, #2027 is the more complete implementation. Both PRs produce the intended single-rounding result for UNORM/SNORM codes, while #2027 also applies the measured truncation behavior to the other non-integer D16 channels and has GPU coverage for both the HLSL and Direct DXIL paths, exact-head NVIDIA validation, and paired smoke runs. Closing this PR in favor of #2027 so testing and review remain focused there.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 08:15 UTC · original

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: 1 failure under parallel scheduling; clean on --test-threads=1 rerun (1312 passed, 0 failed, 27 ignored, 82s). Intermittent single-test flake — tracked in #1978.

Thanks!

— Devin

**@⁠DavidM1911** on GitHub · 2026-11-26 08:15 UTC · [original](https://github.com/xcl-dev/xcl/pull/2360#issuecomment-7186379335) Re-verification on RTX 3060 Ti (Windows 11), new head merged with current `main`: - `cargo test -p xcl --lib`: 1 failure under parallel scheduling; clean on `--test-threads=1` rerun (**1312 passed, 0 failed, 27 ignored**, 82s). Intermittent single-test flake — tracked in #1978. Thanks! — Devin

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.