diff --git a/crates/metal2vulkan-runtime/src/shadow.rs b/crates/metal2vulkan-runtime/src/shadow.rs index 67051f481..7aaa8e623 100644 --- a/crates/metal2vulkan-runtime/src/shadow.rs +++ b/crates/metal2vulkan-runtime/src/shadow.rs @@ -333,6 +333,16 @@ impl Backing { } } +/// The image an image's shadow holds a copy of ([`ShadowSource::Image`]). Its copies name the +/// image's `VkImage` as each is recorded, not as the shadow was made: a texture's storage form +/// swaps its image's `VkImage` for one with `STORAGE` and destroys the first as the swapping +/// command buffer completes (`texture/storage_form.rs`), and a shadow made before the swap (a +/// slot binding's usage shadow, a view's) copies the image the texture holds from then on. +pub(super) trait ImageTruth: Send + Sync { + /// The image's `VkImage` now. + fn raw(&self) -> vk::Image; +} + /// A shadow's truth: what the shadow holds a copy of between an encoder's copies (the module's /// rules, with the truth in the buffer's place). pub(super) enum ShadowSource { @@ -356,7 +366,8 @@ pub(super) enum ShadowSource { /// view presents between the two, the same subresources, texel for texel (formats of one copy /// unit, whose copies keep every bit). Image { - image: vk::Image, + /// The image, whose `VkImage` each copy names as it is recorded ([`ImageTruth`]). + image: Arc, /// The image's identity. key: ResourceKey, /// The image's levels and layers the view presents. @@ -1910,9 +1921,9 @@ impl ShadowCopy { .. } => { let (from, to) = if into_shadow { - (*image, *shadow) + (image.raw(), *shadow) } else { - (*shadow, *image) + (*shadow, image.raw()) }; if let Some(through) = through { let (buffer, _) = through.buffer.at(0); diff --git a/crates/metal2vulkan-runtime/src/tests/shadow.rs b/crates/metal2vulkan-runtime/src/tests/shadow.rs index 5ba5fbbb6..42e52133d 100644 --- a/crates/metal2vulkan-runtime/src/tests/shadow.rs +++ b/crates/metal2vulkan-runtime/src/tests/shadow.rs @@ -5,8 +5,8 @@ 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, KeptArea, Lost, ShadowBuffer, ShadowCarry, ShadowCopies, ShadowCopy, - ShadowSource, ShadowSync, ShadowTarget, ShadowUse, Step, Within, + self, Backing, CopyCause, ImageTruth, KeptArea, Lost, ShadowBuffer, ShadowCarry, ShadowCopies, + ShadowCopy, ShadowSource, ShadowSync, ShadowTarget, ShadowUse, Step, Within, }; use super::super::shadow_merge::ScratchSpares; use super::super::tracker::{Access, Use, UseRange}; @@ -1431,6 +1431,15 @@ fn a_refused_scratch_changes_nothing() { ); } +/// An image no copy is recorded with: these tests track uses alone. +struct NoImage; + +impl ImageTruth for NoImage { + fn raw(&self) -> vk::Image { + vk::Image::null() + } +} + /// A shadow of `levels` and `layers` of the image `image`: a texture view of another component /// layout on a device whose Vulkan views reinterpret none (`texture/view_shadow.rs`). fn view_of(image: ResourceKey, levels: Range, layers: Range) -> Arc { @@ -1441,7 +1450,7 @@ fn view_of(image: ResourceKey, levels: Range, layers: Range) -> Arc vk::Image { + self.own_raw() + } +} + impl Drop for Image { fn drop(&mut self) { // Once the process is exiting, the image is left to its end (`exit_guard`). diff --git a/crates/metal2vulkan-runtime/src/texture/storage_form.rs b/crates/metal2vulkan-runtime/src/texture/storage_form.rs index 938960e33..4bc71c169 100644 --- a/crates/metal2vulkan-runtime/src/texture/storage_form.rs +++ b/crates/metal2vulkan-runtime/src/texture/storage_form.rs @@ -84,7 +84,10 @@ //! encoders name the image the texture has then, their uses after the copy in hazard //! tracking. It waits at most [`SWITCH_WAIT`], and not at all on the scheduler's thread (a //! submission check that makes a command buffer): past that, it gives the switch up, so -//! nothing swaps, and goes on with the old image. +//! nothing swaps, and goes on with the old image. A shadow of the image made before the swap +//! (a slot binding's usage shadow, as a draw reading its own pass's color attachment binds, +//! or a view's) names the image's `VkImage` as each of its copies is recorded +//! (`shadow::ImageTruth`), so its later copies take the image with `STORAGE`. //! - **Once per texture,** by construction: the storage form is a `OnceLock` of the image, which //! is noted at most once. A switch the device refuses (the image's limits, memory) leaves the //! texture its scratch, for good; a commit that fails or is given up leaves it waiting. diff --git a/crates/metal2vulkan-runtime/src/texture/view_shadow.rs b/crates/metal2vulkan-runtime/src/texture/view_shadow.rs index 2e174d8fe..94aa48f08 100644 --- a/crates/metal2vulkan-runtime/src/texture/view_shadow.rs +++ b/crates/metal2vulkan-runtime/src/texture/view_shadow.rs @@ -61,7 +61,7 @@ use crate::image_plan::plan_image; use crate::image_plan::{copies_between, takes_views_of}; use crate::memory::Placement; use crate::resource::{Identity, ResourceKey}; -use crate::shadow::{Backing, ImageThrough, ShadowCopies, ShadowSource}; +use crate::shadow::{Backing, ImageThrough, ImageTruth, ShadowCopies, ShadowSource}; use crate::shadow_merge::ScratchSpares; use crate::texture::{copy_units, image_error, texture_aspects}; use crate::texture_descriptor::{TextureDescriptor, TextureLayout}; @@ -469,7 +469,7 @@ impl Device { tracked: base.identity.tracked, }; let (truth, truth_key, truth_range) = ( - base.own_raw(), + Arc::clone(base) as Arc, base.identity.key, range(texture_aspects(base.plan())), );