diff --git a/crates/metal2vulkan-validation/src/bin/command-replay.rs b/crates/metal2vulkan-validation/src/bin/command-replay.rs index b0c3be737..5fde34a41 100644 --- a/crates/metal2vulkan-validation/src/bin/command-replay.rs +++ b/crates/metal2vulkan-validation/src/bin/command-replay.rs @@ -2,16 +2,20 @@ //! or the new one, or print its records. //! //! `command-replay play --stream FILE --out DIR --device-type cpu|gpu --shader-cache DIR -//! [--blobs DIR] [--runtime old|rt] [--snapshots yes|no] [--managed one-copy|two-copy]` plays the -//! stream whose first segment is `FILE` through the old runtime (the default) or the new one -//! (`rt`), with `--snapshots no` taking no `m2v.privateBytes` snapshot on either (so two -//! runtimes' plays do the same work), and `--managed` telling the new runtime how the recording -//! device kept Managed buffers where the stream has no `m2v.deviceIdentity` record (one copy: -//! unified memory; two copies: a GPU copy; with neither, a Managed buffer stops the play), and -//! writes `DIR/report.txt`: `device NAME runtime old|rt snapshots yes|no`, `relocation ...` (the +//! [--blobs DIR] [--runtime old|rt] [--snapshots yes|no] [--managed one-copy|two-copy] +//! [--until-frame F]` plays the stream whose first segment is `FILE` through the old runtime (the +//! default) or the new one (`rt`), with `--snapshots no` taking no `m2v.privateBytes` snapshot on +//! either (so two runtimes' plays do the same work), `--managed` telling the new runtime how the +//! recording device kept Managed buffers where the stream has no `m2v.deviceIdentity` record (one +//! copy: unified memory; two copies: a GPU copy; with neither, a Managed buffer stops the play), +//! and `--until-frame` stopping the play after frame `F`'s present (frames counted from 0), and +//! writes `DIR/report.txt`: `device NAME runtime old|rt snapshots yes|no`, each frame's `frame` +//! and `end` lines as the frame ends (flushed, so a play that never ends leaves the frames it +//! finished), `relocation ...` (the //! words relocated, the address arguments, the writes into objects with no recorded range, and -//! the objects whose ID differs from the recording's), the player's report lines, the backend's -//! own lines, `cut SEGMENT OFFSET` where the last +//! the objects whose ID differs from the recording's), the player's other report lines, the +//! backend's own lines, `until-frame F` where the play stopped there, `cut SEGMENT OFFSET` where +//! the last //! segment ends in a record cut //! short, `skipped ...` where the backend skipped what its runtime does not build (such a play is //! no gate result), `gaps ...` where it met a typed gap, then `ok` or `error WHAT`; a play @@ -41,8 +45,8 @@ use std::path::PathBuf; const USAGE: &str = "usage: command-replay play --stream FILE --out DIR --device-type cpu|gpu \ --shader-cache DIR [--blobs DIR] [--runtime old|rt] [--snapshots yes|no] \ - [--managed one-copy|two-copy]\n command-replay dump --stream FILE\n \ - command-replay shapes --stream FILE"; + [--managed one-copy|two-copy] [--until-frame F]\n command-replay dump \ + --stream FILE\n command-replay shapes --stream FILE"; fn main() { let args: Vec = std::env::args().skip(1).collect(); @@ -231,6 +235,17 @@ fn play(options: &BTreeMap) -> i32 { return 2; } }; + let until = match options.get("until-frame").map(|f| f.parse::()) { + None => None, + Some(Ok(last)) => Some(last), + Some(Err(_)) => { + report.line(&format!( + "error until-frame: {} is no frame number", + options["until-frame"] + )); + return 2; + } + }; // The first line says which mode ran: a timing table never comes from a snapshotting play // unnoticed. let mode = match snapshots { @@ -252,7 +267,7 @@ fn play(options: &BTreeMap) -> i32 { }; report.line(&format!("device {} runtime old {mode}", device.name())); let mut backend = OldRuntime::new(device, device_type); - run(&mut backend, &mut reader, &mut report, snapshots) + run(&mut backend, &mut reader, &mut report, snapshots, until) } Some("rt") => { let mut backend = match open_rt(device_type, cache) { @@ -268,7 +283,7 @@ fn play(options: &BTreeMap) -> i32 { return 2; } }; - run(&mut backend, &mut reader, &mut report, snapshots) + run(&mut backend, &mut reader, &mut report, snapshots, until) } Some(other) => { report.line(&format!("error runtime: {other} is neither old nor rt")); @@ -328,12 +343,17 @@ fn run( reader: &mut StreamReader, report: &mut ReportFile, snapshots: bool, + until: Option, ) -> i32 { - let player = Player::new(backend); + let player = Player::new(backend).with_frame_lines(&mut report.file); let player = match snapshots { true => player, false => player.without_snapshots(), }; + let player = match until { + Some(last) => player.until_frame(last), + None => player, + }; let (played, ended) = player.play(reader); let counters = backend.counters(); // The objects whose ID the program saw that the runtime gives otherwise, the typed gap of the @@ -351,12 +371,15 @@ fn run( fixed("address_arguments"), fixed("unrelocated_writes"), )); - for line in played.lines() { + for line in played.lines_but_frames() { report.line(&line); } for line in backend.lines() { report.line(&line); } + if let Some(last) = until.filter(|&last| played.frames.len() > last) { + report.line(&format!("until-frame {last}")); + } if let Some((segment, offset)) = reader.truncated() { report.line(&format!("cut {} {offset}", segment.display())); } diff --git a/crates/metal2vulkan-validation/src/replay/new_runtime/encoders.rs b/crates/metal2vulkan-validation/src/replay/new_runtime/encoders.rs index 2d207b397..b8ef64e0a 100644 --- a/crates/metal2vulkan-validation/src/replay/new_runtime/encoders.rs +++ b/crates/metal2vulkan-validation/src/replay/new_runtime/encoders.rs @@ -147,6 +147,7 @@ impl NewRuntime { // Its first use committed, a no-copy Managed buffer's GPU copy changes only by // `didModifyRange:` from here. self.fresh.retain(|_, user| *user != Some(call.receiver)); + self.unwritten.committed(call.receiver); self.in_flight.push_back((self.commits, command_buffer)); for place in self.staging.remove(&call.receiver).unwrap_or_default() { self.places.give(place, self.commits); diff --git a/crates/metal2vulkan-validation/src/replay/new_runtime/mod.rs b/crates/metal2vulkan-validation/src/replay/new_runtime/mod.rs index 2ff3037d3..fc39cf602 100644 --- a/crates/metal2vulkan-validation/src/replay/new_runtime/mod.rs +++ b/crates/metal2vulkan-validation/src/replay/new_runtime/mod.rs @@ -9,6 +9,7 @@ mod encoders; mod places; +pub(super) mod unwritten; use super::args::{arg, data, metal, option_sets, refuse, uint, variant, Fields}; use super::player::{Backend, Counters, Made, PlayError}; @@ -158,6 +159,8 @@ pub struct NewRuntime { /// Whether the stream told the form itself (`m2v.deviceIdentity`): its no-copy Managed /// buffers then carry their bytes at creation. identity: bool, + /// The Shared buffers a dispatch read before anything recorded reached their bytes. + unwritten: unwritten::Unwritten, /// The staging places of each command buffer not yet committed, which hold the bytes of its /// guest-RAM copies: given back at its commit, free once it completes. staging: HashMap>, @@ -387,6 +390,7 @@ impl NewRuntime { fresh: HashMap::new(), from_first_use: HashSet::new(), identity: false, + unwritten: unwritten::Unwritten::default(), staging: HashMap::new(), staged_bytes: 0, unanswered_pipeline_ids: 0, @@ -568,6 +572,9 @@ impl NewRuntime { rt::StorageMode::Shared | rt::StorageMode::Managed => rt::MemoryClass::Shared, _ => return Err(refuse(call, format!("a {mode:?} buffer of this call"))), }; + if class == rt::MemoryClass::Shared && bytes.is_empty() { + self.unwritten.made(call.result, None); + } let completed = self.completed(); let place = (self.places.take(class, length, completed)).map_err(failed(call))?; let (start, block) = (place.range.start, place.block); @@ -1088,7 +1095,12 @@ impl NewRuntime { } _ => device.new_buffer(range.block, at, length, None), }; - addressed(buffer.map_err(failed(call))?, None) + let buffer = buffer.map_err(failed(call))?; + if class == rt::MemoryClass::Shared { + let placed = (call.receiver, offset..offset + length); + self.unwritten.made(call.result, Some(placed)); + } + addressed(buffer, None) }; match &*call.selector { "newBufferWithLength:options:offset:" => { @@ -1234,6 +1246,7 @@ impl Backend for NewRuntime { if &*call.selector == "release" { self.owners.remove(&call.receiver); self.fresh.remove(&call.receiver); + self.unwritten.released(call.receiver); match self.objects.remove(&call.receiver) { Some(Object::Buffer(_, Some(place))) => self.places.give(place, self.commits), // The runtime keeps the block while a buffer of it lives or work uses it, as a @@ -1252,6 +1265,11 @@ impl Backend for NewRuntime { } return Ok(Made::default()); } + if let Some(&command_buffer) = self.owners.get(&call.receiver) { + // Skipped encoders too: what the program's GPU passes reach is the stream's. + let compute = matches!(self.objects.get(&call.receiver), Some(Object::Compute(_))); + self.unwritten.encoded(call, command_buffer, compute); + } if call.receiver != 0 && self.skipped(call.receiver) { // A call on a skipped object; what it makes is skipped too. self.skips.calls += 1; @@ -1378,6 +1396,8 @@ impl Backend for NewRuntime { } fn write(&mut self, target: u64, offset: u64, bytes: &[u8]) -> Result<(), PlayError> { + let end = offset + bytes.len() as u64; + self.unwritten.written(target, offset..end); match self.objects.get(&target) { Some(Object::Buffer(buffer, _)) => { write_into(buffer, offset, bytes)?; @@ -1581,6 +1601,7 @@ impl Backend for NewRuntime { } lines.push(line); } + lines.push(self.unwritten.line()); lines } diff --git a/crates/metal2vulkan-validation/src/replay/new_runtime/unwritten.rs b/crates/metal2vulkan-validation/src/replay/new_runtime/unwritten.rs new file mode 100644 index 000000000..c97af370c --- /dev/null +++ b/crates/metal2vulkan-validation/src/replay/new_runtime/unwritten.rs @@ -0,0 +1,159 @@ +//! The Shared buffers a dispatch read before anything the stream records put bytes in them: a +//! buffer of the Shared class, made without bytes, that a compute encoder binds or uses, whose +//! command buffer commits before any recorded write, upload or GPU pass reached its bytes since its +//! making. Such a buffer plays with whatever its memory held, which is where a recording that +//! missed the program's writes shows. Counted on the report's `unwritten` line, never refused: a +//! dispatch that writes such a buffer before it reads it is counted too. +//! +//! What reaches a buffer's bytes: an `m2v.write` into it, into its block over them or into another +//! buffer of the block over them; a call of a blit or render encoder that names it or another +//! buffer of the block over them (a copy, a fill, an upload from the guest's RAM, an attachment); +//! and the commit of a dispatch that binds it, which may write it. A texture over a buffer is not +//! followed. + +use super::super::stream::Call; +use super::objects_named; +use std::collections::{HashMap, HashSet}; +use std::ops::Range; + +/// How many of the buffers counted the report names. +const NAMED: usize = 8; + +#[derive(Default)] +pub(in crate::replay) struct Unwritten { + /// Each live buffer made in a Shared block: the block and its byte range there. + placed: HashMap)>, + /// The live Shared buffers nothing has reached since their making. + waiting: HashSet, + /// Those of them that lie in a block, by the block. + in_block: HashMap>, + /// The waiting buffers each open compute encoder bound or used since its last dispatch. + bound: HashMap>, + /// The waiting buffers a dispatch of each uncommitted command buffer bound. + read: HashMap>, + /// The buffers a committed dispatch read while waiting, and the first of them with the + /// command buffer that read each. + count: u64, + first: Vec<(u64, u64)>, +} + +impl Unwritten { + /// Shared buffer `id` made without bytes; `placed` is its block and its range there, where it + /// lies in one. + pub(in crate::replay) fn made(&mut self, id: u64, placed: Option<(u64, Range)>) { + self.waiting.insert(id); + if let Some((block, range)) = placed { + self.in_block.entry(block).or_default().push(id); + self.placed.insert(id, (block, range)); + } + } + + /// Bytes `range` of buffer or block `id` written. + pub(in crate::replay) fn written(&mut self, id: u64, range: Range) { + self.waiting.remove(&id); + match self.placed.get(&id) { + Some((block, at)) => { + let block = *block; + let range = at.start + range.start..at.start + range.end; + self.reach(block, range); + } + None => self.reach(id, range), + } + } + + /// Buffer or block `id` named by a GPU pass, which may write any of its bytes. + fn named(&mut self, id: u64) { + self.waiting.remove(&id); + match self.placed.get(&id) { + Some((block, at)) => { + let (block, range) = (*block, at.clone()); + self.reach(block, range); + } + None => self.reach(id, 0..u64::MAX), + } + } + + /// Bytes `range` of block `block` reached: every waiting buffer of the block over them is. + fn reach(&mut self, block: u64, range: Range) { + let Some(ids) = self.in_block.get_mut(&block) else { + return; + }; + let (waiting, placed) = (&mut self.waiting, &self.placed); + ids.retain(|id| { + let over = (placed.get(id)) + .is_some_and(|(_, at)| at.start < range.end && range.start < at.end); + if over { + waiting.remove(id); + } + waiting.contains(id) + }); + } + + /// Call `call` of an encoder of command buffer `command_buffer`, a compute encoder where + /// `compute`. + pub(in crate::replay) fn encoded(&mut self, call: &Call, command_buffer: u64, compute: bool) { + if self.waiting.is_empty() { + return; + } + if compute && call.selector.starts_with("dispatch") { + if let Some(bound) = self.bound.remove(&call.receiver) { + self.read.entry(command_buffer).or_default().extend(bound); + } + return; + } + let mut named = Vec::new(); + objects_named(&call.args, &mut named); + for id in named { + match compute { + true if self.waiting.contains(&id) => { + self.bound.entry(call.receiver).or_default().push(id) + } + true => {} + false => self.named(id), + } + } + } + + /// Command buffer `command_buffer` committed: the buffers its dispatches read still waiting + /// are counted, and every one of them is reached, as the dispatches may write them. + pub(in crate::replay) fn committed(&mut self, command_buffer: u64) { + for id in self.read.remove(&command_buffer).unwrap_or_default() { + if self.waiting.contains(&id) { + self.count += 1; + if self.first.len() < NAMED { + self.first.push((id, command_buffer)); + } + } + self.named(id); + } + } + + /// Object `id` released. + pub(in crate::replay) fn released(&mut self, id: u64) { + self.waiting.remove(&id); + if let Some((block, _)) = self.placed.remove(&id) { + if let Some(ids) = self.in_block.get_mut(&block) { + ids.retain(|other| *other != id); + } + } + self.in_block.remove(&id); + self.bound.remove(&id); + self.read.remove(&id); + } + + /// The report's line. + pub(in crate::replay) fn line(&self) -> String { + let first: Vec = (self.first.iter()) + .map(|(buffer, command_buffer)| format!("#{buffer} in #{command_buffer}")) + .collect(); + let first = match first.is_empty() { + true => String::new(), + false => format!("; first {}", first.join(", ")), + }; + format!( + "unwritten {}: Shared buffers a dispatch read before any recorded write, upload or GPU \ + pass reached their bytes since their making{first}", + self.count + ) + } +} diff --git a/crates/metal2vulkan-validation/src/replay/player.rs b/crates/metal2vulkan-validation/src/replay/player.rs index 6e5daa768..d820a9134 100644 --- a/crates/metal2vulkan-validation/src/replay/player.rs +++ b/crates/metal2vulkan-validation/src/replay/player.rs @@ -11,6 +11,7 @@ use super::value::{Hash, Value}; use sha2::{Digest, Sha256}; use std::collections::{BTreeMap, HashMap, HashSet, VecDeque}; use std::fmt; +use std::io::Write; use std::sync::Arc; /// A runtime's counters, cumulative, by name. @@ -423,15 +424,21 @@ fn counted(counts: &Counts) -> String { impl Report { /// The report's lines (`docs/REPLAY-STREAM.md`, section 10). pub fn lines(&self) -> Vec { + let mut lines = self.lines_but_frames(); + // The frames' lines follow the completed groups' (one line each). + let at = self.completed.len(); + let frames = (0..self.frames.len()).flat_map(|frame| self.frame_lines(frame)); + lines.splice(at..at, frames); + lines + } + + /// Frame `at`'s lines: its counts (`frame`) and its end (`end`). + pub fn frame_lines(&self, at: usize) -> Vec { let mut lines = Vec::new(); - for (ids, counters) in &self.completed { - let ids: String = ids.iter().map(|id| format!(" #{id}")).collect(); - lines.push(format!("completed{ids}{}", counted(counters))); - } - for (at, counters) in self.frames.iter().enumerate() { + if let Some(counters) = self.frames.get(at) { lines.push(format!("frame {at}{}", counted(counters))); } - for (at, end) in self.ends.iter().enumerate() { + if let Some(end) = self.ends.get(at) { let resident = (end.resident_bytes).map_or(String::new(), |r| format!(" resident_bytes={r}")); let live: String = (end.live.iter()) @@ -458,6 +465,17 @@ impl Report { t.gpu_busy, )); } + lines + } + + /// The lines but the frames' (`frame_lines`): for a report that wrote each frame's as it + /// ended (`Player::with_frame_lines`). + pub fn lines_but_frames(&self) -> Vec { + let mut lines = Vec::new(); + for (ids, counters) in &self.completed { + let ids: String = ids.iter().map(|id| format!(" #{id}")).collect(); + lines.push(format!("completed{ids}{}", counted(counters))); + } for check in &self.checks { let verdict = match check.recorded { None => "unrecorded", @@ -697,6 +715,10 @@ pub struct Player<'b, B: Backend> { /// The live objects that calls of `Cost::Resource` made, whose release costs as theirs. resources: HashSet, report: Report, + /// The last frame to play (`until_frame`), counted from 0 as `Report::frames` counts them. + last_frame: Option, + /// Where each frame's lines go as it ends (`with_frame_lines`). + frame_out: Option<&'b mut dyn Write>, } /// `now` past `base`, key by key. @@ -893,9 +915,26 @@ impl<'b, B: Backend> Player<'b, B> { intervals: Vec::new(), resources: HashSet::new(), report: Report::default(), + last_frame: None, + frame_out: None, } } + /// The player that stops after frame `last`'s `m2v.present`, counted from 0 as + /// `Report::frames` counts them: it completes the work committed so far and reports as at the + /// stream's end. + pub fn until_frame(mut self, last: usize) -> Self { + self.last_frame = Some(last); + self + } + + /// The player that writes each frame's lines (`Report::frame_lines`) to `out` as the frame + /// ends, flushed, so that a play that never ends leaves the frames it finished. + pub fn with_frame_lines(mut self, out: &'b mut dyn Write) -> Self { + self.frame_out = Some(out); + self + } + /// The player that takes no `m2v.privateBytes` snapshots on any backend: every dispatch plays as /// the program made it, counted (`Report::unsnapshotted`), so that two runtimes' plays do the /// same work and their times and memory compare. @@ -952,6 +991,9 @@ impl<'b, B: Backend> Player<'b, B> { *self.fixed.entry(key).or_default() += 1; } self.compare(stream, left_out)?; + if (self.last_frame).is_some_and(|last| self.report.frames.len() > last) { + break; + } } Ok(()) } @@ -1110,6 +1152,14 @@ impl<'b, B: Backend> Player<'b, B> { live: self.backend.live(), times, }); + if let Some(out) = &mut self.frame_out { + // A report line lost to a full disk loses only itself, as in the report file. + let at = self.report.frames.len() - 1; + for line in self.report.frame_lines(at) { + let _ = writeln!(out, "{line}"); + } + let _ = out.flush(); + } Ok(()) } "commit" => self.commit(call.receiver), diff --git a/crates/metal2vulkan-validation/src/replay/tests.rs b/crates/metal2vulkan-validation/src/replay/tests.rs index 77a256c30..e21026ca7 100644 --- a/crates/metal2vulkan-validation/src/replay/tests.rs +++ b/crates/metal2vulkan-validation/src/replay/tests.rs @@ -2,6 +2,7 @@ //! is asked (no device). The runtime backends' tests are device tests (`runtime_lane`). use super::addresses::AddressMap; +use super::new_runtime::unwritten::Unwritten; use super::player::{ Backend, Counters, Counts, IdDiffers, Made, PlayError, Player, PrivateBytes, Relaid, Report, WAIT_COMPLETED, @@ -1220,6 +1221,94 @@ fn a_frame_end_reports_the_gauges_as_they_stand() { assert!(ends[1].ends_with(" live calls=3"), "{lines:?}"); } +/// The new runtime's `unwritten` line counts, once, a Shared buffer a committed dispatch read +/// before anything recorded reached its bytes: not one written through its block, one a blit +/// names, one written before the commit, one an earlier commit's dispatch bound or one released +/// before the commit. +#[test] +fn a_dispatch_reading_a_buffer_nothing_recorded_reached_is_counted_once() { + let call = |selector: &str, receiver: u64, args: Vec| Call { + selector: selector.into(), + receiver, + result: 0, + args, + answers: Vec::new(), + }; + let bind = |encoder: u64, id: u64| { + let args = vec![Value::Object(id), Value::Uint(0), Value::Uint(0)]; + call("setBuffer:offset:atIndex:", encoder, args) + }; + let dispatch = |encoder: u64| call("dispatchThreads:threadsPerThreadgroup:", encoder, vec![]); + let mut unwritten = Unwritten::default(); + // Block 1 holds buffers 2, 3 and 4; buffers 5, 6 and 7 lie in none. + for (id, range) in [(2, 0..256), (3, 256..512), (4, 512..768)] { + unwritten.made(id, Some((1, range))); + } + for id in [5, 6, 7] { + unwritten.made(id, None); + } + unwritten.written(1, 300..304); + let fill = call("fillBuffer:range:value:", 11, vec![Value::Object(5)]); + unwritten.encoded(&fill, 10, false); + for id in [2, 3, 4, 5, 6, 7] { + unwritten.encoded(&bind(12, id), 10, true); + } + unwritten.encoded(&dispatch(12), 10, true); + unwritten.encoded(&dispatch(12), 10, true); + unwritten.written(6, 0..4); + unwritten.released(7); + unwritten.committed(10); + // Buffer 8 lies over buffer 2's bytes, made after the commit: its own making starts it over. + unwritten.made(8, Some((1, 0..128))); + for id in [2, 8] { + unwritten.encoded(&bind(13, id), 14, true); + } + unwritten.encoded(&dispatch(13), 14, true); + unwritten.committed(14); + assert_eq!( + unwritten.line(), + "unwritten 3: Shared buffers a dispatch read before any recorded write, upload or GPU \ + pass reached their bytes since their making; first #2 in #10, #4 in #10, #8 in #14" + ); +} + +/// A player told its last frame stops after that frame's present, and one given an output writes +/// each frame's lines there as the frame ends: the report's other lines leave them out. +#[test] +fn a_play_stops_after_its_last_frame_and_writes_each_frame_as_it_ends() { + let mut kept = Kept::default(); + let dir = ScratchDir::new("replay-until").unwrap(); + let path = written(&dir, "s.m2vr", |w| { + w.call("MTLCreateSystemDefaultDevice", 0, 1, &[], &[])?; + w.call("m2v.present", 1, 0, &[Value::Nil], &[])?; + w.call("newCommandQueue", 1, 2, &[], &[])?; + w.call("m2v.present", 1, 0, &[Value::Nil], &[])?; + w.call("newCommandQueue", 1, 3, &[], &[]) + }); + let mut reader = StreamReader::open(&[path], None).unwrap(); + let mut out = Vec::new(); + let player = Player::new(&mut kept).with_frame_lines(&mut out); + let (report, ended) = player.until_frame(1).play(&mut reader); + ended.unwrap(); + assert_eq!(report.frames.len(), 2); + assert_eq!( + kept.calls, + [ + "#1 = MTLCreateSystemDefaultDevice", + "#2 = #1 newCommandQueue" + ] + ); + let out = String::from_utf8(out).unwrap(); + let frames: Vec = (0..2).flat_map(|at| report.frame_lines(at)).collect(); + assert_eq!(out.lines().collect::>(), frames, "{out}"); + assert_eq!(frames.len(), 4); + let rest = report.lines_but_frames(); + assert!( + !(rest.iter()).any(|line| line.starts_with("frame ") || line.starts_with("end ")), + "{rest:?}" + ); +} + /// A frame's end counts the GPU's busy time as the union of the intervals of the command buffers /// the frame waited for, where two overlap once, and its line says where the wall time went. #[test] diff --git a/docs/REPLAY-STREAM.md b/docs/REPLAY-STREAM.md index 703f34630..36472d984 100644 --- a/docs/REPLAY-STREAM.md +++ b/docs/REPLAY-STREAM.md @@ -353,12 +353,15 @@ and the (name id, value) answer pairs. ## 10. The player `command-replay play --stream FILE --out DIR --device-type cpu|gpu --shader-cache DIR -[--blobs DIR] [--runtime old|rt] [--snapshots yes|no] [--managed one-copy|two-copy]` plays a -stream (its first segment) on one device through the old runtime (the default) or the new one -(`rt`), and writes `DIR/report.txt`. +[--blobs DIR] [--runtime old|rt] [--snapshots yes|no] [--managed one-copy|two-copy] +[--until-frame F]` plays a stream (its first segment) on one device through the old runtime (the +default) or the new one (`rt`), and writes `DIR/report.txt`. It writes each frame's `frame` and +`end` lines as the frame ends, flushed, so a play that never ends leaves every frame it finished. With `--snapshots no` it takes no `m2v.privateBytes` snapshot on either runtime: each such dispatch plays as it is, counted on the `unsnapshotted` line, so two runtimes' plays do the same work and -their times and memory compare. `command-replay dump --stream FILE` prints the call records as text, and +their times and memory compare. With `--until-frame F` it stops after frame `F`'s present (frames +counted from 0), completes the work committed so far, reports as at the stream's end and says +`until-frame F`. `command-replay dump --stream FILE` prints the call records as text, and `command-replay shapes --stream FILE` each selector's argument shapes, with no data. - It relocates (section 5) and plays the host's plumbing as the plain calls it stands for @@ -375,6 +378,16 @@ their times and memory compare. `command-replay dump --stream FILE` prints the c unified memory the runtime keeps one copy anyway. The report's `managed` line says which form played and from what, counts the Managed buffers and the no-copy ones whose contents came from first use, not from create, and says where a two-copy recording played as one copy. +- **Unwritten buffers** (the new runtime): its report's `unwritten` line counts the Shared + buffers made without bytes that a compute encoder bound or used and whose command buffer + committed before any recorded write, upload or GPU pass reached their bytes since their making, + and names the first few with the command buffer that read each. Such a buffer plays with + whatever its memory held, which is where a recording that missed the program's writes shows. + What reaches a buffer's bytes: an `m2v.write` into it, into its block over them or into another + buffer of the block over them; a blit or render encoder's call that names it or such another + buffer; and the commit of a dispatch that binds it, which may write it. A dispatch that writes + such a buffer before it reads it is counted too, and a texture over a buffer is not followed. + The line counts; it stops nothing. - After each commit, before each write, check and present, and where the program waited, it waits for every committed command buffer that can complete: one whose event waits are met by values the CPU set or by signals of command buffers that can complete. It never waits on a command buffer