diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index 5fe9e2fbd..bf96dbe35 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -837,8 +837,9 @@ meanwhile wait for it. - The recovery carries the events, the fences, the depth/stencil states, the libraries and their functions, the address pools (`AddressPool`, whose slots take buffers after it as before), the uses of guest RAM (`HostRamUse`), the no-copy buffers, the `Private` buffers, the buffers in the - runtime's own pages and the `Private` heaps with the buffers placed in them to the new - `VkDevice`: the same objects, at the same addresses. + runtime's own pages, the `Private` heaps with the buffers placed in them, the textures of + `new_texture`, the textures over the buffers it carried and the views of either to the new + `VkDevice`: the same objects, at the same addresses and resource IDs. An event keeps the value the host saw and its listeners' notifications. A buffer in the runtime's own pages keeps its bytes and its `contents` pointer: a long host-visible buffer's fresh pages, and, on a device whose checks found that a held import of host pages costs its @@ -852,7 +853,11 @@ meanwhile wait for it. into the device. Its deallocator runs at its release once no `VkDevice` imports its pages. A `Private` buffer's contents are lost: it reads zero. So are a `Private` heap's, whose buffers placed before go on with it and in which buffers and textures are made again; the textures it - made before are refused, as every texture made before the recovery is. + made before are refused. A texture of `new_texture` is made again in new memory, so its + contents are lost (it reads as a new texture of its descriptor: refill one filled once and + kept); one over a carried buffer is made again over the buffer's bytes, and reads them; a view + views its parent there. Their images on the lost `VkDevice` stay with them, and keep it alive, + until they go. - Any other object made before the recovery is refused where it meets the new `VkDevice` (an encoder's bind, a pipeline made from its functions) and in its own calls that need its lost one: `Error::NotImplemented(RuntimeGap::MadeBeforeRecovery)`. That covers pooled `Shared` and @@ -860,13 +865,16 @@ meanwhile wait for it. mapping (on a device that imports no host pointer, or whose checks found that a held import costs its submissions or that textures over such pages take less, or had not answered; and a `Managed` buffer without unified memory), detached no-copy buffers, `Shared`, no-copy and - sparse heaps with the buffers placed in them, textures, pipeline states, buffers over the - caller's `VkBuffer`, and exportable memory or events. Make it again. Metal's objects go on. The - recovery's notice counts the buffers, heaps and events it carried and left, by kind. + sparse heaps with the buffers placed in them, heaps' textures, textures over the caller's + `VkImage`, sparse and shareable textures, textures over buffers left and their views, pipeline + states, buffers over the caller's `VkBuffer`, and exportable memory or events. Make it again. + Metal's objects go on. The recovery's notice counts the buffers, heaps, textures and events it + carried and left, by kind. - The lost `VkDevice` is destroyed once the objects left on it went and, where `Device::raw` answered its handles, a later `raw` call answered the new one's: `WorkCounts::vk_devices_live` - reads 2 until then. A carried object holds nothing of it once none of its command buffers - records. `vk_devices_made` and `device_recoveries` count the rest. + reads 2 until then. A carried object but a texture holds nothing of it once none of its + command buffers records; a carried texture holds it until the texture goes. `vk_devices_made` + and `device_recoveries` count the rest. - An object's `device` is a generation handle: of the `VkDevice` it was made on, else of the one a recovery carried it to last. A handle taken of it before the recovery keeps meaning the lost `VkDevice`: its `raw` answers that one's handles, kept alive while the consumer holds the diff --git a/crates/metal2vulkan-runtime/src/buffer_texture.rs b/crates/metal2vulkan-runtime/src/buffer_texture.rs index ba6e149d8..8ece0ec24 100644 --- a/crates/metal2vulkan-runtime/src/buffer_texture.rs +++ b/crates/metal2vulkan-runtime/src/buffer_texture.rs @@ -73,6 +73,7 @@ use super::shadow_copy_back::WordView; use super::shadow_merge::ScratchSpares; use super::shadow_merge::UnormView; use super::shadow_standing::StandingAcross; +use super::texture::carry::Remake; use super::texture::surface_two_planes; use super::texture::{IdUse, Texture}; use super::texture_descriptor::{ @@ -850,7 +851,36 @@ impl Buffer { if let Some(heap) = self.heap() { heap.hold_texture(&texture); } - Ok(texture) + if whose == Whose::Runtime { + return Ok(texture); + } + let remake = Remake::Over { + buffer: self.clone(), + call, + descriptor: *descriptor, + offset, + bytes_per_row, + form, + ycbcr: ycbcr_surface, + }; + let device = texture.device().clone(); + Ok(device.kept_texture(texture, remake)) + } + + /// The texture over the buffer that `call` made through `form`, of `descriptor` at `over` + /// (its offset and bytes per row), over a surface of `ycbcr_surface`'s facts where given, made + /// again as the runtime's own, which takes no ID: a program's texture over the buffer, on + /// the generation a recovery carried the buffer to (`texture/carry.rs`). + pub(super) fn texture_over_again( + &self, + call: &'static str, + descriptor: &TextureDescriptor, + (offset, bytes_per_row): (u64, u64), + form: BufferTextureCall, + ycbcr_surface: Option, + ) -> Result { + let made = (form, Whose::Runtime); + self.texture_over(call, descriptor, offset, bytes_per_row, made, ycbcr_surface) } /// [`texture_over`](Self::texture_over)'s texture, at `offset` with `bytes_per_row` (`over`), diff --git a/crates/metal2vulkan-runtime/src/degradation.rs b/crates/metal2vulkan-runtime/src/degradation.rs index 658a0d381..c08689e66 100644 --- a/crates/metal2vulkan-runtime/src/degradation.rs +++ b/crates/metal2vulkan-runtime/src/degradation.rs @@ -2310,10 +2310,12 @@ degradations! { of guest RAM, no-copy buffers, `Private` buffers, buffers in the runtime's own pages \ (fresh pages, and the blocks of pages the `Shared` and `Managed` buffers lie in where \ the device's checks found a held host-page import costs its submissions nothing and \ - textures over such pages take what they take over its own memory) and `Private` \ - heaps with the buffers placed in them made before it go on, a `Private` buffer's or \ - heap's contents lost (it reads zero); the other objects made before it are refused \ - (`MadeBeforeRecovery`), where Metal's go on; the calls during it wait for it"; + textures over such pages take what they take over its own memory), `Private` heaps \ + with the buffers placed in them, textures of `new_texture`, textures over the \ + buffers carried and views of them made before it go on, the contents of a `Private` \ + buffer or heap lost (it reads zero) and of a texture of `new_texture` (it reads as a \ + new one); the other objects made before it are refused (`MadeBeforeRecovery`), \ + where Metal's go on; the calls during it wait for it"; /// Apple's private device properties the device has no answer for /// (`private_properties.rs`): no document describes them and nothing the device reports /// maps to them. Announced once, when `Device::private_properties` is first read; the diff --git a/crates/metal2vulkan-runtime/src/device/carry.rs b/crates/metal2vulkan-runtime/src/device/carry.rs index a3d0cb72c..dd22328d2 100644 --- a/crates/metal2vulkan-runtime/src/device/carry.rs +++ b/crates/metal2vulkan-runtime/src/device/carry.rs @@ -1,13 +1,15 @@ //! What a device's recovery carries to its next generation (`line.rs`): the program's events, its //! uses of guest RAM, its no-copy buffers, the buffers of the runtime's memory whose bytes no -//! pointer of the program's reaches or whose pages the runtime owns, and its `Private` heaps with -//! the buffers placed in them, each the same object on the new `VkDevice`, as Metal keeps its -//! objects across its GPU's recovery. A fence, a depth/stencil state, a library, a function and -//! an address pool hold no Vulkan object (`fence.rs`, `depth_stencil.rs`, `library.rs`, +//! pointer of the program's reaches or whose pages the runtime owns, its `Private` heaps with +//! the buffers placed in them, and its textures made by a call the recovery makes again +//! (`texture/carry.rs`), each the same object on the new `VkDevice`, as Metal keeps its objects +//! across its GPU's recovery. A fence, a depth/stencil state, a library, a function and an +//! address pool hold no Vulkan object (`fence.rs`, `depth_stencil.rs`, `library.rs`, //! `address_pool.rs`): the recovery carries their handle of the device alone ([`LineDevice`]). //! -//! - **Kept as made.** Each event (`EventShared::new`) and heap (`Device::new_heap`) is kept here, -//! held weakly, by the generation it was made on; each buffer the program made of its own (`Device::visible`) is +//! - **Kept as made.** Each event (`EventShared::new`), heap (`Device::new_heap`) and texture of +//! the program's (`Texture::made`) is kept here, held weakly, by the generation it was made on; +//! each buffer the program made of its own (`Device::visible`) is //! kept among the generation's program resources already (`Owners::buffer`), which the //! recovery reads ([`Carry::take`]), so making one costs a load of a flag more and no lock. //! - **Carried before the next generation serves.** The recovery takes the lost generation's live @@ -19,7 +21,8 @@ //! generation's objects its maker carries ([`Device::carry_late`]). The take names the buffers //! it took under the registry's lock, which a maker that finds the generation taken asks //! ([`Carry::late_buffer`]), and an event or heap is kept under it, so each object is carried -//! once, by one or the other. A buffer placed in a heap as the heap is carried finds its bytes +//! once, by one or the other; a texture's maker sets how it is made again before it asks +//! ([`Carry::late_texture`]), and a texture carried already is carried no more. A buffer placed in a heap as the heap is carried finds its bytes //! carried under the lock the heap's carry takes its buffers under, and carries itself //! (`Heap::carry`). //! - **What each kind becomes.** An event: a new timeline semaphore at the value the host saw @@ -41,7 +44,11 @@ //! (it reads zero), its identity kept as a buffer's, registered there by its key; each buffer //! placed in it that lives, the same buffer there at its offset in the heap's carried bytes, //! its identity and aliasable state kept, its range in an automatic heap given back once, by its -//! parts on the generation it was carried to last (`Heap::carry`, `Buffer::carry_placed`). +//! parts on the generation it was carried to last (`Heap::carry`, `Buffer::carry_placed`). A +//! texture, after the heaps: its call made again there as a texture of the runtime's own, which +//! holds its parts there, a view's after its parent's; a texture of its own image's contents +//! lost, one over a carried buffer reading the buffer's bytes; its identity, resource ID, +//! label and purgeable state kept (`Texture::carry`). //! - **What stays the lost generation's**, refused where it meets the next //! (`RuntimeGap::MadeBeforeRecovery`): a buffer of pooled host-visible memory (`Shared`, and //! `Managed`) the device allocated, whose `contents` pointer is its block's mapping, which @@ -53,18 +60,20 @@ //! buffer, or one whose last detach's deallocator waits for its next rebind; a `Shared` heap, //! whose bytes are such pooled memory (a heap's own buffer lies where its textures can, never //! in the runtime's own pages), a heap over the caller's memory and a sparse heap, each with -//! the buffers placed in it; every texture, a heap's too; a buffer over the caller's +//! the buffers placed in it; a heap's texture or one over a heap's buffer, a texture over the +//! caller's `VkImage`, a sparse or shareable texture, one over a buffer left, and a view of +//! each (`texture/carry.rs`); a buffer over the caller's //! `VkBuffer`, an object of the lost `VkDevice` that only the caller can make again on the //! new one; a buffer in exported memory, and an event whose semaphore was made exportable, //! whose importers hold the lost allocation or semaphore. The recovery's notice counts the -//! buffers, heaps and events it carried and left by kind (`Degradation::DeviceRecovered`): a -//! heap's buffers with their heap. +//! buffers, heaps, textures and events it carried and left by kind +//! (`Degradation::DeviceRecovered`): a heap's buffers with their heap. //! - **Each generation's work reaches its own parts** (`NoticesFor::generation`). A command buffer of the //! lost generation may still record once the recovery carried its objects: an encoder a //! program's thread opened before the loss, a render encoder's end on the lowering thread. -//! Inside a command buffer's work, a carried buffer answers its parts of that command buffer's -//! generation while it has them there; elsewhere, those of the generation it was carried to -//! last. Such a command buffer fails as its device's lost one does. A carried event answers +//! Inside a command buffer's work, a carried buffer or texture answers its parts of that +//! command buffer's generation while it has them there; elsewhere, those of the generation it +//! was carried to last. Such a command buffer fails as its device's lost one does. A carried event answers //! the generation it was carried to last everywhere: a command buffer of the lost generation //! that waits for or signals it after the carry refuses it, as its device is the next //! generation (`Device::foreign`). A call outside command buffers' work that reaches a buffer's @@ -86,7 +95,8 @@ //! still valid. Those objects must still be destroyed before their parents or the device can be //! destroyed" (vkspec 5.2.3, "Lost Device"). Its device-level objects of work, what it keeps //! for reuse and its kept empty blocks go then too, and no command buffer is made on it again -//! (`DeviceShared::keep_nothing`). So a carried object holds nothing of the lost generation: +//! (`DeviceShared::keep_nothing`). A carried texture keeps its parts there until it goes +//! (`texture/carry.rs`). So a carried object but a texture holds nothing of the lost generation: //! the lost `VkDevice` goes with the last object left on it (a pooled buffer, a pipeline state, //! a texture), through the teardown every generation's goes through, and holds its own objects //! alone meanwhile (`WorkCounts::vk_devices_live`). @@ -98,6 +108,8 @@ use crate::heap::{Heap, WeakHeap}; use crate::host_ram::RamUseCell; use crate::queue::Slots; use crate::resource::ObjectId; +use crate::texture::carry::{Remade, TextureLeft, WeakTexture}; +use crate::texture::Texture; use crate::Error; use std::cell::UnsafeCell; use std::collections::HashSet; @@ -140,11 +152,16 @@ struct State { ram_uses: Vec>, /// The program's heaps, held weakly: as `ram_uses`. heaps: Vec, + /// The program's textures and views (`texture/carry.rs`), held weakly, in the order they were + /// kept: a view after the texture it was made from. + textures: Vec, /// The handles of the device that the objects holding no Vulkan object answer /// ([`LineDevice`]), held weakly. links: Vec>, /// The size at which the next keeping drops the gone events' entries. prune_at: usize, + /// The size at which the next keeping drops the gone textures' entries. + textures_prune_at: usize, /// The size at which the next keeping drops the gone handles' entries. links_prune_at: usize, /// The recovery took the generation's objects ([`Carry::take`]): what is kept from now on, @@ -192,6 +209,7 @@ pub(crate) struct Taken { events: Vec>, ram_uses: Vec>, heaps: Vec, + textures: Vec, links: Vec>, } @@ -237,6 +255,26 @@ impl Carry { state.taken } + /// Keep `texture`, a program's texture or view on this generation, as it is made or carried + /// here (`texture/carry.rs`): as [`event`](Self::event), its gone entries dropped as the + /// registry grows. + pub(crate) fn texture(&self, texture: &Texture) -> bool { + let mut state = lock(&self.state); + if state.textures.len() >= state.textures_prune_at { + state.textures.retain(WeakTexture::lives); + state.textures_prune_at = (2 * state.textures.len()).max(PRUNE_FLOOR); + } + state.textures.push(WeakTexture::of(texture)); + state.taken + } + + /// Whether the recovery took the generation's objects, read under the lock the take sets it + /// under: a texture whose way to be made again was set before this read was in the take, its + /// way read there; one set after, its maker carries (`Device::kept_texture`). + pub(crate) fn late_texture(&self) -> bool { + lock(&self.state).taken + } + /// Keep `link`, this generation's handle of the device an object holding no Vulkan object /// answers ([`LineDevice`]): as [`event`](Self::event), its gone entries dropped as the /// registry grows. @@ -264,6 +302,9 @@ impl Carry { events: state.events.iter().filter_map(Weak::upgrade).collect(), ram_uses: state.ram_uses.iter().filter_map(Weak::upgrade).collect(), heaps: state.heaps.iter().filter_map(WeakHeap::upgrade).collect(), + textures: (state.textures.iter()) + .filter_map(WeakTexture::upgrade) + .collect(), links: state.links.iter().filter_map(Weak::upgrade).collect(), } } @@ -475,6 +516,10 @@ pub(crate) struct Carried { heaps: (u64, u64, u64), /// The heaps left the lost generation's, by why. heaps_left: [u64; 4], + /// The textures carried, by what was made again ([`Remade`]). + textures: [u64; 3], + /// The textures left the lost generation's, by why. + textures_left: [u64; 7], } impl Carried { @@ -498,6 +543,15 @@ impl Carried { "sparse heaps", "heaps whose making there failed", ]; + let texture_kinds = [ + "heaps' textures", + "textures over the caller's `VkImage`", + "sparse textures", + "shareable textures", + "textures over the buffers left", + "textures whose making there failed", + "textures of calls no recovery makes again", + ]; let left = (kinds.iter().zip(self.left).enumerate()) .filter(|&(at, (_, count))| at == Left::Pooled as usize || count > 0) .map(|(_, (kind, count))| format!("{count} {kind}")) @@ -506,6 +560,11 @@ impl Carried { .filter(|&(_, count)| count > 0) .map(|(kind, count)| format!("{count} {kind}")), ) + .chain( + (texture_kinds.iter().zip(self.textures_left)) + .filter(|&(_, count)| count > 0) + .map(|(kind, count)| format!("{count} {kind}")), + ) .chain( (self.events_left > 0) .then(|| format!("{} events made exportable", self.events_left)), @@ -527,10 +586,17 @@ impl Carried { in them, whose contents were lost too" ), }; + let textures = match self.textures { + [0, 0, 0] => String::new(), + [own, over, views] => format!( + ", and {own} textures whose contents were lost too (they read as new ones), \ + {over} textures over the buffers carried and {views} texture views" + ), + }; format!( "it carried {} events, {ram}{} buffers with their contents and {lost} `Private` \ - buffers ({lost_bytes} bytes) whose contents were lost (they read zero){heaps}; left \ - refused (`MadeBeforeRecovery`): {left}", + buffers ({lost_bytes} bytes) whose contents were lost (they read zero){heaps}\ + {textures}; left refused (`MadeBeforeRecovery`): {left}", self.events, self.kept ) } @@ -559,6 +625,15 @@ impl Carried { } } + /// One texture's carry: what was made again, or why it was left. + fn texture(&mut self, carried: Result, TextureLeft>) { + match carried { + Ok(Some(remade)) => self.textures[remade as usize] += 1, + Ok(None) => {} + Err(left) => self.textures_left[left as usize] += 1, + } + } + /// One event's carry. fn event(&mut self, carried: Result<(), Error>) { match carried { @@ -587,6 +662,7 @@ impl Device { events, ram_uses, heaps, + textures, links, } = shared.carry.take(shared); for link in &links { @@ -606,6 +682,11 @@ impl Device { for heap in &heaps { carried.heap(heap.carry(next)); } + // After the buffers, which textures lie over; the textures before the views of them, as + // they were kept (a view's carry carries its parent where it was not). + for texture in &textures { + carried.texture(texture.carry(next)); + } carried } diff --git a/crates/metal2vulkan-runtime/src/error.rs b/crates/metal2vulkan-runtime/src/error.rs index 6459db15f..650c4b41a 100644 --- a/crates/metal2vulkan-runtime/src/error.rs +++ b/crates/metal2vulkan-runtime/src/error.rs @@ -2133,25 +2133,28 @@ pub enum RuntimeGap { /// announced as `Degradation::DeviceRecovered`; `Device::recover_for_test` runs the same /// recovery). The recovery carries the events, the fences, the depth/stencil states, the /// libraries and their functions and the address pools (their handle of the device alone: they - /// hold no Vulkan object), the uses of guest RAM, the no-copy buffers (made again over the same pages), the `Private` buffers - /// (their contents lost: they read zero), the buffers in the runtime's own pages (their - /// contents and `contents` pointer kept): a long host-visible buffer's fresh pages, and the - /// blocks of pages the `Shared` and `Managed` buffers lie in where the device's checks found a - /// held host-page import costs its submissions nothing and textures over such pages take what - /// they take over its own memory; and the `Private` heaps with the buffers placed in them - /// (their contents lost: they read zero), in which buffers and textures are made again after - /// it. Every other object's Vulkan objects are the lost `VkDevice`'s, which serves nothing - /// more: a pooled `Shared` or `Managed` buffer in memory the device allocated, whose `contents` - /// pointer is its lost memory's mapping, a detached no-copy buffer, a `Shared`, no-copy or - /// sparse heap and the buffers placed in it, a texture (a heap's too), a pipeline state, a - /// sampler state, an indirect command buffer, a buffer over the caller's `VkBuffer` or in - /// exportable memory, and an event made exportable. A call that meets such an object with the - /// new generation (an encoder's bind, a pipeline's making from its functions, a buffer or - /// texture placed in its heap) or that needs its own lost `VkDevice` (its placements, its - /// imports again, its event signals) is refused, where Metal's object goes on; the recovery's - /// notice counts the buffers, heaps and events it left. The same object made again on the - /// device serves; a command buffer made before the recovery fails as its victim - /// (`GpuRecoveryVictim`). + /// hold no Vulkan object), the uses of guest RAM, the no-copy buffers (made again over the same pages), the + /// `Private` buffers (their contents lost: they read zero), the buffers in the runtime's own + /// pages (their contents and `contents` pointer kept): a long host-visible buffer's fresh + /// pages, and the blocks of pages the `Shared` and `Managed` buffers lie in where the device's + /// checks found a held host-page import costs its submissions nothing and textures over such + /// pages take what they take over its own memory; and the `Private` heaps with the buffers + /// placed in them (their contents lost: they read zero), in which buffers and textures are made + /// again after it; and the textures of `Device::new_texture` (their contents lost), those over + /// the buffers it carried (reading the buffers' bytes) and the views of either. Every other + /// object's Vulkan objects are the lost `VkDevice`'s, which serves nothing more: a pooled + /// `Shared` or `Managed` buffer in memory the device allocated, whose `contents` pointer is its + /// lost memory's mapping, a detached no-copy buffer, a `Shared`, no-copy or sparse heap and the + /// buffers placed in it, a heap's texture or one over a heap's buffer, a texture over the + /// caller's `VkImage`, a sparse or shareable texture, a texture over a buffer left, a view of + /// any of them, a pipeline state, a sampler state, an indirect command buffer, a buffer over + /// the caller's `VkBuffer` or in exportable memory, and an event made exportable. A call that + /// meets such an object with the new generation (an encoder's bind, a pipeline's making from + /// its functions, a buffer or texture placed in its heap) or that needs its own lost `VkDevice` + /// (its placements, its imports again, its event signals) is refused, where Metal's object goes + /// on; the recovery's notice counts the buffers, heaps, textures and events it left. The same + /// object made again on the device serves; a command buffer made before the recovery fails as + /// its victim (`GpuRecoveryVictim`). MadeBeforeRecovery, /// `Device::recover_for_test` on a device the consumer made (`Device::from_raw`): the runtime /// cannot make a new `VkDevice` of the consumer's, so it recovers none, and the device is diff --git a/crates/metal2vulkan-runtime/src/heap.rs b/crates/metal2vulkan-runtime/src/heap.rs index d55d77ac9..c526d8082 100644 --- a/crates/metal2vulkan-runtime/src/heap.rs +++ b/crates/metal2vulkan-runtime/src/heap.rs @@ -1173,7 +1173,7 @@ impl Heap { /// the heap is the same heap there, registered by its key, and each buffer placed in it that /// lives is the same buffer there, at its offset ([`Buffer::carry_placed`]), listed among the /// generation's live buffers where a command buffer's commands used the heap already. The - /// textures it made stay the lost generation's, as every texture does: they are refused where + /// textures it made stay the lost generation's, as a heap's textures do: they are refused where /// they meet the next generation (`RuntimeGap::MadeBeforeRecovery`), and no use of the heap /// there makes them resident; those it makes there are that generation's, numbered after /// them. The bytes carried, and the buffers placed in it carried with them; or why the heap diff --git a/crates/metal2vulkan-runtime/src/tests/device_recovery_carry.rs b/crates/metal2vulkan-runtime/src/tests/device_recovery_carry.rs index 359886294..38e7822ef 100644 --- a/crates/metal2vulkan-runtime/src/tests/device_recovery_carry.rs +++ b/crates/metal2vulkan-runtime/src/tests/device_recovery_carry.rs @@ -12,8 +12,8 @@ use super::device_recovery::{ }; use crate::fresh_pages::FRESH_PAGES_PAST; use crate::{ - Buffer, CommandBufferStatus, CommandQueue, Device, Error, EventRef, ResourceOptions, - RuntimeGap, SharedEvent, SharedEventListener, TextureDescriptor, + Buffer, CommandBufferStatus, CommandQueue, Device, Error, EventRef, HeapDescriptor, HeapType, + ResourceOptions, RuntimeGap, SharedEvent, SharedEventListener, TextureDescriptor, }; use metal2vulkan::metal::{PixelFormat, TextureUsage}; use std::sync::mpsc; @@ -106,7 +106,7 @@ pub(super) fn live_vk_devices(device: &Device, live: u64) -> u64 { /// GPU signal after it), as its notice counts. Two pooled `Shared` buffers of one block it carries /// as the one in fresh pages where they lie in a block of the runtime's own pages (`memory.rs`'s /// `Holds::PageBuffers`), in one import of its pages again, else leaves refused. What is left -/// (those buffers, and a texture, which no recovery carries) keeps the lost `VkDevice`, but +/// (those buffers, and a `Shared` heap, which no recovery carries) keeps the lost `VkDevice`, but /// nothing it kept for reuse: the memory of buffers the program let go of before the loss (their /// `VkBuffer`s parked, or a block kept empty) is freed, and no empty block is left. The lost /// `VkDevice` goes with what is left. @@ -177,9 +177,8 @@ fn a_recovery_carries_events_private_and_fresh_page_buffers() { "the pooled buffers lie in two blocks" ); // An object no recovery carries. - let mut descriptor = TextureDescriptor::texture_2d(PixelFormat::RGBA8Unorm, 4, 4, false); - descriptor.usage = TextureUsage::SHADER_READ; - let texture = device.new_texture(&descriptor).unwrap(); + let heap = HeapDescriptor::new(HeapType::Automatic, 1 << 16, ResourceOptions::shared()); + let left = device.new_heap(&heap).unwrap(); let event = device.new_shared_event().unwrap(); event.set_signaled_value(5); let listener = SharedEventListener::new(); @@ -197,7 +196,7 @@ fn a_recovery_carries_events_private_and_fresh_page_buffers() { }) .collect(); drop(reused); - let before = texture.device().work_counts_now(); + let before = left.device().work_counts_now(); let from = heard.lock().unwrap().len(); device.recover_for_test().unwrap(); let said = recovery_notices(&heard, from, "the device"); @@ -280,9 +279,9 @@ fn a_recovery_carries_events_private_and_fresh_page_buffers() { } } // What is left holds the lost `VkDevice`, which keeps no memory for work. - assert!(!texture.device().generation_serves()); + assert!(!left.device().generation_serves()); assert_eq!(live_vk_devices(&device, 2), 2); - let after = texture.device().work_counts_now(); + let after = left.device().work_counts_now(); let blocks = |counts: &crate::WorkCounts| counts.memory_blocks_live + counts.empty_memory_blocks_live; eprintln!( @@ -301,7 +300,7 @@ fn a_recovery_carries_events_private_and_fresh_page_buffers() { blocks(&before) ); assert!(after.memory_frees.teardown > before.memory_frees.teardown); - drop((pooled, beside, texture)); + drop((pooled, beside, left)); assert_eq!(live_vk_devices(&device, 1), 1); } @@ -392,10 +391,10 @@ fn a_call_under_way_keeps_the_parts_it_read_past_the_lost_generation_s_rest() { vec![6; BYTES as usize] ); go.send(()).unwrap(); - // The call completed on the generation it began on: its texture is that one's, where the - // lost device made one. + // The call completed on the generation it began on, and its maker carried the texture it + // made there to the next (`texture/carry.rs`): it serves, where the lost device made one. let made = call.join().unwrap(); - assert!(!matches!(made, Ok(true)), "{made:?}"); + assert!(!matches!(made, Ok(false)), "{made:?}"); assert!(buffer.first_parts_freed()); } diff --git a/crates/metal2vulkan-runtime/src/tests/device_recovery_heap.rs b/crates/metal2vulkan-runtime/src/tests/device_recovery_heap.rs index 33168463d..b5eb907c0 100644 --- a/crates/metal2vulkan-runtime/src/tests/device_recovery_heap.rs +++ b/crates/metal2vulkan-runtime/src/tests/device_recovery_heap.rs @@ -1,7 +1,7 @@ //! What a device's recovery carries of its heaps (`Heap::carry`, `device/carry.rs`): a `Private` //! heap goes on as the same heap, its bytes new memory that reads zero, with the buffers placed //! in it before; buffers and textures made in it after the recovery serve, and the textures it -//! made before stay refused, as every texture made before a recovery does. +//! made before stay refused, as a heap's textures made before a recovery do. //! //! A device test: compiled only under the validation crate's GPU safety cfgs, on the kind of device //! the cfg selects (docs/VALIDATION.md). No GPU fault: the loss is marked (`Device::recover_for_test`). diff --git a/crates/metal2vulkan-runtime/src/texture.rs b/crates/metal2vulkan-runtime/src/texture.rs index 8e1dab686..c4cec6897 100644 --- a/crates/metal2vulkan-runtime/src/texture.rs +++ b/crates/metal2vulkan-runtime/src/texture.rs @@ -158,6 +158,7 @@ use wrapped::WrappedImage; mod attached_reads; mod attributes; +pub(crate) mod carry; pub(super) mod copy_images; pub(crate) mod decoded_twin; pub(crate) mod faces; @@ -437,6 +438,12 @@ pub struct Texture(Arc, Option>); /// thread it runs. pub(super) struct Retain(Weak); +/// A texture object. Its storage and what is made of it (`storage`, `moved`, `pending_move`, +/// `usage_shadow`, `usage_shadow_making`, `faces`, `snapshot`, `kept_backings`, `render_shadow`, +/// `facts` and `planes_in_place`) are its parts on the generation it was made on; where its +/// device's recovery carried it (`texture/carry.rs`), its handles reach those of the generation +/// the work at hand is on through [`Texture::s`], each generation's in a texture of the +/// runtime's own there (`next`). The rest is the texture object's own, whatever generation serves. pub(super) struct TextureShared { storage: Storage, /// The [`Retain`] the texture's handles hold, while one does. @@ -502,6 +509,18 @@ pub(super) struct TextureShared { /// (`texture/ycbcr_image.rs`): a slot of a function that reads it only so binds them, not the /// image. `None` for every other texture, a view of one among them. planes_in_place: Option, + /// The generation it was made on: the address of its `DeviceShared`, as + /// `NoticesFor::generation` names a command buffer's. + generation: usize, + /// How a recovery makes a program's texture again on the generation it makes + /// (`texture/carry.rs`), set as the texture is made by a call a recovery makes again. + remake: OnceLock, + /// Its parts on the generation a recovery carried it to (`texture/carry.rs`): a texture of the + /// runtime's own there, made as the texture was, which may itself hold the next generation's. + next: OnceLock, + /// A recovery carried it (`next` is set): its handles reach its parts through `next` + /// ([`Texture::s`]). + carried: AtomicBool, } impl Drop for TextureShared { @@ -542,13 +561,26 @@ impl Drop for TextureShared { impl TextureShared { /// Leave the texture's slot as it goes: the device's texture table no longer names it, and its /// image waits for the command buffers that may still read it through its ID - /// (`heap_sets::gone`). Nothing where it holds no ID. + /// (`heap_sets::gone`). On the generation it was made on, and on each a recovery carried it to + /// (`texture/carry.rs`), whose table names it with its parts there. Nothing where it holds no + /// ID. fn leave_slot(&self) { let id = self.id.id().0; if id == 0 { return; } - let (device, keeper): (&Device, Option>) = match &self.storage { + let mut link = Some(self); + while let Some(shared) = link { + let (device, keeper) = shared.slot_keeper(); + heap_sets::gone(device, id, self.id.serial(), keeper); + link = shared.next.get().map(|next| &*next.0); + } + } + + /// The device of the texture's parts on their generation, and what keeps their image while a + /// command buffer that bound its ID there may read it ([`leave_slot`](Self::leave_slot)). + fn slot_keeper(&self) -> (&Device, Option>) { + match &self.storage { Storage::Image(image) | Storage::Alias { image, .. } | Storage::Shadow { image, .. } => { @@ -565,8 +597,7 @@ impl TextureShared { (&image.device, Some(Box::new((Arc::clone(image), moved)))) } Storage::Texels(texels) => (texels.buffer.device(), None), - }; - heap_sets::gone(device, id, self.id.serial(), keeper); + } } } @@ -1890,7 +1921,11 @@ impl Device { let id_use = IdUse::Program(descriptor.placement); let texture = self.texture_as(CALL, descriptor, (id_use, Initial::AsMetal))?; self.take_device_sampler(); - Ok(texture) + let remake = carry::Remake::Own { + descriptor: *descriptor, + initial: Initial::AsMetal, + }; + Ok(self.kept_texture(texture, remake)) } /// [`Device::new_texture`] with `token` (a runtime extension), dropped once the runtime frees @@ -4873,7 +4908,7 @@ pub(super) fn texel_units( /// How a new texture of the program's starts ([`Device::new_texture_image`]). #[derive(Clone, Copy, Debug, PartialEq, Eq)] -enum Initial { +pub(crate) enum Initial { /// As Metal's new texture of its storage mode starts on the Mac the device presents. AsMetal, /// Zero in every texel, in every storage mode but `Memoryless`: a texture over an IOSurface @@ -5249,6 +5284,10 @@ impl Texture { heap, facts: OnceLock::new(), planes_in_place, + generation: std::ptr::from_ref(device.shared()).addr(), + remake: OnceLock::new(), + next: OnceLock::new(), + carried: AtomicBool::new(false), } }); let texture = Texture(shared, retain); @@ -5274,6 +5313,8 @@ impl Texture { if texture.0.parent.is_none() { device.shared().owners.texture(&texture); } + // Kept for the generation's recovery to carry or leave (`texture/carry.rs`). + device.shared().carry.texture(&texture); // An `Outside` texture has no ID, so no slot (`IdHold::take`). if placement != IdPlacement::Outside { texture @@ -5306,10 +5347,41 @@ impl Texture { /// before its pages' in-place verdict moved to (`TextureShared::moved`), or the second of its /// faces where it presents that one (`texture/faces.rs`). fn storage(&self) -> &Storage { - if let Some(presented) = self.0.faces.get().and_then(faces::Faces::presented) { + let shared = self.s(); + if let Some(presented) = shared.faces.get().and_then(faces::Faces::presented) { return presented; } - self.0.moved.get().unwrap_or(&self.0.storage) + shared.moved.get().unwrap_or(&shared.storage) + } + + /// The texture's parts (its storage and what is made of it, `TextureShared`) as the work at + /// hand reaches them: its own, where its device's recovery never carried it, at one load + /// (`texture/carry.rs`). Where it did, inside a command buffer's work + /// (`NoticesFor::generation`) those of that command buffer's generation where the texture + /// has some, so the lost generation's command buffers record its own images alone; else + /// those of the generation it was carried to last. + #[inline] + fn s(&self) -> &TextureShared { + match self.0.carried.load(Ordering::Relaxed) { + false => &self.0, + true => self.carried(), + } + } + + /// [`s`](Self::s) of a texture its device's recovery carried. + #[cold] + fn carried(&self) -> &TextureShared { + let records = crate::degradation::NoticesFor::generation(); + let mut shared = &*self.0; + loop { + if records == Some(shared.generation) { + return shared; + } + match shared.next.get() { + Some(next) => shared = &*next.0, + None => return shared, + } + } } /// The texture object `shared` names, while it lives (a slot's holder, `resource_ids.rs`), @@ -5340,7 +5412,7 @@ impl Texture { /// The memoryless backings it keeps (`attachment_stand_in::kept_backing`). pub(super) fn kept_backings(&self) -> &Mutex> { - &self.0.kept_backings + &self.s().kept_backings } /// A texture over `texels`, presenting `record` of them, its ID as `id_use` says. @@ -5958,7 +6030,7 @@ impl Texture { /// The facts a binding plan reads of the texture, worked out once and kept /// (`TextureShared::facts`). pub(super) fn facts(&self) -> TextureFacts { - *self.0.facts.get_or_init(|| self.worked_out_facts()) + *self.s().facts.get_or_init(|| self.worked_out_facts()) } /// The facts a binding plan reads of the texture, worked out from what it was made with. @@ -5967,7 +6039,7 @@ impl Texture { let mut facts = texture_facts(&record); facts.sparse = self.is_sparse(); // A two-plane YCbCr texture whose planes a function may read in place. - facts.ycbcr_in_place = self.0.planes_in_place.as_ref().map(|p| match p.image { + facts.ycbcr_in_place = self.s().planes_in_place.as_ref().map(|p| match p.image { Some(_) => p.words.with_planes_image(), None => p.words, }); @@ -6550,19 +6622,39 @@ impl Texture { }) } + /// The view of `request` that `call` makes, its resource ID at `placement`, kept for a + /// recovery to make again (`texture/carry.rs`). fn view( &self, call: &'static str, request: &ViewRequest, placement: IdPlacement, ) -> Result { - self.check_viewable(call)?; - self.device().check_texture_placement( + let view = self.view_as(call, request, IdUse::Program(placement))?; + let remake = carry::Remake::View { call, - placement, - self.0.record.usage, - request.texture_type, - )?; + request: request.clone(), + }; + Ok(self.device().kept_texture(view, remake)) + } + + /// [`view`](Self::view), its resource ID as `id_use` says: the runtime's own for a view a + /// recovery makes again (`texture/carry.rs`). + fn view_as( + &self, + call: &'static str, + request: &ViewRequest, + id_use: IdUse, + ) -> Result { + self.check_viewable(call)?; + if let IdUse::Program(placement) = id_use { + self.device().check_texture_placement( + call, + placement, + self.0.record.usage, + request.texture_type, + )?; + } let profile = self.device().compile_device().profile(); let record = check_view(&self.0.record, request, profile) .map_err(|refusal| view_error(call, refusal))?; @@ -6656,7 +6748,6 @@ impl Texture { self.reinterpreted(call, &record)? }; let parent = Some(self.clone()); - let id_use = IdUse::Program(placement); Ok(Texture::made( self.device(), storage, diff --git a/crates/metal2vulkan-runtime/src/texture/attached_reads.rs b/crates/metal2vulkan-runtime/src/texture/attached_reads.rs index 587744027..340ce4f6b 100644 --- a/crates/metal2vulkan-runtime/src/texture/attached_reads.rs +++ b/crates/metal2vulkan-runtime/src/texture/attached_reads.rs @@ -545,7 +545,7 @@ impl Texture { let format = form.format(); let pixel_format = snapshot_pixel_format(format) .ok_or_else(|| crate::error::internal("a snapshot form of no snapshot's format"))?; - let mut held = crate::device::lock(&owner.0.snapshot); + let mut held = crate::device::lock(&owner.s().snapshot); if let Some(made) = held.iter().find(|t| t.pixel_format() == pixel_format) { return Ok(made.clone()); } diff --git a/crates/metal2vulkan-runtime/src/texture/attributes.rs b/crates/metal2vulkan-runtime/src/texture/attributes.rs index d022cb904..a4386fd37 100644 --- a/crates/metal2vulkan-runtime/src/texture/attributes.rs +++ b/crates/metal2vulkan-runtime/src/texture/attributes.rs @@ -82,6 +82,15 @@ impl Texture { }) } + /// Give `link`, the texture's parts on the generation its device's recovery carries it to + /// (`texture/carry.rs`), the purgeable state its own parts keep, where both keep one. + pub(super) fn carry_purgeable_state(&self, link: &Texture) { + if let (Some(Kept::Image(from)), Some(Kept::Image(to))) = (self.kept(), link.kept()) { + let state = *lock(from); + *lock(to) = state; + } + } + /// Where the texture's purgeable state is kept: `None` for a texture Metal answers /// `NonVolatile` for (the module docs). fn kept(&self) -> Option> { @@ -90,8 +99,9 @@ impl Texture { } // A texture with two faces keeps its state with its own image, whichever face it // presents (`texture/faces.rs`). - let storage = match self.0.faces.get() { - Some(_) => &self.0.storage, + let parts = self.s(); + let storage = match parts.faces.get() { + Some(_) => &parts.storage, None => self.storage(), }; match storage { diff --git a/crates/metal2vulkan-runtime/src/texture/carry.rs b/crates/metal2vulkan-runtime/src/texture/carry.rs new file mode 100644 index 000000000..a98140e91 --- /dev/null +++ b/crates/metal2vulkan-runtime/src/texture/carry.rs @@ -0,0 +1,249 @@ +//! What a device's recovery carries of the program's textures (`device/carry.rs`): each texture +//! made by a call the recovery can make again, the same texture object on the new `VkDevice`. +//! +//! - **What is made again.** A texture of `Device::new_texture` (its image new memory, its +//! contents lost: it reads as a new texture of its descriptor reads), one over a buffer the +//! recovery carried (`Buffer::new_texture` and its kin: made over the buffer's bytes there, so it +//! reads what the buffer holds), and a view of either (`new_texture_view` and its kin: of its +//! parent's parts there). The call is made again on the new generation as the runtime's own +//! texture ([`Remake`]), which takes no resource ID, and holds the texture's parts there +//! (`TextureShared::next`): its handles reach them from then on (`Texture::s`). The texture +//! object stays what it was: its `ObjectId`, resource ID, label, purgeable state, parent and +//! handles; its ID's slot in the new generation's texture table and heap sets names its parts +//! there (`heap_sets::place`). What its uses made of its image (views, shadows, faces, +//! snapshots, memoryless backings, decoded twins) is made again there as its uses need it. +//! - **What stays the lost generation's**, refused where it meets the next +//! (`RuntimeGap::MadeBeforeRecovery`), by kind ([`TextureLeft`]): a heap's texture or one over a +//! heap's buffer, a texture over the caller's `VkImage`, a sparse texture, a shareable texture +//! and one opened from its handles, a texture over a buffer the recovery left, and a view of +//! any of them. +//! - **Kept as made.** Each texture of the program's is kept by its generation's registry as it +//! is made (`Carry::texture`), held weakly; a call the recovery makes again sets how +//! ([`Device::kept_texture`]), and carries the texture itself where the recovery took the +//! generation's objects before that (`Device::carry_late`). +//! - **Its parts on the lost generation** stay with the texture until it goes: its images there +//! and the lost `VkDevice` with them. + +use super::super::buffer::Buffer; +use super::super::buffer_texture::TexelsHome; +use super::super::degradation::NoticesFor; +use super::super::heap_sets; +use super::super::linear_plan::BufferTextureCall; +use super::super::texture_descriptor::TextureDescriptor; +use super::super::view_plan::ViewRequest; +use super::super::ycbcr::IoSurfaceYCbCr; +use super::super::Device; +use super::{IdUse, Initial, Owner, Storage, Texture, TextureShared}; +use std::sync::atomic::Ordering; +use std::sync::Weak; + +/// How a recovery makes a program's texture again (`TextureShared::remake`; the module docs): +/// the call that made it, made again on the next generation as a texture of the runtime's own. +pub(crate) enum Remake { + /// `Device::new_texture` of `descriptor` (its options resolved), starting as `initial`. + Own { + descriptor: TextureDescriptor, + initial: Initial, + }, + /// A texture over `buffer` (`Buffer::new_texture` and its kin): `call`, made through `form`, + /// of `descriptor` at `offset` with `bytes_per_row`, over a surface of `ycbcr` facts where + /// given. + Over { + buffer: Buffer, + call: &'static str, + descriptor: TextureDescriptor, + offset: u64, + bytes_per_row: u64, + form: BufferTextureCall, + ycbcr: Option, + }, + /// A view of the texture's parent: `call` of `request`. + View { + call: &'static str, + request: ViewRequest, + }, +} + +/// What a recovery made again of a texture it carried ([`Texture::carry`]). +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub(crate) enum Remade { + /// A texture of its own image: its contents lost. + Lost, + /// A texture over a buffer the recovery carried: it reads what the buffer holds. + Over, + /// A view, of its parent's parts there. + View, +} + +/// Why a texture stays the lost generation's ([`Texture::carry`]; the module docs). A view +/// stays where its parent stays, and for its parent's reason. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub(crate) enum TextureLeft { + /// A heap's texture, or one over a heap's buffer. + Heap, + /// Over the caller's `VkImage` (`texture/wrapped.rs`), an object of the lost `VkDevice`. + Caller, + /// A sparse heap's texture. + Sparse, + /// A shareable texture (`Device::new_shared_texture`), or one opened from its handles, whose + /// memory another process may import. + Shared, + /// Over a buffer the recovery left. + Buffer, + /// Its making on the new generation failed. + Failed, + /// Made by a call no recovery makes again. + Other, +} + +/// A texture of the program's, held weakly by its generation's registry (`Carry::texture`). +pub(crate) struct WeakTexture(Weak); + +impl WeakTexture { + /// `texture`, held weakly. + pub(crate) fn of(texture: &Texture) -> WeakTexture { + WeakTexture(texture.downgrade()) + } + + /// Whether the texture lives. + pub(crate) fn lives(&self) -> bool { + self.0.strong_count() > 0 + } + + /// The texture, while it lives. + pub(crate) fn upgrade(&self) -> Option { + Texture::upgrade(&self.0) + } +} + +impl Device { + /// `texture`, a program's texture this generation made by a call a recovery makes again, + /// kept with how (`remake`; the module docs): carried by its maker to the generation that + /// serves where this generation's recovery took its objects before then, read under the + /// lock the take sets that under, as a heap's maker carries it (`Device::carry_late`). + pub(crate) fn kept_texture(&self, texture: Texture, remake: Remake) -> Texture { + // Set once: the call that made it. + let _ = texture.0.remake.set(remake); + if self.shared().carry.late_texture() { + self.carry_late(|serving| texture.carry(serving)); + } + texture + } +} + +impl Texture { + /// Whether the texture is a view of another (`parentTexture`). + pub(crate) fn is_view(&self) -> bool { + self.0.parent.is_some() + } + + /// Carry the texture, made on a generation of its device that a recovery leaves, to `to`, + /// the generation that recovery made (the module docs): its call made again there as the + /// runtime's own texture, whose parts the texture's handles reach from then on, its ID's + /// slot there naming them; a view's parent first. What was made again, `None` where it was + /// carried there already; or why it stays the lost generation's. + pub(crate) fn carry(&self, to: &Device) -> Result, TextureLeft> { + const CALL: &str = "new_texture"; + let generation = std::ptr::from_ref(to.shared()).addr(); + // Every carried object's parts this reads (the buffer a texture is over, a view's parent, + // the texture's own as its slot is written) are those on `to`, where it has some, whatever + // command buffer's work or held parts the thread is inside. + let _scope = NoticesFor::of_generation(generation); + // The generation it was carried to last: a later recovery carries it on from there. + let mut last: &TextureShared = &self.0; + while let Some(next) = last.next.get() { + last = &*next.0; + } + if last.generation == generation { + // Carried already, by its maker or as a view's parent. + return Ok(None); + } + let Some(remake) = self.0.remake.get() else { + return Err(self.left()); + }; + let (made, remade) = match remake { + Remake::Own { + descriptor, + initial, + } => { + let made = to.texture_as(CALL, descriptor, (IdUse::Runtime, *initial)); + (made, Remade::Lost) + } + Remake::Over { + buffer, + call, + descriptor, + offset, + bytes_per_row, + form, + ycbcr, + } => { + if buffer.heap().is_some() { + return Err(TextureLeft::Heap); + } + if !buffer.device().same(to) { + return Err(TextureLeft::Buffer); + } + let over = (*offset, *bytes_per_row); + let made = buffer.texture_over_again(*call, descriptor, over, *form, *ycbcr); + (made, Remade::Over) + } + Remake::View { call, request } => { + let Some(parent) = &self.0.parent else { + return Err(TextureLeft::Other); + }; + parent.carry(to)?; + (parent.view_as(*call, request, IdUse::Runtime), Remade::View) + } + }; + let made = made.map_err(|_| TextureLeft::Failed)?; + if !self.is_view() { + self.carry_purgeable_state(&made); + } + if last.next.set(made).is_err() { + // Another carry of it to `to` came first. + return Ok(None); + } + self.0.carried.store(true, Ordering::Release); + // Among the program's resources there, its ID's slot there naming its parts there. + if !self.is_view() { + to.shared().owners.texture(self); + } + if self.0.id.id().0 != 0 { + heap_sets::place(to, self); + } + // Kept there for a later recovery to carry on, as a texture made there is. + if to.shared().carry.texture(self) { + to.carry_late(|serving| self.carry(serving)); + } + Ok(Some(remade)) + } + + /// Why the texture, which no call a recovery makes again made, stays the lost generation's. + fn left(&self) -> TextureLeft { + if self.root().0.heap.is_some() { + return TextureLeft::Heap; + } + match self.storage() { + Storage::Image(image) => match &image.owner { + Owner::Heap(_) | Owner::HeapShadow(_) | Owner::HeapUnaliased(_) => { + TextureLeft::Heap + } + Owner::Caller(_) => TextureLeft::Caller, + Owner::Sparse(_) => TextureLeft::Sparse, + Owner::Runtime { + shareable: true, .. + } => TextureLeft::Shared, + Owner::Buffer { .. } => TextureLeft::Buffer, + Owner::Runtime { .. } | Owner::ViewShadow(_) => TextureLeft::Other, + }, + Storage::Texels(texels) if texels.home == TexelsHome::Shared => TextureLeft::Shared, + Storage::Texels(texels) + | Storage::Alias { texels, .. } + | Storage::Shadow { texels, .. } => match texels.buffer.heap() { + Some(_) => TextureLeft::Heap, + None => TextureLeft::Buffer, + }, + } + } +} diff --git a/crates/metal2vulkan-runtime/src/texture/faces.rs b/crates/metal2vulkan-runtime/src/texture/faces.rs index 6b3395a67..19d26e682 100644 --- a/crates/metal2vulkan-runtime/src/texture/faces.rs +++ b/crates/metal2vulkan-runtime/src/texture/faces.rs @@ -270,8 +270,8 @@ impl Texture { /// Whether the texture may take faces (the module's **Which textures**): and no binding beyond /// its usage made it a shadow of its own before an attached read could. pub(super) fn faces_fit(&self) -> bool { - let shared = &self.0; - let Storage::Image(image) = &shared.storage else { + let (shared, parts) = (&self.0, self.s()); + let Storage::Image(image) = &parts.storage else { return false; }; let own = matches!( @@ -290,8 +290,8 @@ impl Texture { let private = matches!(image.options.storage_mode(), Ok(StorageMode::Private)); own && shared.parent.is_none() && shared.heap.is_none() - && shared.moved.get().is_none() - && shared.planes_in_place.is_none() + && parts.moved.get().is_none() + && parts.planes_in_place.is_none() && private && image.identity.tracked && plan.image_type == ImageType::TYPE_2D @@ -308,12 +308,12 @@ impl Texture { && !image.handed_out() && image.form.plan().is_none() && image.objects.count() == 1 - && shared.usage_shadow.get().is_none() + && parts.usage_shadow.get().is_none() } /// Whether the texture has faces (the module docs). pub(crate) fn has_faces(&self) -> bool { - self.0.faces.get().is_some() + self.s().faces.get().is_some() } /// Why the texture may not take faces now, where it may not @@ -333,7 +333,8 @@ impl Texture { /// The texture's faces, made now (the module docs): its second image, and the copies between /// the two. The attached reads' shadow while the texture presents its own image. pub(super) fn make_faces(&self) -> Result, Error> { - let Storage::Image(own) = &self.0.storage else { + let parts = self.s(); + let Storage::Image(own) = &parts.storage else { return Err(crate::error::internal( "faces of a texture without an image", )); @@ -375,7 +376,7 @@ impl Texture { .other_image() .map_or(own.identity.key, |o| o.identity.key), ]; - if self.0.faces.set(faces).is_err() { + if parts.faces.set(faces).is_err() { return Err(crate::error::internal("a texture's faces made twice")); } (device.shared().face_swaps).faced(keys, Arc::downgrade(&self.0)); @@ -386,13 +387,13 @@ impl Texture { /// The face the texture presents: 0 its own image (a texture without faces too), 1 its /// second; to an encoder encoded again, as its first encoding met it ([`with_faces_as_of`]). pub(crate) fn face(&self) -> u8 { - (self.0.faces.get()).map_or(0, |faces| faces.face() as u8) + (self.s().faces.get()).map_or(0, |faces| faces.face() as u8) } /// End the texture's turns, where it has faces (the module's **Frozen**): it presents the /// face it presents now for good. pub(crate) fn freeze_faces(&self) { - if let Some(faces) = self.root().0.faces.get() { + if let Some(faces) = self.root().s().faces.get() { let _turning = lock(&faces.turning); faces.frozen.store(true, Ordering::Release); } @@ -402,7 +403,8 @@ impl Texture { /// command buffer (the module's **The turn** and **When**); the caller checked the pass. The /// shadow the pass's first instance reads without a copy in, or why it did not turn. pub(crate) fn turn_face(&self, point: &TurnPoint) -> Result { - let Some(faces) = self.0.faces.get() else { + let parts = self.s(); + let Some(faces) = parts.faces.get() else { return Err(match self.faces_fit() { true => Unturned::First, false => Unturned::Storage, @@ -431,7 +433,7 @@ impl Texture { let to = 1 - from; let image = |face: usize| -> Arc { let storage = match face { - 0 => &self.0.storage, + 0 => &parts.storage, _ => &faces.other, }; match storage { @@ -470,7 +472,7 @@ impl Texture { /// the texture still presents the face that turn turned to, the shadow the pass's first /// instance reads without a copy in, the face from before the turn; else `None`. pub(crate) fn retake_turn(&self) -> Option { - let faces = self.0.faces.get()?; + let faces = self.s().faces.get()?; let (owner, parts) = encoding_again()?; let swaps = &self.device().shared().face_swaps; let from = swaps.turned_in(&self.0, owner, &parts)?; @@ -483,7 +485,7 @@ impl Texture { /// The copies of the attached reads' shadow of each face, where the texture has faces: a /// command buffer's carry of either goes at a turn (`render/face_swap.rs`). pub(crate) fn face_copies(&self) -> Option<[Arc; 2]> { - let faces = self.0.faces.get()?; + let faces = self.s().faces.get()?; Some([ Arc::clone(faces.shadows[0].copies()), Arc::clone(faces.shadows[1].copies()), @@ -707,8 +709,8 @@ impl FaceSwaps { .filter(|record| record.owner == owner && record.part >= part) .filter(|record| !record.stale.load(Ordering::Acquire)) .filter_map(|record| { - let texture = record.texture.upgrade()?; - let faces = texture.faces.get()? as *const Faces as usize; + let texture = Texture::upgrade(&record.texture)?; + let faces = texture.s().faces.get()? as *const Faces as usize; Some((faces, record.from)) }) .collect() diff --git a/crates/metal2vulkan-runtime/src/texture/storage_form.rs b/crates/metal2vulkan-runtime/src/texture/storage_form.rs index d0e66f80e..f29c5e2d9 100644 --- a/crates/metal2vulkan-runtime/src/texture/storage_form.rs +++ b/crates/metal2vulkan-runtime/src/texture/storage_form.rs @@ -638,12 +638,13 @@ impl Texture { /// texels is made as the texture's would have been had its pages' verdicts been known as it /// was made. fn move_wanted(&self) -> Option { - let Storage::Shadow { image, texels, .. } = &self.0.storage else { + let shared = self.s(); + let Storage::Shadow { image, texels, .. } = &shared.storage else { return None; }; - let mut pending = lock(&self.0.pending_move); + let mut pending = lock(&shared.pending_move); let wanted = pending.as_ref().and_then(|pending| { - if self.0.moved.get().is_some() || self.shadowed_again() { + if shared.moved.get().is_some() || self.shadowed_again() { return None; } let checks = &image.device.shared().in_place; @@ -690,9 +691,10 @@ impl Texture { copied.then_some(Kind::Form { plan, swapped }) } Made::Move { storage, counted } => { - let moves = self.0.moved.get().is_none() && !self.shadowed_again(); + let shared = self.s(); + let moves = shared.moved.get().is_none() && !self.shadowed_again(); if !moves { - *lock(&self.0.pending_move) = None; + *lock(&shared.pending_move) = None; } let pooled = matches!(counted, MoveCount::Pooled(_)); moves.then(|| Kind::Move { @@ -702,7 +704,7 @@ impl Texture { }) } Made::Refused => { - *lock(&self.0.pending_move) = None; + *lock(&self.s().pending_move) = None; None } }; @@ -795,7 +797,7 @@ impl Texture { /// queues with its own fences and events. fn shadow_goes_after_move(&self, core: &mut EncoderCore, pooled: bool) -> Arc { let moved = Arc::new(AtomicBool::new(false)); - let Storage::Shadow { image, copies, .. } = &self.0.storage else { + let Storage::Shadow { image, copies, .. } = &self.s().storage else { return moved; }; if !image.identity.tracked { @@ -823,14 +825,15 @@ impl Texture { /// docs). fn shadowed_again(&self) -> bool { let usage = (self.usage_shadow_copies()).is_some_and(|copies| !copies.copies_bytes()); - usage || lock(&self.0.render_shadow).is_some() + usage || lock(&self.s().render_shadow).is_some() } /// Wait, a shadow over host pages (or the device's pooled memory) made before its class's /// in-place verdicts, to move in place once they pass (the module docs): `pending` what it /// moves with. pub(crate) fn wait_to_move_in_place(&self, pending: in_place::PendingMove) { - let Storage::Shadow { texels, .. } = &self.0.storage else { + let shared = self.s(); + let Storage::Shadow { texels, .. } = &shared.storage else { return; }; let wait = MoveWait { @@ -841,7 +844,7 @@ impl Texture { usage: pending.usage, texel: texels.texel_bytes(), }; - *lock(&self.0.pending_move) = Some(pending); + *lock(&shared.pending_move) = Some(pending); let device = self.device(); let forms = &device.shared().textures.storage_forms; lock(&forms.moves).push(wait); @@ -934,7 +937,8 @@ impl Prepared { let Kind::Move { storage, moved, .. } = &self.kind else { return false; }; - let Storage::Shadow { image: shadow, .. } = &texture.0.storage else { + let shared = texture.s(); + let Storage::Shadow { image: shadow, .. } = &shared.storage else { return false; }; if texture.shadowed_again() { @@ -943,9 +947,9 @@ impl Prepared { let Some(storage) = lock(storage).take() else { return false; }; - *lock(&texture.0.pending_move) = None; + *lock(&shared.pending_move) = None; let views = lock(&shadow.views); - let swapped = texture.0.moved.set(storage).is_ok(); + let swapped = shared.moved.set(storage).is_ok(); if swapped { shadow.views_go(); } diff --git a/crates/metal2vulkan-runtime/src/texture/usage_shadow.rs b/crates/metal2vulkan-runtime/src/texture/usage_shadow.rs index 90567cc9a..d36e3b1ea 100644 --- a/crates/metal2vulkan-runtime/src/texture/usage_shadow.rs +++ b/crates/metal2vulkan-runtime/src/texture/usage_shadow.rs @@ -259,17 +259,19 @@ impl Texture { /// The copies of the texture's shadow, where a binding made it: its attached reads' now, /// where it has faces (`texture/faces.rs`). pub(crate) fn usage_shadow_copies(&self) -> Option> { - if let Some(faces) = self.0.faces.get() { + let parts = self.s(); + if let Some(faces) = parts.faces.get() { return Some(Arc::clone(faces.shadow().copies())); } - (self.0.usage_shadow.get()).map(|shadow| Arc::clone(&shadow.copies)) + (parts.usage_shadow.get()).map(|shadow| Arc::clone(&shadow.copies)) } /// The copies of the shadow a binding beyond its usage made of a texture with faces, beside /// its attached reads' (`texture/faces.rs`, **Frozen**); `None` for every other texture. pub(crate) fn usage_shadow_copies_beside(&self) -> Option> { - self.0.faces.get()?; - (self.0.usage_shadow.get()).map(|shadow| Arc::clone(&shadow.copies)) + let parts = self.s(); + parts.faces.get()?; + (parts.usage_shadow.get()).map(|shadow| Arc::clone(&shadow.copies)) } /// The texture's shadow, made at its first need (the module docs), `need` a binding's that @@ -279,23 +281,24 @@ impl Texture { /// (`shadow_log.rs`). fn usage_shadow(&self, call: &'static str, need: Need) -> Result, Error> { let attached = matches!(need, Need::AttachedRead); + let parts = self.s(); // A texture with faces: its attached reads take the face it does not present; any other // binding a shadow of its own of the face it presents, which ends its turns // (`texture/faces.rs`, **Frozen**). - if let Some(faces) = self.0.faces.get() { + if let Some(faces) = parts.faces.get() { if attached { return Ok(faces.shadow()); } self.freeze_faces(); } - if let Some(shadow) = self.0.usage_shadow.get() { + if let Some(shadow) = parts.usage_shadow.get() { return Ok(Arc::clone(shadow)); } - let _making = lock(&self.0.usage_shadow_making); - if let Some(faces) = self.0.faces.get().filter(|_| attached) { + let _making = lock(&parts.usage_shadow_making); + if let Some(faces) = parts.faces.get().filter(|_| attached) { return Ok(faces.shadow()); } - if let Some(shadow) = self.0.usage_shadow.get() { + if let Some(shadow) = parts.usage_shadow.get() { return Ok(Arc::clone(shadow)); } // An attached read of a texture that may take faces makes them in the shadow's place. @@ -320,7 +323,7 @@ impl Texture { }; self.log_usage_shadow(call, need); let shadow = Arc::new(shadow); - if self.0.usage_shadow.set(Arc::clone(&shadow)).is_err() { + if parts.usage_shadow.set(Arc::clone(&shadow)).is_err() { return Err(internal("a usage shadow made twice")); } // Counted once it can be read, so a list made after the count reads it. @@ -441,7 +444,7 @@ impl Texture { ) } Storage::Shadow { texels, .. } => (Some(&**texels), "a shadow of the bytes".to_owned()), - Storage::Image(_) if self.0.faces.get().is_some() => ( + Storage::Image(_) if self.s().faces.get().is_some() => ( None, "an image of its own, one of two faces that take turns (texture/faces.rs)" .to_owned(), diff --git a/crates/metal2vulkan-runtime/src/texture/view_shadow.rs b/crates/metal2vulkan-runtime/src/texture/view_shadow.rs index 6895783a1..9733054c1 100644 --- a/crates/metal2vulkan-runtime/src/texture/view_shadow.rs +++ b/crates/metal2vulkan-runtime/src/texture/view_shadow.rs @@ -219,7 +219,7 @@ impl Texture { /// into such a view (probe `a8write`: an `A8Unorm` view of an `R8Unorm` texture stores the /// fragment's alpha). Refused as the shadow's image is. pub(crate) fn view_render_shadow(&self, call: &'static str) -> Result { - let mut held = lock(&self.0.render_shadow); + let mut held = lock(&self.s().render_shadow); if let Some(shadow) = held.as_ref() { return Ok(shadow.clone()); } diff --git a/crates/metal2vulkan-runtime/src/texture/ycbcr_image.rs b/crates/metal2vulkan-runtime/src/texture/ycbcr_image.rs index 27e2071c6..d9353cfb6 100644 --- a/crates/metal2vulkan-runtime/src/texture/ycbcr_image.rs +++ b/crates/metal2vulkan-runtime/src/texture/ycbcr_image.rs @@ -408,7 +408,7 @@ impl Texture { /// The uniform texel buffer view of the texture's planes read in place (the module docs), made /// at its first bind and kept with the texels. Internal for a texture whose planes are not. pub(crate) fn planes_view(&self) -> Result { - let (Some(p), Some(texels)) = (&self.0.planes_in_place, self.buffer_texels()) else { + let (Some(p), Some(texels)) = (&self.s().planes_in_place, self.buffer_texels()) else { return Err(internal( "a planes view of a texture without planes in place", )); @@ -438,7 +438,7 @@ impl Texture { /// them makes, through their texel buffer or their image (the module docs). Internal for a /// texture whose planes are not. pub(crate) fn planes_use(&self, read: Access) -> Result, Error> { - let (Some(p), Some(texels)) = (&self.0.planes_in_place, self.buffer_texels()) else { + let (Some(p), Some(texels)) = (&self.s().planes_in_place, self.buffer_texels()) else { return Err(internal( "a planes use of a texture without planes in place", )); @@ -728,7 +728,7 @@ impl Texture { /// texels are no conversion of planes, none of whose stores is measured; as `new_texture` /// refuses the image. pub(crate) fn ycbcr_render_shadow(&self, call: &'static str) -> Result { - let mut held = lock(&self.0.render_shadow); + let mut held = lock(&self.s().render_shadow); if let Some(shadow) = held.as_ref() { return Ok(shadow.clone()); } diff --git a/docs/API.md b/docs/API.md index 5c49966ca..fbbcdd8ae 100644 --- a/docs/API.md +++ b/docs/API.md @@ -3648,20 +3648,27 @@ bound. functions, address pools, uses of guest RAM, no-copy buffers, `Private` buffers, buffers in the runtime's own pages (fresh pages, and the blocks of pages the `Shared` and `Managed` buffers lie in where the device's checks found a held host-page import costs its submissions nothing and - textures over such pages take what they take over its own memory) and `Private` heaps with the - buffers placed in them made before it go on, a `Private` buffer's or heap's contents lost (it reads zero); the - other objects made before it are refused (`MadeBeforeRecovery`), where Metal's go on; the calls - during it wait for it, and a - device call the loss met while it ran runs again after it. A no-copy buffer is made again over + textures over such pages take what they take over its own memory), `Private` heaps with the + buffers placed in them, textures of `new_texture`, textures over the buffers carried and views of + them made before it go on, the contents of a `Private` buffer or heap lost (it reads zero) and of + a texture of `new_texture` (it reads as a new one); the other objects made before it are refused + (`MadeBeforeRecovery`), where Metal's go on; the calls during it wait for it, and a device call + the loss met while it ran runs again after it. A no-copy buffer is made again over the same pages on the new `VkDevice`, as its making or last rebind made it, so the caller's import gate, resolver of guest RAM runs and dma-buf source are asked again, on the thread that recovers, before the new device serves; its deallocator runs at its release once no `VkDevice`'s import of its pages is left. A detached no-copy buffer, and a no-copy heap's buffers, are refused. A `Private` heap is the same heap on the new `VkDevice` (its identity, address and label), its bytes new memory that reads zero, with the buffers placed in it; buffers and - textures are made in it again, and the textures it made before are refused, as every texture - made before the recovery is. A `Shared` heap, whose bytes are pooled host-visible memory the - device allocated, is refused with its buffers, as a pooled buffer is. + textures are made in it again, and the textures it made before are refused, as a heap's + textures are. A texture of `new_texture`, one over a buffer the recovery carried and a view of + either are the same texture object on the new `VkDevice` (its identity, resource ID, label and + purgeable state): the first made again in new memory, which reads as a new texture of its + descriptor, one over a buffer made again over the buffer's bytes there, a view of its parent's + image there. Their images on the lost `VkDevice` stay with them, and keep it, until they go. A + heap's texture, one over the caller's `VkImage`, a sparse or shareable texture and one over a + buffer left are refused, with their views. A `Shared` heap, whose bytes are pooled host-visible + memory the device allocated, is refused with its buffers, as a pooled buffer is. - `metal2vulkan-degrade-private-properties-unknown` (precision). `PrivatePropertiesUnknown`: Apple's private device properties the device has no answer for: no document describes them and nothing the device reports maps to them. Cost: the device gives no answer for them (`PrivateAnswer::value` is diff --git a/docs/REFUSALS.md b/docs/REFUSALS.md index 0de2081d9..c5881a78d 100644 --- a/docs/REFUSALS.md +++ b/docs/REFUSALS.md @@ -157,7 +157,7 @@ Columns: | `SparseTexture` | A sparse texture (`MTLTexture.isSparse`) bound at `slot`, where a function observes the residency of its accesses (`sparse_color::resident()`) and... | - | `-` | via a helper: 2: `crates/metal2vulkan/src/bind/plan/slots.rs (check_sparse_textures, 2 sites)` | `rare`: sparse residency reads | | `TextureSize` | A texture whose extent, array layers, or level count is past what the device takes for its format, type, and usage (`Capability::Limit` names the... | devices short of a device limit the site names | `device` | 1: `crates/metal2vulkan-runtime/src/image_plan.rs (check_image_limits)` | `app`: a texture past a device's image limits | | `TextureSampleCount` | A texture sample count the device does not take for its format, type, and usage | devices short of a Vulkan property the site names; devices without VkFeature::MultisampleArrayImage; every device (no Vulkan mechanism) | `device` | 3: `crates/metal2vulkan-runtime/src/image_plan.rs (check_image_limits)`, `crates/metal2vulkan-runtime/src/image_plan.rs (plan_held, 2 sites)` | `app`: a sample count a device lacks for the texture | -| `TextureView` | A texture view Vulkan cannot make exactly on this image | every device (no Vulkan mechanism); every device (not implemented) | `ours` | 9: `crates/metal2vulkan-runtime/src/binding_view.rs (binding_view)`, `crates/metal2vulkan-runtime/src/texture.rs (view)` (+6) | `app`: a texture view Vulkan cannot make exactly | +| `TextureView` | A texture view Vulkan cannot make exactly on this image | every device (no Vulkan mechanism); every device (not implemented) | `ours` | 9: `crates/metal2vulkan-runtime/src/binding_view.rs (binding_view)`, `crates/metal2vulkan-runtime/src/texture.rs (view_as)` (+6) | `app`: a texture view Vulkan cannot make exactly | | `TextureSwizzle` | A texture swizzle whose Metal behavior is not measured | devices short of a Vulkan feature the site names; every device (not implemented) | `ours` | 7: `crates/metal2vulkan-runtime/src/binding_view.rs (binding_view)`, `crates/metal2vulkan-runtime/src/texture.rs (may_view)` (+5) | `app`: texture swizzles whose Metal behaviour is unmeasured | | `MipmapGeneration` | `generateMipmapsForTexture:` that cannot run on the device | devices without a format's usage; every device (not implemented) | `ours` | 7: `crates/metal2vulkan-runtime/src/blit_texture.rs (mipmaps)`, `crates/metal2vulkan-runtime/src/mipmap_pick.rs (new)` (+3) | `app`: generateMipmapsForTexture: of a format or chain neither the device's blits nor the compute filter can run | | `HostMemory` | A buffer over the caller's host memory without a copy (`newBufferWithBytesNoCopy:`) | devices without VkExtension::ExtExternalMemoryHost; drivers with defect UnpinnablePagesBreakHostMemory; every device (no Vulkan mechanism); every device (not implemented) | `ours` | 8: `crates/metal2vulkan-runtime/src/host_memory.rs (new, 3 sites)`, `crates/metal2vulkan-runtime/src/host_memory.rs (no_pointer_refusal)` (+4) | `system`: newBufferWithBytesNoCopy: where the device cannot import the memory | @@ -362,7 +362,7 @@ Columns: | `ShaderCacheCapacity` | A shader cache capacity, on disk or in memory, of zero | every device (a public call's own check of its arguments) | `ours`: this crate's shader caches: Metal exposes no capacity | 1: `crates/metal2vulkan-runtime/src/shader_cache/mod.rs (of)` | `-` | | `MaxCommandBufferCount` | A command queue's `maxCommandBufferCount` of zero | every device (a public call's own check of its arguments) | `metal-measured`: an Apple M3 Max: Metal's command queue creation asserts "invalid descriptor.maxCommandBufferCount value 0", with and without API validation | 2: `crates/metal2vulkan-runtime/src/queue.rs (new_command_queue_unshared_now)`, `crates/metal2vulkan-runtime/src/queue.rs (new_command_queue_with_max_command_buffer_count_now)` | `-` | | `Texture` | A texture descriptor Metal stops (`Invalid`), or plain Metal answers nil for (`Nil`) | every device (a public call's own check of its arguments) | `delegated`: TextureProblem, section 9 | 7: `crates/metal2vulkan-runtime/src/buffer_texture.rs (make_texture_over)`, `crates/metal2vulkan-runtime/src/texture.rs (image_error)` (+3) | `-` | -| `TextureView` | A texture view Metal stops, or a use of a texture its usage does not allow | every device (a public call's own check of its arguments) | `delegated`: ViewProblem, section 9 | 6: `crates/metal2vulkan-runtime/src/texture.rs (subview, 2 sites)`, `crates/metal2vulkan-runtime/src/texture.rs (view, 2 sites)` (+1) | `-` | +| `TextureView` | A texture view Metal stops, or a use of a texture its usage does not allow | every device (a public call's own check of its arguments) | `delegated`: ViewProblem, section 9 | 6: `crates/metal2vulkan-runtime/src/texture.rs (subview, 2 sites)`, `crates/metal2vulkan-runtime/src/texture.rs (view_as, 2 sites)` (+1) | `-` | | `Copy` | A texture copy Metal stops | every device (a public call's own check of its arguments) | `delegated`: CopyProblem, section 9 | 25: `crates/metal2vulkan-runtime/src/blit_texture.rs (buffer_into_texture)`, `crates/metal2vulkan-runtime/src/blit_texture.rs (check_slice_level)` (+17) | `-` | | `Mipmap` | A `generate_mipmaps` Metal stops | every device (a public call's own check of its arguments) | `delegated`: MipmapProblem, section 9 | 1: `crates/metal2vulkan-runtime/src/blit_texture.rs (mipmaps)` | `-` | | `BufferTexture` | A texture over a buffer plain Metal itself refuses | every device (a public call's own check of its arguments) | `delegated`: BufferTextureProblem, section 9 | 3: `crates/metal2vulkan-runtime/src/buffer_texture.rs (refusal_error, 2 sites)`, `crates/metal2vulkan-runtime/src/capabilities.rs (linear_alignment_rule)` | `-` | @@ -443,12 +443,12 @@ Columns: | `TextureProblem::NoTextureOfFormat` | A format of which Metal makes no texture from a descriptor alone | every device (a public call's own check of its arguments) | `metal-measured`: an Apple M4, macOS 27.0.1, and an M3 Max under 26.7: plain Metal answers nil from the device, a heap and a buffer, for every texture type the format takes | 3: `crates/metal2vulkan-runtime/src/buffer_texture.rs (make_texture_over)`, `crates/metal2vulkan-runtime/src/texture_descriptor.rs (check_made, 2 sites)` | `-` | | `TextureProblem::PastLargestSide` | A width, height or depth past the largest side Metal makes the type with, `max` | every device (a public call's own check of its arguments) | `metal-measured`: an M3 Max, macOS 27.0.1: plain Metal asserts "MTLTextureDescriptor has width (16385) greater than the maximum allowed size of 16384", the layer off, where the side itself is made | 1: `crates/metal2vulkan-runtime/src/texture_descriptor.rs (check_made)` | `-` | | `ViewProblem::NotAFormat` | [`PixelFormat::Invalid`] or [`PixelFormat::Unspecialized`] | every device (a public call's own check of its arguments) | `metal-measured`: an M3 Max, macOS 26.7: plain Metal makes no such view and answers nil, as the consumer reported | 1: `crates/metal2vulkan-runtime/src/view_plan.rs (check_format)` | `-` | -| `ViewProblem::FormatIncompatible` | A format Metal never views the texture's as | every device (a public call's own check of its arguments) | `metal-documented`: Metal aborts "source texture pixelFormat not compatible with texture view pixelFormat" | 5: `crates/metal2vulkan-runtime/src/texture.rs (view)`, `crates/metal2vulkan-runtime/src/view_plan.rs (check_format, 4 sites)` | `-` | +| `ViewProblem::FormatIncompatible` | A format Metal never views the texture's as | every device (a public call's own check of its arguments) | `metal-documented`: Metal aborts "source texture pixelFormat not compatible with texture view pixelFormat" | 5: `crates/metal2vulkan-runtime/src/texture.rs (view_as)`, `crates/metal2vulkan-runtime/src/view_plan.rs (check_format, 4 sites)` | `-` | | `ViewProblem::TypeIncompatible` | A texture type Metal does not view the texture's type as | every device (a public call's own check of its arguments) | `unknown`: plain Metal's answer for a view type the texture's type is not viewed as is unmeasured: the cube view of a 2D texture on record is stopped over its slice range, not its type | 1: `crates/metal2vulkan-runtime/src/view_plan.rs (check_view)` | `-` | | `ViewProblem::LevelRange` | An empty level range, or one past the texture's levels | every device (a public call's own check of its arguments) | `metal-measured`: an Apple M3 Max, macOS 27.0.1: plain Metal asserts "(newLevelRange.location + newLevelRange.length)(7) must be <= `[texture mipmapLevelCount](4)`", and "newLevelRange.length must not be 0" for an empty one | 3: `crates/metal2vulkan-runtime/src/binding_view.rs (binding_view)`, `crates/metal2vulkan-runtime/src/texture.rs (subview)` (+1) | `-` | | `ViewProblem::SliceRange` | An empty slice range, or one past the texture's slices | every device (a public call's own check of its arguments) | `metal-measured`: an Apple M3 Max, macOS 27.0.1: plain Metal asserts "(newSliceRange.location + newSliceRange.length)(3) must be <= (2)" | 2: `crates/metal2vulkan-runtime/src/texture.rs (subview)`, `crates/metal2vulkan-runtime/src/view_plan.rs (check_view)` | `-` | | `ViewProblem::SliceCount` | A slice count the view's type does not take | every device (a public call's own check of its arguments) | `metal-measured`: an Apple M3 Max, macOS 27.0.1: plain Metal asserts "newSliceRange.length(2) must equal (1) for textureType (MTLTextureType2D)" | 1: `crates/metal2vulkan-runtime/src/view_plan.rs (check_view)` | `-` | -| `ViewProblem::BufferSlices` | More than one slice of a 2D array over a buffer | every device (a public call's own check of its arguments) | `metal-measured`: an M3 Max and an M4: Metal asserts `sliceRange.length == 1` on such a view, plain and validated | 1: `crates/metal2vulkan-runtime/src/texture.rs (view)` | `-` | +| `ViewProblem::BufferSlices` | More than one slice of a 2D array over a buffer | every device (a public call's own check of its arguments) | `metal-measured`: an M3 Max and an M4: Metal asserts `sliceRange.length == 1` on such a view, plain and validated | 1: `crates/metal2vulkan-runtime/src/texture.rs (view_as)` | `-` | | `ViewProblem::SwizzledViewOfNoUsage` | A view with a swizzle of a texture whose usage is none (a texture made with Apple's private usage 0x8 alone) | every device (a public call's own check of its arguments) | `metal-measured`: an Apple M4: Metal asserts `_usage != MTLTextureUsageUnknown` on such a view, plain and validated | 1: `crates/metal2vulkan-runtime/src/view_plan.rs (check_view)` | `-` | | `CopyProblem::CpuAccessPrivate` | `replaceRegion` or `getBytes` of a private texture | every device (a public call's own check of its arguments) | `metal-takes`: an M4, macOS 27.0.1: plain Metal copies a private texture of up to 8 KiB as a shared one, so the refusal reaches past it; most of 16 KiB and more end the process | 6: `crates/metal2vulkan-runtime/src/buffer_texture.rs (bytes)`, `crates/metal2vulkan-runtime/src/buffer_texture.rs (past_runs)` (+4) | `-` | | `CopyProblem::Region` | A level or slice past the texture, or a region past its level (a compressed region past the level's last block) | every device (a public call's own check of its arguments) | `unknown`: plain Metal's answer for a blit level, slice or region past the texture is unmeasured | 10: `crates/metal2vulkan-runtime/src/blit_plan.rs (plan_levels_copy)`, `crates/metal2vulkan-runtime/src/blit_plan.rs (source_region, 2 sites)` (+6) | `-` | @@ -680,7 +680,7 @@ Each refusal's sites, with the function that builds it. - `feature::SparseTexture`: `crates/metal2vulkan/src/bind/plan/slots.rs (check_sparse_textures, 2 sites)` - `feature::TextureSize`: `crates/metal2vulkan-runtime/src/image_plan.rs (check_image_limits)` - `feature::TextureSampleCount`: `crates/metal2vulkan-runtime/src/image_plan.rs (check_image_limits)`; `crates/metal2vulkan-runtime/src/image_plan.rs (plan_held, 2 sites)` -- `feature::TextureView`: `crates/metal2vulkan-runtime/src/binding_view.rs (binding_view)`; `crates/metal2vulkan-runtime/src/texture.rs (view)`; `crates/metal2vulkan-runtime/src/texture/decoded_twin.rs (make_second_twin)`; `crates/metal2vulkan-runtime/src/texture/view_shadow.rs (apart_refusal)`; `crates/metal2vulkan-runtime/src/texture/ycbcr_image.rs (converted_view)`; `crates/metal2vulkan-runtime/src/texture/ycbcr_image.rs (luma_view)`; `crates/metal2vulkan-runtime/src/view_plan.rs (check_format)`; `crates/metal2vulkan-runtime/src/view_plan.rs (check_view, 2 sites)` +- `feature::TextureView`: `crates/metal2vulkan-runtime/src/binding_view.rs (binding_view)`; `crates/metal2vulkan-runtime/src/texture.rs (view_as)`; `crates/metal2vulkan-runtime/src/texture/decoded_twin.rs (make_second_twin)`; `crates/metal2vulkan-runtime/src/texture/view_shadow.rs (apart_refusal)`; `crates/metal2vulkan-runtime/src/texture/ycbcr_image.rs (converted_view)`; `crates/metal2vulkan-runtime/src/texture/ycbcr_image.rs (luma_view)`; `crates/metal2vulkan-runtime/src/view_plan.rs (check_format)`; `crates/metal2vulkan-runtime/src/view_plan.rs (check_view, 2 sites)` - `feature::TextureSwizzle`: `crates/metal2vulkan-runtime/src/binding_view.rs (binding_view)`; `crates/metal2vulkan-runtime/src/texture.rs (may_view)`; `crates/metal2vulkan/src/bind/plan/resources.rs (plain_texture)`; `crates/metal2vulkan/src/lower/sampler/select.rs (select_one)`; `crates/metal2vulkan/src/lower/texture/mod.rs (select_read_as)`; `crates/metal2vulkan/src/lower/texture/mod.rs (select_write)`; `crates/metal2vulkan/src/lower/texture/slice.rs (select)` - `feature::MipmapGeneration`: `crates/metal2vulkan-runtime/src/blit_texture.rs (mipmaps)`; `crates/metal2vulkan-runtime/src/mipmap_pick.rs (new)`; `crates/metal2vulkan-runtime/src/mipmap_plan.rs (blit_lack, 2 sites)`; `crates/metal2vulkan-runtime/src/mipmap_plan.rs (plan_mipmaps, 2 sites)`; `crates/metal2vulkan-runtime/src/shadow.rs (run)` - `feature::HostMemory`: `crates/metal2vulkan-runtime/src/host_memory.rs (new, 3 sites)`; `crates/metal2vulkan-runtime/src/host_memory.rs (no_pointer_refusal)`; `crates/metal2vulkan-runtime/src/host_memory.rs (not_importable)`; `crates/metal2vulkan-runtime/src/host_memory.rs (refuse_unwritable)`; `crates/metal2vulkan-runtime/src/host_memory.rs (unpinnable)`; `crates/metal2vulkan-runtime/src/host_ram.rs (new)` @@ -774,7 +774,7 @@ Each refusal's sites, with the function that builds it. - `gap::ProvokingVertex`: `crates/metal2vulkan-runtime/src/render/restart.rs (gap)` - `gap::WideLines`: `crates/metal2vulkan-runtime/src/render/restart.rs (gap)` - `gap::PrimitiveIdIndices`: `crates/metal2vulkan-runtime/src/render.rs (draw_resident)` -- `gap::RotatedTexture`: `crates/metal2vulkan-runtime/src/buffer_texture.rs (turned_plane)`; `crates/metal2vulkan-runtime/src/rotated.rs (new, 2 sites)`; `crates/metal2vulkan-runtime/src/shadow.rs (unmerged)`; `crates/metal2vulkan-runtime/src/texture.rs (view)`; `crates/metal2vulkan-runtime/src/texture/rotation.rs (check_rotated_reach)`; `crates/metal2vulkan-runtime/src/texture/rotation.rs (copied_image)`; `crates/metal2vulkan-runtime/src/texture/usage_shadow.rs (new_usage_shadow)` +- `gap::RotatedTexture`: `crates/metal2vulkan-runtime/src/buffer_texture.rs (turned_plane)`; `crates/metal2vulkan-runtime/src/rotated.rs (new, 2 sites)`; `crates/metal2vulkan-runtime/src/shadow.rs (unmerged)`; `crates/metal2vulkan-runtime/src/texture.rs (view_as)`; `crates/metal2vulkan-runtime/src/texture/rotation.rs (check_rotated_reach)`; `crates/metal2vulkan-runtime/src/texture/rotation.rs (copied_image)`; `crates/metal2vulkan-runtime/src/texture/usage_shadow.rs (new_usage_shadow)` - `gap::DetachTextures`: `crates/metal2vulkan-runtime/src/buffer_descriptor.rs (rebind_host_pages)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs (make_texture_over)`; `crates/metal2vulkan-runtime/src/detach.rs (detach_host_pages)`; `crates/metal2vulkan-runtime/src/texture/stand_in.rs (new_stand_in)`; `crates/metal2vulkan-runtime/src/texture/stand_in.rs (stand_in_while_detached)`; `crates/metal2vulkan-runtime/src/texture/stand_in.rs (stand_ins, 2 sites)` - `gap::TextureBufferLevels`: `crates/metal2vulkan-runtime/src/texture_descriptor.rs (check_made)` - `gap::WriteSwizzle`: `crates/metal2vulkan-runtime/src/texture_descriptor.rs (check_made)` @@ -850,7 +850,7 @@ Each refusal's sites, with the function that builds it. - `invalid::ShaderCacheCapacity`: `crates/metal2vulkan-runtime/src/shader_cache/mod.rs (of)` - `invalid::MaxCommandBufferCount`: `crates/metal2vulkan-runtime/src/queue.rs (new_command_queue_unshared_now)`; `crates/metal2vulkan-runtime/src/queue.rs (new_command_queue_with_max_command_buffer_count_now)` - `invalid::Texture`: `crates/metal2vulkan-runtime/src/buffer_texture.rs (make_texture_over)`; `crates/metal2vulkan-runtime/src/texture.rs (image_error)`; `crates/metal2vulkan-runtime/src/texture.rs (texture_as)`; `crates/metal2vulkan-runtime/src/texture/heap.rs (planned_heap_texture, 2 sites)`; `crates/metal2vulkan-runtime/src/texture_descriptor.rs (error, 2 sites)` -- `invalid::TextureView`: `crates/metal2vulkan-runtime/src/texture.rs (subview, 2 sites)`; `crates/metal2vulkan-runtime/src/texture.rs (view, 2 sites)`; `crates/metal2vulkan-runtime/src/texture.rs (view_error, 2 sites)` +- `invalid::TextureView`: `crates/metal2vulkan-runtime/src/texture.rs (subview, 2 sites)`; `crates/metal2vulkan-runtime/src/texture.rs (view_as, 2 sites)`; `crates/metal2vulkan-runtime/src/texture.rs (view_error, 2 sites)` - `invalid::Copy`: `crates/metal2vulkan-runtime/src/blit_texture.rs (buffer_into_texture)`; `crates/metal2vulkan-runtime/src/blit_texture.rs (check_slice_level)`; `crates/metal2vulkan-runtime/src/blit_texture.rs (copy_error)`; `crates/metal2vulkan-runtime/src/blit_texture.rs (copy_from_texture_to_buffer)`; `crates/metal2vulkan-runtime/src/blit_texture.rs (copy_texture_slices)`; `crates/metal2vulkan-runtime/src/blit_texture.rs (multisampled_region)`; `crates/metal2vulkan-runtime/src/blit_texture.rs (plan_copy, 2 sites)`; `crates/metal2vulkan-runtime/src/blit_texture.rs (plane_copy)`; `crates/metal2vulkan-runtime/src/blit_texture.rs (region)`; `crates/metal2vulkan-runtime/src/blit_texture.rs (texel_copies)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs (bytes)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs (past_runs)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs (write_past)`; `crates/metal2vulkan-runtime/src/sample_interleave.rs (plan, 2 sites)`; `crates/metal2vulkan-runtime/src/texture.rs (copy_error)`; `crates/metal2vulkan-runtime/src/texture.rs (get_bytes)`; `crates/metal2vulkan-runtime/src/texture.rs (host_copy, 5 sites)`; `crates/metal2vulkan-runtime/src/texture.rs (replace)`; `crates/metal2vulkan-runtime/src/texture/heap.rs (contents)` - `invalid::Mipmap`: `crates/metal2vulkan-runtime/src/blit_texture.rs (mipmaps)` - `invalid::BufferTexture`: `crates/metal2vulkan-runtime/src/buffer_texture.rs (refusal_error, 2 sites)`; `crates/metal2vulkan-runtime/src/capabilities.rs (linear_alignment_rule)` @@ -914,12 +914,12 @@ Each refusal's sites, with the function that builds it. - `subproblem::TextureProblem::NoTextureOfFormat`: `crates/metal2vulkan-runtime/src/buffer_texture.rs (make_texture_over)`; `crates/metal2vulkan-runtime/src/texture_descriptor.rs (check_made, 2 sites)` - `subproblem::TextureProblem::PastLargestSide`: `crates/metal2vulkan-runtime/src/texture_descriptor.rs (check_made)` - `subproblem::ViewProblem::NotAFormat`: `crates/metal2vulkan-runtime/src/view_plan.rs (check_format)` -- `subproblem::ViewProblem::FormatIncompatible`: `crates/metal2vulkan-runtime/src/texture.rs (view)`; `crates/metal2vulkan-runtime/src/view_plan.rs (check_format, 4 sites)` +- `subproblem::ViewProblem::FormatIncompatible`: `crates/metal2vulkan-runtime/src/texture.rs (view_as)`; `crates/metal2vulkan-runtime/src/view_plan.rs (check_format, 4 sites)` - `subproblem::ViewProblem::TypeIncompatible`: `crates/metal2vulkan-runtime/src/view_plan.rs (check_view)` - `subproblem::ViewProblem::LevelRange`: `crates/metal2vulkan-runtime/src/binding_view.rs (binding_view)`; `crates/metal2vulkan-runtime/src/texture.rs (subview)`; `crates/metal2vulkan-runtime/src/view_plan.rs (check_view)` - `subproblem::ViewProblem::SliceRange`: `crates/metal2vulkan-runtime/src/texture.rs (subview)`; `crates/metal2vulkan-runtime/src/view_plan.rs (check_view)` - `subproblem::ViewProblem::SliceCount`: `crates/metal2vulkan-runtime/src/view_plan.rs (check_view)` -- `subproblem::ViewProblem::BufferSlices`: `crates/metal2vulkan-runtime/src/texture.rs (view)` +- `subproblem::ViewProblem::BufferSlices`: `crates/metal2vulkan-runtime/src/texture.rs (view_as)` - `subproblem::ViewProblem::SwizzledViewOfNoUsage`: `crates/metal2vulkan-runtime/src/view_plan.rs (check_view)` - `subproblem::CopyProblem::CpuAccessPrivate`: `crates/metal2vulkan-runtime/src/buffer_texture.rs (bytes)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs (past_runs)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs (write_past)`; `crates/metal2vulkan-runtime/src/copy_plan.rs (plan_host_copy)`; `crates/metal2vulkan-runtime/src/texture.rs (host_copy)`; `crates/metal2vulkan-runtime/src/texture/heap.rs (contents)` - `subproblem::CopyProblem::Region`: `crates/metal2vulkan-runtime/src/blit_plan.rs (plan_levels_copy)`; `crates/metal2vulkan-runtime/src/blit_plan.rs (source_region, 2 sites)`; `crates/metal2vulkan-runtime/src/blit_texture.rs (check_slice_level)`; `crates/metal2vulkan-runtime/src/blit_texture.rs (copy_texture_slices)`; `crates/metal2vulkan-runtime/src/blit_texture.rs (multisampled_region)`; `crates/metal2vulkan-runtime/src/blit_texture.rs (region)`; `crates/metal2vulkan-runtime/src/copy_plan.rs (check_region, 2 sites)`; `crates/metal2vulkan-runtime/src/texture.rs (host_copy)`