Recompiler: clamp out-of-range format codes to INVALID instead of format 77 (#1488) #2336

Closed
github-bot wants to merge 1 commit from gh-pr/2336/head into gh-pr/2336/base
Owner

@⁠slopgobblercobbler on GitHub · 2026-11-25 15:23 UTC · original
slopgobblercobbler:fix/recomp-fmt-info-bounds → main · +32 −2 · 2 files · 1 commits · closed without merging

Resolves XCL-BT-010 in #1488.

What is in it

  • In crates/xcl/src/gpu/recomp/emit.rs (both BufKind::FormatLoad and BufKind::FormatStore):
    • Replaced FMT_INFO[min({fmt}, 77u)] with ({fmt} <= 77u) ? FMT_INFO[{fmt}] : 0u;.
    • Out-of-range 7-bit unified buffer format codes (78..127) now evaluate to 0u (INVALID), turning out-of-range format loads into 0 and stores into no-ops instead of decoding as format 77 (32_32_32_32_FLOAT).
  • In crates/xcl/src/gpu/recomp/tests.rs:
    • Added format_codes_above_77_evaluate_to_invalid testing both HLSL emission and GPU execution with format code 80 in both V# descriptor and MTBUF format immediate.

Tested

  • cargo test -p xcl -- recomp (195 passed, 0 failed, 18 ignored)
  • git diff --check upstream/main..HEAD clean with zero trailing whitespace
  • python -I scripts/check_no_game_data.py crates/xcl/src/gpu/recomp/emit.rs crates/xcl/src/gpu/recomp/tests.rs confirmed clean

Not tested

  • Retail game package execution (retail smoke suite)

AI use

  • Patch implementation and synthetic unit test authored using Gemini 3.8 Flash (High).
**@⁠slopgobblercobbler** on GitHub · 2026-11-25 15:23 UTC · [original](https://github.com/xcl-dev/xcl/pull/2336) `slopgobblercobbler:fix/recomp-fmt-info-bounds` → `main` · +32 −2 · 2 files · 1 commits · closed without merging Resolves XCL-BT-010 in #1488. **What is in it** - In `crates/xcl/src/gpu/recomp/emit.rs` (both `BufKind::FormatLoad` and `BufKind::FormatStore`): - Replaced `FMT_INFO[min({fmt}, 77u)]` with `({fmt} <= 77u) ? FMT_INFO[{fmt}] : 0u;`. - Out-of-range 7-bit unified buffer format codes (`78..127`) now evaluate to `0u` (`INVALID`), turning out-of-range format loads into `0` and stores into no-ops instead of decoding as format `77` (`32_32_32_32_FLOAT`). - In `crates/xcl/src/gpu/recomp/tests.rs`: - Added `format_codes_above_77_evaluate_to_invalid` testing both HLSL emission and GPU execution with format code `80` in both V# descriptor and MTBUF format immediate. **Tested** - `cargo test -p xcl -- recomp` (195 passed, 0 failed, 18 ignored) - `git diff --check upstream/main..HEAD` clean with zero trailing whitespace - `python -I scripts/check_no_game_data.py crates/xcl/src/gpu/recomp/emit.rs crates/xcl/src/gpu/recomp/tests.rs` confirmed clean **Not tested** - Retail game package execution (retail smoke suite) **AI use** - Patch implementation and synthetic unit test authored using Gemini 3.8 Flash (High).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:27:59 +00:00
github-bot closed this pull request 2026-11-26 05:27:59 +00:00
Author
Owner

@⁠nnonno91 on GitHub · 2026-11-25 15:28 UTC · original

Independent Windows check of 21c8b82f58e38e633625ade4a6096e87e6e27aaa. Both buffer instruction forms loaded zeros and left destination memory untouched for invalid formats, on Radeon integrated graphics and RTX 5090.

Tested

  • Windows 11 25H2 (26200.9974), Ryzen 7 9800X3D, Radeon integrated graphics (32.0.21042.62), RTX 5090 (32.0.16.1742), Rust 1.100.0 x64 MSVC, Windows SDK DXC/DXIL 1.8.2502.11. Unoptimized test profile.
  • Clean head, cargo test --locked -p xcl --lib format_codes_above_77_evaluate_to_invalid -- --nocapture --test-threads=1 on Radeon: 1 passed, 0 failed, 0 ignored, no logged skips.
  • Ran cargo test --locked -p xcl --lib local_typed_buffer_format_boundaries -- --nocapture --test-threads=1 with a temporary test-only fixture on each explicitly selected adapter. Each run reported 1 passed, 0 failed, 0 ignored, no logged skips. Checked all four load components and read back separate store destinations for the descriptor-based and immediate-format paths. Format 77 returned and stored the expected nonzero values. Formats 78, 80 and 127 returned four zeros and preserved all four destination words. Restored the clean worktree.

Not tested

Direct DXIL translation, the parent revision, retail titles, or the full workspace suite. The added test exercised the HLSL translation path.

AI use

OpenAI Codex (GPT-6.2 Sol) prepared and ran the tests, verified the results, and wrote this report.

**@⁠nnonno91** on GitHub · 2026-11-25 15:28 UTC · [original](https://github.com/xcl-dev/xcl/pull/2336#issuecomment-7166890830) Independent Windows check of `21c8b82f58e38e633625ade4a6096e87e6e27aaa`. Both buffer instruction forms loaded zeros and left destination memory untouched for invalid formats, on Radeon integrated graphics and RTX 5090. **Tested** - Windows 11 25H2 (26200.9974), Ryzen 7 9800X3D, Radeon integrated graphics (32.0.21042.62), RTX 5090 (32.0.16.1742), Rust 1.100.0 x64 MSVC, Windows SDK DXC/DXIL 1.8.2502.11. Unoptimized test profile. - Clean head, `cargo test --locked -p xcl --lib format_codes_above_77_evaluate_to_invalid -- --nocapture --test-threads=1` on Radeon: 1 passed, 0 failed, 0 ignored, no logged skips. - Ran `cargo test --locked -p xcl --lib local_typed_buffer_format_boundaries -- --nocapture --test-threads=1` with a temporary test-only fixture on each explicitly selected adapter. Each run reported 1 passed, 0 failed, 0 ignored, no logged skips. Checked all four load components and read back separate store destinations for the descriptor-based and immediate-format paths. Format 77 returned and stored the expected nonzero values. Formats 78, 80 and 127 returned four zeros and preserved all four destination words. Restored the clean worktree. **Not tested** Direct DXIL translation, the parent revision, retail titles, or the full workspace suite. The added test exercised the HLSL translation path. **AI use** OpenAI Codex (GPT-6.2 Sol) prepared and ran the tests, verified the results, and wrote this report.
Author
Owner

@⁠SlopTart on GitHub · 2026-11-25 15:30 UTC · original

Tested: current PR head 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).

  • gpu_ suite (--release --locked, --test-threads=2): 144 passed / 3 failed / 1 ignored, same three baseline failures as plain origin/main on this rig (rig's known baseline: fuzz seed 1003 of #2115, gpu_nonfused_mad_and_mac_prevent_fma_contraction, gpu_depth_buffer_created_for_unordered_access_is_placed).
  • New test gpu::recomp::tests::format_codes_above_77_evaluate_to_invalid: passes on this lane (targeted run, --exact).

The clamped format-code lookup behaves identically on RDNA3 under Wine; no delta in the suite.

Not tested: retail titles (no title data on this lane, counts only).

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

**@⁠SlopTart** on GitHub · 2026-11-25 15:30 UTC · [original](https://github.com/xcl-dev/xcl/pull/2336#issuecomment-7166960779) **Tested**: current PR head 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). - `gpu_` suite (`--release --locked`, `--test-threads=2`): 144 passed / 3 failed / 1 ignored, same three baseline failures as plain `origin/main` on this rig (rig's known baseline: fuzz seed 1003 of #2115, `gpu_nonfused_mad_and_mac_prevent_fma_contraction`, `gpu_depth_buffer_created_for_unordered_access_is_placed`). - New test `gpu::recomp::tests::format_codes_above_77_evaluate_to_invalid`: passes on this lane (targeted run, `--exact`). The clamped format-code lookup behaves identically on RDNA3 under Wine; no delta in the suite. **Not tested**: retail titles (no title data on this lane, counts only). **AI use**: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.
Author
Owner

@⁠frenziedcoder on GitHub · 2026-11-25 15:31 UTC · original

NVIDIA test report for 21c8b82: full suite green and a clean smoke pair (1640 vs 1673 frames), but the new test fails with XCL_DIRECT_DXIL=1: the direct-DXIL path has its own format table lookup, which still clamps to 77.

Tested

  • NVIDIA GeForce RTX 5080 16 GB (driver 621.40, 32-lane waves), AMD Ryzen 7 9800X3D, 64 GB, Windows 11 Pro 25H2 (26200.9974), rustc 1.100.0 stable-x86_64-pc-windows-msvc, DXC 1.8.2502.11 (SDK 10.0.26100.0). Exact head 21c8b82f58e38e633625ade4a6096e87e6e27aaa, no local changes.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4 (debug): 859 passed, 0 failed, 42 ignored; the PR's own test format_codes_above_77_evaluate_to_invalid passes. SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu_wave32_program_in_wave64_hardware (no wave64), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).

Direct-DXIL path

  • XCL_DIRECT_DXIL=1 cargo test -p xcl --lib format_codes_above_77 -- --test-threads=1 on the same head: fails, out-of-range format 80 load must return 0, left: 287454020 (0x11223344, the word in memory, i.e. read as format 77). Without the switch it passes.
  • The lookup there is fmt_info in crates/xcl/src/gpu/dxil/lower_mem.rs, which still does umin(fmt, 77) on xcl_fmt_info (and k.min(77) for a constant format). The NVIDIA runs of #2057 use XCL_DIRECT_DXIL=1, so for them this PR doesn't change anything yet.
  • Small one on the HLSL side: HLSL's ?: evaluates both operands, so ({fmt} <= 77u) ? FMT_INFO[{fmt}] : 0u still indexes the 78-entry static const table with 80. select({fmt} <= 77u, FMT_INFO[min({fmt}, 77u)], 0u), the form img_cls in the same file uses, keeps the index in range.

Regression run (scripts/smoke.ps1 -Seconds 60, release, the retail title of #505 at its start screen; XCL_PSO_PRELOAD=0 for both builds, because this machine's preload list holds the program of #1307)

base (c160d86, this PR's merge base with main):

xcl-smoke v1
commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0
gpu: NVIDIA GeForce RTX 5080
title: RetailTitle
seconds: 60
exit: 0x0
frames shown: 1673 (PresentX 1673)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14645 MB

this PR:

xcl-smoke v1
commit: 21c8b82f58e38e633625ade4a6096e87e6e27aaa
gpu: NVIDIA GeForce RTX 5080
title: RetailTitle
seconds: 60
exit: 0x0
frames shown: 1640 (PresentX 1640)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14686 MB

Not tested: the world load (the smoke runs stop at the start screen, so code that only runs later is not exercised there); AMD.

AI use: Claude Code (Claude Opus 5.5) built and ran the tests and smoke runs on my machine and wrote this report.

**@⁠frenziedcoder** on GitHub · 2026-11-25 15:31 UTC · [original](https://github.com/xcl-dev/xcl/pull/2336#issuecomment-7166986260) **NVIDIA test report for `21c8b82`: full suite green and a clean smoke pair (1640 vs 1673 frames), but the new test fails with `XCL_DIRECT_DXIL=1`: the direct-DXIL path has its own format table lookup, which still clamps to 77.** **Tested** - NVIDIA GeForce RTX 5080 16 GB (driver 621.40, 32-lane waves), AMD Ryzen 7 9800X3D, 64 GB, Windows 11 Pro 25H2 (26200.9974), rustc 1.100.0 `stable-x86_64-pc-windows-msvc`, DXC 1.8.2502.11 (SDK 10.0.26100.0). Exact head `21c8b82f58e38e633625ade4a6096e87e6e27aaa`, no local changes. - `cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4` (debug): **859 passed, 0 failed, 42 ignored**; the PR's own test `format_codes_above_77_evaluate_to_invalid` passes. SKIPPED: `gpu_geometry_wave32_prefix_count_over_a_mask` (no wave64), `gpu_wave32_program_in_wave64_hardware` (no wave64), `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows). **Direct-DXIL path** - `XCL_DIRECT_DXIL=1 cargo test -p xcl --lib format_codes_above_77 -- --test-threads=1` on the same head: **fails**, `out-of-range format 80 load must return 0`, `left: 287454020` (`0x11223344`, the word in memory, i.e. read as format 77). Without the switch it passes. - The lookup there is `fmt_info` in `crates/xcl/src/gpu/dxil/lower_mem.rs`, which still does `umin(fmt, 77)` on `xcl_fmt_info` (and `k.min(77)` for a constant format). The NVIDIA runs of #2057 use `XCL_DIRECT_DXIL=1`, so for them this PR doesn't change anything yet. - Small one on the HLSL side: HLSL's `?:` evaluates both operands, so `({fmt} <= 77u) ? FMT_INFO[{fmt}] : 0u` still indexes the 78-entry `static const` table with 80. `select({fmt} <= 77u, FMT_INFO[min({fmt}, 77u)], 0u)`, the form `img_cls` in the same file uses, keeps the index in range. **Regression run** (`scripts/smoke.ps1 -Seconds 60`, release, the retail title of #505 at its start screen; `XCL_PSO_PRELOAD=0` for both builds, because this machine's preload list holds the program of #1307) base (`c160d86`, this PR's merge base with `main`): ``` xcl-smoke v1 commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0 gpu: NVIDIA GeForce RTX 5080 title: RetailTitle seconds: 60 exit: 0x0 frames shown: 1673 (PresentX 1673) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14645 MB ``` this PR: ``` xcl-smoke v1 commit: 21c8b82f58e38e633625ade4a6096e87e6e27aaa gpu: NVIDIA GeForce RTX 5080 title: RetailTitle seconds: 60 exit: 0x0 frames shown: 1640 (PresentX 1640) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14686 MB ``` **Not tested:** the world load (the smoke runs stop at the start screen, so code that only runs later is not exercised there); AMD. *AI use: Claude Code (Claude Opus 5.5) built and ran the tests and smoke runs on my machine and wrote this report.*
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-25 15:59 UTC · original

Confirmed the direct-DXIL gap reported by @⁠frenziedcoder on exact head 21c8b82f58e38e633625ade4a6096e87e6e27aaa, using Windows 11 build 26200, AMD Radeon RX 6800M (driver 30.0.13002.13003), Rust 1.99 MSVC, and DXC/DXIL 1.9.2609.5.

  • Clean head, XCL_ADAPTER=6800M, XCL_DIRECT_DXIL=1: format_codes_above_77_evaluate_to_invalid failed 0 passed / 1 failed. Format 80 returned 287454020 (0x11223344) instead of zero.
  • Clean head, XCL_DIRECT_DXIL=0: the same test passed 1/0/0.
  • Local fix in gpu/dxil/lower_mem.rs::fmt_info: keep umin(fmt, 77) for a safe table index, then select zero when the original format exceeds 77:
let info = self.s.m.load(p, 4);
let valid = self.cmpc(Pred::ULe, fmt, 77);
self.sel(valid, info, z)

With this local change, the direct-DXIL format-80 test passed 1/0/0, and the broader format filter passed 16/0/0, with no explicit skips. I restored the local change; the checkout is clean at the exact PR head. This is a suggested fix for this PR, not a new submitted commit. I did not run a full workspace suite or title smoke pair.

AI use: OpenAI Codex (GPT-6) reproduced the failure, tested the local fix, and prepared this report.

**@⁠luckyteagirl** on GitHub · 2026-11-25 15:59 UTC · [original](https://github.com/xcl-dev/xcl/pull/2336#issuecomment-7167494300) Confirmed the direct-DXIL gap reported by @⁠frenziedcoder on exact head `21c8b82f58e38e633625ade4a6096e87e6e27aaa`, using Windows 11 build 26200, AMD Radeon RX 6800M (driver `30.0.13002.13003`), Rust 1.99 MSVC, and DXC/DXIL 1.9.2609.5. - Clean head, `XCL_ADAPTER=6800M`, `XCL_DIRECT_DXIL=1`: `format_codes_above_77_evaluate_to_invalid` **failed 0 passed / 1 failed**. Format 80 returned `287454020` (`0x11223344`) instead of zero. - Clean head, `XCL_DIRECT_DXIL=0`: the same test **passed 1/0/0**. - Local fix in `gpu/dxil/lower_mem.rs::fmt_info`: keep `umin(fmt, 77)` for a safe table index, then select zero when the *original* format exceeds 77: ```rust let info = self.s.m.load(p, 4); let valid = self.cmpc(Pred::ULe, fmt, 77); self.sel(valid, info, z) ``` With this local change, the direct-DXIL format-80 test **passed 1/0/0**, and the broader `format` filter **passed 16/0/0**, with no explicit skips. I restored the local change; the checkout is clean at the exact PR head. This is a suggested fix for this PR, not a new submitted commit. I did not run a full workspace suite or title smoke pair. **AI use:** OpenAI Codex (GPT-6) reproduced the failure, tested the local fix, and prepared this report.
Author
Owner

@⁠throny on GitHub · 2026-11-25 17:12 UTC · original

Two contributors checked independently and found that this PR makes the same change as #1574 (for #1488): #1607, group D84. They suggest keeping #1574. If you agree, closing this PR or joining the other one would save the maintainers a review. If the two differ in a way the checks missed, a note in #1607 helps.

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 17:12 UTC · [original](https://github.com/xcl-dev/xcl/pull/2336#issuecomment-7169171245) <!-- xcl-1607-hint:D84 --> Two contributors checked independently and found that this PR makes the same change as #1574 (for #1488): #1607, group D84. They suggest keeping #1574. If you agree, closing this PR or joining the other one would save the maintainers a review. If the two differ in a way the checks missed, a note in #1607 helps. 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

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

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 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 18:10 UTC · [original](https://github.com/xcl-dev/xcl/pull/2336#issuecomment-7170539723) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
Author
Owner

@⁠CalvyPZ on GitHub · 2026-11-25 22:42 UTC · original

This PR has been marked as a duplicate and closed after multiple agreeing checks in #1607. If you believe this is incorrect please re-open with why.

**@⁠CalvyPZ** on GitHub · 2026-11-25 22:42 UTC · [original](https://github.com/xcl-dev/xcl/pull/2336#issuecomment-7176685823) This PR has been marked as a duplicate and closed after multiple agreeing checks in #1607. If you believe this is incorrect please re-open with why.

Pull request closed

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