Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
46e001b5f2 | ||
|
|
7cd74a306e | ||
|
|
1404f9af90 | ||
|
|
5fc0508f0b | ||
|
|
96b703c4f2 |
No files matched your search
@@ -8,7 +8,7 @@
|
||||
//! [--binds 1|4|tex|tex-moved|ptr|params|params-off] [--host C] [--pages] [--heap] [--heap-churn K] \
|
||||
//! [--heap-kept H] [--live L] [--idle MS] [--vary] [--ragged] [--samplers K] [--classes K] \
|
||||
//! [--zero-classes Z] [--stay Q] [--states K] [--back-to-back] [--encoding-threads E] \
|
||||
//! [--queue-each] [--spawned] [--settle MS]
|
||||
//! [--settle MS]
|
||||
//! ```
|
||||
//!
|
||||
//! Each run is one command buffer of `N` dispatches (200 by default) of `G` threadgroups of `T`
|
||||
@@ -177,10 +177,7 @@
|
||||
//! `--encoding-threads E` runs `E` threads at once, started together each run, each making its own
|
||||
//! `C` command buffers on the one queue, as a guest's queue is walked on threads of its own: a
|
||||
//! `HOST <shape>/thread-<t>` line for each thread, its calls per its own dispatch, and the lines
|
||||
//! after it over every thread's dispatches. `--queue-each` gives each encoding thread a queue of
|
||||
//! its own, as a program whose threads each encode on their own queue does. `--spawned` runs one
|
||||
//! encoding thread as the several run, a thread of its own started each run, rather than on the
|
||||
//! calling thread. `HOST-COMMIT` splits the commit call by the device's
|
||||
//! after it over every thread's dispatches. `HOST-COMMIT` splits the commit call by the device's
|
||||
//! commit phases (`WorkCounts::commit_lowering_nanos` and kin). `HOST-THREADS` is each group of the
|
||||
//! process's threads' CPU time per dispatch over the counted runs, waits included, by the thread's
|
||||
//! name (Linux only, from `/proc/self/task/*/schedstat`): `committer` is the calling thread (the
|
||||
@@ -566,11 +563,6 @@ struct Shape {
|
||||
/// The threads that each encode a run's command buffers on the one queue at once
|
||||
/// (`--encoding-threads`).
|
||||
encoding_threads: u32,
|
||||
/// Whether each encoding thread encodes on a queue of its own (`--queue-each`).
|
||||
queue_each: bool,
|
||||
/// Whether one encoding thread is started each run, as several are, rather than the calling
|
||||
/// thread encoding (`--spawned`).
|
||||
spawned: bool,
|
||||
}
|
||||
|
||||
/// The dispatches of `--ragged`'s cycle of thread counts.
|
||||
@@ -611,28 +603,16 @@ impl Shape {
|
||||
states: 1,
|
||||
back_to_back: false,
|
||||
encoding_threads: 1,
|
||||
queue_each: false,
|
||||
spawned: false,
|
||||
};
|
||||
let mut args = std::env::args().skip(1);
|
||||
while let Some(flag) = args.next() {
|
||||
let flags = [
|
||||
"--pages",
|
||||
"--heap",
|
||||
"--vary",
|
||||
"--ragged",
|
||||
"--back-to-back",
|
||||
"--queue-each",
|
||||
"--spawned",
|
||||
];
|
||||
let flags = ["--pages", "--heap", "--vary", "--ragged", "--back-to-back"];
|
||||
if flags.contains(&flag.as_str()) {
|
||||
shape.pages |= flag == "--pages";
|
||||
shape.heap |= flag == "--heap";
|
||||
shape.vary |= flag == "--vary";
|
||||
shape.ragged |= flag == "--ragged";
|
||||
shape.back_to_back |= flag == "--back-to-back";
|
||||
shape.queue_each |= flag == "--queue-each";
|
||||
shape.spawned |= flag == "--spawned";
|
||||
continue;
|
||||
}
|
||||
let value = args.next().ok_or(format!("{flag} takes a value"))?;
|
||||
@@ -707,12 +687,6 @@ impl Shape {
|
||||
if shape.encoding_threads == 0 || (shape.encoding_threads > 1 && shape.host.is_none()) {
|
||||
return Err("--encoding-threads takes 1 or more, and more than 1 takes --host".into());
|
||||
}
|
||||
if shape.queue_each && shape.encoding_threads < 2 {
|
||||
return Err("--queue-each takes --encoding-threads 2 or more".into());
|
||||
}
|
||||
if shape.spawned && shape.host.is_none() {
|
||||
return Err("--spawned takes --host".into());
|
||||
}
|
||||
if shape.back_to_back && (shape.host.is_none() || shape.churn.is_some()) {
|
||||
return Err("--back-to-back takes --host and no --heap-churn".into());
|
||||
}
|
||||
@@ -1447,7 +1421,7 @@ impl Ours<'_> {
|
||||
if n > 0 && name == "barriers" {
|
||||
encoder.memory_barrier_with_scope(BarrierScope::BUFFERS);
|
||||
}
|
||||
self.bind(&mut encoder, shape.binds, dispatched as usize, &[])?;
|
||||
self.bind(&mut encoder, shape.binds, n as usize, &[])?;
|
||||
shape.dispatch(&mut encoder, dispatched)?;
|
||||
dispatched += 1;
|
||||
}
|
||||
@@ -1474,11 +1448,10 @@ impl Ours<'_> {
|
||||
Ok((gpu * 1e6 / dispatches, wall * 1e6 / dispatches))
|
||||
}
|
||||
|
||||
/// Bind what dispatch `n` of a command buffer binds, whatever encoder holds it: the words, and
|
||||
/// `bump_wide`'s read-only buffers (the next two of `churned`, the command buffer's buffers in
|
||||
/// its heap, where it has any) or `bump_tex`'s textures the other way round from dispatch
|
||||
/// `n - 1`, with their word of 1, at the offsets `n` moves to: so the `encoders` shape's
|
||||
/// dispatches, one an encoder, bind as the `serial` shape's do.
|
||||
/// Bind what dispatch `n` of an encoder binds: the words, and `bump_wide`'s read-only
|
||||
/// buffers (the next two of `churned`, the command buffer's buffers in its heap, where it has
|
||||
/// any) or `bump_tex`'s textures the other way round from dispatch `n - 1`, with their word
|
||||
/// of 1.
|
||||
fn bind(
|
||||
&self,
|
||||
encoder: &mut ComputeCommandEncoder,
|
||||
@@ -1594,7 +1567,7 @@ impl Ours<'_> {
|
||||
let state = &self.states[dispatched as usize % self.states.len()];
|
||||
encoder.set_compute_pipeline_state(state)?;
|
||||
lap.lap(&mut at, Call::Pipeline);
|
||||
self.bind(&mut encoder, shape.binds, dispatched as usize, &churned)?;
|
||||
self.bind(&mut encoder, shape.binds, n as usize, &churned)?;
|
||||
lap.lap(&mut at, Call::Bind);
|
||||
shape.dispatch(&mut encoder, dispatched)?;
|
||||
dispatched += 1;
|
||||
@@ -1631,26 +1604,24 @@ impl Ours<'_> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// [`run_host`](Self::run_host) on each of `hosts.len()` threads at once, thread `t` on
|
||||
/// `queues[t % queues.len()]`, each counted in its own sample: on the calling thread where
|
||||
/// there is one.
|
||||
/// [`run_host`](Self::run_host) on each of `hosts.len()` threads at once, all on `queue`, each
|
||||
/// counted in its own sample: on the calling thread where there is one.
|
||||
fn run_host_threads(
|
||||
&self,
|
||||
queues: &[CommandQueue],
|
||||
queue: &CommandQueue,
|
||||
name: &str,
|
||||
shape: &Shape,
|
||||
command_buffers: u32,
|
||||
hosts: &mut [HostSample],
|
||||
) -> Result<()> {
|
||||
if let ([host], false) = (&mut *hosts, shape.spawned) {
|
||||
return self.run_host(&queues[0], name, shape, command_buffers, host);
|
||||
if let [host] = hosts {
|
||||
return self.run_host(queue, name, shape, command_buffers, host);
|
||||
}
|
||||
let start = std::sync::Barrier::new(hosts.len());
|
||||
let ran: Vec<std::result::Result<(), String>> = std::thread::scope(|scope| {
|
||||
let running: std::io::Result<Vec<_>> = (hosts.iter_mut().enumerate())
|
||||
.map(|(thread, host)| {
|
||||
let start = &start;
|
||||
let queue = &queues[thread % queues.len()];
|
||||
std::thread::Builder::new()
|
||||
.name(format!("encoding-{thread}"))
|
||||
.spawn_scoped(scope, move || {
|
||||
@@ -1690,18 +1661,15 @@ impl Ours<'_> {
|
||||
/// Clear the words, run the host's time of `shape` as `name` holds it, and check the words.
|
||||
fn host_shape(&self, name: &str, shape: &Shape, command_buffers: u32) -> Result<()> {
|
||||
self.fill(0)?;
|
||||
let queue = self.device.new_command_queue()?;
|
||||
let encoding = shape.encoding_threads as usize;
|
||||
let made = (0..if shape.queue_each { encoding } else { 1 })
|
||||
.map(|_| self.device.new_command_queue())
|
||||
.collect::<std::result::Result<Vec<_>, _>>();
|
||||
let queues = made?;
|
||||
let mut first: Vec<HostSample> = (0..encoding).map(|_| HostSample::default()).collect();
|
||||
self.run_host_threads(&queues, name, shape, command_buffers, &mut first)?;
|
||||
self.run_host_threads(&queue, name, shape, command_buffers, &mut first)?;
|
||||
let mut hosts: Vec<HostSample> = (0..encoding).map(|_| HostSample::default()).collect();
|
||||
let (before, threads) = (self.device.work_counts(), cpu_by_group());
|
||||
let began = Instant::now();
|
||||
for _ in 0..shape.runs {
|
||||
self.run_host_threads(&queues, name, shape, command_buffers, &mut hosts)?;
|
||||
self.run_host_threads(&queue, name, shape, command_buffers, &mut hosts)?;
|
||||
}
|
||||
let wall = began.elapsed();
|
||||
let (after, threads_after) = (self.device.work_counts(), cpu_by_group());
|
||||
|
||||
@@ -18,7 +18,7 @@ impl State {
|
||||
/// The group the encoder opening now joins, asking `joining`, where its
|
||||
/// command buffer's tail holds one it may join (`encoder_fold.rs`'s **Where**): taken, with
|
||||
/// the tail, which the encoder records into, and, where it is the group's second encoder, the
|
||||
/// group's order joined to its first part's summary (`Fold::order`). `None` where it joins
|
||||
/// group's order built from its first part's summary (`Fold::order`). `None` where it joins
|
||||
/// none, the group left in place: the encoder's open closes it once it opened
|
||||
/// ([`close_fold`](Self::close_fold)). A refusal is counted by its reason ([`Refusal`]): the
|
||||
/// group's, or, where the tail holds none, why the encoder before left none
|
||||
@@ -55,14 +55,14 @@ impl State {
|
||||
return None;
|
||||
}
|
||||
// Its second encoder orders after its first part, as that part's end left it.
|
||||
let first = match fold.members.len() {
|
||||
1 => Some(&self.recorded.get(fold.leader)?.summary),
|
||||
let order = match fold.members.len() {
|
||||
1 => Some(FoldOrder::after(&self.recorded.get(fold.leader)?.summary)),
|
||||
_ => None,
|
||||
};
|
||||
self.tail = None;
|
||||
let mut fold = self.fold.take()?;
|
||||
if let Some(first) = first {
|
||||
fold.order.join(first);
|
||||
if let Some(order) = order {
|
||||
fold.order = order;
|
||||
}
|
||||
// It records into the tail outside any render pass instance (`encoder_fold.rs`'s
|
||||
// **Continued passes**).
|
||||
@@ -107,26 +107,19 @@ impl State {
|
||||
if !admits {
|
||||
return None;
|
||||
}
|
||||
// Its second encoder orders after its first part, as that part's end left it: joined
|
||||
// here, and cleared again where `writes` refuses it, so a group of one encoder holds
|
||||
// its order empty.
|
||||
let first = match fold.members.len() {
|
||||
1 => Some(&self.recorded.get(fold.leader)?.summary),
|
||||
let order = match fold.members.len() {
|
||||
1 => Some(FoldOrder::after(&self.recorded.get(fold.leader)?.summary)),
|
||||
_ => None,
|
||||
};
|
||||
let fold = self.fold.as_mut()?;
|
||||
if let Some(first) = first {
|
||||
fold.order.join(first);
|
||||
}
|
||||
if !writes(&fold.order) {
|
||||
if first.is_some() {
|
||||
fold.order.clear();
|
||||
}
|
||||
if !writes(order.as_ref().unwrap_or(&fold.order)) {
|
||||
counts.command_buffer_split_at_aliases();
|
||||
return None;
|
||||
}
|
||||
self.tail = None;
|
||||
let mut fold = self.fold.take()?;
|
||||
if let Some(order) = order {
|
||||
fold.order = order;
|
||||
}
|
||||
fold.order.continued();
|
||||
// The instance is the encoder's own from here: its pass holds it, and ends it or leaves
|
||||
// it open again as it ends.
|
||||
@@ -207,17 +200,15 @@ impl State {
|
||||
record.in_tail = true;
|
||||
}
|
||||
let (leader, batches) = (self.recorded.len() - 1, self.batches.all().len());
|
||||
// Its stash and its order take the room the command buffer's lists keep
|
||||
// (`spare_states.rs`).
|
||||
// Its stash takes the room the command buffer's lists keep (`spare_states.rs`).
|
||||
let mut stashed = self.stash_room.take().unwrap_or_default();
|
||||
stashed.extend(log);
|
||||
let order = self.order_room.take().unwrap_or_else(FoldOrder::none);
|
||||
let open = open.take();
|
||||
self.fold = Some(Box::new(Fold::begun(
|
||||
tail,
|
||||
(leader, encoder),
|
||||
(batches, joining),
|
||||
(stashed, order, open),
|
||||
(stashed, open),
|
||||
)));
|
||||
}
|
||||
(Some(_), None) => {
|
||||
@@ -257,7 +248,7 @@ impl State {
|
||||
/// commit, whose failure may split the group ([`split_failure`](Self::split_failure)). A lone
|
||||
/// encoder's comes back, for the caller to give back to the device's spares without this lock
|
||||
/// (`replay.rs`). A group of more gives the room of its stash back, emptied, for the next
|
||||
/// group's; and every group, the room of its order (`spare_states.rs`).
|
||||
/// group's (`spare_states.rs`).
|
||||
pub(crate) fn close_fold(&mut self, counts: &Counters) -> Vec<Replay> {
|
||||
let Some(mut fold) = self.fold.take() else {
|
||||
return Vec::new();
|
||||
@@ -266,11 +257,8 @@ impl State {
|
||||
let Fold {
|
||||
members,
|
||||
mut stashed,
|
||||
mut order,
|
||||
..
|
||||
} = *fold;
|
||||
order.clear();
|
||||
self.order_room = Some(order);
|
||||
if members.len() < 2 {
|
||||
return stashed.into_iter().map(|stashed| stashed.log).collect();
|
||||
}
|
||||
|
||||
@@ -83,7 +83,6 @@ use super::device::relay::{self, Relayed};
|
||||
use super::device::{lock, DeviceShared};
|
||||
use super::dirty_pages::DirtyCommit;
|
||||
use super::encoder::{Recorded, Segment};
|
||||
use super::encoder_fold::FoldOrder;
|
||||
use super::error::{
|
||||
internal, invalid, vulkan, CommandBufferError, DeadlockCause, EncoderCall, Error,
|
||||
FailedPipeline, FailedState, MemoryKind, MeshRecordsOverflow, PipelineCreationCause, Problem,
|
||||
@@ -112,7 +111,7 @@ use super::program_objects;
|
||||
use super::queue::{QueueGen, Slot};
|
||||
use super::rebind::{Holds, SubmittedHolds, Taken};
|
||||
use super::render::{Carried, EndInFlight, NoneKept};
|
||||
use super::replay::{CallLog, ComputeCall, Replay};
|
||||
use super::replay::Replay;
|
||||
use super::residency::Residency;
|
||||
use super::resource::{ObjectId, ResourceKey};
|
||||
use super::retained::Lately;
|
||||
@@ -871,20 +870,9 @@ pub(super) struct State {
|
||||
/// logs its members do not keep in (`encoder_fold::Fold`'s `stashed`), empty; `None` while a
|
||||
/// group holds it.
|
||||
stash_room: Option<Vec<crate::encoder_fold::Stashed>>,
|
||||
/// The order the next group of its encoders recorded into one `VkCommandBuffer` joins its
|
||||
/// encoders' uses to (`encoder_fold::Fold`'s `order`), empty, the room of the groups before
|
||||
/// kept (`FoldOrder::clear`); `None` while a group holds it.
|
||||
order_room: Option<FoldOrder<ResourceKey>>,
|
||||
/// Cleared logs of compute encoders (`replay.rs`), each with its room in bytes, that the
|
||||
/// release of a command buffer that held this state kept for the compute encoders of the one
|
||||
/// that takes it next, at most [`STATE_LOGS`](spare_states::STATE_LOGS): such an encoder
|
||||
/// takes its log here, under the lock its open takes, and from the device's spares only where
|
||||
/// none is left.
|
||||
compute_logs: Vec<(CallLog<ComputeCall>, usize)>,
|
||||
/// The room its lists of records (`ended`, `recorded`, `held_logs`, `stash_room`, its command
|
||||
/// predication's lists and its groups' order) held as the command buffer took the state
|
||||
/// (`spare_states.rs`): its release counts those that grew past it
|
||||
/// (`WorkCounts::record_lists_grown`).
|
||||
/// The room its lists of records (`ended`, `recorded`, `held_logs` and `stash_room`) held as
|
||||
/// the command buffer took the state (`spare_states.rs`): its release counts those that grew
|
||||
/// past it (`WorkCounts::record_lists_grown`).
|
||||
room: Room,
|
||||
/// What its last ended compute encoder parked for its next one, until the commit gives it back
|
||||
/// to the device (`compute/live.rs`'s `Parked`).
|
||||
@@ -1289,8 +1277,6 @@ impl State {
|
||||
unfolded: None,
|
||||
held_logs: Vec::new(),
|
||||
stash_room: Some(Vec::new()),
|
||||
order_room: Some(FoldOrder::none()),
|
||||
compute_logs: Vec::new(),
|
||||
room: Room::default(),
|
||||
parked_compute: None,
|
||||
left_out_from: None,
|
||||
@@ -1392,49 +1378,21 @@ impl State {
|
||||
}
|
||||
}
|
||||
|
||||
/// The room its lists of records hold, each list's in entries, and with its kept compute
|
||||
/// logs' in bytes (`spare_states.rs`).
|
||||
/// The room its lists of records hold, each list's in entries (`spare_states.rs`).
|
||||
fn lists_room(&self) -> Room {
|
||||
let order = (self.order_room.as_ref()).map_or([0; 3], FoldOrder::room);
|
||||
let logs = self.compute_logs.iter().map(|(_, room)| room).sum();
|
||||
Room::new(
|
||||
[
|
||||
self.ended.capacity(),
|
||||
self.recorded.capacity(),
|
||||
self.stash_room.as_ref().map_or(0, Vec::capacity),
|
||||
self.held_logs.capacity(),
|
||||
],
|
||||
self.predication.room(),
|
||||
order,
|
||||
logs,
|
||||
)
|
||||
}
|
||||
|
||||
/// A compute encoder's log, opening now: a cleared one this state kept
|
||||
/// ([`compute_logs`](Self::compute_logs)), where it keeps one.
|
||||
pub(super) fn kept_compute_log(&mut self) -> Option<CallLog<ComputeCall>> {
|
||||
self.compute_logs.pop().map(|(log, _)| log)
|
||||
}
|
||||
|
||||
/// Keep `logs`, cleared compute logs with their room in bytes, for the compute encoders of
|
||||
/// the command buffer that takes this state next, as many as it has room for
|
||||
/// ([`STATE_LOGS`](spare_states::STATE_LOGS)): those it does not keep come back.
|
||||
pub(super) fn keep_compute_logs(
|
||||
&mut self,
|
||||
mut logs: Vec<(CallLog<ComputeCall>, usize)>,
|
||||
) -> Vec<(CallLog<ComputeCall>, usize)> {
|
||||
let room = spare_states::STATE_LOGS.saturating_sub(self.compute_logs.len());
|
||||
let from = logs.len().saturating_sub(room);
|
||||
self.compute_logs.extend(logs.drain(from..));
|
||||
logs
|
||||
Room([
|
||||
self.ended.capacity(),
|
||||
self.recorded.capacity(),
|
||||
self.stash_room.as_ref().map_or(0, Vec::capacity),
|
||||
self.held_logs.capacity(),
|
||||
])
|
||||
}
|
||||
|
||||
/// The state reset in place, by its release, for a command buffer the device makes next
|
||||
/// (`spare_states.rs`): every part as [`State::new`] makes it, what it held going here, but
|
||||
/// its lists of records, emptied with their room kept (their entries going first, as they
|
||||
/// went before the rest), its command predication's lists and its groups' order, emptied in
|
||||
/// place with their room kept, the compute logs its release kept, and the revision its parts
|
||||
/// move. Its room is the room the next command buffer starts on.
|
||||
/// went before the rest), and the revision its parts move. Its room is the room the next
|
||||
/// command buffer starts on.
|
||||
fn reset(&mut self) {
|
||||
let State {
|
||||
status,
|
||||
@@ -1467,8 +1425,6 @@ impl State {
|
||||
unfolded,
|
||||
held_logs: _,
|
||||
stash_room: _,
|
||||
order_room: _,
|
||||
compute_logs: _,
|
||||
room: _,
|
||||
parked_compute,
|
||||
left_out_from,
|
||||
@@ -1561,7 +1517,7 @@ impl State {
|
||||
check,
|
||||
checks,
|
||||
storage_form,
|
||||
predication: _,
|
||||
predication,
|
||||
replaying_predication,
|
||||
predicated,
|
||||
trail_mark,
|
||||
@@ -1572,7 +1528,6 @@ impl State {
|
||||
self.recorded.clear();
|
||||
self.held_logs.clear();
|
||||
self.stash_room.get_or_insert_with(Vec::new).clear();
|
||||
(self.order_room.get_or_insert_with(FoldOrder::none)).clear();
|
||||
self.status = status;
|
||||
self.error = error;
|
||||
self.encoder_open = encoder_open;
|
||||
@@ -1690,7 +1645,7 @@ impl State {
|
||||
self.check = check;
|
||||
self.checks = checks;
|
||||
self.storage_form = storage_form;
|
||||
self.predication.reset();
|
||||
self.predication = predication;
|
||||
self.replaying_predication = replaying_predication;
|
||||
self.predicated = predicated;
|
||||
self.trail_mark = trail_mark;
|
||||
@@ -5545,8 +5500,15 @@ impl CommandBufferShared {
|
||||
/// as on a lost device, whose submissions fail at once, and for an unshared queue's. The
|
||||
/// budget is 2 ms while another command queue took a batch there within
|
||||
/// `unshared_hold::ACTIVE`, else 16 ms (counted where only that let it go).
|
||||
pub(crate) fn held_for_turn(&self) -> Option<(usize, u64, Option<u64>)> {
|
||||
if self.queue.unshared() || self.device.is_lost() {
|
||||
///
|
||||
/// Only its first batch (`index` 0) takes a turn: once that one went, each later batch goes as
|
||||
/// it is ready, as Metal schedules a command buffer whole. Held behind its own first batch,
|
||||
/// a command buffer whose first batch waits on the GPU for a signal still to come would not
|
||||
/// read `Scheduled` (its last batch's submission) until that signal came, nor could another
|
||||
/// queue's command buffer that waits for its later signal go meanwhile, where Metal schedules
|
||||
/// both at once (`queue_turns.rs`, "Whole command buffers").
|
||||
pub(crate) fn held_for_turn(&self, index: usize) -> Option<(usize, u64, Option<u64>)> {
|
||||
if index > 0 || self.queue.unshared() || self.device.is_lost() {
|
||||
return None;
|
||||
}
|
||||
let index = self.queue.vk_queue();
|
||||
@@ -7450,24 +7412,19 @@ impl CommandBufferShared {
|
||||
drop(resource);
|
||||
}
|
||||
// Its encoders' logs go here too, those they kept and those held for its commit
|
||||
// (`fold.rs`), cleared without the state's lock (`replay.rs`): they hold what their
|
||||
// calls named, which Metal holds until the command buffer completed (a binding
|
||||
// replaced before any command among it), and no thread but this one may hold such a
|
||||
// handle past the completion. Its state keeps the compute ones, as many as it keeps,
|
||||
// for the compute encoders of the command buffer that takes it next
|
||||
// (`spare_states.rs`); the rest go back to the device's spares.
|
||||
// (`fold.rs`), back to the device's spares (`replay.rs`): they hold what their calls
|
||||
// named, which Metal holds until the command buffer completed
|
||||
// (a binding replaced before any command among it), and no thread but this one may
|
||||
// hold such a handle past the completion.
|
||||
let logs: Vec<Arc<Replay>> = (lock(&self.state).ended.iter_mut())
|
||||
.filter_map(|record| record.replay.take())
|
||||
.collect();
|
||||
let held = lock(&self.state).unsplit_logs();
|
||||
let spares = self.device.shared().scheduler.spare_logs();
|
||||
let logs = logs.into_iter().filter_map(Arc::into_inner).chain(held);
|
||||
let compute = spares.cleared_compute(logs);
|
||||
let unkept = match compute.is_empty() {
|
||||
true => compute,
|
||||
false => lock(&self.state).keep_compute_logs(compute),
|
||||
};
|
||||
spares.give_compute(unkept);
|
||||
for log in logs {
|
||||
spares.give_last(log);
|
||||
}
|
||||
let held = lock(&self.state).unsplit_logs();
|
||||
spares.give_held(held);
|
||||
let residency = lock(&self.state).residency.take();
|
||||
drop(residency);
|
||||
let residencies = lock(&self.state).let_go_of_uses();
|
||||
|
||||
@@ -3,17 +3,11 @@
|
||||
//! ([`State::reset`]): what it held goes as it went before, at the release, and its lists of what
|
||||
//! its encoders ended with (its ended encoders' records, their recordings, the logs of a group of
|
||||
//! encoders recorded into one `VkCommandBuffer` its members did not keep, `encoder_fold.rs`'s
|
||||
//! `Fold`, and those held for its commit, `fold.rs`), its command predication's lists
|
||||
//! (`predication.rs`) and its groups' order (`FoldOrder`, its map and its resources' lists) are
|
||||
//! emptied with their room kept. A command buffer being made takes a kept state whole
|
||||
//! ([`SpareStates::take`]): its making neither allocates nor fills one, and its encoders' ends push
|
||||
//! into room the lists already had rather than grow them one reallocation at a time over fresh
|
||||
//! pages. Its release also keeps up to [`STATE_LOGS`] of its compute encoders' logs, cleared, in
|
||||
//! the state (`State::compute_logs`): the compute encoders of the command buffer that takes it
|
||||
//! take those, under the lock their open takes, rather than the device's spares' (`replay.rs`),
|
||||
//! whose lock the queues' handler threads take as they give logs back. A state goes on only to
|
||||
//! command buffers of the device generation that made it, and the kept ones go with that
|
||||
//! generation.
|
||||
//! `Fold`, and those held for its commit, `fold.rs`) are emptied with their room kept. A command
|
||||
//! buffer being made takes a kept state whole ([`SpareStates::take`]): its making neither
|
||||
//! allocates nor fills one, and its encoders' ends push into room the lists already had rather
|
||||
//! than grow them one reallocation at a time over fresh pages. A state goes on only to command
|
||||
//! buffers of the device generation that made it, and the kept ones go with that generation.
|
||||
|
||||
use std::sync::atomic::AtomicU64;
|
||||
use std::sync::{Arc, Mutex};
|
||||
@@ -21,9 +15,7 @@ use std::sync::{Arc, Mutex};
|
||||
use super::State;
|
||||
use crate::device::lock;
|
||||
use crate::encoder::Recorded;
|
||||
use crate::encoder_fold::{FoldOrder, Stashed};
|
||||
use crate::predication::Predication;
|
||||
use crate::resource::ResourceKey;
|
||||
use crate::encoder_fold::Stashed;
|
||||
use crate::used_resources::EncoderRecord;
|
||||
|
||||
/// The states a device keeps, at most: one per uncompleted command buffer of a queue of Metal's
|
||||
@@ -39,70 +31,24 @@ const STATE_ROOM_BYTES: usize = 8 << 20;
|
||||
/// The room the kept states' lists hold together, at most, in bytes.
|
||||
const SPARE_ROOM_BYTES: usize = 2 * STATE_ROOM_BYTES;
|
||||
|
||||
/// The cleared compute logs a state keeps, at most (`State::compute_logs`): each holds at most
|
||||
/// `SPARE_LOG_BYTES` (64 KiB, `replay.rs`), and their room counts toward the state's
|
||||
/// ([`STATE_ROOM_BYTES`]).
|
||||
pub(super) const STATE_LOGS: usize = 32;
|
||||
|
||||
/// The lists of records a state keeps the room of ([`Room`]).
|
||||
const LISTS: usize = 12;
|
||||
|
||||
/// The room of each of a state's lists of records, in entries (its ended encoders' records, their
|
||||
/// recordings, its stash of a group's logs, the logs it holds for its commit, its command
|
||||
/// predication's five lists, and its groups' order's map, boxes and priors), and the room they
|
||||
/// and the compute logs it keeps hold, in bytes.
|
||||
/// The room of each of a state's lists of records, in entries: its ended encoders' records, their
|
||||
/// recordings, its stash of a group's logs and the logs it holds for its commit.
|
||||
#[derive(Clone, Copy, Default)]
|
||||
pub(super) struct Room {
|
||||
lists: [usize; LISTS],
|
||||
bytes: usize,
|
||||
}
|
||||
pub(super) struct Room(pub(super) [usize; 4]);
|
||||
|
||||
impl Room {
|
||||
/// The room of a state's lists: of its lists of records `records` (its ended encoders'
|
||||
/// records, their recordings, its stash and the logs it holds for its commit), of its command
|
||||
/// predication's lists `predication` (`Predication::room`), of its groups' order `order`
|
||||
/// (`FoldOrder::room`), each in entries, and of the compute logs it keeps, `logs` bytes.
|
||||
pub(super) fn new(
|
||||
records: [usize; 4],
|
||||
predication: [usize; 5],
|
||||
order: [usize; 3],
|
||||
logs: usize,
|
||||
) -> Room {
|
||||
let [ended, recorded, stashed, held_logs] = records;
|
||||
let bytes = ended * std::mem::size_of::<EncoderRecord>()
|
||||
+ recorded * std::mem::size_of::<Recorded>()
|
||||
+ (stashed + held_logs) * std::mem::size_of::<Stashed>()
|
||||
+ Predication::room_bytes(predication)
|
||||
+ FoldOrder::<ResourceKey>::room_bytes(order)
|
||||
+ logs;
|
||||
let [runs, open_checks, opened, alone, opened_fresh] = predication;
|
||||
let [map, boxes, priors] = order;
|
||||
let lists = [
|
||||
ended,
|
||||
recorded,
|
||||
stashed,
|
||||
held_logs,
|
||||
runs,
|
||||
open_checks,
|
||||
opened,
|
||||
alone,
|
||||
opened_fresh,
|
||||
map,
|
||||
boxes,
|
||||
priors,
|
||||
];
|
||||
Room { lists, bytes }
|
||||
}
|
||||
|
||||
/// How many of the lists hold more room in `now` than in this: those that grew since.
|
||||
pub(super) fn grown(self, now: Room) -> u64 {
|
||||
let grown = (self.lists.iter().zip(now.lists)).filter(|&(&was, now)| now > was);
|
||||
let grown = (self.0.iter().zip(now.0)).filter(|&(&was, now)| now > was);
|
||||
grown.count() as u64
|
||||
}
|
||||
|
||||
/// The room, in bytes.
|
||||
pub(super) fn bytes(self) -> usize {
|
||||
self.bytes
|
||||
let [ended, recorded, stashed, held_logs] = self.0;
|
||||
ended * std::mem::size_of::<EncoderRecord>()
|
||||
+ recorded * std::mem::size_of::<Recorded>()
|
||||
+ (stashed + held_logs) * std::mem::size_of::<Stashed>()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +111,6 @@ use metal2vulkan::error::{BindError, RuntimeDriverDefect};
|
||||
use metal2vulkan::metal::{BarrierScope, DispatchType, RenderStages, ResourceUsage};
|
||||
use metal2vulkan::pipeline::Stage;
|
||||
use std::borrow::Cow;
|
||||
use std::cell::Cell;
|
||||
use std::collections::BTreeMap;
|
||||
use std::ops::Range;
|
||||
use std::sync::atomic::AtomicU64;
|
||||
@@ -295,13 +294,12 @@ impl CommandBuffer {
|
||||
let counts = &self.device().shared().counts;
|
||||
// Under the core's one lock of the state: it joins its command buffer's unit of command
|
||||
// predication, carrying on the loops open across its start, or starts the next; it starts
|
||||
// with the residency the ended encoders left (`State::inheriting`); it takes what the
|
||||
// command buffer's last compute encoder parked (`compute/live.rs`); and it takes a log its
|
||||
// state kept (`spare_states.rs`), where it kept one.
|
||||
// with the residency the ended encoders left (`State::inheriting`); and it takes what the
|
||||
// command buffer's last compute encoder parked (`compute/live.rs`).
|
||||
// The core is made in the box the command buffer's last compute encoder parked, beside its
|
||||
// bind state (`compute/live.rs`); else in a box of the device's spares, beside one of its
|
||||
// bind states (`EncoderCore::open_placed`).
|
||||
let (mut core, (live, carried, residency, predicated, log)) = EncoderCore::open_placed(
|
||||
let (mut core, (live, carried, residency, predicated)) = EncoderCore::open_placed(
|
||||
self,
|
||||
call,
|
||||
EncoderKind::Compute,
|
||||
@@ -309,11 +307,9 @@ impl CommandBuffer {
|
||||
|state| {
|
||||
let carried = state.enter_predication(dispatch_type);
|
||||
let residency = state.inheriting(false, counts);
|
||||
let parked = state.unpark_compute();
|
||||
let log = state.kept_compute_log();
|
||||
(carried, residency, state.predicated, parked, log)
|
||||
(carried, residency, state.predicated, state.unpark_compute())
|
||||
},
|
||||
|opened, (carried, residency, predicated, parked, log)| {
|
||||
|opened, (carried, residency, predicated, parked)| {
|
||||
let (core, live) = match parked {
|
||||
Some(parked) => {
|
||||
counts.parked_compute_taken();
|
||||
@@ -325,7 +321,7 @@ impl CommandBuffer {
|
||||
(opened.boxed(), live)
|
||||
}
|
||||
};
|
||||
(core, (live, carried, residency, predicated, log))
|
||||
(core, (live, carried, residency, predicated))
|
||||
},
|
||||
)?;
|
||||
// A record of command predication of its unit, or a dispatch it leaves to its host step,
|
||||
@@ -349,9 +345,7 @@ impl CommandBuffer {
|
||||
indirect_stage_in: None,
|
||||
residency,
|
||||
captures: Captures::carried(carried, predicated),
|
||||
log: Some(
|
||||
log.unwrap_or_else(|| self.device().shared().scheduler.spare_logs().compute()),
|
||||
),
|
||||
log: Some(self.device().shared().scheduler.spare_logs().compute()),
|
||||
dispatches: 0,
|
||||
live,
|
||||
heaps_noted: None,
|
||||
@@ -2634,86 +2628,48 @@ impl DispatchMemo {
|
||||
/// does not read changed only in values its commands do not read: a program that binds two
|
||||
/// textures of one shape in turn, an encoder for each dispatch, keeps them. Checked in builds
|
||||
/// with debug assertions, where each dispatch that takes them instantiates again and compares.
|
||||
/// - **Their storage, kept where the entry goes.** Commands no longer of the state stay as the
|
||||
/// storage the next direct dispatch's instantiation writes over
|
||||
/// (`BindingPlan::instantiate_dispatch_into`, `WorkCounts::dispatches_instantiated_in_place`)
|
||||
/// where nothing else holds them (the memo's entry they were taken into goes before: a dispatch
|
||||
/// that instantiates settled anew), so a program that binds a buffer at another offset at each
|
||||
/// dispatch, an encoder for each, makes its commands' lists once. Exact: the method sets every
|
||||
/// field as `instantiate_dispatch` does, which builds with debug assertions instantiate again
|
||||
/// to compare.
|
||||
#[derive(Default)]
|
||||
pub(super) struct Instantiated(Option<KeptCommands>);
|
||||
|
||||
/// An [`Instantiated`]'s entry: its commands, and what they are of, where they still are.
|
||||
/// An [`Instantiated`]'s entry.
|
||||
struct KeptCommands {
|
||||
/// `None` where a value they may read moved since: the commands are then storage alone.
|
||||
of: Option<CommandsOf>,
|
||||
commands: Arc<DispatchCommands>,
|
||||
}
|
||||
|
||||
/// What a [`KeptCommands`]' commands are of.
|
||||
struct CommandsOf {
|
||||
planned: Weak<Planned>,
|
||||
/// The dispatch they run: what it planned may be of another grid of its class
|
||||
/// (`Planned::grids`).
|
||||
dispatch: Dispatch,
|
||||
/// The kinds of the state's values the commands may read.
|
||||
reads: ValueKinds,
|
||||
}
|
||||
|
||||
impl CommandsOf {
|
||||
fn new(planned: &Arc<Planned>, dispatch: Dispatch) -> CommandsOf {
|
||||
CommandsOf {
|
||||
planned: Arc::downgrade(planned),
|
||||
dispatch,
|
||||
reads: ValueKinds::dispatch_reads(&planned.plan),
|
||||
}
|
||||
}
|
||||
commands: Arc<DispatchCommands>,
|
||||
}
|
||||
|
||||
impl Instantiated {
|
||||
/// The commands kept, where they are of `planned` and `dispatch`.
|
||||
fn of(&self, planned: &Arc<Planned>, dispatch: &Dispatch) -> Option<&Arc<DispatchCommands>> {
|
||||
let kept = self.0.as_ref()?;
|
||||
let of = kept.of.as_ref()?;
|
||||
let same = std::ptr::eq(of.planned.as_ptr(), Arc::as_ptr(planned));
|
||||
(same && of.dispatch == *dispatch).then_some(&kept.commands)
|
||||
let of = std::ptr::eq(kept.planned.as_ptr(), Arc::as_ptr(planned));
|
||||
(of && kept.dispatch == *dispatch).then_some(&kept.commands)
|
||||
}
|
||||
|
||||
/// The commands of a direct dispatch of `planned` and `dispatch`, kept in place of the
|
||||
/// entry's: `over` writes them over the kept commands' storage where nothing else holds it
|
||||
/// (with whether it did), else `fresh` makes them.
|
||||
fn instantiate(
|
||||
/// Keep `commands`, a direct dispatch's of `planned` and `dispatch`, in place of the entry.
|
||||
fn keep(
|
||||
&mut self,
|
||||
(planned, dispatch): (&Arc<Planned>, Dispatch),
|
||||
fresh: impl FnOnce() -> Result<DispatchCommands, Error>,
|
||||
over: impl FnOnce(&mut DispatchCommands) -> Result<(), Error>,
|
||||
) -> Result<(Arc<DispatchCommands>, bool), Error> {
|
||||
if let Some(kept) = &mut self.0 {
|
||||
if let Some(commands) = Arc::get_mut(&mut kept.commands) {
|
||||
// Of nothing while they are written, and after an error.
|
||||
kept.of = None;
|
||||
over(commands)?;
|
||||
kept.of = Some(CommandsOf::new(planned, dispatch));
|
||||
return Ok((Arc::clone(&kept.commands), true));
|
||||
}
|
||||
}
|
||||
let commands = Arc::new(fresh()?);
|
||||
planned: &Arc<Planned>,
|
||||
dispatch: Dispatch,
|
||||
commands: Arc<DispatchCommands>,
|
||||
) {
|
||||
self.0 = Some(KeptCommands {
|
||||
of: Some(CommandsOf::new(planned, dispatch)),
|
||||
commands: Arc::clone(&commands),
|
||||
planned: Arc::downgrade(planned),
|
||||
dispatch,
|
||||
reads: ValueKinds::dispatch_reads(&planned.plan),
|
||||
commands,
|
||||
});
|
||||
Ok((commands, false))
|
||||
}
|
||||
|
||||
/// The state's values of the kinds `moved` names changed: the commands are of nothing where
|
||||
/// they may read one, and are kept as storage alone.
|
||||
/// The state's values of the kinds `moved` names changed: the entry goes where its commands
|
||||
/// may read one.
|
||||
fn moved(&mut self, moved: ValueKinds) {
|
||||
if let Some(kept) = &mut self.0 {
|
||||
if (kept.of.as_ref()).is_some_and(|of| of.reads.meets(moved)) {
|
||||
kept.of = None;
|
||||
}
|
||||
if (self.0.as_ref()).is_some_and(|kept| kept.reads.meets(moved)) {
|
||||
self.0 = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2923,34 +2879,14 @@ fn record(
|
||||
Arc::clone(commands)
|
||||
}
|
||||
None => {
|
||||
// A direct dispatch's are kept, over the storage of those kept before where
|
||||
// nothing else holds it.
|
||||
let commands = match (kept_commands, direct) {
|
||||
(Some(memo), Some(_)) => {
|
||||
let over = |commands: &mut DispatchCommands| {
|
||||
(plan.instantiate_dispatch_into(state, &dispatch, commands))
|
||||
.map_err(Error::Bind)?;
|
||||
variant.keyed_regions(core.device(), commands);
|
||||
debug_assert!(
|
||||
instantiate().is_ok_and(|again| again == *commands),
|
||||
"a dispatch's commands written over kept ones that are not \
|
||||
those it instantiates"
|
||||
);
|
||||
Ok(())
|
||||
};
|
||||
let (commands, in_place) =
|
||||
memo.instantiate((planned, dispatch), instantiate, over)?;
|
||||
if in_place {
|
||||
counts.dispatch_instantiated_in_place();
|
||||
}
|
||||
commands
|
||||
}
|
||||
_ => Arc::new(instantiate()?),
|
||||
};
|
||||
let commands = Arc::new(instantiate()?);
|
||||
counts.dispatch_instantiated();
|
||||
if from_aside {
|
||||
counts.set_aside_commands_instantiated();
|
||||
}
|
||||
if let (Some(memo), Some(_)) = (kept_commands, direct) {
|
||||
memo.keep(planned, dispatch, Arc::clone(&commands));
|
||||
}
|
||||
commands
|
||||
}
|
||||
};
|
||||
@@ -3036,11 +2972,12 @@ fn record(
|
||||
// upload (16-aligned, as the variant reads it): the grid in threads is the call's, so nothing
|
||||
// on the device writes it.
|
||||
if let Some(bytes) = commands.region_record {
|
||||
let device = core.device().clone();
|
||||
let record = {
|
||||
let mut state = core.command_buffer().state();
|
||||
state
|
||||
.uploads
|
||||
.upload_aligned(core.device(), &bytes, bytes.len() as u64, 16)?
|
||||
.upload_aligned(&device, &bytes, bytes.len() as u64, 16)?
|
||||
};
|
||||
let Some(address) = record.device_address() else {
|
||||
return Err(internal(
|
||||
@@ -3128,8 +3065,7 @@ fn record(
|
||||
core.counts().dispatch_skipped_inert();
|
||||
return Ok(true);
|
||||
}
|
||||
// The device through the command buffer's handle, borrowed at each use (`core.device()`): no
|
||||
// handle of its own, whose count every encoding thread's handles share.
|
||||
let device = core.device().clone();
|
||||
// Inside a block of command predication, each command runs from its gate: the flat path's
|
||||
// preprocess (whose command then stays zero), else each region's dispatch. Their group
|
||||
// counts are listed only for a unit that gates them.
|
||||
@@ -3148,7 +3084,7 @@ fn record(
|
||||
.map(|region| region.group_count)
|
||||
.collect(),
|
||||
};
|
||||
predication.gates(uploads, core.device(), &counts)?
|
||||
predication.gates(uploads, &device, &counts)?
|
||||
}
|
||||
false => (None, Vec::new()),
|
||||
}
|
||||
@@ -3167,7 +3103,7 @@ fn record(
|
||||
let mut state = core.command_buffer().state();
|
||||
binding::bind(
|
||||
call,
|
||||
core.device(),
|
||||
&device,
|
||||
&mut state,
|
||||
plan,
|
||||
&command,
|
||||
@@ -3198,12 +3134,12 @@ fn record(
|
||||
let kept_made = kept
|
||||
.and_then(|kept| kept.made.get())
|
||||
.or_else(|| planned.made_for(commands))
|
||||
.filter(|_| !apart_samplers(core.device(), objects));
|
||||
.filter(|_| !apart_samplers(&device, objects));
|
||||
// Inside a predicated loop's laying, it waits for them too, so the laying, which its check
|
||||
// may submit again (`command_buffer/rerun.rs`), is not split for it; but where its variant
|
||||
// records in one of its own.
|
||||
let laying = core.command_buffer().state().predication_mut().laying();
|
||||
let waits = laying && !apart_samplers(core.device(), objects);
|
||||
let waits = laying && !apart_samplers(&device, objects);
|
||||
let (pipelines, pending) = match (own.filter(|_| !waits), kept_made) {
|
||||
(Some(_), Some(made)) => {
|
||||
if let Some(kept) = kept.filter(|kept| kept.made.get().is_none()) {
|
||||
@@ -3233,7 +3169,7 @@ fn record(
|
||||
pipeline.record_dispatch(direct, state);
|
||||
}
|
||||
match made {
|
||||
Some(made) if !apart_samplers(core.device(), objects) => {
|
||||
Some(made) if !apart_samplers(&device, objects) => {
|
||||
// Kept with the entry, which the next dispatch of its inputs takes, and with
|
||||
// what it planned, which the next dispatch of its shape takes.
|
||||
if let Some(kept) = kept {
|
||||
@@ -3250,7 +3186,7 @@ fn record(
|
||||
(Cow::Owned(made), None)
|
||||
}
|
||||
Some(_) => {
|
||||
core.device()
|
||||
device
|
||||
.shared()
|
||||
.counts
|
||||
.thread()
|
||||
@@ -3283,20 +3219,18 @@ fn record(
|
||||
};
|
||||
// The shadowed textures the dispatch binds, at the first draw or dispatch of each, its
|
||||
// shadow made now (`shadow_log.rs`).
|
||||
crate::shadow_log::dispatched(core.device(), variant.pipeline(), tables.table);
|
||||
crate::shadow_log::dispatched(&device, variant.pipeline(), tables.table);
|
||||
// The resident textures' shadows as the encoder keeps them (`compute/live.rs`).
|
||||
let textures = tables.table.textures.values();
|
||||
let shadows = match resident_shadows {
|
||||
Some(kept) => {
|
||||
shadow::shadow_uses_of(textures, kept.of(core.device(), tables.residency), uses)
|
||||
}
|
||||
Some(kept) => shadow::shadow_uses_of(textures, kept.of(&device, tables.residency), uses),
|
||||
None => shadow::shadow_uses(textures.chain(tables.residency.textures()), uses),
|
||||
};
|
||||
let copies = core.plan_shadows(&shadows, uses)?;
|
||||
let heap_set = match heap {
|
||||
Some(_) => Some(
|
||||
heap_sets::bind(
|
||||
core.device(),
|
||||
&device,
|
||||
objects,
|
||||
&mut core.command_buffer().state().heaps,
|
||||
heap_writes,
|
||||
@@ -3321,7 +3255,7 @@ fn record(
|
||||
// here, what its push carries (`binding::PushedSetZero`).
|
||||
let pushes = !pushed.is_empty();
|
||||
if pushes && pending.is_some() {
|
||||
(core.device().shared().counts.thread()).dispatch_pushing_set_zero(pushed.len() as u64);
|
||||
(device.shared().counts.thread()).dispatch_pushing_set_zero(pushed.len() as u64);
|
||||
}
|
||||
let recording = Recording {
|
||||
layout: objects.layout(),
|
||||
@@ -3335,7 +3269,7 @@ fn record(
|
||||
};
|
||||
let stages = vk::PipelineStageFlags2::COMPUTE_SHADER;
|
||||
let regions = &commands.regions;
|
||||
(core.device().shared().counts.thread()).dispatch_tracked(uses.len() as u64);
|
||||
(device.shared().counts.thread()).dispatch_tracked(uses.len() as u64);
|
||||
match pending {
|
||||
Some((dispatch, begun, next)) => {
|
||||
// Tracked here, as a command recorded here is; its execution recorded here, its
|
||||
@@ -3368,20 +3302,19 @@ fn record(
|
||||
}
|
||||
None => {
|
||||
let made = &*pipelines;
|
||||
let stale = core.device().shared().pushes_after_pipeline_binds;
|
||||
let shared = device.shared();
|
||||
let stale = shared.pushes_after_pipeline_binds;
|
||||
let resident = uses.resident();
|
||||
let carried = Cell::new(0);
|
||||
core.command_reaching_pushed(stages, uses, resident, |raw, command_buffer, held| {
|
||||
// SAFETY: the encoder's command buffer is recording outside a render pass;
|
||||
// every object recorded is live until the command buffer completes (retained
|
||||
// below), the pipelines are the variant's, one per region, and `held` is what
|
||||
// its compute bind point holds (`EncoderCore::command_reaching_pushed`).
|
||||
let pushed = unsafe { recording.record(raw, command_buffer, made, (held, stale)) };
|
||||
carried.set(carried.get() + pushed);
|
||||
let carried = unsafe { recording.record(raw, command_buffer, made, (held, stale)) };
|
||||
if pushes {
|
||||
(shared.counts.thread()).dispatch_pushing_set_zero(carried);
|
||||
}
|
||||
});
|
||||
if pushes {
|
||||
(core.device().shared().counts.thread()).dispatch_pushing_set_zero(carried.get());
|
||||
}
|
||||
core.shadows_used(&shadows, uses, &[]);
|
||||
core.executed(|| {
|
||||
Execution::new(
|
||||
@@ -3402,7 +3335,7 @@ fn record(
|
||||
.iter()
|
||||
.all(|earlier| earlier.specialization != region.specialization)
|
||||
{
|
||||
core.device().degrade_bound_values(
|
||||
device.degrade_bound_values(
|
||||
std::slice::from_ref(&variant.pipeline().stage),
|
||||
®ion.specialization,
|
||||
&|k| plan.specialized_value(k),
|
||||
@@ -3410,10 +3343,8 @@ fn record(
|
||||
);
|
||||
}
|
||||
}
|
||||
core.device()
|
||||
.degrade_cross_class(&plan.diagnostics, formats);
|
||||
core.device()
|
||||
.degrade_astc_storage(&plan.diagnostics, formats);
|
||||
device.degrade_cross_class(&plan.diagnostics, formats);
|
||||
device.degrade_astc_storage(&plan.diagnostics, formats);
|
||||
objects.announce_bound(
|
||||
(
|
||||
std::slice::from_ref(&variant.pipeline().stage),
|
||||
@@ -3444,20 +3375,20 @@ fn record(
|
||||
}
|
||||
let emulated = variant.emulates_simdgroups();
|
||||
let split = (regions.len(), variant.runs_partial_threadgroups());
|
||||
degrade_dispatch(core.device(), kernel, &dispatch, split, emulated);
|
||||
degrade_dispatch(&device, kernel, &dispatch, split, emulated);
|
||||
// A large kernel's whole grid on its partial-threadgroups variant ([`partial_direct`]).
|
||||
if variant.runs_partial_threadgroups() && whole_grid(&dispatch) {
|
||||
core.counts().whole_dispatch_on_partial_variant();
|
||||
}
|
||||
if let Some(unlisted) = unlisted {
|
||||
heap_sets::degrade_unlisted(
|
||||
core.device(),
|
||||
&device,
|
||||
unlisted,
|
||||
&format!("kernel `{kernel}`'s dispatches"),
|
||||
);
|
||||
// It runs with the states its sampler arrays hold.
|
||||
let mut held = core.command_buffer().state();
|
||||
held.unlisted_argument_sampler(core.device());
|
||||
held.unlisted_argument_sampler(&device);
|
||||
}
|
||||
Ok(true)
|
||||
}
|
||||
@@ -2754,12 +2754,6 @@ impl EncoderCore {
|
||||
shadows: &[ShadowUse],
|
||||
uses: &[Use<ResourceKey>],
|
||||
) -> Result<Vec<ShadowCopy>, Error> {
|
||||
// A command that uses no shadowed texture, of an encoder that used none yet, takes no
|
||||
// copy and changes nothing (`ShadowSync::is_empty`): every dispatch of a program that
|
||||
// shadows nothing, which then touches none of the device's shared state here.
|
||||
if shadows.is_empty() && self.shadows.is_empty() {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
// What a copy records beyond what the texture holds from its making: a converted
|
||||
// two-plane YCbCr texture's conversion, made at its first use of its image; a 4:2:2
|
||||
// texture's set over its buffer's `VkBuffer` now, held until the command buffer completes;
|
||||
@@ -2771,10 +2765,7 @@ impl EncoderCore {
|
||||
self.retain_shared(held);
|
||||
}
|
||||
}
|
||||
// The device through the command buffer's handle, borrowed apart from the shadows and
|
||||
// leases the merges take: no handle of its own, whose count every encoding thread's
|
||||
// handles share.
|
||||
let device = self.open.command_buffer.device();
|
||||
let device = self.device().clone();
|
||||
// The uses with their host memory's, where the shadows read them at all.
|
||||
let aliased = match self.shadows.reads_uses(shadows) {
|
||||
true => self.aliased(uses),
|
||||
@@ -2793,7 +2784,7 @@ impl EncoderCore {
|
||||
.shadows
|
||||
.before(shadows, uses, |copies, made_for, area| {
|
||||
let merging = (made_for.two_ways, made_for.blocks, area);
|
||||
let made = ShadowMerge::new(device, copies, merging, (images, pool), lent)?;
|
||||
let made = ShadowMerge::new(&device, copies, merging, (images, pool), lent)?;
|
||||
let (merge, lease) = (Arc::new(made.0), made.1);
|
||||
if let Some(lease) = lease {
|
||||
leases.push((Arc::downgrade(&merge), lease));
|
||||
@@ -2813,7 +2804,7 @@ impl EncoderCore {
|
||||
// How this command's first copies in stood against their images' last standing, which
|
||||
// sizes the carry on a run without a timing (`shadow::CarryTally`).
|
||||
let tally = self.shadows.tally();
|
||||
(self.device().shared().counts).shadow_first_copies_in_tallied(tally);
|
||||
(device.shared().counts).shadow_first_copies_in_tallied(tally);
|
||||
let by = match Location::caller().file() {
|
||||
file if file.ends_with("compute.rs") => KeepBy::Compute,
|
||||
file if file.ends_with("blit.rs") => KeepBy::Blit,
|
||||
@@ -2821,7 +2812,7 @@ impl EncoderCore {
|
||||
};
|
||||
for copy in &copies {
|
||||
if let Step::Keep(merge) = ©.step {
|
||||
let churn = &self.device().shared().counts.churn;
|
||||
let churn = &device.shared().counts.churn;
|
||||
churn.kept(by, merge.cuts(), merge.texels_kept());
|
||||
self.retain(Arc::clone(merge));
|
||||
}
|
||||
@@ -3037,10 +3028,6 @@ impl EncoderCore {
|
||||
/// the host copies the texels the commands left into its scratch, whose changed bytes the
|
||||
/// host step stores (`shadow_splice.rs`, [`drain_splices`](Self::drain_splices)).
|
||||
pub(super) fn shadow_copies(&mut self, copies: &[ShadowCopy]) {
|
||||
// No copy records nothing, barriers nothing and splices nothing.
|
||||
if copies.is_empty() {
|
||||
return;
|
||||
}
|
||||
let device = self.device().clone();
|
||||
let mut run = ShadowRun::default();
|
||||
// The keeps a dispatch at their copy in took, which record nothing, and those that copy
|
||||
|
||||
@@ -232,11 +232,10 @@
|
||||
//! - **Logs.** A group's members' logs are held from the group's close for the commit, which
|
||||
//! keeps them for every member where one member keeps its own for a rebind, and keeps those of
|
||||
//! a group its failure splits; the rest stay held until the command buffer's release, which
|
||||
//! clears them on its queue's handler thread, as it clears the logs its encoders kept, and keeps
|
||||
//! up to 32 in the command buffer's state for the compute encoders of the one that takes it
|
||||
//! next (`command_buffer/spare_states.rs`), giving the rest back to the device's spares under
|
||||
//! one lock (`SpareLogs::give_compute`). The spares keep as many as it gave back within 1 MiB
|
||||
//! of room, so a next command buffer's encoders reuse them rather than allocate. A log holds one
|
||||
//! gives them back to the device's spares under one lock on its queue's handler thread
|
||||
//! (`SpareLogs::give_held`), as it gives back the logs its encoders kept. The spares keep as
|
||||
//! many as it gave back within 1 MiB of room, so a next command buffer's encoders reuse them
|
||||
//! rather than allocate. A log holds one
|
||||
//! `ComputeCall` per call (at most 64 bytes, `tests::encoder_fold`) besides the bytes and handles
|
||||
//! its slices take in its arenas: a one-dispatch encoder's five calls (state, three buffers, the
|
||||
//! dispatch) hold about 320 bytes, so 2,300 such encoders hold about 0.7 MiB until their command buffer completes.
|
||||
@@ -287,9 +286,6 @@ impl Prior {
|
||||
/// that updated a fence (**Fences** in the module docs).
|
||||
pub(crate) struct FoldOrder<K> {
|
||||
priors: KeyMap<K, Vec<Prior>>,
|
||||
/// The lists of priors of its resources a [`clear`](Self::clear) emptied, their room kept for
|
||||
/// the resources a next group's encoders use.
|
||||
boxes: Vec<Vec<Prior>>,
|
||||
/// The writes the group's fence updates cover, in the stages the updating encoders' commands
|
||||
/// ran in that each update covers: every later command of the group orders after them, to
|
||||
/// what it may reach of memory no use names. Empty where no member updated a fence.
|
||||
@@ -303,41 +299,16 @@ impl<K: Copy + Eq + Hash> FoldOrder<K> {
|
||||
pub(crate) fn none() -> FoldOrder<K> {
|
||||
FoldOrder {
|
||||
priors: KeyMap::default(),
|
||||
boxes: Vec::new(),
|
||||
fenced: Access::NONE,
|
||||
fenced_visible: Access::NONE,
|
||||
}
|
||||
}
|
||||
|
||||
/// Empty it, the order after nothing again, for a next group (`command_buffer/fold.rs`): its
|
||||
/// map's room kept, and each resource's list of priors emptied into its boxes, their room
|
||||
/// kept.
|
||||
pub(crate) fn clear(&mut self) {
|
||||
for (_, mut priors) in self.priors.drain() {
|
||||
priors.clear();
|
||||
self.boxes.push(priors);
|
||||
}
|
||||
self.fenced = Access::NONE;
|
||||
self.fenced_visible = Access::NONE;
|
||||
}
|
||||
|
||||
/// The room it holds, in entries: its map's, its boxes', and the priors' its lists of priors
|
||||
/// hold together.
|
||||
pub(crate) fn room(&self) -> [usize; 3] {
|
||||
let lists = self.priors.values().chain(&self.boxes);
|
||||
[
|
||||
self.priors.capacity(),
|
||||
self.boxes.capacity(),
|
||||
lists.map(Vec::capacity).sum(),
|
||||
]
|
||||
}
|
||||
|
||||
/// [`room`](Self::room) in bytes.
|
||||
pub(crate) fn room_bytes(room: [usize; 3]) -> usize {
|
||||
let [map, boxes, priors] = room;
|
||||
map * std::mem::size_of::<(K, Vec<Prior>)>()
|
||||
+ boxes * std::mem::size_of::<Vec<Prior>>()
|
||||
+ priors * std::mem::size_of::<Prior>()
|
||||
/// The order after the encoder whose summary is `summary`.
|
||||
pub(crate) fn after(summary: &Summary<K>) -> FoldOrder<K> {
|
||||
let mut order = FoldOrder::none();
|
||||
order.join(summary);
|
||||
order
|
||||
}
|
||||
|
||||
/// Note the next encoder of the group ended, with `summary`: its uses come after everything
|
||||
@@ -351,9 +322,7 @@ impl<K: Copy + Eq + Hash> FoldOrder<K> {
|
||||
self.fenced_visible = Access::NONE;
|
||||
}
|
||||
for used in summary.uses() {
|
||||
let boxes = &mut self.boxes;
|
||||
let priors =
|
||||
(self.priors.entry(used.key)).or_insert_with(|| boxes.pop().unwrap_or_default());
|
||||
let priors = self.priors.entry(used.key).or_default();
|
||||
if !used.write.is_empty() {
|
||||
priors.retain(|prior| !used.range.contains(&prior.range));
|
||||
}
|
||||
@@ -726,10 +695,8 @@ pub(crate) struct Fold {
|
||||
/// joins its first part's (`Fold::overwrites_join`).
|
||||
pub(crate) blits_alone: bool,
|
||||
/// What its encoders did, which the next one's commands order after: empty until a second
|
||||
/// encoder joins, which joins its first part's summary to it (`State::join_fold`), so a
|
||||
/// group no encoder joins costs no copy of what its first encoder used. It holds the room
|
||||
/// the command buffer's group before left it (`FoldOrder::clear`), which its close gives
|
||||
/// back.
|
||||
/// encoder joins, which builds it from its first part's summary (`State::join_fold`), so a
|
||||
/// group no encoder joins costs no copy of what its first encoder used.
|
||||
pub(crate) order: FoldOrder<ResourceKey>,
|
||||
/// Its members' logs not kept by themselves.
|
||||
pub(crate) stashed: Vec<Stashed>,
|
||||
@@ -752,12 +719,12 @@ impl Fold {
|
||||
}
|
||||
|
||||
/// The group `joining`'s encoder begins, its first part `leader`, its first `VkCommandBuffer`
|
||||
/// the tail; its order, `order` (empty), is joined as a second encoder joins.
|
||||
/// the tail; its order is built as a second encoder joins.
|
||||
pub(crate) fn begun(
|
||||
tail: vk::CommandBuffer,
|
||||
(leader, encoder): (usize, usize),
|
||||
(batches, joining): (usize, Joining),
|
||||
(stashed, order, open): (Vec<Stashed>, FoldOrder<ResourceKey>, Option<OpenPass>),
|
||||
(stashed, open): (Vec<Stashed>, Option<OpenPass>),
|
||||
) -> Fold {
|
||||
Fold {
|
||||
tail,
|
||||
@@ -766,7 +733,7 @@ impl Fold {
|
||||
batches,
|
||||
dispatch_type: joining.dispatch_type(None),
|
||||
blits_alone: joining == Joining::Blit,
|
||||
order,
|
||||
order: FoldOrder::none(),
|
||||
stashed,
|
||||
open,
|
||||
}
|
||||
|
||||
@@ -107,9 +107,8 @@ pub(super) use render::RenderVariant;
|
||||
pub(super) use render::WeakRenderPipelineState;
|
||||
/// The general and residual forms of a key (`render/residual.rs`), for `tests::general_form`.
|
||||
#[cfg(test)]
|
||||
pub(super) use render::{general_form, residual_form_of, residual_ids};
|
||||
pub(super) use render::{reads_views_at_bind, residual_form};
|
||||
pub(super) use render::{residual_in_place, uniform_residual_ids};
|
||||
pub(super) use render::{general_form, residual_form_of};
|
||||
pub(super) use render::{reads_views_at_bind, residual_form, uniform_residual_form};
|
||||
pub(super) use render::{GraphicsState, Kind as RenderStateKind, StateShared as RenderShared};
|
||||
pub(super) use render::{ProgramName, Settled};
|
||||
pub(super) use tile::TileState;
|
||||
@@ -775,10 +774,6 @@ pub(super) struct Variant {
|
||||
objects: Arc<VariantObjects>,
|
||||
plans: Mutex<Lru<BindShape, Arc<BindingPlan>>>,
|
||||
pipelines: making::Making<RegionKey, RawPipeline>,
|
||||
/// The IDs of the stage's constants that a key of a device reading its uniform views at their
|
||||
/// residuals takes at 0 (`uniform_residual_ids`): what [`keyed_regions`](Self::keyed_regions)
|
||||
/// zeroes.
|
||||
uniform_residuals: Box<[u32]>,
|
||||
}
|
||||
|
||||
/// What a region's `VkPipeline` is made from.
|
||||
@@ -2301,15 +2296,12 @@ impl Variant {
|
||||
memo,
|
||||
}) as Box<dyn making::KeyWatch<RegionKey, RawPipeline>>
|
||||
};
|
||||
let constants = pipeline.stage.specialization.constants.iter();
|
||||
let uniform_residuals = uniform_residual_ids(constants, &pipeline.interface).into();
|
||||
let variant = Arc::new(Variant {
|
||||
key,
|
||||
pipeline,
|
||||
objects: Arc::new(objects),
|
||||
plans: Mutex::new(Lru::counted(PLANS)),
|
||||
pipelines: making::Making::watched(bound, watch),
|
||||
uniform_residuals,
|
||||
});
|
||||
for (place, made) in kept {
|
||||
if let kept::Place::Region(region) = place {
|
||||
@@ -2343,15 +2335,20 @@ impl Variant {
|
||||
/// `commands`' regions, each specialization with its uniform views at their residuals where
|
||||
/// `device` reads no uniform view at its bind offset alone (`render/residual.rs`,
|
||||
/// `uniform_residual_form`): what every region of a dispatch or a tile dispatch of the variant
|
||||
/// takes before its key is looked up. A storage view's key keeps its value. Written in each
|
||||
/// key's own bytes, over the constants the variant listed as it was made
|
||||
/// (`residual_in_place`), so keying a region makes no key.
|
||||
/// takes before its key is looked up. A storage view's key keeps its value.
|
||||
pub(crate) fn keyed_regions(&self, device: &Device, commands: &mut DispatchCommands) {
|
||||
if self.uniform_residuals.is_empty() || reads_views_at_bind(device) {
|
||||
if reads_views_at_bind(device) {
|
||||
return;
|
||||
}
|
||||
let constants = &self.pipeline.stage.specialization.constants;
|
||||
let interface = &self.pipeline.interface;
|
||||
for region in &mut commands.regions {
|
||||
residual_in_place(&mut region.specialization, &self.uniform_residuals);
|
||||
let specialization = ®ion.specialization;
|
||||
if let Some(residual) =
|
||||
uniform_residual_form(constants.iter(), interface, specialization)
|
||||
{
|
||||
region.specialization = residual;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -97,9 +97,8 @@ pub(crate) use residual::views_read_at_bind;
|
||||
/// The general and residual forms of a key, which `tests::general_form` reads from IDs and
|
||||
/// meanings alone.
|
||||
#[cfg(test)]
|
||||
pub(crate) use residual::{general_form, residual_form_of, residual_ids};
|
||||
pub(crate) use residual::{reads_views_at_bind, residual_form};
|
||||
pub(crate) use residual::{residual_in_place, uniform_residual_ids};
|
||||
pub(crate) use residual::{general_form, residual_form_of};
|
||||
pub(crate) use residual::{reads_views_at_bind, residual_form, uniform_residual_form};
|
||||
|
||||
/// A Metal render pipeline state (`MTLRenderPipelineState`): one that draws, or a tile pipeline's
|
||||
/// ([`Device::new_tile_render_pipeline_state`]), which dispatches per tile. Cheap to clone (a
|
||||
|
||||
@@ -242,48 +242,6 @@ pub(crate) fn uniform_residual_form<'a>(
|
||||
residual_form_of(constants, uniform, specialization)
|
||||
}
|
||||
|
||||
/// The IDs of `constants`' `SpecKey::RangeAtBindOffset` constants whose slot `interface` reads
|
||||
/// through a uniform view: those [`uniform_residual_form`] zeroes, listed once for a pipeline so
|
||||
/// each of its keys takes that form in place ([`residual_in_place`]).
|
||||
pub(crate) fn uniform_residual_ids<'a>(
|
||||
constants: impl Iterator<Item = &'a SpecConstant>,
|
||||
interface: &PipelineInterface,
|
||||
) -> Vec<u32> {
|
||||
let uniform = |slot| {
|
||||
matches!(interface.slots.get(&slot),
|
||||
Some(SlotInterface::Buffer(b)) if b.form.uniform_view())
|
||||
};
|
||||
residual_ids(
|
||||
constants.map(|constant| (constant.id, constant.key)),
|
||||
uniform,
|
||||
)
|
||||
}
|
||||
|
||||
/// The IDs of `constants`' (each its ID and its meaning) `SpecKey::RangeAtBindOffset` constants
|
||||
/// whose slot `views` holds: those [`residual_form_of`] zeroes.
|
||||
pub(crate) fn residual_ids(
|
||||
constants: impl Iterator<Item = (u32, SpecKey)>,
|
||||
views: impl Fn(SlotRef) -> bool,
|
||||
) -> Vec<u32> {
|
||||
constants
|
||||
.filter(|&(_, key)| matches!(key, SpecKey::RangeAtBindOffset(slot) if views(slot)))
|
||||
.map(|(id, _)| id)
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// `specialization` with the value of each constant `ids` names at 0, written in its own bytes:
|
||||
/// [`residual_form_of`]'s key where `ids` are [`residual_ids`]' of the same constants and views,
|
||||
/// and `specialization` as it was where that answers `None`, with no key made.
|
||||
pub(crate) fn residual_in_place(specialization: &mut SpecializationKey, ids: &[u32]) {
|
||||
let SpecializationKey { data, entries, .. } = specialization;
|
||||
for entry in entries.iter().filter(|e| ids.contains(&e.constant_id)) {
|
||||
let at = entry.offset as usize;
|
||||
if let Some(bytes) = data.get_mut(at..at + entry.size as usize) {
|
||||
bytes.fill(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `specialization` with each `SpecKey::RangeAtBindOffset` constant of `constants` (a pipeline's
|
||||
/// stages', each its ID and its meaning) whose slot `views` holds at 0; `None` where every one of
|
||||
/// them is 0 there already. A constant `specialization` gives no entry takes the module's
|
||||
|
||||
@@ -207,12 +207,6 @@ pub(super) struct Predication {
|
||||
/// ([`alone`](Self::alone)): a rebind may encode one again
|
||||
/// ([`replaying`](Self::replaying)).
|
||||
alone: Vec<usize>,
|
||||
/// The places among the command buffer's ended encoders of the current unit's compute
|
||||
/// encoders that opened with no step of it laid ([`Unit::fresh`]), in order: its first
|
||||
/// encoder's, and each later one's until one laid a step, so a prefix of its encoders
|
||||
/// ([`alone`](Predication::alone)). Emptied as the unit ends, its room kept for the next
|
||||
/// unit's.
|
||||
opened_fresh: Vec<usize>,
|
||||
}
|
||||
|
||||
/// What a compute encoder found as it opened: its place among the command buffer's ended
|
||||
@@ -486,6 +480,11 @@ struct Unit {
|
||||
looped: bool,
|
||||
/// An unbalanced record left out what its encoders recorded before it.
|
||||
left: bool,
|
||||
/// The places among the command buffer's ended encoders of its compute encoders that opened
|
||||
/// with no step of its laid ([`Unit::fresh`]), in order: its first encoder's, and each
|
||||
/// later one's until one laid a step, so a prefix of its encoders
|
||||
/// ([`alone`](Predication::alone)).
|
||||
opened_fresh: Vec<usize>,
|
||||
}
|
||||
|
||||
/// The range of a unit an unbalanced record drops (the module docs): from the anchor to the next
|
||||
@@ -572,6 +571,7 @@ impl Unit {
|
||||
carried: Vec::new(),
|
||||
looped: false,
|
||||
left: false,
|
||||
opened_fresh: vec![place],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -660,85 +660,24 @@ impl Predication {
|
||||
dispatch_type,
|
||||
records: self.records,
|
||||
});
|
||||
let joins = |unit: &mut Unit| {
|
||||
!unit.closing
|
||||
if let Some(unit) = &mut self.unit {
|
||||
if !unit.closing
|
||||
&& unit.place + 1 == place
|
||||
&& unit.events == events
|
||||
&& unit.dispatch_type == dispatch_type
|
||||
};
|
||||
if let Some(unit) = self.unit.take_if(joins) {
|
||||
if unit.fresh() {
|
||||
self.opened_fresh.push(place);
|
||||
{
|
||||
if unit.fresh() {
|
||||
unit.opened_fresh.push(place);
|
||||
}
|
||||
unit.place = place;
|
||||
return std::mem::take(&mut unit.carried);
|
||||
}
|
||||
// The encoder takes the bodies its unit carried; the unit goes on with it, carrying
|
||||
// none until it ends.
|
||||
let carried = unit.carried;
|
||||
self.unit = Some(Unit {
|
||||
place,
|
||||
carried: Vec::new(),
|
||||
..unit
|
||||
});
|
||||
return carried;
|
||||
}
|
||||
self.end_unit();
|
||||
self.opened_fresh.push(place);
|
||||
self.unit = Some(Unit::new(place, events, dispatch_type));
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
/// Reset in place for the command buffer that takes its state next (`spare_states.rs`):
|
||||
/// every part as [`Predication::default`] makes it, what it held going here, its lists
|
||||
/// emptied with their room kept.
|
||||
pub(super) fn reset(&mut self) {
|
||||
let Predication {
|
||||
unit,
|
||||
runs,
|
||||
open_checks,
|
||||
records,
|
||||
loops,
|
||||
laying,
|
||||
laid,
|
||||
waited,
|
||||
left_out,
|
||||
opened,
|
||||
alone,
|
||||
opened_fresh,
|
||||
} = self;
|
||||
*unit = None;
|
||||
runs.clear();
|
||||
open_checks.clear();
|
||||
*records = 0;
|
||||
*loops = 0;
|
||||
*laying = None;
|
||||
*laid = 0;
|
||||
*waited = 0;
|
||||
*left_out = None;
|
||||
opened.clear();
|
||||
alone.clear();
|
||||
opened_fresh.clear();
|
||||
}
|
||||
|
||||
/// The room of its lists, each in entries: its runs, its open units' check words, its
|
||||
/// opened encoders, those that encode again alone and the current unit's fresh ones.
|
||||
pub(super) fn room(&self) -> [usize; 5] {
|
||||
[
|
||||
self.runs.capacity(),
|
||||
self.open_checks.capacity(),
|
||||
self.opened.capacity(),
|
||||
self.alone.capacity(),
|
||||
self.opened_fresh.capacity(),
|
||||
]
|
||||
}
|
||||
|
||||
/// [`room`](Self::room) in bytes.
|
||||
pub(super) fn room_bytes(room: [usize; 5]) -> usize {
|
||||
let [runs, open_checks, opened, alone, opened_fresh] = room;
|
||||
runs * std::mem::size_of::<Run>()
|
||||
+ open_checks * std::mem::size_of::<(Upload, u32)>()
|
||||
+ opened * std::mem::size_of::<Opened>()
|
||||
+ (alone + opened_fresh) * std::mem::size_of::<usize>()
|
||||
}
|
||||
|
||||
/// The open compute encoder updated a fence: its unit ends with it.
|
||||
pub(super) fn fence_updated(&mut self) {
|
||||
if let Some(unit) = &mut self.unit {
|
||||
@@ -763,14 +702,13 @@ impl Predication {
|
||||
// Where the unit laid a step, the last of `opened_fresh` is the encoder that
|
||||
// laid its first: that one gates the commands of the unit's later encoders, so
|
||||
// it encodes again alone only where the unit ended with it.
|
||||
let first_step_at = self.opened_fresh.len().saturating_sub(1);
|
||||
for (at, &place) in self.opened_fresh.iter().enumerate() {
|
||||
let first_step_at = unit.opened_fresh.len().saturating_sub(1);
|
||||
for (at, &place) in unit.opened_fresh.iter().enumerate() {
|
||||
if !stepped || at < first_step_at || place == unit.place {
|
||||
self.alone.push(place);
|
||||
}
|
||||
}
|
||||
}
|
||||
self.opened_fresh.clear();
|
||||
if let (true, Some(check), Some(outermost)) =
|
||||
(unit.live_open(), unit.check, unit.stack.first())
|
||||
{
|
||||
@@ -826,7 +764,6 @@ impl Predication {
|
||||
Some(Predication {
|
||||
unit: Some(Unit::new(place, opened.events, opened.dispatch_type)),
|
||||
records: opened.records,
|
||||
opened_fresh: vec![place],
|
||||
..Predication::default()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -36,8 +36,19 @@
|
||||
//! - **Turns.** A held batch keeps its place in the scheduler's order (`scheduler/order.rs`), as
|
||||
//! one held for an unshared queue does: a later commit of another queue whose footprint runs in
|
||||
//! commit order with it waits behind it, and one that shares nothing with it goes ahead of it.
|
||||
//! It waits for its own queue's work already submitted alone, never for a later commit, so the
|
||||
//! turns add no wait that can close a cycle.
|
||||
//! It waits for its own queue's work already submitted alone, never for a later commit.
|
||||
//! - **Whole command buffers.** Only a command buffer's first batch takes a turn
|
||||
//! (`CommandBufferShared::held_for_turn`): once it went, each later batch of it (a command
|
||||
//! buffer splits at an event wait after its work, or at a signal before more:
|
||||
//! `command_buffer/batches.rs`) goes as it is ready, as Metal schedules a command buffer whole.
|
||||
//! Held for the turn behind its own first batch, the rest would wait for that batch's
|
||||
//! completion: a command buffer whose first batch waits on the GPU for a signal not yet given
|
||||
//! (another `VkQueue`'s, or the caller's, `Event::reserve_vk_signal`) would read `Scheduled` only
|
||||
//! once that signal came, and another queue's command buffer that waits for one of its later
|
||||
//! signals would be held meanwhile (its wait goes to the `VkQueue` once the signal is
|
||||
//! submitted), where Metal schedules both at once (`runtime_lane::submission_checks`: a program
|
||||
//! that gives the signal once the other command buffer is scheduled waited for the watchdog,
|
||||
//! `command_buffer/stall.rs`).
|
||||
//! - **When it goes.** A pass that holds such a batch leaves the scheduler's thread waiting for
|
||||
//! the completion that lets it go, or that makes the batch of its queue whose run does so the
|
||||
//! oldest on its `VkQueue` (`unshared_hold::turn_through`), not for each completion before it;
|
||||
|
||||
@@ -519,23 +519,17 @@ pub(super) const SPARE_LOG_BYTES: usize = 64 * 1024;
|
||||
const SPARE_ROOM_BYTES: usize = SPARE_LOGS * SPARE_LOG_BYTES;
|
||||
|
||||
/// Cleared logs the device keeps for its next encoders (the module docs): of each kind,
|
||||
/// [`SPARE_LOGS`], or for compute encoders as many as the last command buffer's release gave
|
||||
/// back ([`give_compute`](Self::give_compute)) where that is more; each with at most
|
||||
/// [`SPARE_LOG_BYTES`] of room, all of a kind together with at most [`SPARE_ROOM_BYTES`]
|
||||
/// (1 MiB), and no call or handle. An encoder that logs takes one, or a new log where none is
|
||||
/// kept; its log comes back as its encoder ends where its command buffer does not keep it, and
|
||||
/// else in the command buffer's release, on its queue's handler thread, which keeps a compute
|
||||
/// encoder's in the command buffer's state first, for the compute encoders of the command buffer
|
||||
/// that takes the state next (`command_buffer/spare_states.rs`): those take theirs there, and
|
||||
/// here only where it kept none.
|
||||
/// [`SPARE_LOGS`], or for compute encoders as many as the last command buffer that held logs
|
||||
/// for its commit gave back ([`give_held`](Self::give_held)) where that is more; each with at most [`SPARE_LOG_BYTES`] of
|
||||
/// room, all of a kind together with at most [`SPARE_ROOM_BYTES`] (1 MiB), and no call or handle.
|
||||
/// An encoder that logs takes one, or a new log where none is kept; its log comes back as its
|
||||
/// encoder ends where its command buffer does not keep it, and else in the command buffer's
|
||||
/// release, on its queue's handler thread.
|
||||
#[derive(Default)]
|
||||
pub(crate) struct SpareLogs {
|
||||
compute: Spares<CallLog<ComputeCall>>,
|
||||
blit: Spares<CallLog<BlitCall>>,
|
||||
render: Spares<RenderRoom>,
|
||||
/// The compute logs taken here: a device test's (`tests::spare_states`).
|
||||
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
|
||||
compute_taken: std::sync::atomic::AtomicU64,
|
||||
}
|
||||
|
||||
/// One kind's [`SpareLogs`].
|
||||
@@ -606,48 +600,25 @@ impl<T> Spares<T> {
|
||||
impl SpareLogs {
|
||||
/// A compute encoder's log: a kept one, or a new one.
|
||||
pub(super) fn compute(&self) -> CallLog<ComputeCall> {
|
||||
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
|
||||
self.compute_taken
|
||||
.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
|
||||
self.compute.take().unwrap_or_else(CallLog::new)
|
||||
}
|
||||
|
||||
/// The compute logs taken here so far ([`compute`](Self::compute)): a device test's
|
||||
/// (`tests::spare_states`).
|
||||
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
|
||||
pub(crate) fn compute_taken(&self) -> u64 {
|
||||
self.compute_taken
|
||||
.load(std::sync::atomic::Ordering::Relaxed)
|
||||
}
|
||||
|
||||
/// Clear `logs`, those a command buffer's release lets go of (those its encoders kept and
|
||||
/// those it held for its commit for its groups of encoders and no split took,
|
||||
/// `command_buffer/fold.rs`): their calls and handles go now. The compute ones come back
|
||||
/// cleared, with their room in bytes, for the command buffer's state to keep
|
||||
/// (`State::keep_compute_logs`) and [`give_compute`](Self::give_compute) the rest; the others
|
||||
/// are kept here ([`give`](Self::give)).
|
||||
pub(super) fn cleared_compute(
|
||||
&self,
|
||||
logs: impl Iterator<Item = Replay>,
|
||||
) -> Vec<(CallLog<ComputeCall>, usize)> {
|
||||
let mut compute = Vec::new();
|
||||
for replay in logs {
|
||||
/// Clear `held`, the logs a command buffer held for its commit for its groups of compute
|
||||
/// encoders and no split took (`command_buffer/fold.rs`), in its release, and keep them for
|
||||
/// next encoders under one lock: as many as they are, within [`SPARE_ROOM_BYTES`], so a next
|
||||
/// command buffer's encoders as many reuse their room rather than allocate. Their calls and
|
||||
/// handles go now.
|
||||
pub(super) fn give_held(&self, held: Vec<Replay>) {
|
||||
if held.is_empty() {
|
||||
return;
|
||||
}
|
||||
let mut compute = Vec::with_capacity(held.len());
|
||||
for replay in held {
|
||||
match replay {
|
||||
Replay::Compute { log, .. } => compute.extend(log.cleared()),
|
||||
other => self.give(other),
|
||||
}
|
||||
}
|
||||
compute
|
||||
}
|
||||
|
||||
/// Keep `compute`, cleared compute logs of a command buffer's release its state did not keep
|
||||
/// ([`cleared_compute`](Self::cleared_compute)), for next encoders under one lock: as many as
|
||||
/// they are, within [`SPARE_ROOM_BYTES`], so a next command buffer's encoders as many reuse
|
||||
/// their room rather than allocate.
|
||||
pub(super) fn give_compute(&self, compute: Vec<(CallLog<ComputeCall>, usize)>) {
|
||||
if compute.is_empty() {
|
||||
return;
|
||||
}
|
||||
self.compute.give_all(compute);
|
||||
}
|
||||
|
||||
@@ -688,6 +659,13 @@ impl SpareLogs {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// [`give`](Self::give) `replay` where this is its last hold; else the hold goes.
|
||||
pub(super) fn give_last(&self, replay: Arc<Replay>) {
|
||||
if let Some(replay) = Arc::into_inner(replay) {
|
||||
self.give(replay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Append `items` to `arena`: their span.
|
||||
|
||||
@@ -2040,7 +2040,7 @@ fn submit_ready(
|
||||
// Held back from a `VkQueue` it shares with other command queues, while its own
|
||||
// queue's work enough is in flight there (`queue_turns.rs`): another queue's later
|
||||
// commit goes ahead of it.
|
||||
if let Some(room) = held.buffer.held_for_turn() {
|
||||
if let Some(room) = held.buffer.held_for_turn(held.index) {
|
||||
held.held_for(HeldFor::QueueTurn);
|
||||
await_room(held, room, awaits, &mut room_wake);
|
||||
isolating = true;
|
||||
@@ -2972,7 +2972,7 @@ fn plain(
|
||||
if unshared {
|
||||
return Err(LeftAtCommit::Unshared);
|
||||
}
|
||||
if held.buffer.held_for_turn().is_some() {
|
||||
if held.buffer.held_for_turn(held.index).is_some() {
|
||||
return Err(LeftAtCommit::Turn);
|
||||
}
|
||||
// A batch whose `VkQueue`'s calls are slow is the scheduler thread's to submit, which the
|
||||
|
||||
@@ -11,14 +11,6 @@ use metal2vulkan::device::DriverFact;
|
||||
use std::collections::BTreeSet;
|
||||
use std::ops::Range;
|
||||
|
||||
/// The order of a group after the encoder whose summary is `summary`, as a second encoder's join
|
||||
/// builds it (`State::join_fold`).
|
||||
fn order_after(summary: &Summary<ResourceKey>) -> FoldOrder<ResourceKey> {
|
||||
let mut order = FoldOrder::none();
|
||||
order.join(summary);
|
||||
order
|
||||
}
|
||||
|
||||
fn copy_read() -> Access {
|
||||
Access::new(
|
||||
vk::PipelineStageFlags2::COPY,
|
||||
@@ -111,7 +103,7 @@ fn a_joining_encoder_meets_what_the_group_wrote() {
|
||||
Use::reads(fill, true, UseRange::Bytes(0..16384), copy_read()),
|
||||
bytes_written(heap, 0..16384),
|
||||
]);
|
||||
let order = order_after(&first);
|
||||
let order = FoldOrder::after(&first);
|
||||
let written: Vec<_> = order.byte_writes().collect();
|
||||
assert_eq!(written, [(heap, 0..16384)]);
|
||||
let joined = AliasWrites::joining(Some(&order));
|
||||
@@ -132,7 +124,7 @@ fn a_joining_encoder_meets_what_the_group_wrote() {
|
||||
fn a_draw_noted_apart_over_written_bytes_splits_the_next_command() {
|
||||
let heap = ResourceKey::new();
|
||||
let first = Summary::outside_encoders(vec![bytes_written(heap, 0..16384)]);
|
||||
let order = order_after(&first);
|
||||
let order = FoldOrder::after(&first);
|
||||
let mut writes = AliasWrites::joining(Some(&order));
|
||||
let buffer_read = Use::reads(heap, true, UseRange::Bytes(0..16384), copy_read());
|
||||
writes.noted_apart(&[image_read(heap, 16384..32768), buffer_read]);
|
||||
@@ -195,7 +187,7 @@ fn a_write_after_a_draw_noted_apart_over_its_image_splits_the_next_command() {
|
||||
#[test]
|
||||
fn a_pass_continues_where_no_memory_it_uses_meets_the_group_s_writes() {
|
||||
let heap = ResourceKey::new();
|
||||
let order = order_after(&Summary::outside_encoders(vec![bytes_written(
|
||||
let order = FoldOrder::after(&Summary::outside_encoders(vec![bytes_written(
|
||||
heap,
|
||||
0..16384,
|
||||
)]));
|
||||
@@ -224,7 +216,7 @@ fn a_pass_continues_where_no_memory_it_uses_meets_the_group_s_writes() {
|
||||
);
|
||||
let bytes_read = Use::reads(heap, true, UseRange::Bytes(8192..8256), copy_read());
|
||||
assert!(!AliasWrites::default().continues(&order, &[bytes_read]));
|
||||
let quiet = order_after(&Summary::outside_encoders(Vec::new()));
|
||||
let quiet = FoldOrder::after(&Summary::outside_encoders(Vec::new()));
|
||||
assert!(drawn_over.continues(&quiet, &[image_read(heap, 0..64)]));
|
||||
}
|
||||
|
||||
|
||||
@@ -8,17 +8,15 @@
|
||||
//! each dispatch, as a guest compute benchmark's workloads bind them: the second dispatch on takes the
|
||||
//! commands (`WorkCounts::dispatches_instantiated_as_before`), and each samples its own texture.
|
||||
//! - **A buffer's binding**: the output bound at another offset instantiates again
|
||||
//! (`dispatches_instantiated`) and writes there; five encoders of one command buffer, each
|
||||
//! binding it at the next offset, instantiate each dispatch but the first over the storage of
|
||||
//! the commands the one before kept (`dispatches_instantiated_in_place`).
|
||||
//! (`dispatches_instantiated`) and writes there.
|
||||
//! - **A field**: a buffer made resident (`use_resource`), which the state lists among its used
|
||||
//! resources, instantiates again.
|
||||
//! - **Texture bindings a plan reads**: texture buffers over one buffer at two offsets, read
|
||||
//! through a texel-buffer view whose range the commands state, instantiate again at each change,
|
||||
//! and each dispatch reads its own texels.
|
||||
//!
|
||||
//! Every dispatch is the only one of its compute encoder, in a command buffer of its own (but the
|
||||
//! five encoders'), waited for before the next.
|
||||
//! Every dispatch is the only one of its compute encoder, in a command buffer of its own, waited
|
||||
//! for before the next.
|
||||
//!
|
||||
//! A device test: compiled only under the validation crate's GPU safety cfgs (`m2v_gpu`,
|
||||
//! `m2v_cpu_icd`), on the kind of device the cfg selects. The kernels are owned fixtures under
|
||||
@@ -56,15 +54,6 @@ fn counts(device: &Device) -> [u64; 2] {
|
||||
]
|
||||
}
|
||||
|
||||
/// The dispatches whose commands were instantiated, and those instantiated over kept commands.
|
||||
fn in_place(device: &Device) -> [u64; 2] {
|
||||
let counts = device.work_counts();
|
||||
[
|
||||
counts.dispatches_instantiated,
|
||||
counts.dispatches_instantiated_in_place,
|
||||
]
|
||||
}
|
||||
|
||||
/// A `Shared` buffer of `words`.
|
||||
fn words(device: &Device, words: &[u32]) -> Buffer {
|
||||
let bytes: Vec<u8> = words.iter().flat_map(|w| w.to_le_bytes()).collect();
|
||||
@@ -223,44 +212,6 @@ fn a_buffer_bound_at_another_offset_instantiates_again() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Five encoders of one command buffer, each one dispatch binding the output at the next offset:
|
||||
/// each instantiates, and each but the first over the commands the one before kept, which the
|
||||
/// memo's entry of that dispatch no longer holds; each writes at its own offset.
|
||||
#[test]
|
||||
fn encoders_of_moving_offsets_instantiate_over_the_kept_commands() {
|
||||
let scratch = Scratch::new("instantiated-in-place");
|
||||
let device = device(&scratch.0);
|
||||
let sampler = Sampler::new(&device);
|
||||
let texture = texels(&device, [0.0, 1.0]);
|
||||
let out = device.new_buffer(1280, ResourceOptions::shared()).unwrap();
|
||||
let queue = device.new_command_queue().unwrap();
|
||||
let before = in_place(&device);
|
||||
let command_buffer = queue.command_buffer().unwrap();
|
||||
let offsets = [0, 256, 512, 768, 1024];
|
||||
for offset in offsets {
|
||||
let mut encoder = command_buffer.compute_command_encoder().unwrap();
|
||||
encoder.set_compute_pipeline_state(&sampler.state).unwrap();
|
||||
encoder.set_texture(Some(&texture), 0).unwrap();
|
||||
encoder
|
||||
.set_sampler_state(Some(&sampler.nearest), 0)
|
||||
.unwrap();
|
||||
encoder.set_buffer(Some(&out), offset, 0).unwrap();
|
||||
encoder.set_buffer(Some(&sampler.coords), 0, 1).unwrap();
|
||||
let one = Size::new(1, 1, 1);
|
||||
encoder.dispatch_threads(one, one).unwrap();
|
||||
encoder.end_encoding().unwrap();
|
||||
}
|
||||
let after = in_place(&device);
|
||||
command_buffer.commit().unwrap();
|
||||
command_buffer.wait_until_completed_for(WAIT).unwrap();
|
||||
assert_eq!(command_buffer.status(), CommandBufferStatus::Completed);
|
||||
let moved = [0, 1].map(|at| after[at] - before[at]);
|
||||
assert_eq!(moved, [5, 4], "instantiated, of them over kept commands");
|
||||
for offset in offsets {
|
||||
assert_eq!(red(&out, offset), 1.0, "texel 1 at {offset}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A buffer made resident, which the state lists among its used resources, instantiates again;
|
||||
/// the same buffer made resident again keeps the commands.
|
||||
#[test]
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
//! A compute encoder of one dispatch, as a guest's encoders are, summarizes its hazards from the
|
||||
//! dispatch's own uses (`tracker.rs`, `EncoderUses`'s `lone`): its part builds no map of them, so
|
||||
//! a command buffer of such encoders notes no command in one (`tracker::part_notes`), and one of
|
||||
//! encoders of two dispatches notes both of each.
|
||||
//!
|
||||
//! Device tests: compiled only under the validation crate's GPU safety cfgs (`m2v_gpu`,
|
||||
//! `m2v_cpu_icd`), on the kind of device the cfg selects, with `compute_parked.rs`'s kernel.
|
||||
|
||||
use super::blit_holds::Scratch;
|
||||
use super::compute_parked::{written, Kernel, WORDS};
|
||||
use super::encoder_holds::words_of;
|
||||
use crate::tracker::part_notes;
|
||||
|
||||
/// The compute encoders of a command buffer, a guest's.
|
||||
const ENCODERS: u64 = 5;
|
||||
|
||||
/// A command buffer of [`ENCODERS`] compute encoders of one dispatch each, each writing its own
|
||||
/// words: no dispatch notes its uses in a part's map, and every word is what it wrote.
|
||||
#[test]
|
||||
fn encoders_of_one_dispatch_note_no_part_map() {
|
||||
let scratch = Scratch::new("lone-parts");
|
||||
let kernel = Kernel::new(&scratch);
|
||||
kernel.warm();
|
||||
let queue = kernel.device.new_command_queue().unwrap();
|
||||
let output = kernel.output(ENCODERS);
|
||||
let command_buffer = queue.command_buffer().unwrap();
|
||||
let before = part_notes();
|
||||
for k in 0..ENCODERS {
|
||||
kernel.dispatch(&command_buffer, (&output, k * WORDS * 4));
|
||||
}
|
||||
let noted = part_notes() - before;
|
||||
kernel.run(&command_buffer);
|
||||
assert_eq!(words_of(&output), written(ENCODERS), "the words");
|
||||
assert_eq!(
|
||||
noted, 0,
|
||||
"commands noted in a part's map, {ENCODERS} encoders"
|
||||
);
|
||||
}
|
||||
|
||||
/// The same command buffer with each encoder dispatching twice over its words: each encoder's
|
||||
/// part notes both its dispatches in its map, the first as the second comes.
|
||||
#[test]
|
||||
fn encoders_of_two_dispatches_note_both() {
|
||||
let scratch = Scratch::new("lone-parts-two");
|
||||
let kernel = Kernel::new(&scratch);
|
||||
kernel.warm();
|
||||
let queue = kernel.device.new_command_queue().unwrap();
|
||||
let output = kernel.output(ENCODERS);
|
||||
let command_buffer = queue.command_buffer().unwrap();
|
||||
let before = part_notes();
|
||||
for k in 0..ENCODERS {
|
||||
kernel.dispatches(&command_buffer, (&output, k * WORDS * 4), 2);
|
||||
}
|
||||
let noted = part_notes() - before;
|
||||
kernel.run(&command_buffer);
|
||||
assert_eq!(words_of(&output), written(ENCODERS), "the words");
|
||||
assert_eq!(noted, 2 * ENCODERS, "commands noted in a part's map");
|
||||
}
|
||||
@@ -22,7 +22,7 @@ use crate::{
|
||||
use metal2vulkan::bind::SamplerDescriptor;
|
||||
|
||||
/// The words a dispatch writes, one threadgroup's.
|
||||
pub(super) const WORDS: u64 = 64;
|
||||
const WORDS: u64 = 64;
|
||||
|
||||
/// The compute encoders of a command buffer.
|
||||
const ENCODERS: u64 = 8;
|
||||
@@ -65,27 +65,19 @@ impl Kernel {
|
||||
|
||||
/// A compute encoder of `command_buffer` of one dispatch that writes `output` from byte
|
||||
/// `offset` on, ended.
|
||||
pub(super) fn dispatch(&self, command_buffer: &CommandBuffer, output: (&Buffer, u64)) {
|
||||
self.dispatches(command_buffer, output, 1);
|
||||
}
|
||||
|
||||
/// [`dispatch`](Self::dispatch) with `count` dispatches of the same words in the encoder.
|
||||
pub(super) fn dispatches(
|
||||
pub(super) fn dispatch(
|
||||
&self,
|
||||
command_buffer: &CommandBuffer,
|
||||
(output, offset): (&Buffer, u64),
|
||||
count: u32,
|
||||
) {
|
||||
let mut encoder = command_buffer.compute_command_encoder().unwrap();
|
||||
encoder.set_compute_pipeline_state(&self.state).unwrap();
|
||||
encoder.set_buffer(Some(&self.input), 0, 0).unwrap();
|
||||
encoder.set_buffer(Some(output), offset, 1).unwrap();
|
||||
encoder.set_buffer(Some(&self.scale), 0, 2).unwrap();
|
||||
for _ in 0..count {
|
||||
encoder
|
||||
.dispatch_threads(Size::new(WORDS, 1, 1), Size::new(WORDS, 1, 1))
|
||||
.unwrap();
|
||||
}
|
||||
encoder
|
||||
.dispatch_threads(Size::new(WORDS, 1, 1), Size::new(WORDS, 1, 1))
|
||||
.unwrap();
|
||||
encoder.end_encoding().unwrap();
|
||||
}
|
||||
|
||||
@@ -139,7 +131,7 @@ impl Moved {
|
||||
}
|
||||
|
||||
/// The words `2 * i` of `count` dispatches, as floats' bits.
|
||||
pub(super) fn written(count: u64) -> Vec<u32> {
|
||||
fn written(count: u64) -> Vec<u32> {
|
||||
(0..count)
|
||||
.flat_map(|_| (0..WORDS).map(|i| (2.0 * i as f32).to_bits()))
|
||||
.collect()
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//! plan takes where the device reads its uniform views at their residuals: those views' constants
|
||||
//! alone at 0.
|
||||
|
||||
use crate::pipeline::{general_form, residual_form_of, residual_ids, residual_in_place};
|
||||
use crate::pipeline::{general_form, residual_form_of};
|
||||
use metal2vulkan::cache::SpecializationKey;
|
||||
use metal2vulkan::pipeline::{SlotClass, SlotRef, SpecKey, Stage};
|
||||
use metal2vulkan::vk::SpecializationMapEntry;
|
||||
@@ -115,40 +115,3 @@ fn a_plans_key_zeroes_its_uniform_views_and_keeps_its_storage_views() {
|
||||
let kept = key([0, 1, 1, 1, 3]);
|
||||
assert_eq!(residual_form_of(constants(), uniform_views, &kept), None);
|
||||
}
|
||||
|
||||
/// A dispatch's regions take that key in their own bytes (`Variant::keyed_regions`): zeroing the
|
||||
/// constants `residual_ids` lists in place gives `residual_form_of`'s key, or the key as it was
|
||||
/// where that answers `None`, in the storage the key held, for the uniform views alone and for
|
||||
/// every view.
|
||||
#[test]
|
||||
fn a_key_takes_its_residual_form_in_its_own_bytes() {
|
||||
let uniform = slot(SlotClass::Buffer, 0);
|
||||
let texture = slot(SlotClass::Texture, 0);
|
||||
let constants = || {
|
||||
vec![
|
||||
(0, SpecKey::RangeAtBindOffset(uniform)),
|
||||
(1, SpecKey::RangeAtBindOffset(slot(SlotClass::Buffer, 1))),
|
||||
(2, SpecKey::UnmeasuredTexels(texture)),
|
||||
(3, SpecKey::PlainHalfTexels(texture)),
|
||||
(4, SpecKey::BicubicTexels(texture)),
|
||||
]
|
||||
.into_iter()
|
||||
};
|
||||
let uniform_views = |at: SlotRef| at == uniform;
|
||||
let every_view = |_: SlotRef| true;
|
||||
let views: [&dyn Fn(SlotRef) -> bool; 2] = [&uniform_views, &every_view];
|
||||
assert_eq!(residual_ids(constants(), uniform_views), vec![0]);
|
||||
assert_eq!(residual_ids(constants(), every_view), vec![0, 1]);
|
||||
for (n, views) in views.into_iter().enumerate() {
|
||||
for values in [[1, 1, 1, 1, 3], [0, 1, 1, 1, 3], [0, 0, 0, 0, 0]] {
|
||||
let was = key(values);
|
||||
let made = residual_form_of(constants(), views, &was).unwrap_or_else(|| was.clone());
|
||||
let mut in_place = was.clone();
|
||||
let storage = (in_place.data.as_ptr(), in_place.entries.as_ptr());
|
||||
residual_in_place(&mut in_place, &residual_ids(constants(), views));
|
||||
assert_eq!(in_place, made, "views {n}, {values:?}");
|
||||
let kept = (in_place.data.as_ptr(), in_place.entries.as_ptr());
|
||||
assert_eq!(kept, storage, "views {n}, {values:?}: the key's storage");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,8 +100,6 @@ mod compute_create_scaling_bench;
|
||||
#[cfg(any(m2v_gpu, m2v_cpu_icd))]
|
||||
mod compute_instantiated;
|
||||
#[cfg(any(m2v_gpu, m2v_cpu_icd))]
|
||||
mod compute_lone_parts;
|
||||
#[cfg(any(m2v_gpu, m2v_cpu_icd))]
|
||||
mod compute_parked;
|
||||
#[cfg(any(m2v_gpu, m2v_cpu_icd))]
|
||||
mod compute_sampler_listing;
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
//! A command buffer takes the state a released command buffer of its device left, reset by that
|
||||
//! one's release, its lists of records emptied with their room kept
|
||||
//! (`command_buffer/spare_states.rs`): one of no more encoders than that one grows none of its
|
||||
//! lists (`WorkCounts::record_lists_grown`), its command predication's and its groups' order's
|
||||
//! among them, and its compute encoders take the logs the state kept, none the device's spares';
|
||||
//! one made after another's release builds no state (`WorkCounts::command_buffer_states_made`);
|
||||
//! the state carries nothing of the command buffer before; and the device keeps at most 64
|
||||
//! states, none whose lists hold past 8 MiB.
|
||||
//! lists (`WorkCounts::record_lists_grown`); one made after another's release builds no state
|
||||
//! (`WorkCounts::command_buffer_states_made`); the state carries nothing of the command buffer
|
||||
//! before; and the device keeps at most 64 states, none whose lists hold past 8 MiB.
|
||||
//!
|
||||
//! Device tests: compiled only under the validation crate's GPU safety cfgs (`m2v_gpu`,
|
||||
//! `m2v_cpu_icd`), on the kind of device the cfg selects. The kernel is `compute_parked.rs`'s.
|
||||
@@ -65,64 +63,6 @@ fn a_command_buffer_of_as_many_encoders_as_the_last_grows_no_list() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A command buffer of `encoders` compute encoders of `queue`, one dispatch each, committed,
|
||||
/// completed and dropped: read once its device kept its state, at its release, how many of its
|
||||
/// lists grew, how many of its encoders joined a group (`WorkCounts::encoders_folded`) and how
|
||||
/// many compute logs its encoders took from the device's spares (`SpareLogs::compute`).
|
||||
fn reused(kernel: &Kernel, queue: &CommandQueue, output: &Buffer, encoders: u64) -> [u64; 3] {
|
||||
let before = kernel.device.work_counts();
|
||||
let spares = kernel.device.shared().scheduler.spare_logs();
|
||||
let taken = spares.compute_taken();
|
||||
let command_buffer = queue.command_buffer().unwrap();
|
||||
for _ in 0..encoders {
|
||||
kernel.dispatch(&command_buffer, (output, 0));
|
||||
}
|
||||
let taken = spares.compute_taken() - taken;
|
||||
kernel.run(&command_buffer);
|
||||
drop(command_buffer);
|
||||
until("the command buffer's release kept its state", || {
|
||||
kernel.device.work_counts().record_storage_kept > before.record_storage_kept
|
||||
});
|
||||
let after = kernel.device.work_counts();
|
||||
[
|
||||
after.record_lists_grown - before.record_lists_grown,
|
||||
after.encoders_folded - before.encoders_folded,
|
||||
taken,
|
||||
]
|
||||
}
|
||||
|
||||
/// Command buffers of five compute encoders each, one after another's release, as a guest's
|
||||
/// frame of a few one-dispatch encoders: past the first, each starts on the state the one before
|
||||
/// left and grows none of its lists, its command predication's (each compute encoder enters a
|
||||
/// unit) and its group's order's (its last four encoders join its first's group) among them, and
|
||||
/// its compute encoders take the logs that state kept, none the device's spares'.
|
||||
#[test]
|
||||
fn a_reused_command_buffer_of_five_compute_encoders_grows_no_list_and_takes_no_spare_log() {
|
||||
let scratch = Scratch::new("spare-states-five");
|
||||
let kernel = Kernel::new(&scratch);
|
||||
kernel.warm();
|
||||
until(
|
||||
"the warming command buffer's release kept its state",
|
||||
|| kernel.device.work_counts().record_storage_kept > 0,
|
||||
);
|
||||
let queue = kernel.device.new_command_queue().unwrap();
|
||||
let output = kernel.output(1);
|
||||
let [_, folded, _] = reused(&kernel, &queue, &output, 5);
|
||||
assert_eq!(
|
||||
folded, 4,
|
||||
"the first command buffer's encoders that joined a group"
|
||||
);
|
||||
for round in 1..4 {
|
||||
let [grown, folded, taken] = reused(&kernel, &queue, &output, 5);
|
||||
assert_eq!(folded, 4, "round {round}: the encoders that joined a group");
|
||||
assert_eq!(grown, 0, "round {round}: the lists grown");
|
||||
assert_eq!(
|
||||
taken, 0,
|
||||
"round {round}: the logs taken from the device's spares"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The longest a command buffer is waited for.
|
||||
const WAIT: Duration = Duration::from_secs(30);
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
use crate::binding::ResidentPrefix;
|
||||
use crate::encoder_fold::{joined, FoldOrder};
|
||||
use crate::tracker::{
|
||||
join_looked_at, merge, ordered, part_notes, Access, Barrier, EncoderUses, Footprint,
|
||||
GeometryWrites, ImagePlace, IndirectReads, LegacyBarrier, Owed, Point, Reach, Summary, Tracker,
|
||||
join_looked_at, merge, ordered, Access, Barrier, EncoderUses, Footprint, GeometryWrites,
|
||||
ImagePlace, IndirectReads, LegacyBarrier, Owed, Point, Reach, Summary, Tracker,
|
||||
UnorderedWrites, Use, UseRange, Wait, ENTRIES_PER_KEY, OWED,
|
||||
};
|
||||
use ash::vk;
|
||||
@@ -60,14 +60,6 @@ fn barrier(src: Access, dst: Access) -> Option<Barrier> {
|
||||
Some(Barrier { src, dst })
|
||||
}
|
||||
|
||||
/// The order of a group after the encoder whose summary is `summary`, as a second encoder's join
|
||||
/// builds it (`State::join_fold`).
|
||||
fn order_after(summary: &Summary<Key>) -> FoldOrder<Key> {
|
||||
let mut order = FoldOrder::none();
|
||||
order.join(summary);
|
||||
order
|
||||
}
|
||||
|
||||
/// An ordered encoder with one command per entry of `commands`.
|
||||
fn encoder(commands: &[&[Use<Key>]]) -> Summary<Key> {
|
||||
let mut uses = EncoderUses::new(true);
|
||||
@@ -1666,7 +1658,7 @@ fn a_folded_encoder_s_first_dispatch_takes_a_serial_encoder_s_barrier() {
|
||||
// (`encoder_fold.rs`): its own order needs nothing, the group's order the same barrier.
|
||||
let mut first = EncoderUses::<Key>::new(true);
|
||||
first.order(COMPUTE, &bump(), Reach::Unnamed);
|
||||
let order = order_after(&first.finish());
|
||||
let order = FoldOrder::after(&first.finish());
|
||||
let mut second = EncoderUses::<Key>::new(true);
|
||||
let own = second.order(COMPUTE, &bump(), Reach::Unnamed);
|
||||
assert_eq!(own, None);
|
||||
@@ -1678,43 +1670,6 @@ fn a_folded_encoder_s_first_dispatch_takes_a_serial_encoder_s_barrier() {
|
||||
);
|
||||
}
|
||||
|
||||
/// A group's order cleared for the command buffer's next group (`FoldOrder::clear`, the room
|
||||
/// the groups of a command buffer and of the ones that take its state pass on): it answers as
|
||||
/// one built fresh, nothing of the group before left (its writes and its fenced writes), and the
|
||||
/// same uses again take no more room than the clear kept.
|
||||
#[test]
|
||||
fn a_cleared_fold_order_answers_as_a_fresh_one_in_the_room_it_kept() {
|
||||
let written = [
|
||||
Use::writes(5, true, bytes(0..64), shader_write()),
|
||||
Use::writes(6, true, bytes(0..256), shader_write()),
|
||||
];
|
||||
let read = [Use::reads(5, true, bytes(0..64), shader_read())];
|
||||
let group = |fence: bool| {
|
||||
let mut first = EncoderUses::<Key>::new(true);
|
||||
first.order(COMPUTE, &written, Reach::Unnamed);
|
||||
if fence {
|
||||
first.update_fence(100, None);
|
||||
}
|
||||
first.finish()
|
||||
};
|
||||
let mut order = order_after(&group(true));
|
||||
assert!(order.barrier(&read).is_some(), "the group's write");
|
||||
assert!(order.fence_barrier(COMPUTE, &read).is_some(), "the fence");
|
||||
order.clear();
|
||||
let room = order.room();
|
||||
assert_eq!(order.barrier(&read), None, "the write of the group before");
|
||||
assert_eq!(order.fence_barrier(COMPUTE, &read), None, "its fence");
|
||||
order.join(&group(false));
|
||||
let fresh = order_after(&group(false));
|
||||
assert!(fresh.barrier(&read).is_some());
|
||||
assert_eq!(order.barrier(&read), fresh.barrier(&read));
|
||||
assert_eq!(
|
||||
order.fence_barrier(COMPUTE, &read),
|
||||
fresh.fence_barrier(COMPUTE, &read)
|
||||
);
|
||||
assert_eq!(order.room(), room, "the room it kept");
|
||||
}
|
||||
|
||||
/// A group's encoder after one that wrote an untracked buffer and updated a fence
|
||||
/// (`encoder_fold.rs`'s **Fences**): its first dispatch orders after the fenced writes by the
|
||||
/// least barrier between dispatches; a later dispatch that reaches no more records none; one that
|
||||
@@ -1729,7 +1684,7 @@ fn a_folded_encoder_after_a_fence_update_takes_the_least_barrier_widened_only_by
|
||||
if let Some(fence) = fence {
|
||||
first.update_fence(fence, None);
|
||||
}
|
||||
order_after(&first.finish())
|
||||
FoldOrder::after(&first.finish())
|
||||
};
|
||||
let unfenced = writer(None);
|
||||
let mut order = writer(Some(100));
|
||||
@@ -3087,113 +3042,3 @@ fn runs_of_9_and_20_uses_join_exactly_and_one_with_an_empty_range_does_not() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A command of one key at two ranges, one of them twice (a write, then a read), another key,
|
||||
/// an untracked use and a use that touches nothing: what a part of it alone keeps.
|
||||
fn lone_command() -> [Use<Key>; 6] {
|
||||
[
|
||||
writes(3, bytes(0..64), shader_write()),
|
||||
reads(1, bytes(64..128), shader_read()),
|
||||
reads(3, bytes(128..256), shader_read()),
|
||||
reads(3, bytes(0..64), shader_read()),
|
||||
Use::reads(2, false, bytes(0..64), shader_read()),
|
||||
reads(4, bytes(0..64), Access::NONE),
|
||||
]
|
||||
}
|
||||
|
||||
/// An encoder, ordered or not, of the one command `command`, and the commands it noted in a
|
||||
/// part's map.
|
||||
fn encoder_of_one(ordered: bool, command: &[Use<Key>]) -> (EncoderUses<Key>, u64) {
|
||||
let before = part_notes();
|
||||
let mut uses = EncoderUses::new(ordered);
|
||||
uses.order(COMPUTE, command, Reach::Unnamed);
|
||||
(uses, part_notes() - before)
|
||||
}
|
||||
|
||||
/// A part of one command of an ordered encoder, which waits uncompared, is summarized from the
|
||||
/// uses it recorded and notes nothing in its map: its summary is the one an unordered encoder's
|
||||
/// map makes of the same command (each key's ranges in the order recorded, the uses of one range
|
||||
/// joined, the untracked use and the one that touches nothing left out). A second command notes
|
||||
/// both in the map.
|
||||
#[test]
|
||||
fn a_part_of_one_command_is_summarized_as_its_map_would_be() {
|
||||
let command = lone_command();
|
||||
let (lone, lone_notes) = encoder_of_one(true, &command);
|
||||
let (mapped, mapped_notes) = encoder_of_one(false, &command);
|
||||
assert_eq!(
|
||||
(lone_notes, mapped_notes),
|
||||
(0, 1),
|
||||
"the commands noted in a map"
|
||||
);
|
||||
let (lone, mapped) = (lone.finish_parts(), mapped.finish_parts());
|
||||
assert!(lone == mapped, "the summaries: {lone:?} and {mapped:?}");
|
||||
let want = [
|
||||
reads(1, bytes(64..128), shader_read()),
|
||||
Use {
|
||||
read: shader_read(),
|
||||
..writes(3, bytes(0..64), shader_write())
|
||||
},
|
||||
reads(3, bytes(128..256), shader_read()),
|
||||
];
|
||||
assert_eq!(lone[0].uses(), &want[..]);
|
||||
let before = part_notes();
|
||||
let mut two = EncoderUses::new(true);
|
||||
two.order(COMPUTE, &command, Reach::Unnamed);
|
||||
two.order(
|
||||
COMPUTE,
|
||||
&[reads(5, bytes(0..4), shader_read())],
|
||||
Reach::Unnamed,
|
||||
);
|
||||
assert_eq!(
|
||||
part_notes() - before,
|
||||
2,
|
||||
"a part of two commands notes both"
|
||||
);
|
||||
}
|
||||
|
||||
/// A part of one command answers what its encoder's later commands ask of the commands before
|
||||
/// them as an unordered encoder's map of the same command does: its writes and accesses met, its
|
||||
/// touches in a stage, the ranges of a key it writes and its tracked uses in a stage.
|
||||
#[test]
|
||||
fn a_part_of_one_command_answers_its_readers_as_its_map_would() {
|
||||
let command = lone_command();
|
||||
let (lone, _) = encoder_of_one(true, &command);
|
||||
let (mapped, _) = encoder_of_one(false, &command);
|
||||
let probes = [
|
||||
reads(3, bytes(32..48), shader_read()),
|
||||
reads(1, bytes(64..72), shader_read()),
|
||||
writes(1, bytes(100..101), shader_write()),
|
||||
writes(3, bytes(200..201), shader_write()),
|
||||
writes(2, bytes(0..64), shader_write()),
|
||||
writes(4, bytes(0..8), shader_write()),
|
||||
];
|
||||
let mut met = 0;
|
||||
for probe in &probes {
|
||||
let probe = std::slice::from_ref(probe);
|
||||
let answers = |uses: &EncoderUses<Key>| {
|
||||
[
|
||||
uses.written(probe),
|
||||
uses.accessed(probe),
|
||||
uses.touched_in(probe, COMPUTE),
|
||||
uses.touched_in(probe, TRANSFER),
|
||||
]
|
||||
};
|
||||
assert_eq!(answers(&lone), answers(&mapped), "{probe:?}");
|
||||
met += answers(&lone).iter().filter(|&&met| met).count();
|
||||
}
|
||||
assert!(met > 0, "no probe met the command");
|
||||
for key in 1..=5 {
|
||||
let ranges =
|
||||
|uses: &EncoderUses<Key>| uses.written_ranges(key).cloned().collect::<Vec<_>>();
|
||||
assert_eq!(ranges(&lone), ranges(&mapped), "key {key}");
|
||||
}
|
||||
let by_key = |mut uses: Vec<Use<Key>>| {
|
||||
uses.sort_by_key(|used| used.key);
|
||||
uses
|
||||
};
|
||||
assert_eq!(
|
||||
by_key(lone.tracked_in(COMPUTE)),
|
||||
by_key(mapped.tracked_in(COMPUTE))
|
||||
);
|
||||
assert_eq!(lone.written_ranges(3).count(), 1);
|
||||
}
|
||||
@@ -1384,13 +1384,6 @@ pub(super) struct EncoderUses<K> {
|
||||
/// ([`take_in_first`](Self::take_in_first)), so a part of one command builds no order at all.
|
||||
/// The reach is `None` where none waits; the list's storage is kept for the next part's.
|
||||
first: (Vec<Use<K>>, Option<Reach>),
|
||||
/// The current part's one command so far, waiting in `first`, is noted with the very uses it
|
||||
/// waits with, which its part's tracked map does not hold yet: a part of one command is
|
||||
/// summarized from them at its end ([`lone_summary`]), as `note` would leave its map, and
|
||||
/// builds no map at all. Anything else that adds to the part, or orders after or splits it,
|
||||
/// puts them in its map first ([`note_waiting`](Self::note_waiting)), and the readers of the
|
||||
/// map read them beside it ([`lone_uses`](Self::lone_uses)).
|
||||
lone: bool,
|
||||
/// How many commands the part's orders took in so far (`WorkCounts::commands_ordered_inside`).
|
||||
taken_in: u64,
|
||||
/// How many commands [`order_joined`](Self::order_joined) ordered by their runs joined.
|
||||
@@ -1569,7 +1562,6 @@ impl<K: Copy + Ord + Hash> EncoderUses<K> {
|
||||
compared: Vec::new(),
|
||||
kept: Vec::new(),
|
||||
first: (Vec::new(), None),
|
||||
lone: false,
|
||||
taken_in: 0,
|
||||
#[cfg(test)]
|
||||
joined: 0,
|
||||
@@ -1666,7 +1658,6 @@ impl<K: Copy + Ord + Hash> EncoderUses<K> {
|
||||
/// and named by no other use of the command: each key's list as [`note`](Self::note) leaves it
|
||||
/// from the run's uses, put in at once.
|
||||
fn note_kept(&mut self, kept: Vec<(K, Few<Use<K>>)>) {
|
||||
self.note_waiting();
|
||||
let part = self.current();
|
||||
part.tracked.reserve(kept.len());
|
||||
for (key, entries) in kept {
|
||||
@@ -1681,9 +1672,7 @@ impl<K: Copy + Ord + Hash> EncoderUses<K> {
|
||||
fn uses_key(&self, key: K) -> bool {
|
||||
let inside = (self.inside.get(&Class::Key(key))).is_some_and(|entries| !entries.is_empty());
|
||||
let part = self.parts.last().expect("an encoder has a part");
|
||||
inside
|
||||
|| (part.tracked.get(&key)).is_some_and(|known| !known.is_empty())
|
||||
|| self.lone_uses().any(|used| used.key == key)
|
||||
inside || (part.tracked.get(&key)).is_some_and(|known| !known.is_empty())
|
||||
}
|
||||
|
||||
/// [`order`](Self::order) of a command whose uses, as the order compares and takes them in,
|
||||
@@ -1695,8 +1684,7 @@ impl<K: Copy + Ord + Hash> EncoderUses<K> {
|
||||
reach: Reach,
|
||||
) -> Option<Barrier> {
|
||||
let barrier = self.barrier(ordered, reach);
|
||||
let waits = self.ordered && self.wait_first(ordered, reach);
|
||||
if self.ordered && !waits {
|
||||
if self.ordered && !self.wait_first(ordered, reach) {
|
||||
let kept = match ordered.iter().all(|used| used.tracked) {
|
||||
true => &self.compared,
|
||||
false => {
|
||||
@@ -1707,8 +1695,7 @@ impl<K: Copy + Ord + Hash> EncoderUses<K> {
|
||||
admit(&mut self.inside, kept, barrier, &[], Point::default());
|
||||
self.taken_in += 1;
|
||||
}
|
||||
// Waiting with the very uses it notes, it may be the part's one command (`lone`).
|
||||
self.note(stages, noted, waits && std::ptr::eq(ordered, noted));
|
||||
self.note(stages, noted);
|
||||
barrier
|
||||
}
|
||||
|
||||
@@ -1721,17 +1708,15 @@ impl<K: Copy + Ord + Hash> EncoderUses<K> {
|
||||
uses: &[Use<K>],
|
||||
barrier: Option<Barrier>,
|
||||
) {
|
||||
let mut waits = false;
|
||||
if self.ordered {
|
||||
self.take_in_first();
|
||||
waits = self.wait_first(uses, Reach::Unnamed);
|
||||
if !waits {
|
||||
if !self.wait_first(uses, Reach::Unnamed) {
|
||||
inside_uses(uses, Reach::Unnamed, true, &mut self.kept);
|
||||
admit(&mut self.inside, &self.kept, barrier, &[], Point::default());
|
||||
self.taken_in += 1;
|
||||
}
|
||||
}
|
||||
self.note(stages, uses, waits);
|
||||
self.note(stages, uses);
|
||||
}
|
||||
|
||||
/// Keep a command's `uses` and `reach` out of the part's order while nothing is in it (no
|
||||
@@ -1756,7 +1741,6 @@ impl<K: Copy + Ord + Hash> EncoderUses<K> {
|
||||
/// into it, where one waits: before anything compares with or adds to the order. Its list is
|
||||
/// made in the storage the next command compares in, which it writes over after.
|
||||
fn take_in_first(&mut self) {
|
||||
self.note_waiting();
|
||||
let (waiting, at) = &mut self.first;
|
||||
let Some(reach) = at.take() else {
|
||||
return;
|
||||
@@ -1779,56 +1763,42 @@ impl<K: Copy + Ord + Hash> EncoderUses<K> {
|
||||
}
|
||||
|
||||
/// Note a command the encoder orders recorded, in `stages`, with `uses`: its held images'
|
||||
/// holds, its part's stages and tracked uses. Where it `waits` in `first` with these very
|
||||
/// uses, the part's first command with no tracked use before it, of no more uses than a key
|
||||
/// keeps ranges (so no key's list would merge), its tracked uses stay there (`lone`).
|
||||
fn note(&mut self, stages: vk::PipelineStageFlags2, uses: &[Use<K>], waits: bool) {
|
||||
self.note_waiting();
|
||||
/// holds, its part's stages and tracked uses.
|
||||
fn note(&mut self, stages: vk::PipelineStageFlags2, uses: &[Use<K>]) {
|
||||
if !self.held.is_empty() {
|
||||
let held = &self.held;
|
||||
self.broke |= uses.iter().any(|used| {
|
||||
held.contains(&used.key) && !used.is_nothing() && !used.is_depth_attachment()
|
||||
});
|
||||
}
|
||||
let part = self.parts.last_mut().expect("an encoder has a part");
|
||||
let part = self.current();
|
||||
// Every stage, untracked work's too: a fence wait orders all of the encoder's work.
|
||||
part.stages |= uses.iter().fold(stages, |all, used| {
|
||||
all | used.read.stages | used.write.stages
|
||||
});
|
||||
if waits && uses.len() <= ENTRIES_PER_KEY && part.tracked.is_empty() {
|
||||
debug_assert!(
|
||||
uses == &self.first.0[..],
|
||||
"a part's one command noted with other uses than it waits with"
|
||||
);
|
||||
self.lone = true;
|
||||
return;
|
||||
// Room for a few resources at once, made at the part's first: grown from nothing, the map
|
||||
// would allocate again at its fourth and eighth.
|
||||
if part.tracked.capacity() == 0 {
|
||||
part.tracked.reserve(TRACKED_ROOM);
|
||||
}
|
||||
note_tracked(part, uses);
|
||||
}
|
||||
|
||||
/// Put the uses of the current part's one command, waiting in `first` (`lone`), in its
|
||||
/// tracked map, where they are not: as `note` would have put them there.
|
||||
fn note_waiting(&mut self) {
|
||||
if !self.lone {
|
||||
return;
|
||||
}
|
||||
self.lone = false;
|
||||
let part = self.parts.last_mut().expect("an encoder has a part");
|
||||
note_tracked(part, &self.first.0);
|
||||
}
|
||||
|
||||
/// The tracked uses that touch something of the current part's one command, waiting in
|
||||
/// `first` with its part's map not holding them (`lone`), as it recorded them: none else.
|
||||
/// Each key's are those `note` would keep in its list, but that two of one range are not
|
||||
/// joined (a part of one command keeps none past a list's length, so none merge either).
|
||||
fn lone_uses(&self) -> impl Iterator<Item = &Use<K>> + Clone + '_ {
|
||||
let waiting = match self.lone {
|
||||
true => &self.first.0[..],
|
||||
false => &[],
|
||||
};
|
||||
waiting
|
||||
for used in uses
|
||||
.iter()
|
||||
.filter(|used| used.tracked && !used.is_nothing())
|
||||
{
|
||||
let ranges = part.tracked.entry(used.key).or_default();
|
||||
match ranges.iter_mut().find(|known| known.range == used.range) {
|
||||
Some(known) => {
|
||||
known.read = known.read.union(used.read);
|
||||
known.write = known.write.union(used.write);
|
||||
}
|
||||
// A resource used at a second range (a buffer whose draws move along it) takes
|
||||
// room for every range it keeps before they merge, and the merge's own, at once.
|
||||
None => ranges.push_with_room(used.clone(), ENTRIES_PER_KEY + 1),
|
||||
}
|
||||
if ranges.len() > ENTRIES_PER_KEY {
|
||||
ranges.change_all(coalesce_uses);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a command the encoder recorded so far writes memory one of `uses` reads: an
|
||||
@@ -1839,10 +1809,13 @@ impl<K: Copy + Ord + Hash> EncoderUses<K> {
|
||||
uses.iter()
|
||||
.filter(|read| read.tracked && !read.read.is_empty())
|
||||
.any(|read| {
|
||||
let writes = |k: &Use<K>| !k.write.is_empty() && k.range.overlaps(&read.range);
|
||||
self.parts.iter().any(|part| {
|
||||
(part.tracked.get(&read.key)).is_some_and(|known| known.iter().any(writes))
|
||||
}) || self.lone_uses().any(|k| k.key == read.key && writes(k))
|
||||
part.tracked.get(&read.key).is_some_and(|known| {
|
||||
known
|
||||
.iter()
|
||||
.any(|k| !k.write.is_empty() && k.range.overlaps(&read.range))
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1854,23 +1827,19 @@ impl<K: Copy + Ord + Hash> EncoderUses<K> {
|
||||
uses.iter()
|
||||
.filter(|write| write.tracked && !write.write.is_empty())
|
||||
.any(|write| {
|
||||
let meets = |k: &Use<K>| k.range.overlaps(&write.range);
|
||||
self.parts.iter().any(|part| {
|
||||
(part.tracked.get(&write.key)).is_some_and(|known| known.iter().any(meets))
|
||||
}) || self.lone_uses().any(|k| k.key == write.key && meets(k))
|
||||
part.tracked
|
||||
.get(&write.key)
|
||||
.is_some_and(|known| known.iter().any(|k| k.range.overlaps(&write.range)))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/// The tracked uses of the commands recorded so far that ran in one of `stages`.
|
||||
pub(super) fn tracked_in(&self, stages: vk::PipelineStageFlags2) -> Vec<Use<K>> {
|
||||
let lone = match self.lone {
|
||||
true => lone_summary(self.first.0.clone()),
|
||||
false => Vec::new(),
|
||||
};
|
||||
self.parts
|
||||
.iter()
|
||||
.flat_map(|part| part.tracked.values().flatten())
|
||||
.chain(&lone)
|
||||
.filter(|known| (known.read.stages | known.write.stages).intersects(stages))
|
||||
.cloned()
|
||||
.collect()
|
||||
@@ -1884,7 +1853,7 @@ impl<K: Copy + Ord + Hash> EncoderUses<K> {
|
||||
part.tracked
|
||||
.get(&used.key)
|
||||
.is_some_and(|known| known.iter().any(|k| touches(k, used, stages)))
|
||||
}) || self.lone_uses().any(|k| touches(k, used, stages))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1945,37 +1914,16 @@ impl<K: Copy + Ord + Hash> EncoderUses<K> {
|
||||
/// The ranges of `key` its tracked uses so far write, in every part: what a copy out decided
|
||||
/// as it is encoded takes of its encoder's commands before it (`managed_sync.rs`).
|
||||
pub(super) fn written_ranges(&self, key: K) -> impl Iterator<Item = &UseRange> + '_ {
|
||||
// The current part's one command's ([`lone_uses`](Self::lone_uses)): each range of the
|
||||
// key once, where it first was, if a use of it writes, as its list would hold them.
|
||||
let lone = self.lone_uses().filter(move |used| used.key == key);
|
||||
let lone_ranges = (lone.clone().enumerate())
|
||||
.filter({
|
||||
let lone = lone.clone();
|
||||
move |(at, used)| {
|
||||
lone.clone()
|
||||
.take(*at)
|
||||
.all(|known| known.range != used.range)
|
||||
}
|
||||
})
|
||||
.filter({
|
||||
let lone = lone.clone();
|
||||
move |(_, used)| {
|
||||
(lone.clone()).any(|known| known.range == used.range && !known.write.is_empty())
|
||||
}
|
||||
})
|
||||
.map(|(_, used)| &used.range);
|
||||
(self.parts.iter())
|
||||
.filter_map(move |part| part.tracked.get(&key))
|
||||
.flat_map(Few::iter)
|
||||
.filter(|used| !used.write.is_empty())
|
||||
.map(|used| &used.range)
|
||||
.chain(lone_ranges)
|
||||
}
|
||||
|
||||
/// End the current part: the commands after this run in a part of their own, after
|
||||
/// everything before it completed, so they need no barrier after the commands before.
|
||||
pub(super) fn split(&mut self) {
|
||||
self.note_waiting();
|
||||
self.inside.clear();
|
||||
// The part's first command, ordered after nothing, orders nothing after it any more.
|
||||
self.first.1 = None;
|
||||
@@ -2000,37 +1948,28 @@ impl<K: Copy + Ord + Hash> EncoderUses<K> {
|
||||
parts,
|
||||
waits,
|
||||
updates,
|
||||
first: (waiting, _),
|
||||
lone,
|
||||
..
|
||||
} = self;
|
||||
let mut summaries: Vec<Summary<K>> = parts
|
||||
.into_iter()
|
||||
.map(|part| Summary {
|
||||
uses: part_uses(&part),
|
||||
stages: part.stages,
|
||||
waits: Vec::new(),
|
||||
updates: Vec::new(),
|
||||
.map(|part| {
|
||||
// By key, each resource's uses in the order they were recorded, as a stable sort
|
||||
// of the uses by key leaves them: a resource's uses are one list, so ordering
|
||||
// the resources orders them, and only their keys, each once, are sorted, each
|
||||
// beside its list where the part holds it (`by_key`).
|
||||
// Sized once: a flattened iterator tells no length, which would grow the vector
|
||||
// use by use.
|
||||
let count = part.tracked.values().map(Few::len).sum();
|
||||
let mut uses: Vec<Use<K>> = Vec::with_capacity(count);
|
||||
by_key(&part.tracked, |few| uses.extend(few.iter().cloned()));
|
||||
Summary {
|
||||
uses,
|
||||
stages: part.stages,
|
||||
waits: Vec::new(),
|
||||
updates: Vec::new(),
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
// The last part's one command's, which its map does not hold (`lone`): summarized from
|
||||
// the uses it waited with, checked against those its map would have held in builds with
|
||||
// debug assertions.
|
||||
if let (true, Some(last)) = (lone, summaries.last_mut()) {
|
||||
debug_assert!(last.uses.is_empty(), "a part of one command with a map");
|
||||
#[cfg(debug_assertions)]
|
||||
let noted = {
|
||||
let mut part = Part::new();
|
||||
note_map(&mut part, &waiting);
|
||||
part_uses(&part)
|
||||
};
|
||||
last.uses = lone_summary(waiting);
|
||||
#[cfg(debug_assertions)]
|
||||
assert!(
|
||||
last.uses == noted,
|
||||
"a part of one command summarized otherwise than its map would be"
|
||||
);
|
||||
}
|
||||
if let Some(first) = summaries.first_mut() {
|
||||
first.waits = waits;
|
||||
}
|
||||
@@ -2063,101 +2002,6 @@ fn by_key<K: Copy + Ord, V, S>(tracked: &HashMap<K, V, S>, mut each: impl FnMut(
|
||||
order.iter().for_each(|&(_, value)| each(value));
|
||||
}
|
||||
|
||||
/// Note `uses`, a command's, in `part`'s tracked map ([`EncoderUses::note`]), counted in
|
||||
/// tests (`part_notes`).
|
||||
fn note_tracked<K: Copy + Eq + Hash>(part: &mut Part<K>, uses: &[Use<K>]) {
|
||||
#[cfg(test)]
|
||||
PART_NOTES.with(|notes| notes.set(notes.get() + 1));
|
||||
note_map(part, uses);
|
||||
}
|
||||
|
||||
/// [`note_tracked`]'s work: each tracked use that touches something joins its key's use of the
|
||||
/// same range, else its key's list, whose ranges merge past [`ENTRIES_PER_KEY`].
|
||||
fn note_map<K: Copy + Eq + Hash>(part: &mut Part<K>, uses: &[Use<K>]) {
|
||||
// Room for a few resources at once, made at the part's first: grown from nothing, the map
|
||||
// would allocate again at its fourth and eighth.
|
||||
if part.tracked.capacity() == 0 {
|
||||
part.tracked.reserve(TRACKED_ROOM);
|
||||
}
|
||||
for used in uses
|
||||
.iter()
|
||||
.filter(|used| used.tracked && !used.is_nothing())
|
||||
{
|
||||
let ranges = part.tracked.entry(used.key).or_default();
|
||||
match ranges.iter_mut().find(|known| known.range == used.range) {
|
||||
Some(known) => {
|
||||
known.read = known.read.union(used.read);
|
||||
known.write = known.write.union(used.write);
|
||||
}
|
||||
// A resource used at a second range (a buffer whose draws move along it) takes
|
||||
// room for every range it keeps before they merge, and the merge's own, at once.
|
||||
None => ranges.push_with_room(used.clone(), ENTRIES_PER_KEY + 1),
|
||||
}
|
||||
if ranges.len() > ENTRIES_PER_KEY {
|
||||
ranges.change_all(coalesce_uses);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
thread_local! {
|
||||
/// The commands noted in a part's tracked map on this thread ([`note_tracked`]), in tests.
|
||||
static PART_NOTES: std::cell::Cell<u64> = const { std::cell::Cell::new(0) };
|
||||
}
|
||||
|
||||
/// How many commands this thread noted in a part's tracked map so far ([`note_tracked`]): none
|
||||
/// for a part of one command ([`EncoderUses`]'s `lone`).
|
||||
#[cfg(test)]
|
||||
pub(super) fn part_notes() -> u64 {
|
||||
PART_NOTES.with(std::cell::Cell::get)
|
||||
}
|
||||
|
||||
/// A part's tracked uses, as its summary holds them: by key, each resource's uses in the order
|
||||
/// they were recorded, as a stable sort of the uses by key leaves them. A resource's uses are one
|
||||
/// list, so ordering the resources orders them, and only their keys, each once, are sorted, each
|
||||
/// beside its list where the part holds it ([`by_key`]).
|
||||
fn part_uses<K: Copy + Ord>(part: &Part<K>) -> Vec<Use<K>> {
|
||||
// Sized once: a flattened iterator tells no length, which would grow the vector use by use.
|
||||
let count = part.tracked.values().map(Few::len).sum();
|
||||
let mut uses: Vec<Use<K>> = Vec::with_capacity(count);
|
||||
by_key(&part.tracked, |few| uses.extend(few.iter().cloned()));
|
||||
uses
|
||||
}
|
||||
|
||||
/// The summary's uses of a part of one command, `uses` its own as it recorded them (the
|
||||
/// `lone` of [`EncoderUses`]): those tracked that touch something, by key in the order recorded,
|
||||
/// and the uses of one key and range joined into the first, as the part's tracked map would hold
|
||||
/// them, read by key ([`by_key`]). Of no more uses than [`ENTRIES_PER_KEY`], no key's ranges merge.
|
||||
fn lone_summary<K: Copy + Ord>(mut uses: Vec<Use<K>>) -> Vec<Use<K>> {
|
||||
debug_assert!(uses.len() <= ENTRIES_PER_KEY);
|
||||
uses.retain(|used| used.tracked && !used.is_nothing());
|
||||
uses.sort_by_key(|used| used.key);
|
||||
// The uses kept so far lie before `kept`; one of the key and range of one of those joins it.
|
||||
let mut kept = 0;
|
||||
for at in 0..uses.len() {
|
||||
let same = {
|
||||
let used = &uses[at];
|
||||
(0..kept)
|
||||
.rev()
|
||||
.take_while(|&known| uses[known].key == used.key)
|
||||
.find(|&known| uses[known].range == used.range)
|
||||
};
|
||||
match same {
|
||||
Some(known) => {
|
||||
let (read, write) = (uses[at].read, uses[at].write);
|
||||
uses[known].read = uses[known].read.union(read);
|
||||
uses[known].write = uses[known].write.union(write);
|
||||
}
|
||||
None => {
|
||||
uses.swap(kept, at);
|
||||
kept += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
uses.truncate(kept);
|
||||
uses
|
||||
}
|
||||
|
||||
impl<K> fmt::Debug for EncoderUses<K> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("EncoderUses")
|
||||
|
||||
@@ -902,7 +902,6 @@ struct CommandCounters {
|
||||
dispatches_settled_as_before: AtomicU64,
|
||||
dispatches_settled_across_encoders: AtomicU64,
|
||||
dispatches_instantiated: AtomicU64,
|
||||
dispatches_instantiated_in_place: AtomicU64,
|
||||
dispatches_instantiated_as_before: AtomicU64,
|
||||
dispatches_from_set_aside: AtomicU64,
|
||||
set_aside_commands_kept: AtomicU64,
|
||||
@@ -2159,13 +2158,6 @@ impl Counting<'_> {
|
||||
self.0.add(|counts| &counts.dispatches_instantiated, 1);
|
||||
}
|
||||
|
||||
/// A compute encoder's dispatch whose commands `compute::record` instantiated over the
|
||||
/// storage of those its kept bind state kept (`compute::Instantiated`).
|
||||
pub(crate) fn dispatch_instantiated_in_place(&self) {
|
||||
self.0
|
||||
.add(|counts| &counts.dispatches_instantiated_in_place, 1);
|
||||
}
|
||||
|
||||
/// A compute encoder's dispatch that took the commands its kept bind state kept of what it
|
||||
/// planned (`compute::Instantiated`).
|
||||
pub(crate) fn dispatch_instantiated_as_before(&self) {
|
||||
@@ -7982,8 +7974,7 @@ pub struct WorkCounts {
|
||||
pub parked_compute_taken: u64,
|
||||
/// The lists a released command buffer keeps of what its encoders ended with (its ended
|
||||
/// encoders' records, their recordings, a group's logs its members did not keep and those held
|
||||
/// for its commit, its command predication's lists, and its groups' order's map and lists)
|
||||
/// that held more room as it was released than the storage it started on:
|
||||
/// for its commit) that held more room as it was released than the storage it started on:
|
||||
/// counted once each, at the release. A command buffer starts on the state a released one of
|
||||
/// the device left (`record_storage_kept`), its lists emptied with their room kept, so one of
|
||||
/// no more encoders than that one's grows none.
|
||||
@@ -10122,13 +10113,6 @@ pub struct WorkCounts {
|
||||
/// execution, or of a host step. None for a compute encoder's dispatch counted in
|
||||
/// `dispatches_settled_as_before` or `dispatches_instantiated_as_before`.
|
||||
pub dispatches_instantiated: u64,
|
||||
/// Of `dispatches_instantiated`, compute encoders' direct dispatches whose commands were
|
||||
/// written over the storage of those their encoder's kept bind state kept
|
||||
/// (`BindingPlan::instantiate_dispatch_into`, `compute::Instantiated`), which nothing else
|
||||
/// held any more, rather than made anew: a dispatch of an encoder of its own that binds a
|
||||
/// buffer at another offset than its pipeline state's last dispatch, for one. A function of
|
||||
/// what the dispatches bind and of their order alone.
|
||||
pub dispatches_instantiated_in_place: u64,
|
||||
/// Compute encoders' dispatches that took the commands their encoder's kept bind state kept
|
||||
/// rather than instantiating them (`compute::Instantiated`): those of the very variant, plan
|
||||
/// and dispatch (`pipeline::Planned`) a direct dispatch of the encoder, or of an earlier
|
||||
@@ -13285,9 +13269,6 @@ impl Device {
|
||||
&counts.dispatches_settled_across_encoders
|
||||
}),
|
||||
dispatches_instantiated: commands(|counts| &counts.dispatches_instantiated),
|
||||
dispatches_instantiated_in_place: commands(|counts| {
|
||||
&counts.dispatches_instantiated_in_place
|
||||
}),
|
||||
dispatches_instantiated_as_before: commands(|counts| {
|
||||
&counts.dispatches_instantiated_as_before
|
||||
}),
|
||||
|
||||
@@ -1 +1 @@
|
||||
dac9ca69cf61a096b374b5621565ff7c400fc33a05d5db618891572e63d53706
|
||||
178fdf404e82e2905ba72645d4c5f81cc8e8ff00e3d62405e7b3f64666bd5986
|
||||
@@ -90,14 +90,13 @@
|
||||
//! dispatch carries an [`IndirectClamp`] prepass and its region reads the clamp's scratch
|
||||
//! ([`IndirectArgs::ClampScratch`]).
|
||||
|
||||
use crate::bind::graphics::zeroed;
|
||||
use crate::bind::heap::HeapSource;
|
||||
use crate::bind::indirect_clamp::IndirectClamp;
|
||||
use crate::bind::instantiate::{
|
||||
bind_buffers, put, slot_field, texel_ranges, BufferExtent, DescriptorBytes, DescriptorRange,
|
||||
FieldBytes, IndirectRef, PushConstantWrite, PushHole, RootEntry, RootTable,
|
||||
};
|
||||
use crate::bind::plan::compute::{internal, not_implemented, spec_key_into};
|
||||
use crate::bind::plan::compute::{internal, not_implemented, spec_key};
|
||||
use crate::bind::plan::{
|
||||
AccessClass, BindingPlan, ByteRange, ComputeTemplate, LocalRules, ResourceUse, UseTarget,
|
||||
};
|
||||
@@ -212,23 +211,6 @@ pub struct DispatchCommands {
|
||||
pub uses: Vec<ResourceUse>,
|
||||
}
|
||||
|
||||
impl DispatchCommands {
|
||||
/// No dispatch's commands, which an instantiation writes over (`instantiate`).
|
||||
fn none() -> DispatchCommands {
|
||||
DispatchCommands {
|
||||
regions: Vec::new(),
|
||||
descriptor_bytes: Vec::new(),
|
||||
descriptor_ranges: Vec::new(),
|
||||
extents: Vec::new(),
|
||||
push_holes: Vec::new(),
|
||||
region_record: None,
|
||||
root_table: None,
|
||||
indirect_clamp: None,
|
||||
uses: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Where an indirect region reads its group counts.
|
||||
#[non_exhaustive]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
@@ -336,16 +318,17 @@ fn emulated_rules(rules: &LocalRules) -> LocalRules {
|
||||
/// least 1), with every region checked against that pipeline's rules. A flattened tier's dispatch
|
||||
/// with a region that is not whole subgroups runs whole on the emulated-simdgroups variant, so each
|
||||
/// of its regions is checked against the variant's rules ([`emulated_rules`]).
|
||||
pub(crate) fn fit(
|
||||
rules: &LocalRules,
|
||||
mut locals: impl Iterator<Item = [u32; 3]> + Clone,
|
||||
) -> Result<Fit, BindError> {
|
||||
if locals.clone().any(|r| partial(rules, r)) {
|
||||
pub(crate) fn fit(rules: &LocalRules, locals: &[[u32; 3]]) -> Result<Fit, BindError> {
|
||||
if locals.iter().any(|&r| partial(rules, r)) {
|
||||
let emulated = emulated_rules(rules);
|
||||
locals.try_for_each(|r| check_local(&emulated, r))?;
|
||||
for &r in locals {
|
||||
check_local(&emulated, r)?;
|
||||
}
|
||||
Ok(Fit::EmulatedSimdgroups)
|
||||
} else {
|
||||
locals.try_for_each(|r| check_local(rules, r))?;
|
||||
for &r in locals {
|
||||
check_local(rules, r)?;
|
||||
}
|
||||
Ok(Fit::Planned)
|
||||
}
|
||||
}
|
||||
@@ -434,174 +417,24 @@ pub(crate) struct Region {
|
||||
pub multi: bool,
|
||||
}
|
||||
|
||||
/// One piece of an axis: `(base, count, local)`.
|
||||
/// One axis's pieces: `(base, count, local)`.
|
||||
type Piece = (u32, u32, u32);
|
||||
|
||||
/// One axis's pieces: `count` groups of `local` threads from group `base`, in chunks of at most
|
||||
/// `max`, then the edge piece where there is one. Held as these numbers alone, so a dispatch's
|
||||
/// regions are planned with no list of each axis's pieces, nor of the regions ([`Regions`]).
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
struct Pieces {
|
||||
base: u32,
|
||||
count: u32,
|
||||
local: u32,
|
||||
max: u32,
|
||||
/// How many chunks `count` takes: `count / max`, rounded up.
|
||||
chunks: u32,
|
||||
edge: Option<Piece>,
|
||||
}
|
||||
|
||||
impl Pieces {
|
||||
/// `count` groups of `local` threads from group `base`, in chunks of at most `max`.
|
||||
fn chunks(base: u32, count: u32, local: u32, max: u32) -> Pieces {
|
||||
let max = max.max(1);
|
||||
Pieces {
|
||||
base,
|
||||
count,
|
||||
local,
|
||||
max,
|
||||
chunks: count.div_ceil(max),
|
||||
edge: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The one piece `(base, count, local)`, whatever its count (0 for an indirect region's).
|
||||
fn one(base: u32, count: u32, local: u32) -> Pieces {
|
||||
Pieces {
|
||||
base,
|
||||
count: 0,
|
||||
local,
|
||||
max: 1,
|
||||
chunks: 0,
|
||||
edge: Some((base, count, local)),
|
||||
}
|
||||
}
|
||||
|
||||
/// How many pieces the axis has.
|
||||
fn len(&self) -> u64 {
|
||||
u64::from(self.chunks) + u64::from(self.edge.is_some())
|
||||
}
|
||||
|
||||
/// Piece `k` in order: each chunk, then the edge; `None` past the last.
|
||||
fn piece(&self, k: u64) -> Option<Piece> {
|
||||
match u32::try_from(k) {
|
||||
// Each chunk starts below `count`, so no start overflows.
|
||||
Ok(k) if k < self.chunks => {
|
||||
let done = k * self.max;
|
||||
Some((
|
||||
self.base + done,
|
||||
(self.count - done).min(self.max),
|
||||
self.local,
|
||||
))
|
||||
}
|
||||
Ok(k) if k == self.chunks => self.edge,
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The widest local size of its pieces, 0 where it has none.
|
||||
fn widest(&self) -> u32 {
|
||||
let chunk = if self.chunks > 0 { self.local } else { 0 };
|
||||
chunk.max(self.edge.map_or(0, |(_, _, local)| local))
|
||||
}
|
||||
}
|
||||
|
||||
/// The regions of a dispatch: the product of each axis's pieces, x slowest, each region taking one
|
||||
/// piece of every axis, all of one `MultiRegion`. Held as these numbers alone, so planning a
|
||||
/// dispatch makes no list of its regions: [`Regions::iter`] gives them in order.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) struct Regions {
|
||||
pieces: [Pieces; 3],
|
||||
multi: bool,
|
||||
}
|
||||
|
||||
impl Regions {
|
||||
/// No region.
|
||||
fn none() -> Regions {
|
||||
Regions {
|
||||
pieces: [Pieces::chunks(0, 0, 0, 1); 3],
|
||||
multi: false,
|
||||
}
|
||||
}
|
||||
|
||||
/// The one region `r`.
|
||||
fn one(r: Region) -> Regions {
|
||||
Regions {
|
||||
pieces: std::array::from_fn(|i| Pieces::one(r.base[i], r.groups[i], r.local[i])),
|
||||
multi: r.multi,
|
||||
}
|
||||
}
|
||||
|
||||
/// How many regions there are.
|
||||
pub(crate) fn len(&self) -> usize {
|
||||
self.pieces.iter().map(Pieces::len).product::<u64>() as usize
|
||||
}
|
||||
|
||||
pub(crate) fn is_empty(&self) -> bool {
|
||||
self.len() == 0
|
||||
}
|
||||
|
||||
/// The regions in order.
|
||||
pub(crate) fn iter(&self) -> RegionsIter {
|
||||
RegionsIter {
|
||||
regions: *self,
|
||||
at: [0; 3],
|
||||
left: self.len(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The widest local size along `axis` of any region, 0 where there is none: each piece of an
|
||||
/// axis is some region's where there is a region.
|
||||
fn widest(&self, axis: usize) -> u32 {
|
||||
match self.is_empty() {
|
||||
true => 0,
|
||||
false => self.pieces[axis].widest(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Every region with `MultiRegion` 1: it reads its record.
|
||||
fn read_records(&mut self) {
|
||||
self.multi = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// [`Regions::iter`]: each region in order, the piece of each axis it takes counted from x
|
||||
/// slowest to z fastest.
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct RegionsIter {
|
||||
regions: Regions,
|
||||
at: [u64; 3],
|
||||
left: usize,
|
||||
}
|
||||
|
||||
impl Iterator for RegionsIter {
|
||||
type Item = Region;
|
||||
|
||||
fn next(&mut self) -> Option<Region> {
|
||||
self.left = self.left.checked_sub(1)?;
|
||||
let pieces = &self.regions.pieces;
|
||||
let [x, y, z] = [0, 1, 2].map(|i| pieces[i].piece(self.at[i]));
|
||||
let ((bx, cx, lx), (by, cy, ly), (bz, cz, lz)) = (x?, y?, z?);
|
||||
for i in [2, 1, 0] {
|
||||
self.at[i] += 1;
|
||||
if i == 0 || self.at[i] < pieces[i].len() {
|
||||
break;
|
||||
}
|
||||
self.at[i] = 0;
|
||||
}
|
||||
Some(Region {
|
||||
local: [lx, ly, lz],
|
||||
groups: [cx, cy, cz],
|
||||
base: [bx, by, bz],
|
||||
multi: self.regions.multi,
|
||||
})
|
||||
/// `count` groups of `local` threads from group `base`, in chunks of at most `max`.
|
||||
fn chunks(out: &mut Vec<Piece>, base: u32, count: u32, local: u32, max: u32) {
|
||||
let max = max.max(1);
|
||||
let mut done = 0;
|
||||
while done < count {
|
||||
let n = (count - done).min(max);
|
||||
out.push((base + done, n, local));
|
||||
done += n;
|
||||
}
|
||||
}
|
||||
|
||||
/// The regions of a direct dispatch whose axes split into `pieces`; `MultiRegion` whenever there
|
||||
/// is more than one region or `force_multi`.
|
||||
fn product(pieces: [Pieces; 3], force_multi: bool) -> Result<Regions, BindError> {
|
||||
let total: u64 = pieces.iter().map(Pieces::len).product();
|
||||
fn product(pieces: [Vec<Piece>; 3], force_multi: bool) -> Result<Vec<Region>, BindError> {
|
||||
let total: u64 = pieces.iter().map(|p| p.len() as u64).product();
|
||||
if total > MAX_REGIONS {
|
||||
let (i, _) = pieces
|
||||
.iter()
|
||||
@@ -614,10 +447,21 @@ fn product(pieces: [Pieces; 3], force_multi: bool) -> Result<Regions, BindError>
|
||||
},
|
||||
)));
|
||||
}
|
||||
Ok(Regions {
|
||||
pieces,
|
||||
multi: force_multi || total > 1,
|
||||
})
|
||||
let multi = force_multi || total > 1;
|
||||
let mut out = Vec::with_capacity(total as usize);
|
||||
for &(bx, cx, lx) in &pieces[0] {
|
||||
for &(by, cy, ly) in &pieces[1] {
|
||||
for &(bz, cz, lz) in &pieces[2] {
|
||||
out.push(Region {
|
||||
local: [lx, ly, lz],
|
||||
groups: [cx, cy, cz],
|
||||
base: [bx, by, bz],
|
||||
multi,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// Whether a region of `planned` has more than one row (`y` or `z` above 1), where a simdgroup
|
||||
@@ -626,7 +470,7 @@ fn product(pieces: [Pieces; 3], force_multi: bool) -> Result<Regions, BindError>
|
||||
/// 2 `z`): Metal's `threads_per_threadgroup` there is 1, and so is every region's local size.
|
||||
fn unit_axes(planned: &Planned) -> u8 {
|
||||
(0..3)
|
||||
.filter(|&a| planned.nominal[a] == 1 && planned.regions.widest(a) <= 1)
|
||||
.filter(|&a| planned.nominal[a] == 1 && planned.regions.iter().all(|r| r.local[a] <= 1))
|
||||
.fold(0, |axes, a| axes | 1 << a)
|
||||
}
|
||||
|
||||
@@ -637,13 +481,16 @@ fn unit_axes_run(axes: u8, planned: &Planned) -> bool {
|
||||
}
|
||||
|
||||
fn multi_row(planned: &Planned) -> bool {
|
||||
planned.regions.widest(1) > 1 || planned.regions.widest(2) > 1
|
||||
planned
|
||||
.regions
|
||||
.iter()
|
||||
.any(|r| r.local[1] > 1 || r.local[2] > 1)
|
||||
}
|
||||
|
||||
/// The regions of a dispatch.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub(crate) struct Planned {
|
||||
pub regions: Regions,
|
||||
pub regions: Vec<Region>,
|
||||
/// The Metal grid (`threads_per_grid`) the `DispatchRegion` field reports (0 for an indirect
|
||||
/// dispatch, whose grid only the GPU knows).
|
||||
pub grid: [u32; 3],
|
||||
@@ -785,7 +632,7 @@ pub(crate) fn regions(
|
||||
}
|
||||
}
|
||||
let empty = |v: [u32; 3]| v.contains(&0);
|
||||
let planned = |regions: Regions, grid, emulated: bool| Planned {
|
||||
let planned = |regions: Vec<Region>, grid, emulated: bool| Planned {
|
||||
emulated: emulated && !regions.is_empty(),
|
||||
regions,
|
||||
grid,
|
||||
@@ -794,13 +641,16 @@ pub(crate) fn regions(
|
||||
};
|
||||
match *dispatch {
|
||||
Dispatch::Threadgroups { groups, .. } => {
|
||||
let fit = fit(rules, std::iter::once(l))?;
|
||||
let fit = fit(rules, &[l])?;
|
||||
let grid = threadgroup_grid(groups, nominal)?;
|
||||
if empty(groups) {
|
||||
return Ok(planned(Regions::none(), grid, false));
|
||||
return Ok(planned(Vec::new(), grid, false));
|
||||
}
|
||||
let pieces =
|
||||
std::array::from_fn(|i| Pieces::chunks(0, groups[i], l[i], rules.max_count[i]));
|
||||
let pieces = std::array::from_fn(|i| {
|
||||
let mut p = Vec::new();
|
||||
chunks(&mut p, 0, groups[i], l[i], rules.max_count[i]);
|
||||
p
|
||||
});
|
||||
// A partial-threadgroups variant's regions read their region, as its `Threads`
|
||||
// regions do, so both run on its one `VkPipeline` of the dispatch's size.
|
||||
let multi = tile_sized || ragged == Ragged::Partial;
|
||||
@@ -816,16 +666,24 @@ pub(crate) fn regions(
|
||||
count,
|
||||
..
|
||||
} => {
|
||||
let fit = fit(rules, std::iter::once(l))?;
|
||||
let fit = fit(rules, &[l])?;
|
||||
let grid = threadgroup_grid(groups, nominal)?;
|
||||
let start: [u32; 3] = std::array::from_fn(|i| first[i].min(groups[i]));
|
||||
let end: [u32; 3] =
|
||||
std::array::from_fn(|i| first[i].saturating_add(count[i]).min(groups[i]));
|
||||
if (0..3).any(|i| end[i] <= start[i]) {
|
||||
return Ok(planned(Regions::none(), grid, false));
|
||||
return Ok(planned(Vec::new(), grid, false));
|
||||
}
|
||||
let pieces = std::array::from_fn(|i| {
|
||||
Pieces::chunks(start[i], end[i] - start[i], l[i], rules.max_count[i])
|
||||
let mut p = Vec::new();
|
||||
chunks(
|
||||
&mut p,
|
||||
start[i],
|
||||
end[i] - start[i],
|
||||
l[i],
|
||||
rules.max_count[i],
|
||||
);
|
||||
p
|
||||
});
|
||||
// Every region takes its first threadgroup from the push field.
|
||||
Ok(planned(
|
||||
@@ -836,7 +694,7 @@ pub(crate) fn regions(
|
||||
}
|
||||
Dispatch::Threads { threads, .. } => {
|
||||
if empty(threads) {
|
||||
return Ok(planned(Regions::none(), threads, false));
|
||||
return Ok(planned(Vec::new(), threads, false));
|
||||
}
|
||||
// A flat variant runs the whole grid in one region of the dispatch's own threadgroup
|
||||
// size: invocation `((wz · ny + wy) · nx + wx) · N + LocalInvocationIndex`, with
|
||||
@@ -846,7 +704,7 @@ pub(crate) fn regions(
|
||||
// in each and run the same threads again: the region is never chunked, and its counts
|
||||
// only have to cover the grid ([`spread`]).
|
||||
if ragged == Ragged::Flat {
|
||||
let fit = fit(rules, std::iter::once(l))?;
|
||||
let fit = fit(rules, &[l])?;
|
||||
let n: u64 = l.iter().map(|&x| u64::from(x)).product();
|
||||
let total: u128 = threads.iter().map(|&x| u128::from(x)).product();
|
||||
let need = u64::try_from(total.div_ceil(u128::from(n))).map_err(|_| {
|
||||
@@ -864,7 +722,7 @@ pub(crate) fn regions(
|
||||
multi: false,
|
||||
};
|
||||
return Ok(planned(
|
||||
Regions::one(region),
|
||||
vec![region],
|
||||
threads,
|
||||
fit == Fit::EmulatedSimdgroups,
|
||||
));
|
||||
@@ -876,10 +734,18 @@ pub(crate) fn regions(
|
||||
// every thread is live, on the same `VkPipeline` of the dispatch's size.
|
||||
let nonuniform = (0..3).any(|i| !threads[i].is_multiple_of(l[i]));
|
||||
if ragged == Ragged::Partial {
|
||||
let pieces = std::array::from_fn(|i| {
|
||||
Pieces::chunks(0, threads[i].div_ceil(l[i]), l[i], rules.max_count[i])
|
||||
let pieces: [Vec<Piece>; 3] = std::array::from_fn(|i| {
|
||||
let mut p = Vec::new();
|
||||
chunks(
|
||||
&mut p,
|
||||
0,
|
||||
threads[i].div_ceil(l[i]),
|
||||
l[i],
|
||||
rules.max_count[i],
|
||||
);
|
||||
p
|
||||
});
|
||||
let fit = fit(rules, std::iter::once(l))?;
|
||||
let fit = fit(rules, &[l])?;
|
||||
let mut out = planned(
|
||||
product(pieces, true)?,
|
||||
threads,
|
||||
@@ -889,21 +755,23 @@ pub(crate) fn regions(
|
||||
return Ok(out);
|
||||
}
|
||||
let mut edges = false;
|
||||
let pieces = std::array::from_fn(|i| {
|
||||
let pieces: [Vec<Piece>; 3] = std::array::from_fn(|i| {
|
||||
let (full, rem) = (threads[i] / l[i], threads[i] % l[i]);
|
||||
let mut p = Pieces::chunks(0, full, l[i], rules.max_count[i]);
|
||||
let mut p = Vec::new();
|
||||
chunks(&mut p, 0, full, l[i], rules.max_count[i]);
|
||||
if rem > 0 {
|
||||
edges = true;
|
||||
p.edge = Some((full, 1, rem));
|
||||
p.push((full, 1, rem));
|
||||
}
|
||||
p
|
||||
});
|
||||
let out = product(pieces, edges)?;
|
||||
let fit = fit(rules, out.iter().map(|r| r.local))?;
|
||||
let locals: Vec<[u32; 3]> = out.iter().map(|r| r.local).collect();
|
||||
let fit = fit(rules, &locals)?;
|
||||
Ok(planned(out, threads, fit == Fit::EmulatedSimdgroups))
|
||||
}
|
||||
Dispatch::ThreadgroupsIndirect { .. } => {
|
||||
let fit = fit(rules, std::iter::once(l))?;
|
||||
let fit = fit(rules, &[l])?;
|
||||
let region = Region {
|
||||
local: l,
|
||||
groups: [0; 3],
|
||||
@@ -911,7 +779,7 @@ pub(crate) fn regions(
|
||||
multi: false,
|
||||
};
|
||||
Ok(planned(
|
||||
Regions::one(region),
|
||||
vec![region],
|
||||
[0; 3],
|
||||
fit == Fit::EmulatedSimdgroups,
|
||||
))
|
||||
@@ -971,23 +839,6 @@ impl BindingPlan {
|
||||
state: &BindState,
|
||||
dispatch: &Dispatch,
|
||||
) -> Result<DispatchCommands, BindError> {
|
||||
let mut commands = DispatchCommands::none();
|
||||
self.instantiate_dispatch_into(state, dispatch, &mut commands)?;
|
||||
Ok(commands)
|
||||
}
|
||||
|
||||
/// [`instantiate_dispatch`](Self::instantiate_dispatch)'s commands, written over `commands`:
|
||||
/// every field is set as `instantiate_dispatch` sets it, and the vectors (each region's
|
||||
/// specialization and push write's bytes, and the argument table's, among them) keep the
|
||||
/// storage the commands written there before left, so a consumer that keeps one
|
||||
/// `DispatchCommands` from dispatch to dispatch allocates none of it again once it holds as
|
||||
/// much. On an error `commands` holds no dispatch's commands.
|
||||
pub fn instantiate_dispatch_into(
|
||||
&self,
|
||||
state: &BindState,
|
||||
dispatch: &Dispatch,
|
||||
commands: &mut DispatchCommands,
|
||||
) -> Result<(), BindError> {
|
||||
let t = self.compute_template("instantiate_dispatch")?;
|
||||
let flat = self.variant.flat_grid;
|
||||
let ragged = Ragged::of(&self.variant);
|
||||
@@ -1019,9 +870,11 @@ impl BindingPlan {
|
||||
}
|
||||
// A folded variant's region reads its record.
|
||||
if self.variant.folded_groups {
|
||||
planned.regions.read_records();
|
||||
for r in &mut planned.regions {
|
||||
r.multi = true;
|
||||
}
|
||||
}
|
||||
instantiate(t, planned, (state, dispatch), records, commands)
|
||||
instantiate(t, planned, state, dispatch, records)
|
||||
}
|
||||
|
||||
/// Whether [`instantiate_dispatch`](Self::instantiate_dispatch)'s commands may read a value the
|
||||
@@ -1096,16 +949,10 @@ impl BindingPlan {
|
||||
});
|
||||
}
|
||||
// Every region record states the dispatch's region.
|
||||
planned.regions.read_records();
|
||||
let mut commands = DispatchCommands::none();
|
||||
instantiate(
|
||||
t,
|
||||
planned,
|
||||
(state, &dispatch),
|
||||
Records::Replay,
|
||||
&mut commands,
|
||||
)?;
|
||||
Ok(commands)
|
||||
for r in &mut planned.regions {
|
||||
r.multi = true;
|
||||
}
|
||||
instantiate(t, planned, state, &dispatch, Records::Replay)
|
||||
}
|
||||
|
||||
/// The variant of the pipeline a compute dispatch runs on: the plan's
|
||||
@@ -1221,39 +1068,14 @@ fn region_specialization(
|
||||
multi: bool,
|
||||
reach: bool,
|
||||
) -> SpecializationKey {
|
||||
let mut key = SpecializationKey::new();
|
||||
region_specialization_into(t, (local, multi, reach), &mut key);
|
||||
key
|
||||
}
|
||||
|
||||
/// [`region_specialization`]'s key of a region of `local` threads, `multi` and `reach`, written
|
||||
/// over `key` in the storage its lists hold ([`spec_key_into`]).
|
||||
///
|
||||
/// The template's fixed constants are the plan's value of every other constant of the layout, in
|
||||
/// the layout's order, each a function of its key alone (`plan::compute`): each is taken where the
|
||||
/// one before left off, and found from the start only where that one is another key's, so a
|
||||
/// region's key takes no search of them.
|
||||
fn region_specialization_into(
|
||||
t: &ComputeTemplate,
|
||||
(local, multi, reach): ([u32; 3], bool, bool),
|
||||
key: &mut SpecializationKey,
|
||||
) {
|
||||
let n: u64 = local.iter().map(|&x| u64::from(x)).product();
|
||||
let next = std::cell::Cell::new(0);
|
||||
let value = |k| match k {
|
||||
spec_key(&t.spec, |k| match k {
|
||||
SpecKey::LocalSize(a) => Some(u64::from(local[a as usize])),
|
||||
SpecKey::FlatLocalSize => Some(n),
|
||||
SpecKey::MultiRegion => Some(u64::from(multi)),
|
||||
SpecKey::StageInReach => Some(u64::from(reach)),
|
||||
other => match t.fixed.get(next.get()) {
|
||||
Some(&(at, v)) if at == other => {
|
||||
next.set(next.get() + 1);
|
||||
Some(v)
|
||||
}
|
||||
_ => t.fixed.iter().find(|(key, _)| *key == other).map(|f| f.1),
|
||||
},
|
||||
};
|
||||
spec_key_into(&t.spec, value, key);
|
||||
other => t.fixed.iter().find(|(key, _)| *key == other).map(|f| f.1),
|
||||
})
|
||||
}
|
||||
|
||||
/// The stride the compute encoder binds kernel buffer `index` with in `state`
|
||||
@@ -1399,27 +1221,13 @@ enum Records {
|
||||
/// The commands of `dispatch` planned as `planned`, whose region records and group counts
|
||||
/// `records` writes: for a device-replay variant (whose `dispatch` is the `ThreadgroupsIndirect` of
|
||||
/// its threadgroup size) the region reads the replay's arguments and no root table is built.
|
||||
/// Written over `out`: each of its fields set, its vectors cleared or their values overwritten in
|
||||
/// place (each region's specialization and push write, the argument table's bytes), never
|
||||
/// replaced. On an error `out` holds no dispatch's commands.
|
||||
fn instantiate(
|
||||
t: &ComputeTemplate,
|
||||
planned: Planned,
|
||||
(state, dispatch): (&BindState, &Dispatch),
|
||||
state: &BindState,
|
||||
dispatch: &Dispatch,
|
||||
records: Records,
|
||||
out: &mut DispatchCommands,
|
||||
) -> Result<(), BindError> {
|
||||
let DispatchCommands {
|
||||
regions: regions_out,
|
||||
descriptor_bytes,
|
||||
descriptor_ranges,
|
||||
extents,
|
||||
push_holes,
|
||||
region_record: region_record_out,
|
||||
root_table: root_table_out,
|
||||
indirect_clamp: indirect_clamp_out,
|
||||
uses,
|
||||
} = out;
|
||||
) -> Result<DispatchCommands, BindError> {
|
||||
let replay = records == Records::Replay;
|
||||
// A kernel that reads the stage-in region needs the encoder's.
|
||||
let region = match t.stage_in_region {
|
||||
@@ -1431,76 +1239,18 @@ fn instantiate(
|
||||
),
|
||||
};
|
||||
let (push_start, push_size) = t.push_range.unwrap_or((0, 0));
|
||||
let mut push = vec![0u8; push_size as usize];
|
||||
let mut table = vec![0u8; t.table.map_or(0, |(_, _, size)| size as usize)];
|
||||
let compute = vk::ShaderStageFlags::COMPUTE;
|
||||
// One region of the commands per planned region, each over the one a dispatch before left
|
||||
// at its place where there is one.
|
||||
let count = planned.regions.len();
|
||||
regions_out.truncate(count);
|
||||
while regions_out.len() < count {
|
||||
regions_out.push(DispatchRegion {
|
||||
specialization: SpecializationKey::new(),
|
||||
group_count: [0; 3],
|
||||
push_constants: Vec::new(),
|
||||
indirect: None,
|
||||
stage_flags: vk::PipelineShaderStageCreateFlags::empty(),
|
||||
required_subgroup_size: None,
|
||||
});
|
||||
}
|
||||
// Each region's one push write, where the plan pushes bytes.
|
||||
for r in regions_out.iter_mut() {
|
||||
let writes = &mut r.push_constants;
|
||||
writes.truncate(usize::from(push_size > 0));
|
||||
if push_size > 0 && writes.is_empty() {
|
||||
writes.push(PushConstantWrite {
|
||||
stages: compute,
|
||||
offset: push_start,
|
||||
bytes: Vec::new(),
|
||||
});
|
||||
}
|
||||
for w in writes.iter_mut() {
|
||||
w.stages = compute;
|
||||
w.offset = push_start;
|
||||
}
|
||||
}
|
||||
// The push bytes every region shares, written in the first region's write (a grid of no
|
||||
// region pushes none, and writes them apart), and the argument table, in the first
|
||||
// descriptor bytes.
|
||||
let mut apart = Vec::new();
|
||||
let push = match regions_out
|
||||
.first_mut()
|
||||
.and_then(|r| r.push_constants.first_mut())
|
||||
{
|
||||
Some(write) => zeroed(&mut write.bytes, push_size as usize),
|
||||
None => zeroed(&mut apart, push_size as usize),
|
||||
};
|
||||
descriptor_bytes.truncate(usize::from(t.table.is_some()));
|
||||
let mut no_table = Vec::new();
|
||||
let table = match t.table {
|
||||
Some((set, binding, size)) => {
|
||||
if descriptor_bytes.is_empty() {
|
||||
descriptor_bytes.push(DescriptorBytes {
|
||||
set,
|
||||
binding,
|
||||
bytes: Vec::new(),
|
||||
});
|
||||
}
|
||||
let written = &mut descriptor_bytes[0];
|
||||
written.set = set;
|
||||
written.binding = binding;
|
||||
zeroed(&mut written.bytes, size as usize)
|
||||
}
|
||||
None => &mut no_table,
|
||||
};
|
||||
|
||||
// Buffer slots: descriptor ranges and residuals, root entries, extents; texel buffers.
|
||||
descriptor_ranges.clear();
|
||||
extents.clear();
|
||||
let bound = bind_buffers(&t.buffers, state, descriptor_ranges, extents)?;
|
||||
let (mut descriptor_ranges, mut extents) = (Vec::new(), Vec::new());
|
||||
let bound = bind_buffers(&t.buffers, state, &mut descriptor_ranges, &mut extents)?;
|
||||
descriptor_ranges.extend(texel_ranges(&t.resources, state)?);
|
||||
|
||||
// The root table: the Psb entries and the resident set.
|
||||
push_holes.clear();
|
||||
*root_table_out = match t.root_first {
|
||||
let mut push_holes = Vec::new();
|
||||
let root_table = match t.root_first {
|
||||
// A replay variant's root table is its command's slot table.
|
||||
Some(_) if replay => None,
|
||||
Some(first) => {
|
||||
@@ -1557,23 +1307,13 @@ fn instantiate(
|
||||
field => slot_field(field, &bound.residuals, &t.resources, state)
|
||||
.ok_or_else(|| internal(format!("a compute push field {field:?}")))?,
|
||||
};
|
||||
put(push, push_start, table, f.loc, &bytes)?;
|
||||
put(&mut push, push_start, &mut table, f.loc, &bytes)?;
|
||||
}
|
||||
let region_field = t
|
||||
.fields
|
||||
.iter()
|
||||
.find(|f| f.field == PushField::DispatchRegion)
|
||||
.map(|f| f.loc);
|
||||
// Every later region's push bytes start as the first's.
|
||||
if let Some((first, rest)) = regions_out.split_first_mut() {
|
||||
if let Some(shared) = first.push_constants.first() {
|
||||
for r in rest {
|
||||
for w in &mut r.push_constants {
|
||||
w.bytes.clone_from(&shared.bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Regions.
|
||||
let Planned {
|
||||
@@ -1584,21 +1324,19 @@ fn instantiate(
|
||||
..
|
||||
} = planned;
|
||||
let reach = stage_in_reach(t, region, grid, state);
|
||||
for (r, out) in planned.iter().zip(regions_out.iter_mut()) {
|
||||
let mut regions = Vec::with_capacity(planned.len());
|
||||
for r in planned {
|
||||
let mut bytes = push.clone();
|
||||
if let Some(loc) = region_field {
|
||||
let b = match nonuniform {
|
||||
true => nonuniform_region_bytes(r.base, grid, nominal),
|
||||
false => region_bytes(r.base, grid, nominal),
|
||||
}
|
||||
.ok_or_else(|| internal("an unpackable nominal threadgroup size"))?;
|
||||
let bytes = match out.push_constants.first_mut() {
|
||||
Some(write) => &mut write.bytes[..],
|
||||
None => &mut [],
|
||||
};
|
||||
put(bytes, push_start, &mut [], loc, &b)?;
|
||||
put(&mut bytes, push_start, &mut [], loc, &b)?;
|
||||
}
|
||||
region_specialization_into(t, (r.local, r.multi, reach), &mut out.specialization);
|
||||
out.indirect = match *dispatch {
|
||||
let specialization = region_specialization(t, r.local, r.multi, reach);
|
||||
let indirect = match *dispatch {
|
||||
Dispatch::ThreadgroupsIndirect { .. } if replay => Some(IndirectArgs::Replay),
|
||||
Dispatch::ThreadgroupsIndirect { indirect, .. } => {
|
||||
Some(if records == Records::Binder && needs_clamp(&t.local) {
|
||||
@@ -1609,13 +1347,26 @@ fn instantiate(
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
out.group_count = r.groups;
|
||||
out.stage_flags = region_flags(&t.local, r.local);
|
||||
out.required_subgroup_size = t.local.required_subgroup_size;
|
||||
regions.push(DispatchRegion {
|
||||
specialization,
|
||||
group_count: r.groups,
|
||||
push_constants: if push_size == 0 {
|
||||
Vec::new()
|
||||
} else {
|
||||
vec![PushConstantWrite {
|
||||
stages: compute,
|
||||
offset: push_start,
|
||||
bytes,
|
||||
}]
|
||||
},
|
||||
indirect,
|
||||
stage_flags: region_flags(&t.local, r.local),
|
||||
required_subgroup_size: t.local.required_subgroup_size,
|
||||
});
|
||||
}
|
||||
|
||||
// A preprocess checks its group counts against the limit.
|
||||
*indirect_clamp_out = match *dispatch {
|
||||
let indirect_clamp = match *dispatch {
|
||||
Dispatch::ThreadgroupsIndirect { indirect, .. }
|
||||
if records == Records::Binder && needs_clamp(&t.local) =>
|
||||
{
|
||||
@@ -1634,7 +1385,7 @@ fn instantiate(
|
||||
// A direct dispatch on a flat variant reads its region from the record the consumer writes
|
||||
// (base 0, the dispatch's threadgroup size, and the grid in threads), since the flat lowering
|
||||
// reads the record by address wherever its group counts come from.
|
||||
*region_record_out = match (records, *dispatch) {
|
||||
let region_record = match (records, *dispatch) {
|
||||
(Records::Flat, Dispatch::ThreadgroupsIndirect { .. }) | (Records::Binder, _) => None,
|
||||
(Records::Flat, _) => Some(
|
||||
region_bytes([0; 3], grid, nominal)
|
||||
@@ -1642,32 +1393,54 @@ fn instantiate(
|
||||
),
|
||||
(Records::Replay, _) => None,
|
||||
};
|
||||
let mut descriptor_bytes = match t.table {
|
||||
Some((set, binding, _)) => vec![DescriptorBytes {
|
||||
set,
|
||||
binding,
|
||||
bytes: table,
|
||||
}],
|
||||
None => Vec::new(),
|
||||
};
|
||||
descriptor_bytes.extend(crate::bind::heap::table_bytes(&t.resources, state)?);
|
||||
uses.clear();
|
||||
if let Dispatch::ThreadgroupsIndirect { .. } = *dispatch {
|
||||
let (class, stages) = if indirect_clamp_out.is_some() {
|
||||
(
|
||||
AccessClass::Storage,
|
||||
vk::PipelineStageFlags2::COMPUTE_SHADER,
|
||||
)
|
||||
} else {
|
||||
(
|
||||
AccessClass::Indirect,
|
||||
vk::PipelineStageFlags2::DRAW_INDIRECT,
|
||||
)
|
||||
};
|
||||
uses.push(ResourceUse {
|
||||
resource: UseTarget::Indirect,
|
||||
access: AccessSet::READ,
|
||||
class,
|
||||
stages,
|
||||
range: Some(ByteRange {
|
||||
offset: 0,
|
||||
len: u64::from(IndirectClamp::SCRATCH_BYTES),
|
||||
}),
|
||||
});
|
||||
}
|
||||
Ok(())
|
||||
let uses = match *dispatch {
|
||||
Dispatch::ThreadgroupsIndirect { .. } => {
|
||||
let (class, stages) = if indirect_clamp.is_some() {
|
||||
(
|
||||
AccessClass::Storage,
|
||||
vk::PipelineStageFlags2::COMPUTE_SHADER,
|
||||
)
|
||||
} else {
|
||||
(
|
||||
AccessClass::Indirect,
|
||||
vk::PipelineStageFlags2::DRAW_INDIRECT,
|
||||
)
|
||||
};
|
||||
vec![ResourceUse {
|
||||
resource: UseTarget::Indirect,
|
||||
access: AccessSet::READ,
|
||||
class,
|
||||
stages,
|
||||
range: Some(ByteRange {
|
||||
offset: 0,
|
||||
len: u64::from(IndirectClamp::SCRATCH_BYTES),
|
||||
}),
|
||||
}]
|
||||
}
|
||||
Dispatch::Threadgroups { .. }
|
||||
| Dispatch::Threads { .. }
|
||||
| Dispatch::ThreadgroupRange { .. } => Vec::new(),
|
||||
};
|
||||
Ok(DispatchCommands {
|
||||
regions,
|
||||
descriptor_bytes,
|
||||
descriptor_ranges,
|
||||
extents,
|
||||
push_holes,
|
||||
region_record,
|
||||
root_table,
|
||||
indirect_clamp,
|
||||
uses,
|
||||
})
|
||||
}
|
||||
|
||||
/// Whether an indirect dispatch needs the clamp prepass: some axis of the device's group-count
|
||||
|
||||
@@ -268,115 +268,6 @@ fn dispatch_threads_edges_become_multi_region_dispatches() {
|
||||
.is_empty());
|
||||
}
|
||||
|
||||
/// `instantiate_dispatch_into` over commands a dispatch before left, of more regions, fewer, none,
|
||||
/// another state: each time the commands a fresh `instantiate_dispatch` gives, in the storage
|
||||
/// kept (a region's specialization written over a key of as many constants allocates nothing).
|
||||
#[test]
|
||||
fn instantiating_over_kept_commands_gives_a_fresh_instantiation() {
|
||||
let plan = compute_plan(&template(), VariantKey::new());
|
||||
let threads = |threads| Dispatch::Threads {
|
||||
threads,
|
||||
threads_per_group: [16, 2, 1],
|
||||
};
|
||||
let split = Dispatch::Threadgroups {
|
||||
groups: [70000, 1, 2],
|
||||
threads_per_group: [1, 1, 1],
|
||||
};
|
||||
let dispatches = [
|
||||
(threads([40, 3, 1]), 0),
|
||||
(threads([64, 4, 1]), 64),
|
||||
(split, 0),
|
||||
(threads([0, 4, 1]), 64),
|
||||
(threads([40, 3, 1]), 128),
|
||||
(threads([64, 4, 1]), 128),
|
||||
];
|
||||
let mut kept = plan
|
||||
.instantiate_dispatch(&state(0), &threads([64, 4, 1]))
|
||||
.expect("first");
|
||||
for (at, (d, offset)) in dispatches.into_iter().enumerate() {
|
||||
let s = state(offset);
|
||||
let data = kept.regions.first().map(|r| r.specialization.data.as_ptr());
|
||||
plan.instantiate_dispatch_into(&s, &d, &mut kept)
|
||||
.expect("into");
|
||||
let fresh = plan.instantiate_dispatch(&s, &d).expect("fresh");
|
||||
assert_eq!(kept, fresh, "dispatch {at}");
|
||||
// The first region's key, kept, is written in the storage it held.
|
||||
let first = kept.regions.first().map(|r| r.specialization.data.as_ptr());
|
||||
if let (Some(was), Some(now)) = (data, first) {
|
||||
assert_eq!(was, now, "dispatch {at}: the key's storage");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `instantiate_dispatch_into` over commands a dispatch of as many regions or more left allocates
|
||||
/// nothing: the regions are planned as numbers (`Regions`), and each region's key and push write,
|
||||
/// the ranges and the extents are written in the storage kept.
|
||||
#[test]
|
||||
fn instantiating_over_kept_commands_allocates_nothing() {
|
||||
use crate::tests::constant_blob_footprint::allocations_during;
|
||||
let plan = compute_plan(&template(), VariantKey::new());
|
||||
let ragged = Dispatch::Threads {
|
||||
threads: [40, 3, 1],
|
||||
threads_per_group: [16, 2, 1],
|
||||
};
|
||||
let whole = Dispatch::Threadgroups {
|
||||
groups: [4, 2, 1],
|
||||
threads_per_group: [16, 2, 1],
|
||||
};
|
||||
let mut kept = plan
|
||||
.instantiate_dispatch(&state(0), &ragged)
|
||||
.expect("first");
|
||||
assert_eq!(kept.regions.len(), 4, "the interior and three edges");
|
||||
for (at, (d, offset)) in [(ragged, 64), (ragged, 128), (whole, 192)]
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
{
|
||||
let s = state(offset);
|
||||
let (into, made) = allocations_during(|| plan.instantiate_dispatch_into(&s, &d, &mut kept));
|
||||
into.expect("into");
|
||||
assert_eq!(made, 0, "dispatch {at}: allocations");
|
||||
let fresh = plan.instantiate_dispatch(&s, &d).expect("fresh");
|
||||
assert_eq!(kept, fresh, "dispatch {at}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A region's key takes each fixed constant of the template where the walk of the layout left
|
||||
/// off, the order the planner lists them in, and finds one listed out of that order: the same key
|
||||
/// either way, each constant at its own value.
|
||||
#[test]
|
||||
fn a_regions_key_takes_its_fixed_constants_in_any_order() {
|
||||
let mut t = template();
|
||||
t.spec = vec![
|
||||
spec(0, SpecKey::LocalSize(Axis::X)),
|
||||
spec(1, SpecKey::TgLength(0)),
|
||||
spec(2, SpecKey::LocalSize(Axis::Y)),
|
||||
spec(3, SpecKey::TgLength(1)),
|
||||
spec(4, SpecKey::LocalSize(Axis::Z)),
|
||||
spec(5, SpecKey::MultiRegion),
|
||||
spec(6, SpecKey::TgLength(2)),
|
||||
];
|
||||
let fixed = [
|
||||
(SpecKey::TgLength(0), 16),
|
||||
(SpecKey::TgLength(1), 32),
|
||||
(SpecKey::TgLength(2), 48),
|
||||
];
|
||||
let d = Dispatch::Threadgroups {
|
||||
groups: [4, 2, 1],
|
||||
threads_per_group: [16, 2, 1],
|
||||
};
|
||||
let mut keys = Vec::new();
|
||||
for order in [[0, 1, 2], [2, 0, 1], [1, 2, 0]] {
|
||||
t.fixed = order.iter().map(|&i| fixed[i]).collect();
|
||||
let c = instantiate(&t, &state(0), &d).expect("one region");
|
||||
let key = c.regions[0].specialization.clone();
|
||||
let values: Vec<_> = (0..7).map(|id| spec_value(&key, id)).collect();
|
||||
let expected = [16, 16, 2, 32, 1, 0, 48].map(Some);
|
||||
assert_eq!(values, expected, "{order:?}");
|
||||
keys.push(key);
|
||||
}
|
||||
assert!(keys.windows(2).all(|k| k[0] == k[1]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn group_counts_above_the_limit_are_split_with_their_base() {
|
||||
let t = template();
|
||||
@@ -457,28 +348,25 @@ fn local_sizes_are_checked_against_every_d4_limit() {
|
||||
// A partial simdgroup runs on the emulated-simdgroups variant, whose local size is not
|
||||
// flattened: each axis and the product are checked, not `sn` and the subgroups.
|
||||
assert_eq!(
|
||||
fit(&r, std::iter::once([33, 1, 1])).expect("partial"),
|
||||
fit(&r, &[[33, 1, 1]]).expect("partial"),
|
||||
Fit::EmulatedSimdgroups
|
||||
);
|
||||
assert_eq!(fit(&r, &[[32, 1, 1]]).expect("full"), Fit::Planned);
|
||||
assert_eq!(
|
||||
fit(&r, std::iter::once([32, 1, 1])).expect("full"),
|
||||
Fit::Planned
|
||||
);
|
||||
assert_eq!(
|
||||
fit(&r, std::iter::once([1, 1, 1])).expect("one thread"),
|
||||
fit(&r, &[[1, 1, 1]]).expect("one thread"),
|
||||
Fit::EmulatedSimdgroups
|
||||
);
|
||||
r.max_subgroups = 1;
|
||||
assert_eq!(
|
||||
fit(&r, std::iter::once([60, 1, 1])).expect("the subgroup limit is the flattened tier's"),
|
||||
fit(&r, &[[60, 1, 1]]).expect("the subgroup limit is the flattened tier's"),
|
||||
Fit::EmulatedSimdgroups
|
||||
);
|
||||
let e = fit(&r, std::iter::once([1, 1, 65])).expect_err("z of a partial region");
|
||||
let e = fit(&r, &[[1, 1, 65]]).expect_err("z of a partial region");
|
||||
assert!(
|
||||
matches!(&e, BindError::Unsupported(u) if u.feature == Feature::LocalSize { axis: Some(Axis::Z) }),
|
||||
"{e:?}"
|
||||
);
|
||||
let e = fit(&r, std::iter::once([33, 33, 1])).expect_err("invocations of a partial region");
|
||||
let e = fit(&r, &[[33, 33, 1]]).expect_err("invocations of a partial region");
|
||||
assert!(
|
||||
matches!(&e, BindError::Unsupported(u) if u.feature == Feature::LocalSize { axis: None }),
|
||||
"{e:?}"
|
||||
@@ -486,27 +374,24 @@ fn local_sizes_are_checked_against_every_d4_limit() {
|
||||
// The whole dispatch runs on the variant, so every region of a dispatch with a partial one
|
||||
// is checked against the variant's limits, its whole-subgroup regions included: the z of
|
||||
// [1, 1, 96] is past them, and [1, 1, 64], past the flattened tier's subgroups, is not.
|
||||
let e = fit(&r, [[1, 1, 96], [1, 1, 4]].into_iter()).expect_err("z of a whole region");
|
||||
let e = fit(&r, &[[1, 1, 96], [1, 1, 4]]).expect_err("z of a whole region");
|
||||
assert!(
|
||||
matches!(&e, BindError::Unsupported(u) if u.feature == Feature::LocalSize { axis: Some(Axis::Z) }),
|
||||
"{e:?}"
|
||||
);
|
||||
assert!(
|
||||
fit(&r, std::iter::once([1, 1, 64])).is_err(),
|
||||
fit(&r, &[[1, 1, 64]]).is_err(),
|
||||
"two subgroups on the flattened tier"
|
||||
);
|
||||
assert_eq!(
|
||||
fit(&r, [[1, 1, 64], [1, 1, 36]].into_iter()).expect("mixed"),
|
||||
fit(&r, &[[1, 1, 64], [1, 1, 36]]).expect("mixed"),
|
||||
Fit::EmulatedSimdgroups
|
||||
);
|
||||
// Outside the flattened tiers a multiple is a derivative group's, and stays refused.
|
||||
let mut d4 = rules();
|
||||
d4.multiples = vec![4];
|
||||
assert_eq!(
|
||||
fit(&d4, std::iter::once([8, 1, 1])).expect("quads"),
|
||||
Fit::Planned
|
||||
);
|
||||
let e = fit(&d4, std::iter::once([6, 1, 1])).expect_err("a partial quad");
|
||||
assert_eq!(fit(&d4, &[[8, 1, 1]]).expect("quads"), Fit::Planned);
|
||||
let e = fit(&d4, &[[6, 1, 1]]).expect_err("a partial quad");
|
||||
assert!(
|
||||
matches!(&e, BindError::Unsupported(u) if u.feature == Feature::ComputeDerivatives),
|
||||
"{e:?}"
|
||||
@@ -1045,7 +930,7 @@ fn a_flat_region_counts_every_grid_thread_exactly_once() {
|
||||
assert_eq!(planned.regions.len(), 1, "{what}");
|
||||
assert_eq!(planned.grid, threads, "{what}");
|
||||
assert_eq!(planned.nominal, local, "{what}");
|
||||
let r = planned.regions.iter().next().expect("a region");
|
||||
let r = planned.regions[0];
|
||||
assert_eq!(r.local, local, "{what}");
|
||||
assert_eq!(r.base, [0; 3], "{what}");
|
||||
for (&count, &limit) in r.groups.iter().zip(&max_count) {
|
||||
|
||||
@@ -5446,7 +5446,7 @@ fn reused<T>(list: &mut Vec<T>, at: usize, made: impl FnOnce() -> T) -> &mut T {
|
||||
}
|
||||
|
||||
/// `bytes`, made `len` zero bytes in the storage it holds.
|
||||
pub(crate) fn zeroed(bytes: &mut Vec<u8>, len: usize) -> &mut Vec<u8> {
|
||||
fn zeroed(bytes: &mut Vec<u8>, len: usize) -> &mut Vec<u8> {
|
||||
bytes.clear();
|
||||
bytes.resize(len, 0);
|
||||
bytes
|
||||
|
||||
@@ -357,19 +357,6 @@ pub(crate) fn spec_key(
|
||||
value: impl Fn(SpecKey) -> Option<u64>,
|
||||
) -> SpecializationKey {
|
||||
let mut key = SpecializationKey::new();
|
||||
spec_key_into(layout, value, &mut key);
|
||||
key
|
||||
}
|
||||
|
||||
/// [`spec_key`]'s key, written over `key` in the storage its two lists hold: a key written over
|
||||
/// one of as many constants allocates nothing.
|
||||
pub(crate) fn spec_key_into(
|
||||
layout: &[SpecConstant],
|
||||
value: impl Fn(SpecKey) -> Option<u64>,
|
||||
key: &mut SpecializationKey,
|
||||
) {
|
||||
key.entries.clear();
|
||||
key.data.clear();
|
||||
for (at, c) in layout.iter().enumerate() {
|
||||
let Some(v) = value(c.key) else { continue };
|
||||
// Room for the rest of the layout at once, rather than growing a push at a time: a
|
||||
@@ -389,6 +376,7 @@ pub(crate) fn spec_key_into(
|
||||
key.data
|
||||
.extend_from_slice(&v.to_le_bytes()[..size as usize]);
|
||||
}
|
||||
key
|
||||
}
|
||||
|
||||
fn plan(p: &ComputePipeline, device: &Device, shape: &BindShape) -> Result<BindingPlan, BindError> {
|
||||
|
||||
Vendored
+1
-1
@@ -94,7 +94,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 525;
|
||||
/// changes no behaviour, and then updates that hash alone with the commit saying why, or changes
|
||||
/// behaviour and also bumps this version. The commit that bumps it says what changed; this comment
|
||||
/// keeps no history.
|
||||
pub const RUNTIME_VERSION: u32 = 2512;
|
||||
pub const RUNTIME_VERSION: u32 = 2520;
|
||||
|
||||
/// The digest of the sources this build of the crate was compiled from: SHA-256, as lowercase hex,
|
||||
/// of the manifest, the build script, and exactly the files the crate roots' module tree compiles
|
||||
|
||||
@@ -133,7 +133,7 @@ pub(crate) fn held_during<T>(work: impl FnOnce() -> T) -> (T, u64) {
|
||||
|
||||
/// `work`'s result, and the allocations and reallocations it made while it ran (the calling
|
||||
/// thread's).
|
||||
pub(crate) fn allocations_during<T>(work: impl FnOnce() -> T) -> (T, u64) {
|
||||
pub(super) fn allocations_during<T>(work: impl FnOnce() -> T) -> (T, u64) {
|
||||
let (value, counts) = measured(work);
|
||||
(value, counts.allocations)
|
||||
}
|
||||
|
||||
@@ -2977,7 +2977,6 @@ field metal2vulkan-runtime::WorkCounts.dispatch_uses_tracked pub dispatch_uses_t
|
||||
field metal2vulkan-runtime::WorkCounts.dispatches_from_set_aside pub dispatches_from_set_aside: u64
|
||||
field metal2vulkan-runtime::WorkCounts.dispatches_instantiated pub dispatches_instantiated: u64
|
||||
field metal2vulkan-runtime::WorkCounts.dispatches_instantiated_as_before pub dispatches_instantiated_as_before: u64
|
||||
field metal2vulkan-runtime::WorkCounts.dispatches_instantiated_in_place pub dispatches_instantiated_in_place: u64
|
||||
field metal2vulkan-runtime::WorkCounts.dispatches_planned_across_grids pub dispatches_planned_across_grids: u64
|
||||
field metal2vulkan-runtime::WorkCounts.dispatches_planned_as_before pub dispatches_planned_as_before: u64
|
||||
field metal2vulkan-runtime::WorkCounts.dispatches_pushing_set_zero pub dispatches_pushing_set_zero: u64
|
||||
@@ -9602,7 +9601,6 @@ method metal2vulkan::bind::BindingPlan::heap_elements pub fn heap_elements(&self
|
||||
method metal2vulkan::bind::BindingPlan::heap_slots pub fn heap_slots(&self) -> impl Iterator<Item = SlotRef> + '_
|
||||
method metal2vulkan::bind::BindingPlan::heap_tables_into pub fn heap_tables_into(&self, state: &BindState, tables: &mut Vec<crate::bind::instantiate::DescriptorBytes>) -> Result<(), BindError>
|
||||
method metal2vulkan::bind::BindingPlan::instantiate_dispatch pub fn instantiate_dispatch(&self, state: &BindState, dispatch: &Dispatch) -> Result<DispatchCommands, BindError>
|
||||
method metal2vulkan::bind::BindingPlan::instantiate_dispatch_into pub fn instantiate_dispatch_into(&self, state: &BindState, dispatch: &Dispatch, commands: &mut DispatchCommands) -> Result<(), BindError>
|
||||
method metal2vulkan::bind::BindingPlan::instantiate_draw pub fn instantiate_draw(&self, state: &BindState, draw: &DrawCall) -> Result<DrawCommands, BindError>
|
||||
method metal2vulkan::bind::BindingPlan::instantiate_draw_apart_into pub fn instantiate_draw_apart_into(&self, state: &BindState, draw: &DrawCall, commands: &mut DrawCommands) -> Result<(), BindError>
|
||||
method metal2vulkan::bind::BindingPlan::instantiate_draw_into pub fn instantiate_draw_into(&self, state: &BindState, draw: &DrawCall, commands: &mut DrawCommands) -> Result<(), BindError>
|
||||
|
||||
|
Can't render this file because it is too large.
|
+1
-4
@@ -1739,10 +1739,7 @@ reads the buffer's bytes inside the range.
|
||||
|
||||
`instantiate_draw_into` writes the same commands over a `DrawCommands` you keep, in the storage
|
||||
its vectors already hold: keep one from draw to draw (`DrawCommands::default()` to start) and the
|
||||
draws allocate none of it again once it holds as much. `instantiate_dispatch_into` does the same
|
||||
for a compute dispatch over a `DispatchCommands` you keep (one `instantiate_dispatch` made, to
|
||||
start): each region's specialization and push bytes, and the argument table's, are written in the
|
||||
storage the commands before held.
|
||||
draws allocate none of it again once it holds as much.
|
||||
|
||||
`dispatch_reads` says which slot classes' bound values, past their shape, a compute plan's
|
||||
`instantiate_dispatch` may read: buffer slots always; texture slots only where the plan binds a
|
||||
|
||||
+5
-1
@@ -216,7 +216,11 @@ known. The rest of the differences are docs/API.md section 9's precision notes.
|
||||
queue's burst (a long command buffer cut into parts, a backlog of frames) goes in behind about
|
||||
16 ms of it and one batch, not the whole burst, and from its submission on, while that queue
|
||||
keeps submitting there, behind about 2 ms and one batch of each busy queue. An unshared queue's
|
||||
batches are never held for their turn, and count as another queue's. The next batch goes in
|
||||
batches are never held for their turn, and count as another queue's. Only a command buffer's
|
||||
first batch takes a turn: its later batches (split at a mid-buffer event wait or signal) go as
|
||||
each is ready, as Metal schedules a command buffer whole, so a command buffer whose first batch
|
||||
waits on the GPU for a signal not yet given reads `Scheduled` at once, and another queue's
|
||||
command buffer waiting for its later signal goes at once too. The next batch goes in
|
||||
before the one ahead ends (the scheduler's thread woken at the completion that lets it go or
|
||||
makes its queue's batch whose run does so the oldest, and at the time that run brings the work
|
||||
left under the budget, no sleep slice's), so the GPU idles for the hold only
|
||||
|
||||
Reference in new issue
Block a user