From 006d650e8742bfcf06e51dd82449262e3b0bca6b Mon Sep 17 00:00:00 2001 From: Pipodi Date: Mon, 30 Nov 2026 04:12:27 +0100 Subject: [PATCH] D3D12.X: warn when a root argument write runs past its parameter A retail title's BVH builder writes 4 dwords into compute parameter 3, the last parameter of a 9-dword table (3 fit). The write was dropped whole until the clip to the parameter's size; the radix pass then read a null BVH header and the refit's box stores corrupted vertex and index lists. With the clip alone (r262) L24 went 80 -> 0 and de5c's bad parent loads 30.7M -> 1. Nothing in the log said the write had been cut, so two investigations each added the same line locally. put_in now logs one line for each distinct shape of an overrunning write (list kind, parameter, offset, dwords written, dwords that fit, table size in dwords), at most 8 shapes, so a title that does it every frame costs 8 lines. No switch, no change to what is written, no return value. No test: it is a log line. An atomic flag, set once 8 shapes are logged, is checked before the lock, so a title that overruns on every dispatch does not take the mutex from every recording thread after the cap. Co-Authored-By: Claude Sonnet 5.5 --- crates/xcl/src/hle/d3d12x/bind.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/crates/xcl/src/hle/d3d12x/bind.rs b/crates/xcl/src/hle/d3d12x/bind.rs index 0c064f8f93..af06198573 100644 --- a/crates/xcl/src/hle/d3d12x/bind.rs +++ b/crates/xcl/src/hle/d3d12x/bind.rs @@ -1477,6 +1477,25 @@ fn put_in(list: *mut c_void, gfx: bool, i: u32, offset: u32, bytes: &[u8]) { return; }; let write_end = end.min(limit); + // (once 8 shapes are logged, an overrun does not take the lock) + static FULL: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false); + if end > limit && !FULL.load(std::sync::atomic::Ordering::Relaxed) { + // one line per distinct shape, 8 shapes at most + static SEEN: std::sync::Mutex> = std::sync::Mutex::new(Vec::new()); + let shape = (gfx, i, offset, bytes.len() / 4, write_end.saturating_sub(at) / 4, args.len() / 4); + let mut seen = SEEN.lock().unwrap_or_else(|e| e.into_inner()); + if seen.len() < 8 && !seen.contains(&shape) { + seen.push(shape); + FULL.store(seen.len() >= 8, std::sync::atomic::Ordering::Relaxed); + crate::xlog_warn!( + "D3D12.X: root argument write past its parameter: {} parameter {i} offset {offset} dwords: {} dwords written, {} fit; table {} dwords", + if gfx { "graphics" } else { "compute" }, + shape.3, + shape.4, + shape.5 + ); + } + } if write_end > at { if let Some(t) = args.get_mut(at..write_end) { t.copy_from_slice(&bytes[..write_end - at]);