diff --git a/README.md b/README.md index 3f76544f6a..49bfc2626e 100644 --- a/README.md +++ b/README.md @@ -400,6 +400,10 @@ Fill the reusable DXIL cache ahead of a run with the read-only package wrapper. 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`). +- 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_TEXTURE_LEVEL_PAGES=1` gives sampled title textures backing as their mip levels stream in. Zero-filled mip uploads in a batch share one staging span and still clear any mapped tiles. - `XCL_DSTORAGE_PARALLEL_DECOMPRESS=1` enables parallel CPU decompression for file-backed zlib diff --git a/crates/xcl/src/hle/d3d12x/bind.rs b/crates/xcl/src/hle/d3d12x/bind.rs index 7938495b9f..a95cf2d240 100644 --- a/crates/xcl/src/hle/d3d12x/bind.rs +++ b/crates/xcl/src/hle/d3d12x/bind.rs @@ -962,6 +962,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 { loop { let entry = state_entry(list as usize); @@ -3790,6 +3817,10 @@ unsafe fn execute_indirect_snapshot( } return; } + if gfx && debug_skip_shader_draw(pso) { + count(DRAWS_SKIPPED); + return; + } let Some(list) = ID3D12GraphicsCommandList::from_raw_borrowed(&this) else { return }; if !gfx && super::real::skip_named_cs(pso) { return; @@ -4238,6 +4269,10 @@ unsafe fn graphics_bound(this: *mut c_void) -> Option<(ID3D12GraphicsCommandList } return Some((list, real)); } + if debug_skip_shader_draw(pso) { + count(DRAWS_SKIPPED); + return None; + } if super::present::trace_frame() { trace_ui_draw(this, pso, real, false); } @@ -5509,6 +5544,12 @@ mod tests { assert!(left_out([0x3F80_0000, 1, 1], [0, 0, 0]) && !left_out([0, 5, 1], [0, 0, 0]) && !left_out([70_000, 2, 1], [65_535, 2, 1])); } + #[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() {