Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 18 additions & 5 deletions crates/xcl/src/hle/d3d12x/dred.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -34,7 +36,7 @@ thread_local! {

pub fn on() -> bool {
static ON: OnceLock<bool> = 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())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XCL_PIX=1 now activates DRED's MARKS recording even when XCL_DRED is unset, but the console-list Reset and KickoffX paths still do not start a new recording. On multi-frame captures, marker history can therefore carry across resets and grow. Open PR #2510 already adds the missing recording restart and initial-pipeline marking in those paths. Could #2510 be merged first and this PR refreshed on it, or could the reset wiring be coordinated with its author? A multi-frame marker-history check would cover the combined behavior. This is a source-derived dependency; I did not run a PIX capture.

AI-assisted review: OpenAI Codex (GPT-6; exact serving variant unavailable) and a Luna subagent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — I confirmed the dependency at 72e9487.

XCL_PIX=1 enables the shared MARKS recorder, while list_x::reset_pc and kickoff_x call the native Reset directly and therefore bypass real::cl_reset. Without #2510, those paths keep appending markers to the previous recording, so the per-list history can span frames and the RECORDINGS cap is not applied.

#2510 already provides the appropriate post-successful-Reset wiring, records the initial pipeline, and includes a ten-frame test verifying that only four recordings are retained. I will avoid duplicating that work: this PR will be refreshed on #2510 after it lands, preserving its ON_FOR_TEST hook while extending on() to enable recording for either XCL_DRED or XCL_PIX.

After refreshing, I’ll rerun the combined multi-frame recording test and the PIX marker-text test. I’ll leave this thread open until that integration is present. Thank you for catching the interaction.

AI-assisted review: OpenAI Codex (GPT-6.2 Astra, Ultra reasoning).

}

/// Name a translated pipeline by its console shaders (`("ms", bytes)`, …).
Expand All @@ -50,6 +52,10 @@ pub(super) fn label_of(pso: usize) -> Option<String> {
LABELS.lock().unwrap().as_ref()?.get(&pso).cloned()
}

fn marker_text(label: &str) -> Vec<u16> {
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) {
Expand All @@ -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<u16> = "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));
Expand Down Expand Up @@ -210,6 +216,13 @@ pub fn bound_at(list: usize, history: &[i32], done: usize) -> Option<String> {
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
Expand Down
2 changes: 1 addition & 1 deletion crates/xcl/src/hle/d3d12x/real.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
Expand Down
Loading