Recompiler: validate DXIL containers and split pieces in translated cache #2540

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

@⁠ramon-victor on GitHub · 2026-11-25 22:18 UTC · original
ramon-victor:fix/pso-translated-cache-validation → main · +93 −2 · 1 files · 1 commits · open

Enforces DXIL container and split dispatch_chain validation in translated::cached_rerouted, translated::cached_in, and translated::store_in, matching the invariants already enforced by translated::load_in.

Previously, the production path translated::cached_rerouted skipped dxc::valid_dxil_container(&c.dxil) (unlike the test-only cached_in), and none of store_in, cached_in, or cached_rerouted validated c.dispatch_chain (dwords_per_group > 0, pieces.len() >= 2, and valid_dxil_container(piece) for every piece). A corrupt or truncated whole container or split piece could therefore be returned directly to D3D12 and persisted to disk (where load_in later rejected it).

Part of #2463 (specifically item 3's container/piece validation; direct_output() already tracks compact_nest_tag() on main).

What is in it

  • crates/xcl/src/gpu/recomp/pso.rs:
    • Add translated::valid_compiled(c: &Compiled) -> bool verifying dxc::valid_dxil_container(&c.dxil) and, when dispatch_chain is Some, dwords_per_group > 0, pieces.len() >= 2, and valid_dxil_container on every piece.
    • Enforce valid_compiled in store_in, cached_in, and cached_rerouted (returning an error without writing .bin or a permanent .err marker when validation fails).
    • Add shader_cache_tests::translated_cache_rejects_invalid_dxil_and_split_pieces covering invalid whole DXIL in cached_rerouted, malformed dispatch_chain cases (bad piece bytes, < 2 pieces, 0 dwords per group) across cached_rerouted, cached_in, and store_in, plus a valid 2-piece round-trip.

Tested

  • Hardware / toolchain: NVIDIA GeForce RTX 3070 8 GiB (driver 621.24, wave32), AMD Ryzen 7 5700X, 32 GiB RAM, Windows 11 Pro (26300), rustc 1.99.0 (x86_64-pc-windows-msvc), DXC/DXIL 1.8.2502.11 (Windows SDK 10.0.26100.0).
  • Failing-first before fix: cargo test -p xcl --lib translated_cache_rejects_invalid_dxil_and_split_pieces -- --nocapture failed (0 passed, 1 failed: cached_rerouted must reject invalid whole DXIL).
  • After fix: cargo test -p xcl --lib gpu::recomp::pso:: -- --test-threads=1: 25 passed, 0 failed, 1 ignored (repeated_pso_shader_compile benchmark).
  • Full workspace suite (.\scripts\test.ps1, debug): 1424 passed, 0 failed, 46 ignored (skipped on this adapter: wave64-only GPU tests, unsupported per-lane semantics variants, no heap windows).
  • Release build (cargo build --release -p xcl) and clean 60 s retail smoke run (.\scripts\smoke.ps1).

Regression run

Baseline (main):

xcl-smoke v1
commit: f087b998d0d51a9f11bbfa0761967a63e778edd9
gpu: NVIDIA GeForce RTX 3070
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14467 MB

PR (f5cb7ea):

xcl-smoke v1
commit: f5cb7eaa1c54b3ab321bf1f3c026826008dfeb49
gpu: NVIDIA GeForce RTX 3070
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1619 (PresentX 1619)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14024 MB

Not tested

  • Corrupting an on-disk retail cache during a live title run (covered deterministically by the unit tests on translated::cached_rerouted, cached_in, and store_in).
  • AMD / Intel GPUs and Wine / macOS hosts.

AI use

  • Antigravity (Gemini 4 Neon): analyzed #2463 item 3 against main, implemented valid_compiled across store_in/cached_in/cached_rerouted and its failing-first unit tests, ran .\scripts\test.ps1, release build, and the 60 s smoke.ps1 run, and drafted this PR description.
