From 1e4a2c787a074b1aa541465bc709801d45babb18 Mon Sep 17 00:00:00 2001 From: xpatfussy69x <178718790+xpatfussy69x@users.noreply.github.com> Date: Thu, 26 Nov 2026 08:21:32 +1030 Subject: [PATCH] Recompiler: the rerouted shader cache checks fresh DXIL and chain pieces cached_in refuses freshly translated DXIL that is not a container, but cached_rerouted (the path of compute programs too big for the HLSL path, #2463 item 3) handed it on and wrote it. store_in checked only the main DXIL, so a split program with a bad piece was written although load_in always refuses it. valid_containers checks the DXIL and every dispatch-chain piece, as load_in does; store_in and cached_rerouted's fresh output use it. The issue's other half (direct_output without compact_nest_tag) is already fixed on main. Test: invalid fresh DXIL and a split program with one bad piece are both refused by cached_rerouted and nothing reaches the disk; store_in skips the bad split program and writes a valid one. Co-Authored-By: Claude Opus 5.5 --- crates/xcl/src/gpu/recomp/pso.rs | 47 +++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/crates/xcl/src/gpu/recomp/pso.rs b/crates/xcl/src/gpu/recomp/pso.rs index da4b25e5fb..76476636f9 100644 --- a/crates/xcl/src/gpu/recomp/pso.rs +++ b/crates/xcl/src/gpu/recomp/pso.rs @@ -341,8 +341,14 @@ mod translated { Some(Compiled { dxil: whole.to_vec(), samplers, dispatch_chain }) } + /// `c`'s DXIL and every piece of its dispatch chain are DXIL containers (what `load_in` takes). + fn valid_containers(c: &Compiled) -> bool { + super::dxc::valid_dxil_container(&c.dxil) + && c.dispatch_chain.as_ref().is_none_or(|chain| chain.pieces.iter().all(|p| super::dxc::valid_dxil_container(p))) + } + pub(super) fn store_in(path: &Path, ident: u64, blob: &[u8], c: &Compiled) { - if !super::dxc::valid_dxil_container(&c.dxil) { + if !valid_containers(c) { return; } let mut b = header(ident, blob); @@ -549,6 +555,10 @@ mod translated { } match translate() { Ok((c, direct)) => { + // as `cached_in`: not kept, and not handed on + if !valid_containers(&c) { + return Err("translated cache: translator returned an invalid DXIL container".into()); + } if err_path.is_file() { let _ = std::fs::remove_file(&err_path); } @@ -1605,6 +1615,41 @@ mod shader_cache_tests { let _ = std::fs::remove_dir_all(&dir); } + /// The rerouted path refuses fresh DXIL that is not a container, as `cached_in` does, and a + /// split program is written only when every piece is one (`load_in` refuses it otherwise; + /// #2463 item 3) + #[test] + fn rerouted_cache_validates_fresh_dxil_and_chain_pieces() { + use crate::gpu::dxil::kernel::DispatchChain; + use translated::{cached_rerouted, rerouted_identity}; + let dir = std::env::temp_dir().join(format!("xcl-translated-rerouted-valid-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + let (blob, ident) = (b"console-rerouted-valid".as_slice(), 0x4321); + let at = |id| translated::file(&dir, id, blob, Stage::Compute, 0, 1, false); + let chained = |piece: Vec| Compiled { + dispatch_chain: Some(Arc::new(DispatchChain { pieces: vec![synthetic_dxil(2), piece], dwords_per_group: 4 })), + ..compiled(1) + }; + + let err = cached_rerouted(&dir, ident, 7, blob, Stage::Compute, 0, 1, false, || { + Ok((Compiled { dispatch_chain: None, dxil: b"not DXIL".to_vec(), samplers: Vec::new() }, true)) + }) + .err() + .expect("invalid fresh DXIL must be rejected"); + assert!(err.contains("invalid DXIL container"), "{err}"); + let err = cached_rerouted(&dir, ident, 7, blob, Stage::Compute, 0, 1, false, || Ok((chained(b"not DXIL".to_vec()), true))) + .err() + .expect("an invalid fresh piece must be rejected"); + assert!(err.contains("invalid DXIL container"), "{err}"); + assert!(!at(rerouted_identity(ident, 7)).exists() && !at(ident).exists(), "nothing invalid on disk"); + + translated::store_in(&at(ident), ident, blob, &chained(b"not DXIL".to_vec())); + assert!(!at(ident).exists(), "store_in must not write an invalid piece"); + translated::store_in(&at(ident), ident, blob, &chained(synthetic_dxil(3))); + assert!(at(ident).exists(), "a valid split program is written"); + let _ = std::fs::remove_dir_all(&dir); + } + #[test] fn rerouted_disk_entries_follow_compact_nesting_policy() { use std::process::Command;