DeviceOptions::pipeline_records (and RawDevice::pipeline_records) hands a
hook an opaque PipelineRecord once per pipeline state creation that made its
state. That covers compute, render, mesh and tile states, the
additional-binary-functions forms, and a render state's draw-time twins (the
one-sample and factor-scaling ones). A failed creation and a binary
archive's add make none. A record holds the descriptor field by field
("M2VPREC\0", RECORD_FORMAT 1, the library table by content hash, SHA-256),
read back and compared at its making. Its libraries are kept once in the
shader cache's content directory. to_bytes and from_bytes carry it between
processes.
Device::warm(records, byte_budget) stands in for Metal's own pipeline caches
across processes:
- One background thread per device (utility QoS on macOS, Urgency::Warm in
the making budget) runs each record's creation under the default options
and drops the state. Translations, creation records and driver
pipeline-cache data are then in place before the program asks.
- The guest sees nothing of it: no identifier, resource ID, sampler number,
neutral, room, stand-in copy, kept-variant traffic, live-variant sharing,
announcement or record.
- It stops at byte_budget of added driver data.
- An unread record is counted, and the device's first is announced as the
warning metal2vulkan-warm-record-unread; nothing fails.
- WarmStatistics and Device::warm_statistics report the pass.
Ports dev-perf 14df1fb5fe and 66fe0ada29 without per-entry stamps.
Development's build directory names the translator, and its creation records
name RUNTIME_VERSION, so no entry of another translator or runtime version
is ever found, and dev-perf's re-translate-and-compare check has nothing to
do. Adapted:
- the memo is asked but never hands a warm thread a live variant the
program holds;
- a warm thread's waits rank Urgency::Warm, not Program (making.rs), and the
pipewait creation bound still applies on warm threads;
- unread records are announced.
DeviceOptions' and RawDevice's Debug are hand-written. PipelineRecord is
among the consumer auto-trait checks. api_signatures re-blessed; runtime
README and HOWTO updated. RUNTIME_VERSION 1707.
Verified on the M3 Max (MoltenVK 1.4.2), on development 2e2e238346:
- 140 device tests and 500 plain tests pass.
- Five sabotages each fail their guard: an archive add making a record; a
pass answering Warmed without creating; no unread announcement; a warm
state taking an identifier; a warm thread taking a live variant.
- clippy plain and --cfg m2v_gpu, and rustdoc -D warnings, clean.
- Release, 5 runs of the cross-process test, three creations (render,
compute, indirect compute):
- after a warm pass: 3.11-3.42 ms, with 0 stages decoded, 0 translated, 0
directory lookups and 0 driver caches loaded;
- unwarmed over the same directory: 4.19-4.32 ms (6 lookups, 2 loads);
- cold: 4.98-5.10 ms.
Small shaders, and Metal's own cross-process compiler cache serves all
three legs.
Lane commits: ws/warmrec-lane (8d106f29ab hook, 30de4fc948 warm).
One work packet, landed as 2 commits on archive/development-linear-2026-10-29: 8c709f27a7, then e2f0f2a3d9 (the re-pin).
91 lines
3.7 KiB
Rust
91 lines
3.7 KiB
Rust
//! 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<T: Send + Sync + 'static>`'s bound (one counted reference), an encoder,
|
|
//! which Metal's program uses on one thread at a time, as a `Mutex<Option<_>>` 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, PipelineRecord,
|
|
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<T>`, one
|
|
/// counted reference shared across threads.
|
|
fn held<T: Send + Sync + 'static>() {}
|
|
|
|
/// 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<Option<RenderCommandEncoder>>;
|
|
compute_encoder: Mutex<Option<ComputeCommandEncoder>>;
|
|
blit_encoder: Mutex<Option<BlitCommandEncoder>>;
|
|
resource_state_encoder: Mutex<Option<ResourceStateCommandEncoder>>;
|
|
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<RenderPassDescriptor>;
|
|
argument_encoder: ArgumentEncoder;
|
|
visible_function_table: VisibleFunctionTable;
|
|
rasterization_rate_map: RasterizationRateMap;
|
|
pipeline_record: PipelineRecord;
|
|
message_sink: MessageSink;
|
|
error: Error;
|
|
command_buffer_error: CommandBufferError;
|
|
degrade_notice: DegradeNotice;
|
|
work_counts: WorkCounts;
|
|
}
|