diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index ee776736d..5fe9e2fbd 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -867,6 +867,10 @@ meanwhile wait for it. 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. +- 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 + handle, so the consumer destroys what it made with them through it. - Each recovery is announced (`device-recovered`), naming the hang's command buffer. - `Device::raw` answers the new `VkDevice`'s handles once a later call asks; the handles it answered before stay valid until then, and the lost `VkDevice` stays alive until then, so the diff --git a/crates/metal2vulkan-runtime/src/address_pool.rs b/crates/metal2vulkan-runtime/src/address_pool.rs index ce1cc2ebe..f9168da1a 100644 --- a/crates/metal2vulkan-runtime/src/address_pool.rs +++ b/crates/metal2vulkan-runtime/src/address_pool.rs @@ -8,6 +8,7 @@ //! its model gives (`BufferDescriptor::with_pool_slot`): the buffer answers Metal's address. use super::address::{AddressPlacement, AddressSpace, GpuAddress}; +use super::device::carry::LineDevice; use super::device::lock; use super::error::Error; use super::Device; @@ -24,9 +25,9 @@ use std::sync::{Arc, Mutex}; /// device shares, and holds no Vulkan object, so buffers made after the recovery take its slots /// as before. pub struct AddressPool { - /// A root handle (`device/line.rs`): of the device, never of the `VkDevice` it was reserved - /// on. - device: Device, + /// The device: its root handle, which a buffer's placement in a slot matches by its line, + /// and the generation handle `device` answers. + device: LineDevice, /// The device's address space, which its span is of. addresses: Arc>, address: GpuAddress, @@ -44,10 +45,17 @@ impl AddressPool { self.length } - /// The device whose address space the pool is of: a handle of the device whose calls go to - /// the `VkDevice` that serves it, across its recoveries. + /// The device whose address space the pool is of: a generation handle of the device: of the generation the pool was made on, then of + /// each one the device's recoveries carried the pool to. A handle taken of it keeps meaning that + /// generation: its raw handles are that generation's `VkDevice`'s, kept alive while held. pub fn device(&self) -> &Device { - &self.device + self.device.generation() + } + + /// A root handle of the pool's device, which a buffer's placement in a slot matches by its + /// line. + pub(crate) fn root_device(&self) -> &Device { + self.device.root() } } @@ -92,7 +100,7 @@ impl Device { ) -> Result { let address = (self.address_space_for(placement)).reserve_pool(placement, length)?; Ok(AddressPool { - device: self.root(), + device: LineDevice::new(self), addresses: Arc::clone(&self.shared().addresses), address, length, diff --git a/crates/metal2vulkan-runtime/src/buffer_descriptor.rs b/crates/metal2vulkan-runtime/src/buffer_descriptor.rs index 1c138367a..617469f3d 100644 --- a/crates/metal2vulkan-runtime/src/buffer_descriptor.rs +++ b/crates/metal2vulkan-runtime/src/buffer_descriptor.rs @@ -370,8 +370,8 @@ impl Device { self.shared_place(CALL, other, &contents, length, placement, in_pool)? } (None, Some((pool, offset))) => { - if !pool.device().same(self) { - return Err(pool.device().foreign(CALL, self)); + if !pool.root_device().same(self) { + return Err(pool.root_device().foreign(CALL, self)); } Place::InPool { pool: pool.gpu_address().0, diff --git a/crates/metal2vulkan-runtime/src/depth_stencil.rs b/crates/metal2vulkan-runtime/src/depth_stencil.rs index 82efd9937..2eadbd1e7 100644 --- a/crates/metal2vulkan-runtime/src/depth_stencil.rs +++ b/crates/metal2vulkan-runtime/src/depth_stencil.rs @@ -7,8 +7,8 @@ //! pipeline's static depth/stencil state, or as dynamic state where the pipeline makes it dynamic //! (`render.rs`). Metal makes a state of any descriptor, masks wider than the 8-bit stencil //! included (measured on an M4), so creation refuses nothing. A state holds no Vulkan object, so -//! it is no generation's (`device/line.rs`): it holds a root handle of its device and goes on past -//! the device's recovery, as Metal's state does. +//! it goes on past the device's recovery, as Metal's state does, the recovery carrying its handle +//! of the device alone (`device/carry.rs`'s `LineDevice`). //! //! A state's `gpuResourceID` below Apple10 is the release's answer, not a refusal: Metal's API //! validation stops the call ("Obtaining the resourceID of a DepthStencilState object requires @@ -32,8 +32,9 @@ use std::sync::Arc; pub struct DepthStencilState(Arc); struct Shared { - /// A root handle of the device (`device/line.rs`): of whatever generation serves. - device: Device, + /// The device: its root handle, which the encoders' checks match by its line, and the + /// generation handle `device` answers. + device: LineDevice, descriptor: DepthStencilDescriptor, vulkan: metal2vulkan::metal::state::DepthStencilState, } @@ -68,7 +69,7 @@ impl Device { descriptor: &DepthStencilDescriptor, ) -> Result { Ok(DepthStencilState(Arc::new(Shared { - device: self.root(), + device: LineDevice::new(self), descriptor: *descriptor, vulkan: depth_stencil_state(descriptor), }))) @@ -76,10 +77,16 @@ impl Device { } impl DepthStencilState { - /// `device`: the device that made the state, as a root handle, whose calls go to the - /// generation that serves (the module docs). + /// `device`: a generation handle of the device: of the generation the state was made on, then of + /// each one the device's recoveries carried the state to. A handle taken of it keeps meaning that + /// generation: its raw handles are that generation's `VkDevice`'s, kept alive while held. pub fn device(&self) -> &Device { - &self.0.device + self.0.device.generation() + } + + /// A root handle of the state's device, which an encoder of any of its generations matches. + pub(super) fn root_device(&self) -> &Device { + self.0.device.root() } /// The descriptor the state was made with. No Metal counterpart: Metal's state keeps none. @@ -92,7 +99,7 @@ impl DepthStencilState { /// `NotImplemented(IndirectRenderCommands)` on a device that claims Apple10: indirect render /// commands that set a depth/stencil state are not built. pub fn gpu_resource_id(&self) -> Result { - if self.0.device.supports_family(GpuFamily::Apple10.raw()) { + if (self.0.device.root()).supports_family(GpuFamily::Apple10.raw()) { return Err(Error::NotImplemented(RuntimeGap::IndirectRenderCommands( IndirectRule::CommandRenderStates, ))); diff --git a/crates/metal2vulkan-runtime/src/device/carry.rs b/crates/metal2vulkan-runtime/src/device/carry.rs index bf2bc34fc..a3d0cb72c 100644 --- a/crates/metal2vulkan-runtime/src/device/carry.rs +++ b/crates/metal2vulkan-runtime/src/device/carry.rs @@ -3,8 +3,8 @@ //! 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, which hold no Vulkan object, are no generation's (`fence.rs`, -//! `depth_stencil.rs`, `library.rs`, `address_pool.rs`): nothing here carries them. +//! 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 @@ -101,9 +101,10 @@ use crate::resource::ObjectId; use crate::Error; use std::cell::UnsafeCell; use std::collections::HashSet; +use std::convert::Infallible; use std::mem::ManuallyDrop; use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::{Arc, Mutex, Weak}; +use std::sync::{Arc, Mutex, OnceLock, Weak}; /// The least size at which the registry drops gone objects' entries. const PRUNE_FLOOR: usize = 256; @@ -139,8 +140,13 @@ struct State { ram_uses: Vec>, /// The program's heaps, held weakly: as `ram_uses`. heaps: 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 handles' entries. + links_prune_at: usize, /// The recovery took the generation's objects ([`Carry::take`]): what is kept from now on, /// its maker carries. taken: bool, @@ -186,6 +192,7 @@ pub(crate) struct Taken { events: Vec>, ram_uses: Vec>, heaps: Vec, + links: Vec>, } impl Carry { @@ -230,6 +237,19 @@ impl Carry { 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. + fn link(&self, link: &Arc) -> bool { + let mut state = lock(&self.state); + if state.links.len() >= state.links_prune_at { + state.links.retain(|link| link.strong_count() > 0); + state.links_prune_at = (2 * state.links.len()).max(PRUNE_FLOOR); + } + state.links.push(Arc::downgrade(link)); + state.taken + } + /// The live objects of `shared`, this generation, for its recovery to carry: its events, its /// uses of guest RAM, its heaps and its program resources' buffers (`Owners::buffers`). From /// now on, each one made is its maker's to carry. @@ -244,6 +264,7 @@ 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(), + links: state.links.iter().filter_map(Weak::upgrade).collect(), } } @@ -566,7 +587,11 @@ impl Device { events, ram_uses, heaps, + links, } = shared.carry.take(shared); + for link in &links { + link.carry(next); + } let mut carried = Carried::default(); for event in &events { carried.event(event.carry(next)); @@ -663,3 +688,105 @@ impl Drop for MadeOn { } } } + +/// The device of an object that holds no Vulkan object (a fence, a depth/stencil state, a library +/// and its functions, an address pool), which a recovery carries as its handle of the device +/// alone: a root handle, which the object's own calls and checks go through +/// ([`root`](Self::root): of whatever generation serves, matched by its line), and the generation +/// handle its `device` answers ([`generation`](Self::generation)): the generation it was made on, +/// then each one the device's recoveries carried it to. A handle taken of it keeps meaning that +/// generation, as any object's device does: its raw handles are that generation's `VkDevice`'s, +/// kept alive while the caller holds it. The object lets go of a lost generation's handle at that +/// generation's rest ([`MadeOn`]), so it holds nothing of it after. +#[derive(Clone)] +pub(crate) struct LineDevice { + root: Device, + first: Arc, +} + +/// One generation's handle of a [`LineDevice`], linked to the next generation's once a recovery +/// carried the object there. +pub(crate) struct GenerationLink { + device: MadeOn, + next: OnceLock>, +} + +impl LineDevice { + /// The device of an object made on `made_on`, a generation handle: its handle kept by the + /// generation's registry for its recovery to carry ([`Carry::take`]), or carried by its maker + /// where the recovery took the generation's objects before then ([`Device::carry_late`]). + pub(crate) fn new(made_on: &Device) -> LineDevice { + LineDevice { + root: made_on.root(), + first: GenerationLink::kept(made_on), + } + } + + /// The root handle: of whatever generation serves, as the object is no generation's. + pub(crate) fn root(&self) -> &Device { + &self.root + } + + /// The generation handle of the generation the object was carried to last, else of the one + /// it was made on. + pub(crate) fn generation(&self) -> &Device { + let mut link = &self.first; + while let Some(next) = link.next.get() { + link = next; + } + &link.device + } +} + +impl std::fmt::Debug for LineDevice { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.generation().fmt(f) + } +} + +impl GenerationLink { + /// `device`'s handle, a generation handle, kept by its generation's registry; carried by + /// this maker where that generation's recovery took its objects before. + fn kept(device: &Device) -> Arc { + let link = Arc::new(GenerationLink { + device: MadeOn::new(device.clone()), + next: OnceLock::new(), + }); + if device.shared().carry.link(&link) { + device.carry_late(|serving| { + link.carry(serving); + Ok::<(), Infallible>(()) + }); + } + link + } + + /// Carry the handle to `to`, the generation this one's recovery made: `to`'s handle linked + /// after it, and this one let go of at the lost generation's rest. Nothing where it was + /// carried already. + fn carry(self: &Arc, to: &Device) { + if self.next.get().is_some() { + return; + } + if self.next.set(GenerationLink::kept(to)).is_err() { + // Another carry of it came first. + return; + } + let lost = Device::clone(&self.device); + let parts = Box::new(LostHandle(Arc::clone(self))); + lost.shared().carry.lost(lost.shared(), parts); + } +} + +/// A [`LineDevice`]'s handle of a lost generation, let go of once none of the generation's command +/// buffers may record. +struct LostHandle(Arc); + +impl LostParts for LostHandle { + fn release(self: Box) { + // SAFETY: its next link is set, so the object's device answers a later generation's handle + // (`LineDevice::generation`), and its own calls and checks go through its root handle: no + // reach of the object reads this handle any more. + unsafe { self.0.device.let_go() }; + } +} diff --git a/crates/metal2vulkan-runtime/src/dynamic_library.rs b/crates/metal2vulkan-runtime/src/dynamic_library.rs index d7fb3e2cc..867c49094 100644 --- a/crates/metal2vulkan-runtime/src/dynamic_library.rs +++ b/crates/metal2vulkan-runtime/src/dynamic_library.rs @@ -59,8 +59,8 @@ impl Device { &self, library: &Library, ) -> Result { - if !library.device().same(self) { - return Err(library.device().foreign("new_dynamic_library", self)); + if !library.root_device().same(self) { + return Err(library.root_device().foreign("new_dynamic_library", self)); } self.dynamic_library(library.compile_library().clone()) } diff --git a/crates/metal2vulkan-runtime/src/error.rs b/crates/metal2vulkan-runtime/src/error.rs index 39d4d24c1..6459db15f 100644 --- a/crates/metal2vulkan-runtime/src/error.rs +++ b/crates/metal2vulkan-runtime/src/error.rs @@ -2132,8 +2132,8 @@ pub enum RuntimeGap { /// recovery did not carry to the new one (the runtime made a new `VkDevice` behind the device, /// 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 (no generation's: they hold no Vulkan - /// object), the uses of guest RAM, the no-copy buffers (made again over the same pages), the `Private` buffers + /// 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 diff --git a/crates/metal2vulkan-runtime/src/fence.rs b/crates/metal2vulkan-runtime/src/fence.rs index 8d1508395..5ff79b3b4 100644 --- a/crates/metal2vulkan-runtime/src/fence.rs +++ b/crates/metal2vulkan-runtime/src/fence.rs @@ -5,10 +5,10 @@ //! "after this encoder's work" in the device's submission order, and a later encoder's //! `wait_for_fence` becomes a barrier from that work's stages, or a wait for its `VkQueue` when //! the update ran on another ([`tracker`](super::tracker)). A fence has no Vulkan object: it is -//! an identity the tracker keys on. So it is no generation's (`device/line.rs`): it holds a -//! root handle of its device, and goes on past the device's recovery as Metal's fence does, an -//! encoder of any generation updating and waiting for it, its updates on a lost generation -//! gone with that generation's work. +//! an identity the tracker keys on. So it goes on past the device's recovery as Metal's fence +//! does, the recovery carrying its handle of the device alone (`device/carry.rs`'s +//! `LineDevice`): an encoder of any generation updates and waits for it, its updates on a lost +//! generation gone with that generation's work. //! - **Resource barriers** order dispatches of one compute encoder: one global memory barrier, //! as for a scope barrier. //! - **A render encoder's** fences order the render stages its calls name, as the M3 Max's do @@ -72,6 +72,7 @@ use super::blit::BlitCommandEncoder; use super::compute::ComputeCommandEncoder; +use super::device::carry::LineDevice; use super::device::{lock, Device}; use super::encoder::EncoderCore; use super::error::Error; @@ -93,8 +94,9 @@ use std::sync::{Arc, Mutex}; pub struct Fence(Arc); struct FenceShared { - /// A root handle of the device (`device/line.rs`): of whatever generation serves. - device: Device, + /// The device: its root handle, which the encoders' checks match by its line, and the + /// generation handle `device` answers. + device: LineDevice, key: ResourceKey, label: Mutex>, } @@ -128,10 +130,10 @@ impl Device { } /// [`Device::new_fence`] on the generation that serves (`device/line.rs`): a fence of the - /// device whatever generation serves, which holds none (the module docs). + /// device whatever generation serves (the module docs). pub(crate) fn new_fence_now(&self) -> Fence { Fence(Arc::new(FenceShared { - device: self.root(), + device: LineDevice::new(self), key: ResourceKey::new(), label: Mutex::new(None), })) @@ -139,10 +141,16 @@ impl Device { } impl Fence { - /// `device`: a root handle, whose calls go to the generation that serves, as the fence is no - /// generation's (the module docs). + /// `device`: a generation handle of the device: of the generation the fence was made on, then of + /// each one the device's recoveries carried the fence to. A handle taken of it keeps meaning that + /// generation: its raw handles are that generation's `VkDevice`'s, kept alive while held. pub fn device(&self) -> &Device { - &self.0.device + self.0.device.generation() + } + + /// A root handle of the fence's device, which an encoder of any of its generations matches. + pub(super) fn root_device(&self) -> &Device { + self.0.device.root() } /// `setLabel:`. @@ -170,7 +178,7 @@ impl EncoderCore { fence: &Fence, draws: Option, ) -> Result<(), Error> { - self.check_device(call, fence.device())?; + self.check_device(call, fence.root_device())?; self.uses().update_fence(fence.0.key, draws); Ok(()) } @@ -185,7 +193,7 @@ impl EncoderCore { fence: &Fence, draws: Option, ) -> Result<(), Error> { - self.check_device(call, fence.device())?; + self.check_device(call, fence.root_device())?; self.uses().wait_for_fence(fence.0.key, draws); // Metal shows the work the wait orders after it the bytes the update's writer left, so // no shadowed texture's image is carried on (`shadow::ShadowCarry`). diff --git a/crates/metal2vulkan-runtime/src/function_table.rs b/crates/metal2vulkan-runtime/src/function_table.rs index 4e6c258ad..e0477a1b4 100644 --- a/crates/metal2vulkan-runtime/src/function_table.rs +++ b/crates/metal2vulkan-runtime/src/function_table.rs @@ -195,8 +195,10 @@ impl Maker { /// link in `functions` or `binary_functions`. A function of another device is refused /// (`Invalid(ForeignObject)`). fn function_handle(self, function: &Function) -> Result, Error> { - if !function.device().same(self.device()) { - return Err(function.device().foreign("function_handle", self.device())); + if !function.root_device().same(self.device()) { + return Err(function + .root_device() + .foreign("function_handle", self.device())); } let handle = self .linked_functions() diff --git a/crates/metal2vulkan-runtime/src/library.rs b/crates/metal2vulkan-runtime/src/library.rs index 74029d01a..610253cd4 100644 --- a/crates/metal2vulkan-runtime/src/library.rs +++ b/crates/metal2vulkan-runtime/src/library.rs @@ -9,10 +9,11 @@ //! it with, as its stage or as a function the stage links ([`Function::linked_function`], //! `MTLLinkedFunctions`), and the options it was made with (`newFunctionWithDescriptor:`): one //! compiled to a binary is what Metal takes in a stage's `binaryFunctions` and adds to a made -//! pipeline state. A library and its functions hold no Vulkan object, so they are no generation's -//! (`device/line.rs`): they hold a root handle of their device and go on past the device's -//! recovery, as Metal's do. +//! pipeline state. A library and its functions hold no Vulkan object, so they go on past the +//! device's recovery, as Metal's do, the recovery carrying their handle of the device alone +//! (`device/carry.rs`'s `LineDevice`), which a library's functions share. +use super::device::carry::LineDevice; use super::device::device_error; use super::error::{invalid, Problem, RuntimeGap}; use super::Device; @@ -33,8 +34,9 @@ use std::sync::{Arc, Mutex}; /// A Metal library (`MTLLibrary`). Cheap to clone; `Send + Sync`. #[derive(Clone, Debug)] pub struct Library { - /// A root handle of the device (`device/line.rs`): of whatever generation serves. - device: Device, + /// The device: its root handle, which the checks of the calls that take the library match + /// by its line, and the generation handle `device` answers. + device: LineDevice, library: metal2vulkan::library::Library, /// What the library holds of the sampler IDs its functions' pipeline states numbered, shared /// with every live library of the same content (`resource_ids/numbered.rs`). @@ -56,8 +58,8 @@ pub struct Library { /// Cheap to clone; `Send + Sync`. #[derive(Clone, Debug)] pub struct Function { - /// A root handle of the device (`device/line.rs`), its library's. - device: Device, + /// The device, its library's. + device: LineDevice, function: metal2vulkan::library::Function, constants: FunctionConstantValues, /// Whether the function was made with constant values (`newFunctionWithName:constantValues:`), @@ -196,7 +198,7 @@ impl Device { ) -> Library { let holds = LibraryHolds::of(&self.shared().resource_ids, *library.content_hash()); Library { - device: self.root(), + device: LineDevice::new(self), library, holds, reflections: Arc::default(), @@ -205,9 +207,16 @@ impl Device { } impl Library { - /// `device`: a root handle, whose calls go to the generation that serves (the module docs). + /// `device`: a generation handle of the device: of the generation the library was made on, then of + /// each one the device's recoveries carried the library to. A handle taken of it keeps meaning that + /// generation: its raw handles are that generation's `VkDevice`'s, kept alive while held. pub fn device(&self) -> &Device { - &self.device + self.device.generation() + } + + /// A root handle of the library's device, which the calls that take it match by its line. + pub(crate) fn root_device(&self) -> &Device { + self.device.root() } /// `functionNames`, in the library's table order. A Core Image kernel library's extern @@ -413,9 +422,16 @@ impl Library { } impl Function { - /// `device`: a root handle, whose calls go to the generation that serves (the module docs). + /// `device`: a generation handle of the device: of the generation its library was made on, then of + /// each one the device's recoveries carried its library to. A handle taken of it keeps meaning that + /// generation: its raw handles are that generation's `VkDevice`'s, kept alive while held. pub fn device(&self) -> &Device { - &self.device + self.device.generation() + } + + /// A root handle of the function's device, which the calls that take it match by its line. + pub(crate) fn root_device(&self) -> &Device { + self.device.root() } /// `name`: the specialized name a [`FunctionDescriptor`] made the function with, else the diff --git a/crates/metal2vulkan-runtime/src/pipeline/additions.rs b/crates/metal2vulkan-runtime/src/pipeline/additions.rs index d4c5629ad..797a82fd8 100644 --- a/crates/metal2vulkan-runtime/src/pipeline/additions.rs +++ b/crates/metal2vulkan-runtime/src/pipeline/additions.rs @@ -482,8 +482,8 @@ fn added( }; let mut descriptor = descriptor.clone(); for function in functions { - if !function.device().same(device) { - return Err(function.device().foreign(call, device)); + if !function.root_device().same(device) { + return Err(function.root_device().foreign(call, device)); } let linked = function.linked_function(); if !linked.precompiled { @@ -543,8 +543,8 @@ fn added_counting( /// of another device. fn ignored(device: &Device, call: &'static str, functions: &[Function]) -> Result<(), Error> { for function in functions { - if !function.device().same(device) { - return Err(function.device().foreign(call, device)); + if !function.root_device().same(device) { + return Err(function.root_device().foreign(call, device)); } } Ok(()) diff --git a/crates/metal2vulkan-runtime/src/pipeline/mod.rs b/crates/metal2vulkan-runtime/src/pipeline/mod.rs index c0f1dc8eb..12b025eae 100644 --- a/crates/metal2vulkan-runtime/src/pipeline/mod.rs +++ b/crates/metal2vulkan-runtime/src/pipeline/mod.rs @@ -600,9 +600,9 @@ impl Device { function: &Function, options: &PipelineOptions, ) -> Result { - if !function.device().same(self) { + if !function.root_device().same(self) { return Err(function - .device() + .root_device() .foreign("new_compute_pipeline_state_with_function", self)); } self.new_compute_pipeline_state_now( @@ -722,8 +722,8 @@ impl Device { function: &Function, options: &PipelineOptions, ) -> Result<(ComputePipelineState, Option), Error> { - if !function.device().same(self) { - return Err(function.device().foreign( + if !function.root_device().same(self) { + return Err(function.root_device().foreign( "new_compute_pipeline_state_with_function_and_reflection", self, )); diff --git a/crates/metal2vulkan-runtime/src/render.rs b/crates/metal2vulkan-runtime/src/render.rs index b51b04bed..7eccd0470 100644 --- a/crates/metal2vulkan-runtime/src/render.rs +++ b/crates/metal2vulkan-runtime/src/render.rs @@ -3574,7 +3574,7 @@ impl RenderLowering { }); if let Some(state) = state { self.core - .check_device("set_depth_stencil_state", state.device())?; + .check_device("set_depth_stencil_state", state.root_device())?; } // One boolean: a pass that sets one but draws under none keeps a depth's signs. self.depth_writes |= state.is_some_and(|s| s.descriptor().depth_write_enabled); diff --git a/crates/metal2vulkan-runtime/src/render/call_checks.rs b/crates/metal2vulkan-runtime/src/render/call_checks.rs index ec26e0a44..4c8c249ce 100644 --- a/crates/metal2vulkan-runtime/src/render/call_checks.rs +++ b/crates/metal2vulkan-runtime/src/render/call_checks.rs @@ -278,7 +278,7 @@ impl CallChecks { C::DepthStencilState(held) => { let state = held.map(|held| log.depth_stencil(held)); if let Some(state) = state { - check_device(device, "set_depth_stencil_state", state.device())?; + check_device(device, "set_depth_stencil_state", state.root_device())?; } self.state.set_depth_stencil(state); Ok(Checked::Logged) diff --git a/crates/metal2vulkan-runtime/src/sparse/encoder.rs b/crates/metal2vulkan-runtime/src/sparse/encoder.rs index 4b15f0ad0..a809b322e 100644 --- a/crates/metal2vulkan-runtime/src/sparse/encoder.rs +++ b/crates/metal2vulkan-runtime/src/sparse/encoder.rs @@ -371,9 +371,9 @@ impl ResourceStateCommandEncoder { /// Refused (`Invalid`): a fence of another device. pub fn update_fence(&mut self, fence: &Fence) -> Result<(), Error> { let _for = self.open.command_buffer.notices_for(); - if !fence.device().same(self.open.command_buffer.device()) { + if !fence.root_device().same(self.open.command_buffer.device()) { return Err(fence - .device() + .root_device() .foreign("update_fence", self.open.command_buffer.device())); } let key = fence.key(); @@ -393,9 +393,9 @@ impl ResourceStateCommandEncoder { pub fn wait_for_fence(&mut self, fence: &Fence) -> Result<(), Error> { let _for = self.open.command_buffer.notices_for(); const CALL: &str = "wait_for_fence"; - if !fence.device().same(self.open.command_buffer.device()) { + if !fence.root_device().same(self.open.command_buffer.device()) { return Err(fence - .device() + .root_device() .foreign(CALL, self.open.command_buffer.device())); } let key = fence.key();