replay: Managed buffers play in the recording device's form, from its identity record or --managed
How a Managed buffer behaves depends on the recording device's hasUnifiedMemory: one copy where it is true (a CPU write needs no didModifyRange), a GPU copy made at the buffer's making and changed only by didModifyRange where it is false. The stream did not say which, and the rt backend always made the runtime's Managed buffer: gb, recorded on a discrete GPU, wrote its no-copy Managed buffers (#368205, #368202, #368214) once before first use with no didModifyRange, so their GPU copies never got the bytes; b2, recorded with unified memory, relies on such writes legitimately. The player now takes the form from the stream's new m2v.deviceIdentity record (it plays as nothing and tells the backend hasUnifiedMemory through Backend::recorded_unified_memory), or for a stream without one from command-replay's --managed one-copy|two-copy. One copy: every Managed buffer plays as a Shared one. Two copies: the runtime's Managed buffer, its GPU copy from the bytes it was made with: a copied buffer's, or the new create-time bytes a no-copy one's making now carries (newBufferWithBytesNoCopy's first argument, a no-copy descriptor's contents). A stream with no identity record gives none, so a no-copy buffer's GPU copy takes the writes recorded before its first use (the commit of a command buffer whose encoder names it). With neither the record nor the setting a Managed buffer stops the play with an error saying so. The report's managed line names the form and its source, counts the Managed buffers and the no-copy ones with contents from first use, not from create, and notes a two-copy recording played on a unified-memory device. REPLAY-STREAM.md documents the identity record, the create-time bytes and the player's rule. Verified: a replay test plays an identity record as nothing and sees the backend told hasUnifiedMemory; the rt paths need a device play (gb on the 3090 next).
This commit is contained in:
1 parent
b1eeec6981
commit
13bb9a0a4e
7 files changed
+268
-28
No files matched your search
@@ -2,9 +2,12 @@
|
||||
//! 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]` 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
|
||||
//! [--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
|
||||
//! 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
|
||||
@@ -29,14 +32,16 @@ use metal2vulkan_runtime::{DeviceOptions, ShaderCacheOptions};
|
||||
use metal2vulkan_validation::candidate::runtime_case::open_device;
|
||||
use metal2vulkan_validation::gpu::DeviceType;
|
||||
use metal2vulkan_validation::replay::{
|
||||
segments, Backend, NewRuntime, OldRuntime, PlayError, Player, StreamError, StreamReader, Value,
|
||||
segments, Backend, ManagedCopies, NewRuntime, OldRuntime, PlayError, Player, StreamError,
|
||||
StreamReader, Value,
|
||||
};
|
||||
use std::collections::BTreeMap;
|
||||
use std::io::Write as _;
|
||||
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]\n command-replay dump --stream FILE\n \
|
||||
--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";
|
||||
|
||||
fn main() {
|
||||
@@ -215,6 +220,17 @@ fn play(options: &BTreeMap<String, String>) -> i32 {
|
||||
return 2;
|
||||
}
|
||||
};
|
||||
let managed = match options.get("managed").map(String::as_str) {
|
||||
None => None,
|
||||
Some("one-copy") => Some(ManagedCopies::One),
|
||||
Some("two-copy") => Some(ManagedCopies::Two),
|
||||
Some(other) => {
|
||||
report.line(&format!(
|
||||
"error managed: {other} is neither one-copy nor two-copy"
|
||||
));
|
||||
return 2;
|
||||
}
|
||||
};
|
||||
// The first line says which mode ran: a timing table never comes from a snapshotting play
|
||||
// unnoticed.
|
||||
let mode = match snapshots {
|
||||
@@ -242,7 +258,10 @@ fn play(options: &BTreeMap<String, String>) -> i32 {
|
||||
let mut backend = match open_rt(device_type, cache) {
|
||||
Ok((backend, name)) => {
|
||||
report.line(&format!("device {name} runtime rt {mode}"));
|
||||
backend
|
||||
match managed {
|
||||
Some(copies) => backend.with_managed(copies),
|
||||
None => backend,
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
report.line(&format!("error device: {error}"));
|
||||
|
||||
@@ -10,7 +10,7 @@ mod stream;
|
||||
mod translator;
|
||||
mod value;
|
||||
|
||||
pub use new_runtime::NewRuntime;
|
||||
pub use new_runtime::{ManagedCopies, NewRuntime};
|
||||
pub use old_runtime::OldRuntime;
|
||||
pub use player::WAIT_COMPLETED;
|
||||
pub use player::{
|
||||
|
||||
@@ -121,6 +121,9 @@ impl NewRuntime {
|
||||
};
|
||||
super::unaddressed(Object::Compute(Box::new(compute)))
|
||||
};
|
||||
if call.result != 0 && call.selector.contains("CommandEncoder") {
|
||||
self.owners.insert(call.result, call.receiver);
|
||||
}
|
||||
match &*call.selector {
|
||||
"computeCommandEncoder" => encoder(0),
|
||||
"computeCommandEncoderWithDispatchType:" => encoder(uint(call, 0)?),
|
||||
@@ -131,7 +134,6 @@ impl NewRuntime {
|
||||
"blitCommandEncoder" => {
|
||||
let encoder = command_buffer.blit_command_encoder();
|
||||
let encoder = encoder.map_err(failed(call))?;
|
||||
self.blit_owners.insert(call.result, call.receiver);
|
||||
super::unaddressed(Object::Blit(Box::new(encoder)))
|
||||
}
|
||||
"renderCommandEncoderWithDescriptor:"
|
||||
@@ -142,6 +144,9 @@ impl NewRuntime {
|
||||
"commit" => {
|
||||
command_buffer.commit().map_err(failed(call))?;
|
||||
self.commits += 1;
|
||||
// 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.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);
|
||||
@@ -404,7 +409,7 @@ impl NewRuntime {
|
||||
copied.map_err(failed(call))?;
|
||||
}
|
||||
self.staged_bytes += len;
|
||||
match self.blit_owners.get(&id).copied() {
|
||||
match self.owners.get(&id).copied() {
|
||||
Some(command_buffer) => self.staging.entry(command_buffer).or_default().push(place),
|
||||
None => self.places.give(place, self.commits),
|
||||
}
|
||||
@@ -429,7 +434,7 @@ impl NewRuntime {
|
||||
let Some(Object::Blit(encoder)) = self.objects.remove(&id) else {
|
||||
unreachable!("a blit encoder's call");
|
||||
};
|
||||
self.blit_owners.remove(&id);
|
||||
self.owners.remove(&id);
|
||||
(*encoder).end_encoding();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -111,6 +111,21 @@ struct Creation {
|
||||
new_kernel: bool,
|
||||
}
|
||||
|
||||
/// How the device that recorded a stream kept a Managed buffer: Metal's `hasUnifiedMemory`
|
||||
/// there. With unified memory a Managed buffer is one copy, so a CPU write needs no
|
||||
/// `didModifyRange:`; without it the GPU has a copy of its own, made from the buffer's bytes at
|
||||
/// its creation and changed after only by `didModifyRange:`. A stream does not record it: the
|
||||
/// player is told it for each stream.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum ManagedCopies {
|
||||
/// Recorded with unified memory: every Managed buffer plays as a Shared one, on every device.
|
||||
One,
|
||||
/// Recorded without it: a Managed buffer plays as the runtime's Managed buffer. A no-copy
|
||||
/// one's GPU copy takes the bytes the stream records before its first use, its nearest record
|
||||
/// of its bytes at creation.
|
||||
Two,
|
||||
}
|
||||
|
||||
/// The new runtime on one device.
|
||||
pub struct NewRuntime {
|
||||
device: rt::Device,
|
||||
@@ -127,8 +142,22 @@ pub struct NewRuntime {
|
||||
completed: u64,
|
||||
skips: Skips,
|
||||
substitutes: Substitutes,
|
||||
/// Each open blit encoder's command buffer.
|
||||
blit_owners: HashMap<u64, u64>,
|
||||
/// Each open encoder's command buffer.
|
||||
owners: HashMap<u64, u64>,
|
||||
/// How the recording's device kept Managed buffers; `None` where the player was not told,
|
||||
/// and a Managed buffer is refused.
|
||||
managed: Option<ManagedCopies>,
|
||||
/// The Managed buffers made.
|
||||
managed_buffers: u64,
|
||||
/// The no-copy Managed buffers of a two-copy stream whose first use has not been committed,
|
||||
/// with the command buffer that first uses one: the stream's writes into such a buffer go to
|
||||
/// its GPU copy too.
|
||||
fresh: HashMap<u64, Option<u64>>,
|
||||
/// The no-copy Managed buffers whose GPU copy took bytes written before their first use.
|
||||
from_first_use: HashSet<u64>,
|
||||
/// Whether the stream told the form itself (`m2v.deviceIdentity`): its no-copy Managed
|
||||
/// buffers then carry their bytes at creation.
|
||||
identity: bool,
|
||||
/// 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<u64, Vec<Place>>,
|
||||
@@ -144,6 +173,17 @@ pub struct NewRuntime {
|
||||
kernels: HashSet<Kernel>,
|
||||
}
|
||||
|
||||
/// The objects `values` name, lists included.
|
||||
fn objects_named(values: &[Value], out: &mut Vec<u64>) {
|
||||
for value in values {
|
||||
match value {
|
||||
Value::Object(id) => out.push(*id),
|
||||
Value::List(items) => objects_named(items, out),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A made object with no address.
|
||||
fn unaddressed(object: Object) -> Result<Option<(Object, Made)>, PlayError> {
|
||||
Ok(Some((object, Made::default())))
|
||||
@@ -341,7 +381,12 @@ impl NewRuntime {
|
||||
completed: 0,
|
||||
skips: Skips::default(),
|
||||
substitutes: Substitutes::default(),
|
||||
blit_owners: HashMap::new(),
|
||||
owners: HashMap::new(),
|
||||
managed: None,
|
||||
managed_buffers: 0,
|
||||
fresh: HashMap::new(),
|
||||
from_first_use: HashSet::new(),
|
||||
identity: false,
|
||||
staging: HashMap::new(),
|
||||
staged_bytes: 0,
|
||||
unanswered_pipeline_ids: 0,
|
||||
@@ -351,6 +396,26 @@ impl NewRuntime {
|
||||
})
|
||||
}
|
||||
|
||||
/// The backend told how the stream's recording device kept Managed buffers.
|
||||
pub fn with_managed(mut self, copies: ManagedCopies) -> Self {
|
||||
self.managed = Some(copies);
|
||||
self
|
||||
}
|
||||
|
||||
/// How a Managed buffer of `call` plays: as a Shared buffer for a one-copy stream, the
|
||||
/// runtime's Managed buffer for a two-copy one; refused where the player was not told.
|
||||
fn managed_form(&mut self, call: &Call) -> Result<ManagedCopies, PlayError> {
|
||||
let copies = self.managed.ok_or_else(|| {
|
||||
refuse(
|
||||
call,
|
||||
"a Managed buffer, and the stream's Managed form (one copy or two: the \
|
||||
recording device's hasUnifiedMemory) was not given",
|
||||
)
|
||||
})?;
|
||||
self.managed_buffers += 1;
|
||||
Ok(copies)
|
||||
}
|
||||
|
||||
fn get(&self, call: &Call, id: u64) -> Result<&Object, PlayError> {
|
||||
self.objects.get(&id).ok_or_else(|| {
|
||||
PlayError::Invalid(format!("{}: #{id} is no live object", call.selector))
|
||||
@@ -476,14 +541,28 @@ impl NewRuntime {
|
||||
}
|
||||
|
||||
/// A buffer of `length` bytes and storage `mode` in a place of its own, zeroed, holding
|
||||
/// `bytes` from its start.
|
||||
/// `bytes` from its start; `no_copy` where its bytes are the program's memory.
|
||||
fn new_buffer(
|
||||
&mut self,
|
||||
call: &Call,
|
||||
length: u64,
|
||||
mode: rt::StorageMode,
|
||||
bytes: &[u8],
|
||||
no_copy: bool,
|
||||
) -> Result<Option<(Object, Made)>, PlayError> {
|
||||
let mode = match mode {
|
||||
rt::StorageMode::Managed => match self.managed_form(call)? {
|
||||
ManagedCopies::One => rt::StorageMode::Shared,
|
||||
ManagedCopies::Two => {
|
||||
// A stream that tells its form gives a no-copy buffer's bytes at creation.
|
||||
if no_copy && !self.identity && bytes.is_empty() {
|
||||
self.fresh.insert(call.result, None);
|
||||
}
|
||||
rt::StorageMode::Managed
|
||||
}
|
||||
},
|
||||
mode => mode,
|
||||
};
|
||||
let class = match mode {
|
||||
rt::StorageMode::Private if bytes.is_empty() => rt::MemoryClass::Private,
|
||||
rt::StorageMode::Shared | rt::StorageMode::Managed => rt::MemoryClass::Shared,
|
||||
@@ -739,11 +818,13 @@ impl NewRuntime {
|
||||
}
|
||||
"newBufferWithLength:options:" => {
|
||||
let mode = storage(call, uint(call, 1)?)?;
|
||||
self.new_buffer(call, uint(call, 0)?, mode, &[])
|
||||
self.new_buffer(call, uint(call, 0)?, mode, &[], false)
|
||||
}
|
||||
"newBufferWithBytesNoCopy:length:options:deallocator:" => {
|
||||
let mode = storage(call, uint(call, 2)?)?;
|
||||
self.new_buffer(call, uint(call, 1)?, mode, &[])
|
||||
// The pages' bytes at creation, where the stream gives them.
|
||||
let bytes = arg(call, 0)?.as_bytes().unwrap_or_default();
|
||||
self.new_buffer(call, uint(call, 1)?, mode, bytes, true)
|
||||
}
|
||||
"newBufferWithBytes:length:options:" => {
|
||||
let length = uint(call, 1)?;
|
||||
@@ -752,7 +833,7 @@ impl NewRuntime {
|
||||
.and_then(|length| data(call, 0).ok()?.get(..length))
|
||||
.ok_or_else(|| refuse(call, "fewer bytes than its length"))?;
|
||||
let mode = storage(call, uint(call, 2)?)?;
|
||||
self.new_buffer(call, length, mode, bytes)
|
||||
self.new_buffer(call, length, mode, bytes, false)
|
||||
}
|
||||
"newBufferWithDescriptor:" => {
|
||||
let f = Fields::arg(
|
||||
@@ -768,12 +849,17 @@ impl NewRuntime {
|
||||
"zeroFrom",
|
||||
],
|
||||
)?;
|
||||
if f.get("contents").is_some() {
|
||||
return Err(refuse(call, "contents that are no bytes"));
|
||||
}
|
||||
// A no-copy buffer's bytes at creation, where the stream gives them.
|
||||
let contents = match f.get("contents") {
|
||||
None => &[][..],
|
||||
Some(value) => value
|
||||
.as_bytes()
|
||||
.ok_or_else(|| refuse(call, "contents that are no bytes"))?,
|
||||
};
|
||||
let raw = option_sets(call, 0, f.list("options")?.unwrap_or_default())?;
|
||||
let length = f.required("length", Fields::uint)?;
|
||||
self.new_buffer(call, length, storage(call, raw)?, &[])
|
||||
let no_copy = f.get("noCopy").and_then(Value::as_bool) == Some(true);
|
||||
self.new_buffer(call, length, storage(call, raw)?, contents, no_copy)
|
||||
}
|
||||
"m2v.newBlockWithLength:storageMode:" | "newHeapWithDescriptor:" => {
|
||||
let (length, class) = match &*call.selector {
|
||||
@@ -989,11 +1075,16 @@ impl NewRuntime {
|
||||
) -> Result<Option<(Object, Made)>, PlayError> {
|
||||
// A buffer of `length` bytes and storage options `raw` at `offset` in the block.
|
||||
let device = self.device.clone();
|
||||
let placed = |length: u64, raw: u64, offset: u64| {
|
||||
let mut placed = |length: u64, raw: u64, offset: u64| {
|
||||
let at = range.offset + offset;
|
||||
let buffer = match storage(call, raw)? {
|
||||
rt::StorageMode::Managed if class == rt::MemoryClass::Shared => {
|
||||
device.new_managed_buffer(range.block, at, length, length)
|
||||
match self.managed_form(call)? {
|
||||
ManagedCopies::One => device.new_buffer(range.block, at, length, false),
|
||||
ManagedCopies::Two => {
|
||||
device.new_managed_buffer(range.block, at, length, length)
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => device.new_buffer(range.block, at, length, false),
|
||||
};
|
||||
@@ -1141,6 +1232,8 @@ fn write_into(buffer: &rt::Buffer, offset: u64, bytes: &[u8]) -> Result<(), Play
|
||||
impl Backend for NewRuntime {
|
||||
fn call(&mut self, call: &Call) -> Result<Made, PlayError> {
|
||||
if &*call.selector == "release" {
|
||||
self.owners.remove(&call.receiver);
|
||||
self.fresh.remove(&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
|
||||
@@ -1177,6 +1270,19 @@ impl Backend for NewRuntime {
|
||||
self.objects.insert(call.result, Object::Skipped);
|
||||
return Ok(Made::default());
|
||||
}
|
||||
if !self.fresh.is_empty() {
|
||||
// An encoder naming a no-copy Managed buffer not yet used: its command buffer is the
|
||||
// buffer's first use.
|
||||
if let Some(&user) = self.owners.get(&call.receiver) {
|
||||
let mut named = Vec::new();
|
||||
objects_named(&call.args, &mut named);
|
||||
for id in named {
|
||||
if let Some(first @ None) = self.fresh.get_mut(&id) {
|
||||
*first = Some(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let made = match call.receiver {
|
||||
0 => self.device_call(call)?,
|
||||
id => match self.get(call, id)? {
|
||||
@@ -1273,7 +1379,21 @@ impl Backend for NewRuntime {
|
||||
|
||||
fn write(&mut self, target: u64, offset: u64, bytes: &[u8]) -> Result<(), PlayError> {
|
||||
match self.objects.get(&target) {
|
||||
Some(Object::Buffer(buffer, _)) => write_into(buffer, offset, bytes),
|
||||
Some(Object::Buffer(buffer, _)) => {
|
||||
write_into(buffer, offset, bytes)?;
|
||||
// Bytes recorded before a no-copy Managed buffer's first use are its contents
|
||||
// at creation, as near as the stream has them: its GPU copy takes them too.
|
||||
if self.fresh.contains_key(&target) && !bytes.is_empty() {
|
||||
let length = bytes.len() as u64;
|
||||
let did = buffer.did_modify_range(offset, length);
|
||||
did.map_err(|error| PlayError::Runtime {
|
||||
selector: "m2v.write".into(),
|
||||
error: error.to_string(),
|
||||
})?;
|
||||
self.from_first_use.insert(target);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Some(Object::Block(range, rt::MemoryClass::Shared, _)) => {
|
||||
let whole = self
|
||||
.device
|
||||
@@ -1428,7 +1548,40 @@ impl Backend for NewRuntime {
|
||||
let kernel = if made.new_kernel { "new" } else { "again" };
|
||||
format!("pipeline {at} wall_nanos={} kernel={kernel}", made.nanos)
|
||||
});
|
||||
lines.collect()
|
||||
let mut lines: Vec<String> = lines.collect();
|
||||
if let Some(copies) = self.managed {
|
||||
let from = match self.identity {
|
||||
true => "the stream's device identity",
|
||||
false => "the player's setting",
|
||||
};
|
||||
let mut line = match copies {
|
||||
ManagedCopies::One => format!(
|
||||
"managed one copy ({from}): {} Managed buffers played as Shared",
|
||||
self.managed_buffers
|
||||
),
|
||||
ManagedCopies::Two => format!(
|
||||
"managed two copies ({from}): {} Managed buffers; {} no-copy ones with \
|
||||
contents from first use, not from create",
|
||||
self.managed_buffers,
|
||||
self.from_first_use.len()
|
||||
),
|
||||
};
|
||||
if copies == ManagedCopies::Two && self.device.has_unified_memory() {
|
||||
line.push_str(
|
||||
"; recorded with two copies, played as this device's one copy (unified memory)",
|
||||
);
|
||||
}
|
||||
lines.push(line);
|
||||
}
|
||||
lines
|
||||
}
|
||||
|
||||
fn recorded_unified_memory(&mut self, unified: bool) {
|
||||
self.identity = true;
|
||||
self.managed = Some(match unified {
|
||||
true => ManagedCopies::One,
|
||||
false => ManagedCopies::Two,
|
||||
});
|
||||
}
|
||||
|
||||
/// The runtime makes no blits between buffers yet.
|
||||
|
||||
@@ -105,6 +105,10 @@ pub trait Backend {
|
||||
/// player's own. Where it does not, those dispatches play as they are, counted
|
||||
/// (`Report::unsnapshotted`).
|
||||
fn snapshots(&self) -> bool;
|
||||
|
||||
/// The recording device's `hasUnifiedMemory`, from the stream's `m2v.deviceIdentity` record:
|
||||
/// how it kept Managed buffers. A backend with one form of Managed buffer ignores it.
|
||||
fn recorded_unified_memory(&mut self, _unified: bool) {}
|
||||
}
|
||||
|
||||
/// Why a play stopped.
|
||||
@@ -1125,6 +1129,12 @@ impl<'b, B: Backend> Player<'b, B> {
|
||||
let queue = self.queue_of(call.receiver)?;
|
||||
self.part(queue, call.result)
|
||||
}
|
||||
"m2v.deviceIdentity" => {
|
||||
if let Some(unified) = call.answer("hasUnifiedMemory").and_then(Value::as_bool) {
|
||||
self.backend.recorded_unified_memory(unified);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
"m2v.setCompletionJoinsNext"
|
||||
| "m2v.holdsNoPredication"
|
||||
| "m2v.rebindNoCopy"
|
||||
|
||||
@@ -300,6 +300,8 @@ struct Kept {
|
||||
declines_snapshots: bool,
|
||||
/// The GPU start and end it gives each command buffer; one not here has none.
|
||||
gpu: HashMap<u64, (u64, u64)>,
|
||||
/// The recording device's `hasUnifiedMemory` the player told it.
|
||||
unified: Option<bool>,
|
||||
}
|
||||
|
||||
impl Backend for Kept {
|
||||
@@ -406,6 +408,10 @@ impl Backend for Kept {
|
||||
fn snapshots(&self) -> bool {
|
||||
!self.declines_snapshots
|
||||
}
|
||||
|
||||
fn recorded_unified_memory(&mut self, unified: bool) {
|
||||
self.unified = Some(unified);
|
||||
}
|
||||
}
|
||||
|
||||
/// `build`'s stream, played on `backend`.
|
||||
@@ -1169,6 +1175,26 @@ fn a_message_to_nil_does_nothing() {
|
||||
assert_eq!(report.total.stream["calls"], 2);
|
||||
}
|
||||
|
||||
/// A device identity record plays as nothing and tells the backend how the recording device kept
|
||||
/// Managed buffers.
|
||||
#[test]
|
||||
fn a_device_identity_record_tells_the_backend_how_managed_buffers_were_kept() {
|
||||
let mut kept = Kept::default();
|
||||
let (report, ended) = played(&mut kept, |w| {
|
||||
w.call("MTLCreateSystemDefaultDevice", 0, 1, &[], &[])?;
|
||||
let answers = [
|
||||
("name", Value::Str("GPU".into())),
|
||||
("hasUnifiedMemory", Value::Bool(false)),
|
||||
];
|
||||
w.call("m2v.deviceIdentity", 1, 0, &[], &answers)?;
|
||||
Ok(())
|
||||
});
|
||||
ended.unwrap();
|
||||
assert_eq!(kept.calls, ["#1 = MTLCreateSystemDefaultDevice"]);
|
||||
assert_eq!(kept.unified, Some(false));
|
||||
assert_eq!(report.total.stream["calls"], 2);
|
||||
}
|
||||
|
||||
/// Each frame's end reports the backend's gauges as they stand then, never their growth over the
|
||||
/// frame, beside the frame's wall time.
|
||||
#[test]
|
||||
|
||||
+30
-3
@@ -100,6 +100,12 @@ and the (name id, value) answer pairs.
|
||||
its last reference). Releasing a device releases everything it made.
|
||||
- **Devices:** `MTLCreateSystemDefaultDevice`, one per device the recording's host made; every
|
||||
guest process may share one. The player serves every recorded device from one runtime device.
|
||||
- **Device identity:** `m2v.deviceIdentity` (receiver: the device; no arguments) follows each
|
||||
`MTLCreateSystemDefaultDevice` record, and opens every later segment, one record per live device
|
||||
in id order. Its answers are `name` (the recording runtime's device name) and
|
||||
`hasUnifiedMemory` (what the guest's `hasUnifiedMemory` answered), and later keys may join them.
|
||||
It plays as nothing; the player takes from it how the recording kept Managed buffers
|
||||
(section 10). A stream without it says nothing of that.
|
||||
- Everything else is made by its Metal selector: queues, command buffers, encoders of every kind,
|
||||
buffers, heaps, textures and views, samplers, depth and stencil states, events, shared events,
|
||||
fences, indirect command buffers, libraries, functions, pipeline states, argument encoders and
|
||||
@@ -127,6 +133,14 @@ and the (name id, value) answer pairs.
|
||||
without a pinned address answers none. `newBufferWithBytesNoCopy:length:options:deallocator:`
|
||||
is `[nil, length, options, nil]`, and a no-copy descriptor's `contents` nil; their bytes arrive
|
||||
as writes.
|
||||
- **A no-copy Managed buffer's bytes at its making.** Where the device's `hasUnifiedMemory` is
|
||||
false, the GPU copy of a Managed buffer is made from its bytes at its making, then changed only by
|
||||
`didModifyRange:`. A no-copy one (storage mode Managed) then carries those bytes:
|
||||
`newBufferWithBytesNoCopy:length:options:deallocator:`'s first argument holds all its bytes as
|
||||
the making read them (a blob where they are 64 bytes or longer, bytes otherwise), and a no-copy
|
||||
descriptor's `contents` holds its bytes up to `zeroFrom` (all of them where `zeroFrom` is nil;
|
||||
nil where it is 0), its GPU copy zero from there. Its bytes still arrive as writes before its
|
||||
first use, as any buffer's do.
|
||||
- **Copied buffers.** A buffer `newBufferWithDescriptor:` made as a copy of host memory (`contents`
|
||||
set, `noCopy` not) carries the bytes it starts with as its descriptor's `contents`: a blob where
|
||||
they are 64 bytes or longer, bytes otherwise. The player makes the buffer, then puts them at its
|
||||
@@ -321,7 +335,7 @@ and the (name id, value) answer pairs.
|
||||
| `front`, `back` | `frontFaceStencil`, `backFaceStencil` |
|
||||
| `heapType` | `type` |
|
||||
| `options` | the setters of `resourceOptions`, `storageMode` and `hazardTrackingMode` |
|
||||
| `pinnedGpuAddress`, `contents`, `noCopy`, `deallocator`, `zeroFrom` | the host's buffer creation: a pin, the bytes a copied buffer starts with (section 5), no-copy host memory and its deallocator, and the bytes known zero from an offset |
|
||||
| `pinnedGpuAddress`, `contents`, `noCopy`, `deallocator`, `zeroFrom` | the host's buffer creation: a pin, the bytes a copied buffer starts with or a no-copy Managed one's at its making (section 5), no-copy host memory and its deallocator, and the bytes known zero from an offset |
|
||||
| `openGlModeEnabled`, `openClMode` | `openGLModeEnabled`, `openCLModeEnabled` |
|
||||
| `znear`, `zfar` | `MTLViewport`'s `znear` and `zfar` |
|
||||
| `rotation`, `isDrawable`, `framebufferOnly`, `protectionOptions`, `writeSwizzleEnabled` | Apple's texture descriptor properties of those names |
|
||||
@@ -339,8 +353,9 @@ 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]` 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]` 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`.
|
||||
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
|
||||
@@ -348,6 +363,18 @@ their times and memory compare. `command-replay dump --stream FILE` prints the c
|
||||
|
||||
- It relocates (section 5) and plays the host's plumbing as the plain calls it stands for
|
||||
(section 4).
|
||||
- **Managed buffers** (the new runtime) play in the form the recording device kept them: its
|
||||
`m2v.deviceIdentity` record's `hasUnifiedMemory`, or where the stream has none, `--managed`
|
||||
(`one-copy` for unified memory, `two-copy` for a GPU copy). With neither, a Managed buffer stops
|
||||
the play with an error that says so. One copy: every Managed buffer plays as a Shared buffer, on
|
||||
every device. Two copies: it plays as the runtime's Managed buffer, whose GPU copy starts from
|
||||
the bytes it was made with: a copied buffer's bytes, or a no-copy one's bytes at its making
|
||||
(section 5). A stream with no identity record gives a no-copy buffer none, so its GPU copy takes
|
||||
the writes recorded before its first use (a commit of a command buffer one of whose encoders
|
||||
names it), the nearest record the stream has of its bytes at its making. On a device with
|
||||
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.
|
||||
- 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
|
||||
|
||||
Reference in new issue
Block a user