diff --git a/crates/metal2vulkan-runtime/src/command_buffer/mod.rs b/crates/metal2vulkan-runtime/src/command_buffer/mod.rs index c2374cc96..d037491c2 100644 --- a/crates/metal2vulkan-runtime/src/command_buffer/mod.rs +++ b/crates/metal2vulkan-runtime/src/command_buffer/mod.rs @@ -98,7 +98,7 @@ use super::replay::Replay; use super::residency::Residency; use super::resource::{ObjectId, ResourceKey}; use super::scheduler::{BatchSync, Hand, StepWaits}; -use super::shadow::{Replaced, ShadowCarry, Takes}; +use super::shadow::{ShadowCarry, Takes}; use super::spares::CommandPool; use super::sparse::encoder::SparseUpdate; use super::sparse::indirect; @@ -855,15 +855,16 @@ pub(super) struct State { /// The keeps the encoder being encoded again records after itself, where it leaves a run of /// passes another pass went on in (`pass_runs.rs`, `command_buffer/reencode.rs`). pub(super) replaying_keeps: Vec, - /// What the recordings never submitted that a host step or a rebind records work again in - /// place of decided of their copies taken at use, while it records, that no core recorded in - /// their place met yet (`shadow::Replaced`): a host step's segment's, an encoder's first - /// encoding's, its segments' among it, which a rebind encodes again, and a segment's that a - /// rebind records again on the GPU alone. Each core recorded meanwhile takes from them where - /// it meets them (`shadow::ShadowSync::over`, `EncoderCore::segment`). None otherwise. The - /// step and the rebind hold the turn (`reencoding`), so no other recording into the command - /// buffer's pool meets them. - pub(super) replaced_takes: Option, + /// What the first encoding of the encoder being encoded again decided of its copies taken at + /// use, which its encoding again takes as they did (`shadow::Takes`, + /// `command_buffer/reencode.rs`). + pub(super) replaying_takes: Takes, + /// What the recording a host step records a segment again in place of decided of its copies + /// taken at use, while the step records it: each core the step records into keeps those + /// takes where it meets them (`shadow::ShadowSync::over`, `EncoderCore::segment`). None + /// otherwise. The step holds the turn (`reencoding`), so no other recording into the command + /// buffer's pool meets it. + pub(super) step_takes: Takes, /// The pools of its commands' set 0 (`descriptor_arena.rs`), given back or released with /// the uploads. pub(super) descriptors: DescriptorArena, @@ -2268,7 +2269,8 @@ impl CommandBuffer { carry_batches: 1, pass_runs: PassRuns::default(), replaying_keeps: Vec::new(), - replaced_takes: None, + replaying_takes: Takes::default(), + step_takes: Takes::default(), descriptors: DescriptorArena::default(), status_words: None, mesh_grid_past: false, @@ -4627,7 +4629,7 @@ impl CommandBufferShared { let mut state = lock(&self.state); let segment = &state.recorded[encoder].segments[at]; let replaced = segment.recorded.as_ref().map(|done| done.takes.clone()); - state.replaced_takes = replaced.map(Replaced::new); + state.step_takes = replaced.unwrap_or_default(); } let recorded = work.step(&buffer, &inputs); // A device test's failure of the recording (`CommandBuffer::fail_host_step`), the @@ -4641,7 +4643,7 @@ impl CommandBufferShared { } }; let mut state = lock(&self.state); - state.replaced_takes = None; + state.step_takes.clear(); match recorded { Ok(done) => { let segment = &mut state.recorded[encoder].segments[at]; diff --git a/crates/metal2vulkan-runtime/src/command_buffer/reencode.rs b/crates/metal2vulkan-runtime/src/command_buffer/reencode.rs index 635e9af4f..5f307ca61 100644 --- a/crates/metal2vulkan-runtime/src/command_buffer/reencode.rs +++ b/crates/metal2vulkan-runtime/src/command_buffer/reencode.rs @@ -45,14 +45,9 @@ //! keeps that step's recording. //! - **Copies taken at use.** A tiled texture's copy of its bytes taken at use (`shadow.rs`) is //! taken by the first use encoded after its mark was set, which clears it. An encoder encoded -//! again, its segments recorded again among it, takes it where the use in its place in its -//! first encoding or that encoding's segments took it, keeping that take, whose recording is +//! again takes it where the use in its place in its first encoding took it, whose recording is //! never submitted, and leaves the mark as it finds it: set by a `did_modify_data` since, it is -//! the next use's to take (`State::replaced_takes`, `shadow::ShadowSync::over`). So does work -//! recorded again on the GPU alone, where its first recording took it. A take of the first -//! recordings the encoding again does not meet is given back as it takes their place, and one -//! of its own the first recordings did not hold is given back where it is refused -//! (`shadow::Takes::give_back_unheld`). +//! the next use's to take (`shadow::Takes`). //! - **Runs of passes.** An encoder encoded again that was a pass of a run of passes merged once //! (a shadowed texture's or a linear attachment's, `pass_runs.rs`) leaves the run once it is //! put in place: the merge of the run's pass before it, which it took over, records after all, @@ -77,7 +72,6 @@ use crate::pipeline::budget::Urgency; use crate::replay::Replay; use crate::residency::Residency; use crate::resource::ResourceKey; -use crate::shadow::{Replaced, Takes}; use crate::used_resources::EncoderKind; use std::collections::BTreeSet; use std::sync::atomic::Ordering; @@ -157,7 +151,7 @@ impl CommandBufferShared { // (`Predication::replaying`). // The merges its first encoding left to runs of passes (`pass_runs.rs`): encoded again, // it leaves them, and keeps after itself what a later pass of a run went on over. - let (residency, runs, first) = { + let (residency, runs) = { let mut state = lock(&self.state); state.replaying_predication = match state.predicated { true => state.predication.replaying(at), @@ -172,18 +166,16 @@ impl CommandBufferShared { }) .collect(); state.replaying_keeps = runs.iter().filter_map(|run| run.keep_after()).collect(); - // Its first encoding's takes of copies taken at use, its segments' among them, - // kept where the encoding again meets them: that encoding's recordings are never - // submitted (`shadow::ShadowSync::over`). - let first = state.takes_of(at); - state.replaced_takes = Some(Replaced::new(first.clone())); - (state.residency_before(at, replay.kind()), runs, first) + // Its first encoding's takes of copies taken at use, taken again where they were: + // that encoding's recording is never submitted (`shadow::Takes`). + state.replaying_takes = state.ended[at].takes.clone(); + (state.residency_before(at, replay.kind()), runs) }; let run = replay.run(&handle, residency); { let mut state = lock(&self.state); state.replaying_keeps.clear(); - state.replaced_takes = None; + state.replaying_takes.clear(); } // Its steps' gates listed as the commit lists the first encoding's. let run = { @@ -236,8 +228,6 @@ impl CommandBufferShared { } Err(unspliced) => { counts.reencode_refused(); - // Its first recordings stay: a take of its own they did not hold goes back. - unspliced.0.all_takes().give_back_unheld(&first); let refusal = "its place holds other parts or work than its encoding again's"; let reset = { let mut state = lock(&self.state); @@ -279,7 +269,7 @@ impl CommandBufferShared { // hold through this turn: only the first submission places segments, and // it waits for the turn; a host step, which records one, takes the turn too. What it // reaches through its resident set its first submission points it at as it lies then. - let alone: Vec<((usize, usize), Deferred, Takes)> = { + let alone: Vec<((usize, usize), Deferred)> = { let state = lock(&self.state); match state.submitted { true => Vec::new(), @@ -294,26 +284,18 @@ impl CommandBufferShared { .filter(|(_, recorded)| !spliced.contains(&recorded.encoder)) .flat_map(|(part, recorded)| { let segments = recorded.segments.iter().enumerate(); - segments.filter(|(_, segment)| moved(segment)).map( - move |(at, segment)| { - let takes = (segment.recorded.as_ref()) - .map(|done| done.takes.clone()) - .unwrap_or_default(); - ((part, at), segment.work.clone(), takes) - }, - ) + segments + .filter(|(_, segment)| moved(segment)) + .map(move |(at, segment)| ((part, at), segment.work.clone())) }) .collect() } } }; - for (place, work, first) in alone { + for (place, work) in alone { // Its notices were announced as it committed (`replay::is_replaying`), and its - // commands take what they use without holding it. It keeps its first recording's - // takes of copies taken at use where it meets them (`shadow::ShadowSync::over`). - lock(&self.state).replaced_takes = Some(Replaced::new(first.clone())); + // commands take what they use without holding it. let again = crate::replay::replaying(|| work.record_on_gpu(&handle)); - lock(&self.state).replaced_takes = None; let counts = &device.shared().counts; let Ok(Some((recorded, inputs))) = again else { counts.reencode_refused(); @@ -324,8 +306,6 @@ impl CommandBufferShared { Ok(()) => counts.segment_recorded_again(), Err(unspliced) => { counts.reencode_refused(); - // The first recording stays: a take of its own it did not hold goes back. - unspliced.0.takes.give_back_unheld(&first); drop(unspliced); } } @@ -342,19 +322,6 @@ impl CommandBufferShared { } impl State { - /// What ended encoder `at`'s recordings decided of their copies taken at use - /// (`shadow::Takes`): its own, then its parts' segments' recordings' in order. - pub(super) fn takes_of(&self, at: usize) -> Takes { - let mut takes = self.ended[at].takes.clone(); - let segments = (self.recorded.iter()) - .filter(|part| part.encoder == at) - .flat_map(|part| &part.segments); - for done in segments.filter_map(|segment| segment.recorded.as_ref()) { - takes.join(done.takes.clone()); - } - takes - } - /// The residency an ended encoder `at` of `kind` started with, as the command buffer's /// encoders ended before it leave it (`CommandBuffer::inherited_residency`): none for a blit /// encoder, which makes nothing resident. @@ -376,11 +343,10 @@ impl State { /// Put `replayed`, ended encoder `at` encoded again, and what it made resident in its place, /// before the submission of its event group: each of its parts' recordings, uses and segments /// (recorded on the GPU alone), its executions (the later encoders' and segments' places - /// among them moved by the difference), its keys, what its commands and its segments' took - /// (held weakly until that submission), and its takes of copies taken at use, a take of the - /// first recordings it did not meet given back. What its first recording retained stays - /// retained, and so does what its first segments recorded and what their host steps needed; - /// its `VkCommandBuffer`s go with the pool unsubmitted. Refused, changing nothing and giving + /// among them moved by the difference), its keys, and what its commands and its segments' + /// took (held weakly until that submission). What its first recording retained stays retained, + /// and so does what its first segments recorded and what their host steps needed; its + /// `VkCommandBuffer`s go with the pool unsubmitted. Refused, changing nothing and giving /// `replayed` back, where its place holds other parts than the encoding again's, or a segment /// but one whose pipelines are being made (which goes, the encoding again having left one of /// its own in its place), work its commit recorded on the GPU alone, a run's merge (which @@ -421,9 +387,6 @@ impl State { if !fits { return Err(Box::new((replayed, residency))); } - // A take of copies taken at use of its first recordings the encoding again did not meet - // goes back: they are never submitted (`shadow::ShadowSync::over`). - self.takes_of(at).give_back_unheld(&replayed.all_takes()); let Replayed { parts: mut replayed_parts, held, @@ -432,7 +395,6 @@ impl State { keys, mut taken, heaps, - takes, } = replayed; // Held weakly until its group's submission, as the commit held what the first recording // and its segments took. @@ -494,7 +456,6 @@ impl State { record.keys = keys; record.held = held; record.taken = taken; - record.takes = takes; if let Some(residency) = residency { if let Some(first) = record.residency.replace(residency) { self.retained.push(Box::new(first)); @@ -509,9 +470,8 @@ impl State { /// before the first submission, with `inputs`, what its host step needs now: what its /// commands took held weakly until the first submission, as the commit holds them. What the first /// recording retained, its executions and its host step's inputs stay retained; its - /// `VkCommandBuffer`s go with the pool unsubmitted, what its commands took, held weakly, - /// goes, and so does a take of copies taken at use of its that `recorded` did not meet, given - /// back. Refused, changing nothing and giving `recorded` and `inputs` back, where the place + /// `VkCommandBuffer`s go with the pool unsubmitted, and what its commands took, held weakly, + /// goes. Refused, changing nothing and giving `recorded` and `inputs` back, where the place /// holds no such segment, or the command buffer was submitted. pub(super) fn splice_segment( &mut self, @@ -531,11 +491,6 @@ impl State { let first = segment.recorded.replace(recorded); let before = segment.inputs.replace(inputs); if let Some(first) = first { - // A take of copies taken at use of the first recording this one did not meet goes - // back (`shadow::ShadowSync::over`). - if let Some(now) = &segment.recorded { - first.takes.give_back_unheld(&now.takes); - } let RecordedSegment { retained, executions, diff --git a/crates/metal2vulkan-runtime/src/encoder.rs b/crates/metal2vulkan-runtime/src/encoder.rs index 12f8cfe65..0117ce470 100644 --- a/crates/metal2vulkan-runtime/src/encoder.rs +++ b/crates/metal2vulkan-runtime/src/encoder.rs @@ -510,22 +510,6 @@ pub(super) struct Replayed { pub(super) keys: BTreeSet, pub(super) taken: Taken, pub(super) heaps: Vec, - /// What its first uses of copies taken at use decided (`shadow::Takes`), its segments' - /// apart: the first encoding's takes kept where it met them. - pub(super) takes: Takes, -} - -impl Replayed { - /// What it decided of copies taken at use, its segments' recordings' after its own - /// (`shadow::Takes`). - pub(super) fn all_takes(&self) -> Takes { - let mut takes = self.takes.clone(); - let segments = self.parts.iter().flat_map(|part| &part.segments); - for done in segments.filter_map(|segment| segment.recorded.as_ref()) { - takes.join(done.takes.clone()); - } - takes - } } /// One part of an encoder encoded again ([`Replayed::parts`]): its `VkCommandBuffer`s, what they @@ -747,6 +731,10 @@ impl EncoderCore { ) -> Result { let mut core = EncoderCore::segment_raw(command_buffer, ordered)?; core.replaying = true; + // Its first uses of copies taken at use take them where its first encoding's did, whose + // recording is never submitted (`shadow::Takes`, `command_buffer/reencode.rs`). + let first = command_buffer.state().replaying_takes.clone(); + core.shadows = ShadowSync::again(first); Ok(core) } @@ -756,7 +744,7 @@ impl EncoderCore { let (raw, keeping, replaced) = { let mut state = command_buffer.state(); let raw = command_buffer.allocate_raw(&mut state)?; - (raw, state.keeping(), state.replaced_takes.clone()) + (raw, state.keeping(), state.step_takes.clone()) }; let device = command_buffer.device().shared().vk(); // A chunk kept for later command buffers (`kept_commands.rs`) may run in several at once. @@ -774,12 +762,9 @@ impl EncoderCore { .counts .encoder_command_buffer_begun(Begun::Segment); let mut core = EncoderCore::over(command_buffer, raw, ordered); - // Work recorded again keeps the takes of copies taken at use of the recordings it - // replaces, which are never submitted (`State::replaced_takes`): a host step's, a - // rebind's encoding again (`command_buffer/reencode.rs`). - if let Some(replaced) = replaced { - core.shadows = ShadowSync::over(replaced); - } + // A host step's recording keeps the takes of the recording it replaces + // (`State::step_takes`); none elsewhere. + core.shadows = ShadowSync::over(replaced); Ok(core) } @@ -2974,7 +2959,6 @@ impl EncoderCore { taken, fails_command_buffer, faults, - shadows, .. } = self; if fails_command_buffer.is_some() || faults.is_some() || taken.dead() { @@ -3033,7 +3017,6 @@ impl EncoderCore { keys, taken, heaps, - takes: shadows.into_takes(), }) } } diff --git a/crates/metal2vulkan-runtime/src/shadow.rs b/crates/metal2vulkan-runtime/src/shadow.rs index 6824e03c1..7becfd061 100644 --- a/crates/metal2vulkan-runtime/src/shadow.rs +++ b/crates/metal2vulkan-runtime/src/shadow.rs @@ -243,29 +243,28 @@ //! they are when the command buffer runs, after its commit. Every other use copies nothing in, //! whatever wrote the bytes, and nothing written through the image is copied back or merged: it //! stays in the image, as a Mac's texture's own memory keeps it. A use whose encoding is left -//! out of its command buffer's work ([`ShadowSync::forget`]) leaves the copy to the next use. -//! Work recorded again in place of a recording never submitted takes the copy where that -//! recording took it, keeping its take, and leaves the mark as it finds it there: a host step's -//! recording of work its commit recorded (`CommandBufferShared::host_step`), and a rebind's -//! encoding again of an encoder, its segments among it, or its recording again of work its -//! commit recorded on the GPU alone (`command_buffer/reencode.rs`). A use that recording did not -//! meet decides by the mark, and a take of that recording no use meets is given back -//! ([`ShadowSync::over`], [`Takes::give_back_unheld`]). A take whose encoder runs nothing, its -//! command buffer failed before it ran, is given back: as its part is failed (committed as -//! failed, an encoder a failure names, a submission that runs nothing, `State::fail_part`), or -//! as its batch's submission fails, a host step's recording or the `vkQueueSubmit` among it -//! (`State::give_back_from`). The next use takes the copy, where that take is still the -//! texture's latest and nothing set the mark since ([`Takes::give_back`]). An encoder of +//! out of its command buffer's work ([`ShadowSync::forget`]) leaves the copy to the next use. An +//! encoder a rebind encodes again (`command_buffer/reencode.rs`), whose first recording is never +//! submitted, takes the copy where its first encoding took it and leaves the mark as it finds it +//! ([`Takes`]). A take whose encoder runs nothing, its command buffer failed before it ran, is +//! given back: as its part is failed (committed as failed, an encoder a failure names, a +//! submission that runs nothing, `State::fail_part`), or as its batch's submission fails, a host +//! step's recording or the `vkQueueSubmit` among it (`State::give_back_from`). The next use +//! takes the copy, where that take is still the texture's latest and nothing set the mark since +//! ([`Takes::give_back`]). An encoder of //! several parts (split at a host step) gives back every take of its own where any of its parts //! runs nothing, so one that ran in an earlier part is taken again at the next use //! (docs/FAST-PATHS.md, known gaps). A command buffer dropped without a commit gives back every -//! take of its ended encoders (`CommandBufferShared`'s drop). +//! take of its ended encoders (`CommandBufferShared`'s drop). Work its commit recorded and its +//! host step records again (`CommandBufferShared::host_step`), the commit's recording never +//! submitted, takes the copy where the commit's recording took it, keeping that take, and +//! decides a use that recording did not meet by the mark; a take of that recording the step's +//! does not meet is given back ([`ShadowSync::over`], [`Takes::give_back_unheld`]). //! For a format `generate_mipmaps` leaves as it is or refuses, the copy in moves the first level //! alone and the later levels keep what they hold (docs/FAST-PATHS.md, known gaps). use super::blit_texture::announce_mipmaps; use super::buffer::{Buffer, CallerMemory, WeakBuffer}; -use super::device::lock; use super::dirty_pages::{CopyInGate, ShadowLog}; use super::error::{Error, RuntimeGap}; use super::image_plan::{ImageFacts, ImagePlan}; @@ -295,7 +294,7 @@ use metal2vulkan::error::{Feature, Unsupported}; use metal2vulkan::metal::PixelFormat; use std::ops::Range; use std::sync::atomic::{AtomicU64, Ordering}; -use std::sync::{Arc, Mutex, Weak}; +use std::sync::{Arc, Weak}; /// What a shadowed texture's copies need: its truth, its shadow, and the copies between them. pub(super) struct ShadowCopies { @@ -2962,9 +2961,9 @@ struct Entry { /// changed. stale: Option<[u32; 4]>, /// The number of the take of the copy at use of a texture whose shadow is one - /// ([`ShadowCopies::levels`]) the encoder's use took, by the mark ([`LevelsCopy::take`]) or - /// kept from a recording it replaces ([`ShadowSync::over`]): given back where what it - /// recorded is left out ([`ShadowSync::forget`]). `None` where it took none. + /// ([`ShadowCopies::levels`]) the encoder's use took by the mark ([`LevelsCopy::take`]): + /// given back where what it recorded is left out ([`ShadowSync::forget`]). `None` where it + /// took none so, an encoding again's take among them. took: Option, } @@ -3185,6 +3184,11 @@ pub(super) struct Took { } impl Takes { + /// None decided: an encoder that met no copy taken at use. + pub(super) fn clear(&mut self) { + self.0.clear(); + } + /// `other`'s, decided after these, joined after them. pub(super) fn join(&mut self, other: Takes) { self.0.extend(other.0); @@ -3225,60 +3229,45 @@ impl Took { } } -/// The decisions of copies taken at use ([`Takes`]) of recordings never submitted that work is -/// recorded again in place of, those no use recorded in their place met yet, in their order: -/// shared by every core recorded in their place ([`ShadowSync::over`]), each first use of a -/// texture among them meeting the first of its texture's left (`State::replaced_takes`). -#[derive(Clone, Debug)] -pub(super) struct Replaced(Arc>); - -impl Replaced { - /// `takes`, none of them met yet. - pub(super) fn new(takes: Takes) -> Replaced { - Replaced(Arc::new(Mutex::new(takes))) - } - - /// Meet the first decision left of the texture of `key`, its take where it took the copy; - /// `None` where none is left. - fn meet(&self, key: ResourceKey) -> Option> { - let mut takes = lock(&self.0); - let at = takes.0.iter().position(|(met, _)| *met == key)?; - Some(takes.0.remove(at).1) - } -} - -/// How an encoder's first uses of a copy taken at use decide whether they take it: where the -/// texture's mark asks ([`LevelsCopy::take`], which clears it), each decision noted. Recorded in -/// place of recordings never submitted ([`ShadowSync::over`]), a use that meets a decision of -/// theirs decides as it did, keeping its take, and is noted so; only the others ask the mark. -#[derive(Default)] -struct TakeBy { - /// The decisions of the recordings this one is recorded in place of, where it is. - replaced: Option, - /// What its first uses decided, in order. - noted: Takes, +/// How an encoder's first uses of a copy taken at use decide whether they take it. +enum TakeBy { + /// As the program encodes it: where the texture's mark asks ([`LevelsCopy::take`], which + /// clears it), each decision noted. Recorded in place of a recording that decided `replaced` + /// ([`ShadowSync::over`]), a use that one met decides as it did, keeping its take, and + /// noted so; only the others ask the mark. + Mark { replaced: Takes, noted: Takes }, + /// Encoded again (`command_buffer/reencode.rs`): as the use in its place in the first + /// encoding decided, the first encoding's decisions not met yet held here. The first + /// recording is never submitted, so its take is this one's; the mark is left as it is found, + /// for the next use encoded after a later `Texture::did_modify_data`. + Again(Takes), } impl TakeBy { /// Whether this first use in the encoder of `copies`, whose copy is `levels`, takes the copy, - /// and the take's number where it takes it by the mark or keeps the take of a recording it - /// replaces. + /// and the take's number where it takes it by the mark or keeps the take of the recording it + /// replaces (none for an encoding again's). fn take(&mut self, copies: &Arc, levels: &LevelsCopy) -> (bool, Option) { let key = copies.shadow_key; - let kept = self - .replaced - .as_ref() - .and_then(|replaced| replaced.meet(key)); - let took = match kept { - Some(took) => took, - None => levels.take().map(|number| Took { - copies: Arc::downgrade(copies), - number, - }), - }; - let number = took.as_ref().map(|took| took.number); - self.noted.0.push((key, took)); - (number.is_some(), number) + match self { + TakeBy::Mark { replaced, noted } => { + let took = match replaced.0.iter().position(|(met, _)| *met == key) { + Some(at) => replaced.0.remove(at).1, + None => levels.take().map(|number| Took { + copies: Arc::downgrade(copies), + number, + }), + }; + let number = took.as_ref().map(|took| took.number); + noted.0.push((key, took)); + (number.is_some(), number) + } + // A use the first encoding did not meet takes nothing, as it did not. + TakeBy::Again(first) => match first.0.iter().position(|(met, _)| *met == key) { + Some(at) => (first.0.remove(at).1.is_some(), None), + None => (false, None), + }, + } } } @@ -3291,34 +3280,49 @@ impl ShadowSync { entries: Vec::new(), carry, tally: CarryTally::default(), - takes: TakeBy::default(), + takes: TakeBy::Mark { + replaced: Takes::default(), + noted: Takes::default(), + }, } } - /// A core that records work again in place of recordings never submitted, whose decisions of - /// their copies taken at use no core in their place met yet are `replaced`: a host step's - /// recording of work its commit recorded (`CommandBufferShared::host_step`), a rebind's - /// encoding again of an encoder and its segments, and its recording again of work its commit - /// recorded on the GPU alone (`command_buffer/reencode.rs`). Each of its first uses that meets - /// a decision of theirs takes the copy where that one took it, keeping its take; any other - /// where the texture's mark asks. A take of theirs no use meets is given back as their - /// recordings are replaced ([`Takes::give_back_unheld`]). Nothing is carried: every other - /// texture copies in at its first use. - pub(super) fn over(replaced: Replaced) -> ShadowSync { + /// A core that records work again in place of a recording that decided `replaced` of its + /// copies taken at use ([`Takes`]), which never runs: a host step's recording of work its + /// commit recorded (`CommandBufferShared::host_step`). Each of its first uses that recording + /// met takes the copy where it took it, keeping its take; any other where the texture's mark + /// asks. A take of `replaced` it never meets is given back as its recording replaces that + /// one ([`Takes::give_back_unheld`]). Nothing is carried: every other texture copies in at + /// its first use. + pub(super) fn over(replaced: Takes) -> ShadowSync { ShadowSync { - takes: TakeBy { - replaced: Some(replaced), + takes: TakeBy::Mark { + replaced, noted: Takes::default(), }, ..ShadowSync::default() } } + /// An encoder encoded again (`command_buffer/reencode.rs`), whose first encoding decided + /// `first` of its copies taken at use ([`Takes`]): each of its first uses of such a texture + /// takes the copy where the use in its place there took it, the texture's mark untouched. + /// Nothing is carried: every other texture copies in at its first use. + pub(super) fn again(first: Takes) -> ShadowSync { + ShadowSync { + takes: TakeBy::Again(first), + ..ShadowSync::default() + } + } + /// What its first uses of copies taken at use decided, as the program encoded them or as a - /// recording in place of others kept them ([`over`](Self::over)), for a recording of the - /// work again and for a give-back. + /// recording in place of another kept them ([`over`](Self::over)), for an encoding of the + /// encoder again ([`again`](Self::again)) and for a give-back; none for an encoding again. pub(super) fn into_takes(self) -> Takes { - self.takes.noted + match self.takes { + TakeBy::Mark { noted, .. } => noted, + TakeBy::Again(_) => Takes::default(), + } } /// How the encoder's first copies in since this was last called stood against their images' @@ -3578,8 +3582,8 @@ impl ShadowSync { None => (Standing::Unread, None, None), }; // A copy taken at use is copied in at the first use after its making or its - // `did_modify_data`, wherever it is; else its image holds what it took. Recorded - // again, where the recording it replaces took it ([`TakeBy`]). + // `did_modify_data`, wherever it is; else its image holds what it took. Encoded + // again, where its first encoding took it ([`TakeBy`]). let (took, number) = match &copies.levels { Some(levels) => self.takes.take(copies, levels), None => (false, None), @@ -4113,7 +4117,8 @@ impl ShadowSync { /// copy in there moved, and nothing written through one there ran. A later command copies in /// again. pub(super) fn forget(&mut self) { - // A copy taken at use whose copy in is left out is taken at the next use instead. + // A copy taken at use whose copy in is left out is taken at the next use instead. An + // encoding again took none by the mark, and gives none back to it. for entry in &self.entries { if let (Some(number), Some(levels)) = (entry.took, &entry.copies.levels) { levels.give_back(number); diff --git a/crates/metal2vulkan-runtime/src/tests/shadow.rs b/crates/metal2vulkan-runtime/src/tests/shadow.rs index 4677e5efa..e0a5fa6b9 100644 --- a/crates/metal2vulkan-runtime/src/tests/shadow.rs +++ b/crates/metal2vulkan-runtime/src/tests/shadow.rs @@ -5,9 +5,9 @@ use super::super::host_aliases::{self, Alias}; use super::super::key_hash::KeyMap; use super::super::resource::ResourceKey; use super::super::shadow::{ - self, Backing, CopyCause, ImageTruth, KeptArea, LaterLevels, LevelsCopy, Lost, Replaced, - ShadowBuffer, ShadowCarry, ShadowCopies, ShadowCopy, ShadowSource, ShadowSync, ShadowTarget, - ShadowUse, Step, Within, + self, Backing, CopyCause, ImageTruth, KeptArea, LaterLevels, LevelsCopy, Lost, ShadowBuffer, + ShadowCarry, ShadowCopies, ShadowCopy, ShadowSource, ShadowSync, ShadowTarget, ShadowUse, Step, + Within, }; use super::super::shadow_merge::ScratchSpares; use super::super::tracker::{Access, Use, UseRange}; @@ -2416,18 +2416,15 @@ fn taken_at_use(buffer: ResourceKey, bytes: Range) -> Arc { } /// A copy taken at use is taken by the first use encoded after its mark, which clears it. An -/// encoding of an encoder again (`command_buffer/reencode.rs`, `ShadowSync::over`) takes it where -/// its first encoding took it, keeping that take, and not where it did not, whatever the mark, -/// which it leaves as it finds it: a `did_modify_data` after the first encoding is the next use's -/// to take. The cores recorded in place of the first share its decisions (`Replaced`): the first -/// use of the texture among them meets its take, and another decides by the mark. +/// encoding of an encoder again (`command_buffer/reencode.rs`) takes it where its first encoding +/// took it and not where it did not, whatever the mark, which it leaves as it finds it: a +/// `did_modify_data` after the first encoding is the next use's to take. #[test] fn an_encoding_again_takes_a_copy_taken_at_use_where_its_first_encoding_took_it() { let t = taken_at_use(ResourceKey::new(), 0..4096); let k = t.shadow_key; let levels = t.levels.as_ref().expect("a copy taken at use"); let first_use = |sync: &mut ShadowSync| moved(&planned(sync, &mut 0, &[(&t, false)], &[])); - let again = |takes| ShadowSync::over(Replaced::new(takes)); // The first encoding takes it at its first use alone. let mut first = ShadowSync::default(); assert_eq!(first_use(&mut first), [Moved::Into(k)]); @@ -2438,24 +2435,17 @@ fn an_encoding_again_takes_a_copy_taken_at_use_where_its_first_encoding_took_it( assert_eq!(first_use(&mut later), []); let took_none = later.into_takes(); // Encoded again, the first takes it again, and the mark stays clear. - let mut once = again(took.clone()); - assert_eq!(first_use(&mut once), [Moved::Into(k)]); - assert_eq!(first_use(&mut once), []); - // It keeps the take: encoded again in its turn, it takes the copy there too. - assert_eq!(first_use(&mut again(once.into_takes())), [Moved::Into(k)]); + let mut again = ShadowSync::again(took.clone()); + assert_eq!(first_use(&mut again), [Moved::Into(k)]); + assert_eq!(first_use(&mut again), []); + // An encoding again notes no take of its own. + assert_eq!(first_use(&mut ShadowSync::again(again.into_takes())), []); assert_eq!(first_use(&mut ShadowSync::default()), []); - // Two cores in place of the first meet its take once. - let shared = Replaced::new(took.clone()); - assert_eq!( - first_use(&mut ShadowSync::over(shared.clone())), - [Moved::Into(k)] - ); - assert_eq!(first_use(&mut ShadowSync::over(shared)), []); // After a `did_modify_data`, the later one encoded again takes nothing and the first takes it, // as each did; the mark stays for the next use encoded. levels.mark_stale(); - assert_eq!(first_use(&mut again(took_none)), []); - assert_eq!(first_use(&mut again(took)), [Moved::Into(k)]); + assert_eq!(first_use(&mut ShadowSync::again(took_none)), []); + assert_eq!(first_use(&mut ShadowSync::again(took)), [Moved::Into(k)]); assert_eq!(first_use(&mut ShadowSync::default()), [Moved::Into(k)]); assert_eq!(first_use(&mut ShadowSync::default()), []); } @@ -2527,7 +2517,7 @@ fn a_recording_in_place_of_another_keeps_its_takes() { assert_eq!(first_use(&mut commit, &t), [Moved::Into(kt)]); let took = commit.into_takes(); // The step's takes t's where the commit's took it, the mark clear, and u's by its mark. - let mut step = ShadowSync::over(Replaced::new(took.clone())); + let mut step = ShadowSync::over(took.clone()); assert_eq!(first_use(&mut step, &t), [Moved::Into(kt)]); assert_eq!(first_use(&mut step, &u), [Moved::Into(ku)]); let kept = step.into_takes(); @@ -2544,7 +2534,7 @@ fn a_recording_in_place_of_another_keeps_its_takes() { let mut commit = ShadowSync::default(); assert_eq!(first_use(&mut commit, &t), [Moved::Into(kt)]); let took = commit.into_takes(); - let step = ShadowSync::::over(Replaced::new(took.clone())); + let step = ShadowSync::::over(took.clone()); took.give_back_unheld(&step.into_takes()); assert_eq!(first_use(&mut ShadowSync::default(), &t), [Moved::Into(kt)]); // A use the commit's met and took nothing at takes nothing after a `did_modify_data`, which @@ -2553,9 +2543,6 @@ fn a_recording_in_place_of_another_keeps_its_takes() { assert_eq!(first_use(&mut commit, &t), []); let took_none = commit.into_takes(); levels.mark_stale(); - assert_eq!( - first_use(&mut ShadowSync::over(Replaced::new(took_none)), &t), - [] - ); + assert_eq!(first_use(&mut ShadowSync::over(took_none), &t), []); assert_eq!(first_use(&mut ShadowSync::default(), &t), [Moved::Into(kt)]); } diff --git a/crates/metal2vulkan-runtime/src/tests/tiled_texture_reencode.rs b/crates/metal2vulkan-runtime/src/tests/tiled_texture_reencode.rs index 9b3fb9fb9..3a924e8bf 100644 --- a/crates/metal2vulkan-runtime/src/tests/tiled_texture_reencode.rs +++ b/crates/metal2vulkan-runtime/src/tests/tiled_texture_reencode.rs @@ -17,10 +17,11 @@ //! take that call's mark, so the next command buffer takes the copy again. //! - **A pass recorded on the GPU alone** (it executes indirect commands the GPU writes, //! `render/executions/gpu.rs`), whose indexed draw after the execution reads the texture and -//! takes its indices from the buffer: the commit records the execution's instance, the draw -//! among it, in a segment, and the encoding again records it again in a segment of its own, -//! which takes the copy where the commit's took it (`EncoderCore::finish_replay`), so the draw -//! reads the bytes. +//! takes its indices from the buffer: the commit records the pass in a segment, and the encoding +//! again records it again in a segment of its own (`EncoderCore::finish_replay`). The pass's +//! copies are planned by its encoder as the pass ends, the take among them, so the encoding again +//! takes the copy where the first encoding took it, its segment records the copy in, and the +//! draw reads the bytes. //! //! 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. Printed (`TILED-REENCODE`): each leg's @@ -344,8 +345,8 @@ fn a_pass_on_the_gpu_alone_encoded_again_takes_the_copy_where_its_commit_took_it let mut encoder = (command_buffer.render_command_encoder(&pass(&target))).unwrap(); encoder.set_render_pipeline_state(&inherited).unwrap(); encoder.execute_commands_in_buffer(&icb, 0..1).unwrap(); - // The texture's first use, after the execution in its instance, which the segment - // records: by the draw whose indices the buffer the rebind moves holds. + // The texture's first use, after the execution in the instance the segment records: by + // the draw whose indices the buffer the rebind moves holds. encoder.set_render_pipeline_state(&sampled).unwrap(); (encoder.set_fragment_texture(Some(&texture), 0)).unwrap(); (encoder.draw_indexed_primitives( diff --git a/crates/metal2vulkan-runtime/src/used_resources.rs b/crates/metal2vulkan-runtime/src/used_resources.rs index 394ec4b2e..5cf17cc9d 100644 --- a/crates/metal2vulkan-runtime/src/used_resources.rs +++ b/crates/metal2vulkan-runtime/src/used_resources.rs @@ -115,10 +115,10 @@ pub(super) struct EncoderRecord { /// encodes it again from them. Kept, with what they hold, until the command buffer's release /// (`CommandBufferShared::complete`); `None` where it cannot be encoded again, or need not. pub(super) replay: Option>, - /// What its first uses of copies taken at use decided, as the program encoded it or as its - /// encoding again kept them, and its placed segments' recordings' after them: an encoding of - /// it again takes each as they did, and a part of it that runs nothing gives its takes back - /// (`shadow::Takes`, `State::fail_part`, `State::give_back_from`). + /// What its first uses of copies taken at use decided as the program encoded it, and its + /// placed segments' recordings' after them: an encoding of it again takes each as they did, + /// and a part of it that runs nothing gives its takes back (`shadow::Takes`, + /// `State::fail_part`, `State::give_back_from`). pub(super) takes: crate::shadow::Takes, /// Its executions' place among the command buffer's (`State::executions`). pub(super) executions: std::ops::Range,