Player: --dump-command-buffers takes a list of ranges and single ids

A play that should dump only the command buffers holding a changed kernel's dispatches had to
dump every command buffer between the first and the last of them: on a recording whose workloads
interleave, tens of gigabytes the compare then reads for nothing. The option now takes LIST:
FIRST..LAST ranges (both ends held) and single ids, joined by commas, in any order
(CommandBufferList, in dumps.rs beside the dumps it selects). Ranges that overlap or touch are
merged and a lookup is one ordered-map search, so a list of thousands of command buffers costs
the play nothing per call. A single FIRST..LAST range reads as before; anything else stops the
play before it starts, as a bad range did.

Before: the dump test helper passed 20..=29 as a RangeInclusive, the only form there was.
Verified: the red tests from the previous commit (a_dump_list_holds_its_ranges_and_ids_and_
nothing_between, a_play_dumps_the_listed_command_buffers_alone) run in the job named in the
lane's report; no local build.
This commit is contained in:
Anees Iqbal committed 2026-11-23 08:48:02 -08:00
1 parent f96b637291
commit 15af4d5de0
5 files changed
+71 -25

No files matched your search

@@ -69,10 +69,10 @@
//! passed over, a state plays as a skipped object, which a states-only play binds nowhere, so its
//! `render states made` count leaves them out.
//!
//! With `--dump-command-buffers FIRST..LAST --dump-dir DIR`, the play also writes into `DIR`, once
//! each command buffer whose stream id lies in `FIRST..=LAST` completed, every buffer its encoders
//! named, with the ranges of it the cover rule held covered then (`docs/REPLAY-STREAM.md`, section
//! 10).
//! With `--dump-command-buffers LIST --dump-dir DIR`, the play also writes into `DIR`, once each
//! command buffer whose stream id `LIST` holds completed, every buffer its encoders named, with
//! the ranges of it the cover rule held covered then (`docs/REPLAY-STREAM.md`, section 10).
//! `LIST` is `FIRST..LAST` ranges (both ends held) and single ids, joined by commas.
//!
//! A check or dump of a buffer the play keeps two copies of (a Managed buffer of a stream recorded
//! without unified memory) names the copy it read: its CPU copy, as Metal's `contents` answers, or
@@ -105,13 +105,12 @@ use metal2vulkan_validation::gpu::wait::{parse_wait_timeout, set_wait_timeout, W
use metal2vulkan_validation::gpu::DeviceType;
use metal2vulkan_validation::replay::{
compare_dumps, compare_plays, display_library, judged_records, recording_range, segments,
shown_differences, Backend, ManagedCopies, NewRuntime, PlayError, Player, RangeSource,
RecordingRange, StreamError, StreamReader, Value, VideoHandle, FLAG_COMPLETION_BYTES_RECORDED,
RECORDED_RANGES,
shown_differences, Backend, CommandBufferList, ManagedCopies, NewRuntime, PlayError, Player,
RangeSource, RecordingRange, StreamError, StreamReader, Value, VideoHandle,
FLAG_COMPLETION_BYTES_RECORDED, RECORDED_RANGES,
};
use std::collections::{BTreeMap, HashSet};
use std::io::Write as _;
use std::ops::RangeInclusive;
use std::path::{Path, PathBuf};
const USAGE: &str = "usage: command-replay play --stream FILE --out DIR --device-type cpu|gpu \
@@ -120,7 +119,7 @@ const USAGE: &str = "usage: command-replay play --stream FILE --out DIR --device
[--states-only yes|no] [--state-log FILE] [--state-threads N] \
[--state-keys KEY,...] [--gpu-wait-timeout SECONDS] [--video-handle dma-buf|opaque-fd|opaque-win32] \
[--check-presents F,...] [--read-device-copies yes|no] [--prepass-width N] \
[--dump-command-buffers FIRST..LAST --dump-dir DIR]\n \
[--dump-command-buffers LIST --dump-dir DIR]\n \
command-replay compare-dumps --a DIR --b DIR\n \
command-replay compare-plays --a REPORT --b REPORT [--frame F]\n \
command-replay dump \
@@ -574,12 +573,10 @@ fn play(options: &BTreeMap<String, String>) -> i32 {
let dump = match (options.get("dump-command-buffers"), options.get("dump-dir")) {
(None, None) => None,
(Some(listed), Some(dir)) => {
let parsed = listed.split_once("..").and_then(|(first, last)| {
Some(first.parse::<u64>().ok()?..=last.parse::<u64>().ok()?)
});
let Some(command_buffers) = parsed else {
let Some(command_buffers) = CommandBufferList::parse(listed) else {
report.line(&format!(
"error dump-command-buffers: {listed} is no FIRST..LAST"
"error dump-command-buffers: {listed} is no list of FIRST..LAST ranges and \
ids joined by commas"
));
return 2;
};
@@ -753,7 +750,7 @@ fn open_rt(device_type: DeviceType, cache: PathBuf) -> Result<(NewRuntime, Strin
}
/// The command buffers a play dumps and where (`--dump-command-buffers`, `--dump-dir`).
type Dumped = Option<(RangeInclusive<u64>, PathBuf)>;
type Dumped = Option<(CommandBufferList, PathBuf)>;
/// The frames whose present a play checks (`--check-presents`), and where it keeps their bytes.
type Presents = (Vec<u64>, PathBuf);
@@ -26,6 +26,55 @@ use std::collections::BTreeMap;
use std::io;
use std::path::Path;
/// The command buffers a play dumps ([`Player::dumping`](super::player::Player::dumping)), by
/// stream id: what `--dump-command-buffers` lists.
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct CommandBufferList {
/// Each range's first id and its last, ranges that overlap or touch merged into one.
ranges: BTreeMap<u64, u64>,
}
impl CommandBufferList {
/// The list `listed` names: items joined by commas, in any order, each `FIRST..LAST` (both
/// ends held, `FIRST` at most `LAST`) or one id. `None` where any item is neither.
pub fn parse(listed: &str) -> Option<CommandBufferList> {
let mut list = CommandBufferList::default();
for item in listed.split(',') {
let (first, last) = match item.split_once("..") {
Some((first, last)) => (first.parse().ok()?, last.parse().ok()?),
None => {
let id = item.parse().ok()?;
(id, id)
}
};
if first > last {
return None;
}
list.add(first, last);
}
Some(list)
}
/// Whether the list holds command buffer `id`.
pub fn contains(&self, id: u64) -> bool {
(self.ranges.range(..=id).next_back()).is_some_and(|(_, &last)| id <= last)
}
/// Hold `first..=last`, merged with the ranges it overlaps or touches.
fn add(&mut self, mut first: u64, mut last: u64) {
let merged: Vec<u64> = (self.ranges.range(..=last.saturating_add(1)).rev())
.take_while(|&(_, &end)| end.saturating_add(1) >= first)
.map(|(&start, _)| start)
.collect();
for start in merged {
let end = self.ranges.remove(&start).unwrap_or(start);
first = first.min(start);
last = last.max(end);
}
self.ranges.insert(first, last);
}
}
/// The dump of buffer `object` named by command buffer `command_buffer`: its bytes, or why the
/// backend could not read them, which of its two copies they are where it has two, and the ranges
/// of it covered then, written into `dir`.
@@ -20,7 +20,7 @@ mod value;
pub use compare::{compare_plays, shown_differences};
pub use covers::SlotStage;
pub use dumps::{compare_dumps, Comparison, Difference};
pub use dumps::{compare_dumps, CommandBufferList, Comparison, Difference};
pub use new_runtime::{judged_records, Ended, ManagedCopies, NewRuntime, VideoHandle};
pub use pixels::Shape;
pub use player::WAIT_COMPLETED;
@@ -19,7 +19,6 @@ use sha2::{Digest, Sha256};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::fmt;
use std::io::Write;
use std::ops::RangeInclusive;
use std::path::PathBuf;
use std::sync::Arc;
use std::time::{SystemTime, UNIX_EPOCH};
@@ -989,7 +988,7 @@ pub struct Player<'b, B: Backend> {
/// A play's dump of command buffers ([`Player::dumping`]): which, where, and what each named.
struct Dump {
command_buffers: RangeInclusive<u64>,
command_buffers: dumps::CommandBufferList,
dir: PathBuf,
/// The live buffers.
buffers: HashSet<u64>,
@@ -1248,12 +1247,12 @@ impl<'b, B: Backend> Player<'b, B> {
self
}
/// The player that, once each command buffer whose stream id lies in `command_buffers`
/// The player that, once each command buffer whose stream id `command_buffers` holds
/// completed, writes every buffer its encoders named into `dir`, with the ranges of it the
/// cover rule held covered then (`dumps.rs`): the per-command-buffer compare of two plays
/// ([`compare_dumps`](super::compare_dumps)) reads them. A listed command buffer's buffers are
/// read after the wait that saw it complete, before the next call plays.
pub fn dumping(mut self, command_buffers: RangeInclusive<u64>, dir: PathBuf) -> Self {
pub fn dumping(mut self, command_buffers: dumps::CommandBufferList, dir: PathBuf) -> Self {
self.dump = Some(Dump {
command_buffers,
dir,
@@ -1675,7 +1674,7 @@ impl<'b, B: Backend> Player<'b, B> {
dump.buffers.insert(call.result);
}
let listed = match self.kinds.get(&call.receiver) {
Some(Kind::CommandBuffer) => dump.command_buffers.contains(&call.receiver),
Some(Kind::CommandBuffer) => dump.command_buffers.contains(call.receiver),
_ => false,
};
let command_buffer = match listed {
+5 -4
View File
@@ -1115,14 +1115,15 @@ also writes `error teardown: WHAT`. The exit status is 0 for `ok`, 1 for a run t
by `error teardown`, 2 for a harness failure (a bad command line or an unreadable stream) and 3
for `ids`, a run that played to the end.
With `--dump-command-buffers FIRST..LAST --dump-dir DIR`, the player also writes, once each
command buffer whose stream id lies in `FIRST..=LAST` completed (a split command buffer's parts by
their own ids), every buffer its encoders named, read after the wait that saw the command buffer
With `--dump-command-buffers LIST --dump-dir DIR`, the player also writes, once each command
buffer whose stream id `LIST` holds completed (a split command buffer's parts by their own ids),
every buffer its encoders named, read after the wait that saw the command buffer
complete and before the next call plays: `cbC-objO.bin` its bytes, `cbC-objO.cover` the ranges of
it covered then (as above, `start..end` byte offsets joined by commas, or `-`), and
`cbC-objO.unread` in place of the bytes where the backend could not read it, and for a buffer with
two copies `cbC-objO.copy`, which copy the bytes are: `CPU copy` or `device copy, read back`
(above). `command-replay
(above). `LIST` is `FIRST..LAST` ranges (both ends held) and single ids, joined by commas, such as
`20..29,31`; anything else stops the play before it starts. `command-replay
compare-dumps --a DIR --b DIR` compares two plays' dumps word by word (4 bytes), leaving out a word
wholly inside a range either play held covered, and prints `differs cb #C obj #O: N words outside every cover, the first word
W; M covered; lengths A and B` for each buffer that differs outside every cover, `only in a|b: