From 24ceac6e88fe66ff408d197a3aabc692e18db6bc Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Sat, 7 Nov 2026 11:31:12 -0800 Subject: [PATCH] Make device copies on a discrete GPU of Managed textures over host pages alone On a discrete GPU, a texture over host pages that only samples or reads, over memory that carries a log of its writes, was a device copy (a shadow in VRAM whose copies in take the rows the log reports) whatever its storage mode: a speed choice, so the GPU read the surface from its own memory instead of across the bus. The owner's ruling of 11-07 (confirmed for discrete): Shared and IOSurface memory over guest pages is used in place over the import, never shadowed to VRAM for speed; Managed keeps Metal's two copies on a discrete Mac. So `Texels::device_copy` now also asks for `Managed` storage and a buffer's bytes (not an IOSurface plane's, whose memory is one copy whatever the descriptor's storage mode): a Shared texture and an IOSurface's are in place over the import where the device's check passed, as on every other device. Tests: the runtime's `a_logged_device_copy_sampled_in_an_inline_pass_is_copied_in_before_the_pass` and the device_copies lane make their buffers Managed (`over_logged_as`, `over_as`); the new lane test `a_shared_surface_over_logged_pages_is_no_device_copy` asserts a Shared surface over logged pages is no device copy on any device, in place exactly where the check passed for pointer pages, and that its reads hold the pages' texels before and after a logged CPU write. Docs: API.md, the runtime README, FAST-PATHS.md's in-place row, the WorkCounts field and the lanes' module docs. (cherry picked from commit fd9fc11dd372a0985fdbc921adb2bc971ff78a3d) --- crates/metal2vulkan-runtime/README.md | 17 ++- .../src/buffer_texture.rs | 13 +- .../src/tests/dirty_pages_device.rs | 52 +++++-- crates/metal2vulkan-runtime/src/texture.rs | 13 +- .../metal2vulkan-runtime/src/work_counts.rs | 12 +- .../src/runtime_lane/device_copies.rs | 140 +++++++++++++++--- .../src/runtime_lane/shadow_sync_costs.rs | 2 +- docs/API.md | 15 +- docs/FAST-PATHS.md | 2 +- 9 files changed, 201 insertions(+), 65 deletions(-) diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index 11e72ff69..71e6ca8dd 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -339,14 +339,15 @@ the record the pass is making. announces it (`shadowed-texture`, naming why) for every other texture there (under `HostPageTexturePolicy::Shadow`, one that writes through a shader, one made before the check answered or whose check did not pass), where the device's linear images cannot hold Metal's - layout, and where the rows lie with bytes between them. On a discrete GPU, a texture that only - samples or reads whose policy takes the image in place, over a no-copy buffer whose memory - carries a log of its writes (`HostMemory::with_dirty_pages`), tracked and laid out as one copy, - is instead such a copy in the device's memory, announced nowhere, whatever the check answered: - its copies in take only the rows the log reports changed, so the GPU reads the surface from its - own memory, where in place it reads the pages across the bus at every sample - (`WorkCounts::device_copy_textures`). Exact either way; integrated GPUs, CPU devices and memory - without a log keep the image in place. + layout, and where the rows lie with bytes between them. On a discrete GPU, a `Managed` texture + over a no-copy buffer's bytes (not an IOSurface plane's) that only samples or reads, whose + policy takes the image in place, over memory that carries a log of its writes + (`HostMemory::with_dirty_pages`), tracked and laid out as one copy, is instead such a copy in + the device's memory, announced nowhere, whatever the check answered: the GPU's copy of the two + a `Managed` resource is on a Mac with a discrete GPU, its copies in only the rows the log + reports changed (`WorkCounts::device_copy_textures`). A `Shared` texture and an IOSurface's + stay in place there, read across the bus as a discrete Mac's GPU reads them. Exact either way; + integrated GPUs, CPU devices and memory without a log keep the image in place. - **Two-plane YCbCr textures** (`YCBCR8_420_2P` and its kin over a surface's planes) hold an image of the texels Metal reads, converted from the planes before a command buffer's first use where they changed. Where `has_unified_memory`, a function that only samples or gathers a diff --git a/crates/metal2vulkan-runtime/src/buffer_texture.rs b/crates/metal2vulkan-runtime/src/buffer_texture.rs index 71d5974af..bc85fcf7b 100644 --- a/crates/metal2vulkan-runtime/src/buffer_texture.rs +++ b/crates/metal2vulkan-runtime/src/buffer_texture.rs @@ -1598,15 +1598,20 @@ impl Texels { /// its image's view of its own 8-bit unsigned normalized format, where given so /// (`shadow_merge.rs`). Refused as `new_buffer` refuses the staging buffer. /// Whether these texels take a device copy on `device` (`texture.rs`, `dirty_pages.rs`): on - /// a discrete GPU, tracked, over host pages whose memory carries a log, where the shadow's - /// copy in is one region straight from the texels' place in the buffer's `VkBuffer` (one - /// slice, rows that share no bytes, a first texel at a multiple of the texel's size there), - /// the copy in a log decides. + /// a discrete GPU, a `Managed` texture over a buffer's bytes (not an IOSurface plane's), + /// tracked, over host pages whose memory carries a log, where the shadow's copy in is one + /// region straight from the texels' place in the buffer's `VkBuffer` (one slice, rows that + /// share no bytes, a first texel at a multiple of the texel's size there), the copy in a log + /// decides. A `Managed` resource on a Mac with a discrete GPU is two copies, the system + /// memory's and the GPU's own; a `Shared` texture and an IOSurface's are the system memory's + /// alone, which that GPU reads across the bus, so they take none. pub(super) fn device_copy(&self, device: &Device) -> bool { let layout = &self.layout; // The looks at the pages last: each takes their lock (`WorkCounts::no_copy_lies_read`), // which a texture on any other GPU never needs. device.properties().kind == crate::DeviceKind::Discrete + && !self.surface + && matches!(self.options.storage_mode(), Ok(StorageMode::Managed)) && self.tracked() && layout.slices == 1 && layout.shared_bytes() == 0 diff --git a/crates/metal2vulkan-runtime/src/tests/dirty_pages_device.rs b/crates/metal2vulkan-runtime/src/tests/dirty_pages_device.rs index b7ef2fe7a..e5dea2e41 100644 --- a/crates/metal2vulkan-runtime/src/tests/dirty_pages_device.rs +++ b/crates/metal2vulkan-runtime/src/tests/dirty_pages_device.rs @@ -71,9 +71,9 @@ //! Such a shadow sampled by a pass whose first instance records inline (`render/inline_first.rs`) //! takes its gated copy in before the pass, as every command before the pass does //! (`EncoderCore::hold_pass`): the pass's draws read the bytes the CPU wrote, the first time and -//! after a write told to the log, and the pass stays one inline instance. So does a texture the -//! pass only samples, which a discrete GPU makes a device copy (`WorkCounts::device_copy_textures`) -//! and every other device reads in place (no copy, printed). +//! after a write told to the log, and the pass stays one inline instance. So does a `Managed` +//! texture the pass only samples, which a discrete GPU makes a device copy +//! (`WorkCounts::device_copy_textures`) and every other device reads in place (no copy, printed). //! //! Device tests: compiled only under the validation crate's GPU safety cfgs (`m2v_gpu`, //! `m2v_cpu_icd`). The kernels are the owned fixture @@ -82,10 +82,10 @@ use super::blit_holds::{device, over_host, Host, Scratch, BYTES, WAIT}; use super::encoder_holds::{bytes_of, render_state}; use crate::{ - Buffer, ClearColor, CommandBufferStatus, ComputePipelineState, Device, DirtyPages, DirtyStamp, - Error, EventRef, HostMemory, Library, LoadAction, PipelineOptions, Region, - RenderPassDescriptor, ResourceOptions, ScissorRect, Size, StoreAction, Texture, - TextureDescriptor, + Buffer, ClearColor, CommandBufferStatus, ComputePipelineState, CpuCacheMode, Device, + DirtyPages, DirtyStamp, Error, EventRef, HazardTrackingMode, HostMemory, Library, LoadAction, + PipelineOptions, Region, RenderPassDescriptor, ResourceOptions, ScissorRect, Size, StorageMode, + StoreAction, Texture, TextureDescriptor, }; use metal2vulkan::metal::{PixelFormat, PrimitiveType, TextureUsage}; use std::num::NonZeroU64; @@ -215,12 +215,20 @@ fn delta(device: &Device, before: [u64; 5]) -> [u64; 5] { /// The buffer over `host`, its memory logged by `log`. fn over_logged(device: &Device, host: &Host, log: &Arc) -> Option { + over_logged_as(device, host, log, ResourceOptions::default()) +} + +/// [`over_logged`], of `options`. +fn over_logged_as( + device: &Device, + host: &Host, + log: &Arc, + options: ResourceOptions, +) -> Option { // SAFETY: the memory outlives the buffer (dropped after the device), and only the buffer's // commands and the test use it while it lives. let memory: HostMemory = unsafe { host.memory() }.with_dirty_pages(Arc::clone(log)); - let made = unsafe { - device.new_buffer_with_bytes_no_copy(memory, BYTES as u64, ResourceOptions::default(), None) - }; + let made = unsafe { device.new_buffer_with_bytes_no_copy(memory, BYTES as u64, options, None) }; match made { Ok(buffer) => Some(buffer), Err(Error::Unsupported(gap)) => { @@ -1309,23 +1317,34 @@ fn draw_sampled(device: &Device, source: &Texture, target: &Texture) { #[test] fn a_logged_shadow_sampled_in_an_inline_pass_is_copied_in_before_the_pass() { let usage = TextureUsage::SHADER_READ | TextureUsage::SHADER_WRITE; - sampled_in_an_inline_pass("dirty-pages-inline", usage); + let options = ResourceOptions::default(); + sampled_in_an_inline_pass("dirty-pages-inline", usage, options); } #[test] fn a_logged_device_copy_sampled_in_an_inline_pass_is_copied_in_before_the_pass() { - sampled_in_an_inline_pass("dirty-pages-inline-copy", TextureUsage::SHADER_READ); + let managed = ResourceOptions::new( + StorageMode::Managed, + CpuCacheMode::DefaultCache, + HazardTrackingMode::Default, + ); + sampled_in_an_inline_pass( + "dirty-pages-inline-copy", + TextureUsage::SHADER_READ, + managed, + ); } -/// A texture of `usage` over logged pages, sampled by a pass recorded inline, its copies in -/// before the pass (the module docs); nothing where the device reads it in place. -fn sampled_in_an_inline_pass(name: &str, usage: TextureUsage) { +/// A texture of `usage` over logged pages of a buffer of `options`, sampled by a pass recorded +/// inline, its copies in before the pass (the module docs); nothing where the device reads it in +/// place. +fn sampled_in_an_inline_pass(name: &str, usage: TextureUsage, options: ResourceOptions) { let scratch = Scratch::new(name); let host = Host::new(); let device = device(&scratch.0); eprintln!("DIRTY-PAGES: device {:?}", device.name()); let log = Arc::new(Log::default()); - let Some(buffer) = over_logged(&device, &host, &log) else { + let Some(buffer) = over_logged_as(&device, &host, &log, options) else { return; }; host.fill(0x4040_4040); @@ -1336,6 +1355,7 @@ fn sampled_in_an_inline_pass(name: &str, usage: TextureUsage) { let before = made(&device); let mut descriptor = TextureDescriptor::texture_2d(PixelFormat::RGBA8Unorm, SIDE, SIDE, false); descriptor.usage = usage; + descriptor.resource_options = options; let source = buffer.new_texture(&descriptor, 0, ROW).unwrap(); let [shadowed, copied] = std::array::from_fn(|i| made(&device)[i] - before[i]); eprintln!("DIRTY-PAGES: {usage:?}: {shadowed} shadow, {copied} device copy made"); diff --git a/crates/metal2vulkan-runtime/src/texture.rs b/crates/metal2vulkan-runtime/src/texture.rs index 6ce75d053..f407759bc 100644 --- a/crates/metal2vulkan-runtime/src/texture.rs +++ b/crates/metal2vulkan-runtime/src/texture.rs @@ -2236,12 +2236,13 @@ impl Device { None if texels.buffer.in_fresh_pages() => Some(PagesClass::Fresh), _ => None, }; - // On a discrete GPU, a texture that only samples or reads whose policy takes the image in - // place, over pages whose memory carries a log, is a device copy instead: a shadow whose - // copies in take only the rows the log reports changed (`dirty_pages.rs`), so the GPU - // reads the texels from its own memory, where in place it reads the pages across the bus - // at every sample. It binds no image to the pages, so the in-place check's verdict is not - // asked. One that renders works on the pages in place, as a discrete Mac's GPU does. + // On a discrete GPU, a `Managed` texture over a buffer's bytes that only samples or reads + // whose policy takes the image in place, over pages whose memory carries a log, is a + // device copy instead (`Texels::device_copy`): a shadow whose copies in take only the + // rows the log reports changed (`dirty_pages.rs`), the GPU's copy of the two a `Managed` + // resource is on a Mac with a discrete GPU. It binds no image to the pages, so the + // in-place check's verdict is not asked. A `Shared` texture, an IOSurface's, and one that + // renders work on the pages in place, across the bus, as such a Mac's GPU does. // Texels past the buffer's length lie in no image over its memory: the shadow's copies go // through the texture's tail (`buffer_texture.rs`). let past = texels.past().is_some(); diff --git a/crates/metal2vulkan-runtime/src/work_counts.rs b/crates/metal2vulkan-runtime/src/work_counts.rs index 854c8d31d..36d9a5d7d 100644 --- a/crates/metal2vulkan-runtime/src/work_counts.rs +++ b/crates/metal2vulkan-runtime/src/work_counts.rs @@ -5865,11 +5865,13 @@ pub struct WorkCounts { /// (`HostPageTexturePolicy::InPlace`): no shadow, and no copy in or back. One that renders /// whose image took feedback loop usage is also counted in `feedback_loop_alias_images`. pub host_textures_in_place: u64, - /// Textures over host pages that `host_textures_in_place` would count (or a shadow made - /// before the check answered or where it failed), made instead a copy in the device's memory - /// on a discrete GPU, where their memory carries a log of its writes - /// (`HostMemory::with_dirty_pages`): a shadow whose copies in take only the rows the log - /// reports changed (`dirty_copies_in_gated` and kin), announced nowhere. + /// `Managed` textures over a buffer's host pages (not an IOSurface's) that only sample or + /// read, which `host_textures_in_place` would count (or a shadow made before the check + /// answered or where it failed), made instead a copy in the device's memory on a discrete + /// GPU, where their memory carries a log of its writes (`HostMemory::with_dirty_pages`): the + /// GPU's copy of the two a `Managed` resource is on a Mac with a discrete GPU, a shadow whose + /// copies in take only the rows the log reports changed (`dirty_copies_in_gated` and kin), + /// announced nowhere. A `Shared` texture and an IOSurface's are in place over the pages. pub device_copy_textures: u64, /// Of `host_textures_in_place`, those over pages imported as dma-bufs: each a /// `DRM_FORMAT_MOD_LINEAR` image over a dma-buf of its own pages (also counted in diff --git a/crates/metal2vulkan-validation/src/runtime_lane/device_copies.rs b/crates/metal2vulkan-validation/src/runtime_lane/device_copies.rs index e9269e884..6d2683cf4 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/device_copies.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/device_copies.rs @@ -1,12 +1,13 @@ -//! Device tests of device copies on the device the cfg selects: on a discrete GPU, a texture that -//! would read host pages in place, over a no-copy buffer whose memory carries a log of its writes -//! (`HostMemory::with_dirty_pages`), is a shadow in the device's memory whose copies in take only -//! the rows the log reports changed (the runtime's `dirty_pages.rs`); on any other device, and -//! without a log, it is placed as before. +//! Device tests of device copies on the device the cfg selects: on a discrete GPU, a `Managed` +//! texture that would read host pages in place, over a no-copy buffer whose memory carries a log +//! of its writes (`HostMemory::with_dirty_pages`), is a shadow in the device's memory whose copies +//! in take only the rows the log reports changed (the runtime's `dirty_pages.rs`): the GPU's copy +//! of the two a `Managed` resource is on a Mac with a discrete GPU. A `Shared` texture there, any +//! texture on any other device, and one without a log, is placed as before. //! //! - [`a_sampled_surface_over_logged_pages_follows_the_guest_s_writes`], under the validation -//! layer: a 1920x1080 `BGRA8Unorm` surface over logged pages, read whole each frame by a -//! fragment function into a private target, which then holds the pages' texels after each +//! layer: a 1920x1080 `BGRA8Unorm` `Managed` surface over logged pages, read whole each frame by +//! a fragment function into a private target, which then holds the pages' texels after each //! frame's CPU write of a run of a row. On a discrete GPU it is a device copy //! (`device_copy_textures`, no `vk_image`): its first copy in moves every row, each later one //! only the rows the log reported (`dirty_copies_in_gated`, `dirty_copy_in_bytes_copied`), one @@ -17,24 +18,29 @@ //! (on a discrete GPU a whole copy in: the fill let go of the copy's hold). //! - [`without_a_log_the_surface_is_placed_as_before`], under the validation layer: the same //! surface over pages without a log is no device copy. +//! - [`a_shared_surface_over_logged_pages_is_no_device_copy`], under the validation layer: a +//! `Shared` surface over logged pages is no device copy on any device, in place where the +//! device's check passed for pointer pages (on a discrete GPU, read across the bus as a +//! discrete Mac's GPU reads a `Shared` texture), its reads the pages' texels. //! - [`device_copy_costs`], without the validation layer, report only (built in release for the -//! numbers): a 3840x2160 `BGRA8Unorm` surface read whole each frame, with a few CPU-written +//! numbers): a 3840x2160 `BGRA8Unorm` `Managed` surface read whole each frame, with a few CPU-written //! runs a frame, in one pass and in three, over pages without a log (in place where the check //! passed) and with one (a device copy on a discrete GPU): the median and fastest GPU time of a //! frame's command buffer (`DEVICE-COPY-COST`). use super::first_use_writes::CHECK_WAIT; use super::host_memory::{counting, Mapping, GUEST_PAGE}; -use super::in_place_textures::{in_place, sampled}; +use super::in_place_textures::{in_place, passed, sampled}; use super::no_copy_textures::{floats, staged}; use super::pitched_surfaces::reading; use super::{layer_reported_nothing_at_all, validated_device_with, Messages, ScratchCache, WAIT}; use crate::gpu::TEST_DEVICE; use metal2vulkan::metal::{PixelFormat, PrimitiveType, TextureUsage}; use metal2vulkan_runtime::{ - BlitOption, Buffer, CommandQueue, Device, DeviceKind, DirtyPages, DirtyStamp, HostMemory, - LoadAction, Origin, RenderPassDescriptor, RenderPipelineState, ResourceOptions, ScissorRect, - Size, StoreAction, Texture, TextureDescriptor, WorkCounts, + BlitOption, Buffer, CommandQueue, CpuCacheMode, Device, DeviceKind, DirtyPages, DirtyStamp, + HazardTrackingMode, HostMemory, LoadAction, Origin, RenderPassDescriptor, RenderPipelineState, + ResourceOptions, ScissorRect, Size, StorageMode, StoreAction, Texture, TextureDescriptor, + WorkCounts, }; use std::ops::Range; use std::sync::{Arc, Mutex}; @@ -104,9 +110,30 @@ impl DirtyPages for Log { } } -/// A no-copy buffer over `mapping`'s `len` bytes on `device`, its memory carrying `log` where -/// given. +/// `Managed` storage, the other modes at their defaults: the storage whose textures a discrete GPU +/// makes device copies. +fn managed() -> ResourceOptions { + ResourceOptions::new( + StorageMode::Managed, + CpuCacheMode::DefaultCache, + HazardTrackingMode::Default, + ) +} + +/// A no-copy `Managed` buffer over `mapping`'s `len` bytes on `device`, its memory carrying `log` +/// where given. fn over(device: &Device, mapping: &Mapping, len: usize, log: Option<&Arc>) -> Buffer { + over_as(device, mapping, len, log, managed()) +} + +/// [`over`], of `options`. +fn over_as( + device: &Device, + mapping: &Mapping, + len: usize, + log: Option<&Arc>, + options: ResourceOptions, +) -> Buffer { // SAFETY: the mapping outlives the buffer (dropped first by every caller), and stays // writable. let memory = unsafe { HostMemory::new(mapping.pointer()) }; @@ -115,10 +142,7 @@ fn over(device: &Device, mapping: &Mapping, len: usize, log: Option<&Arc>) None => memory, }; // SAFETY: as above. - unsafe { - device.new_buffer_with_bytes_no_copy(memory, len as u64, ResourceOptions::default(), None) - } - .unwrap() + unsafe { device.new_buffer_with_bytes_no_copy(memory, len as u64, options, None) }.unwrap() } /// One frame's command buffer on `queue`: `passes` passes, each reading the top `rows` rows of @@ -411,6 +435,86 @@ fn without_a_log_the_surface_is_placed_as_before() { layer_reported_nothing_at_all(&messages); } +#[test] +fn a_shared_surface_over_logged_pages_is_no_device_copy() { + let cache = ScratchCache::new().unwrap(); + let messages = Messages::default(); + let device = validated_device_with(TEST_DEVICE, &messages, cache.path(), in_place).unwrap(); + let queue = device.new_command_queue().unwrap(); + let reads = reading(&device, PixelFormat::BGRA8Unorm, "tob_read"); + let corners = staged(&device, &floats([-1.0, -1.0, 1.0, 1.0])); + let (w, h, bpr) = (256u64, 256u64, 1024u64); + let len = ((bpr * h) as usize).next_multiple_of(GUEST_PAGE); + // A texture over host pages starts the device's in-place check, which the one measured then + // follows. + { + let mapping = Mapping::anonymous(GUEST_PAGE); + let buffer = over_as( + &device, + &mapping, + GUEST_PAGE, + None, + ResourceOptions::shared(), + ); + drop(sampled(&buffer, PixelFormat::BGRA8Unorm, (16, 16, 64))); + assert!( + device.settle_in_place_checks(CHECK_WAIT), + "the check answered" + ); + } + let mapping = Mapping::anonymous(len); + mapping.write(0, &counting(len, 7)); + let log = Arc::new(Log::default()); + let before = device.work_counts(); + let buffer = over_as( + &device, + &mapping, + len, + Some(&log), + ResourceOptions::shared(), + ); + let texture = sampled(&buffer, PixelFormat::BGRA8Unorm, (w, h, bpr)); + let after = device.work_counts(); + // SAFETY: the handle is only compared. + let in_place = unsafe { texture.vk_image() }.is_some(); + let pointer = passed(&device, "Pointer"); + eprintln!( + "DEVICE-COPY on {} ({:?}): a Shared surface over logged pages: device copy {}, in place \ + {in_place}, in places {}, the check passed for pointer pages {pointer}", + device.name(), + device.properties().kind, + copied(&before, &after)[0], + after.host_textures_in_place - before.host_textures_in_place, + ); + assert_eq!( + copied(&before, &after)[0], + 0, + "no device copy of a Shared texture" + ); + assert_eq!(in_place, pointer, "in place where the check passed"); + let target = target_of(&device, (w, h)); + let objects = (&reads, &corners); + frame(&queue, objects, (&texture, &target), (w, h), 1); + let read = texels(&queue, &target, (w, h)); + assert!( + read == guest_texels(&mapping, (w, h, bpr)), + "the pages' texels" + ); + // A logged CPU write of a run of row 9 reaches the next frame. + let offset = 9 * bpr + 64; + mapping.write(offset as usize, &[0xc3; 64]); + log.mark(offset..offset + 64); + frame(&queue, objects, (&texture, &target), (w, h), 1); + let read = texels(&queue, &target, (w, h)); + assert!( + read == guest_texels(&mapping, (w, h, bpr)), + "the write's texels" + ); + drop((texture, buffer, target)); + drop(mapping); + layer_reported_nothing_at_all(&messages); +} + #[test] fn device_copy_costs() { const FRAMES: usize = 40; diff --git a/crates/metal2vulkan-validation/src/runtime_lane/shadow_sync_costs.rs b/crates/metal2vulkan-validation/src/runtime_lane/shadow_sync_costs.rs index 5cb964e10..4206849af 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/shadow_sync_costs.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/shadow_sync_costs.rs @@ -25,7 +25,7 @@ //! - `WriteUnscissored`: the same rectangle drawn with no scissor. //! - `WriteReadApart`: as `Write`, the read through a second texture of the plane whose usage only //! samples it (as another process's texture over the same surface): in place where the -//! device's check passed, a device copy on a discrete GPU over logged pages. +//! device's check passed, on a discrete GPU too (an IOSurface's texture takes no device copy). //! - `WriteThenReadApart`: as `WriteReadApart`, the write and the read in two command buffers one //! after the other (one process's pass into its window, then the compositor's read of it). //! - `Rewrite`: as `Write`, the same color every frame: the GPU writes and no word changes. diff --git a/docs/API.md b/docs/API.md index 2756f3102..5aeb6d6c5 100644 --- a/docs/API.md +++ b/docs/API.md @@ -359,12 +359,15 @@ before a use and back (merged back: only the bytes the commands changed) after a is bound to the pages, and `Texture::vk_image` gives `None` for it. A texture in place renders and is written beyond its declared usage, as plain Metal allows, through its usage shadow and an attachment stand-in, whose copies touch its texels alone. -On a discrete GPU, a texture that only samples or reads whose policy takes the image in place, over -a no-copy buffer whose memory carries a log of its writes (`HostMemory::with_dirty_pages`), -tracked, one slice laid out as one copy, is instead a device copy (`WorkCounts::device_copy_textures`, -whatever the check answered): a shadow whose copies in take only the bands of rows the log reports changed -(`dirty_copies_in_gated` and kin). Its notice is not announced: it holds the bytes wherever a -command reads it. +On a discrete GPU, a `Managed` texture over a no-copy buffer's bytes (not an IOSurface plane's) +that only samples or reads, whose policy takes the image in place, over memory that carries a log +of its writes (`HostMemory::with_dirty_pages`), tracked, one slice laid out as one copy, is instead +a device copy (`WorkCounts::device_copy_textures`, whatever the check answered): the GPU's copy of +the two a `Managed` resource is on a Mac with a discrete GPU, a shadow whose copies in take only +the bands of rows the log reports changed (`dirty_copies_in_gated` and kin). Its notice is not +announced: it holds the bytes wherever a command reads it. A `Shared` texture and an IOSurface's +are the pages' alone there too, in place where the check passed, which the GPU reads across the +bus as a discrete Mac's GPU reads them. A texture placed in a heap over dma-buf pages is an image over a dma-buf of its own pages, which its first submission acquires from `VK_QUEUE_FAMILY_FOREIGN_EXT`; a linear image over a buffer of the runtime's own memory starts `VK_IMAGE_LAYOUT_PREINITIALIZED`, and its move from there keeps its diff --git a/docs/FAST-PATHS.md b/docs/FAST-PATHS.md index a758a6614..1f4b31721 100644 --- a/docs/FAST-PATHS.md +++ b/docs/FAST-PATHS.md @@ -38,7 +38,7 @@ three consumer pipelines: A2X (`a2x-s4`, `a2x-s96`), Xgc14 (`xgc14-bgra8`) and X | 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) | | 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), 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`. 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, round robin, 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 or renders into it and does not write it through a shader (no `ShaderWrite` or `ShaderAtomic` usage) 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) 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, checked apart. 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: the GPU works on the caller's pages in place as a Mac's does, whatever a linear image costs it; `in_place.rs`). 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 and access, on a thread of its own, its verdicts kept in the shader cache's directory; a texture made before its verdict waits for it as it is made, up to `in_place::VERDICT_WAIT` (5 s), and past that is a shadow. A texture whose usage writes through a shader, 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 counted apart in `host_texture_shadows_render_target`). | `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; a resolve into it is not among the rounds); a driver whose operations changed a byte outside every round's window would undo a CPU write made meanwhile. 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 | +| A texture that samples, reads or renders into it and does not write it through a shader (no `ShaderWrite` or `ShaderAtomic` usage) 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) 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, checked apart. 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: the GPU works on the caller's pages in place as a Mac's does, whatever a linear image costs it; `in_place.rs`). 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 and access, on a thread of its own, its verdicts kept in the shader cache's directory; a texture made before its verdict waits for it as it is made, up to `in_place::VERDICT_WAIT` (5 s), and past that is a shadow. A texture whose usage writes through a shader, 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 counted apart in `host_texture_shadows_render_target`). 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` texture over a no-copy buffer's bytes 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; a resolve into it is not among the rounds); a driver whose operations changed a byte outside every round's window would undo a CPU write made meanwhile. 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 | | A render or compute state's creation hands the driver's making of its predicted pipeline (`pipeline/predicted.rs`, `pipeline/dispatch_making.rs`) to the runtime's pool, kept by the state as a draw's or dispatch's making is, and waits for it `pipeline_creation_wait` at most; a committed command buffer's recordings wait until its commit plus `pipeline_commit_wait` at most, one deadline its commands share, for its draws' and dispatches' (a compute encoder's, a render pass's tile dispatches) pipelines still being made (the scheduler wakes at the bound, `StepWaits::until`), an execution's replayed draws (`render/pending.rs`) among them, whose pipelines the commit's settle hands to the pool (a device replay's, one recording for every command, waits until made under either value), then record each such command as nothing: a draw's barriers and visibility query, a dispatch's barrier (a tile dispatch's copies into its scratch and back), no draw or dispatch, the command buffer running on without error. The making goes on, and the command buffers after it draw and dispatch with the pipeline once made. Metal compiles inside `newRenderPipelineState`, so no draw of a made state waits or is dropped; a host that creates a state inside a command buffer's encoding (the consumer creates a guest's state at an execution's first lookup of it) held that execution through the driver's whole compile: 11.59 s inside one execution on an M2 Pro (MoltenVK 1.4.2, a cold Metal compiler service; a sample of such a stall finds the compile's thread waiting in `MVKMetalCompiler::compile` for Metal's compiler), past the guest's 10 s FIFO check, which ended the guest's task. Each bound is 4.5 s: a creation and a commit may fall in one step of the guest's FIFO (a task's jobs run one after another, and a draw's own variant waits under its command buffer's bound), and no runtime call waits for both, so one step waits 9 s at most for makings, under that 10 s check. A creation waits on no command buffer's deadline and a `commit` on no creation's; a `commit` waits until its own deadline at most (it records there what it can, an execution of render commands the CPU writes among them), every other recording on the scheduler's thread, a host step's on one of the steps' threads. Made until made under either value, in the call that makes them: a draw that records nothing, one in a pass of custom sample positions and one recorded again into another instance of its pass (each in the draw's call or an execution's replay), a device replay's draws (in its `commit`), and a failed making made again (`PipelineWaitPolicy`'s docs). The runtime's: no pipeline differs. | `pipeline_waits = PipelineWaitPolicy::Bounded`, `pipeline_creation_wait = 4.5 s`, `pipeline_commit_wait = 4.5 s` | `pipeline_waits = PipelineWaitPolicy::Exact`: the creation makes its predicted pipeline before it returns (a render state's first key on its own thread, the rest on the pool, joined; a compute state's on its own thread), an execution's settle makes its replayed draws' pipelines at the commit, and a command buffer waits for each draw's and dispatch's pipeline until it is made | A draw whose pipeline was still being made `pipeline_commit_wait` after its command buffer's commit renders nothing in that command buffer (only there: later ones draw it), where Metal's renders: content drawn once (a layer, a glyph cache) stays without it until redrawn. A creation returns after `pipeline_creation_wait` at most with its making in flight (`WorkCounts::creations_left_making`). `DrawDroppedStillMaking` (`draw-dropped-still-making`), at each such draw where `DeviceOptions::announce_each` asks, else once per device; `CommandBuffer::dropped_draw` names the first with `VK_TIMEOUT`; `WorkCounts::draws_dropped_still_making`; `deferred_calls::a_draw_whose_pipeline_is_still_being_made_at_its_bound_runs_nothing` and `under_the_exact_wait_a_held_making_holds_its_command_buffer_until_it_lands`. A dispatch whose pipeline was still being made then writes nothing in that command buffer, where Metal's runs: `DispatchDroppedStillMaking` (`dispatch-dropped-still-making`), `WorkCounts::dispatches_dropped_still_making`, the first named by `dropped_draw`; `deferred_calls::a_dispatch_whose_pipeline_is_still_being_made_at_its_bound_runs_nothing`, `a_compute_state_s_creation_waits_its_bound_for_its_predicted_making` and `a_replayed_draw_whose_pipeline_is_still_being_made_at_its_bound_runs_nothing` | No GPU cost. The exact form holds the creating thread, and the command buffer, for the whole compile: up to 11.59 s on the M2 Pro's cold boot (that boot's 2,483 render state creations, translation included: 300 over 16 ms, 151 over 100 ms, 14 over 250 ms, 3 over 1 s, the longest 11.59 s, 5.82 s and 1.17 s), where the default holds a creation for 4.5 s at most and a command buffer for 4.5 s from its commit, which drops the draws of the compiles that outlast those (2 of that boot's 2,483 were over 4.5 s) for the command buffers committed before they land; bounds of 1 s dropped 39 draws in a cold boot on the M2 Pro, and the guest's menu bar, drawn once, stayed half drawn | | A line Apple's `setLineWidth:` widens (`w' = floor(16 w) / 16`, other than 1), and a triangle's edge in fill mode `Lines`, is drawn by the device's own lines at `w'` wherever it draws that width (`wideLines`, `w'` in `lineWidthRange` and above 0), where Metal draws the parallelogram Vulkan's non-strict wide lines may be (`render/line_width.rs`). They are exactly it on a non-strict device whose wide lines are parallelograms (`strictLines` unset, `nonStrictWideLinesUseParallelogram` set) at a width above 1 on its `lineWidthGranularity`, unannounced there; elsewhere they differ: a strict device's rectangle with square ends (lavapipe, NVIDIA), lines Vulkan does not state as parallelograms (ANV, and every width below 1), a width rounded to the granularity. A mesh draw's lines and edges and a tessellated patch draw's edges take the device's lines under either value, the band not drawing them (at the nearest width they draw where they do not draw `w'`, announced `lines-at-nearest-width`: a known gap below). The runtime's: no pipeline's code differs. | `wide_lines = WideLinePolicy::Device` | `wide_lines = WideLinePolicy::Exact`: a draw of lines or edges the device's lines draw otherwise than Metal is the pipeline's band variant (`VariantKey::line_band`, `pipeline::link::band`) on a device with `tessellationShader` (the device's lines where it has none, or where the translator refuses the state's band or the draw's): two triangles over each line's parallelogram, and each triangle's three edges' parallelograms facing as the triangle, through a tessellation control and evaluation stage; every other width other than 1 is the band under either value | The lines can cover pixels the parallelogram does not, and miss others, at each end and along each edge: up to half the width past each end (square ends), and a rounded width. `DeviceWideLines` (`device-wide-lines`), at each such draw where `DeviceOptions::announce_each` asks, else once per device; `WorkCounts::device_wide_line_draws`, `line_band_draws`, `nearest_width_line_draws`; `runtime_lane::line_widths` (the band matches Metal's maps of lines and of triangles' edges, their facing, culling, flat inputs, primitive IDs and depth on MoltenVK under both values, which has no `wideLines`; a band of edges under a depth bias is announced `wide-edge-depth-bias`) | Not measured. Expected from the band's form: a second pipeline variant made for each render state that draws such lines or edges (its two synthesized stages), each line tessellated as a patch of two control points into four corners and each triangle as a patch of three into 21 triangles (12 degenerate), and a strip, loop or fan drawn as the list of its primitives | | A blit or fill through a `BGRA10_XR` or `BGRA10_XR_sRGB` texture Metal keeps losslessly compressed (`allowGPUOptimizedContents`, 16 texels or more a side, neither `ShaderWrite` nor `PixelFormatView` usage, one sample, not over a buffer) is the device's copy, which keeps the bytes it moves, on every device: Metal's GPU blit into, out of or between such textures moves the texels through its compression, which writes each 16-bit field's low six bits cleared and the alpha code clamped to `[384, 894]`, and its fill clears the low six bits alone (an Apple M3 Max under macOS 27.0.1, every direction, storage mode, usage and size that decides the compression; CPU copies keep the bytes on Metal too). A pass's draws through such an attachment are the device-gap row below. The runtime's choice: no pipeline differs (`compressed_blit.rs`). | `extended_range_blits = ExtendedRangeBlitPolicy::Kept` | `extended_range_blits = ExtendedRangeBlitPolicy::Canonical`: after a blit writes such a texture's region, or a blit out of one writes a buffer's words, a texture over a buffer's or another texture's, a compute dispatch (`bind::extended_canonical_module`, `extended_canonical.rs`) rewrites the texels it wrote in Metal's encoding: in place in a buffer's bytes, an image's through a scratch buffer, a copy out and back around the dispatch; a fill's texel is encoded before it is written. A buffer whose words the device cannot bind (an offset or pitch off 4 bytes, a region past `maxStorageBufferRange`) and a texture over a buffer whose rows share bytes keep the bytes under either value, announced | Bytes no Metal write left (uploaded, CPU-copied or kernel-written texels: a field's low six bits, an alpha code outside `[384, 894]`) keep what Metal's blit would rewrite; a texel reads the same value either way, its low six bits unread and its alpha read clamped. `ExtendedRangeBitsKept` (`extended-range-bits-kept`), once per device; under `Canonical` not for the blits it makes exact; `runtime_lane::compressed_blits` (both values on MoltenVK), the conformance cases `compressed-blits-bgra10xr` and `compressed-blits-bgra10xr-srgb` | Measured, `Canonical` against `Kept`, on `Private` `BGRA10_XR` textures Metal keeps compressed (the sRGB twin and fills not measured), 256x256 and 2048x2048, one whole-texture blit a command buffer: p50 of 300 blits a run, the two values interleaved in one process, three runs a host. RTX 5080 Laptop (NVIDIA 615.71.09, the command buffer's GPU time): a buffer into the texture 23.5 against 11.5 us and 761 against 244 us from a `Private` buffer, 42 against 30 us and 1,945 against 1,176 us from a `Shared` one; the texture into a `Private` buffer 14.1 against 11.2 us and 287 against 246 us, into a `Shared` one, whose words the dispatch rewrites in system memory, 66 against 27 us and 3,386 against 1,182 us; texture into texture 22.5 against 9.7 us and 630 against 80 us. Apple M3 Max (MoltenVK 1.4.2, whose GPU times are the host's, so per blit of 16 in one command buffer), the same blits: into the texture +38 to +57 us and +536 to +548 us, out of it into a buffer +15 us and +84 to +94 us, texture into texture +46 to +48 us and +535 to +541 us. Every figure is above its `Kept` one in every run, by more than the runs' spread (under 1 us on the 5080): measurable at both sizes on both hosts. Into an image a blit adds a copy out into a scratch buffer of the region's size, the dispatch, a copy back and the barriers between them; into a buffer the dispatch and a barrier. The scratch is made without zeros, since the copy out writes every byte the dispatch and the copy back read; the figures above were taken while it was zeroed first, by a command buffer of its own (a fill on the 5080, a copy on MoltenVK). CPU from the command buffer's making through its commit, a blit alone: +1 to +3 us on the M3 Max, +1 to +127 us on the 5080, whose host other builds loaded; 16 blits into 2048x2048 images in one command buffer hold 16 scratch buffers of 32 MiB, and encoding each costs 141 to 165 us (5080) and 286 to 356 us (M3 Max), new memory blocks among it, against 2 to 6 us under `Kept`. Nothing for a texture Metal keeps uncompressed or of another format |