Reset and mutable rasterization-rate maps, as Metal's GPU reads them
The steps this packet landed as, in order: - Read a YCbCr texture's 2D-array view as Metal's, and drop packed 4:4:4 writes - Name bfloat attachments in the unreached-tiles notice - Let go of each predicated loop run's sets and uploads once the run completed - Check that a lent descriptor arena takes every set and reuses its reset pools - Bump the semantics, artifact format and runtime versions for the eighth stack - Pin the runtime sources of the eighth stack - Bless the golden hash tables over the eighth stack Content: the tree of `development` at ee0b90d176, unchanged.
This commit is contained in:
1 parent
58338b04cd
commit
87eb8bc3b7
38 files changed
+2267
-431
No files matched your search
@@ -1827,6 +1827,12 @@ impl CommandBuffer {
|
||||
self.state().failures_injected = count;
|
||||
}
|
||||
|
||||
/// The bytes its upload arena's regions took: a device test's measure (`tests::rerun_arenas`).
|
||||
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
|
||||
pub(crate) fn upload_bytes(&self) -> u64 {
|
||||
self.state().uploads.bytes()
|
||||
}
|
||||
|
||||
/// Whether `waiting` holds this command buffer.
|
||||
pub(crate) fn is(&self, waiting: &dyn Waiting) -> bool {
|
||||
self.0.address() == waiting.address()
|
||||
@@ -2552,7 +2558,7 @@ impl CommandBuffer {
|
||||
.filter(|(_, prepared)| prepared.pipelines)
|
||||
.map(|((work, _), _)| work.clone())
|
||||
.collect();
|
||||
let (waits, away, reaches, unreplayable) = {
|
||||
let (waits, away, reaches, unreplayable, reset) = {
|
||||
let mut state = self.state();
|
||||
state.committing = false;
|
||||
if let Some(failure) = failure {
|
||||
@@ -2601,10 +2607,20 @@ impl CommandBuffer {
|
||||
}
|
||||
// A rebind before its first submission of a buffer its replayable encoders, or its
|
||||
// work on the GPU alone, named encodes or records them again (`reencode.rs`): noted
|
||||
// while their holds still refuse one.
|
||||
let (unreplayable, keys) = state.keep_replays();
|
||||
if !keys.is_empty() {
|
||||
device.shared().rebinds.wait_for_replay(&self.0, keys);
|
||||
// while their holds still refuse one. So does a reset of a rasterization-rate map
|
||||
// their passes are over (`rate_mapped_pass.rs`): noted first, then a reset before the
|
||||
// commit found here, marked before the scheduler sees the command buffer.
|
||||
let kept = state.keep_replays();
|
||||
if !kept.keys.is_empty() || !kept.maps.is_empty() {
|
||||
device
|
||||
.shared()
|
||||
.rebinds
|
||||
.wait_for_replay(&self.0, kept.keys, kept.maps);
|
||||
}
|
||||
let unreplayable = kept.gone;
|
||||
let reset = state.rate_maps_reset();
|
||||
if reset.0 {
|
||||
self.0.mark_reencode();
|
||||
}
|
||||
if let Some(slot) = &mut state.slot {
|
||||
slot.committed();
|
||||
@@ -2677,7 +2693,7 @@ impl CommandBuffer {
|
||||
.find(|image| image.rests_out_of_general());
|
||||
// Its commands may reach every texture through its resource ID where one bound a
|
||||
// heap set.
|
||||
(waits, away, state.heaps.bound(), unreplayable)
|
||||
(waits, away, state.heaps.bound(), unreplayable, reset)
|
||||
};
|
||||
// Each making the batches wait for wakes the scheduler as it finishes, with no lock
|
||||
// held (`render/pending.rs`), registered before the scheduler first looks at the batches:
|
||||
@@ -2703,6 +2719,16 @@ impl CommandBuffer {
|
||||
.shared()
|
||||
.scheduler
|
||||
.commit(&self.0, self.0.queue.id(), waits);
|
||||
// Its passes that took a rasterization-rate map since reset, encoded again in this call
|
||||
// as a reset's are; its first submission waits for them (marked above). Those it cannot
|
||||
// encode again are announced.
|
||||
let (again, unencoded) = reset;
|
||||
if again {
|
||||
self.0.reencode();
|
||||
}
|
||||
for unlogged in unencoded {
|
||||
crate::rate_mapped_pass::degrade_unencoded(device, unlogged);
|
||||
}
|
||||
if let Some(image) = away {
|
||||
device.degrade(Degradation::WrappedImageLayoutTransitions, || {
|
||||
image.notice()
|
||||
|
||||
@@ -91,6 +91,9 @@ impl CommandBufferShared {
|
||||
let device = &self.device;
|
||||
// The encoders of its event groups not submitted yet: those before were judged, and run
|
||||
// over the pages they took.
|
||||
// So are those whose pass took a rasterization-rate map since reset; one that kept no
|
||||
// log draws by the map as it took it, announced (`rate_mapped_pass.rs`).
|
||||
let mut unencoded = Vec::new();
|
||||
let moved: Vec<(usize, Arc<Replay>)> = {
|
||||
let state = lock(&self.state);
|
||||
match state.finished() {
|
||||
@@ -103,15 +106,23 @@ impl CommandBufferShared {
|
||||
(state.ended.iter().enumerate())
|
||||
.filter(|(at, _)| open.contains(at))
|
||||
.filter_map(|(at, record)| {
|
||||
let replay = record.replay.as_ref()?;
|
||||
submitting
|
||||
.rebound(&record.taken)
|
||||
.then(|| (at, Arc::clone(replay)))
|
||||
let reset = record.taken.rate_map_reset();
|
||||
let Some(replay) = record.replay.as_ref() else {
|
||||
if reset {
|
||||
unencoded.push(record.unlogged);
|
||||
}
|
||||
return None;
|
||||
};
|
||||
let moved = submitting.rebound(&record.taken) || reset;
|
||||
moved.then(|| (at, Arc::clone(replay)))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
};
|
||||
for unlogged in unencoded {
|
||||
crate::rate_mapped_pass::degrade_unencoded(device, unlogged);
|
||||
}
|
||||
let handle = CommandBuffer(Arc::clone(self));
|
||||
// The encoders encoded again, whose segments the encoding again recorded.
|
||||
let mut spliced = Vec::new();
|
||||
@@ -123,7 +134,14 @@ impl CommandBufferShared {
|
||||
Ok(replayed) => replayed,
|
||||
Err(error) => {
|
||||
counts.reencode_refused();
|
||||
lock(&self.state).ended[at].refused = Some(error.to_string());
|
||||
let reset = {
|
||||
let mut state = lock(&self.state);
|
||||
state.ended[at].refused = Some(error.to_string());
|
||||
state.ended[at].taken.rate_map_reset()
|
||||
};
|
||||
if reset {
|
||||
crate::rate_mapped_pass::degrade_unencoded(device, None);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
};
|
||||
@@ -138,8 +156,15 @@ impl CommandBufferShared {
|
||||
Err(unspliced) => {
|
||||
counts.reencode_refused();
|
||||
let refusal = "its place holds other parts or work than its encoding again's";
|
||||
lock(&self.state).ended[at].refused = Some(refusal.to_owned());
|
||||
let reset = {
|
||||
let mut state = lock(&self.state);
|
||||
state.ended[at].refused = Some(refusal.to_owned());
|
||||
state.ended[at].taken.rate_map_reset()
|
||||
};
|
||||
drop(unspliced);
|
||||
if reset {
|
||||
crate::rate_mapped_pass::degrade_unencoded(device, None);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -396,16 +421,20 @@ impl State {
|
||||
/// of without this lock: every log where an encoder used command predication, and those of
|
||||
/// encoders the commit's failure fails (they run nothing). The keys of buffers over host pages
|
||||
/// the encoders whose logs stay named, and the work its commit recorded on the GPU alone,
|
||||
/// sorted, each once (`Rebinds::wait_for_replay`).
|
||||
pub(super) fn keep_replays(&mut self) -> (Vec<Arc<Replay>>, Box<[ResourceKey]>) {
|
||||
/// sorted, each once, and the identities of the rasterization-rate maps its encoders' passes
|
||||
/// are over, logged or not (a reset encodes the one again, or announces the other:
|
||||
/// `Rebinds::wait_for_replay`).
|
||||
pub(super) fn keep_replays(&mut self) -> KeptReplays {
|
||||
let mut gone = Vec::new();
|
||||
let mut keys = Vec::new();
|
||||
let mut maps = Vec::new();
|
||||
let predicated = self.predicated;
|
||||
for (at, record) in self.ended.iter_mut().enumerate() {
|
||||
let fails = self
|
||||
.failed_at_commit
|
||||
.as_ref()
|
||||
.is_some_and(|failed| failed.fails(at));
|
||||
maps.extend(record.taken.rate_map_id());
|
||||
if predicated || fails {
|
||||
if let Some(log) = record.replay.take() {
|
||||
gone.push(log);
|
||||
@@ -429,6 +458,42 @@ impl State {
|
||||
}
|
||||
keys.sort_unstable();
|
||||
keys.dedup();
|
||||
(gone, keys.into_boxed_slice())
|
||||
maps.sort_unstable();
|
||||
maps.dedup();
|
||||
KeptReplays {
|
||||
gone,
|
||||
keys: keys.into_boxed_slice(),
|
||||
maps: maps.into_boxed_slice(),
|
||||
}
|
||||
}
|
||||
|
||||
/// As it commits, once its replays are kept ([`State::keep_replays`]): whether an encoder
|
||||
/// whose pass took a rasterization-rate map since reset, before the commit, is to be encoded
|
||||
/// again before its first submission, its log kept (`rate_mapped_pass.rs`); and why each that
|
||||
/// kept no log did not, which draws by the map as it took it, for the caller to announce
|
||||
/// without this lock (`rate-map-reset-unencoded`).
|
||||
pub(super) fn rate_maps_reset(&self) -> (bool, Vec<Option<Unlogged>>) {
|
||||
let mut again = false;
|
||||
let mut unencoded = Vec::new();
|
||||
for record in &self.ended {
|
||||
if !record.taken.rate_map_reset() {
|
||||
continue;
|
||||
}
|
||||
match record.replay {
|
||||
Some(_) => again = true,
|
||||
None => unencoded.push(record.unlogged),
|
||||
}
|
||||
}
|
||||
(again, unencoded)
|
||||
}
|
||||
}
|
||||
|
||||
/// What [`State::keep_replays`] keeps and lets go of.
|
||||
pub(super) struct KeptReplays {
|
||||
/// The logs no rebind encodes again, for the caller to let go of without the lock.
|
||||
pub(super) gone: Vec<Arc<Replay>>,
|
||||
/// The keys of the buffers over host pages the kept logs' encoders named.
|
||||
pub(super) keys: Box<[ResourceKey]>,
|
||||
/// The identities of the rasterization-rate maps its encoders' passes are over.
|
||||
pub(super) maps: Box<[usize]>,
|
||||
}
|
||||
@@ -23,9 +23,10 @@
|
||||
//! wrote: an indirect dispatch's arguments, an execution's records or its block's counter), waits
|
||||
//! for them too, then records it again as its host step did (`Deferred::step`), or as the commit
|
||||
//! did on the GPU alone (`Deferred::record_on_gpu`), and goes on. Those recordings come from a
|
||||
//! command pool of the check's own, taken back after each run again, so a loop that runs on
|
||||
//! holds no more command buffers than one run; the descriptor sets and uploads they take stay
|
||||
//! with the command buffer until it completes, as its first run's do.
|
||||
//! command pool of the check's own, and take their descriptor sets and uploads from arenas of
|
||||
//! its own, lent to the command buffer meanwhile ([`RunArenas`]); once the run again completed,
|
||||
//! the pool is taken back, the sets' pools reset and the uploads let go (their chunks parked
|
||||
//! for the next run, `recycle.rs`), so a loop that runs on holds no more of them than one run.
|
||||
//! - **The check** is a host step (`Deferred::Loop`), its segment the first of the batch after the
|
||||
//! laying: once the work before it completed, it reads the unit's halt word. 0: the batch goes.
|
||||
//! Else a thread of its own ([`run_again`]) runs the laying again on the command buffer's
|
||||
@@ -49,6 +50,7 @@ use super::{
|
||||
command_pool, recording_error, step_error, submission_error, CommandBuffer, CommandBufferShared,
|
||||
};
|
||||
use crate::deferred::{Deferred, StepInputs};
|
||||
use crate::descriptor_arena::DescriptorArena;
|
||||
use crate::device::lock;
|
||||
use crate::encoder::{Recorded, RecordedSegment, Segment};
|
||||
use crate::error::{internal, CommandBufferError, Error};
|
||||
@@ -56,7 +58,7 @@ use crate::exit_guard::{self, Call};
|
||||
use crate::retained::Retained;
|
||||
use crate::spares::CommandPool;
|
||||
use crate::tracker::EncoderUses;
|
||||
use crate::upload::Upload;
|
||||
use crate::upload::{Upload, Uploads};
|
||||
use ash::vk;
|
||||
use metal2vulkan::bind::ReplayFaults;
|
||||
use std::sync::atomic::Ordering;
|
||||
@@ -74,6 +76,41 @@ pub(crate) enum Piece {
|
||||
Apart(Deferred),
|
||||
}
|
||||
|
||||
/// The arenas a check's runs again take their descriptor sets and uploads from, each lent to the
|
||||
/// command buffer while a run's work apart records (`Uploads::lend`, `DescriptorArena::lend`),
|
||||
/// and emptied once the run completed ([`settle`](Self::settle)).
|
||||
struct RunArenas {
|
||||
uploads: Arc<Mutex<Uploads>>,
|
||||
descriptors: Arc<Mutex<DescriptorArena>>,
|
||||
}
|
||||
|
||||
impl RunArenas {
|
||||
/// Empty arenas.
|
||||
fn new() -> RunArenas {
|
||||
RunArenas {
|
||||
uploads: Arc::new(Mutex::new(Uploads::new())),
|
||||
descriptors: Arc::new(Mutex::new(DescriptorArena::default())),
|
||||
}
|
||||
}
|
||||
|
||||
/// Lend the arenas to the command buffer of `state`, or (`false`) take them back.
|
||||
fn lend(&self, state: &mut super::State, lent: bool) {
|
||||
state.uploads.lend(lent.then(|| Arc::clone(&self.uploads)));
|
||||
state
|
||||
.descriptors
|
||||
.lend(lent.then(|| Arc::clone(&self.descriptors)));
|
||||
}
|
||||
|
||||
/// The run again completed, so nothing uses what it took: the sets' pools reset for the next
|
||||
/// run, and the uploads let go, without a lock of the command buffer (a chunk's last holder
|
||||
/// parks it, `recycle.rs`). Inside a section of the exit guard; refused as the reset is.
|
||||
fn settle(&self) -> Result<(), Error> {
|
||||
let uploads = lock(&self.uploads).take();
|
||||
drop(uploads);
|
||||
lock(&self.descriptors).reset()
|
||||
}
|
||||
}
|
||||
|
||||
/// How a run again records a piece of work apart: as its first run did.
|
||||
enum Again {
|
||||
/// As its host step did, from `inputs`, after the work before it completed where `waits`.
|
||||
@@ -214,15 +251,15 @@ impl LoopCheck {
|
||||
Ok(nothing())
|
||||
}
|
||||
|
||||
/// Run the laying again on `buffer`'s `VkQueue`, its work apart recorded from `pool`, and
|
||||
/// read the halt word.
|
||||
/// Run the laying again on `buffer`'s `VkQueue`, its work apart recorded from `pool` and
|
||||
/// `arenas`, and read the halt word.
|
||||
fn run_once(
|
||||
&self,
|
||||
buffer: &Hold<CommandBufferShared>,
|
||||
pool: &Arc<Mutex<CommandPool>>,
|
||||
(pool, arenas): (&Arc<Mutex<CommandPool>>, &RunArenas),
|
||||
) -> Round {
|
||||
let mut recordings = Vec::new();
|
||||
let ran = self.run_pieces(buffer, pool, &mut recordings);
|
||||
let ran = self.run_pieces(buffer, (pool, arenas), &mut recordings);
|
||||
// Its recordings' command buffers go back to the pool for the next run: they ended there,
|
||||
// none of the command buffer's own pool (`CommandBufferShared::end_raw` counted them).
|
||||
let ended: usize = recordings.iter().map(|done| done.raws.len()).sum();
|
||||
@@ -245,6 +282,14 @@ impl LoopCheck {
|
||||
Err(Stop::Failed(error)) => return Round::Failed(error),
|
||||
Err(Stop::Exiting) => return Round::Exiting,
|
||||
}
|
||||
{
|
||||
let Some(_busy) = exit_guard::enter() else {
|
||||
return Round::Exiting;
|
||||
};
|
||||
if let Err(error) = arenas.settle() {
|
||||
return Round::Failed(recording_error(&buffer.device, error));
|
||||
}
|
||||
}
|
||||
buffer.device.shared().counts.predicated_loop_ran_again();
|
||||
match self.halted() {
|
||||
true => Round::Again,
|
||||
@@ -258,7 +303,7 @@ impl LoopCheck {
|
||||
fn run_pieces(
|
||||
&self,
|
||||
buffer: &Hold<CommandBufferShared>,
|
||||
pool: &Arc<Mutex<CommandPool>>,
|
||||
sources: (&Arc<Mutex<CommandPool>>, &RunArenas),
|
||||
recordings: &mut Vec<RecordedSegment>,
|
||||
) -> Result<(), Stop> {
|
||||
let device = &buffer.device;
|
||||
@@ -278,7 +323,7 @@ impl LoopCheck {
|
||||
self.submit(buffer, &submits)?;
|
||||
submits.clear();
|
||||
}
|
||||
let done = self.record(buffer, pool, work, again)?;
|
||||
let done = self.record(buffer, sources, work, again)?;
|
||||
submits.extend(&done.raws);
|
||||
recordings.push(done);
|
||||
}
|
||||
@@ -287,12 +332,13 @@ impl LoopCheck {
|
||||
self.submit(buffer, &submits)
|
||||
}
|
||||
|
||||
/// Record `work` again as `again` says, its command buffers from `pool`, as a host step: on
|
||||
/// this thread, inside a section of the exit guard, with no lock of the command buffer held.
|
||||
/// Record `work` again as `again` says, its command buffers from `pool` and its sets and
|
||||
/// uploads from `arenas`, as a host step: on this thread, inside a section of the exit guard,
|
||||
/// with no lock of the command buffer held.
|
||||
fn record(
|
||||
&self,
|
||||
buffer: &Hold<CommandBufferShared>,
|
||||
pool: &Arc<Mutex<CommandPool>>,
|
||||
(pool, arenas): (&Arc<Mutex<CommandPool>>, &RunArenas),
|
||||
work: &Deferred,
|
||||
again: &Again,
|
||||
) -> Result<RecordedSegment, Stop> {
|
||||
@@ -302,7 +348,11 @@ impl LoopCheck {
|
||||
};
|
||||
let _turn = lock(&buffer.reencoding);
|
||||
let command_buffer = CommandBuffer(Arc::clone(buffer));
|
||||
lock(&buffer.state).rerun_pool = Some(Arc::clone(pool));
|
||||
{
|
||||
let mut state = lock(&buffer.state);
|
||||
state.rerun_pool = Some(Arc::clone(pool));
|
||||
arenas.lend(&mut state, true);
|
||||
}
|
||||
let record = || {
|
||||
exit_guard::host_step(|| match again {
|
||||
Again::OnGpu => (work.record_on_gpu(&command_buffer)?)
|
||||
@@ -317,6 +367,7 @@ impl LoopCheck {
|
||||
};
|
||||
let mut state = lock(&buffer.state);
|
||||
state.rerun_pool = None;
|
||||
arenas.lend(&mut state, false);
|
||||
match recorded {
|
||||
// Its first run named no detached buffer, or the command buffer failed there.
|
||||
Ok(done) if done.taken.dead() => {
|
||||
@@ -454,16 +505,21 @@ fn run_again(check: &LoopCheck, buffer: Hold<CommandBufferShared>) {
|
||||
};
|
||||
command_pool(device, family).map(|pool| Arc::new(Mutex::new(pool)))
|
||||
};
|
||||
let arenas = RunArenas::new();
|
||||
let (failure, settled) = match &pool {
|
||||
Ok(pool) => loop {
|
||||
let round = before_round(&buffer).unwrap_or_else(|| check.run_once(&buffer, pool));
|
||||
let round =
|
||||
before_round(&buffer).unwrap_or_else(|| check.run_once(&buffer, (pool, &arenas)));
|
||||
match round {
|
||||
Round::Again => continue,
|
||||
Round::Ended => break (None, true),
|
||||
// A recording it left unended leaves the pool to be reset.
|
||||
Round::Failed(error) => break (Some(error), false),
|
||||
// What it holds stays held to the process's end, as the scheduler's does.
|
||||
Round::Exiting => return std::mem::forget(buffer),
|
||||
Round::Exiting => {
|
||||
std::mem::forget(arenas);
|
||||
return std::mem::forget(buffer);
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(error) => (Some(recording_error(device, error.clone())), true),
|
||||
|
||||
Reference in new issue
Block a user