From 62923811dc49ae0b70a8f178cd548bc5d436090e Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Thu, 12 Nov 2026 15:06:56 -0800 Subject: [PATCH] A library and its functions go on past their device's recovery What: a library holds a root handle of its device (Device::root) rather than the generation it was made on, and its functions take that handle, as a fence does. A library is the compile layer's parsed library and a function the compile layer's function with its constants, no Vulkan object; their sampler-ID holds are the line's resource IDs, which every generation shares. So a pipeline made from them on any generation passes its device check (same matches a root handle by its line), and they no longer keep the lost VkDevice alive. Docs: library.rs, carry.rs, MadeBeforeRecovery (libraries leave the refused list), the device-recovered cost (degradation.rs and docs/API.md), the runtime README. REFUSALS.md regenerated: unchanged. Why: after a recovery a pipeline made from a library or function made before it was refused NotImplemented(MadeBeforeRecovery); Metal's library goes on. Verified: see the lane run reported with this sha (the test commit before it fails, this one passes). --- crates/metal2vulkan-runtime/README.md | 14 +++---- .../metal2vulkan-runtime/src/degradation.rs | 16 ++++---- .../metal2vulkan-runtime/src/device/carry.rs | 5 ++- crates/metal2vulkan-runtime/src/error.rs | 41 ++++++++++--------- crates/metal2vulkan-runtime/src/library.rs | 12 ++++-- docs/API.md | 15 +++---- 6 files changed, 55 insertions(+), 48 deletions(-) diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index b142534dd..6d234cce9 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -832,10 +832,10 @@ meanwhile wait for it. second run could not have, runs on the new `VkDevice` where the loss came before it took them, and completes on the lost one where the loss came after, its object then one made before the recovery. -- The recovery carries the events, the fences, the depth/stencil states, 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. +- The recovery carries the events, the fences, the depth/stencil states, the libraries and their + functions, 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. 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 @@ -857,9 +857,9 @@ 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, libraries, 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, 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. - 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 diff --git a/crates/metal2vulkan-runtime/src/degradation.rs b/crates/metal2vulkan-runtime/src/degradation.rs index 628bc65fa..7458f7354 100644 --- a/crates/metal2vulkan-runtime/src/degradation.rs +++ b/crates/metal2vulkan-runtime/src/degradation.rs @@ -2335,14 +2335,14 @@ degradations! { /// waits on), and where its new `VkDevice` could not be made (the device then answers as /// a lost one). DeviceRecovered = "device-recovered", Performance, - "the events, fences, depth/stencil states, 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"; + "the events, fences, depth/stencil states, libraries, functions, 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"; /// 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 a90ac25f5..0afb6c4d4 100644 --- a/crates/metal2vulkan-runtime/src/device/carry.rs +++ b/crates/metal2vulkan-runtime/src/device/carry.rs @@ -2,8 +2,9 @@ //! 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 and a depth/stencil state, which hold no Vulkan -//! object, are no generation's (`fence.rs`, `depth_stencil.rs`): nothing here carries them. +//! objects across its GPU's recovery. A fence, a depth/stencil state, a library and a function, +//! which hold no Vulkan object, are no generation's (`fence.rs`, `depth_stencil.rs`, +//! `library.rs`): nothing here carries them. //! //! - **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 diff --git a/crates/metal2vulkan-runtime/src/error.rs b/crates/metal2vulkan-runtime/src/error.rs index 1f2f40818..21a39563c 100644 --- a/crates/metal2vulkan-runtime/src/error.rs +++ b/crates/metal2vulkan-runtime/src/error.rs @@ -2131,26 +2131,27 @@ pub enum RuntimeGap { /// An object made before its device's recovery from the loss of its `VkDevice` that the /// 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 and the depth/stencil states (no - /// generation's: they have 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 library, 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`). + /// recovery). The recovery carries the events, the fences, the depth/stencil states, the + /// libraries and their functions (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 + /// (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`). 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/library.rs b/crates/metal2vulkan-runtime/src/library.rs index e5932ad24..74029d01a 100644 --- a/crates/metal2vulkan-runtime/src/library.rs +++ b/crates/metal2vulkan-runtime/src/library.rs @@ -9,7 +9,9 @@ //! 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. +//! 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. use super::device::device_error; use super::error::{invalid, Problem, RuntimeGap}; @@ -31,6 +33,7 @@ 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, library: metal2vulkan::library::Library, /// What the library holds of the sampler IDs its functions' pipeline states numbered, shared @@ -53,6 +56,7 @@ 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, function: metal2vulkan::library::Function, constants: FunctionConstantValues, @@ -192,7 +196,7 @@ impl Device { ) -> Library { let holds = LibraryHolds::of(&self.shared().resource_ids, *library.content_hash()); Library { - device: self.clone(), + device: self.root(), library, holds, reflections: Arc::default(), @@ -201,7 +205,7 @@ impl Device { } impl Library { - /// `device`. + /// `device`: a root handle, whose calls go to the generation that serves (the module docs). pub fn device(&self) -> &Device { &self.device } @@ -409,7 +413,7 @@ impl Library { } impl Function { - /// `device`. + /// `device`: a root handle, whose calls go to the generation that serves (the module docs). pub fn device(&self) -> &Device { &self.device } diff --git a/docs/API.md b/docs/API.md index 7936c896f..0a2b66aa1 100644 --- a/docs/API.md +++ b/docs/API.md @@ -3670,13 +3670,14 @@ bound. recovery announced: where a call waited past 10 seconds for the recovery under way, where its command buffers in flight took past 10 seconds to fail, and where its new `VkDevice` could not be made, after which the device answers as a lost one. `Device::recover_for_test` runs the - same recovery with no GPU fault. Cost: the events, fences, depth/stencil states, 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 + same recovery with no GPU fault. Cost: the events, fences, depth/stencil states, libraries, + functions, 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 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