From 72e94879f2680935608975a993e1663889c66838 Mon Sep 17 00:00:00 2001 From: mokkamokacaffe <329663686+mokkamokacaffe@users.noreply.github.com> Date: Wed, 25 Nov 2026 23:55:17 +0100 Subject: [PATCH] Diagnostics: label translated pipelines in PIX captures --- README.md | 3 +++ crates/xcl/src/hle/d3d12x/dred.rs | 23 ++++++++++++++++++----- crates/xcl/src/hle/d3d12x/real.rs | 2 +- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e966a88b65..aa9b95c8e8 100644 --- a/README.md +++ b/README.md @@ -279,6 +279,9 @@ xcl rpf D:\data\shaders.rpf --extract NAME --out folder 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_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/dred.rs b/crates/xcl/src/hle/d3d12x/dred.rs index 85bb784bdf..d9a7006618 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 @@ 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) { @@ -59,13 +65,13 @@ pub unsafe fn mark_pipeline(list: *mut c_void, pso: usize, bound: usize) { // nothing labelled: a stand-in still building, or a pipeline of PC shaders let text = label_of(bound).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)); @@ -159,6 +165,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 91085d3933..b08d5f5d1f 100644 --- a/crates/xcl/src/hle/d3d12x/real.rs +++ b/crates/xcl/src/hle/d3d12x/real.rs @@ -6883,7 +6883,7 @@ unsafe extern "system" fn cl_set_pipeline_state(this: *mut c_void, pso: *mut c_v super::list_x::on_set_pipeline_state(this, pso as usize); } -/// 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")));