Recompiler: map out-of-range typed buffer format codes (>77) to INVALID instead of 77 #1574

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

@⁠b3IKK on GitHub · 2026-11-24 17:50 UTC · original
b3IKK:recomp/fmt-info-oob-invalid → main · +32 −2 · 2 files · 1 commits · open

Addresses XCL-BT-010 from #1488.

BufKind::FormatLoad and BufKind::FormatStore in crates/xcl/src/gpu/recomp/emit.rs emitted FMT_INFO[min(fmt, 77u)]. Because entry 77 is valid 32_32_32_32_FLOAT (16 bytes) while entry 0 is INVALID, any out-of-range 7-bit format code in 78..=127 was clamped to format 77 and treated as a valid 16-byte float4 read or write instead of INVALID.

This emits uint t_fmt = fmt; uint t_info = (t_fmt <= 77u) ? FMT_INFO[t_fmt] : 0u; so out-of-range format codes evaluate to 0 (INVALID), returning 0 on loads and skipping stores.

Note on premise: mapping reserved codes 78..=127 to INVALID (0) is derived from the GFX10 IMG_FORMAT table layout (0..=77 valid, 0 = INVALID), not measured on RDNA2 hardware (no RDNA2 GPU is available on this test machine to probe reserved format codes directly; the previous min(fmt, 77u) was an array-bounds clamp that accidentally aliased 78..=127 to 32_32_32_32_FLOAT).

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs: map fmt > 77u to 0u (INVALID) instead of clamping to 77u in BufKind::FormatLoad and BufKind::FormatStore.
  • crates/xcl/src/gpu/recomp/tests.rs: add GPU test gpu_typed_buffer_out_of_range_format_codes_are_invalid (verified failing before the fix with 0xDEADBEEF returned on format 78).

Tested

  • hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1)
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 777 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2 no wave64 — gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware; 1 no heap windows — heap_window_out_of_memory_falls_back_to_the_switch_form)
  • cargo test -p xcl --lib gpu_typed_buffer_out_of_range_format_codes_are_invalid: 1 passed, 0 failed (failed on RTX 5080 before the fix)

Regression run

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1226 (PresentX 1226)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15341 MB

PR:

xcl-smoke v1
commit: 6ac16ddf8a49e0249f86ecc11cfbdfae5fdd9c66
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1647 (PresentX 1647)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14617 MB

Not tested

  • RDNA2 hardware behavior of reserved format codes 78..=127 (derived from the GFX10 format table, not hardware-probed)
  • AMD GPUs and native wave64 hardware
  • other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine

AI use

  • OpenCode, Gemini 4 Neon: verified XCL-BT-010 from #1488, wrote the fix and GPU regression test, ran the test suite and scripts/smoke.ps1 regression runs, and drafted this PR description.
