Skip to content

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

Open
b3IKK wants to merge 1 commit into
xcl-dev:mainfrom
b3IKK:recomp/fmt-info-oob-invalid
Open

b3IKK wants to merge 1 commit into
xcl-dev:mainfrom
b3IKK:recomp/fmt-info-oob-invalid

Conversation

@b3IKK

@b3IKK b3IKK commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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

…ID instead of 77

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 xcl-dev#1488.

Assisted-by: OpenCode (Gemini 4 Neon)
@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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.

@b3IKK

b3IKK commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

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.

@futurepro62

Copy link
Copy Markdown

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 Tests: heap_window_out_of_memory_falls_back_to_the_switch_form fails under XCL_REQUIRE_GPU=mesh (opt-in skip counted as missing coverage) #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.

@DavidM1911

Copy link
Copy Markdown
Contributor

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!

@Belox17

Belox17 commented Nov 24, 2026

Copy link
Copy Markdown

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.

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This duplicates #2336 and has the same P1: it fixes only HLSL emit.rs, while Direct-DXIL lower_mem.rs still aliases typed-buffer format codes 78-127 to 77 under XCL_DIRECT_DXIL=1. Consolidate into one PR that fixes both backends and adds Direct-DXIL coverage. No Windows Build/test check is visible.

@CalvyPZ CalvyPZ added the duplicate This issue or pull request already exists label Nov 25, 2026
@CalvyPZ CalvyPZ closed this Nov 25, 2026
@CalvyPZ CalvyPZ reopened this Nov 25, 2026
@CalvyPZ CalvyPZ removed the duplicate This issue or pull request already exists label Nov 25, 2026
@frenziedcoder

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants