Record and replay a frame's D3D12 work (diagnostics builds)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
localandClaude Opus 5.5 committed 2026-11-24 20:00:23 -06:00
1 parent eca1d231e3
commit 59a556e4b0
15 files changed
+8270 -7

No files matched your search

+23 -6
View File
@@ -178,6 +178,27 @@ fn save_as(name: &str, width: u32, height: u32, pitch: usize, bgra: bool, rows:
}
}
}
let png = encode(w, h, &raw);
let path = folder.join(format!("{name}.png"));
match std::fs::write(&path, png) {
Ok(()) => tracing::info!(path = %path.display(), "frame saved"),
Err(e) => tracing::warn!(error = %e, path = %path.display(), "frame not saved"),
}
}
/// A PNG of `width * height` pixels of 8-bit RGB.
pub(crate) fn png(width: u32, height: u32, rgb: &[u8]) -> Vec<u8> {
let row = width as usize * 3;
let mut raw = Vec::with_capacity((row + 1) * height as usize);
for line in rgb.chunks_exact(row.max(1)) {
raw.push(0);
raw.extend_from_slice(line);
}
encode(width, height, &raw)
}
/// A PNG of rows of RGB, each behind its filter byte.
fn encode(w: u32, h: u32, raw: &[u8]) -> Vec<u8> {
let mut png = b"\x89PNG\r\n\x1a\n".to_vec();
let mut header = Vec::new();
header.extend(w.to_be_bytes());
@@ -185,15 +206,11 @@ fn save_as(name: &str, width: u32, height: u32, pitch: usize, bgra: bool, rows:
header.extend([8, 2, 0, 0, 0]); // 8-bit RGB
chunk(&mut png, b"IHDR", &header);
let mut compressed = vec![0u8; zlib_rs::compress_bound(raw.len())];
let (idat, rc) = zlib_rs::compress_slice(&mut compressed, &raw, zlib_rs::DeflateConfig::new(3));
let (idat, rc) = zlib_rs::compress_slice(&mut compressed, raw, zlib_rs::DeflateConfig::new(3));
debug_assert_eq!(rc, zlib_rs::ReturnCode::Ok);
chunk(&mut png, b"IDAT", idat);
chunk(&mut png, b"IEND", &[]);
let path = folder.join(format!("{name}.png"));
match std::fs::write(&path, png) {
Ok(()) => tracing::info!(path = %path.display(), "frame saved"),
Err(e) => tracing::warn!(error = %e, path = %path.display(), "frame not saved"),
}
png
}
fn chunk(png: &mut Vec<u8>, kind: &[u8; 4], data: &[u8]) {