diff --git a/crates/metal2vulkan-runtime/src/command_buffer/mod.rs b/crates/metal2vulkan-runtime/src/command_buffer/mod.rs index dd954d539..9cbc9c6b4 100644 --- a/crates/metal2vulkan-runtime/src/command_buffer/mod.rs +++ b/crates/metal2vulkan-runtime/src/command_buffer/mod.rs @@ -227,7 +227,7 @@ impl WeakCommandBuffer { pub(super) struct CommandBufferShared { device: Device, queue: CommandQueue, - state: StateLock, + state: Mutex, /// Signaled when the command buffer's status changes (`wait_until_scheduled` waits on it). changed: Condvar, /// What `wait_until_completed` waits for: the command buffer finished, and the runtime's @@ -661,35 +661,6 @@ fn probe_answers(work: &Deferred, rerecord: Option<&StepInputs>) -> [bool; 5] { ] } -/// A command buffer's [`State`] behind its lock (`CommandBufferShared::state`): a `Mutex` -/// whose `Send` and `Sync` are written out (below). -struct StateLock(Mutex); - -impl std::ops::Deref for StateLock { - type Target = Mutex; - - fn deref(&self) -> &Mutex { - &self.0 - } -} - -// SAFETY: a `StateLock` is a `Mutex`, which is `Send` and `Sync` for every `State: Send`; -// the constant below makes the compiler prove `State: Send` from its fields, so these impls claim -// nothing it does not check. Written out, they end the compiler's walk of a command buffer's -// fields at its state where a program's crate proves its own objects' `Send` and `Sync`: the walk -// from an encoder through its command buffer's state, down its recordings, runs past rustc's -// default recursion limit (`recursion_depth_exceeding_limit`), which a program's crate keeps -// (`tests/consumer_auto_traits.rs`). -unsafe impl Send for StateLock {} -// SAFETY: as for `Send` above. -unsafe impl Sync for StateLock {} - -// The compiler's proof of what `StateLock`'s `Send` and `Sync` impls rest on. -const _: () = { - const fn sent() {} - sent::(); -}; - /// A command buffer's mutable state. pub(super) struct State { status: CommandBufferStatus, @@ -2114,7 +2085,7 @@ impl CommandBuffer { CommandBuffer(Arc::new(CommandBufferShared { device: queue.device().clone(), queue: queue.clone(), - state: StateLock(Mutex::new(State { + state: Mutex::new(State { status: CommandBufferStatus::NotEnqueued, error: None, encoder_open: false, @@ -2212,7 +2183,7 @@ impl CommandBuffer { replaying_predication: None, predicated: false, trail_mark: 0, - })), + }), changed: Condvar::new(), gate: Arc::default(), relayed: Arc::default(), diff --git a/crates/metal2vulkan-runtime/src/deferred.rs b/crates/metal2vulkan-runtime/src/deferred.rs index 57efbc67b..e45af5cc0 100644 --- a/crates/metal2vulkan-runtime/src/deferred.rs +++ b/crates/metal2vulkan-runtime/src/deferred.rs @@ -54,6 +54,33 @@ pub(super) enum Deferred { Loop(Arc), } +// SAFETY: a `Deferred` holds one `Arc` of its variant's work, which is `Send` and `Sync` for every +// work that is both; the constant below makes the compiler prove that of each variant's work, its +// match naming every variant (one added fails it until its work is proved too), so these impls +// claim nothing it does not check. Written out, they end the compiler's walk of a segment's work +// where a program's crate proves its own objects' `Send` and `Sync`: the walk from an encoder's +// segments down the work's types runs past rustc's default recursion limit +// (`recursion_depth_exceeding_limit`), which a program's crate keeps +// (`tests/consumer_auto_traits.rs`). +unsafe impl Send for Deferred {} +// SAFETY: as for `Send` above. +unsafe impl Sync for Deferred {} + +// The compiler's proof of what `Deferred`'s `Send` and `Sync` impls rest on: each variant's work. +const _: fn(&Deferred) = |work| { + fn shared(_: &T) {} + match work { + Deferred::Execute(work) => shared(work), + Deferred::Dispatch(work) => shared(work), + Deferred::SparseScrub(work) => shared(work), + Deferred::GatedCopyIn(work) => shared(work), + Deferred::RunMerge(work) => shared(work), + Deferred::RenderPass(work) => shared(work), + Deferred::Pending(work) => shared(work), + Deferred::Loop(work) => shared(work), + } +}; + /// What `commit` left a segment for its host step. #[derive(Clone)] pub(super) enum StepInputs {