**@⁠ramon-victor** on GitHub · 2026-11-25 22:18 UTC · [original](https://github.com/xcl-dev/xcl/pull/2540) `ramon-victor:fix/pso-translated-cache-validation` → `main` · +93 −2 · 1 files · 1 commits · open Enforces DXIL container and split `dispatch_chain` validation in `translated::cached_rerouted`, `translated::cached_in`, and `translated::store_in`, matching the invariants already enforced by `translated::load_in`. Previously, the production path `translated::cached_rerouted` skipped `dxc::valid_dxil_container(&c.dxil)` (unlike the test-only `cached_in`), and none of `store_in`, `cached_in`, or `cached_rerouted` validated `c.dispatch_chain` (`dwords_per_group > 0`, `pieces.len() >= 2`, and `valid_dxil_container(piece)` for every piece). A corrupt or truncated whole container or split piece could therefore be returned directly to D3D12 and persisted to disk (where `load_in` later rejected it). Part of #2463 (specifically item 3's container/piece validation; `direct_output()` already tracks `compact_nest_tag()` on `main`). **What is in it** - `crates/xcl/src/gpu/recomp/pso.rs`: - Add `translated::valid_compiled(c: &Compiled) -> bool` verifying `dxc::valid_dxil_container(&c.dxil)` and, when `dispatch_chain` is `Some`, `dwords_per_group > 0`, `pieces.len() >= 2`, and `valid_dxil_container` on every piece. - Enforce `valid_compiled` in `store_in`, `cached_in`, and `cached_rerouted` (returning an error without writing `.bin` or a permanent `.err` marker when validation fails). - Add `shader_cache_tests::translated_cache_rejects_invalid_dxil_and_split_pieces` covering invalid whole DXIL in `cached_rerouted`, malformed `dispatch_chain` cases (bad piece bytes, `< 2` pieces, `0` dwords per group) across `cached_rerouted`, `cached_in`, and `store_in`, plus a valid 2-piece round-trip. **Tested** - Hardware / toolchain: NVIDIA GeForce RTX 3070 8 GiB (driver `621.24`, wave32), AMD Ryzen 7 5700X, 32 GiB RAM, Windows 11 Pro (`26300`), `rustc 1.99.0` (`x86_64-pc-windows-msvc`), DXC/DXIL `1.8.2502.11` (Windows SDK `10.0.26100.0`). - Failing-first before fix: `cargo test -p xcl --lib translated_cache_rejects_invalid_dxil_and_split_pieces -- --nocapture` failed (`0 passed, 1 failed`: `cached_rerouted must reject invalid whole DXIL`). - After fix: `cargo test -p xcl --lib gpu::recomp::pso:: -- --test-threads=1`: `25 passed, 0 failed, 1 ignored` (`repeated_pso_shader_compile` benchmark). - Full workspace suite (`.\scripts\test.ps1`, debug): `1424 passed, 0 failed, 46 ignored` (skipped on this adapter: wave64-only GPU tests, unsupported per-lane semantics variants, `no heap windows`). - Release build (`cargo build --release -p xcl`) and clean 60 s retail smoke run (`.\scripts\smoke.ps1`). **Regression run** Baseline (`main`): ``` xcl-smoke v1 commit: f087b998d0d51a9f11bbfa0761967a63e778edd9 gpu: NVIDIA GeForce RTX 3070 title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1618 (PresentX 1618) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14467 MB ``` PR (`f5cb7ea`): ``` xcl-smoke v1 commit: f5cb7eaa1c54b3ab321bf1f3c026826008dfeb49 gpu: NVIDIA GeForce RTX 3070 title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1619 (PresentX 1619) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14024 MB ``` **Not tested** - Corrupting an on-disk retail cache during a live title run (covered deterministically by the unit tests on `translated::cached_rerouted`, `cached_in`, and `store_in`). - AMD / Intel GPUs and Wine / macOS hosts. **AI use** - Antigravity (Gemini 4 Neon): analyzed #2463 item 3 against `main`, implemented `valid_compiled` across `store_in`/`cached_in`/`cached_rerouted` and its failing-first unit tests, ran `.\scripts\test.ps1`, release build, and the 60 s `smoke.ps1` run, and drafted this PR description.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:33:19 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 22:26 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 22:26 UTC · [original](https://github.com/xcl-dev/xcl/pull/2540#issuecomment-7176373717) 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

@⁠emirduran707 on GitHub · 2026-11-25 22:37 UTC · original

Independent AMD RDNA4 (native wave64) test report on exact head f5cb7eaa1c54b3ab321bf1f3c026826008dfeb49 (clean detached checkout, no local changes).

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64, driver 32.0.31044.16), Ryzen 5 5600, 32 GB RAM, Windows 11 Pro 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17; tests debug, smoke release.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 1422 passed, 2 failed, 46 ignored; 8 SKIPPED (6 in lower_dxil::tests::{f16,f32}_programs_on_the_gpu refused by per-lane form; heap_window_out_of_memory_falls_back_to_the_switch_form; pso_measurement_compiles_an_exact_synthetic_record). All native wave64 GPU tests ran and passed.
    • The PR's test passed: gpu::recomp::pso::shader_cache_tests::translated_cache_rejects_invalid_dxil_and_split_pieces.
    • The 2 failures (gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 seed 722 and fuzz_validate_and_gpu_3 seed 1599) are pre-existing on unmodified main on this GPU.

