Player: a render encoder's residency declarations play through the runtime
The render encoder's arm played its eight residency forms (useResource:usage:,
useResources:count:usage:, useHeap:, useHeaps:count:, each with stages: or without) as nothing,
"as the runtime's render encoder has none". The runtime's RenderCommandEncoder has use_resource
and use_heap now, so they play through it as a compute encoder's do: each resource of the call,
or of its list, through use_resource with the call's usage; each heap, or each of its list,
through use_heap. The stream records each C array and its count as one list, so the usage is
argument 1, and the stages come last; the runtime's render encoder takes no stages, so they are
not read.
What each read before, and now:
- Render encoder, all eight forms: before, no argument and no runtime call; a skipped object they
named was not counted. Now: the resource ({Buffer: object} or {Texture: object}) or heap of
argument 0, each of a list; the usage at argument 1; a skipped object is a skipped call, each
of a list as its own, as docs/REPLAY-STREAM.md says of skipped_calls.
- Compute encoder, the four forms: unchanged in what they read; one resolver (NewRuntime::uses)
now serves both encoders, and heap_of, which only the compute arm called, is gone.
- The usage: before, 1, 2 or 3, any other value refused. Now MTLResourceUsage's option set of
read (1), write (2) and sample (4), any other bit or none refused. Without the sample bit, a
render encoder's useResource:usage: of read | sample, which played as nothing before, would
now be refused.
- objects_named, which the unwritten count reads a render or blit encoder's call by, and which
notes the objects a command buffer's encoders name (resource indices owed, placed buffers' and
no-copy Managed buffers' users, tiled textures' takes): before, bare objects and lists only, so
a residency declaration's {Buffer: object} or {Texture: object} named nothing. Now it names the
resource too, on compute and render encoders alike.
docs/REPLAY-STREAM.md: render and compute encoders play their residency declarations through
the runtime's encoder, the stages forms as those without; the unwritten count's reaching calls
include a residency declaration's resource.
Tests: the commit before this one (red: the skipped-object device test and the unwritten test).
This commit is contained in:
1 parent
980262d1b4
commit
17473a1a42
5 files changed
+99
-86
No files matched your search
@@ -79,32 +79,69 @@ fn buffer_layout(call: &Call, at: usize) -> Result<rt::BufferLayout, PlayError>
|
||||
})
|
||||
}
|
||||
|
||||
/// A residency declaration's usage (`MTLResourceUsage`, argument 1): read, write or both.
|
||||
/// A residency declaration's usage (`MTLResourceUsage`, argument 1): an option set of read (1),
|
||||
/// write (2) and sample (4).
|
||||
fn resource_usage(call: &Call) -> Result<rt::ResourceUsage, PlayError> {
|
||||
Ok(match uint(call, 1)? {
|
||||
1 => rt::ResourceUsage::READ,
|
||||
2 => rt::ResourceUsage::WRITE,
|
||||
3 => rt::ResourceUsage::READ | rt::ResourceUsage::WRITE,
|
||||
raw => return Err(refuse(call, format!("resource usage {raw}"))),
|
||||
})
|
||||
let raw = uint(call, 1)?;
|
||||
let bits = [
|
||||
(1, rt::ResourceUsage::READ),
|
||||
(2, rt::ResourceUsage::WRITE),
|
||||
(4, rt::ResourceUsage::SAMPLE),
|
||||
];
|
||||
let usage = (bits.into_iter())
|
||||
.filter(|(bit, _)| raw & bit != 0)
|
||||
.map(|(_, usage)| usage)
|
||||
.reduce(|all, usage| all | usage);
|
||||
match usage {
|
||||
Some(usage) if raw & !7 == 0 => Ok(usage),
|
||||
_ => Err(refuse(call, format!("resource usage {raw}"))),
|
||||
}
|
||||
}
|
||||
|
||||
/// What a residency declaration uses: a buffer or a texture with the call's usage, or a heap's
|
||||
/// block.
|
||||
pub(super) enum Use {
|
||||
Buffer(rt::Buffer, rt::ResourceUsage),
|
||||
Texture(rt::Texture, rt::ResourceUsage),
|
||||
Heap(rt::BlockId),
|
||||
}
|
||||
|
||||
impl NewRuntime {
|
||||
/// Compute encoder `id` uses `held` with `usage`: through the runtime's `use_resource`; a
|
||||
/// skipped object counted.
|
||||
fn use_held(&mut self, id: u64, held: Held, usage: rt::ResourceUsage) -> Result<(), rt::Error> {
|
||||
match held {
|
||||
Held::Buffer(buffer) => {
|
||||
(self.compute(id).encoder).use_resource(rt::Resource::Buffer(&buffer), usage)
|
||||
}
|
||||
Held::Texture(texture) => {
|
||||
(self.compute(id).encoder).use_resource(rt::Resource::Texture(&texture), usage)
|
||||
}
|
||||
Held::Skipped => {
|
||||
self.skips.calls += 1;
|
||||
Ok(())
|
||||
/// What residency declaration `call` of a compute or render encoder uses, each of a list as
|
||||
/// its single form, as the stream records it (a C array and its count one list):
|
||||
/// `useResource:usage:`'s resource and each of `useResources:count:usage:`'s list, with the
|
||||
/// usage at argument 1; `useHeap:`'s heap and each of `useHeaps:count:`'s. A render encoder's
|
||||
/// forms with `stages:` read as those without: the runtime takes no stages. A skipped object
|
||||
/// uses nothing, and is counted.
|
||||
pub(super) fn uses(&mut self, call: &Call) -> Result<Vec<Use>, PlayError> {
|
||||
let items = match call.selector.contains("count:") {
|
||||
true => list(call, 0)?,
|
||||
false => std::slice::from_ref(arg(call, 0)?),
|
||||
};
|
||||
let usage = match call.selector.starts_with("useResource") {
|
||||
true => Some(resource_usage(call)?),
|
||||
false => None,
|
||||
};
|
||||
let mut uses = Vec::with_capacity(items.len());
|
||||
for item in items {
|
||||
let used = match usage {
|
||||
Some(usage) => match self.held(call, item)? {
|
||||
Held::Buffer(buffer) => Some(Use::Buffer(buffer, usage)),
|
||||
Held::Texture(texture) => Some(Use::Texture(texture, usage)),
|
||||
Held::Skipped => None,
|
||||
},
|
||||
None => {
|
||||
let heap =
|
||||
(item.as_object()).ok_or_else(|| refuse(call, format!("heap {item}")))?;
|
||||
self.block_of(call, heap)?.map(Use::Heap)
|
||||
}
|
||||
};
|
||||
match used {
|
||||
Some(used) => uses.push(used),
|
||||
None => self.skips.calls += 1,
|
||||
}
|
||||
}
|
||||
Ok(uses)
|
||||
}
|
||||
|
||||
/// An event argument: an event's, or a shared event's.
|
||||
@@ -397,24 +434,18 @@ impl NewRuntime {
|
||||
_ => encoder.dispatch_threadgroups(grid, threads),
|
||||
}
|
||||
}
|
||||
"useResource:usage:" => {
|
||||
let usage = resource_usage(call)?;
|
||||
let held = self.resource(call, 0)?;
|
||||
self.use_held(id, held, usage)
|
||||
}
|
||||
// The C array and its count are one list (docs/REPLAY-STREAM.md): each resource of
|
||||
// it used as `useResource:usage:` uses its one.
|
||||
"useResources:count:usage:" => {
|
||||
let usage = resource_usage(call)?;
|
||||
let mut used = Ok(());
|
||||
for item in list(call, 0)? {
|
||||
let held = self.held(call, item)?;
|
||||
used = self.use_held(id, held, usage);
|
||||
if used.is_err() {
|
||||
break;
|
||||
"useResource:usage:" | "useResources:count:usage:" | "useHeap:" | "useHeaps:count:" => {
|
||||
let uses = self.uses(call)?;
|
||||
let encoder = &mut self.compute(id).encoder;
|
||||
uses.iter().try_for_each(|used| match used {
|
||||
Use::Buffer(buffer, usage) => {
|
||||
encoder.use_resource(rt::Resource::Buffer(buffer), *usage)
|
||||
}
|
||||
}
|
||||
used
|
||||
Use::Texture(texture, usage) => {
|
||||
encoder.use_resource(rt::Resource::Texture(texture), *usage)
|
||||
}
|
||||
Use::Heap(block) => encoder.use_heap(*block),
|
||||
})
|
||||
}
|
||||
"updateFence:" => {
|
||||
let fence = self.fence_of(call, 0)?;
|
||||
@@ -424,33 +455,6 @@ impl NewRuntime {
|
||||
let fence = self.fence_of(call, 0)?;
|
||||
self.compute(id).encoder.wait_for_fence(&fence)
|
||||
}
|
||||
"useHeap:" => match self.heap_of(call, 0)? {
|
||||
Some(heap) => self.compute(id).encoder.use_heap(heap),
|
||||
None => {
|
||||
self.skips.calls += 1;
|
||||
Ok(())
|
||||
}
|
||||
},
|
||||
// Each heap of the list used as `useHeap:` uses its one.
|
||||
"useHeaps:count:" => {
|
||||
let mut used = Ok(());
|
||||
for item in list(call, 0)? {
|
||||
let id_of = item
|
||||
.as_object()
|
||||
.ok_or_else(|| refuse(call, format!("heap {item}")))?;
|
||||
used = match self.block_of(call, id_of)? {
|
||||
Some(heap) => self.compute(id).encoder.use_heap(heap),
|
||||
None => {
|
||||
self.skips.calls += 1;
|
||||
Ok(())
|
||||
}
|
||||
};
|
||||
if used.is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
used
|
||||
}
|
||||
_ => return Err(refuse(call, "not played on a compute encoder")),
|
||||
};
|
||||
result.map_err(failed(call))
|
||||
|
||||
@@ -644,12 +644,14 @@ pub struct NewRuntime {
|
||||
videos: videos::Videos,
|
||||
}
|
||||
|
||||
/// The objects `values` name, lists included.
|
||||
/// The objects `values` name, lists included, and a resource argument's (`{Buffer: object}` or
|
||||
/// `{Texture: object}`).
|
||||
pub(super) 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),
|
||||
Value::Map(_) => out.extend(value.as_resource()),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@@ -1215,11 +1217,6 @@ impl NewRuntime {
|
||||
}
|
||||
}
|
||||
|
||||
/// The block of the heap argument `at` names; none for a skipped object.
|
||||
fn heap_of(&self, call: &Call, at: usize) -> Result<Option<rt::BlockId>, PlayError> {
|
||||
self.block_of(call, Self::id(call, at)?)
|
||||
}
|
||||
|
||||
/// The block of heap `id`; none for a skipped object.
|
||||
fn block_of(&self, call: &Call, id: u64) -> Result<Option<rt::BlockId>, PlayError> {
|
||||
match self.get(call, id)? {
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
use super::super::args::{arg, data, index, list, metal, refuse, uint, Fields};
|
||||
use super::super::translator::{self, attachment_keys, LINKED_KEYS, PASS_KEYS};
|
||||
use super::encoders::first;
|
||||
use super::encoders::{first, Use};
|
||||
use super::{failed, makes, states, unaddressed, NewRuntime, Object, Skips};
|
||||
use crate::replay::player::{Made, PlayError};
|
||||
use crate::replay::stream::Call;
|
||||
@@ -1018,9 +1018,8 @@ impl NewRuntime {
|
||||
self.render(id).encoder.set_line_width(width);
|
||||
Ok(())
|
||||
}
|
||||
// A render encoder's residency declarations: no runtime call, as the runtime's render
|
||||
// encoder has none and every object of the play is resident. What they name is noted
|
||||
// before the call plays, as any encoder call's names are.
|
||||
// A render encoder's residency declarations, through the runtime's, with `stages:` or
|
||||
// without ([`uses`](Self::uses)).
|
||||
"useResource:usage:"
|
||||
| "useResource:usage:stages:"
|
||||
| "useResources:count:usage:"
|
||||
@@ -1028,7 +1027,19 @@ impl NewRuntime {
|
||||
| "useHeap:"
|
||||
| "useHeap:stages:"
|
||||
| "useHeaps:count:"
|
||||
| "useHeaps:count:stages:" => Ok(()),
|
||||
| "useHeaps:count:stages:" => {
|
||||
let uses = self.uses(call)?;
|
||||
let encoder = &mut self.render(id).encoder;
|
||||
uses.iter().try_for_each(|used| match used {
|
||||
Use::Buffer(buffer, usage) => {
|
||||
encoder.use_resource(rt::Resource::Buffer(buffer), *usage)
|
||||
}
|
||||
Use::Texture(texture, usage) => {
|
||||
encoder.use_resource(rt::Resource::Texture(texture), *usage)
|
||||
}
|
||||
Use::Heap(block) => encoder.use_heap(*block),
|
||||
})
|
||||
}
|
||||
_ => return Err(refuse(call, "not played on a render encoder")),
|
||||
};
|
||||
match result {
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
//!
|
||||
//! 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);
|
||||
//! buffer of the block over them (a copy, a fill, an upload from the guest's RAM, an attachment, a
|
||||
//! residency declaration);
|
||||
//! and the commit of a command buffer whose dispatch writes it or another buffer of the block over
|
||||
//! them. A block's bytes reached before a buffer is made over them reach the buffer, as those
|
||||
//! after do. Every commit the player makes counts here: a `commit`, an `m2v.split` and an
|
||||
|
||||
+10
-10
@@ -631,7 +631,8 @@ records as text, and
|
||||
written, and the line says how many of the count were. In a command buffer a dispatch's write
|
||||
comes before the later dispatches' reads. 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 command buffer whose
|
||||
encoder's call that names it or such another buffer (a residency declaration's resource
|
||||
included, `{Buffer: object}`); and the commit of a command buffer whose
|
||||
dispatch writes it or such another buffer. A buffer made in a block over bytes that a write or a
|
||||
GPU pass reached before is not counted. Every commit the player makes counts: a `commit`, an
|
||||
`m2v.split` and an `m2v.commitPart` it cuts. A texture over a buffer is not followed. The line
|
||||
@@ -929,18 +930,17 @@ records as text, and
|
||||
buffers, offsets, bytes, textures and sampler states, the viewport, scissor, cull mode, winding,
|
||||
blend color and stencil references, the draws (indexed or not, with instance counts, base
|
||||
vertex and base instance), fences and memory barriers (their stages are the runtime's to
|
||||
order). Their residency declarations (`useResource:usage:`, `useResources:count:usage:`,
|
||||
`useHeap:` and `useHeaps:count:`, each with `stages:` or without) play as nothing: the
|
||||
runtime's render encoder has no such call, and every object of the play is resident. A bind
|
||||
of a range (`withRange:`) of buffers, textures or sampler states plays as the single-slot bind
|
||||
of each, from the range's location, on render and compute encoders alike.
|
||||
order). A bind of a range (`withRange:`) of buffers, textures or sampler states plays as the
|
||||
single-slot bind of each, from the range's location, on render and compute encoders alike.
|
||||
Compute encoders play `setStageInRegion:` (the runtime takes it and it changes nothing a
|
||||
dispatch of a kernel without a stage-in argument does, the only kernel it builds) and
|
||||
`setImageblockWidth:height:`, whose size the player's pre-pass passes with each dispatch it
|
||||
prepares, 1 by 1 until the encoder sets one. They play their residency declarations through the
|
||||
runtime's compute encoder: `useResource:usage:` and, for each resource of its list,
|
||||
`useResources:count:usage:` through `use_resource` with the usage; `useHeap:` and, for each heap
|
||||
of its list, `useHeaps:count:` through `use_heap`.
|
||||
prepares, 1 by 1 until the encoder sets one. Render and compute encoders play their residency
|
||||
declarations through the runtime's encoder: `useResource:usage:` and, for each resource of its
|
||||
list, `useResources:count:usage:` through `use_resource` with the usage (`MTLResourceUsage`'s
|
||||
read, write and sample bits); `useHeap:` and, for each heap of its list, `useHeaps:count:`
|
||||
through `use_heap`. A render encoder's forms with `stages:` play as those without: the
|
||||
runtime's render encoder takes no stages.
|
||||
|
||||
`report.txt` holds one line per item: the mode line (`mode full: every call` or `mode
|
||||
states-only: ...`) first, then the line `recorded before the recorder's completion fix: the
|
||||
|
||||
Reference in new issue
Block a user