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 @@ -154,6 +154,9 @@ xcl rpf D:\data\shaders.rpf --extract NAME --out folder
(decoded 8-bit R+G+B > 30). The field is `null` until a frame is sampled; `non_dark_samples` is
`null` if its format cannot be decoded. Intermediate render-target dumps do not update it.
Sampling uses every fourth pixel in each direction (`XCL_FRAME_DUMP_FULL=1`: every pixel).
`XCL_DUMP_TARGETS=<draws>[,<frames>]` logs, for the first frames with that many draws and dispatches,
each render target and the depth buffer drawn into (draws ran / stand-in / PC / skipped) and dumps
the eight drawn into most (`target<k>_<n>.bmp`); `XCL_DUMP_AFTER_S=<s>` waits `s` seconds first.
A coarse sample can miss detail; a non-dark sample does not establish correct rendering or gameplay.
- Title data: `%LOCALAPPDATA%\XCL\<title>\` (`%XCL_DATA_ROOT%`): `xcl.toml`, `overlay\`, `saves\`,
`pls\` (the title's `S:\`), `temp\` (`T:\`), `cache\`, `logs\xcl.log`, `logs\report.json` (the
Expand Down
24 changes: 24 additions & 0 deletions crates/xcl/src/hle/d3d12x/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ pub(super) unsafe extern "system" fn execute_indirect(this: *mut c_void, sig: us
// doesn't match the currently set Pipeline State Object"; a retail title's world then
// hung the GPU, 0x887a0006). Skipped, like a draw or dispatch of such a pipeline.
if super::pso_async::is_pending(with(this, |s| s.pso)) {
ei_work(this, sig, super::targets::STANDIN);
count(DRAWS_SKIPPED);
static N: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
if N.fetch_add(1, Ordering::Relaxed) < 4 {
Expand All @@ -275,6 +276,7 @@ pub(super) unsafe extern "system" fn execute_indirect(this: *mut c_void, sig: us
// can still be XCL's ABI one from a translated dispatch before it (debug layer 953).
// A native PC compute pipeline is not one of these and still goes to the PC call.
if signature_dispatches(sig) && super::real::is_console_compute(pso) {
super::targets::note_dispatch();
count(DISPATCHES_SKIPPED);
static N: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
if N.fetch_add(1, Ordering::Relaxed) < 4 {
Expand All @@ -287,9 +289,11 @@ pub(super) unsafe extern "system" fn execute_indirect(this: *mut c_void, sig: us
if let (Some(list), Some(r)) = (ID3D12GraphicsCommandList::from_raw_borrowed(&this), ID3D12RootSignature::from_raw_borrowed(&rs)) {
list.SetGraphicsRootSignature(r);
}
ei_work(this, sig, super::targets::PC);
return fresh_indirect_arguments(this, || pc(this, sig, max, args, args_off, count_buf, count_off));
}
if ROOT_SIGNATURES.lock().unwrap().as_ref().is_some_and(|s| s.contains(&sig)) {
ei_work(this, sig, super::targets::SKIPPED);
static N: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
if N.fetch_add(1, Ordering::Relaxed) < 4 {
crate::xlog_warn!("D3D12.X: ExecuteIndirect that changes root arguments with a translated pipeline skipped");
Expand All @@ -299,10 +303,12 @@ pub(super) unsafe extern "system" fn execute_indirect(this: *mut c_void, sig: us
let Some(list) = ID3D12GraphicsCommandList::from_raw_borrowed(&this) else { return };
match bind_abi(this, list, pso, gfx) {
Ok(()) => {
ei_work(this, sig, super::targets::RAN);
count(if gfx { DRAWS } else { DISPATCHES });
fresh_indirect_arguments(this, || pc(this, sig, max, args, args_off, count_buf, count_off))
}
Err(e) => {
ei_work(this, sig, super::targets::SKIPPED);
count(if gfx { DRAWS_SKIPPED } else { DISPATCHES_SKIPPED });
static N: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
if N.fetch_add(1, Ordering::Relaxed) < 4 {
Expand All @@ -312,6 +318,18 @@ pub(super) unsafe extern "system" fn execute_indirect(this: *mut c_void, sig: us
}
}

/// `XCL_DUMP_TARGETS`: an ExecuteIndirect with `outcome` (a dispatch signature's: a dispatch)
unsafe fn ei_work(this: *mut c_void, sig: usize, outcome: usize) {
if !super::targets::enabled() {
return;
}
if signature_dispatches(sig) {
super::targets::note_dispatch();
} else {
super::targets::note_draw(this, outcome);
}
}

/// XCL's own buffer for `fresh_indirect_arguments` (device, buffer): COMMON between its uses
static ARGUMENT_ORDER: Mutex<Option<(usize, ID3D12Resource)>> = Mutex::new(None);

Expand Down Expand Up @@ -497,6 +515,9 @@ unsafe fn graphics_bound(this: *mut c_void) -> Option<ID3D12GraphicsCommandList>
let pso = with(this, |s| s.pso);
// a pipeline still being built in the background is waited for (its stand-in draws nothing)
if !super::real::is_translated_graphics(super::pso_async::resolve_wait(pso)) {
if super::targets::enabled() {
super::targets::note_draw(this, if super::pso_async::is_pending(pso) { super::targets::STANDIN } else { super::targets::PC });
}
count(DRAWS_PC);
if super::present::trace_frame() {
// which pipelines draw without a translation (first 12 distinct)
Expand Down Expand Up @@ -527,10 +548,12 @@ unsafe fn graphics_bound(this: *mut c_void) -> Option<ID3D12GraphicsCommandList>
}
match bind_abi(this, &list, pso, true) {
Ok(()) => {
super::targets::note_draw(this, super::targets::RAN);
count(DRAWS);
Some(list)
}
Err(e) => {
super::targets::note_draw(this, super::targets::SKIPPED);
count(DRAWS_SKIPPED);
static N: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
if N.fetch_add(1, std::sync::atomic::Ordering::Relaxed) < 4 {
Expand Down Expand Up @@ -801,6 +824,7 @@ pub(super) unsafe extern "system" fn set_pipeline_state(this: *mut c_void, pso:

/// #14 Dispatch: with a translated pipeline, on XCL's ABI with the kept root arguments
pub(super) unsafe extern "system" fn dispatch(this: *mut c_void, x: u32, y: u32, z: u32) {
super::targets::note_dispatch();
let pso = super::pso_async::resolve_wait(with(this, |s| s.pso));
let Some(list) = ID3D12GraphicsCommandList::from_raw_borrowed(&this) else { return };
if !super::real::is_translated_compute(pso) {
Expand Down
18 changes: 18 additions & 0 deletions crates/xcl/src/hle/d3d12x/list_x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,24 @@ pub(super) unsafe fn note_render_targets(this: *mut c_void, n: u32, rtvs: *const
with_bindings(this, |b| b.render_targets = Some(RenderTargets { num_targets, handles, single, dsv: d }));
}

/// The render target views bound on `list` (each one of a single descriptor range too).
pub(super) unsafe fn bound_render_targets(list: *mut c_void) -> Vec<usize> {
static INC: AtomicU32 = AtomicU32::new(0);
let Some(rt) = LISTS.lock().unwrap().as_ref().and_then(|m| m.get(&(list as usize))).and_then(|s| s.bindings.render_targets.clone()) else {
return Vec::new();
};
if rt.single == 0 || rt.num_targets <= 1 {
return rt.handles;
}
let Some(&base) = rt.handles.first() else { return Vec::new() };
let mut inc = INC.load(Ordering::Relaxed) as usize;
if inc == 0 {
inc = device_of(list).map_or(0, |d| d.GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV) as usize);
INC.store(inc as u32, Ordering::Relaxed);
}
(0..rt.num_targets as usize).map(|i| base + i * inc).collect()
}

/// Set again what `b` holds (after KickoffX's Reset or a deferred mid-list split).
unsafe fn restore_bindings(this: *mut c_void, b: &Bindings, ty: D3D12_COMMAND_LIST_TYPE) {
if ty == D3D12_COMMAND_LIST_TYPE_COPY {
Expand Down
1 change: 1 addition & 0 deletions crates/xcl/src/hle/d3d12x/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub mod pso_async;
pub mod real;
mod shader_cache_session;
pub mod sparse;
mod targets;
pub mod title_list;
pub mod title_textures;
pub mod vram;
Expand Down
28 changes: 27 additions & 1 deletion crates/xcl/src/hle/d3d12x/present.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub unsafe extern "system" fn present_x(queue: *mut c_void, plane_count: u32, pl

unsafe fn present_x_frame(queue: *mut c_void, plane_count: u32, planes: *const u8) {
let frames = BOUNDARIES.fetch_add(1, Ordering::Relaxed) + 1;
super::targets::frame_end();
if frames % 300 == 0 {
// the title's frame rate, for comparing runs (every 300 frames)
static LAST: Mutex<Option<std::time::Instant>> = Mutex::new(None);
Expand Down Expand Up @@ -202,6 +203,15 @@ pub fn rtv_resource(handle: usize) -> Option<usize> {
RTVS.lock().unwrap().as_ref()?.get(&handle).copied()
}

/// The resource `r` while a view still names it (AddRef'd), for `XCL_DUMP_TARGETS`.
pub(super) unsafe fn view_resource(r: usize) -> Option<ID3D12Resource> {
let g = RTVS.lock().unwrap();
if !g.as_ref()?.values().any(|&v| v == r) {
return None;
}
ID3D12Resource::from_raw_borrowed(&(r as *mut c_void)).cloned()
}

/// The resource bound as render target 0 on `list` (`XCL_TRACE_FRAME`).
pub fn rt0_resource(list: usize) -> Option<usize> {
let h = *LISTS.lock().unwrap().as_ref()?.get(&list)?;
Expand Down Expand Up @@ -695,8 +705,18 @@ unsafe fn present_now(min_interval: Duration, frame: Option<(usize, usize)>) {
let b1 = [transition(&bb, D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_COPY_DEST)];
p.list.ResourceBarrier(&b1);
p.list.CopyResource(&bb, &src);
let due = frame_dump_due();
// `XCL_DUMP_TARGETS`: a busy frame's render targets go with its picture (copied in the
// state the title left them, as `XCL_TRACE_FRAME`'s; its frame dump is also the
// `last_frame_dump` of the report)
let targets = super::targets::take_pending();
let dumping_targets = targets.is_some();
let due = frame_dump_due() || dumping_targets;
let mut dumps = Vec::new();
for (tag, res, d) in targets.map_or(Vec::new(), |f| super::targets::to_dump(PRESENTS.load(Ordering::Relaxed), &f)) {
if let Some((buffer, footprint)) = readback_copy(&p.list, &res, &d) {
dumps.push(FrameDump { _source: res, buffer, footprint, format: d.Format, tag });
}
}
if due {
if let Some((buffer, footprint)) = readback_copy(&p.list, &src, &desc) {
dumps.push(FrameDump { _source: src.clone(), buffer, footprint, format: desc.Format, tag: "frame".into() });
Expand Down Expand Up @@ -744,6 +764,9 @@ unsafe fn present_now(min_interval: Duration, frame: Option<(usize, usize)>) {
crate::xlog_error!("present: submit copy: {e}");
return;
}
if dumping_targets {
super::targets::submitted();
}
if let Err(e) = sc.Present(0, DXGI_PRESENT(0)).ok() {
let e = fence::api_error(&p.dev, "Present", e);
p.disabled = matches!(&e, FenceError::Removed(_));
Expand All @@ -755,6 +778,9 @@ unsafe fn present_now(min_interval: Duration, frame: Option<(usize, usize)>) {
match fence::wait(&p.fence, p.value, &p.dev, Some(p.event), 2000) {
Ok(()) => {
for dump in p.dumps.drain(..) {
if dump.tag.starts_with("target") {
super::targets::log_census(&dump.buffer, &dump.footprint, &dump.tag);
}
write_frame(&dump.buffer, &dump.footprint, dump.format, &dump.tag);
}
}
Expand Down
5 changes: 5 additions & 0 deletions crates/xcl/src/hle/d3d12x/real.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1971,6 +1971,11 @@ unsafe extern "system" fn dev_create_dsv_x(this: *mut c_void, res: *mut c_void,
if copy.is_none() {
copy = ID3D12Resource::from_raw_borrowed(&res).and_then(|r| default_dsv(&r.GetDesc()));
}
// `XCL_DUMP_TARGETS`: the depth buffer a DSV names, kept with the RTVs' resources (DSV
// and RTV handles are in different heaps)
if super::targets::enabled() {
super::present::note_rtv(cpu as usize, res);
}
f(this, res, copy.as_ref().map_or(desc, |c| c as *const _), cpu)
}

Expand Down
Loading
Loading