diff --git a/README.md b/README.md index 3f76544f6a..d23e6dac7a 100644 --- a/README.md +++ b/README.md @@ -400,6 +400,9 @@ 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`). +- With `XCL_PIX=1`, those pipeline binds are also D3D12 marker operations whose text contains + the same console shader hashes, so a PIX GPU capture can be matched to XCL shader dumps. + This marker path uses D3D12 directly and does not require WinPixEventRuntime. - `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/dred.rs b/crates/xcl/src/hle/d3d12x/dred.rs index 4eef23183e..ce7e6cbf07 100644 --- a/crates/xcl/src/hle/d3d12x/dred.rs +++ b/crates/xcl/src/hle/d3d12x/dred.rs @@ -1,9 +1,11 @@ -//! `XCL_DRED=1`: which translated pipeline a command list had bound where the GPU faulted. +//! `XCL_DRED=1` / `XCL_PIX=1`: which translated pipeline a command list had bound. //! //! DRED's breadcrumbs give the operations a list got through, not which pipeline was bound, so //! a page fault in a translated shader names no console shader. With `XCL_DRED=1` every //! `SetPipelineState` XCL records for the title is followed by a `SetMarker`, and XCL keeps the -//! pipeline's label (its console shaders' hashes) in the list's order. The runtime kept no +//! pipeline's label (its console shaders' hashes) in the list's order. `XCL_PIX=1` puts that +//! label in the marker text so a PIX GPU capture names the console shaders at each bind. +//! The runtime kept no //! marker text here (breadcrumb contexts came back empty: Windows 26300, NVIDIA 621.40), but it //! records each marker as an operation, so the markers before the operation DRED stopped at //! give the label bound there. DRED's count can lag behind the GPU (NVIDIA: a fault in the @@ -34,7 +36,7 @@ thread_local! { pub fn on() -> bool { static ON: OnceLock = OnceLock::new(); - *ON.get_or_init(|| std::env::var_os("XCL_DRED").is_some()) + *ON.get_or_init(|| std::env::var_os("XCL_DRED").is_some() || std::env::var_os("XCL_PIX").is_some()) } /// Name a translated pipeline by its console shaders (`("ms", bytes)`, …). @@ -50,6 +52,10 @@ pub(super) fn label_of(pso: usize) -> Option { LABELS.lock().unwrap().as_ref()?.get(&pso).cloned() } +fn marker_text(label: &str) -> Vec { + format!("xcl {label}").encode_utf16().chain([0]).collect() +} + /// After `SetPipelineState(pso)` on `list`: a marker, and the label of what is bound now. /// `pso` is the title's object, `bound` what reached the PC list (a stand-in while it builds). pub unsafe fn mark_pipeline(list: *mut c_void, pso: usize, bound: usize) { @@ -62,13 +68,13 @@ pub unsafe fn mark_pipeline(list: *mut c_void, pso: usize, bound: usize) { .or_else(|| super::pso_async::describe(pso)) .unwrap_or_else(|| format!("pipeline {pso:#x} (a stand-in, or not translated)")); let first = !MARKS.lock().unwrap().as_ref().and_then(|m| m.get(&(list as usize))).and_then(|r| r.last()).is_some_and(|v| v.iter().any(Option::is_some)); - push(list as usize, Some(text)); + push(list as usize, Some(text.clone())); if let Some(l) = ID3D12GraphicsCommandList::from_raw_borrowed(&list) { // DRED's node may give the list's name and not its pointer (NVIDIA, Windows 26300) if first { let _ = l.SetName(&windows::core::HSTRING::from(format!("xcl list {:#x}", list as usize))); } - let w: Vec = "xcl pipeline".encode_utf16().chain([0]).collect(); + let w = marker_text(&text); OWN_MARKER.with(|f| f.set(true)); l.SetMarker(0, Some(w.as_ptr() as *const c_void), (w.len() * 2) as u32); OWN_MARKER.with(|f| f.set(false)); @@ -210,6 +216,13 @@ pub fn bound_at(list: usize, history: &[i32], done: usize) -> Option { mod tests { use super::*; + #[test] + fn pix_marker_contains_the_pipeline_label_as_terminated_utf16() { + let marker = marker_text("vs 0123456789abcdef ps fedcba9876543210"); + assert_eq!(marker.last(), Some(&0)); + assert_eq!(String::from_utf16(&marker[..marker.len() - 1]).unwrap(), "xcl vs 0123456789abcdef ps fedcba9876543210"); + } + #[test] fn a_fault_in_an_earlier_recording_finds_that_recording() { // the list was Reset and recorded again while its first submission (2 markers) ran diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs index 6fcaf053c6..8493d4f684 100644 --- a/crates/xcl/src/hle/d3d12x/real.rs +++ b/crates/xcl/src/hle/d3d12x/real.rs @@ -11282,7 +11282,7 @@ unsafe extern "system" fn cl_execute_bundle(this: *mut c_void, bundle: *mut c_vo f(this, bundle); } -/// The title's markers are counted for `XCL_DRED=1`'s pipeline labels (`dred`). +/// The title's markers are counted for `XCL_DRED=1` / `XCL_PIX=1` pipeline labels (`dred`). unsafe extern "system" fn cl_set_marker(this: *mut c_void, metadata: u32, data: *const c_void, size: u32) { type F = unsafe extern "system" fn(*mut c_void, u32, *const c_void, u32); let f: F = std::mem::transmute(orig_fn(this, slot_of(this, "SetMarker")));