Footprints: a completed command buffer lets go of its batches' kept footprints A batch's kept footprint (CommandBufferShared::footprints) holds a probe of each of its segments (SegmentProbe), and each probe holds a clone of the segment's work (Deferred) and of a Rerecord step input. The command buffer moves every segment's work into what it retained at its batch's submission (State::place) or at its completion (State::unplaced) and lets go of that as it completes, but the kept footprints stayed until the CommandBuffer was dropped. So a program that keeps a completed command buffer, as Metal programs keep a completed MTLCommandBuffer to read its status, error and GPU times, kept the work of every segment whose batch's footprint the scheduler had kept: a staged scatter's (its staging region of the arena and the RAM's use), a splice's (its arena regions and its merges' scratch), an execution's, a render pass's and a loop's check's among them. Nothing asks for a footprint once the command buffer completed: the scheduler asks only of the batches it holds. The release lets go of them now (Footprints::let_go), after its completed handlers and before what it retained, each popped under the leaf lock and dropped without it, as retained is. Verified: the device test tests::host_ram_copy_device::a_kept_completed_command_buffer_holds_nothing_of_its_staged_scatter failed without this on lavapipe (msi job m3-max-36825: alive after its completion 2, kept footprints' probes 1, after its drop 0; a staging of 163840 bytes). It now also asserts no kept probe after the completion; the run with this change is reported with the tip. Sparse updates: a completed command buffer lets go of its resource state encoders' updates A resource state encoder's part keeps its updates (SparseUpdate: the textures a mapping or a move names, and an indirect update's buffer) after its batch's submission bound them: that submission clones them for the bind, and the part held them until the CommandBuffer was dropped, so a program that keeps a completed command buffer kept those textures and that buffer, where Metal lets go of what a command buffer used as it completes. Nothing reads a part's updates after its batch's submission (the steps, the footprint, the fold and storage-form checks and an encoding again all come before it). The release takes them out of the parts under the state's lock and drops them without it, after the completed handlers, beside the kept footprints. Verified: see the tip report (the device test tests::kept_sparse_updates::a_kept_completed_command_buffer_holds_no_texture_its_mapping_update_names run at the commit before this one and at this one). Runtime tests: a kept completed command buffer's staged scatter, measured A device test of the case: a program keeps a completed command buffer (as a Metal program keeps a completed MTLCommandBuffer to read its status, error and GPU times) whose blit encoder staged a scatter into a guest RAM through the CPU (host_ram/copy.rs's StagedScatter: its staging region of the arena, as long as the copy's bytes, and the RAM's use). It holds a weak reference to each segment's work, taken before the commit (CommandBuffer::segment_works, a device test's view, through Deferred::weak), and asserts none is alive once the command buffer completed, while the program still holds it; it prints how many are, how many segments the batches' kept footprints probe (CommandBuffer::kept_footprint_probes), and how many are alive once it is dropped. Verified: not yet run; this commit is the measurement. Runtime tests: name the work's type in Deferred::weak's downgrade Verified: the measurement job m3-max-36816 failed to compile without it (E0308). Runtime tests: a kept completed command buffer's mapping update, measured A device test of a resource state encoder's update: a mapping of every tile of a sparse texture the program let go of once it encoded the mapping, its command buffer kept after it completed. It asserts the texture's handles' retain is gone once the command buffer completed, while the program still holds it, and prints the retain's and the texture object's holds after the completion and after the drop. Verified: not run at this commit alone; the job that runs it here and with the fix after it is reported with that fix. Verified: m3-max-36850 (msi, lavapipe) at 006565aff9: clippy --cfg m2v_cpu_icd 0; the scatter test (alive after completion 0, kept probes 0) and the sparse test ((0, 0) after completion) pass; footprint families 177/177; the sparse control at 02b1234c4d fails ((1, 1) after completion); the scatter control m3-max-36825 fails (alive 2, probes 1). Clippy plain and --cfg m2v_gpu and rustdoc run after the merge.
991 lines
50 KiB
Rust
991 lines
50 KiB
Rust
//! The work an encoder leaves to record later: what one segment of it records (`encoder.rs`). Each
|
|
//! kind states what `commit` makes of it, whether the GPU may write what it reads (so a host step
|
|
//! records it once the work before it completed, `scheduler`), how that step records it, and what
|
|
//! the device announces for the step. The command buffer handles every kind alike
|
|
//! (`command_buffer`).
|
|
|
|
use super::command_buffer::rerun::LoopCheck;
|
|
use super::command_buffer::CommandBuffer;
|
|
use super::commit_times::{self, Phase};
|
|
use super::device::lock;
|
|
use super::encoder::RecordedSegment;
|
|
use super::error::{internal, Error};
|
|
use super::gpu_execute::{self, Rerecord};
|
|
use super::host_ram::copy::{StagedGather, StagedScatter};
|
|
use super::indirect_dispatch::ArgumentDispatch;
|
|
use super::indirect_execute::{self, Execute, Settled, Unforeseen};
|
|
use super::pass_runs::RunMerge;
|
|
use super::pending_dispatch::PendingDispatch;
|
|
use super::pipeline::ComputePipelineState;
|
|
use super::render::DeferredPass;
|
|
use super::resource::ResourceKey;
|
|
use super::shadow::GatedCopyIn;
|
|
use super::shadow_splice::ShadowSplices;
|
|
use super::sparse::emulated::Scrub;
|
|
use super::tracker::{EncoderUses, Summary, Use};
|
|
use super::Device;
|
|
use super::IndirectCommandBuffer;
|
|
use crate::pipeline::budget::Urgency;
|
|
use std::any::Any;
|
|
use std::sync::Arc;
|
|
|
|
/// Work an encoder left to record later: one segment's.
|
|
#[derive(Clone)]
|
|
pub(super) enum Deferred {
|
|
/// An indirect command buffer's execution (`indirect_execute.rs`).
|
|
Execute(Arc<Execute>),
|
|
/// An indirect dispatch, whose arguments the GPU may write (`indirect_dispatch.rs`).
|
|
Dispatch(Arc<ArgumentDispatch>),
|
|
/// The scrub of a blit's or a render pass's writes of a sparse texture the runtime zeroes
|
|
/// (`sparse/emulated.rs`): neither `commit` nor a host step records it, but its batch's
|
|
/// submission, with the mappings the batch applied.
|
|
SparseScrub(Arc<Scrub>),
|
|
/// A shadow's copy in over host pages a consumer logs, whose regions the log decides: as with
|
|
/// a scrub, neither `commit` nor a host step records it, but its batch's submission, once the
|
|
/// commit's stamp is published (`shadow::GatedCopyIn`, `dirty_pages.rs`).
|
|
GatedCopyIn(Arc<GatedCopyIn>),
|
|
/// The merge of a run's pass over a linear attachment rendered apart, or over a shadowed
|
|
/// texture merged back (`pass_runs.rs`): as with a scrub, neither `commit` nor a host step
|
|
/// records it, but its batch's submission, unless a later pass of the run took it over.
|
|
RunMerge(Arc<RunMerge>),
|
|
/// A render pass that executes render commands (`render/executions.rs`).
|
|
RenderPass(Arc<DeferredPass>),
|
|
/// A compute encoder's dispatch whose pipelines were being made (`pending_dispatch.rs`).
|
|
Pending(Arc<PendingDispatch>),
|
|
/// The check after a predicated loop's laying, which runs it again while the loop would run
|
|
/// on (`command_buffer/rerun.rs`): it records nothing, and its batch waits for it.
|
|
Loop(Arc<LoopCheck>),
|
|
/// A gather from a guest RAM staged through the CPU (`host_ram/copy.rs`,
|
|
/// [`StagedGather::stage`]): its batch's host step takes the staging, fills it by the CPU and
|
|
/// records the GPU's copy from it, so the staging's memory is not made on the encoding thread;
|
|
/// it waits for the work before it only where the GPU may write the pages it reads.
|
|
GatherStage(Arc<StagedGather>),
|
|
/// A scatter into a guest RAM staged through the CPU, its GPU's copy into the staging
|
|
/// (`host_ram/copy.rs`, [`StagedScatter::stage`]): its batch's host step records it, waiting
|
|
/// for no work on the GPU, so the staging's memory is not made on the encoding thread.
|
|
ScatterStage(Arc<StagedScatter>),
|
|
/// The same scatter's CPU copy from the staging into the pages
|
|
/// ([`StagedScatter::drain`]): the host step of a batch of its own records nothing, once the
|
|
/// work before it completed.
|
|
ScatterDrain(Arc<StagedScatter>),
|
|
/// The CPU's part of an encoder's copies back spliced and merges on the host at one place
|
|
/// (`shadow_splice.rs`, [`ShadowSplices::drain`]): its texels' bytes in lines the GPU's
|
|
/// copies left, copied from the arena into the pages, and the bytes its merges' commands
|
|
/// changed, stored there, by the host step of a batch of its own, which records nothing,
|
|
/// once the work before it completed.
|
|
ShadowSplice(Arc<ShadowSplices>),
|
|
}
|
|
|
|
// SAFETY: a `Deferred` holds one `Arc` of its variant's work, which is `Send` and `Sync` for every
|
|
// work that is both; the constant below makes the compiler prove that of each variant's work, its
|
|
// match naming every variant (one added fails it until its work is proved too), so these impls
|
|
// claim nothing it does not check. Written out, they end the compiler's walk of a segment's work
|
|
// where a program's crate proves its own objects' `Send` and `Sync`: the walk from an encoder's
|
|
// segments down the work's types runs past rustc's default recursion limit
|
|
// (`recursion_depth_exceeding_limit`), which a program's crate keeps
|
|
// (`tests/consumer_auto_traits.rs`).
|
|
unsafe impl Send for Deferred {}
|
|
// SAFETY: as for `Send` above.
|
|
unsafe impl Sync for Deferred {}
|
|
|
|
// The compiler's proof of what `Deferred`'s `Send` and `Sync` impls rest on: each variant's work.
|
|
const _: fn(&Deferred) = |work| {
|
|
fn shared<T: Send + Sync>(_: &T) {}
|
|
match work {
|
|
Deferred::Execute(work) => shared(work),
|
|
Deferred::Dispatch(work) => shared(work),
|
|
Deferred::SparseScrub(work) => shared(work),
|
|
Deferred::GatedCopyIn(work) => shared(work),
|
|
Deferred::RunMerge(work) => shared(work),
|
|
Deferred::RenderPass(work) => shared(work),
|
|
Deferred::Pending(work) => shared(work),
|
|
Deferred::Loop(work) => shared(work),
|
|
Deferred::GatherStage(work) => shared(work),
|
|
Deferred::ScatterStage(work) => shared(work),
|
|
Deferred::ScatterDrain(work) => shared(work),
|
|
Deferred::ShadowSplice(work) => shared(work),
|
|
}
|
|
};
|
|
|
|
/// What `commit` left a segment for its host step.
|
|
#[derive(Clone)]
|
|
pub(super) enum StepInputs {
|
|
/// An execution's: the pipeline states its records may name, as `commit` settled them.
|
|
Settled(Vec<ComputePipelineState>),
|
|
/// An execution `commit` recorded from the CPU's records, which its buffer watches for a host
|
|
/// step `commit` did not foresee (`indirect_execute::Unforeseen`).
|
|
Unforeseen(Arc<Unforeseen>),
|
|
/// An indirect dispatch's: nothing past the work itself, which holds the encoder's tables.
|
|
/// And a dispatch's whose pipelines were being made, which holds its recording.
|
|
Dispatch,
|
|
/// A scrub's: none, as it has no host step.
|
|
None,
|
|
/// A render pass's: nothing past the pass itself, which holds the encoder's state at each
|
|
/// execution; its step names states among those alive then, and compiles only what `commit`
|
|
/// could not settle (`DeferredPass::settle`).
|
|
RenderPass,
|
|
/// A loop's check: nothing past the check itself.
|
|
Loop,
|
|
/// A staged gather's or scatter's copies: nothing past the work itself.
|
|
Staged,
|
|
/// An execution `commit` recorded on the GPU alone with no barrier between its commands, which
|
|
/// its batch's submission records again with them where a route encoded since may set a
|
|
/// barrier in a record (`gpu_execute::Rerecord`); no work on the GPU is waited for.
|
|
Rerecord(Arc<Rerecord>),
|
|
}
|
|
|
|
impl StepInputs {
|
|
/// Whether the segment's recording must be made again before its batch is submitted, though
|
|
/// a recording is in place: [`Rerecord::due`].
|
|
pub(super) fn rerecords(&self) -> bool {
|
|
matches!(self, StepInputs::Rerecord(rerecord) if rerecord.due())
|
|
}
|
|
}
|
|
|
|
/// What `commit` made of a segment's work ([`Deferred::prepare`]).
|
|
pub(super) struct Prepared {
|
|
/// Its recording, where `commit` recorded it.
|
|
pub(super) recorded: Option<RecordedSegment>,
|
|
/// `commit` recorded it for good, though the GPU may write what it reads: it runs on the GPU
|
|
/// alone (`gpu_execute.rs`, `render/executions/gpu.rs`), and no host step records it.
|
|
pub(super) for_good: bool,
|
|
/// What its host step needs.
|
|
pub(super) inputs: StepInputs,
|
|
/// What the command buffer holds until it completes.
|
|
pub(super) retained: Option<Box<dyn Any + Send + Sync>>,
|
|
/// `commit` left its recording to a host step for the pipelines it records, being made (or
|
|
/// failed) then (`render/pending.rs`).
|
|
pub(super) pipelines: bool,
|
|
/// Where its host step records it for what the GPU may write, what the step's recording may
|
|
/// use that Metal orders (`Segment::bound`).
|
|
pub(super) bound: Option<Summary<ResourceKey>>,
|
|
/// `commit`'s recording of it was refused, though a route met later may write the records it
|
|
/// read first ([`Deferred::prepare`]): its host step records it once the work before it
|
|
/// completed (`Segment::host`).
|
|
pub(super) held: bool,
|
|
}
|
|
|
|
/// Whether `commit`'s refused recording of an execution of `executed`, buffers read from the CPU's
|
|
/// records, is held for its host step: where its command buffer made one of them resident for
|
|
/// writing (`residency`, its), as a route met after the commit may still write the records before
|
|
/// the work runs (another queue's command buffer it waits for through an event, encoded after this
|
|
/// commit: the probe `crates/metal2vulkan-conformance/probes/icb_cross_queue_writes.m`), and Metal
|
|
/// runs what that route wrote. The step records the work from the records as they stand once the
|
|
/// work before it completed, and fails the command buffer, at the batch's submission, only where
|
|
/// they are still refused (`WorkCounts::commit_refusals_held`). A refusal of another buffer's
|
|
/// records stands at `commit`.
|
|
fn held<'a>(
|
|
residency: &crate::residency::Residency,
|
|
executed: impl IntoIterator<Item = &'a IndirectCommandBuffer>,
|
|
) -> bool {
|
|
let writable = residency.writable_indirect_command_buffers();
|
|
executed.into_iter().any(|icb| writable.contains(icb))
|
|
}
|
|
|
|
impl Deferred {
|
|
/// Whether `self` and `other` are the same work: one segment's.
|
|
pub(super) fn same(&self, other: &Deferred) -> bool {
|
|
match (self, other) {
|
|
(Deferred::Execute(a), Deferred::Execute(b)) => Arc::ptr_eq(a, b),
|
|
(Deferred::Dispatch(a), Deferred::Dispatch(b)) => Arc::ptr_eq(a, b),
|
|
(Deferred::SparseScrub(a), Deferred::SparseScrub(b)) => Arc::ptr_eq(a, b),
|
|
(Deferred::GatedCopyIn(a), Deferred::GatedCopyIn(b)) => Arc::ptr_eq(a, b),
|
|
(Deferred::RunMerge(a), Deferred::RunMerge(b)) => Arc::ptr_eq(a, b),
|
|
(Deferred::RenderPass(a), Deferred::RenderPass(b)) => Arc::ptr_eq(a, b),
|
|
(Deferred::Pending(a), Deferred::Pending(b)) => Arc::ptr_eq(a, b),
|
|
(Deferred::Loop(a), Deferred::Loop(b)) => Arc::ptr_eq(a, b),
|
|
(Deferred::GatherStage(a), Deferred::GatherStage(b)) => Arc::ptr_eq(a, b),
|
|
(Deferred::ScatterStage(a), Deferred::ScatterStage(b)) => Arc::ptr_eq(a, b),
|
|
(Deferred::ScatterDrain(a), Deferred::ScatterDrain(b)) => Arc::ptr_eq(a, b),
|
|
(Deferred::ShadowSplice(a), Deferred::ShadowSplice(b)) => Arc::ptr_eq(a, b),
|
|
_ => false,
|
|
}
|
|
}
|
|
|
|
/// Whether the encoder copies back its shadowed textures before the work and forgets them
|
|
/// (`EncoderCore::defer`): work recorded apart, with copies of its own. A render pass that
|
|
/// executes render commands is not: its shadowed textures are its encoder's, copied in
|
|
/// before it and back as the encoder ends (`render/shadows.rs`).
|
|
/// Nor is a dispatch whose pipelines were being made: its shadowed textures were copied in
|
|
/// at the dispatch, and its writes are its encoder's to copy back. Nor is a gated copy in,
|
|
/// which is one of the encoder's shadow copies, nor a run's merge (`pass_runs.rs`): a linear
|
|
/// attachment's touches no shadowed texture, and a shadowed texture's is the copy back its
|
|
/// encoder took out of its shadows to leave there. A staged copy's do: a gather's writes the
|
|
/// buffer, a scatter's reads it and writes the pages, after every command before them. A
|
|
/// splice's CPU part does not: it ends copies back its encoder just recorded.
|
|
pub(super) fn leaves_shadows(&self) -> bool {
|
|
match self {
|
|
Deferred::Execute(_)
|
|
| Deferred::Dispatch(_)
|
|
| Deferred::SparseScrub(_)
|
|
| Deferred::Loop(_)
|
|
| Deferred::GatherStage(_)
|
|
| Deferred::ScatterStage(_)
|
|
| Deferred::ScatterDrain(_) => true,
|
|
Deferred::RenderPass(_)
|
|
| Deferred::Pending(_)
|
|
| Deferred::GatedCopyIn(_)
|
|
| Deferred::RunMerge(_)
|
|
| Deferred::ShadowSplice(_) => false,
|
|
}
|
|
}
|
|
|
|
/// Whether the GPU may write what the work reads now: a host step records it, before its
|
|
/// batch is submitted. For an execution, whether a route that may write its buffer's records
|
|
/// met it (`IndirectCommandBuffer::gpu_written`, for good), or it reads its range from a buffer
|
|
/// (`Execute::indirect`), or it lies inside a block of command predication, whose counter its
|
|
/// host step reads (`Execute::predicated`); an indirect dispatch's arguments always are GPU
|
|
/// memory the work
|
|
/// before it may write. A render pass's, whether such a route met the buffer of one of its
|
|
/// executions, or one of them reads its range from a buffer. A staged scatter's CPU copy
|
|
/// reads the staging the GPU's copy before it wrote; a staged gather's reads guest RAM pages
|
|
/// a command before it may write (`StagedGather::after_the_gpu`); a splice's CPU part reads
|
|
/// the region its copies back wrote.
|
|
pub(super) fn gpu_written(&self) -> bool {
|
|
match self {
|
|
Deferred::Execute(execute) => {
|
|
execute.icb.gpu_written() || execute.indirect() || execute.predicated()
|
|
}
|
|
Deferred::Dispatch(_)
|
|
| Deferred::Loop(_)
|
|
| Deferred::ScatterDrain(_)
|
|
| Deferred::ShadowSplice(_) => true,
|
|
Deferred::GatherStage(gather) => gather.after_the_gpu(),
|
|
Deferred::SparseScrub(_)
|
|
| Deferred::GatedCopyIn(_)
|
|
| Deferred::RunMerge(_)
|
|
| Deferred::Pending(_)
|
|
| Deferred::ScatterStage(_) => false,
|
|
Deferred::RenderPass(pass) => pass.gpu_written(),
|
|
}
|
|
}
|
|
|
|
/// `commit`'s work on it, with no lock of `command_buffer` held: for a segment its host step
|
|
/// records (`step`), what the step needs; else its recording. An execution its step would
|
|
/// record runs on the GPU alone instead where every record it may hold is covered
|
|
/// (`gpu_execute.rs`), recorded now for good; otherwise its step needs the states its
|
|
/// records may name and their variants ([`Execute::settle`]). An execution recorded now from
|
|
/// the CPU's records is watched by its buffer for a host step `commit` did not foresee. An
|
|
/// indirect dispatch's step needs its variants ([`ArgumentDispatch::settle`]); it is never
|
|
/// recorded before its step. A render pass is recorded now from the CPU's records, unless
|
|
/// its step records it; a pass its step would record is recorded now for good where its
|
|
/// executions run on the GPU alone (`DeferredPass::record_on_gpu`); otherwise the step's draws
|
|
/// need the variants and pipelines of the states its records may name
|
|
/// ([`DeferredPass::settle`]).
|
|
pub(super) fn prepare(
|
|
&self,
|
|
command_buffer: &CommandBuffer,
|
|
step: bool,
|
|
) -> Result<Prepared, Error> {
|
|
let device = command_buffer.device();
|
|
match self {
|
|
Deferred::Execute(execute) if step => {
|
|
// On the GPU alone where it is total (`gpu_execute.rs`): not a checked execution
|
|
// whose check may see something, whose step reads its records for the check, nor
|
|
// one inside a block of command predication without its preprocess's gate, whose
|
|
// step reads the counter. A checked one's host step, where a route encoded since
|
|
// gives its check something to see (`Execute::outgrown`), is settled now.
|
|
if let Some((recorded, inputs)) = self.record_on_gpu(command_buffer)? {
|
|
let retained: Option<Box<dyn Any + Send + Sync>> = match &execute.check {
|
|
Some(_) => {
|
|
let residency = command_buffer.residency()?.kernel();
|
|
let Settled { states, variants } =
|
|
execute.settle(device, execute.states(device), &residency);
|
|
*lock(&execute.unchecked) = Some(states);
|
|
Some(Box::new(variants))
|
|
}
|
|
None => None,
|
|
};
|
|
return Ok(Prepared {
|
|
recorded: Some(recorded),
|
|
for_good: true,
|
|
inputs,
|
|
retained,
|
|
pipelines: false,
|
|
bound: None,
|
|
held: false,
|
|
});
|
|
}
|
|
let residency = command_buffer.residency()?.kernel();
|
|
let Settled { states, variants } =
|
|
execute.settle(device, execute.states(device), &residency);
|
|
Ok(Prepared {
|
|
recorded: None,
|
|
for_good: false,
|
|
inputs: StepInputs::Settled(states),
|
|
retained: Some(Box::new(variants)),
|
|
pipelines: false,
|
|
bound: execute.bound(&residency),
|
|
held: false,
|
|
})
|
|
}
|
|
Deferred::Execute(execute) => {
|
|
let recorded = match execute.record(command_buffer, None) {
|
|
Ok(recorded) => recorded,
|
|
// Held for its host step (`held`).
|
|
Err(error) => {
|
|
let residency = command_buffer.residency()?;
|
|
if !held(&residency, [&execute.icb]) {
|
|
return Err(error);
|
|
}
|
|
device.shared().counts.commit_refusal_held();
|
|
let residency = residency.kernel();
|
|
let Settled { states, variants } =
|
|
execute.settle(device, execute.states(device), &residency);
|
|
return Ok(Prepared {
|
|
recorded: None,
|
|
for_good: false,
|
|
inputs: StepInputs::Settled(states),
|
|
retained: Some(Box::new(variants)),
|
|
pipelines: false,
|
|
bound: execute.bound(&residency),
|
|
held: true,
|
|
});
|
|
}
|
|
};
|
|
let residency = command_buffer.residency()?.kernel();
|
|
let unforeseen = Unforeseen::new(device, execute, residency);
|
|
execute.icb.watch(&unforeseen);
|
|
Ok(Prepared {
|
|
recorded: Some(recorded),
|
|
for_good: false,
|
|
inputs: StepInputs::Unforeseen(unforeseen),
|
|
retained: None,
|
|
pipelines: false,
|
|
bound: None,
|
|
held: false,
|
|
})
|
|
}
|
|
Deferred::Dispatch(dispatch) if step => Ok(Prepared {
|
|
recorded: None,
|
|
for_good: false,
|
|
inputs: StepInputs::Dispatch,
|
|
retained: Some(Box::new(
|
|
dispatch.settle(device, &command_buffer.residency()?.kernel()),
|
|
)),
|
|
pipelines: false,
|
|
bound: None,
|
|
held: false,
|
|
}),
|
|
Deferred::Dispatch(_) => Err(internal(
|
|
"an indirect dispatch recorded before the work it waits for completed",
|
|
)),
|
|
Deferred::SparseScrub(_) | Deferred::GatedCopyIn(_) | Deferred::RunMerge(_) => {
|
|
Ok(Prepared {
|
|
recorded: None,
|
|
for_good: false,
|
|
inputs: StepInputs::None,
|
|
retained: None,
|
|
pipelines: false,
|
|
bound: None,
|
|
held: false,
|
|
})
|
|
}
|
|
// Recorded now for good where every execution whose records the GPU may write runs
|
|
// on the GPU alone (`render/executions/gpu.rs`). Otherwise its step's draws compile
|
|
// what `commit` cannot foresee alone: it settles their variants and pipelines now
|
|
// (`DeferredPass::settle`), held until the command buffer completes.
|
|
// The step waits for the pipelines its draws record too (`render/pending.rs`).
|
|
// And makes now what the step would make (`render/executions/ahead.rs`).
|
|
Deferred::RenderPass(pass) if step => {
|
|
if let Some((recorded, inputs)) = self.record_on_gpu(command_buffer)? {
|
|
return Ok(Prepared {
|
|
recorded: Some(recorded),
|
|
for_good: true,
|
|
inputs,
|
|
retained: None,
|
|
pipelines: false,
|
|
bound: None,
|
|
held: false,
|
|
});
|
|
}
|
|
pass.make_ahead(command_buffer);
|
|
Ok(Prepared {
|
|
recorded: None,
|
|
for_good: false,
|
|
inputs: StepInputs::RenderPass,
|
|
retained: Some(Box::new(pass.settle(command_buffer))),
|
|
pipelines: pass.making() || pass.failed(),
|
|
bound: pass.bound(device, &command_buffer.residency()?),
|
|
held: false,
|
|
})
|
|
}
|
|
// A pass of draws whose pipelines are being made, or one of which failed, is
|
|
// recorded by a host step once they are made, which drops the draw of a failed one
|
|
// (`render/pending.rs`). One whose executions read the CPU's records as they stand now
|
|
// waits for them first, until the command buffer's bound at most; so does its
|
|
// executions' replay for a making it begins itself, which leaves the pass to the host
|
|
// step past that bound (`DeferredPass::left_for_makings`).
|
|
Deferred::RenderPass(pass) => {
|
|
let left = Prepared {
|
|
recorded: None,
|
|
for_good: false,
|
|
inputs: StepInputs::RenderPass,
|
|
retained: None,
|
|
pipelines: true,
|
|
bound: None,
|
|
held: false,
|
|
};
|
|
if pass.reads_at_commit() {
|
|
let deadline = command_buffer.making_deadline();
|
|
commit_times::phase(Phase::PipelineWait, || pass.wait_made(deadline));
|
|
}
|
|
if pass.making() || pass.failed() {
|
|
return Ok(left);
|
|
}
|
|
let recorded = match pass.record(command_buffer, false) {
|
|
Ok(recorded) => recorded,
|
|
Err(_) if pass.left_for_makings(command_buffer) => return Ok(left),
|
|
// Held for its host step (`held`), as a step's pass is prepared above.
|
|
Err(error) => {
|
|
let residency = command_buffer.residency()?;
|
|
if !held(&residency, pass.executed()) {
|
|
return Err(error);
|
|
}
|
|
device.shared().counts.commit_refusal_held();
|
|
pass.make_ahead(command_buffer);
|
|
return Ok(Prepared {
|
|
recorded: None,
|
|
for_good: false,
|
|
inputs: StepInputs::RenderPass,
|
|
retained: Some(Box::new(pass.settle(command_buffer))),
|
|
pipelines: false,
|
|
bound: pass.bound(device, &residency),
|
|
held: true,
|
|
});
|
|
}
|
|
};
|
|
Ok(Prepared {
|
|
recorded: Some(recorded),
|
|
for_good: false,
|
|
inputs: StepInputs::RenderPass,
|
|
retained: None,
|
|
pipelines: false,
|
|
bound: None,
|
|
held: false,
|
|
})
|
|
}
|
|
// Its host step reads the unit's halt word once the laying completed.
|
|
Deferred::Loop(_) => Ok(Prepared {
|
|
recorded: None,
|
|
for_good: false,
|
|
inputs: StepInputs::Loop,
|
|
retained: None,
|
|
pipelines: false,
|
|
bound: None,
|
|
held: false,
|
|
}),
|
|
// Recorded by host steps: a gather's and a scatter's GPU copy by its batch's
|
|
// (`records_at_its_step`); a scatter's CPU copy, and a splice's, which record nothing
|
|
// on the GPU, once the work before it completed. Their uses are their encoder's, noted
|
|
// at the call (`host_ram/copy.rs`, `EncoderCore::shadow_copies`): the steps'
|
|
// recordings name none of their own.
|
|
Deferred::GatherStage(_)
|
|
| Deferred::ScatterStage(_)
|
|
| Deferred::ScatterDrain(_)
|
|
| Deferred::ShadowSplice(_) => Ok(Prepared {
|
|
recorded: None,
|
|
for_good: false,
|
|
inputs: StepInputs::Staged,
|
|
retained: None,
|
|
pipelines: false,
|
|
bound: match self {
|
|
Deferred::ScatterDrain(_) | Deferred::ShadowSplice(_) => {
|
|
Some(EncoderUses::new(true).finish())
|
|
}
|
|
_ => None,
|
|
},
|
|
held: false,
|
|
}),
|
|
// Recorded now where its pipelines are made; else by a host step once they are,
|
|
// which makes again one whose making failed.
|
|
Deferred::Pending(dispatch) => {
|
|
let later = step || dispatch.making() || dispatch.failed();
|
|
Ok(Prepared {
|
|
recorded: match later {
|
|
true => None,
|
|
false => Some(dispatch.record(command_buffer)?),
|
|
},
|
|
for_good: false,
|
|
inputs: StepInputs::Dispatch,
|
|
retained: None,
|
|
pipelines: later,
|
|
bound: None,
|
|
held: false,
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Whether it is a run's pass's merge (`pass_runs.rs`), which an encoding again of its pass
|
|
/// replaces with that pass's own merge (`command_buffer/reencode.rs`).
|
|
pub(super) fn joins_a_run(&self) -> bool {
|
|
matches!(self, Deferred::RunMerge(_))
|
|
}
|
|
|
|
/// Whether `commit` leaves its recording to its batch's host step, which waits for no work on
|
|
/// the GPU but where [`steps_after_the_gpu_now`](Self::steps_after_the_gpu_now) says: a
|
|
/// staged gather's or scatter's GPU copy, whose region of the arena that step takes, so its
|
|
/// memory is made on neither the encoding nor the committing thread (`host_ram/copy.rs`).
|
|
pub(super) fn records_at_its_step(&self) -> bool {
|
|
matches!(self, Deferred::GatherStage(_) | Deferred::ScatterStage(_))
|
|
}
|
|
|
|
/// Whether its host step, not yet run, waits for the work submitted before it to complete
|
|
/// though the work is not GPU-written for good ([`gpu_written`](Self::gpu_written)): a staged
|
|
/// gather's where the GPU may write the pages it reads now (`StagedGather::waits_for_the_gpu`).
|
|
pub(super) fn steps_after_the_gpu_now(&self, device: &Device) -> bool {
|
|
match self {
|
|
Deferred::GatherStage(gather) => gather.waits_for_the_gpu(device),
|
|
_ => false,
|
|
}
|
|
}
|
|
|
|
/// What its host step reads on the host of what the GPU may write, where that is all the
|
|
/// step waits for of the work before it (`CommandBufferShared::step_reads`): an execution's
|
|
/// records and range (`ExecutionRange::host_reads`), outside a block of command predication,
|
|
/// whose counter its step reads too; a render pass's executions'. `None` for every other
|
|
/// work, whose step waits for all the work submitted before it.
|
|
pub(super) fn host_reads(&self) -> Option<Vec<Use<ResourceKey>>> {
|
|
match self {
|
|
Deferred::Execute(execute) => execute.host_reads(),
|
|
Deferred::RenderPass(pass) => Some(pass.host_reads()),
|
|
Deferred::Dispatch(_)
|
|
| Deferred::SparseScrub(_)
|
|
| Deferred::GatedCopyIn(_)
|
|
| Deferred::RunMerge(_)
|
|
| Deferred::Pending(_)
|
|
| Deferred::Loop(_)
|
|
| Deferred::GatherStage(_)
|
|
| Deferred::ScatterStage(_)
|
|
| Deferred::ScatterDrain(_)
|
|
| Deferred::ShadowSplice(_) => None,
|
|
}
|
|
}
|
|
|
|
/// Whether a rebind's encoding again of its encoder records it at once in its place, leaving
|
|
/// no segment of it (`command_buffer/reencode.rs`): a staged gather, which an encoder encoded
|
|
/// again copies through the imports (`host_ram/copy.rs`), but one over a chunk that takes no
|
|
/// import or in a part of its own (`StagedGather::encoded_again_through_imports`), which it
|
|
/// stages again ([`left_again_by_an_encoding_again`](Self::left_again_by_an_encoding_again)).
|
|
/// The encoding again's parts are the first's: such a gather's segment starts none.
|
|
pub(super) fn recorded_by_an_encoding_again(&self) -> bool {
|
|
match self {
|
|
Deferred::GatherStage(gather) => gather.encoded_again_through_imports(),
|
|
_ => false,
|
|
}
|
|
}
|
|
|
|
/// Whether a rebind's encoding again of its encoder leaves a segment of its own in its place
|
|
/// (`command_buffer/reencode.rs`): a splice's and a merge on the host's CPU part
|
|
/// (`shadow_splice.rs`), which the encoding again's copies back plan over the pages the
|
|
/// buffer lies in then and leave again, in a part as the first's (a rebind keeps the bytes'
|
|
/// offset in their page, `rebind.rs`, so the copies cut alike); a staged scatter's two
|
|
/// steps, which the encoding again stages again from where the buffer lies then, its CPU
|
|
/// copy in a part of its own as the first's; and a staged gather the imports would not copy
|
|
/// as the first staged it (over a chunk that takes no import, or in a part of its own:
|
|
/// `StagedGather::encoded_again_through_imports`), staged again so (`host_ram/copy.rs`'s
|
|
/// `HostRamCall::staged_again`); and a shadow's copy in left to its batch's submission
|
|
/// (`shadow::GatedCopyIn`), which the encoding again's copy in leaves again, gated as it
|
|
/// decides then (or records in place, where it decides to copy every texel): its gate of a
|
|
/// log, made after the commit's decisions (`DirtyShadows::committed`), holds no stamp and
|
|
/// copies every region (`CopyInGate::regions`); and a sparse texture's scrub, left for its
|
|
/// batch's submission (`sparse::emulated::Scrub`), which the blit or the pass encoded again
|
|
/// leaves again over the same texture. The first's go unrun.
|
|
pub(super) fn left_again_by_an_encoding_again(&self) -> bool {
|
|
match self {
|
|
Deferred::ShadowSplice(_)
|
|
| Deferred::ScatterStage(_)
|
|
| Deferred::ScatterDrain(_)
|
|
| Deferred::GatedCopyIn(_)
|
|
| Deferred::SparseScrub(_) => true,
|
|
Deferred::GatherStage(gather) => !gather.encoded_again_through_imports(),
|
|
_ => false,
|
|
}
|
|
}
|
|
|
|
/// Whether a commit may record it on the GPU alone, for good
|
|
/// ([`record_on_gpu`](Self::record_on_gpu)): an execution's, or a render pass's that executes
|
|
/// render commands.
|
|
pub(super) fn may_run_on_gpu_alone(&self) -> bool {
|
|
matches!(self, Deferred::Execute(_) | Deferred::RenderPass(_))
|
|
}
|
|
|
|
/// Its recording on the GPU alone, for good, with what its host step needs, where it runs
|
|
/// there over the buffers as they lie now (`gpu_execute.rs`, `DeferredPass::record_on_gpu`);
|
|
/// `None` where it does not, or is work that never runs there. With no lock of
|
|
/// `command_buffer` held: at the commit, and at a rebind before the command buffer's first
|
|
/// submission, which records it again (`command_buffer/reencode.rs`).
|
|
pub(super) fn record_on_gpu(
|
|
&self,
|
|
command_buffer: &CommandBuffer,
|
|
) -> Result<Option<(RecordedSegment, StepInputs)>, Error> {
|
|
match self {
|
|
Deferred::Execute(execute) => {
|
|
let recorded = gpu_execute::record(command_buffer, execute)?;
|
|
Ok(recorded.map(|(recorded, rerecord)| {
|
|
let inputs = match rerecord {
|
|
Some(rerecord) => StepInputs::Rerecord(rerecord),
|
|
None => StepInputs::Settled(Vec::new()),
|
|
};
|
|
(recorded, inputs)
|
|
}))
|
|
}
|
|
Deferred::RenderPass(pass) => Ok(pass
|
|
.record_on_gpu(command_buffer)?
|
|
.map(|recorded| (recorded, StepInputs::RenderPass))),
|
|
Deferred::Dispatch(_)
|
|
| Deferred::SparseScrub(_)
|
|
| Deferred::GatedCopyIn(_)
|
|
| Deferred::RunMerge(_)
|
|
| Deferred::Pending(_)
|
|
| Deferred::Loop(_)
|
|
| Deferred::GatherStage(_)
|
|
| Deferred::ScatterStage(_)
|
|
| Deferred::ScatterDrain(_)
|
|
| Deferred::ShadowSplice(_) => Ok(None),
|
|
}
|
|
}
|
|
|
|
/// Its host step, on the steps' thread (`scheduler/steps.rs`) with no lock of `command_buffer`
|
|
/// held: its
|
|
/// recording from what it reads now and `inputs`. An execution's records name their states
|
|
/// among those `commit` settled, or for one `commit` recorded from the CPU's records, those
|
|
/// `use_resource` settled since. An indirect dispatch's arguments state its size. A render
|
|
/// pass's executions read their records as the GPU and the CPU left them.
|
|
pub(super) fn step(
|
|
&self,
|
|
command_buffer: &CommandBuffer,
|
|
inputs: &StepInputs,
|
|
) -> Result<RecordedSegment, Error> {
|
|
match self {
|
|
Deferred::Execute(execute) => {
|
|
// Recorded on the GPU alone with a check a route encoded since gave something to
|
|
// see: recorded from the records as the GPU and the CPU left them, naming states
|
|
// among those `commit` settled, for good.
|
|
if let Some(states) = execute.take_outgrown() {
|
|
return execute.record(command_buffer, Some(&states));
|
|
}
|
|
let states = match inputs {
|
|
StepInputs::Settled(states) => states.clone(),
|
|
StepInputs::Unforeseen(unforeseen) => {
|
|
unforeseen.states(command_buffer.device())
|
|
}
|
|
// Recorded again on the GPU alone, with the barriers: no record is read.
|
|
StepInputs::Rerecord(rerecord) => {
|
|
return rerecord.record(command_buffer, execute);
|
|
}
|
|
StepInputs::Dispatch
|
|
| StepInputs::None
|
|
| StepInputs::RenderPass
|
|
| StepInputs::Loop
|
|
| StepInputs::Staged => {
|
|
return Err(internal("an execution's host step without its states"));
|
|
}
|
|
};
|
|
// The states go after the recording, with no lock held: one may be a state's
|
|
// last handle.
|
|
execute.record(command_buffer, Some(&states))
|
|
}
|
|
Deferred::Dispatch(dispatch) => dispatch.record(command_buffer),
|
|
Deferred::SparseScrub(_) => Err(internal("a sparse scrub's host step")),
|
|
Deferred::GatedCopyIn(_) => Err(internal("a gated copy in's host step")),
|
|
Deferred::RunMerge(_) => Err(internal("a run's merge's host step")),
|
|
Deferred::RenderPass(pass) => pass.record(command_buffer, true),
|
|
Deferred::Pending(dispatch) => dispatch.record(command_buffer),
|
|
Deferred::Loop(check) => check.step(command_buffer),
|
|
Deferred::GatherStage(gather) => gather.stage(command_buffer),
|
|
Deferred::ScatterStage(scatter) => scatter.stage(command_buffer),
|
|
Deferred::ScatterDrain(scatter) => scatter.drain(command_buffer.device()),
|
|
Deferred::ShadowSplice(splices) => Ok(splices.drain(command_buffer.device())),
|
|
}
|
|
}
|
|
|
|
/// Whether a route encoded since `commit` recorded the work for good on the GPU may write
|
|
/// more than `commit` decided on (`DeferredPass::outgrown`), or gives the check of an
|
|
/// execution recorded there something to see (`Execute::outgrown`): its host step records it
|
|
/// instead, before its batch is submitted. A render pass's executions' GPU form, and an
|
|
/// execution's on the GPU alone with a check.
|
|
pub(super) fn outgrown(&self) -> bool {
|
|
match self {
|
|
Deferred::RenderPass(pass) => pass.outgrown(),
|
|
Deferred::Execute(execute) => execute.outgrown(),
|
|
Deferred::Dispatch(_)
|
|
| Deferred::SparseScrub(_)
|
|
| Deferred::GatedCopyIn(_)
|
|
| Deferred::RunMerge(_)
|
|
| Deferred::Pending(_)
|
|
| Deferred::Loop(_)
|
|
| Deferred::GatherStage(_)
|
|
| Deferred::ScatterStage(_)
|
|
| Deferred::ScatterDrain(_)
|
|
| Deferred::ShadowSplice(_) => false,
|
|
}
|
|
}
|
|
|
|
/// Whether `commit` recorded it from the CPU's records of an indirect command buffer the CPU
|
|
/// wrote since (`Execute::rewritten`, `DeferredPass::rewritten`): its host step records it
|
|
/// again from the records as they stand then, before its batch is submitted, waiting for no
|
|
/// work on the GPU.
|
|
pub(super) fn rewritten(&self) -> bool {
|
|
match self {
|
|
Deferred::Execute(execute) => execute.rewritten(),
|
|
Deferred::RenderPass(pass) => pass.rewritten(),
|
|
Deferred::Dispatch(_)
|
|
| Deferred::SparseScrub(_)
|
|
| Deferred::GatedCopyIn(_)
|
|
| Deferred::RunMerge(_)
|
|
| Deferred::Pending(_)
|
|
| Deferred::Loop(_)
|
|
| Deferred::GatherStage(_)
|
|
| Deferred::ScatterStage(_)
|
|
| Deferred::ScatterDrain(_)
|
|
| Deferred::ShadowSplice(_) => false,
|
|
}
|
|
}
|
|
|
|
/// Whether its batch waits for it after its host step: a loop's check while it runs the
|
|
/// laying again (`command_buffer/rerun.rs`), which wakes the scheduler as it ends.
|
|
pub(super) fn holds(&self) -> bool {
|
|
match self {
|
|
Deferred::Loop(check) => check.running(),
|
|
Deferred::GatherStage(_)
|
|
| Deferred::ScatterStage(_)
|
|
| Deferred::ScatterDrain(_)
|
|
| Deferred::ShadowSplice(_) => false,
|
|
Deferred::Execute(_)
|
|
| Deferred::Dispatch(_)
|
|
| Deferred::SparseScrub(_)
|
|
| Deferred::GatedCopyIn(_)
|
|
| Deferred::RunMerge(_)
|
|
| Deferred::RenderPass(_)
|
|
| Deferred::Pending(_) => false,
|
|
}
|
|
}
|
|
|
|
/// Whether it is a render pass left for its draws' or tile dispatches' pipelines alone, made
|
|
/// since or not (`DeferredPass::left_for_pipelines`): an encoding again records those draws
|
|
/// where it finds their pipelines made, and leaves a segment of its own where they are still
|
|
/// being made, so it takes such a pass's place (`State::splice_replay`).
|
|
pub(super) fn left_for_pipelines(&self) -> bool {
|
|
match self {
|
|
Deferred::RenderPass(pass) => pass.left_for_pipelines(),
|
|
_ => false,
|
|
}
|
|
}
|
|
|
|
/// Whether a pipeline the work records is still being made (`render/pending.rs`).
|
|
pub(super) fn making(&self) -> bool {
|
|
match self {
|
|
Deferred::RenderPass(pass) => pass.making(),
|
|
Deferred::Pending(dispatch) => dispatch.making(),
|
|
Deferred::Execute(_)
|
|
| Deferred::Dispatch(_)
|
|
| Deferred::SparseScrub(_)
|
|
| Deferred::GatedCopyIn(_)
|
|
| Deferred::RunMerge(_)
|
|
| Deferred::Loop(_)
|
|
| Deferred::GatherStage(_)
|
|
| Deferred::ScatterStage(_)
|
|
| Deferred::ScatterDrain(_)
|
|
| Deferred::ShadowSplice(_) => false,
|
|
}
|
|
}
|
|
|
|
/// Whether its recording may write memory no use its command buffer noted names, so the merge
|
|
/// back of copied host buffers takes every copy as written by it (`copied.rs`): an indirect
|
|
/// command buffer's execution and a render pass that executes render commands, whose
|
|
/// commands its step resolves from records, an indirect dispatch and a scrub, which their
|
|
/// steps or submissions record. A dispatch whose pipelines were being made records the uses
|
|
/// its encoding noted, a gated copy in writes the shadow it names, a run's merge
|
|
/// the bytes its pass noted it writes, a loop's check records nothing, and a staged copy's
|
|
/// steps write the runtime's staging and the buffer or pages its call noted.
|
|
pub(super) fn reaches_unnamed(&self) -> bool {
|
|
match self {
|
|
Deferred::Execute(_) | Deferred::Dispatch(_) | Deferred::SparseScrub(_) => true,
|
|
Deferred::RenderPass(pass) => pass.executes(),
|
|
Deferred::GatedCopyIn(_)
|
|
| Deferred::RunMerge(_)
|
|
| Deferred::Pending(_)
|
|
| Deferred::Loop(_)
|
|
| Deferred::GatherStage(_)
|
|
| Deferred::ScatterStage(_)
|
|
| Deferred::ScatterDrain(_)
|
|
| Deferred::ShadowSplice(_) => false,
|
|
}
|
|
}
|
|
|
|
/// Whether a host step records it from what its calls resolved alone, nothing of the buffers
|
|
/// it names read again then: the buffers over host pages its commands used let their pages go
|
|
/// at the commit instead of keeping them until it completes (`CommandBuffer::commit`'s
|
|
/// `steps_hold`, `rebind.rs`), so a rebind of one is not refused but encodes its encoder
|
|
/// again (`command_buffer/reencode.rs`). A dispatch whose pipelines were being made records
|
|
/// what its encoding resolved (`pending_dispatch.rs`), and so does a render pass `commit`
|
|
/// left for the pipelines its draws and tile dispatches record (`pipelines`) that executes no
|
|
/// render commands, whose instances' commands its calls recorded
|
|
/// (`render/pending_tile.rs`). So does a run's merge (`pass_runs.rs`), which writes only the
|
|
/// bytes its encoder's commands named (a linear attachment's, none over host pages; a
|
|
/// shadowed texture's truth, whose uses its pass noted): a rebind of them encodes that
|
|
/// encoder again, the merge with it. So do a staged copy's steps, between the buffer its call
|
|
/// resolved (`blit_at`) and the pages it named, and a splice's and a merge on the host's CPU
|
|
/// part (`shadow_splice.rs`), which writes the pages the truth's buffer lay in at its
|
|
/// encoder's call, a shadow's gated copy in, which copies from the truth's `VkBuffer` as its
|
|
/// encoder's call found it (`shadow::GatedCopyIn`), and a sparse texture's scrub, which zeroes
|
|
/// tiles of its texture alone, as its batch mapped them, and reads no buffer
|
|
/// (`sparse::emulated::Scrub`): a rebind before the command buffer's submission encodes that
|
|
/// encoder again, its CPU part, its copy in or its scrub with it, and one after it keeps the
|
|
/// old pages until the command buffer completes (`rebind.rs`). So does a predicated loop's
|
|
/// check whose laying left no work apart (`command_buffer/rerun.rs`): its step reads only its
|
|
/// unit's halt word, in the command buffer's arena, and each run again submits the laying's
|
|
/// command buffers again as they were encoded, over the pages their first submission took,
|
|
/// which the command buffer holds until it completes. A rebind after that submission keeps
|
|
/// the old pages for every run again, as Metal's loop reads the pages its submission found;
|
|
/// one before it fails that submission (`EncodedUseRebound`,
|
|
/// `command_buffer/first_submission.rs`), as the laying's encoders keep no log to be encoded
|
|
/// again from (`predication.rs`).
|
|
/// Everything else its step resolves as it records (an execution, a dispatch left to its host
|
|
/// step, a loop's check whose laying left work apart, which each run again records again as
|
|
/// it records: a host step's work resolving the buffers its encoder named then, work on the
|
|
/// GPU alone over the buffers as they lie then): a rebind meanwhile is refused
|
|
/// (`RebindProblem::EncodedUses`), a known gap (`docs/FAST-PATHS.md`).
|
|
pub(super) fn resolved_at_its_calls(&self, pipelines: bool) -> bool {
|
|
match self {
|
|
Deferred::Pending(_)
|
|
| Deferred::RunMerge(_)
|
|
| Deferred::GatherStage(_)
|
|
| Deferred::ScatterStage(_)
|
|
| Deferred::ScatterDrain(_)
|
|
| Deferred::ShadowSplice(_)
|
|
| Deferred::GatedCopyIn(_)
|
|
| Deferred::SparseScrub(_) => true,
|
|
Deferred::RenderPass(pass) => pipelines && !pass.executes(),
|
|
Deferred::Loop(check) => !check.leaves_work_apart(),
|
|
Deferred::Execute(_) | Deferred::Dispatch(_) => false,
|
|
}
|
|
}
|
|
|
|
/// Whether the making of a pipeline the work records failed (`DeferredPass::failed`,
|
|
/// `PendingDispatch::failed`): a dispatch's, which its recording makes again, on the thread
|
|
/// that records it, the command buffer completing with
|
|
/// `CommandBufferError::PipelineCreation` where that fails too; a draw's, which its
|
|
/// recording drops (`render/pending.rs`).
|
|
pub(super) fn failed(&self) -> bool {
|
|
match self {
|
|
Deferred::RenderPass(pass) => pass.failed(),
|
|
Deferred::Pending(dispatch) => dispatch.failed(),
|
|
Deferred::Execute(_)
|
|
| Deferred::Dispatch(_)
|
|
| Deferred::SparseScrub(_)
|
|
| Deferred::GatedCopyIn(_)
|
|
| Deferred::RunMerge(_)
|
|
| Deferred::Loop(_)
|
|
| Deferred::GatherStage(_)
|
|
| Deferred::ScatterStage(_)
|
|
| Deferred::ScatterDrain(_)
|
|
| Deferred::ShadowSplice(_) => false,
|
|
}
|
|
}
|
|
|
|
/// What its recording uses, on `device`, where that is known before it records
|
|
/// (`DeferredPass::known_summary`): a render pass's that executes no render commands. `None`
|
|
/// for the rest, whose uses their recording finds: an execution's or an indirect dispatch's
|
|
/// from the records and arguments it reads, a scrub's at its submission; a loop's check's are
|
|
/// its laying's (`CommandBufferShared::footprint`). A staged copy's GPU copy uses none past
|
|
/// what its call noted in its encoder's part.
|
|
pub(super) fn known_summary(&self, device: &Device) -> Option<Summary<ResourceKey>> {
|
|
match self {
|
|
Deferred::RenderPass(pass) => pass.known_summary(device),
|
|
Deferred::Pending(dispatch) => Some(dispatch.known_summary()),
|
|
Deferred::GatherStage(_) | Deferred::ScatterStage(_) => {
|
|
Some(EncoderUses::new(true).finish())
|
|
}
|
|
Deferred::Execute(_)
|
|
| Deferred::Dispatch(_)
|
|
| Deferred::SparseScrub(_)
|
|
| Deferred::GatedCopyIn(_)
|
|
| Deferred::RunMerge(_)
|
|
| Deferred::Loop(_)
|
|
| Deferred::ScatterDrain(_)
|
|
| Deferred::ShadowSplice(_) => None,
|
|
}
|
|
}
|
|
|
|
/// Run `waker` each time the making of a pipeline the work records finishes.
|
|
pub(super) fn when_made(&self, waker: &(impl Fn() + Clone + Send + 'static)) {
|
|
match self {
|
|
Deferred::RenderPass(pass) => pass.when_made(waker),
|
|
Deferred::Pending(dispatch) => dispatch.when_made(waker),
|
|
Deferred::Execute(_)
|
|
| Deferred::Dispatch(_)
|
|
| Deferred::SparseScrub(_)
|
|
| Deferred::GatedCopyIn(_)
|
|
| Deferred::RunMerge(_)
|
|
| Deferred::Loop(_)
|
|
| Deferred::GatherStage(_)
|
|
| Deferred::ScatterStage(_)
|
|
| Deferred::ScatterDrain(_)
|
|
| Deferred::ShadowSplice(_) => {}
|
|
}
|
|
}
|
|
|
|
/// Run the makings of the pipelines the work records before the device's pool's pieces of a
|
|
/// lower rank than `urgency` (`pipeline/pool.rs`): its submission waits for them.
|
|
pub(super) fn hasten(&self, urgency: Urgency) {
|
|
match self {
|
|
Deferred::RenderPass(pass) => pass.hasten(urgency),
|
|
Deferred::Pending(dispatch) => dispatch.hasten(urgency),
|
|
Deferred::Execute(_)
|
|
| Deferred::Dispatch(_)
|
|
| Deferred::SparseScrub(_)
|
|
| Deferred::GatedCopyIn(_)
|
|
| Deferred::RunMerge(_)
|
|
| Deferred::Loop(_)
|
|
| Deferred::GatherStage(_)
|
|
| Deferred::ScatterStage(_)
|
|
| Deferred::ScatterDrain(_)
|
|
| Deferred::ShadowSplice(_) => {}
|
|
}
|
|
}
|
|
|
|
/// A weak reference to its work, which holds none of it: a device test's view of what still
|
|
/// holds the work (`tests::host_ram_copy_device`).
|
|
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
|
|
pub(super) fn weak(&self) -> std::sync::Weak<dyn Any + Send + Sync> {
|
|
fn weak<T: Any + Send + Sync>(work: &Arc<T>) -> std::sync::Weak<dyn Any + Send + Sync> {
|
|
Arc::<T>::downgrade(work)
|
|
}
|
|
match self {
|
|
Deferred::Execute(work) => weak(work),
|
|
Deferred::Dispatch(work) => weak(work),
|
|
Deferred::SparseScrub(work) => weak(work),
|
|
Deferred::GatedCopyIn(work) => weak(work),
|
|
Deferred::RunMerge(work) => weak(work),
|
|
Deferred::RenderPass(work) => weak(work),
|
|
Deferred::Pending(work) => weak(work),
|
|
Deferred::Loop(work) => weak(work),
|
|
Deferred::GatherStage(work) => weak(work),
|
|
Deferred::ScatterStage(work) => weak(work),
|
|
Deferred::ScatterDrain(work) => weak(work),
|
|
Deferred::ShadowSplice(work) => weak(work),
|
|
}
|
|
}
|
|
|
|
/// Announce on `device`, once, that a host step records such work.
|
|
pub(super) fn degrade(&self, device: &Device) {
|
|
match self {
|
|
Deferred::Execute(execute) => indirect_execute::degrade_host_replay(device, execute),
|
|
Deferred::Dispatch(dispatch) => dispatch.degrade(device),
|
|
Deferred::SparseScrub(_)
|
|
| Deferred::GatedCopyIn(_)
|
|
| Deferred::RunMerge(_)
|
|
| Deferred::Pending(_)
|
|
| Deferred::Loop(_)
|
|
| Deferred::GatherStage(_)
|
|
| Deferred::ScatterStage(_)
|
|
| Deferred::ScatterDrain(_)
|
|
| Deferred::ShadowSplice(_) => {}
|
|
Deferred::RenderPass(pass) => pass.degrade(device),
|
|
}
|
|
}
|
|
}
|