From 69e0883d7e61f85c171dac64407319caa68c54d9 Mon Sep 17 00:00:00 2001 From: MadaraXor Date: Wed, 25 Nov 2026 16:32:21 +0100 Subject: [PATCH 1/4] D3D12.X: the capture format of one draw or dispatch A GPU hang in a retail title costs a whole game run per experiment. The plan is to write one draw or dispatch of a named shader to disk during a run and to run it again alone, in seconds (this stack: the format, the hook, the textures, xcl replay). This is the format only: capture::manifest, the manifest.json of a capture folder (the call, shader files, the PC pipeline description, root arguments, fixed-function state, targets, memory ranges, textures, views, samplers, descriptor slots, what was left out) with Manifest::write and Manifest::read. Structures D3D12 gives as plain data are kept as hex of their bytes. Nothing writes a capture yet. Co-Authored-By: Claude Fable 5.2 --- crates/xcl/src/hle/d3d12x/capture.rs | 4 + crates/xcl/src/hle/d3d12x/capture/manifest.rs | 451 ++++++++++++++++++ crates/xcl/src/hle/d3d12x/mod.rs | 1 + 3 files changed, 456 insertions(+) create mode 100644 crates/xcl/src/hle/d3d12x/capture.rs create mode 100644 crates/xcl/src/hle/d3d12x/capture/manifest.rs diff --git a/crates/xcl/src/hle/d3d12x/capture.rs b/crates/xcl/src/hle/d3d12x/capture.rs new file mode 100644 index 0000000000..4261e05750 --- /dev/null +++ b/crates/xcl/src/hle/d3d12x/capture.rs @@ -0,0 +1,4 @@ +//! One draw or dispatch written to disk, to be run again alone on a fresh device: the format +//! of such a capture (`manifest`). Nothing writes one yet. + +pub mod manifest; diff --git a/crates/xcl/src/hle/d3d12x/capture/manifest.rs b/crates/xcl/src/hle/d3d12x/capture/manifest.rs new file mode 100644 index 0000000000..9fde63175e --- /dev/null +++ b/crates/xcl/src/hle/d3d12x/capture/manifest.rs @@ -0,0 +1,451 @@ +//! What a capture of one draw or dispatch is on disk: a folder with `manifest.json` (this +//! module's `Manifest`) and, beside it, the files it names – the console shader containers, +//! `memory.bin` (the ranges of unified memory the call can read, one after the other) and a +//! `tex_.bin` per texture (all its subresources in the layout of `GetCopyableFootprints` +//! from offset 0). Descriptions D3D12 gives as plain structures (the pipeline, views, +//! samplers) are kept as their bytes in hex: a capture is read by the build that wrote it, or +//! one with the same `windows` crate structures. + +use std::path::Path; + +use serde::{Deserialize, Serialize}; + +/// The manifest's file in a capture folder. +pub const FILE: &str = "manifest.json"; +/// `Manifest::version` this build writes and reads. +pub const VERSION: u32 = 1; + +#[derive(Serialize, Deserialize, Clone, Copy, Debug)] +#[serde(tag = "kind")] +pub enum Call { + Draw { vertices: u32, instances: u32, first_vertex: u32, first_instance: u32 }, + DrawIndexed { indices: u32, instances: u32, first_index: u32, base_vertex: i32, first_instance: u32 }, + Dispatch { x: u32, y: u32, z: u32 }, + /// ExecuteIndirect: its arguments are not captured + Indirect { max: u32 }, +} + +#[derive(Serialize, Deserialize, Default, Debug)] +pub struct Shader { + /// "vs", "ps", "gs", "cs" + pub stage: String, + pub hash: String, + pub file: String, +} + +#[derive(Serialize, Deserialize, Default, Debug, Clone)] +pub struct InputElement { + pub name: String, + pub index: u32, + pub format: i32, + pub slot: u32, + pub offset: u32, + pub class: i32, + pub step: u32, +} + +#[derive(Serialize, Deserialize, Default, Debug, Clone)] +pub struct Pso { + /// D3D12_GRAPHICS_PIPELINE_STATE_DESC as the PC pipeline was made with (formats and topology + /// type the PC's), bytes in hex; its pointers mean nothing + pub desc: String, + pub input: Vec, + /// the pipeline got XCL's rect list GS + pub rect_list_gs: bool, +} + +#[derive(Serialize, Deserialize, Default, Debug)] +pub struct RootParam { + /// "constants", "descriptor", "table" + pub kind: String, + pub at: u32, + pub count: u32, + /// table: its 32-bit console address; descriptor: the 64-bit address + pub value: u64, +} + +#[derive(Serialize, Deserialize, Default, Debug)] +pub struct Root { + pub params: Vec, + /// the packed root arguments, hex + pub args: String, + /// bytes of them passed in user SGPRs + pub inline: u32, + /// the `io` buffer (u0): the SGPRs the program starts with + pub io: Vec, + /// where the rest of the arguments was put (unified memory) + pub table_at: u64, +} + +#[derive(Serialize, Deserialize, Default, Debug)] +pub struct Uma { + pub base: u64, + /// (base, size) of each shader window + pub windows: Vec<(u64, u64)>, +} + +#[derive(Serialize, Deserialize, Default, Debug)] +pub struct State { + pub topology: Option, + /// x, y, width, height, min depth, max depth + pub viewports: Vec<[f32; 6]>, + /// left, top, right, bottom + pub scissors: Vec<[i32; 4]>, + pub blend_factor: Option<[f32; 4]>, + pub stencil_ref: Option, +} + +#[derive(Serialize, Deserialize, Default, Debug)] +pub struct Target { + pub handle: u64, + /// index in `textures` (None: XCL does not know the view's resource) + pub texture: Option, + /// the PC view description, hex (None: the default view) + pub desc: Option, +} + +#[derive(Serialize, Deserialize, Default, Debug)] +pub struct VertexBuffer { + pub slot: u32, + /// unified-memory address of what the PC view names (0: not in unified memory) + pub address: u64, + pub size: u32, + pub stride: u32, +} + +#[derive(Serialize, Deserialize, Default, Debug)] +pub struct IndexBuffer { + pub address: u64, + pub size: u32, + pub format: i32, +} + +#[derive(Serialize, Deserialize, Default, Debug)] +pub struct Range { + pub address: u64, + pub len: u64, + pub window: u32, + /// offset in the window + pub offset: u64, + /// offset in `memory_file` + pub file_offset: u64, + pub what: Vec, + /// bytes the CPU could not read (written as zeros) + pub unreadable: u64, +} + +#[derive(Serialize, Deserialize, Default, Debug)] +pub struct Texture { + pub id: usize, + pub resource: String, + pub dimension: i32, + pub width: u64, + pub height: u32, + pub depth_or_array: u16, + pub mips: u16, + pub format: i32, + pub samples: u32, + pub flags: i32, + pub title_address: Option, + /// the D3D12_RESOURCE_STATES the copy took the texture to be in, and why + pub state: u32, + pub state_source: String, + pub uses: Vec, + /// all subresources in the layout of GetCopyableFootprints (base offset 0); None: left out + pub file: Option, + pub bytes: u64, + pub subresources: u32, +} + +#[derive(Serialize, Deserialize, Default, Debug)] +pub struct View { + /// index in the shader-visible heap (an SRV at a T#'s word 0, its UAV at + 1) + pub index: u32, + pub uav: bool, + pub texture: usize, + pub desc: Option, +} + +#[derive(Serialize, Deserialize, Default, Debug)] +pub struct Sampler { + /// index in the sampler heap (an S#'s word 3 [11:0]) + pub index: u32, + /// D3D12_SAMPLER_DESC, hex + pub desc: String, +} + +#[derive(Serialize, Deserialize, Default, Debug)] +pub struct Slot { + pub param: u32, + /// byte offset in the table + pub offset: u32, + pub words: [u32; 8], + /// "image" (T#), "buffer" (V#), "other" + pub kind: String, +} + +#[derive(Serialize, Deserialize, Default, Debug)] +pub struct Manifest { + pub version: u32, + pub hash: String, + pub call_number: u32, + pub call: Option, + pub graphics: bool, + pub shaders: Vec, + /// `pso::mem_windows()` and the split flag the shaders were translated with + pub mem_windows: u32, + pub split_wave64: bool, + pub pso: Option, + pub root: Root, + pub uma: Uma, + pub state: State, + pub targets: Vec, + pub depth: Option, + pub vertex_buffers: Vec, + pub index_buffer: Option, + pub memory_file: String, + pub memory: Vec, + pub textures: Vec, + pub views: Vec, + pub slots: Vec, + /// every sampler the title has made in a console sampler heap, by its index there (the + /// heaps are not told apart: the last one made at an index) + #[serde(default)] + pub samplers: Vec, + pub left_out: Vec, +} + +pub fn hex(b: &[u8]) -> String { + use std::fmt::Write; + b.iter().fold(String::with_capacity(2 * b.len()), |mut s, x| { + let _ = write!(s, "{x:02x}"); + s + }) +} + +/// The bytes `hex` wrote; an odd number of digits or anything but hex digits is an error. +pub fn unhex(s: &str) -> Result, String> { + if s.len() % 2 != 0 { + return Err(format!("{} hex digits (an odd number)", s.len())); + } + s.as_bytes() + .chunks_exact(2) + .enumerate() + .map(|(i, d)| std::str::from_utf8(d).ok().and_then(|d| u8::from_str_radix(d, 16).ok()).filter(|_| d.iter().all(u8::is_ascii_hexdigit)).ok_or_else(|| format!("not hex at digit {}", 2 * i))) + .collect() +} + +/// `name` is one plain file name (no folder, no `..`, no drive): what a capture names lies in +/// its own folder. +pub fn plain_name(what: &str, name: &str) -> Result<(), String> { + use std::path::Component; + let mut c = Path::new(name).components(); + match (c.next(), c.next()) { + (Some(Component::Normal(n)), None) if n == std::ffi::OsStr::new(name) => Ok(()), + _ => Err(format!("{what}: {name:?} is not a plain file name")), + } +} + +/// `s` holds `bytes` bytes in hex (`bytes`: None, any number). +fn check_hex(what: &str, s: &str, bytes: Option) -> Result<(), String> { + let b = unhex(s).map_err(|e| format!("{what}: {e}"))?; + match bytes { + Some(n) if b.len() != n => Err(format!("{what}: {} bytes, this build's structure has {n}", b.len())), + _ => Ok(()), + } +} + +impl Manifest { + /// `manifest.json` in `dir` (the folder is made). + pub fn write(&self, dir: &Path) -> Result<(), String> { + std::fs::create_dir_all(dir).map_err(|e| format!("{}: {e}", dir.display()))?; + let text = serde_json::to_string_pretty(self).map_err(|e| e.to_string())?; + std::fs::write(dir.join(FILE), text).map_err(|e| format!("{}: {e}", dir.join(FILE).display())) + } + + /// The manifest of the capture in `dir`; one of another version is refused. + pub fn read(dir: &Path) -> Result { + let path = dir.join(FILE); + let text = std::fs::read_to_string(&path).map_err(|e| format!("{}: {e}", path.display()))?; + let m: Manifest = serde_json::from_str(&text).map_err(|e| format!("{}: {e}", path.display()))?; + if m.version != VERSION { + return Err(format!("{}: version {} (this build reads {VERSION})", path.display(), m.version)); + } + m.check().map_err(|e| format!("{}: {e}", path.display()))?; + Ok(m) + } + + /// Every field in hex is hex, and those of a D3D12 structure have its size in this build: a + /// damaged or foreign capture is refused rather than read as another pipeline or view. + fn check(&self) -> Result<(), String> { + use std::mem::size_of; + use windows::Win32::Graphics::Direct3D12::*; + for s in &self.shaders { + plain_name(&format!("{} shader file", s.stage), &s.file)?; + } + if !self.memory_file.is_empty() { + plain_name("memory file", &self.memory_file)?; + } + for t in &self.textures { + if let Some(f) = &t.file { + plain_name(&format!("texture {} file", t.id), f)?; + } + } + if let Some(p) = &self.pso { + // (the capture keeps the description of a graphics pipeline only) + check_hex("pipeline description", &p.desc, self.graphics.then(size_of::))?; + } + check_hex("root arguments", &self.root.args, None)?; + if self.root.args.len() % 8 != 0 { + return Err(format!("root arguments: {} hex digits, not whole dwords", self.root.args.len())); + } + for (i, t) in self.targets.iter().enumerate() { + if let Some(d) = &t.desc { + check_hex(&format!("render target {i} view"), d, Some(size_of::()))?; + } + } + if let Some(d) = self.depth.as_ref().and_then(|t| t.desc.as_ref()) { + check_hex("depth view", d, Some(size_of::()))?; + } + for v in &self.views { + if let Some(d) = &v.desc { + let n = if v.uav { size_of::() } else { size_of::() }; + check_hex(&format!("view {}", v.index), d, Some(n))?; + } + } + for x in &self.samplers { + check_hex(&format!("sampler {}", x.index), &x.desc, Some(size_of::()))?; + } + Ok(()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn hex_round_trips() { + let b: Vec = (0..=255).collect(); + assert_eq!(unhex(&hex(&b)).unwrap(), b); + assert_eq!(hex(&[0x0f, 0xa0]), "0fa0"); + assert_eq!(unhex("0FA0").unwrap(), vec![0x0f, 0xa0]); + // an odd tail and what is not hex are errors, not dropped + assert!(unhex("0fa").unwrap_err().contains("odd")); + assert!(unhex("zz10").unwrap_err().contains("digit 0")); + assert!(unhex("10zz").unwrap_err().contains("digit 2")); + assert!(unhex("+1").is_err(), "a sign is not a hex digit"); + assert!(unhex("é1").is_err()); + } + + fn sample() -> Manifest { + use std::mem::size_of; + use windows::Win32::Graphics::Direct3D12::*; + Manifest { + version: VERSION, + hash: "0123456789abcdef".into(), + call_number: 3, + call: Some(Call::DrawIndexed { indices: 72, instances: 6000, first_index: 3, base_vertex: -2, first_instance: 1 }), + graphics: true, + shaders: vec![Shader { stage: "ps".into(), hash: "0123456789abcdef".into(), file: "ps.bin".into() }], + mem_windows: 4, + pso: Some(Pso { desc: hex(&vec![1; size_of::()]), input: vec![InputElement { name: "POSITION".into(), format: 2, ..Default::default() }], rect_list_gs: false }), + root: Root { params: vec![RootParam { kind: "table".into(), at: 8, count: 1, value: 0x41be_0400 }], args: hex(&[0; 16]), inline: 8, io: vec![7; 128], table_at: 0x40_0000_1000 }, + uma: Uma { base: 0x40_0000_0000, windows: vec![(0x40_0000_0000, 0xFFFF_0000)] }, + state: State { topology: Some(4), viewports: vec![[0.0, 0.0, 240.0, 136.0, 0.0, 1.0]], scissors: vec![[0, 0, 240, 136]], blend_factor: Some([1.0; 4]), stencil_ref: None }, + targets: vec![Target { handle: 0x1000, texture: Some(0), desc: None }], + memory_file: "memory.bin".into(), + memory: vec![Range { address: 0x41_0000_1000, len: 64, window: 1, offset: 0x1000, file_offset: 0, what: vec!["p0 descriptor table".into()], unreadable: 0 }], + textures: vec![Texture { id: 0, dimension: 3, width: 240, height: 136, depth_or_array: 1, mips: 1, format: 10, samples: 1, file: Some("tex_0.bin".into()), subresources: 1, ..Default::default() }], + views: vec![View { index: 174598, uav: false, texture: 0, desc: Some(hex(&vec![9; size_of::()])) }], + slots: vec![Slot { param: 0, offset: 0xd20, words: [174598, 2, 3, 0xA000_0000, 5, 6, 7, 8], kind: "image".into() }], + samplers: vec![Sampler { index: 5, desc: hex(&vec![4; size_of::()]) }], + left_out: vec!["texture 9: multisampled".into()], + ..Default::default() + } + } + + /// A manifest written to a folder reads back as it was. + #[test] + fn a_manifest_reads_back_as_written() { + let dir = std::env::temp_dir().join(format!("xcl-capture-manifest-{}", std::process::id())); + let m = sample(); + m.write(&dir).unwrap(); + let back = Manifest::read(&dir).unwrap(); + assert_eq!(serde_json::to_string(&back).unwrap(), serde_json::to_string(&m).unwrap()); + assert!(matches!(back.call, Some(Call::DrawIndexed { indices: 72, instances: 6000, first_index: 3, base_vertex: -2, first_instance: 1 }))); + assert_eq!(back.slots[0].words[3], 0xA000_0000); + assert_eq!(back.memory[0].address, 0x41_0000_1000); + let _ = std::fs::remove_dir_all(&dir); + } + + /// A manifest of another version, or none, is an error that names the file. + #[test] + fn another_version_is_refused() { + let dir = std::env::temp_dir().join(format!("xcl-capture-version-{}", std::process::id())); + assert!(Manifest::read(&dir).unwrap_err().contains(FILE)); + Manifest { version: VERSION + 1, ..sample() }.write(&dir).unwrap(); + assert!(Manifest::read(&dir).unwrap_err().contains("version")); + let _ = std::fs::remove_dir_all(&dir); + } + + /// A damaged capture is refused, naming what is wrong: a field that is not hex, an odd + /// number of digits, or a D3D12 structure of another size than this build's. + #[test] + fn a_damaged_manifest_is_refused() { + let dir = std::env::temp_dir().join(format!("xcl-capture-damaged-{}", std::process::id())); + let refused = |m: Manifest| { + m.write(&dir).unwrap(); + Manifest::read(&dir).unwrap_err() + }; + let mut m = sample(); + m.views[0].desc = Some("0fa".into()); + assert!(refused(m).contains("view 174598")); + let mut m = sample(); + m.views[0].uav = true; + m.views[0].desc = Some(hex(&[9; 3])); + assert!(refused(m).contains("view 174598: 3 bytes")); + let mut m = sample(); + m.pso.as_mut().unwrap().desc = hex(&[1, 2, 3]); + assert!(refused(m).contains("pipeline description: 3 bytes")); + let mut m = sample(); + m.samplers[0].desc = "zz".repeat(52); + assert!(refused(m).contains("sampler 5")); + let mut m = sample(); + m.root.args = hex(&[0; 3]); + assert!(refused(m).contains("root arguments")); + // the files it names lie in its own folder + let mut m = sample(); + m.shaders[0].file = "../ps.bin".into(); + assert!(refused(m).contains("ps shader file")); + let mut m = sample(); + m.textures[0].file = Some("C:\\x\\tex_0.bin".into()); + assert!(refused(m).contains("texture 0 file")); + let mut m = sample(); + m.memory_file = "sub/memory.bin".into(); + assert!(refused(m).contains("memory file")); + // as written, it reads + sample().write(&dir).unwrap(); + assert!(Manifest::read(&dir).is_ok()); + let _ = std::fs::remove_dir_all(&dir); + } + + #[test] + fn plain_names_only() { + for ok in ["ps.bin", "tex_12.bin", "memory.bin", "a..b"] { + assert!(plain_name("f", ok).is_ok(), "{ok}"); + } + for bad in ["", ".", "..", "../x", "a/b", "a\\b", "C:x", "C:\\x", "\\x", "/x"] { + assert!(plain_name("f", bad).is_err(), "{bad}"); + } + } + + /// A manifest without the fields a later build added still reads (`samplers`). + #[test] + fn a_manifest_without_samplers_reads() { + let mut v: serde_json::Value = serde_json::to_value(sample()).unwrap(); + v.as_object_mut().unwrap().remove("samplers"); + let m: Manifest = serde_json::from_value(v).unwrap(); + assert!(m.samplers.is_empty() && m.views.len() == 1); + } +} diff --git a/crates/xcl/src/hle/d3d12x/mod.rs b/crates/xcl/src/hle/d3d12x/mod.rs index 8886624632..579ce097e0 100644 --- a/crates/xcl/src/hle/d3d12x/mod.rs +++ b/crates/xcl/src/hle/d3d12x/mod.rs @@ -11,6 +11,7 @@ mod alloc_pool; pub mod bind; +pub mod capture; pub mod console_heap; pub mod console_list; pub mod device_x; From 3d496a1723f81856a3d445f27412c1ba6707c756 Mon Sep 17 00:00:00 2001 From: MadaraXor Date: Wed, 25 Nov 2026 16:36:51 +0100 Subject: [PATCH 2/4] D3D12.X: XCL_CAPTURE_DRAW writes one draw or dispatch to disk MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit XCL_CAPTURE_DRAW=[:N] writes the Nth draw or dispatch whose VS, PS or CS is that console shader to /captures: the shader containers, the PC pipeline description, the root arguments and the io words bind_abi made, the list's fixed-function state, targets, PC vertex and index buffer views, the non-zero slots of each descriptor table, the samplers made so far, and the unified memory the tables, root buffers and V# name. Textures are listed with their descriptions and the PC views made of them; their contents follow in the next change. The call is taken in bind_abi, where the io words and the argument table exist. Memory is read at the submit of the call's list, not when the call is recorded: titles fill buffers in between. The matching calls are not run unless XCL_CAPTURE_RUN=1: the switch is for calls that hang the GPU. To find the hash to give: with the variable set (XCL_CAPTURE_DRAW=list for that alone) every pipeline made from translated console shaders is logged with its shaders' hashes, the first 200, where dred::label names it – the one place all five pipeline kinds pass. Draws of VS + PS pipelines and dispatches of single compute pipelines are captured; geometry, mesh and split compute pipelines are listed only. To name what a slot's T# means on the PC, the SRV / UAV made at each heap index, the RTV / DSV at each handle, samplers and the last transition of a resource are noted while a shader is chosen. A view counts only if its resource was not released since. Without the variable every hook returns at capture::on(). Co-Authored-By: Claude Fable 5.2 --- crates/xcl/src/hle/d3d12x/bind.rs | 10 + crates/xcl/src/hle/d3d12x/capture.rs | 842 +++++++++++++++++++++- crates/xcl/src/hle/d3d12x/console_heap.rs | 2 + crates/xcl/src/hle/d3d12x/dred.rs | 1 + crates/xcl/src/hle/d3d12x/list_x.rs | 41 ++ crates/xcl/src/hle/d3d12x/real.rs | 14 +- 6 files changed, 907 insertions(+), 3 deletions(-) diff --git a/crates/xcl/src/hle/d3d12x/bind.rs b/crates/xcl/src/hle/d3d12x/bind.rs index 3f31c48b43..66c2208e89 100644 --- a/crates/xcl/src/hle/d3d12x/bind.rs +++ b/crates/xcl/src/hle/d3d12x/bind.rs @@ -73,6 +73,7 @@ fn with(list: *mut c_void, f: impl FnOnce(&mut State) -> R) -> R { /// recording's memory is the previous allocator's until that one is reset, and pipeline /// and root signature state reset per D3D12 `CreateCommandList` / `Reset` semantics. pub(super) fn reset(list: *mut c_void, allocator: usize, initial_pso: usize) { + super::capture::list_reset(list as usize); let (old, blocks) = with(list, |s| { let old = std::mem::replace(&mut s.allocator, allocator); s.arena = Default::default(); @@ -335,6 +336,7 @@ pub(super) unsafe extern "system" fn execute_indirect(this: *mut c_void, sig: us return; } let Some(list) = ID3D12GraphicsCommandList::from_raw_borrowed(&this) else { return }; + let _call = super::capture::call_scope(super::capture::Call::Indirect { max }); match bind_abi(this, list, pso, gfx) { Ok(()) => { if compute { @@ -492,6 +494,7 @@ fn cpu_rect_expansion(pso: usize) -> bool { /// #12 DrawInstanced pub(super) unsafe extern "system" fn draw_instanced(this: *mut c_void, vertices: u32, instances: u32, first_vertex: u32, first_instance: u32) { DRAW_ARGS.with(|d| d.set((false, vertices, instances, first_vertex, 0))); + let _call = super::capture::call_scope(super::capture::Call::Draw { vertices, instances, first_vertex, first_instance }); if let Some(list) = graphics_bound(this) { if draw_rects(this, &list, vertices, instances, first_vertex, first_instance) { return; @@ -508,6 +511,7 @@ thread_local! { /// #13 DrawIndexedInstanced pub(super) unsafe extern "system" fn draw_indexed_instanced(this: *mut c_void, indices: u32, instances: u32, first_index: u32, base_vertex: i32, first_instance: u32) { + let _call = super::capture::call_scope(super::capture::Call::DrawIndexed { indices, instances, first_index, base_vertex, first_instance }); if let Some(list) = prepare_indexed_draw(this, indices, instances, first_index, base_vertex) { super::list_x::sync_title_buffers(this, Some((first_index, indices, base_vertex)), 0, 0, if first_instance != 0 { instances.max(2) } else { instances }); emit_prepared_indexed_draw(&list, indices, instances, first_index, base_vertex, first_instance); @@ -523,6 +527,7 @@ pub(super) unsafe fn prepare_indexed_draw( base_vertex: i32, ) -> Option { DRAW_ARGS.with(|d| d.set((true, indices, instances, first_index, base_vertex))); + super::capture::set_call_if_unset(super::capture::Call::DrawIndexed { indices, instances, first_index, base_vertex, first_instance: 0 }); graphics_bound(this) } @@ -1007,6 +1012,7 @@ unsafe fn translated_dispatch(this: *mut c_void, list: &ID3D12GraphicsCommandLis if super::present::trace_frame() { trace_fullscreen(this, pso, [x, y, z]); } + let _call = super::capture::call_scope(super::capture::Call::Dispatch { x, y, z }); bind_abi(this, list, pso, false)?; super::real::dispatch_chain::dispatch(list, pso, with(this, |s| s.allocator), [x, y, z]) } @@ -1060,6 +1066,10 @@ unsafe fn bind_abi(this: *mut c_void, list: &ID3D12GraphicsCommandList, pso: usi let real = real as *mut c_void; let pc = ID3D12PipelineState::from_raw_borrowed(&real).ok_or("pipeline")?; list.SetPipelineState(pc); + // `XCL_CAPTURE_DRAW`: the call is written to disk, and not run + if super::capture::on() && super::capture::on_call(this, real as usize, gfx, layout.as_deref(), &args, inline, &io, table_at) { + return Err("a call of the XCL_CAPTURE_DRAW shader: not run".into()); + } Ok(()) } diff --git a/crates/xcl/src/hle/d3d12x/capture.rs b/crates/xcl/src/hle/d3d12x/capture.rs index 4261e05750..8c96806996 100644 --- a/crates/xcl/src/hle/d3d12x/capture.rs +++ b/crates/xcl/src/hle/d3d12x/capture.rs @@ -1,4 +1,842 @@ -//! One draw or dispatch written to disk, to be run again alone on a fresh device: the format -//! of such a capture (`manifest`). Nothing writes one yet. +//! One draw or dispatch written to disk. `XCL_CAPTURE_DRAW=[:]`: +//! the nth draw / dispatch (default the first) whose VS, PS or CS is that container is written +//! to `\captures\__