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 @@ -144,6 +144,9 @@ xcl rpf D:\data\shaders.rpf --extract NAME --out folder
- `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.
- With `XCL_STALL_DUMP=N`, a title that has presented frames and then presents none for N seconds
gets every thread's stack in `xcl.log` (twice, a second apart), then ends as with
`XCL_RUN_SECONDS`: a stalled frame loop is caught before the title's own watchdog ends it.
- Every run writes `report.json` (called stubs, unknown D3D12.X slots and interfaces, XGameRuntime
classes asked for, shader statistics, audio formats, crash).
`d3d12.presents` counts presentations, not visible content. With `XCL_FRAME_DUMP=N` (`N > 1`),
Expand Down
62 changes: 62 additions & 0 deletions crates/xcl/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,34 @@ pub fn host_main(boot_path: &Path) -> i32 {
}
});
}
// `XCL_STALL_DUMP=n`: once the title has presented frames and then presents none for n
// seconds (a stalled frame loop), where every thread is goes to the log – twice, a second
// apart, to tell stuck threads from moving ones – and the title ends as for
// `XCL_RUN_SECONDS`: a stall diagnosed without waiting for the title's own watchdog.
if let Some(secs) = stall_seconds(std::env::var("XCL_STALL_DUMP").ok().as_deref()) {
let _ = std::thread::Builder::new().name("xcl-stall-dump".into()).spawn(move || {
let mut last = crate::hle::d3d12x::present::presents();
let mut since = std::time::Instant::now();
loop {
std::thread::sleep(std::time::Duration::from_millis(250));
let now = crate::hle::d3d12x::present::presents();
if now != last {
(last, since) = (now, std::time::Instant::now());
continue;
}
if !stalled(last, since.elapsed(), secs) {
continue;
}
crate::xlog_warn!("XCL_STALL_DUMP: no frame presented for {secs} s after frame {last} – where every thread is, then the end");
crate::eh::dump_threads();
std::thread::sleep(std::time::Duration::from_secs(1));
crate::eh::dump_threads();
crate::report::write_final(None);
crate::log::flush();
crate::hle::d3d12x::real::end_title(0);
}
});
}
// `XCL_RUN_SECONDS=n`: the title ends itself after n seconds – the GPU drained, the log and
// report written (a process killed from outside with GPU work in flight can hang in the driver)
if let Some(secs) = std::env::var("XCL_RUN_SECONDS").ok().and_then(|v| v.parse::<u64>().ok()) {
Expand Down Expand Up @@ -146,3 +174,37 @@ pub fn host_main(boot_path: &Path) -> i32 {
crate::log::flush();
code as i32
}

/// `XCL_STALL_DUMP`'s value: seconds without a frame, if it is a positive number.
fn stall_seconds(value: Option<&str>) -> Option<f64> {
value.and_then(|v| v.trim().parse::<f64>().ok()).filter(|s| s.is_finite() && *s > 0.0)
}

/// Whether the title has stalled for `XCL_STALL_DUMP`: it has presented a frame (`last` is the
/// count seen) and no other for `secs`. A title still at its first frame has not.
fn stalled(last: u64, idle: std::time::Duration, secs: f64) -> bool {
last > 0 && idle.as_secs_f64() >= secs
}

#[cfg(test)]
mod tests {
use super::*;
use std::time::Duration;

#[test]
fn stall_dump_takes_a_positive_number_of_seconds() {
assert_eq!(stall_seconds(Some("6")), Some(6.0));
assert_eq!(stall_seconds(Some(" 2.5 ")), Some(2.5));
for v in [None, Some(""), Some("0"), Some("-3"), Some("abc"), Some("inf"), Some("NaN")] {
assert_eq!(stall_seconds(v), None, "{v:?}");
}
}

#[test]
fn a_stall_needs_a_presented_frame_and_the_full_wait() {
assert!(!stalled(0, Duration::from_secs(600), 6.0), "no frame presented yet");
assert!(!stalled(940, Duration::from_millis(5_999), 6.0));
assert!(stalled(940, Duration::from_secs(6), 6.0));
assert!(stalled(1, Duration::from_secs(60), 6.0));
}
}
Loading