**@⁠b3IKK** on GitHub · 2026-11-24 17:50 UTC · [original](https://github.com/xcl-dev/xcl/pull/1574) `b3IKK:recomp/fmt-info-oob-invalid` → `main` · +32 −2 · 2 files · 1 commits · open Addresses `XCL-BT-010` from #1488. `BufKind::FormatLoad` and `BufKind::FormatStore` in `crates/xcl/src/gpu/recomp/emit.rs` emitted `FMT_INFO[min(fmt, 77u)]`. Because entry `77` is valid `32_32_32_32_FLOAT` (16 bytes) while entry `0` is `INVALID`, any out-of-range 7-bit format code in `78..=127` was clamped to format `77` and treated as a valid 16-byte float4 read or write instead of `INVALID`. This emits `uint t_fmt = fmt; uint t_info = (t_fmt <= 77u) ? FMT_INFO[t_fmt] : 0u;` so out-of-range format codes evaluate to `0` (`INVALID`), returning `0` on loads and skipping stores. Note on premise: mapping reserved codes `78..=127` to `INVALID` (`0`) is **derived from the GFX10 `IMG_FORMAT` table layout (`0..=77` valid, `0 = INVALID`), not measured on RDNA2 hardware** (no RDNA2 GPU is available on this test machine to probe reserved format codes directly; the previous `min(fmt, 77u)` was an array-bounds clamp that accidentally aliased `78..=127` to `32_32_32_32_FLOAT`). **What is in it** - `crates/xcl/src/gpu/recomp/emit.rs`: map `fmt > 77u` to `0u` (`INVALID`) instead of clamping to `77u` in `BufKind::FormatLoad` and `BufKind::FormatStore`. - `crates/xcl/src/gpu/recomp/tests.rs`: add GPU test `gpu_typed_buffer_out_of_range_format_codes_are_invalid` (verified failing before the fix with `0xDEADBEEF` returned on format `78`). **Tested** - hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (`stable-x86_64-pc-windows-msvc`), DXC 1.9.2609.5, debug (`scripts/test.ps1`) and release (`scripts/smoke.ps1`) - `.\scripts\test.ps1` (`cargo build --workspace` + `cargo test --workspace -- --test-threads=4`): 777 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2 `no wave64` — `gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware`; 1 `no heap windows` — `heap_window_out_of_memory_falls_back_to_the_switch_form`) - `cargo test -p xcl --lib gpu_typed_buffer_out_of_range_format_codes_are_invalid`: 1 passed, 0 failed (failed on RTX 5080 before the fix) **Regression run** main: ``` xcl-smoke v1 commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1226 (PresentX 1226) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15341 MB ``` PR: ``` xcl-smoke v1 commit: 6ac16ddf8a49e0249f86ecc11cfbdfae5fdd9c66 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1647 (PresentX 1647) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14617 MB ``` **Not tested** - RDNA2 hardware behavior of reserved format codes `78..=127` (derived from the GFX10 format table, not hardware-probed) - AMD GPUs and native wave64 hardware - other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine **AI use** - OpenCode, Gemini 4 Neon: verified `XCL-BT-010` from #1488, wrote the fix and GPU regression test, ran the test suite and `scripts/smoke.ps1` regression runs, and drafted this PR description.
BufKind::FormatLoad and BufKind::FormatStore emitted
`FMT_INFO[min(fmt, 77u)]`. Because entry 77 is valid `32_32_32_32_FLOAT`
(16 bytes) while entry 0 is `INVALID`, any 7-bit format code in 78..=127
was treated as a valid 16-byte float4 read or write instead of INVALID.

Emit `(fmt <= 77u) ? FMT_INFO[fmt] : 0u` so out-of-range format codes
evaluate to 0 (INVALID), returning 0 on loads and skipping stores.
Addresses XCL-BT-010 in #1488.

Assisted-by: OpenCode (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:57:56 +00:00
Author
Owner

@⁠upipibi on GitHub · 2026-11-24 18:13 UTC · original

One question on the premise: is "78–127 is INVALID (loads give 0, stores are dropped)" measured on RDNA2 hardware, or taken from the table's layout? The GPU test checks what this PR emits, not what the console does. #1414's measurements (77 formats on a gfx1036 by Lyrnc) stop at the valid codes. A reserved code could also behave like another format, or like 0 with the descriptor ignored. If nobody has a hardware answer, "derived, not measured" in the description would make that clear.

AI use: Claude Code (Claude Opus 5.5) read the change and wrote this.

**@⁠upipibi** on GitHub · 2026-11-24 18:13 UTC · [original](https://github.com/xcl-dev/xcl/pull/1574#issuecomment-7140337105) One question on the premise: is "78–127 is INVALID (loads give 0, stores are dropped)" measured on RDNA2 hardware, or taken from the table's layout? The GPU test checks what this PR emits, not what the console does. #1414's measurements (77 formats on a gfx1036 by Lyrnc) stop at the valid codes. A reserved code could also behave like another format, or like 0 with the descriptor ignored. If nobody has a hardware answer, "derived, not measured" in the description would make that clear. AI use: Claude Code (Claude Opus 5.5) read the change and wrote this.
Author
Owner

@⁠b3IKK on GitHub · 2026-11-24 18:29 UTC · original

Good point @⁠upipibi — mapping reserved codes 78..=127 to INVALID (0) is derived from the GFX10 format table definition (0..=77 valid, 0 = INVALID) rather than probed on RDNA2 silicon (no AMD GPU on this machine). I updated the PR description and Not tested section to state that explicitly.

**@⁠b3IKK** on GitHub · 2026-11-24 18:29 UTC · [original](https://github.com/xcl-dev/xcl/pull/1574#issuecomment-7140710243) Good point @⁠upipibi — mapping reserved codes 78..=127 to INVALID (0) is derived from the GFX10 format table definition (0..=77 valid, 0 = INVALID) rather than probed on RDNA2 silicon (no AMD GPU on this machine). I updated the PR description and **Not tested** section to state that explicitly.
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-24 18:54 UTC · original

Full-suite run, since this PR has no test report yet. Tested exact head 6ac16dd (on its base 9e3831e).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form: 776 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: gpu_typed_buffer_out_of_range_format_codes_are_invalid.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 777 passed, 0 failed, 41 ignored. SKIPPED: heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • heap_window_out_of_memory_falls_back_to_the_switch_form was skipped with --skip. It fails on main 9e3831e too, not because of this PR: under XCL_REQUIRE_GPU=mesh, runner::skip_test turns every skip except "no wave64" into a failure, including this test's opt-in "no heap windows" skip (XCL_HEAP_WINDOWS unset). Reported as #1651.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-24 18:54 UTC · [original](https://github.com/xcl-dev/xcl/pull/1574#issuecomment-7141316392) Full-suite run, since this PR has no test report yet. Tested exact head `6ac16dd` (on its base `9e3831e`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form`: **776 passed, 0 failed, 41 ignored**. SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. - The new tests ran and passed: `gpu_typed_buffer_out_of_range_format_codes_are_invalid`. - Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, `XCL_ADAPTER=radeon`), `cargo test --workspace -- --test-threads=4`: **777 passed, 0 failed, 41 ignored**. SKIPPED: `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows). - `heap_window_out_of_memory_falls_back_to_the_switch_form` was skipped with `--skip`. It fails on main `9e3831e` too, not because of this PR: under `XCL_REQUIRE_GPU=mesh`, `runner::skip_test` turns every skip except "no wave64" into a failure, including this test's opt-in "no heap windows" skip (`XCL_HEAP_WINDOWS` unset). Reported as #1651. **Not tested** - a release build, a game (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 19:51 UTC · original

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 19:51 UTC · [original](https://github.com/xcl-dev/xcl/pull/1574#issuecomment-7142689838) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified `main`.) Thanks!
Author
Owner

@⁠Belox17 on GitHub · 2026-11-24 20:02 UTC · original

Test report for 6ac16ddf on NVIDIA (RTX 3060 Ti): passes, and the GPU test fails without the fix

Tested

  • NVIDIA GeForce RTX 3060 Ti 8 GB (32-lane waves), driver 32.0.16.2124; Ryzen 5 5600X; Windows 11 build 26300; rustc 1.98.1 MSVC; DXC 1.8.2502.11 (Windows SDK 10.0.26100); debug build. Head 6ac16ddf as is (base 9e3831e), clean tree.
  • The new test (gpu_typed_buffer_out_of_range_format_codes_are_invalid) with cargo test -p xcl --lib <name>: 1 passed (the GPU part ran on this adapter, no SKIPPED).
  • cargo test --workspace -- --test-threads=4 on the head: 777 passed, 0 failed, 41 ignored; its base 9e3831e on the same machine: 776 passed, 0 failed, 41 ignored. SKIPPED on both: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • Merged into current main c160d86e (clean merge): 859 passed, 0 failed, 42 ignored; main alone: 858 passed, 0 failed, 42 ignored, the same three SKIPPED as above.
  • With the two hunks of emit.rs reverted (test kept), the GPU test fails on this adapter: lane 0: format 78 load must yield 0 (INVALID), left [3735928559, 3735928559, 3735928559, 3735928559] (0xDEADBEEF), right [0, 0, 0, 0].

Not tested

  • AMD / native wave64 hardware; any retail title (no smoke run).

AI use: Claude Code (Claude Opus 5.5) ran the commands on this machine and wrote this report from those runs.

**@⁠Belox17** on GitHub · 2026-11-24 20:02 UTC · [original](https://github.com/xcl-dev/xcl/pull/1574#issuecomment-7142966448) **Test report for `6ac16ddf` on NVIDIA (RTX 3060 Ti): passes, and the GPU test fails without the fix** **Tested** - NVIDIA GeForce RTX 3060 Ti 8 GB (32-lane waves), driver 32.0.16.2124; Ryzen 5 5600X; Windows 11 build 26300; rustc 1.98.1 MSVC; DXC 1.8.2502.11 (Windows SDK 10.0.26100); debug build. Head `6ac16ddf` as is (base `9e3831e`), clean tree. - The new test (`gpu_typed_buffer_out_of_range_format_codes_are_invalid`) with `cargo test -p xcl --lib <name>`: 1 passed (the GPU part ran on this adapter, no `SKIPPED`). - `cargo test --workspace -- --test-threads=4` on the head: **777 passed, 0 failed, 41 ignored**; its base `9e3831e` on the same machine: 776 passed, 0 failed, 41 ignored. SKIPPED on both: `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware` (no wave64), `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows). - Merged into current `main` `c160d86e` (clean merge): **859 passed, 0 failed, 42 ignored**; `main` alone: 858 passed, 0 failed, 42 ignored, the same three SKIPPED as above. - With the two hunks of `emit.rs` reverted (test kept), the GPU test fails on this adapter: `lane 0: format 78 load must yield 0 (INVALID)`, left `[3735928559, 3735928559, 3735928559, 3735928559]` (0xDEADBEEF), right `[0, 0, 0, 0]`. **Not tested** - AMD / native wave64 hardware; any retail title (no smoke run). **AI use:** Claude Code (Claude Opus 5.5) ran the commands on this machine and wrote this report from those runs.
Author
Owner

@⁠frenziedcoder on GitHub · 2026-11-26 07:44 UTC · original

Measured on NVIDIA, for @⁠bmjask's review point: merged onto current main, this PR's own test passes on the default backend and fails with XCL_DIRECT_DXIL=1. So the test is already the Direct-DXIL coverage the review asks for, once it runs on a main whose test runner honours the switch.

RTX 5080 16 GB (driver 621.40), Windows 11 Pro 26200, rustc 1.100.0 MSVC, debug, DXC 1.8.2502.11. cargo test -p xcl --lib gpu_typed_buffer_out_of_range_format_codes_are_invalid -- --test-threads=1, each backend in its own process (XCL_DIRECT_DXIL removed for the default run, =1 for the other), Cargo's exit code kept and the named test required to have run:

tree default XCL_DIRECT_DXIL=1
main 08db8020 + this PR (clean merge) pass (exit 0) fail (exit 101): lane 0: format 78 load must yield 0 (INVALID)
this PR as pushed, 6ac16dd (base 9e3831e) pass pass, but not a check: on 9e3831e runner::run_code always compiles the HLSL and nothing under gpu/ reads XCL_DIRECT_DXIL
9e3831e + only this PR's test (no fix) fail (101) fail (101)

That second row is why the green reports above (all on 9e3831e) could not show it. On main b49be183 fmt_info in crates/xcl/src/gpu/dxil/lower_mem.rs still does k.min(77) / umin(fmt, 77); no commit since 08db8020 touches it.

AI use: Claude Code (Claude Opus 5.5) ran the checks on my machine and wrote this comment.

**@⁠frenziedcoder** on GitHub · 2026-11-26 07:44 UTC · [original](https://github.com/xcl-dev/xcl/pull/1574#issuecomment-7185780836) **Measured on NVIDIA, for @⁠bmjask's review point: merged onto current `main`, this PR's own test passes on the default backend and fails with `XCL_DIRECT_DXIL=1`.** So the test is already the Direct-DXIL coverage the review asks for, once it runs on a `main` whose test runner honours the switch. RTX 5080 16 GB (driver 621.40), Windows 11 Pro 26200, rustc 1.100.0 MSVC, debug, DXC 1.8.2502.11. `cargo test -p xcl --lib gpu_typed_buffer_out_of_range_format_codes_are_invalid -- --test-threads=1`, each backend in its own process (`XCL_DIRECT_DXIL` removed for the default run, `=1` for the other), Cargo's exit code kept and the named test required to have run: | tree | default | `XCL_DIRECT_DXIL=1` | |---|---|---| | `main` `08db8020` + this PR (clean merge) | pass (exit 0) | **fail** (exit 101): `lane 0: format 78 load must yield 0 (INVALID)` | | this PR as pushed, `6ac16dd` (base `9e3831e`) | pass | pass, but not a check: on `9e3831e` `runner::run_code` always compiles the HLSL and nothing under `gpu/` reads `XCL_DIRECT_DXIL` | | `9e3831e` + only this PR's test (no fix) | fail (101) | fail (101) | That second row is why the green reports above (all on `9e3831e`) could not show it. On `main` `b49be183` `fmt_info` in `crates/xcl/src/gpu/dxil/lower_mem.rs` still does `k.min(77)` / `umin(fmt, 77)`; no commit since `08db8020` touches it. *AI use: Claude Code (Claude Opus 5.5) ran the checks on my machine and wrote this comment.*
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/1574/head:github-bot/gh-1574'
git switch 'github-bot/gh-1574'

Merge

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