diff --git a/crates/metal2vulkan-runtime/src/batch_order.rs b/crates/metal2vulkan-runtime/src/batch_order.rs index 1fef73096..0ffd75507 100644 --- a/crates/metal2vulkan-runtime/src/batch_order.rs +++ b/crates/metal2vulkan-runtime/src/batch_order.rs @@ -26,15 +26,20 @@ //! On those drivers ([`ends_order`]) the default form orders batches by their ends: every batch //! ends with [`Barrier::to_all`], every write before every access of every later command of its //! `VkQueue`, so the tracker plans no barrier after an access of an earlier batch there -//! ([`Tracker::by_ends`](crate::tracker::Tracker)), and a batch's start timestamp is written at the -//! bottom of the pipe ([`start_stage`]): once everything before it in submission order completed, -//! which is when such a driver starts it. A batch no longer needs a command buffer of barriers +//! ([`Tracker::by_ends`](crate::tracker::Tracker)). A batch's start timestamp, written at the top +//! of the pipe as on every driver (`gpu_time.rs`), is then written once everything before it in +//! submission order completed, which is when such a driver starts it: the earlier batch's +//! [`Barrier::to_all`] holds it, as "the second synchronization scope includes all commands that +//! occur later in submission order" (`vkCmdPipelineBarrier`), its destination stages all commands. +//! A start written at the bottom of the pipe there read late on RADV (Mesa 26.2.6) on an RX 7900 +//! XTX and a Radeon 780M: in a traced compute benchmark's pass, a population of command buffers +//! read their start in the last tenth of their own kernel job, spans of 1 us on jobs of 4.5 to +//! 36.5 ms. A batch no longer needs a command buffer of barriers //! for a dependency on the batch before it (on the UHD 770, with the consumer's frames over 520 //! host imports, 67.0 command buffers submitted a frame against 129.3 to 129.7), and runs as the //! driver ran it before. Elsewhere, and under `BatchOrderPolicy::Exact`, the exact form. use crate::tracker::Barrier; -use ash::vk; use metal2vulkan::device::{BatchOrderPolicy, DevicePolicy}; use metal2vulkan::vk::DriverId; @@ -61,13 +66,3 @@ pub(crate) fn end(by_ends: bool) -> Barrier { false => Barrier::to_host(), } } - -/// The stage a batch's start timestamp is written at where nothing is planned before it: the -/// top of the pipe, as its work begins, or, where batches are ordered `by_ends`, the bottom, -/// once everything before it completed. -pub(crate) fn start_stage(by_ends: bool) -> vk::PipelineStageFlags { - match by_ends { - true => vk::PipelineStageFlags::BOTTOM_OF_PIPE, - false => vk::PipelineStageFlags::TOP_OF_PIPE, - } -} diff --git a/crates/metal2vulkan-runtime/src/command_buffer/kept_barriers.rs b/crates/metal2vulkan-runtime/src/command_buffer/kept_barriers.rs index e2a16b634..58c8792e3 100644 --- a/crates/metal2vulkan-runtime/src/command_buffer/kept_barriers.rs +++ b/crates/metal2vulkan-runtime/src/command_buffer/kept_barriers.rs @@ -88,8 +88,9 @@ pub(crate) struct KeptBarriers { /// The timestamps a barrier command buffer writes into a timed command buffer's slot of the /// device's timestamp pools (`gpu_time::Slot`): with `start`, the slot reset before its barriers -/// and the start timestamp before them at the top of the pipe (the bottom where batches are -/// ordered by their ends: `batch_order.rs`), or with `after` after them at the bottom of the pipe; +/// and the start timestamp before them at the top of the pipe (`batch_order.rs`: where batches +/// are ordered by their ends, the earlier batch's end barrier holds it), or with `after` after them +/// at the bottom of the pipe; /// with `end`, the end timestamp after them. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub(crate) struct SlotStamps { @@ -396,8 +397,8 @@ impl KeptBarriers { exit_guard::called(Call::CmdResetQueryPool); } if !stamps.after { - let stage = crate::batch_order::start_stage(shared.by_ends); - raw.cmd_write_timestamp(buffer, stage, stamps.queries, stamps.first); + let top = vk::PipelineStageFlags::TOP_OF_PIPE; + raw.cmd_write_timestamp(buffer, top, stamps.queries, stamps.first); exit_guard::called(Call::CmdWriteTimestamp); } } diff --git a/crates/metal2vulkan-runtime/src/command_buffer/mod.rs b/crates/metal2vulkan-runtime/src/command_buffer/mod.rs index 485b79dd7..dba445ba4 100644 --- a/crates/metal2vulkan-runtime/src/command_buffer/mod.rs +++ b/crates/metal2vulkan-runtime/src/command_buffer/mod.rs @@ -6248,9 +6248,8 @@ impl CommandBufferShared { /// first `VkCommandBuffer` of the command buffer's first encoder, which opens its first batch: /// take the slot now, and write the start into its third query as `raw`'s first commands, the /// reset of the end and of that query (where the device does not reset the slot on the host as - /// it takes it), then the timestamp at the top of the pipe (the bottom where batches are - /// ordered by their ends: `batch_order.rs`; `gpu_time.rs`). The first batch's submission - /// decides which start is read (`submit.rs`). + /// it takes it), then the timestamp at the top of the pipe (`batch_order.rs`; `gpu_time.rs`). + /// The first batch's submission decides which start is read (`submit.rs`). fn open_start(&self, state: &mut State, raw: vk::CommandBuffer) { let timing = &self.device.shared().timing; let first_batch = match state.batches.all() { @@ -6282,8 +6281,8 @@ impl CommandBufferShared { device.cmd_reset_query_pool(raw, queries, prefix - 1, 2); exit_guard::called(Call::CmdResetQueryPool); } - let stage = crate::batch_order::start_stage(self.device.shared().by_ends); - device.cmd_write_timestamp(raw, stage, queries, prefix); + let top = vk::PipelineStageFlags::TOP_OF_PIPE; + device.cmd_write_timestamp(raw, top, queries, prefix); exit_guard::called(Call::CmdWriteTimestamp); } state.prefix = Some(raw); diff --git a/crates/metal2vulkan-runtime/src/command_buffer/submit.rs b/crates/metal2vulkan-runtime/src/command_buffer/submit.rs index 994c0640c..3e7c2ffde 100644 --- a/crates/metal2vulkan-runtime/src/command_buffer/submit.rs +++ b/crates/metal2vulkan-runtime/src/command_buffer/submit.rs @@ -159,7 +159,16 @@ //! ([`fences`](super::fences)), at which the command buffer then finishes. //! //! **GPU times** (`gpu_time.rs`). In a timed command buffer, the start timestamp is written at the -//! top of the pipe, before every barrier and encoder of its first batch: by its first encoder's +//! top of the pipe, before every barrier and encoder of its first batch. Where that batch has first +//! work (**New resources' first work**, above: zeros, moves, `Managed` copies in), the work's own +//! command buffer writes it first, after an execution barrier from every command before ("the +//! first synchronization scope includes all commands that occur earlier in submission order ... +//! the second synchronization scope includes all commands that occur later in submission order", +//! `vkCmdPipelineBarrier`), so the start follows every earlier command of the queue and precedes +//! the work, whose GPU time is the command buffer's: on an RX 7900 XTX, a command buffer's copies +//! in of the ranges `did_modify_range` named ran 4.5 to 36.5 ms before a start written after them. +//! (Whether Metal's span holds a `Managed` copy in on a Mac with a discrete GPU is not measured.) +//! Elsewhere it is written by its first encoder's //! first command buffer, which wrote it into its slot's third query as it opened, where the batch //! plans nothing before that encoder (no barrier, no image moved, and no //! [`Barrier::after_completed`] where the driver stalls on semaphore operations) and the command @@ -175,8 +184,10 @@ //! starts after that work ended, as Metal's does: on an M3 Max under macOS 27.0.1, a fill committed //! behind a running fill of the same bytes started 0.5 to 0.9 us after the first's `GPUEndTime` (10 //! of 10), and one of other bytes while the first ran (probe `gpustart`). Where batches are ordered -//! by their ends (`batch_order.rs`), every start is written at the bottom of the pipe, as such a -//! driver starts no batch before the ones before it ended. The end of its last batch writes the end +//! by their ends (`batch_order.rs`), the end barrier of the batch before ([`Barrier::to_all`], all +//! commands to all commands) holds every start, at the top of the pipe, until the batches before it +//! ended, as such a driver starts no batch before them; one written at the bottom of the pipe there +//! read late on RADV. The end of its last batch writes the end //! timestamp at the bottom of the pipe, after its barriers. The scheduler's host times as it begins //! the first batch and ends the last submission are the kernel times. //! @@ -889,6 +900,14 @@ impl CommandBufferShared { // module docs). let by_barrier = shared.completed_by_barrier; let mut completed_barrier = by_barrier.then(Barrier::after_completed); + // A first batch with first work (new resources' first moves and fills, copies in) writes + // the start in that work's command buffer, before the work, which runs in the batch's + // submission before its commands: the command buffer's GPU work begins there + // (**GPU times**, the module docs). + let first_start = start_stamp.filter(|_| first_work.has_first() || first_work.has_staged()); + if first_start.is_some() { + start_stamp = None; + } // The first encoder's prefix wrote the start where the batch plans nothing before that // encoder (no barrier, no image moved, no barrier for completed work) and its first // command buffer goes to the queue as recorded (`gpu_time.rs`): then no command buffer of @@ -983,6 +1002,12 @@ impl CommandBufferShared { let recorded = (has_first || has_staged) .then(|| { self.record_raw(&mut state, |_, buffer| { + if let Some((queries, first, _)) = first_start { + // SAFETY: the command buffer is recording, outside a render pass, and is + // submitted first in the batch; the slot is the command buffer's, which + // only its batches write. + unsafe { record_first_start(shared, buffer, queries, first) }; + } if has_first { // SAFETY: the command buffer is recording, outside a render pass; it is // submitted first in the batch, before any later one, and every batch on @@ -2240,8 +2265,8 @@ impl CommandBufferShared { exit_guard::called(Call::CmdResetQueryPool); } if !stamps.after { - let stage = crate::batch_order::start_stage(device.shared().by_ends); - raw.cmd_write_timestamp(buffer, stage, queries, first); + let top = vk::PipelineStageFlags::TOP_OF_PIPE; + raw.cmd_write_timestamp(buffer, top, queries, first); exit_guard::called(Call::CmdWriteTimestamp); } } @@ -2295,6 +2320,45 @@ fn bind_error(device: &crate::Device, failure: BindFailure) -> CommandBufferErro } } +/// Record a first batch's start into `buffer`, the command buffer of its first work, before that +/// work: the reset of the slot's start and end where the device does not reset it on the host as +/// it is taken, an execution barrier from every command before to every command after, then the +/// start into query `first` of `queries` at the top of the pipe (**GPU times**, the module docs). +/// +/// # Safety +/// +/// `buffer` is recording, outside a render pass, and is submitted first in its batch; the slot is +/// the command buffer's, which no other command buffer writes meanwhile. +unsafe fn record_first_start( + shared: &crate::device::DeviceShared, + buffer: vk::CommandBuffer, + queries: vk::QueryPool, + first: u32, +) { + let raw = shared.vk(); + let all = vk::PipelineStageFlags::ALL_COMMANDS; + // SAFETY: the caller's contract. + unsafe { + if !shared.timing.resets_on_host() { + raw.cmd_reset_query_pool(buffer, queries, first, 2); + exit_guard::called(Call::CmdResetQueryPool); + } + raw.cmd_pipeline_barrier( + buffer, + all, + all, + vk::DependencyFlags::empty(), + &[], + &[], + &[], + ); + exit_guard::called(Call::CmdPipelineBarrier); + let top = vk::PipelineStageFlags::TOP_OF_PIPE; + raw.cmd_write_timestamp(buffer, top, queries, first); + exit_guard::called(Call::CmdWriteTimestamp); + } +} + /// The timestamps a barrier command buffer writes into its command buffer's slot of the device's /// timestamp pools, each the slot's pool, its first query and the holding's lease /// (`gpu_time::Slot::lease`): the start (after resetting the slot) before its barriers at the top diff --git a/crates/metal2vulkan-runtime/src/device/mod.rs b/crates/metal2vulkan-runtime/src/device/mod.rs index bf3a289d6..77c367aa4 100644 --- a/crates/metal2vulkan-runtime/src/device/mod.rs +++ b/crates/metal2vulkan-runtime/src/device/mod.rs @@ -380,8 +380,8 @@ pub(super) struct DeviceShared { /// `command_buffer/submit.rs`). pub(super) completed_by_barrier: bool, /// Each batch ends with `Barrier::to_all`, so a later batch of its `VkQueue` plans no barrier - /// for its accesses, and a batch's start timestamp is written at the bottom of the pipe - /// (`batch_order.rs`). + /// for its accesses, and holds a later batch's start timestamp, at the top of the pipe, until + /// it ended (`batch_order.rs`). pub(crate) by_ends: bool, /// The last sparse binding of a no-copy buffer's dma-bufs (`dma_buf.rs`) the host has not /// seen complete: the internal timeline and the value it signals, which every later diff --git a/crates/metal2vulkan-runtime/src/gpu_time.rs b/crates/metal2vulkan-runtime/src/gpu_time.rs index 49fadaf3e..cecb0c7ee 100644 --- a/crates/metal2vulkan-runtime/src/gpu_time.rs +++ b/crates/metal2vulkan-runtime/src/gpu_time.rs @@ -22,8 +22,13 @@ //! the batch begins with no command buffer of its own, and the prefix's start is the command //! buffer's. It is the same place: either start is written at the top of the pipe, after every //! command submitted before the batch's work and before any of it; where batches are ordered by -//! their ends (`batch_order.rs`), at the bottom, once every command submitted before it -//! completed, when such a driver starts the batch. Elsewhere (a barrier planned +//! their ends (`batch_order.rs`), once every command submitted before it completed, which the +//! earlier batch's end barrier to all later commands holds, when such a driver starts the +//! batch. A first batch with first work (new resources' first moves and fills, `Managed` +//! copies in: `texture/first_move.rs`) writes the start in that work's command buffer instead, +//! after a barrier from every command before and before the work, which runs in the batch's +//! submission ahead of its commands, so its GPU time is the command buffer's +//! (`command_buffer/submit.rs`). Elsewhere (a barrier planned //! there, a caller's image moved first, the encoder run again or not at all) a command buffer of //! barriers writes the first start before the barrier, as without a prefix, and that start is //! read; the prefix's is written after it and never read. A Metal counter sample buffer's slot diff --git a/crates/metal2vulkan-runtime/src/tests/mod.rs b/crates/metal2vulkan-runtime/src/tests/mod.rs index 20625bdb3..d81a410da 100644 --- a/crates/metal2vulkan-runtime/src/tests/mod.rs +++ b/crates/metal2vulkan-runtime/src/tests/mod.rs @@ -829,6 +829,8 @@ mod staging_waits; mod stall; mod stand_in; #[cfg(any(m2v_gpu, m2v_cpu_icd))] +mod start_stamp; +#[cfg(any(m2v_gpu, m2v_cpu_icd))] mod stencil_target; #[cfg(any(m2v_gpu, m2v_cpu_icd))] mod storage_creation_times; diff --git a/crates/metal2vulkan-runtime/src/tests/start_stamp.rs b/crates/metal2vulkan-runtime/src/tests/start_stamp.rs new file mode 100644 index 000000000..09c1eac60 --- /dev/null +++ b/crates/metal2vulkan-runtime/src/tests/start_stamp.rs @@ -0,0 +1,215 @@ +//! A command buffer's GPU start (`gpu_time.rs`) against the GPU work its submission carries. +//! +//! - **Its own long work.** A compute encoder of [`DISPATCHES`] dispatches over [`FLOATS`] floats, +//! its pipeline made and its buffers' first work done by a command buffer before it, committed +//! once that one completed: its GPU start lies in the first half of its life from its kernel end +//! time to its GPU end, as the GPU starts the work once the submission reaches it, not at its +//! end. +//! - **The batch's first work.** The next command buffer after a new `Private` buffer of +//! [`FIRST`] bytes (its fill with zeros, `texture/first_move.rs`) and, on a device without +//! unified memory, a `Managed` buffer of [`FIRST`] bytes whose whole range `did_modify_range` +//! named (its copy in, `managed_copy.rs`), the command buffer one blit fill of a word of the +//! `Managed` buffer (else of a buffer made before): its GPU span holds at least half the time +//! that work adds to its life against the same fill without it, as the work runs in its own +//! submission, before its commands. Where the device's fill queue took the work +//! (`device/staging.rs`: it runs before the batch, outside it), the leg says so and checks +//! nothing. +//! +//! Each leg prints its times (`START-STAMP`). Device tests: compiled only under the GPU safety +//! cfgs (`m2v_gpu`, `m2v_cpu_icd`), on the kind of device the cfg selects. + +use super::blit_holds::{device, Scratch, WAIT}; +use super::encoder_holds::library; +use crate::{ + Buffer, CommandBuffer, CommandBufferStatus, CommandQueue, ComputePipelineState, CpuCacheMode, + HazardTrackingMode, PipelineOptions, ResourceOptions, Size, StorageMode, +}; + +/// The floats each long dispatch scales. +const FLOATS: u64 = 1 << 24; + +/// The long encoder's dispatches; a CPU device runs fewer. +const DISPATCHES: usize = match cfg!(m2v_cpu_icd) { + true => 4, + false => 64, +}; + +/// The bytes of each buffer of the first work. +const FIRST: u64 = match cfg!(m2v_cpu_icd) { + true => 64 << 20, + false => 256 << 20, +}; + +/// The kernel, and the fixture it is in. +const FIXTURE: &str = "examples/runtime_examples.ll"; +const KERNEL: &str = "scale_and_offset"; + +/// A completed command buffer's kernel end time and GPU times, in seconds of the host's clock. +#[derive(Clone, Copy, Debug)] +struct Times { + kernel_end: f64, + start: f64, + end: f64, +} + +impl Times { + /// From its kernel end time to its GPU end. + fn life(self) -> f64 { + self.end - self.kernel_end + } + + /// From its GPU start to its GPU end. + fn span(self) -> f64 { + self.end - self.start + } + + /// From its kernel end time to its GPU start. + fn lead(self) -> f64 { + self.start - self.kernel_end + } + + fn line(self) -> String { + format!( + "life {:.3} ms, kernel end to GPU start {:.3} ms, GPU span {:.3} ms", + self.life() * 1e3, + self.lead() * 1e3, + self.span() * 1e3 + ) + } +} + +/// Commit `command_buffer`, hold that it completed, and read its times. +fn run(command_buffer: &CommandBuffer) -> Times { + command_buffer.commit().unwrap(); + command_buffer.wait_until_completed_for(WAIT).unwrap(); + assert_eq!(command_buffer.status(), CommandBufferStatus::Completed); + Times { + kernel_end: command_buffer.kernel_end_time(), + start: command_buffer.gpu_start_time().unwrap(), + end: command_buffer.gpu_end_time().unwrap(), + } +} + +/// A command buffer of `queue`'s of one compute encoder that scales [`FLOATS`] floats of `input` +/// into `output` with `state`, `times` over. +fn scale( + queue: &CommandQueue, + state: &ComputePipelineState, + (input, output): (&Buffer, &Buffer), + times: usize, +) -> CommandBuffer { + let command_buffer = queue.command_buffer().unwrap(); + let mut encoder = command_buffer.compute_command_encoder().unwrap(); + encoder.set_compute_pipeline_state(state).unwrap(); + encoder.set_buffer(Some(input), 0, 0).unwrap(); + encoder.set_buffer(Some(output), 0, 1).unwrap(); + encoder.set_bytes(&1.0f32.to_le_bytes(), 2).unwrap(); + for _ in 0..times { + (encoder.dispatch_threads(Size::new(FLOATS, 1, 1), Size::new(256, 1, 1))).unwrap(); + } + encoder.end_encoding().unwrap(); + command_buffer +} + +/// A command buffer of `queue`'s of one blit fill of `target`'s first word. +fn fill(queue: &CommandQueue, target: &Buffer) -> CommandBuffer { + let command_buffer = queue.command_buffer().unwrap(); + let mut blit = command_buffer.blit_command_encoder().unwrap(); + blit.fill_buffer(target, 0..4, 7).unwrap(); + blit.end_encoding().unwrap(); + command_buffer +} + +#[test] +fn a_command_buffer_s_gpu_start_comes_before_its_own_long_work() { + let scratch = Scratch::new("start-stamp-long"); + let device = device(&scratch.0); + let queue = device.new_command_queue().unwrap(); + let function = library(&device, FIXTURE) + .new_function_with_name(KERNEL) + .unwrap(); + let state = (device + .new_compute_pipeline_state_with_function(&function, &PipelineOptions::default())) + .unwrap(); + let bytes = FLOATS * 4; + let input = device + .new_buffer(bytes, ResourceOptions::private()) + .unwrap(); + let output = device + .new_buffer(bytes, ResourceOptions::private()) + .unwrap(); + // Its pipeline made, its buffers' first work done. + run(&scale(&queue, &state, (&input, &output), 1)); + let long = run(&scale(&queue, &state, (&input, &output), DISPATCHES)); + eprintln!( + "START-STAMP long {}: {DISPATCHES} dispatches: {}", + device.name(), + long.line() + ); + assert!( + long.lead() <= long.life() / 2.0, + "the GPU start lies in the second half of the command buffer's life: {}", + long.line() + ); +} + +#[test] +fn a_command_buffer_s_gpu_span_holds_its_batch_s_first_work() { + let scratch = Scratch::new("start-stamp-first"); + let device = device(&scratch.0); + let queue = device.new_command_queue().unwrap(); + let two_copies = !device.properties().has_unified_memory; + let small = device.new_buffer(4096, ResourceOptions::private()).unwrap(); + // Its first work done, then the fill alone. + run(&fill(&queue, &small)); + let alone = run(&fill(&queue, &small)); + let before = device.work_counts(); + let fresh = device + .new_buffer(FIRST, ResourceOptions::private()) + .unwrap(); + let managed = two_copies.then(|| { + let options = ResourceOptions::new( + StorageMode::Managed, + CpuCacheMode::DefaultCache, + HazardTrackingMode::Default, + ); + let buffer = device.new_buffer(FIRST, options).unwrap(); + let contents = buffer.contents().expect("a Managed buffer's host copy"); + // SAFETY: the buffer's host copy of `FIRST` bytes, which no command buffer uses yet. + unsafe { std::ptr::write_bytes(contents.as_ptr(), 0x5a, FIRST as usize) }; + buffer.did_modify_range(0..FIRST).unwrap(); + buffer + }); + let with = run(&fill(&queue, managed.as_ref().unwrap_or(&small))); + let after = device.work_counts(); + let copied_in = after.managed_bytes_copied_in - before.managed_bytes_copied_in; + let zero_fills = after.new_buffer_zero_fills - before.new_buffer_zero_fills; + let on_fill_queue = after.fill_queue_submissions - before.fill_queue_submissions; + let added = with.life() - alone.life(); + eprintln!( + "START-STAMP first work {}: {zero_fills} zero fills, {copied_in} bytes copied in, \ + {on_fill_queue} fill-queue submissions; alone: {}; with it: {}; it adds {:.3} ms", + device.name(), + alone.line(), + with.line(), + added * 1e3 + ); + drop(fresh); + if on_fill_queue > 0 { + eprintln!("START-STAMP first work: the fill queue took it, before the batch: no check"); + return; + } + assert!(zero_fills > 0, "the new buffer took no fill with zeros"); + if two_copies { + assert!( + copied_in >= FIRST, + "{copied_in} bytes copied in, of {FIRST}" + ); + } + assert!( + with.span() >= added / 2.0, + "the GPU span leaves out the batch's first work: {:.3} ms added, span {:.3} ms", + added * 1e3, + with.span() * 1e3 + ); +} diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index 7d657f3d9..d9ddaca3a 100644 --- a/crates/metal2vulkan/src/cache/mod.rs +++ b/crates/metal2vulkan/src/cache/mod.rs @@ -94,7 +94,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 524; /// changes no behaviour, and then updates that hash alone with the commit saying why, or changes /// behaviour and also bumps this version. The commit that bumps it says what changed; this comment /// keeps no history. -pub const RUNTIME_VERSION: u32 = 2465; +pub const RUNTIME_VERSION: u32 = 2466; /// The digest of the sources this build of the crate was compiled from: SHA-256, as lowercase hex, /// of the manifest, the build script, and exactly the files the crate roots' module tree compiles diff --git a/docs/FAST-PATHS.md b/docs/FAST-PATHS.md index f4f672c50..858998ce7 100644 --- a/docs/FAST-PATHS.md +++ b/docs/FAST-PATHS.md @@ -36,7 +36,7 @@ three consumer pipelines: A2X (`a2x-s4`, `a2x-s96`), Xgc14 (`xgc14-bgra8`) and X | A heap's colour texture that Metal keeps losslessly compressed (`allowGPUOptimizedContents`, no `ShaderWrite`, `PixelFormatView` or `ShaderAtomic` usage, 16 texels or more a side), on a driver whose compressed images may keep their texels apart from the memory they are bound to (`DriverFact::CompressedImagesHideAliasedWrites`: ANV), is the driver's compressed optimal image, its compression and fast clears kept. A texture Metal keeps uncompressed takes the uncompressed image under either value. The runtime's choice: no pipeline differs. | `heap_compression = HeapCompressionPolicy::Compressed` | `heap_compression = HeapCompressionPolicy::Uncompressed`: an image the driver keeps uncompressed in the heap's bytes, as for a texture Metal keeps uncompressed: host-transfer usage where the device enabled `hostImageCopy` (`heap-texture-host-transfer`), else a linear image (`heap-texture-linear`), else the optimal one (`heap-texture-hides-aliased-writes`) | A write through a buffer or another texture over the texture's bytes may leave its texels as they were or change them otherwise than as written, where Metal's texture reads opaque magenta (`0xffff00ff`) in every texel of drawn content the write covers and the written bytes where it held only a clear; the texture's own writes may show in those bytes compressed. Within Metal's contract: Metal documents such a texture's layout as its own (`allowGPUOptimizedContents` lets it "adjust the private layout"), so no write through another view over its bytes has a defined result there either. `HeapTextureCompressed` (`heap-texture-compressed`), announced once per device where such a texture is made; `runtime_lane::heap_textures` | ANV (Iris Xe of RPL-P; `heap_textures::heap_compression_costs`), a 2048x2048 `RGBA8Unorm` render target in a `Private` placement heap: a pass that clears it 26.9 us against 676.2-676.5 us; a copy into another such texture 647.7-649.1 us against 673.9-693.2 us. The compressed image lies in the heap only where the heap's answer holds it (`heap_answers = HeapAnswerPolicy::Device`, the next row). This 2048x2048 texture's does not under either answer policy, so it takes the linear image under either compression value: a clear 963.5 us against 958.4 us under `heap_answers = HeapAnswerPolicy::Metal`, 955.3 us against 971.4 us under the default, the copy 488-496 us | | A heap texture whose image of the route the device takes for it needs more bytes or a coarser alignment of the heap than Metal's answer (each of a guest compositor's 22 heap shapes, `RGBA16Float` 2D arrays of one slice and 2D textures to 456x255: on ANV, whose compressed images align to 64 KiB; on the RTX 3090 at 1024; on the RX 7900 XTX at 256 to 64 KiB, where Metal answers 128 for each but the 299x299 array's 16 KiB): the size query (`heapTextureSizeAndAlign`) answers the larger of Metal's answer and that image's, and the texture lies in that image in the heap's bytes. A `Shared` texture's answer also holds the linear image a heap over host pages binds for it. Its alignment is the device's up to a heap's memory's own, 256 KiB, past which no image binds there (on the RX 7900 XTX, 128 KiB for a depth image and 256 KiB for a 4-sample render target past 128 texels a side). Where that image's alignment is past 256 KiB, or past both 4 KiB and the texture's size, the texture's image that a 4 KiB alignment holds takes its place (host-transfer usage, else linear), the answer that one's; else Metal's answer, as under the switch. A multisample texture takes it too and lies in its image in the heap's bytes, in the driver's layout of its samples, where under the switch it is a shadow of its samples in Metal's tiles (`heap_placed_targets`: a frame's 4-sample `RGBA16Float` and `Depth32Float` targets placed in a tracked `Private` heap). Metal's measured answers (4:2:2, one-plane YCbCr, two-plane extended-range, `X32_Stencil8`, `BlockWritesOnly` textures) and textures whose image lies in memory of its own keep Metal's answer. The runtime's choice: no pipeline differs. | `heap_answers = HeapAnswerPolicy::Device` | `heap_answers = HeapAnswerPolicy::Metal`: Metal's answer; the texture lies in an image that fits it (host-transfer usage, else linear: `heap-texture-host-transfer`, `heap-texture-linear`), else is a shadow of the heap's bytes in Metal's tiles, copied in before and out after the commands that use it (`shadowed-texture`) | A heap holds fewer such textures than Metal's: of the 22 shapes, the small arrays answer 4096 bytes where Metal answers 128 to 2176 (on ANV and the XTX; the XTX's 1x1 answers 256), and the 22 answers take 3769962 bytes of heaps placed one after another on ANV and 4155498 on the XTX, against Metal's 3656426 (`heap_texture_images`, `HEAP-COUNT`). A program that places a heap's resources by sizes of its own rather than the query's may overlap the texture with its neighbour; Metal's answer differs by GPU too (65536 on an AMD Radeon Pro 5300M, 4096 on an Intel UHD 630, 128 on an M3). `HeapTextureLargerThanMetal` (`heap-texture-larger-than-metal`), announced once per device; `tests::heap`, `tests::heap_placed_targets`, `heap_shadow_costs::heap_texture_images` | Of the 22 shapes made in heaps under the switch (`heap_texture_images`), on ANV (Iris Xe of RPL-P) 14 lie in an image put in place of their first one and 7 are shadows in Metal's tiles; on the RX 7900 XTX (RADV) 1 and 8, every other answer Metal's; under the default none on either. ANV (`heap_shadow_costs::heap_texture_shadow_costs`), a 1x1 `RGBA16Float` array held as a shadow: a frame that clears it and blits it 34.7 us in the heap against 8.2 us outside | | Batches of command buffers committed on one queue that the scheduler finds ready together (a backlog) go to the driver in one `vkQueueSubmit`, at most four and at most 16 ms of their queues' expected GPU runs summed (`GROUP_RUN`, `command_buffer/group.rs`: a kernel job that a timeout ends as a whole, as Linux's amdgpu ends one past 2 s by default, never carries more of the others' expected work than that), only the last signalling the queue's timeline, on a device whose own check finds a submission that signals nothing merged into the next (`submit_check.rs`, once per driver, release and kernel: one `vkQueueSubmit` of four empty infos against four calls of one, merged where the one costs at most 0.6 of the four; Mesa 26.2.6's RADV on the Radeon 780M, the RX 7900 XTX and the RX 550 at 0.33-0.38, ANV on the Iris Xe of RPL-P at 0.39, MoltenVK 1.4.2 on the M3 Max at 0.98; a device whose check has not answered, or that does not merge, takes the ungrouped form under either value of the switch): one kernel submission, where ANV on i915 lists every `VkDeviceMemory` in each (the consumer's guest drag on the Iris Xe: about 300 entries per execbuffer, 260 of them its host imports, at 112 to 128 execbuffers a frame). A batch's event signals ride to the group's end, which signals each event's semaphore to the highest index the batches held signal it to (an event's indices rise in commit order). A batch that signals a binary semaphore, takes a fence, binds a sparse update, does first work, names the caller's wrapped image, or waits for anything not seen complete (an event, another queue's work) goes alone, after the batches held: a batch with a wait leads a group, never joins one. Nor does an unshared queue's batch (`Device::new_command_queue_unshared`) on a `VkQueue` whose other queues' work is held back for it (`UnsharedIsolationPolicy::Bounded`, the default), and no group is kept there while earlier work runs (below): on RADV, ANV and lavapipe, whose one graphics `VkQueue` every command queue shares, a live unshared queue so keeps no group of any queue. Each batch on a `VkQueue` whose batches group that goes in a kernel submission of its own counts once by why (`WorkCounts::batches_alone_unshared` and kin), and `WorkCounts::batches_of_unshared_queues` counts the unshared queues' batches under either value. So does a batch whose queue's expected run is unknown (none of its batches seen complete yet) or would take the group past 16 ms (`WorkCounts::group_ends_long`), leading the next group where its own run is within the bound; a queue's expected GPU run follows its command buffers' own GPU times by their timestamps (raised at once by a longer one, halved toward a shorter one), which other `VkDevice`s' work on the GPU does not lengthen; with `DeviceOptions::gpu_times_from_host` it follows those host times, which hold other clients' work on the GPU too, so under contention there a queue's batches may stop grouping. So that checked command buffers (the consumer checks each) are found ready together, the submission checks of up to three batches right behind a line's head that goes run with the head's, in commit order, none committed after another queue's batch: such a check runs before the previous batch's `vkQueueSubmit` rather than after it, in the scheduler pass that submits its own batch. A pass that finds no batch ready sends the batches held, unless two or more earlier submissions of their `VkQueue` are not seen complete: the GPU runs those first in any case, so the batches stay held, and those committed meanwhile join them, until one submission is left in flight (a completion turn wakes the scheduler at its value), the group fills, a later batch sends it, a head waits for the GPU, or a thread waits for one of their command buffers' completion, which sends them at once; nor are they kept where the scheduler's thread runs next a submission handler of another queue's command buffer (one a pass that settled a switch of storage forms keeps; the thread hands every other pass's to the device's handler threads, where none holds its passes back): they go first, as Metal schedules a queue's command buffers whatever another queue's handler does (an M3 Max, probe `cross_queue_handler_waits`); a batch that ends a command buffer with a switch of storage forms riding on it, which settles by its submission's outcome, is never kept so. A batch a committing thread submits (`CommandBuffer::commit_and_submit`) goes alone where its `VkQueue` runs at most one earlier submission not seen complete, as the pass that held it would send the group at once; where two or more run it is left to the scheduler's thread, which holds it. A held batch that ends its command buffer is `Scheduled` as it is held, its submission handlers run first, then its scheduled handlers, and its kernel end time set, as an M3 Max schedules a command buffer committed behind running work 0.04 to 0.18 ms after its commit. The runtime's: no pipeline differs. | `completion = CompletionPolicy::Grouped` | `completion = CompletionPolicy::Exact`: one submission per batch, each signalling its own values; each line's head checked alone; but a command buffer the program marks to join the next (`CommandBuffer::set_completion_joins_next`, a runtime extension the consumer sets on the parts of one of its own command buffers whose completion nothing observes) groups as under the default, on a device whose check finds the merge and only there: its batches wait in the group within the pass that found them ready (no group is kept past its pass), the first batch of its `VkQueue` behind them that is not marked goes last in the group, which then goes at once (`WorkCounts::group_ends_closed`), so that one is seen complete at its own end and never held back, and its check runs with theirs; a marked batch held alone whose group went at the pass's end counts `WorkCounts::batches_held_alone_unkept` | Each command buffer of a submission but the last is seen complete (status, completed handlers, waits), and the event values it signals are reached (by the GPU waits on other queues, the host's waits, value reads and listeners), once the last completed: late by the GPU time of at most three later batches (about 0.1 to 0.2 ms each in the consumer's compositor frames on the Iris Xe), at most 16 ms of their expected runs, never early, in commit order. Metal's contract states no bound on when completion is seen (an M3 Max reports a command buffer complete, its handlers, status, waits and event listeners alike, 0.04 to 0.10 ms after its GPU end), and no member but the first waits, so no wait holds a member back: a valid program sees only later completion, as of slower GPU work. Measured in the consumer's macOS 26.7.2 guest walks on RADV at ca6259f7d1, the lateness of command buffers seen complete after a later one's GPU end was, at the 99th percentile, 18.4 ms against `Exact`'s 2.1 ms (60 ms at most) on the Radeon 780M and 5.1 ms against 2.4 ms (17.5 ms at most) on the RX 7900 XTX, where the consumer's Metal oracles (an M3 Max under macOS 27.0.1, two x86 Macs under 26.7.1) ran a completed handler at most 0.28 ms after its command buffer's GPU end at the 99th percentile. The bounds are on expected runs, so a later batch that runs longer than its queue's recent ones makes the members before it late by its actual run, which no bound set ahead of the run can cap. `CompletionPolicy::Exact` adds none of this lateness: each command buffer is seen complete at its own end. A batch kept while earlier work runs is seen complete within the same bound, and, where the one submission left in flight ends before its group reaches the GPU, late besides by that gap: at most a completion turn's reaction and the group's `vkQueueSubmit`. Commands, barriers and GPU times are unchanged. `GroupedCompletion` (`grouped-completion`), announced once per device at its first such submission; `runtime_lane::grouped_submissions` | ANV (Iris Xe of RPL-P; `frame_costs::frame_costs_over_imports`, the checked device, 67 command buffers a frame, GPU at 467-783 MHz), with 520 host imports live, where the Exact form's submissions fall behind the commits as the guest's do: 32.0-33.2 kernel submissions a frame against 67.0, 3.4-3.5 ms of execbuffer ioctl a frame against 6.9-7.9 ms, the scheduler thread's CPU 61-63 us a command buffer against 121-136 us, a frame through completion 4.7-5.9 ms against 8.6-9.7 ms; in the guest's shape with 520 (a second queue taking every 20th command buffer, each signalling a shared event, every 10th waiting for one): 26.2-26.7 kernel submissions a frame against 67.0, 2.8 ms of ioctl a frame against 6.9-7.0 ms, the scheduler 52-53 us a command buffer against 122-123 us, a frame through completion 6.0 ms against 8.7 ms; with 260, where it keeps up, 64.9-66.3 kernel submissions a frame against 67.0, the CPU and wall times alike. The cost (`grouped_submissions::grouped_completion_delays`, 8 command buffers of 0.3-0.5 ms of GPU work ready together): the host saw each but a group's last complete later by the later ones' GPU time, the last 0.1-0.3 ms later than alone (the completion turn's per-command-buffer work for the group, done at its end). Keeping a group while earlier work runs (UHD 770 of RPL-S, ANV, the guest's shape with 520 host imports, a submission handler on every command buffer and a 16 MiB fill ahead of each, about 1.3 ms of GPU each; the kept form against the batches sent as found): committed every 1 ms, 18.1-18.2 groups kept a frame, 24.9-25.0 kernel submissions a frame against 57.9, 2.18-2.90 ms of execbuffer ioctl a frame against 4.64-5.43 ms, the scheduler thread's CPU 67-82 us a command buffer against 113-118 us, the GPU idle within a frame's span 0.61 ms against 0.68-0.69 ms, a frame through completion 89.5-89.6 ms alike, completion seen later (GPU end to completed handler: mean 1.82-1.86 ms against 0.43-0.46 ms, p50 1.57-1.60 against 0.11-0.13, p99 4.35-4.37 against 4.09-4.11, max 4.52-4.55 against 4.18-4.23); committed at once, 18.0 kernel submissions a frame against 23.4; with no fill, 18.0 against 20.6, the GPU idle 0.59 ms against 0.58-0.66 ms. In the consumer's guest drag on the Iris Xe (i9-13900H; three passes each way): 24.4-27.5 kernel submissions a frame against 42.4-43.8, the scheduler thread 0.4-1.7 ms of CPU a frame less, 15.7-17.3 frames a second against 16.4-17.6: the frame rate alike within noise, as the scheduler thread does not bound that frame. A batch a committing thread submits alone (RADV, Mesa 26.2.6, RX 7900 XTX, whose check finds submissions merged; two rounds each against the form that left every batch that may wait in a group to the scheduler's thread, `tests::completion_latency`): a checked fill's `commit_and_submit` to its submission handler p50 30.4-32.8 us, p90 32.3-35.9, p99 48.8-57.8 against 36.2-55.7, 56.4-176.3 and 112.1-198.5, the call returning after its submission (32-34 us against 4-8); committed 2 ms apart between two shapes of `commit`, its commit to submission p50 31.9-36.1 us, p90 102.6-135.7 against 39.2-50.1 and 152.1-169.7, and the `commit`s beside it alike (p50 32.1-47.3 us against 38.9-46.7, the scheduler thread's wake p50 4.0-4.5 us against 4.1), as the committing thread wakes that thread after a batch it submitted alone, as the batch's hand-off to it would have. On lavapipe, whose check finds no merge, the two forms alike, the scheduler's thread woken alike (a checked fill's p50 12.5-13.4 us against 12.4-13.4). The bound on a group's expected runs (`GROUP_RUN`, 16 ms; RADV, Mesa 26.2.6, Radeon 780M, `frame_costs::frame_costs_over_imports`, one run with it and one without on one host at a load of 11 to 14, each leg twice): grouped `vkQueueSubmit` calls a frame 22.3-22.5 against 23.9-24.8 with 260 host imports (calls in all 23.8-24.4 against 25.4-26.5), 17.0 against 17.0 with 520, 17.2-17.5 against 17.3-17.4 in the guest's shape; no group went for a batch's expected run (`group_ends_long` 0.0 a frame). | -| Batches of command buffers on one `VkQueue`, on a driver measured to start no kernel submission of a queue before the one before it completed (ANV, RADV and NVIDIA's; `batch_order.rs`), are ordered by their ends: each ends with a barrier ordering its work before every later command of its `VkQueue` (the exact form's end orders it before the host's reads and writes alone), so a batch that depends on an earlier one there begins with no barrier of its own, often no command buffer of barriers, and its first encoder's GPU start is written at the bottom of the pipe, once everything before it completed. Metal starts an independent command buffer committed behind running work while that work runs (an M3 Max under macOS 27.0.1, probe `gpustart`); those drivers ran two batches of independent work one after the other under every shape measured (no end barrier, the host's or the widened one; in one `vkQueueSubmit` or two, merged into one kernel submission or not), where two dispatches of one command buffer ran side by side. The runtime's: no pipeline differs. | `batch_order = BatchOrderPolicy::Ends` | `batch_order = BatchOrderPolicy::Exact`: a barrier for each dependency of a batch's work on an earlier batch's of its `VkQueue`, the end's barrier to the host's reads and writes alone, the GPU start written at the top of the pipe; every other driver takes it under either value | None: on those drivers each batch starts once the one before it completed under either value, so the work's order, its results and its GPU times are the same, and a batch's GPU start is the end of the work before it, when such a driver starts it. Not announced; `runtime_lane::commit_work` and `runtime_lane::gpu_times` test both values | UHD 770 (ANV, RPL-S), the consumer's frame shape over 520 host imports, 67 command buffers a frame, Grouped completion, the widened end barrier against the exact form (a probe build of each): with no fill ahead of each command buffer, 67.0 command buffers submitted a frame against 129.3-129.7, the GPU's span a frame 1.84-1.90 ms against 1.99-2.06 ms, a frame through completion 2.13-2.22 ms against 2.27-2.38 ms; with a 1 MiB fill ahead of each, 134.0 against 262.9, 8.03-8.22 ms against 8.32-8.42 ms, 9.00-9.15 ms against 9.25-9.36 ms. Radeon 780M (RADV, Mesa 26.0.8), this switch: with no fill, 67.0 against 128.9-129.0, a frame through completion 48.3-48.6 ms against 42.6-47.0 ms; with a 16 MiB fill committed at once, 134.0 against 251.0-251.1, 50.6-50.8 ms against 50.8-57.3 ms; committed every 1 ms, 134.0 against 249.7-250.2, 71.3-83.6 ms against 106.3-113.6 ms (each kernel submission there leaves about 2.5 ms of the GPU idle over 520 host imports, which sets these frames) | +| Batches of command buffers on one `VkQueue`, on a driver measured to start no kernel submission of a queue before the one before it completed (ANV, RADV and NVIDIA's; `batch_order.rs`), are ordered by their ends: each ends with a barrier ordering its work before every later command of its `VkQueue` (the exact form's end orders it before the host's reads and writes alone), so a batch that depends on an earlier one there begins with no barrier of its own, often no command buffer of barriers, and its GPU start, written at the top of the pipe, waits behind that end barrier until everything before it completed. Metal starts an independent command buffer committed behind running work while that work runs (an M3 Max under macOS 27.0.1, probe `gpustart`); those drivers ran two batches of independent work one after the other under every shape measured (no end barrier, the host's or the widened one; in one `vkQueueSubmit` or two, merged into one kernel submission or not), where two dispatches of one command buffer ran side by side. The runtime's: no pipeline differs. | `batch_order = BatchOrderPolicy::Ends` | `batch_order = BatchOrderPolicy::Exact`: a barrier for each dependency of a batch's work on an earlier batch's of its `VkQueue`, the end's barrier to the host's reads and writes alone, the GPU start written at the top of the pipe; every other driver takes it under either value | None: on those drivers each batch starts once the one before it completed under either value, so the work's order, its results and its GPU times are the same, and a batch's GPU start is the end of the work before it, when such a driver starts it. Not announced; `runtime_lane::commit_work` and `runtime_lane::gpu_times` test both values | UHD 770 (ANV, RPL-S), the consumer's frame shape over 520 host imports, 67 command buffers a frame, Grouped completion, the widened end barrier against the exact form (a probe build of each): with no fill ahead of each command buffer, 67.0 command buffers submitted a frame against 129.3-129.7, the GPU's span a frame 1.84-1.90 ms against 1.99-2.06 ms, a frame through completion 2.13-2.22 ms against 2.27-2.38 ms; with a 1 MiB fill ahead of each, 134.0 against 262.9, 8.03-8.22 ms against 8.32-8.42 ms, 9.00-9.15 ms against 9.25-9.36 ms. Radeon 780M (RADV, Mesa 26.0.8), this switch: with no fill, 67.0 against 128.9-129.0, a frame through completion 48.3-48.6 ms against 42.6-47.0 ms; with a 16 MiB fill committed at once, 134.0 against 251.0-251.1, 50.6-50.8 ms against 50.8-57.3 ms; committed every 1 ms, 134.0 against 249.7-250.2, 71.3-83.6 ms against 106.3-113.6 ms (each kernel submission there leaves about 2.5 ms of the GPU idle over 520 host imports, which sets these frames) | | Command queues on a device whose GPU idles when consecutive work comes from another `VkQueue` share `VkQueue`s by choice (`queue_share.rs`): the runtime's own self-check, not a `DriverFact` row, measures that idling once per driver, release and runtime on a thread of its own and keeps its verdict (`Idles`, `DoesNotIdle`, `Unchecked`) in the shader cache's directory, as the in-place check keeps its own (`queue_switch_check.rs`: 48.7 to 51.3 us a switch on the RTX 5080 Laptop GPU, NVIDIA 615.71.09, `Idles` above 20 us). A command queue that makes a command buffer while it holds no other uncompleted one moves onto the busy `VkQueue` of its family whose oldest batch has run under 0.5 ms, the most batches in flight first, so short command buffers of several queues run with no switch between them. A queue one of whose command buffers ran on the GPU for over 2 ms, by its own timestamps (not the host's view of how long it ran as its `VkQueue`'s oldest, which also holds its wait for the GPU to start it and the waiter's lateness to see it complete), or held its `VkQueue` for over 2 ms from the submission of a batch that waited on the GPU for another `VkQueue`'s work (an `MTLEvent`'s signal, the tracker's wait, new resources' first work) to its own GPU end, is long: no queue joins its `VkQueue` while it lives, and it moves once more, at its next idle point, to an idle `VkQueue` no long or unshared queue holds. A queue whose command buffers must never wait behind another queue's (a compositor's beside an application's) is made with `Device::new_command_queue_unshared`: it never moves and no queue joins its `VkQueue`. Under either value, as a queue is made, it takes the round robin's `VkQueue` the fewest live command queues hold, of those no unshared queue holds, in turn among equals, and an unshared queue one no command queue holds where one is free (one pass over the `VkQueue`s' counts; one that finds none shares the one the fewest hold, `WorkCounts::unshared_queues_sharing_a_vk_queue`). Presenting queues and a queue that lent its `VkQueue` (`with_vk_queue`) never move. Before the verdict, and where it is not `Idles` or there are no two `VkQueue`s of one family (MoltenVK, RADV, lavapipe), every queue keeps the `VkQueue` it took at its creation; so does every queue of a device whose command buffers write no GPU timestamps it reads (`gpu_times_from_host`, or a driver whose timestamps wait for every queue's), which does not share and is counted (`WorkCounts::queue_sharing_untimed`). The runtime's: no pipeline differs. | `queue_sharing = QueueSharingPolicy::Adaptive` | `queue_sharing = QueueSharingPolicy::PerQueue`: each command queue keeps the `VkQueue` it took at its creation (the fewest live queues' as above), and the check does not run | A command buffer waits behind the command buffers of the queues sharing its `VkQueue`, where Metal's queues wait for each other only inside one command. The residual stall: once per logical queue that goes long, for a queue that joined its `VkQueue` during its short phase, about one long command buffer's length: the command buffers committed behind that queue's first long one there wait for its whole length (and those behind its later ones while it holds work, until its next idle point). Measured on the RTX 5080 Laptop GPU beside an application that alternates draws with 30 ms command buffers: a shared compositor's commits at 4,800 a second had 64 completions over 10 ms, at most 26.4 to 30.1 ms, in each of 3 runs of each of two such shapes (one join each), against none over 10 ms under `PerQueue` in those 6 runs (at most 5.6 to 9.7 ms); with 2 ms of draws between long command buffers, none over 10 ms in 3 runs (at most 5.7 to 9.8 ms) against 7, 0 and 0 under `PerQueue` (at most 6.9 to 11.2 ms). On an unshared queue, 0 over 10 ms in every run. A command buffer's GPU start time includes the other queues' work before it. `QueueSharing` (`queue-sharing`), at the device's first join | Command buffers a second on the RTX 5080 Laptop GPU, one-draw command buffers, each thread its own queue, the default against `PerQueue`, runs after a lock hold's first: 8 threads with 3 in flight 50.7k to 54.7k against 27.4k to 28.0k (5 runs each); 8 threads with 1 in flight 47.0k to 50.1k against 13.9k to 14.3k (5); 2 threads with 3 in flight 28.0k to 53.7k against 21.4k to 28.0k (10 each, in turn, the default above `PerQueue` in each pair; no thread's queue marked long), and beside another process's 30 ms command buffers 5.1k to 6.7k against 4.0k to 4.1k (3 each; the host's view marked a thread's queue long in 1 of 3 runs, which then ran at `PerQueue`'s 4.1k); 2 threads with 1 in flight 16.9k to 20.7k against 10.1k to 11.5k (5); one thread over 16 queues in turn 21.7k to 43.3k against 10.2k to 11.1k, over 2,048 20.0k to 39.2k against 10.2k to 11.2k (4). Beside an application whose queue never shared with the compositor (isolation, 300 and 30 dispatches), both 0 over 10 ms | | A chain of `half` additions, subtractions and products on a device without `shaderFloat16` (vk12-floor, SwiftShader, Pascal; capability emulation: the module computes each in `float` and rounds it by the device's `OpQuantizeToF16`): an operation whose flags hold `contract` and `reassoc` and whose result only such operations read is held at `float` precision unrounded, so the chain rounds where a value leaves it (a store, an output, a conversion, a comparison, a call, a phi, a vector move, an operation without both flags), one quantize per exit instead of one per operation (`lower::arith::half_chain`). A device with `shaderFloat16` computes `half` alike under either value. | `half_chains = HalfChainPolicy::AtExits` | `half_chains = HalfChainPolicy::EachOperation`: every operation's result rounded to `half`, as the AIR computes it | The result may differ from the rounded operations' by the roundings the chain skips, each within half a unit in the last place of a `half` at its step, compounded along the chain; a value inside the chain past `half`'s range (65504) stays finite where the rounded operations reach infinity. Within the AIR's flags, which let a compiler regroup and fuse such operations. `FastMathRewrites` (`fast-math-rewrites`) | Not timed. Size on vk12-floor (the fixtures' SPIR-V words, the default against the accurate form): `hfb_filter_bank` 121,270 against 131,766 (1,024 quantizes against 2,464), `grd_half_many_samples` 82,019 against 84,627, `nan_half_fast` 9,808 against 9,832 | | A texture that samples, reads, renders into it or is written through a shader (`ShaderWrite` or `ShaderAtomic` usage, of texels of 1, 2, 4, 8 or 16 bytes) over host pages (a no-copy buffer's, or a no-copy heap's buffer's, imported by their pointer or as dma-bufs; or a buffer in fresh pages; or a copied host buffer's copy of them, `copied.rs`, its image bound in the copy's memory where the check passed for the pages, and for the copy's fresh pages or, for a `DRM_FORMAT_MOD_LINEAR` image in memory the device allocates, its pooled memory, `WorkCounts::copied_textures_in_place`) is a linear image aliasing the pages in place, where the device makes the image (its format and usage linear, at the pages' pitch) and its own check shows that the operations Vulkan lets read and write every byte bound to it leave every byte alone while the CPU writes beside it: the image's first move (`VUID-VkImageCreateInfo-pNext-01443` makes such an image start `UNDEFINED`), and for one that renders a render pass's load and store operations and its moves into `ATTACHMENT_FEEDBACK_LOOP_OPTIMAL_EXT` and back, and for one a shader writes a kernel's storage writes of its texels (which of a linear image a driver may widen past a texel), each access checked apart (a shader's writes of 1- or 2-byte texels apart from those of wider ones, which a driver may store through a wider access), and each apart for texels that share a line of the device's memory (`nonCoherentAtomSize`, "the size and alignment in bytes that bounds concurrent access to host-mapped device memory") with bytes beside them and for texels that share none (their start, their end and, with bytes between rows, each row's start and end on a line; `in_place::RowEnds`): a byte changed beside texels that share none fails both, one changed beside texels that share one fails those alone (the Iris Xe, ANV, Mesa 26.2.6, whose clear and store, and draws, write back whole the 64-byte line that holds a row's last texels, fails renders, and writes, for rows that end inside a line, a byte between rows changed, and passes both for rows that end on one: a 3840x2160 `BGRA8Unorm` surface's 15360-byte rows are 240 lines each). Over a no-copy buffer's dma-buf pages the image is a `DRM_FORMAT_MOD_LINEAR` one whose first move acquires it from `VK_QUEUE_FAMILY_FOREIGN_EXT`, in one of two forms, each judged by a class of its own: bound at the texels' offset in the import the buffer lies in, its plane at offset 0, where that is one import dedicated to nothing and the driver takes such an image there (no dedicated allocation required, `VUID-vkBindImageMemory-image-01445`; none of the buffer's, `-memory-10926`; its alignment dividing the offset, `-None-10735`), with no dma-buf or import of its own (`PagesClass::DmaBufInImport`, `WorkCounts::dma_buf_images_in_import`); else over a dma-buf of its own pages in a dedicated import (`PagesClass::DmaBuf`; RADV, **Known gaps**). A kernel's writes of a texture over a buffer's rows (no IOSurface plane's) whose rows, each to its pitch, start and end on a line, its buffer holding the last row to its pitch, take a verdict of their own from the same rounds, which a round that changed only bytes of its rows' padding (after a row's last texel, before its pitch, the last row's included) passes (`in_place::Padding`, `Access::BufferWrites`): Metal leaves those bytes to the GPU there (an Intel UHD Graphics 630 under macOS 26.7.1 wrote older values back over the CPU's writes to them under a kernel's writes of a texture over a buffer, the last row's included, where an M3 Max under macOS 27.0.1 and a Radeon Pro 5300M kept them, and all three kept them under draws, clears and stores and over IOSurfaces; `crates/metal2vulkan-conformance/probes/row_padding_writes.m`), and the rule follows the x86 Macs' envelope (docs/API.md, section 10, **Kernels**), so the Iris Xe's written textures over a buffer take the image in place whatever their rows' ends. A deliberate, scoped exception to relying on documented Vulkan behaviour alone, the owner's rulings (2026-10-26, and 2026-10-27 and 2026-11-07 for render targets and written textures: the GPU works on the caller's pages in place as a Mac's does, whatever a linear image costs it, on a discrete GPU too; `in_place.rs`). A texture over a buffer of the runtime's pooled memory whose rows the device's own linear image lays out otherwise (a padded pitch the driver does not take: ANV lays linear rows tight; rows apart only over a buffer that declares them unobserved, `BufferDescriptor::padding_unobserved`) is, by the same rule, a `DRM_FORMAT_MOD_LINEAR` image at Metal's pitch bound in the buffer's memory, at any size, where the device makes one (no external memory, which Vulkan allows: `VUID-VkImageCreateInfo-tiling-02261`, `VUID-vkBindImageMemory-image-01445`), made `UNDEFINED` (`VUID-VkImageCreateInfo-initialLayout-12478`), whose first move the check's pooled class judges (`PagesClass::Pooled`: a buffer of that memory, its images at Metal's pitch alone; `WorkCounts::pooled_pitched_images`); a texture made before that class's verdict is a shadow that moves to that image once the verdict passes, as one over host pages moves in place (below; `WorkCounts::pooled_textures_moved_in_place`, `pooled_texture_shadows_freed_after_move`). A texture over a buffer whose memory the runtime exports (`exported_memory.rs`: a block that exportable buffers of one handle type share) is, by the same rule, the device's linear image or that `DRM_FORMAT_MOD_LINEAR` image made for the memory's handle type, which an image bound there must name (`VUID-vkBindImageMemory-memory-02728`), and so made `UNDEFINED` (`VUID-VkImageCreateInfo-pNext-01443`), whose first move the check's exported classes judge, one per handle type (`PagesClass::ExportedFd`, `PagesClass::ExportedDmaBuf`: an exportable buffer of that handle type, its textures taking the product's image), a texture made before their verdicts moving to it once they pass as over the pooled memory; a shadow, its notice naming why, where the memory is a buffer's dedicated allocation (`VUID-vkBindImageMemory-memory-10926`) or the device's image format query (`VkPhysicalDeviceExternalImageFormatInfo`) takes the handle type for no such image without a dedicated allocation. A texture over a buffer in a block of the runtime's buffers allocated exportable as an opaque file descriptor and never exported (`memory.rs`'s "Buffers in exportable blocks") is the device's linear image made for that handle type, made `UNDEFINED`, or, over rows whose bytes between them only the device's ordered commands write at a pitch that image does not lie at, the `DRM_FORMAT_MOD_LINEAR` one made for that handle type where the device makes one without a dedicated allocation (RADV asks one of every such image made for a handle type, so there such a texture is a shadow: **Known gaps**), whose first move and accesses the check's class of such blocks judges (`PagesClass::FdBlocks`: a buffer in such a block, its textures taking the product's images, made only where such a block holds every image a texture over a plain block's buffer that keeps its padding takes in place, but for rows with bytes between them at a pitch the device's linear image does not lie at, `texture/fd_blocks_cover.rs`), its first move over rows whose bytes between them only the device's ordered commands write keeping the bytes it is bound to by copies whatever the verdicts (`texture/first_move.rs`'s `GpuKeep`, as for a `DRM_FORMAT_MOD_LINEAR` image over such rows in a plain block); the device's buffers lie there only where those verdicts give every texture over one what it takes over a plain block's buffer (`in_place::fd_blocks_take`), in plain blocks until they are known; a buffer that declares its padding unobserved never lies there, but in a block of its own kind allocated exportable as a dma-buf too where the device takes such blocks (`memory.rs`'s `Holds::FdDmaBufs`), in which no image is bound, a texture over it taking a `DRM_FORMAT_MOD_LINEAR` image bound to a dedicated import of the block's dma-buf, whose first move and accesses the check's class of exported dma-bufs judges (`PagesClass::ExportedDmaBuf`; `texture.rs`'s `exported_dma_buf_alias`), and in a plain block elsewhere, so that such a texture keeps a `DRM_FORMAT_MOD_LINEAR` image or the device's linear image either way. A texture that renders over a buffer that declares its padding unobserved, its rows each to its pitch sharing no line with bytes past them, takes the verdict of renders that lets a byte of its rows' padding change (`Access::UnobservedRenders`, `Padding::Unobserved`), which the renders' own rounds give as the writes' give theirs: the declaration lets a pass's load and store write those bytes (the Iris Xe's clear and store write back the 64-byte line that holds a row's last texels whole), and a byte past the last row's pitch, or a texel, fails it. A texture that renders over host pages whose renders failed is a shadow whatever its rows' padding. The class's copies of a texture's texels into a buffer's rows (`Access::Copies`: a blit into the rows of a buffer over the pages, as a shadow's copy back writes them, while the CPU writes beside them) decide no texture's placement: where they or a kernel's writes failed for rows that end inside a line, or have not answered, a shadow's copy back into such pages is spliced and its merge goes on the host, so the CPU's writes beside its texels stay (`shadow_splice.rs`; the Iris Xe's render targets over rows that end inside a line, **Known gaps**). Where the class's own copies kept every byte or were not checked, the copies of another class of host pages that failed for those row ends, its reads of them passing, decide it, but only where the check's pages of both lay in memory of a type of the same property flags as the driver reports them (`VkMemoryPropertyFlags`: host-cached or not, coherent or not; `in_place::copies_verdict`, each class's flags kept in the check's record): a copy's line write-back is the GPU's store path into memory of that type, which a class's rounds catch only as often as the CPU's writes race it there, and a write-back measured through memory of other flags says nothing of this memory, so where the flags differ, or are not known, the class keeps its own copies' verdict. The check runs once per driver and driver version (its record named by the driver and the check's own version, not the runtime release), per class of pages, access and row ends (but the copies of the class whose images bind in their buffer's import, which takes the dma-buf class's copies' verdicts where that class measured them and both classes' check pages lay in memory of a type of the same property flags: its pages are made as that class's, and a copy puts no image over them; `in_place_check::shared_copies`), on a thread of its own, the verdicts it measured kept in the shader cache's directory with those it could not check for a cause that lasts for the driver (the device lacks an extension, a feature, an import, a format or an image of the shape), while one it could not check for a cause that may pass (pages or memory not made, an import refused, its writer thread not started, a move or the stores that failed) is checked again by the next device, its reason noted; a texture made before its verdict is a shadow, made without waiting for the check (its rounds take seconds on some devices and builds; `host_texture_shadows_check_pending`), and moves in place once its class's verdicts pass, at the commit of the device's only uncommitted command buffer, with no copy (`host_textures_moved_in_place`), its shadow's image freed once the command buffer that took the move completed (`host_texture_shadows_freed_after_move`), or, where a view made before the move presents it, a shadow made over it holds it as its truth, or the texture is untracked, once those and the texture went. A texture a shader writes of texels of a width no check stores (none of 1, 2, 4, 8 and 16 bytes), a check that failed or made no image, and a format, usage or pitch no image takes keep the shadow (`shadowed-texture`, its reason named, `WorkCounts::host_texture_shadows_*`, those that render and those a shader writes counted apart in `host_texture_shadows_render_target` and `host_texture_shadows_shader_write`). On a discrete GPU a `Shared` texture and an IOSurface's are in place too, read across the bus, never copied to the device's memory for speed; a `Managed` no-copy buffer there is two copies (`managed_copy.rs`, the **Costs of matching Metal** bullet), and a texture over its bytes is over its GPU copy, no texture over host pages; a `Managed` texture over the bytes of a no-copy buffer that lies in its pages there (its GPU copy found no room, or Metal's private option bit 24 drops its GPU writes) that only samples or reads, over memory that carries a log of its writes, is a device copy instead (`WorkCounts::device_copy_textures`), the GPU's copy of the two Metal keeps of a `Managed` resource on a Mac with a discrete GPU, its copies in only the rows the log reports changed. | `host_page_textures = HostPageTexturePolicy::InPlace` | `host_page_textures = HostPageTexturePolicy::Shadow`: every texture over host pages a shadow, its texels copied in before each command buffer that uses it and merged back after each write (the host-pages bullet under **Costs of matching Metal**) | Exact where the driver keeps what its check showed: the check covers texels, the bytes between rows and those after the image, of 1, 2, 4, 8 and 16-byte texels and a 3840x2160 surface, three rounds each, for an image that reads and one that renders (its pass a clear at load and a store, then a draw over its last column in a pass that loads and stores it; a resolve into it is not among the rounds), the CPU writing beside the texels sweep after sweep until each step completed, so that a device that writes back bytes it read beside them, wherever in the step, puts back an older value the check finds, and, for one a shader writes, of 4, 8 and 16-byte texels, rows apart (of widths no multiple of 4 and odd heights among them) or tight, and 1920x1080, and apart of 1- and 2-byte texels, rows apart at a 256-byte pitch (of rows that end inside a 4-byte word and odd heights) or tight, and 1024x64, each texel stored by a kernel through an unsigned-integer view (a program's atomics, and its stores through a float view, are not among the rounds); a driver whose operations changed a byte outside every round's window would undo a CPU write made meanwhile. A kernel's writes of a texture over a buffer whose padding is free may change that padding, as an x86 Mac's GPU's do (above). Not announced where the check passed. A CPU write reaches the image's reads as it reaches the buffer's (Host Write Ordering Guarantees) | See **Costs of matching Metal** (host pages): the shadow copies a sampled 3840x2160 surface in whole each command buffer, and a render target's shadow copies it in, keeps it and merges it back at each render pass instance |