From 62197903bc41af638f862be81882eb34af72a3c5 Mon Sep 17 00:00:00 2001 From: mokkamokacaffe <329663686+mokkamokacaffe@users.noreply.github.com> Date: Wed, 25 Nov 2026 00:10:16 +0100 Subject: [PATCH 1/2] D3D12.X: isolate rendering artifacts by shader hash --- README.md | 4 +++ crates/xcl/src/hle/d3d12x/bind.rs | 41 +++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/README.md b/README.md index e35903a1cf..534d5229df 100644 --- a/README.md +++ b/README.md @@ -141,6 +141,10 @@ xcl rpf D:\data\shaders.rpf --extract NAME --out folder - With `XCL_DRED=1`, a D3D12 device removal logs GPU breadcrumbs in `xcl.log`. XCL examines up to 4,096 command lists and reports up to 64 unfinished lists, starting with those on which the GPU completed at least one operation. +- To isolate a rendering artifact, `XCL_TRACE_FRAME=1` logs distinct translated VS/PS hashes and + their render-target context. `XCL_DEBUG_SKIP_SHADERS=hash,...` suppresses draws using selected + VS/PS hashes (including indirect draws); bisect the logged hashes until the artifact disappears. + This is diagnostic only: skipped draws leave holes in the frame and are counted in `xcl.log`. - `XCL_DSTORAGE_PARALLEL_DECOMPRESS=1` enables parallel CPU decompression for file-backed zlib requests with virtual destinations. Defaults: four workers and a shared 32 MiB staging budget (`XCL_DSTORAGE_WORKERS`, `XCL_DSTORAGE_MEMORY_BUDGET_MIB`). Requests retire in queue order. diff --git a/crates/xcl/src/hle/d3d12x/bind.rs b/crates/xcl/src/hle/d3d12x/bind.rs index da5b15ef42..60377c6232 100644 --- a/crates/xcl/src/hle/d3d12x/bind.rs +++ b/crates/xcl/src/hle/d3d12x/bind.rs @@ -65,6 +65,33 @@ fn count(k: usize) { } } +fn shader_hashes(value: &str) -> Vec { + value.split(',').filter_map(|h| u64::from_str_radix(h.trim(), 16).ok()).filter(|&h| h != 0).collect() +} + +/// `XCL_DEBUG_SKIP_SHADERS=hash,...`: do not submit graphics draws whose translated vertex or +/// pixel shader has one of the dump hashes. This is a diagnostic for reducing a visible rendering +/// error to a shader: collect candidates with `XCL_TRACE_FRAME`, then add/remove half of them until +/// the error disappears. The title's draw order and resources are otherwise left alone. +fn debug_skip_shader_draw(pso: usize) -> bool { + static HASHES: std::sync::OnceLock> = std::sync::OnceLock::new(); + let hashes = HASHES.get_or_init(|| shader_hashes(&std::env::var("XCL_DEBUG_SKIP_SHADERS").unwrap_or_default())); + if hashes.is_empty() { + return false; + } + let real = super::pso_async::resolve(pso); + let Some((vs, ps)) = super::real::pso_shaders(real) else { return false }; + if !hashes.contains(&vs) && !hashes.contains(&ps) { + return false; + } + static SKIPPED: AtomicU64 = AtomicU64::new(0); + let n = SKIPPED.fetch_add(1, Ordering::Relaxed) + 1; + if n <= 8 || n.is_power_of_two() { + crate::xlog_info!("D3D12.X: diagnostic skipped draw #{n}: vs {vs:016x}, ps {ps:016x}"); + } + true +} + fn with(list: *mut c_void, f: impl FnOnce(&mut State) -> R) -> R { f(STATES.lock().unwrap().get_or_insert_with(HashMap::new).entry(list as usize).or_default()) } @@ -296,6 +323,10 @@ pub(super) unsafe extern "system" fn execute_indirect(this: *mut c_void, sig: us } return; } + if gfx && debug_skip_shader_draw(pso) { + count(DRAWS_SKIPPED); + return; + } let Some(list) = ID3D12GraphicsCommandList::from_raw_borrowed(&this) else { return }; match bind_abi(this, list, pso, gfx) { Ok(()) => { @@ -522,6 +553,10 @@ unsafe fn graphics_bound(this: *mut c_void) -> Option } return Some(list); } + if debug_skip_shader_draw(pso) { + count(DRAWS_SKIPPED); + return None; + } if super::present::trace_frame() { trace_ui_draw(this, pso); } @@ -1017,6 +1052,12 @@ mod tests { use super::*; use std::sync::atomic::AtomicUsize; + #[test] + fn debug_shader_hash_list_ignores_bad_and_zero_entries() { + assert_eq!(shader_hashes(" 0123456789abcdef, bad!,0, 2A ,,"), vec![0x0123_4567_89ab_cdef, 0x2a]); + assert!(shader_hashes("").is_empty()); + } + /// A pipeline with the rect list GS draws its rect lists whole: draw_rects leaves them alone. #[test] fn rect_lists_with_the_rect_list_gs_are_not_expanded_on_the_cpu() { From c87b0eb5252fff7a01e14d278eb0b9864a55b032 Mon Sep 17 00:00:00 2001 From: mokkamokacaffe Date: Wed, 25 Nov 2026 14:58:48 +0100 Subject: [PATCH 2/2] Clarify GPU breadcrumbs logging in README Updated the README to clarify logging behavior with XCL_DRED. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d2a44c8cdd..c9a71eb21f 100644 --- a/README.md +++ b/README.md @@ -258,7 +258,7 @@ xcl rpf D:\data\shaders.rpf --extract NAME --out folder `XCL_PSO_TRACE=1` logs every driver compile. A huge compute program the driver refuses is logged with the driver's verdict (`the driver refused the compute PSO of record HASH … with 0x…`): its dispatches are skipped. -- XCL examines up to 4,096 command lists and reports up to 64 unfinished lists, starting with +- With XCL_DRED=1, a D3D12 device removal logs GPU breadcrumbs in xcl.log. XCL examines up to 4,096 command lists and reports up to 64 unfinished lists, starting with those on which the GPU completed at least one operation. For each, it names the translated pipeline bound at the last operation DRED saw complete and those bound after it, by their console shaders' hashes (`cs`, `vs` / `ps`, `ms` / `ps`, `vs` / `gs` / `ps`).