Skip to content

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

Closed
slopgobblercobbler wants to merge 1 commit into
xcl-dev:mainfrom
slopgobblercobbler:fix/recomp-fmt-info-bounds
Closed

slopgobblercobbler wants to merge 1 commit into
xcl-dev:mainfrom
slopgobblercobbler:fix/recomp-fmt-info-bounds

Conversation

@slopgobblercobbler

Copy link
Copy Markdown
Contributor

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).

@nnonno91

Copy link
Copy Markdown

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.

@SlopTart

Copy link
Copy Markdown

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).

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.

@frenziedcoder

Copy link
Copy Markdown

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 D3D12.X: integration branch that reaches the in-world HUD on NVIDIA (reference, not for merge) #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.

@luckyteagirl

Copy link
Copy Markdown
Contributor

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.

@throny

throny commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

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.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@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.

P1: this fixes invalid format codes only in HLSL, not Direct DXIL. HLSL changes emit.rs:1780/1816, but Direct DXIL lower_mem.rs:286-304 still applies umin(fmt, 77) in fmt_info for both loads/stores, so codes 78-127 remain interpreted as format 77 instead of INVALID under XCL_DIRECT_DXIL=1. Reports on this head reproduce format 80 returning 0x11223344 rather than zero. Keep umin only for a safe table index and select zero info when original fmt > 77; add Direct-DXIL coverage. This is also functionally duplicated by #1574 and should be consolidated.

@CalvyPZ

CalvyPZ commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

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 CalvyPZ closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants