This commit is contained in:
ivall
2026-11-23 22:06:36 +01:00
3 changed files with 127 additions and 0 deletions
+7
View File
@@ -125,6 +125,13 @@ xcl rpf D:\data\shaders.rpf --extract NAME --out folder
- **The game folder is never modified** – writes go to the overlay.
- 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`),
the existing optional frame dumps also set `d3d12.last_frame_dump`: the latest sampled frame's
zero-based index, source dimensions, DXGI format, sample step, sample count and `non_dark_samples`
(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).
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
previous run's: `xcl.prev.log`, `report.prev.json`).
+116
View File
@@ -38,6 +38,7 @@ static RTVS: Mutex<Option<HashMap<usize, usize>>> = Mutex::new(None);
static LISTS: Mutex<Option<HashMap<usize, usize>>> = Mutex::new(None);
static CANDIDATE: Mutex<Option<(usize, usize)>> = Mutex::new(None); // (queue, resource) – resource AddRef'd
static PRESENTS: AtomicU64 = AtomicU64::new(0);
static LAST_FRAME_DUMP: Mutex<Option<FrameDumpSample>> = Mutex::new(None);
static BOUNDARIES: AtomicU64 = AtomicU64::new(0);
static LAST_BOUNDARY_MS: AtomicU64 = AtomicU64::new(0);
static HWND_RAW: AtomicIsize = AtomicIsize::new(0);
@@ -754,6 +755,25 @@ pub fn presents() -> u64 {
PRESENTS.load(Ordering::Relaxed)
}
/// Content sampled by an existing `XCL_FRAME_DUMP` readback, not proof of gameplay.
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct FrameDumpSample {
/// Zero-based presentation index, as in `frame_<n>.bmp`.
pub frame: u64,
pub width: u32,
pub height: u32,
pub format: i32,
/// One texel every `sample_step` pixels in each direction (normally 4).
pub sample_step: u32,
pub sampled_pixels: u64,
/// Samples whose decoded 8-bit R+G+B exceeds 30; None for an undecoded format.
pub non_dark_samples: Option<u64>,
}
pub fn last_frame_dump() -> Option<FrameDumpSample> {
LAST_FRAME_DUMP.lock().ok().and_then(|s| *s)
}
/// a copy of subresource 0 of `src` into a new readback buffer, recorded on `list`
unsafe fn readback_copy(list: &ID3D12GraphicsCommandList, src: &ID3D12Resource, desc: &D3D12_RESOURCE_DESC) -> Option<(ID3D12Resource, D3D12_PLACED_SUBRESOURCE_FOOTPRINT)> {
let dev: ID3D12Device = {
@@ -907,6 +927,20 @@ unsafe fn write_frame(rb: &ID3D12Resource, fp: &D3D12_PLACED_SUBRESOURCE_FOOTPRI
}
rb.Unmap(0, None);
let n = PRESENTS.load(Ordering::Relaxed);
// `XCL_TRACE_FRAME` also dumps intermediate targets; only the presented image belongs here.
if tag == "frame" {
if let Ok(mut last) = LAST_FRAME_DUMP.lock() {
*last = Some(FrameDumpSample {
frame: n,
width: w as u32,
height: h as u32,
format: format.0,
sample_step: step as u32,
sampled_pixels: (ow * oh) as u64,
non_dark_samples: decoded.then_some(lit as u64),
});
}
}
let Some(boot) = crate::state::boot() else { return };
let path = boot.logs_dir().join(format!("{tag}_{n}.bmp"));
let _ = std::fs::write(&path, &bmp);
@@ -969,3 +1003,85 @@ mod tests {
}
}
}
#[cfg(test)]
mod frame_dump_tests {
use super::*;
use super::super::real::D3d12Stats;
use windows::Win32::Graphics::Direct3D::D3D_FEATURE_LEVEL_11_0;
#[test]
fn reports_without_frame_dumps_remain_readable() {
let stats = D3d12Stats { presents: 100, ..Default::default() };
let mut json = serde_json::to_value(&stats).unwrap();
assert!(json["last_frame_dump"].is_null(), "presents alone do not establish content");
json.as_object_mut().unwrap().remove("last_frame_dump");
let old: D3d12Stats = serde_json::from_value(json).unwrap();
assert_eq!(old.presents, 100);
assert_eq!(old.last_frame_dump, None);
}
#[test]
fn mapped_frame_dump_distinguishes_dark_bright_and_undecoded_content() {
unsafe {
// WARP needs no physical GPU. Fill a CPU-visible buffer with the same padded
// footprint used by a readback, so this exercises write_frame's actual decoder.
let factory: IDXGIFactory4 = CreateDXGIFactory2(DXGI_CREATE_FACTORY_FLAGS(0)).unwrap();
let adapter: IDXGIAdapter = factory.EnumWarpAdapter().unwrap();
let mut dev: Option<ID3D12Device> = None;
D3D12CreateDevice(&adapter, D3D_FEATURE_LEVEL_11_0, &mut dev).unwrap();
let dev = dev.unwrap();
let desc = D3D12_RESOURCE_DESC {
Dimension: D3D12_RESOURCE_DIMENSION_BUFFER,
Width: 512 + 256 * 8,
Height: 1,
DepthOrArraySize: 1,
MipLevels: 1,
SampleDesc: DXGI_SAMPLE_DESC { Count: 1, Quality: 0 },
Layout: D3D12_TEXTURE_LAYOUT_ROW_MAJOR,
..Default::default()
};
let mut buffer: Option<ID3D12Resource> = None;
dev.CreateCommittedResource(
&D3D12_HEAP_PROPERTIES { Type: D3D12_HEAP_TYPE_UPLOAD, ..Default::default() },
D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_GENERIC_READ, None, &mut buffer,
).unwrap();
let buffer = buffer.unwrap();
let fp = D3D12_PLACED_SUBRESOURCE_FOOTPRINT {
Offset: 512,
Footprint: D3D12_SUBRESOURCE_FOOTPRINT {
Format: DXGI_FORMAT_R8G8B8A8_UNORM, Width: 8, Height: 8, Depth: 1, RowPitch: 256,
},
};
let fill = |red: u8| {
let mut p: *mut c_void = std::ptr::null_mut();
buffer.Map(0, None, Some(&mut p)).unwrap();
let bytes = std::slice::from_raw_parts_mut(p as *mut u8, desc.Width as usize);
bytes.fill(255); // padding must not be counted as bright pixels
for y in 0..8 {
for x in 0..8 {
let start = 512 + y * 256 + x * 4;
bytes[start..start + 4].copy_from_slice(&[red, 0, 0, 255]);
}
}
buffer.Unmap(0, None);
};
fill(30);
write_frame(&buffer, &fp, fp.Footprint.Format, "frame");
let dark = last_frame_dump().unwrap();
assert_eq!((dark.width, dark.height, dark.format), (8, 8, 28));
assert_eq!(dark.sampled_pixels, (8 / dark.sample_step).pow(2) as u64);
assert_eq!(dark.non_dark_samples, Some(0));
fill(31);
write_frame(&buffer, &fp, fp.Footprint.Format, "rt");
assert_eq!(last_frame_dump(), Some(dark), "intermediate targets must not replace frame content");
write_frame(&buffer, &fp, fp.Footprint.Format, "frame");
let bright = last_frame_dump().unwrap();
assert_eq!(bright.non_dark_samples, Some(bright.sampled_pixels));
write_frame(&buffer, &fp, DXGI_FORMAT_R32_FLOAT, "frame");
let json = serde_json::to_value(last_frame_dump().unwrap()).unwrap();
assert!(json["non_dark_samples"].is_null(), "undecoded is different from dark");
}
}
}
+4
View File
@@ -103,6 +103,9 @@ pub struct D3d12Stats {
pub fallback_root_signatures: u64,
pub presents: u64,
pub frame_boundaries: u64,
/// Optional content evidence from the existing frame-dump readback; no new GPU readback.
#[serde(default)]
pub last_frame_dump: Option<super::present::FrameDumpSample>,
/// unified memory region opened as a GPU heap (`gpu::uma`): size, bytes in use, buffer VA
#[serde(default)]
pub uma_mb: u64,
@@ -292,6 +295,7 @@ pub fn stats() -> D3d12Stats {
fallback_root_signatures: FALLBACK_RS.load(Ordering::Relaxed),
presents,
frame_boundaries: boundaries,
last_frame_dump: super::present::last_frame_dump(),
uma_mb: crate::gpu::uma::get().map(|u| (u.size() >> 20) as u64).unwrap_or(0),
uma_used_kb: crate::gpu::uma::get().map(|u| (u.used() >> 10) as u64).unwrap_or(0),
uma_gpu_va: match uma_gpu_va() {