Regression run (60 s retail-title smoke, XCL_NETWORK=0, release)

xcl-smoke v1
commit: f5cb7eaa1c54b3ab321bf1f3c026826008dfeb49
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1597 (PresentX 1597)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13963 MB

(Matched main 68a284a baseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.)

Not tested

  • D3D12 debug layer; Intel GPUs.

AI use

  • Antigravity with Gemini 4 Neon ran the build, test suite, and smoke run and drafted this report.
**@⁠emirduran707** on GitHub · 2026-11-25 22:37 UTC · [original](https://github.com/xcl-dev/xcl/pull/2540#issuecomment-7176601857) Independent AMD RDNA4 (native wave64) test report on exact head `f5cb7eaa1c54b3ab321bf1f3c026826008dfeb49` (clean detached checkout, no local changes). **Tested** - AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64, driver 32.0.31044.16), Ryzen 5 5600, 32 GB RAM, Windows 11 Pro 26300, Rust 1.100.0 (`stable-x86_64-pc-windows-msvc`), DXC 1.9.2602.17; tests debug, smoke release. - `cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4`: **1422 passed, 2 failed, 46 ignored; 8 SKIPPED** (6 in `lower_dxil::tests::{f16,f32}_programs_on_the_gpu` refused by per-lane form; `heap_window_out_of_memory_falls_back_to_the_switch_form`; `pso_measurement_compiles_an_exact_synthetic_record`). All native wave64 GPU tests ran and passed. - The PR's test passed: `gpu::recomp::pso::shader_cache_tests::translated_cache_rejects_invalid_dxil_and_split_pieces`. - The 2 failures (`gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1` seed 722 and `fuzz_validate_and_gpu_3` seed 1599) are pre-existing on unmodified `main` on this GPU. **Regression run** (60 s retail-title smoke, `XCL_NETWORK=0`, release) ``` xcl-smoke v1 commit: f5cb7eaa1c54b3ab321bf1f3c026826008dfeb49 gpu: AMD Radeon RX 9060 XT title: 21222967 seconds: 60 exit: 0x0 frames shown: 1597 (PresentX 1597) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 13963 MB ``` (Matched `main` `68a284a` baseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.) **Not tested** - D3D12 debug layer; Intel GPUs. **AI use** - Antigravity with Gemini 4 Neon ran the build, test suite, and smoke run and drafted this report.
Author
Owner

@⁠SlopTart on GitHub · 2026-11-25 23:24 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 (cold cache): 165 passed / 3 failed, no crashes. The three are the known baseline on this lane (seed-1003 fuzz, mad/mac contraction, promoted-UAV-clear driver gap, PR #2490); none caused by this PR.
Targeted run of translated_cache_rejects_invalid_dxil_and_split_pieces: 2 passed.

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 23:24 UTC · [original](https://github.com/xcl-dev/xcl/pull/2540#issuecomment-7177527741) **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 (cold cache): 165 passed / 3 failed, no crashes. The three are the known baseline on this lane (seed-1003 fuzz, mad/mac contraction, promoted-UAV-clear driver gap, PR #2490); none caused by this PR. Targeted run of `translated_cache_rejects_invalid_dxil_and_split_pieces`: 2 passed. **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.
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/2540/head:github-bot/gh-2540'
git switch 'github-bot/gh-2540'

Merge

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