diff --git a/crates/metal2vulkan-runtime/src/lib.rs b/crates/metal2vulkan-runtime/src/lib.rs index cdd299da4..d58b252d1 100644 --- a/crates/metal2vulkan-runtime/src/lib.rs +++ b/crates/metal2vulkan-runtime/src/lib.rs @@ -22,10 +22,6 @@ // Every public item says what it is and its Metal counterpart: a new undocumented one fails the // warnings-denied gates. #![warn(missing_docs)] -// Rustdoc works out each public type's `Send` and `Sync` through every type it holds: a device's -// open encoders' lowerings and checks (`render/deferral.rs`) down to the translator's reflection, -// past the default limit of 128 nested obligations. -#![recursion_limit = "256"] mod address; mod address_map; diff --git a/crates/metal2vulkan-runtime/src/render/deferral.rs b/crates/metal2vulkan-runtime/src/render/deferral.rs index 762b5179e..1d7430abd 100644 --- a/crates/metal2vulkan-runtime/src/render/deferral.rs +++ b/crates/metal2vulkan-runtime/src/render/deferral.rs @@ -178,6 +178,25 @@ pub(crate) struct LoweringSlot { handed_back: Condvar, } +// SAFETY: a slot is `Send` and `Sync` exactly when `SlotState` and `Lowerer` are `Send`: each is +// held only inside a `Mutex`, and `Mutex` is `Send` and `Sync` for every `T: Send`; the +// slot's other field, a `Condvar`, is both. The constant below makes the compiler prove those +// two, so these impls claim nothing it does not check. Written out, they end the compiler's +// walk of a slot's fields where a program's crate proves its own objects' `Send` and `Sync`: the +// walk from a `Device` or an encoder through a slot's lowering, down to the translator's +// reflection, ran past rustc's default recursion limit (`E0275`), which a program's crate keeps +// (`tests/consumer_auto_traits.rs`). +unsafe impl Send for LoweringSlot {} +// SAFETY: as for `Send` above. +unsafe impl Sync for LoweringSlot {} + +// The compiler's proof of what `LoweringSlot`'s `Send` and `Sync` impls rest on. +const _: () = { + const fn sent() {} + sent::(); + sent::(); +}; + /// A slot's lowering, and whether it refused a call. struct Lowerer { /// Its encoder's lowering: `None` once the encoder ended, and in a slot not taken. diff --git a/crates/metal2vulkan-runtime/tests/consumer_auto_traits.rs b/crates/metal2vulkan-runtime/tests/consumer_auto_traits.rs new file mode 100644 index 000000000..f25938220 --- /dev/null +++ b/crates/metal2vulkan-runtime/tests/consumer_auto_traits.rs @@ -0,0 +1,89 @@ +//! A program's crate holds the runtime's objects across threads at rustc's default recursion +//! limit: this test crate, like a program's, sets none. Each object is held as reims-vgpu holds +//! it: under its `Obj`'s bound (one counted reference), an encoder, +//! which Metal's program uses on one thread at a time, as a `Mutex>` under it. +//! rustc proves those bounds by walking each object's fields. A walk deeper than the limit fails +//! this crate's build (`E0275`), as it fails the program's: the walk from an encoder through its +//! device's render lowering slots down to the translator's reflection once did. +//! +//! rustc keeps each bound it proved for the rest of the crate, so an object checked after another +//! that reaches it would ride on the earlier, shallower proof, where a program that holds only +//! the later one walks it in full. Each object is therefore checked in a function of its own, +//! whose `where` clause names it: the environment differs, and rustc proves the object's bounds +//! afresh there. + +use std::sync::Mutex; + +use metal2vulkan_runtime::{ + ArgumentEncoder, BinaryArchive, BlitCommandEncoder, Buffer, CommandBuffer, CommandBufferError, + CommandQueue, ComputeCommandEncoder, ComputePipelineState, DegradeNotice, DepthStencilState, + Device, DynamicLibrary, Error, Event, Fence, Function, Heap, IndirectCommandBuffer, + IndirectComputeCommand, IndirectRenderCommand, Library, MessageSink, RasterizationRateMap, + RenderCommandEncoder, RenderPassDescriptor, RenderPipelineState, ResourceStateCommandEncoder, + SamplerState, SharedEvent, SharedEventHandle, SharedEventListener, SharedTextureHandle, + Texture, VisibleFunctionTable, WorkCounts, +}; + +/// `T` held as a program's crate holds it: the bound of reims-vgpu's `platform::Obj`, one +/// counted reference shared across threads. +fn held() {} + +/// Each object, in a function of its own (the module docs). +macro_rules! held { + ($($check:ident: $held:ty;)*) => { + $( + fn $check() + where + $held: Sized, + { + held::<$held>(); + } + )* + + #[test] + fn every_object_is_held_across_threads_at_the_default_recursion_limit() { + $( + $check(); + )* + } + }; +} + +held! { + render_encoder: Mutex>; + compute_encoder: Mutex>; + blit_encoder: Mutex>; + resource_state_encoder: Mutex>; + device: Device; + command_queue: CommandQueue; + command_buffer: CommandBuffer; + buffer: Buffer; + texture: Texture; + heap: Heap; + fence: Fence; + event: Event; + shared_event: SharedEvent; + shared_event_listener: SharedEventListener; + shared_event_handle: SharedEventHandle; + shared_texture_handle: SharedTextureHandle; + library: Library; + function: Function; + dynamic_library: DynamicLibrary; + binary_archive: BinaryArchive; + compute_pipeline_state: ComputePipelineState; + render_pipeline_state: RenderPipelineState; + depth_stencil_state: DepthStencilState; + sampler_state: SamplerState; + indirect_command_buffer: IndirectCommandBuffer; + indirect_render_command: IndirectRenderCommand; + indirect_compute_command: IndirectComputeCommand; + render_pass_descriptor: Mutex; + argument_encoder: ArgumentEncoder; + visible_function_table: VisibleFunctionTable; + rasterization_rate_map: RasterizationRateMap; + message_sink: MessageSink; + error: Error; + command_buffer_error: CommandBufferError; + degrade_notice: DegradeNotice; + work_counts: WorkCounts; +} diff --git a/crates/metal2vulkan-validation/runtime-sources.sha256 b/crates/metal2vulkan-validation/runtime-sources.sha256 index ec07ac082..59289f643 100644 --- a/crates/metal2vulkan-validation/runtime-sources.sha256 +++ b/crates/metal2vulkan-validation/runtime-sources.sha256 @@ -1 +1 @@ -f70309b45eb4810a3ad53c06f8385903315aea920f18f7a92ac1ce3df8ef882c +98be5a02d537ee4d861591c0ccf9bea610251efaa6fb5c5716731b1cfd984de6 diff --git a/docs/REFUSALS.md b/docs/REFUSALS.md index 10942e5f4..8860aa41c 100644 --- a/docs/REFUSALS.md +++ b/docs/REFUSALS.md @@ -14,7 +14,7 @@ Columns: - `none`: no public API path: malformed or non-Metal input, Apple-private calls, or a cap no valid program of ordinary size meets; - `?`: not assessed yet. -Generated at `a4c315e38`. +Generated at `fb41c3216`. ## Totals