diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index 5b1a66595..209457879 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -726,12 +726,20 @@ 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. -- An 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)`. Make it again. Metal's objects go on. -- The lost `VkDevice` is destroyed once the objects made on it went and, where `Device::raw` +- The recovery carries the events, the `Private` buffers and the buffers in the runtime's fresh + pages 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 fresh pages keeps its bytes and its + `contents` pointer. A `Private` buffer's contents are lost: it reads zero. +- 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 + `Managed` buffers (their `contents` pointer is the lost memory's mapping), no-copy buffers, + heaps, textures, pipeline states, libraries and exportable memory or events. Make it again. + Metal's objects go on. The recovery's notice counts the buffers and events it carried and left. +- 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. `vk_devices_made` and `device_recoveries` count the rest. + 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. - 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/degradation.rs b/crates/metal2vulkan-runtime/src/degradation.rs index 9f3c47cfb..df98fbf9a 100644 --- a/crates/metal2vulkan-runtime/src/degradation.rs +++ b/crates/metal2vulkan-runtime/src/degradation.rs @@ -2223,14 +2223,17 @@ degradations! { /// (`GpuRecoveryVictim`); every later call goes to the new `VkDevice`. Announced at each /// recovery, from the call that made it; the payload names the culprit (where two or more /// `VkQueue`s had work in flight it is an inference, and says so) and the recovery's - /// time. Announced as well, at most once each per recovery, whatever an earlier recovery - /// announced: where a call waited past 10 seconds for the recovery under way (it waits - /// on), where its command buffers in flight took past 10 seconds to fail (it waits on), - /// and where its new `VkDevice` could not be made (the device then answers as a lost - /// one). + /// time, and the objects it carried to the new `VkDevice` and left refused, by kind + /// (`device/carry.rs`). Announced as well, at most once each per recovery, whatever an + /// earlier recovery announced: where a call waited past 10 seconds for the recovery under + /// way (it waits on), where its command buffers in flight took past 10 seconds to fail (it + /// waits on), and where its new `VkDevice` could not be made (the device then answers as + /// a lost one). DeviceRecovered = "device-recovered", Performance, - "the objects made before the recovery are refused (`MadeBeforeRecovery`), where \ - Metal's go on; the calls during it wait for it"; + "the events, `Private` buffers and buffers in fresh pages made before it go on, a \ + `Private` buffer'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/line.rs b/crates/metal2vulkan-runtime/src/device/line.rs index e2a167a87..a7c59e351 100644 --- a/crates/metal2vulkan-runtime/src/device/line.rs +++ b/crates/metal2vulkan-runtime/src/device/line.rs @@ -16,8 +16,10 @@ //! [`Device::at_serving_taking`]). A *generation* handle holds one generation: the device of //! every object made on it (a buffer's, a pipeline state's), through which the object's Vulkan //! calls reach its own `VkDevice` alone, its drop included. So no object's Vulkan handle ever -//! reaches another generation's `VkDevice`, and an object made before a recovery is refused -//! where it meets the new generation (`RuntimeGap::MadeBeforeRecovery`, `error.rs`). +//! reaches another generation's `VkDevice`: the recovery carries the program's events, `Private` +//! buffers and buffers in fresh pages to the new generation, each with new Vulkan objects there +//! (`carry.rs`), and any other object made before it is refused where it meets the new +//! generation (`RuntimeGap::MadeBeforeRecovery`, `error.rs`). //! - **The states.** [`State`]: the line serves one generation (`Live`); once it is lost, the //! first call that needs the device recovers it (`Lost`, then claimed), while every other call //! waits for that recovery, the first to wait past [`RECOVERY_NOTICE`] announcing it and waiting @@ -29,8 +31,9 @@ //! its queues waited idle, each under its lock; then a new `VkDevice` of the same physical //! device, options, queue families and extensions (`create.rs`, the same making as the first), //! whose device-level objects are made as the first generation's were, the shader cache's -//! records kept on disk warm. The calls waiting go on with it, the command queues made before -//! take a new place on it at their next command buffer (`queue.rs`), and it announces +//! records kept on disk warm. It carries the program's objects it can to the new generation +//! before that serves (`carry.rs`). The calls waiting go on with it, the command queues made +//! before take a new place on it at their next command buffer (`queue.rs`), and it announces //! `Degradation::DeviceRecovered`. //! - **Each recovery's notices are its own.** The kinds a device announced go on across its //! generations, each kind announced once for the device, but a recovery's notices @@ -44,10 +47,11 @@ //! `uniqueIdentifier`s, so nothing made after a recovery takes an address or an identity one made //! before holds. //! - **At most two `VkDevice`s.** A generation is destroyed when its last handle goes: the lost -//! one once the objects made on it went, and, where `Device::raw` of a root handle answered its +//! one once the objects left on it went (a carried object lets go of it once none of its +//! command buffers records, `carry.rs`), and, where `Device::raw` of a root handle answered its //! handles, once a later such call answered the new one's (`Line::lend`), the new one serving -//! meanwhile. Counted: `WorkCounts::vk_devices_live`. A second recovery while objects made -//! before the first still live keeps their `VkDevice` as well, counted there too. +//! meanwhile. Counted: `WorkCounts::vk_devices_live`. A second recovery while objects left on +//! the first's lost generation still live keeps their `VkDevice` as well, counted there too. use super::create; use super::{holds, lock, Device, DeviceOptions, DeviceShared, InstanceShared}; @@ -605,8 +609,10 @@ impl Device { /// its queue as Metal counts a hang, so a queue's second revokes it, `AccessRevoked`) and the /// rest as its victims (`GpuRecoveryVictim`); the runtime makes a new `VkDevice` of the same /// physical device, options, queue families and extensions, and every later call of the - /// device, and of its command queues, goes to it. An object made before is refused where it - /// meets it (`RuntimeGap::MadeBeforeRecovery`). Announced (`Degradation::DeviceRecovered`). + /// device, and of its command queues, goes to it. The events, `Private` buffers and buffers in + /// fresh pages made before go on there (`device/carry.rs`); any other object made before is + /// refused where it meets it (`RuntimeGap::MadeBeforeRecovery`). Announced + /// (`Degradation::DeviceRecovered`). /// Returns once the new `VkDevice` serves; where it could not be made, `DeviceLost`, and the /// device answers as a lost one from then on. /// @@ -668,9 +674,10 @@ impl Device { /// the one serving next, and the call then runs on it whole, a loss of it from then on /// following the call, as one after the call returned would. Its checks of the generation's /// loss answer so ([`RunsOn`]): the call is not refused for a loss once it took its - /// arguments, and answers as on a generation lost after it (its objects of that generation, - /// refused where they meet the next: `RuntimeGap::MadeBeforeRecovery`). A line that cannot - /// recover refuses it as before. + /// arguments, and answers as on a generation lost after it: its objects of that generation, + /// carried to the next by their maker where a recovery carries such (`carry.rs`), else refused + /// where they meet the next (`RuntimeGap::MadeBeforeRecovery`). A line that cannot recover + /// refuses it as before. pub(crate) fn at_serving_taking( &self, taken: A, diff --git a/crates/metal2vulkan-runtime/src/error.rs b/crates/metal2vulkan-runtime/src/error.rs index 1c661f5ca..235fed1e5 100644 --- a/crates/metal2vulkan-runtime/src/error.rs +++ b/crates/metal2vulkan-runtime/src/error.rs @@ -2013,15 +2013,22 @@ pub enum RuntimeGap { /// bytes it may reach through a root table), and a resolve target set on a texture a draw of /// the pass read. ColorAttachmentGroups, - /// An object made before its device's recovery from the loss of its `VkDevice` (the runtime - /// made a new `VkDevice` behind the device, announced as `Degradation::DeviceRecovered`; - /// `Device::recover_for_test` runs the same recovery). The object's Vulkan objects are the - /// lost `VkDevice`'s, which serves nothing more, and the runtime does not make them again on - /// the new one: a call that meets it 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 same object made again on the device serves; a command - /// buffer made before the recovery fails as its victim (`GpuRecoveryVictim`). + /// 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 `Private` buffers (their contents lost: + /// they read zero) and the buffers in the runtime's fresh pages (their contents and + /// `contents` pointer kept); every other object's Vulkan objects are the lost `VkDevice`'s, + /// which serves nothing more: a pooled `Shared` or `Managed` buffer, whose `contents` pointer + /// is its lost memory's mapping, a no-copy buffer, a heap and its resources, a texture, a + /// pipeline state, a library, a sampler state, an indirect command buffer, a buffer over the + /// caller's `VkBuffer` or 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 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/in_place.rs b/crates/metal2vulkan-runtime/src/in_place.rs index a39f16583..f5d79222b 100644 --- a/crates/metal2vulkan-runtime/src/in_place.rs +++ b/crates/metal2vulkan-runtime/src/in_place.rs @@ -1324,7 +1324,7 @@ impl Device { /// recovery's new one (`Degradation::DeviceRecovered`) reads the record so too; /// where the lost one's check had not ended, or the device keeps no record (no shader cache /// directory, or `DeviceOptions::fail_in_place_check`), they are pending again, and this - /// answers `false` until the new one's check ends. Buffers made before a + /// answers `false` until the new one's check ends. No-copy buffers made before a /// recovery are refused on the new device (`RuntimeGap::MadeBeforeRecovery`), so a program /// makes its textures over host pages again after one, and asks again. pub fn settle_in_place_checks(&self, timeout: Duration) -> bool { diff --git a/crates/metal2vulkan-runtime/src/tests/device_recovery.rs b/crates/metal2vulkan-runtime/src/tests/device_recovery.rs index b5000d851..7ecd51ad0 100644 --- a/crates/metal2vulkan-runtime/src/tests/device_recovery.rs +++ b/crates/metal2vulkan-runtime/src/tests/device_recovery.rs @@ -34,10 +34,10 @@ const COPIES: u64 = 24; const ATTEMPTS: usize = 6; /// A scratch directory for the device's shader cache, removed when dropped. -struct Scratch(PathBuf); +pub(super) struct Scratch(pub(super) PathBuf); impl Scratch { - fn new() -> Scratch { + pub(super) fn new() -> Scratch { let path = std::env::temp_dir().join(format!("m2v-device-recovery-{}", std::process::id())); std::fs::create_dir_all(&path).unwrap(); Scratch(path) @@ -52,15 +52,15 @@ impl Drop for Scratch { /// The device the cfg selects: a CPU device under `m2v_cpu_icd`, else a GPU, its shader cache /// in `cache`. -fn device(cache: &Path) -> Device { +pub(super) fn device(cache: &Path) -> Device { device_with(cache, None) } /// The degrade notices a device's sink heard, in order. -type Heard = Arc>>; +pub(super) type Heard = Arc>>; /// [`device`], its degrade notices kept in `heard`. -fn heard_device(cache: &Path, heard: &Heard) -> Device { +pub(super) fn heard_device(cache: &Path, heard: &Heard) -> Device { let heard = Arc::clone(heard); device_with( cache, @@ -125,11 +125,13 @@ fn busy(device: &Device, queue: &CommandQueue) -> CommandBuffer { /// The longest the test waits for a command buffer to complete: one that does not fails the test /// at its line, its status named, where an unbounded wait would hang it. -const WAIT: Duration = Duration::from_secs(60); +pub(super) const WAIT: Duration = Duration::from_secs(60); /// The command buffer's final status and error, awaited for at most [`WAIT`]. #[track_caller] -fn outcome(command_buffer: &CommandBuffer) -> (CommandBufferStatus, Option) { +pub(super) fn outcome( + command_buffer: &CommandBuffer, +) -> (CommandBufferStatus, Option) { if command_buffer.wait_until_completed_for(WAIT).is_err() { panic!( "a command buffer did not complete in {WAIT:?}: {:?}, {:?}", @@ -318,7 +320,7 @@ const WAITERS: usize = 3; /// The recovery notices `heard` holds from `from` on whose object is `object`: a recovery's own /// is "the device", a call's wait for one "a call made during the device's recovery", its command /// buffers' failing past the bound "the device's recovery" (`device/line.rs`). -fn recovery_notices(heard: &Heard, from: usize, object: &str) -> Vec { +pub(super) fn recovery_notices(heard: &Heard, from: usize, object: &str) -> Vec { heard.lock().unwrap()[from..] .iter() .filter(|notice| notice.degradation == Degradation::DeviceRecovered) @@ -483,6 +485,7 @@ fn a_call_refused_for_a_loss_under_it_runs_again_on_the_next_generation() { fn a_call_that_took_its_arguments_completes_on_a_generation_lost_after() { let scratch = Scratch::new(); let device = device(&scratch.0); + // A pooled `Shared` buffer, which a recovery leaves refused (`device/carry.rs`). let buffer = device .at_serving_taking(4096, |serving, length| { serving.recover_for_test().unwrap(); diff --git a/crates/metal2vulkan-runtime/src/tests/device_recovery_carry.rs b/crates/metal2vulkan-runtime/src/tests/device_recovery_carry.rs new file mode 100644 index 000000000..298bfbf48 --- /dev/null +++ b/crates/metal2vulkan-runtime/src/tests/device_recovery_carry.rs @@ -0,0 +1,241 @@ +//! What a device's recovery carries to its next generation (`device/carry.rs`): the program's +//! events, `Private` buffers and buffers in fresh pages go on as the same objects, a pooled `Shared` +//! buffer stays refused, and the lost generation goes once nothing records on it and the last +//! object left on it went, however many recoveries the program's objects outlive. +//! +//! 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`). + +use super::device_recovery::{ + device, heard_device, outcome, recovery_notices, Heard, Scratch, WAIT, +}; +use crate::fresh_pages::FRESH_PAGES_PAST; +use crate::{ + Buffer, CommandBufferStatus, CommandQueue, Device, Error, EventRef, ResourceOptions, + RuntimeGap, SharedEvent, SharedEventListener, +}; +use std::sync::mpsc; +use std::time::{Duration, Instant}; + +/// The bytes the tests write and read of each buffer. +const BYTES: u64 = 4096; + +/// The recoveries one process's objects outlive in [`seven_recoveries_end_with_one_live_vk_device`]: +/// one less than the live `VkDevice`s an NVIDIA driver lets a process hold. +const RECOVERIES: u64 = 7; + +/// `buffer`'s first [`BYTES`] bytes set to `byte` by `queue`'s GPU work, completed. +#[track_caller] +fn fill(queue: &CommandQueue, buffer: &Buffer, byte: u8) { + let command_buffer = queue.command_buffer().unwrap(); + let mut blit = command_buffer.blit_command_encoder().unwrap(); + blit.fill_buffer(buffer, 0..BYTES, byte).unwrap(); + blit.end_encoding().unwrap(); + command_buffer.commit().unwrap(); + assert_eq!( + outcome(&command_buffer), + (CommandBufferStatus::Completed, None) + ); +} + +/// `source`'s first [`BYTES`] bytes as `queue`'s GPU work reads them: copied into a new `Shared` +/// buffer of `device`'s serving generation, completed. Refused as the copy's encoding refuses +/// `source`. +#[track_caller] +fn read(device: &Device, queue: &CommandQueue, source: &Buffer) -> Result, Error> { + let target = device.new_buffer(BYTES, ResourceOptions::shared())?; + let command_buffer = queue.command_buffer()?; + let mut blit = command_buffer.blit_command_encoder()?; + blit.copy_from_buffer_to_buffer(source, 0, &target, 0, BYTES)?; + blit.end_encoding()?; + command_buffer.commit()?; + assert_eq!( + outcome(&command_buffer), + (CommandBufferStatus::Completed, None) + ); + let contents = target.contents().unwrap(); + // SAFETY: a `Shared` buffer of `BYTES` bytes, which no work in flight writes. + let bytes = unsafe { std::slice::from_raw_parts(contents.as_ptr(), BYTES as usize) }; + Ok(bytes.to_vec()) +} + +/// `event` signalled to `value` by `queue`'s GPU work, completed. +#[track_caller] +fn signal(queue: &CommandQueue, event: &SharedEvent, value: u64) { + let command_buffer = queue.command_buffer().unwrap(); + (command_buffer.encode_signal_event(EventRef::from(event), value)).unwrap(); + command_buffer.commit().unwrap(); + assert_eq!( + outcome(&command_buffer), + (CommandBufferStatus::Completed, None) + ); + assert!(event.wait_until_signaled_value(value, WAIT)); +} + +/// The device's live `VkDevice`s once they are `live`, waited for at most [`WAIT`]: a generation +/// goes as its last holder lets go of it, which a runtime thread may be a moment after the test's. +fn live_vk_devices(device: &Device, live: u64) -> u64 { + let began = Instant::now(); + loop { + let now = device.work_counts().vk_devices_live; + if now == live || began.elapsed() > WAIT { + return now; + } + std::thread::sleep(Duration::from_millis(5)); + } +} + +/// A recovery carries a `Private` buffer (its address kept, its bytes zero), a buffer in fresh +/// pages (its `contents` pointer and bytes kept, the host's writes through that pointer after +/// the recovery read by the GPU), and a shared event (its value, a listener's notification, a +/// GPU signal after it), and leaves a pooled `Shared` buffer refused, as its notice counts. The +/// pooled buffer keeps the lost `VkDevice`, but nothing of its memory for work: no empty block, +/// and less memory than before the loss. The lost `VkDevice` goes with it. +#[test] +fn a_recovery_carries_events_private_and_fresh_page_buffers() { + let scratch = Scratch::new(); + let heard = Heard::default(); + let device = heard_device(&scratch.0, &heard); + let queue = device.new_command_queue().unwrap(); + let private = device + .new_buffer(BYTES, ResourceOptions::private()) + .unwrap(); + fill(&queue, &private, 7); + assert_eq!( + read(&device, &queue, &private).unwrap(), + vec![7; BYTES as usize] + ); + let address = private.gpu_address(); + // A buffer of the program's in fresh pages, wherever the device takes them. + let fresh = { + let made_on = private.device().clone(); + let fresh = made_on + .fresh_pages_check_buffer(2 * FRESH_PAGES_PAST) + .unwrap(); + made_on.visible(fresh) + }; + assert!( + fresh.in_fresh_pages(), + "{} took no fresh pages: their carry is not exercised", + device.name() + ); + let pointer = fresh.contents().unwrap(); + // SAFETY: the buffer's first `BYTES` bytes, which no work in flight uses. + unsafe { std::ptr::write_bytes(pointer.as_ptr(), 3, BYTES as usize) }; + let pooled = device.new_buffer(BYTES, ResourceOptions::shared()).unwrap(); + let event = device.new_shared_event().unwrap(); + event.set_signaled_value(5); + let listener = SharedEventListener::new(); + let (sent, notified) = mpsc::channel(); + let notification = move |_: &SharedEvent, value: u64| drop(sent.send(value)); + event.notify_listener(&listener, 9, Box::new(notification)); + let before = pooled.device().work_counts_now(); + let from = heard.lock().unwrap().len(); + device.recover_for_test().unwrap(); + let said = recovery_notices(&heard, from, "the device"); + assert_eq!(said.len(), 1, "{said:?}"); + assert!( + said[0].contains( + "it carried 1 events, 1 buffers with their contents and 1 `Private` buffers (4096 \ + bytes) whose contents were lost (they read zero); left refused \ + (`MadeBeforeRecovery`): 1 pooled `Shared` or `Managed` buffers" + ), + "{said:?}" + ); + // The `Private` buffer: the same buffer on the next generation, its bytes zero. + assert!(private.device().generation_serves()); + assert_eq!(private.gpu_address(), address); + assert_eq!( + read(&device, &queue, &private).unwrap(), + vec![0; BYTES as usize] + ); + fill(&queue, &private, 9); + assert_eq!( + read(&device, &queue, &private).unwrap(), + vec![9; BYTES as usize] + ); + // The buffer in fresh pages: the same pointer, the same bytes, and the host's writes through + // the pointer taken before the recovery reach the GPU after it. + assert!(fresh.device().generation_serves() && fresh.in_fresh_pages()); + assert_eq!(fresh.contents(), Some(pointer)); + assert_eq!( + read(&device, &queue, &fresh).unwrap(), + vec![3; BYTES as usize] + ); + // SAFETY: as above. + unsafe { std::ptr::write_bytes(pointer.as_ptr(), 4, BYTES as usize) }; + assert_eq!( + read(&device, &queue, &fresh).unwrap(), + vec![4; BYTES as usize] + ); + // The event: the value the host saw, its listener's notification, the GPU's signals after. + assert_eq!(event.signaled_value(), 5); + signal(&queue, &event, 9); + assert_eq!(notified.recv_timeout(WAIT), Ok(9)); + // The pooled buffer stays the lost generation's, refused where it meets the next. + assert!(!pooled.device().generation_serves()); + let refused = read(&device, &queue, &pooled); + assert!( + matches!( + refused, + Err(Error::NotImplemented(RuntimeGap::MadeBeforeRecovery)) + ), + "{refused:?}" + ); + // It holds the lost `VkDevice`, which keeps no memory for work. + assert_eq!(live_vk_devices(&device, 2), 2); + let after = pooled.device().work_counts_now(); + assert_eq!(after.empty_memory_blocks_live, 0, "{after:?}"); + assert!( + after.device_memory_allocated < before.device_memory_allocated, + "the lost generation holds {} bytes, {} before the loss", + after.device_memory_allocated, + before.device_memory_allocated + ); + eprintln!( + "CARRY-LOST-MEMORY: {}: the lost generation held {} bytes in {} blocks before the loss, \ + {} in {} at rest", + device.name(), + before.device_memory_allocated, + before.memory_blocks_live, + after.device_memory_allocated, + after.memory_blocks_live + ); + drop(pooled); + assert_eq!(live_vk_devices(&device, 1), 1); +} + +/// Seven recoveries, each with the program's carried buffer and event in use between them, end +/// with one live `VkDevice`: no carried object holds a lost generation, so each goes once its +/// command buffers went. The buffer and the event serve on the last generation. +#[test] +fn seven_recoveries_end_with_one_live_vk_device() { + let scratch = Scratch::new(); + let device = device(&scratch.0); + let queue = device.new_command_queue().unwrap(); + let private = device + .new_buffer(BYTES, ResourceOptions::private()) + .unwrap(); + let event = device.new_shared_event().unwrap(); + let began = Instant::now(); + for round in 1..=RECOVERIES { + device.recover_for_test().unwrap(); + let byte = u8::try_from(round).unwrap(); + fill(&queue, &private, byte); + assert_eq!( + read(&device, &queue, &private).unwrap(), + vec![byte; BYTES as usize] + ); + signal(&queue, &event, round); + } + let counts = device.work_counts(); + assert_eq!(counts.device_recoveries, RECOVERIES); + assert_eq!(counts.vk_devices_made, RECOVERIES + 1); + assert_eq!(live_vk_devices(&device, 1), 1); + eprintln!( + "CARRY-RECOVERIES: {}: {RECOVERIES} recoveries in {:?}, {} VkDevices live at the end", + device.name(), + began.elapsed(), + device.work_counts().vk_devices_live + ); +} diff --git a/crates/metal2vulkan-runtime/src/tests/mod.rs b/crates/metal2vulkan-runtime/src/tests/mod.rs index 50907ae84..b639e7d29 100644 --- a/crates/metal2vulkan-runtime/src/tests/mod.rs +++ b/crates/metal2vulkan-runtime/src/tests/mod.rs @@ -121,6 +121,8 @@ mod device_memory_overflow; #[cfg(any(m2v_gpu, m2v_cpu_icd))] mod device_recovery; #[cfg(any(m2v_gpu, m2v_cpu_icd))] +mod device_recovery_carry; +#[cfg(any(m2v_gpu, m2v_cpu_icd))] mod device_registry; #[cfg(any(m2v_gpu, m2v_cpu_icd))] mod direct_arguments_from_compiled; diff --git a/crates/metal2vulkan-validation/src/runtime_lane/device_recovery.rs b/crates/metal2vulkan-validation/src/runtime_lane/device_recovery.rs index 0ecdd5211..fc78fd445 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/device_recovery.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/device_recovery.rs @@ -5,7 +5,8 @@ //! Metal's device survives a GPU recovery: the hung command buffer fails with `GpuHang`, the others //! in flight with `GpuRecoveryVictim`, a queue's second hang revokes it (`AccessRevoked`), and the //! program goes on with the same device and queues. The runtime makes a new `VkDevice` behind the -//! device: its command queues go on, objects made before are refused where they meet the new one +//! device: its command queues go on, the events, `Private` buffers and buffers in fresh pages made +//! before go on with it, other objects made before are refused where they meet the new one //! (`RuntimeGap::MadeBeforeRecovery`), and the lost `VkDevice` goes once they went. The layer //! reporting nothing over each test is the check that no handle of the lost `VkDevice` reached the //! new one. @@ -241,7 +242,8 @@ fn a_recovery_fails_the_command_buffers_on_their_way_as_its_victims() { }); } -/// An object made before a recovery is refused where it meets the new `VkDevice`, typed; the same +/// An object made before a recovery that it does not carry (a pooled `Shared` buffer) is refused +/// where it meets the new `VkDevice`, typed; the same /// object made again serves. The lost `VkDevice` stays while an object made on it lives, so the /// device holds two, and goes with the last of them, once a `Device::raw` call that answered its /// handles was followed by one that answered the new one's. diff --git a/docs/API.md b/docs/API.md index b68db7ac7..7b542b789 100644 --- a/docs/API.md +++ b/docs/API.md @@ -3281,13 +3281,16 @@ bound. (`GpuRecoveryVictim`), and every later call of the device and of its command queues goes to the new `VkDevice`; a queue's lent `VkQueue` (`CommandQueue::with_vk_queue`) comes with the `VkDevice` it belongs to, the new one from then on. Announced at each recovery, by the call that made it; the reason names the hang's - command buffer (an inference, said so, where two or more `VkQueue`s had work in flight) and how - long the recovery took. Announced too, at most once each per recovery whatever an earlier + command buffer (an inference, said so, where two or more `VkQueue`s had work in flight), how + long the recovery took, and the objects it carried to the new `VkDevice` and left refused, by + kind. Announced too, at most once each per recovery whatever an earlier 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 objects made - before the recovery 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. + 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, + `Private` buffers and buffers in fresh pages made before it go on, a `Private` buffer'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. - `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/scripts/refusal-surface/reach.tsv b/scripts/refusal-surface/reach.tsv index bda7707d2..0d1ae3204 100644 --- a/scripts/refusal-surface/reach.tsv +++ b/scripts/refusal-surface/reach.tsv @@ -242,7 +242,7 @@ feature SeqCstFence rare a seq_cst fence in a vertex or fragment stage without i gap MultisampledBufferCopy rare a buffer<->multisampled-texture copy on a device without sample-rate shading, an integer multisample attachment at the count, or the copy format's storage; and, where maintenance8's depth/colour copies are missing or wrong, what the sample-rate draws cannot move: a 16-bit depth on a driver whose codes the fragment-depth draw is not measured to keep, or a depth or stencil texture they cannot sample or render to (emulated elsewhere; the consumer's Maps pans and screensaver make the copy) gap MultisampledBufferLayout rare a buffer<->multisampled-texture copy at a bytesPerRow of 0 from an offset that is a multiple of 16, or of pixels of 32 bytes or more at a pitch below a row or off the pixel: Metal copies these by rules not yet reduced, and its API validation rejects them gap ColorAttachmentGroups app in a render pass of more color attachments than the device draws at once (five or more on a device of four), or one at an index past them: a pipeline state of other colors, a tile state, an execution of render commands, a draw reading another group's attachment -gap MadeBeforeRecovery app any object a program made before its device recovered from a lost VkDevice, used after the recovery +gap MadeBeforeRecovery app any object a program made before its device recovered from a lost VkDevice that the recovery does not carry (a pooled Shared or Managed buffer, a texture, a pipeline state), used after the recovery gap AdoptedDeviceRecovery none the recovery test hook on a device the consumer made itself feature WideLines none a line under the Apple-private setLineWidth: at a width other than 1 drawn as the band, whose pipeline form the translator does not build (a selected slice or viewport, barycentric weights, multiview, synthesized geometry, too many stage outputs) gap WideLines none under the Apple-private setLineWidth: at a width other than 1, a line strip drawn as the band whose list of segments the runtime cannot draw (past what a u32 counts or one storage range binds, or indices an unordered draw wrote)