From dae9923446ae439e424e169e1ebf37b15dca925c Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Sun, 8 Nov 2026 13:26:47 -0800 Subject: [PATCH] Heap refit docs: which textures an image in place serves, and what the shadows of Metal's tiles cost HeapTextureHostTransfer and HeapTextureLinear (and docs/API.md's catalogue) say the refit takes an image of host-transfer usage only for a texture Metal compresses or whose layout is not modelled, and of one Metal keeps uncompressed only a linear image whose every element lies where Metal's tiles place it. docs/FAST-PATHS.md's costs record the shadow of Metal's tiles kept for every other such texture, with the 1x1 shadow's GPU time measured on the Iris Xe at RUNTIME_VERSION 1909 (35.9 us against 8.1 us a frame); the compositor's 3x3 to 10x10 shapes are not measured apart. (cherry picked from commit dc30f3c6c8768ab3780bad861bba9db1ad9f4b84) --- crates/metal2vulkan-runtime/src/degradation.rs | 11 +++++++---- docs/API.md | 11 +++++++---- docs/FAST-PATHS.md | 16 ++++++++++++++++ 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/crates/metal2vulkan-runtime/src/degradation.rs b/crates/metal2vulkan-runtime/src/degradation.rs index e59680414..08a026f13 100644 --- a/crates/metal2vulkan-runtime/src/degradation.rs +++ b/crates/metal2vulkan-runtime/src/degradation.rs @@ -978,9 +978,10 @@ degradations! { /// ([`metal2vulkan::device::DriverFact::CompressedImagesHideAliasedWrites`]), whose image /// takes host-transfer usage, which the driver keeps uncompressed in the heap's bytes /// ([`metal2vulkan::device::DriverFact::HostTransferImagesKeepTheirBytes`]). Also, on any - /// device, a single-sample colour texture whose image of the route it first took takes - /// more bytes or a coarser alignment than Metal's answer, where this one fits the answer: - /// it lies in the heap's bytes in place of a shadow of them (`texture/heap.rs`). + /// device, a single-sample colour texture Metal keeps compressed, or whose layout Metal's + /// model does not state, whose image of the route it first took takes more bytes or a + /// coarser alignment than Metal's answer, where this one fits the answer: it lies in the + /// heap's bytes in place of a shadow of them (`texture/heap.rs`). HeapTextureHostTransfer = "heap-texture-host-transfer", Performance, "the texture's image is kept uncompressed, so writes through the heap's buffers and \ textures over its bytes show in it as Metal's do: a clear of it loses the driver's \ @@ -993,7 +994,9 @@ degradations! { /// texture whose image of the route it first took takes more bytes or a coarser /// alignment than Metal's answer, where no image of host-transfer usage fits the answer /// and a linear one does: it lies in the heap's bytes in place of a shadow of them - /// (`texture/heap.rs`). + /// (`texture/heap.rs`). Of a texture Metal keeps uncompressed, whose bytes are Metal's + /// tiles, only a linear image whose every element lies where those tiles place it (a + /// level of one element or one row), and no image of host-transfer usage. HeapTextureLinear = "heap-texture-linear", Performance, "the texture's image is linear, so writes through the heap's buffers and textures \ over its bytes show in it as Metal's do: its reads and writes go without the \ diff --git a/docs/API.md b/docs/API.md index 28947e5c5..1e698a587 100644 --- a/docs/API.md +++ b/docs/API.md @@ -2293,9 +2293,10 @@ bound. alias (`DriverFact::CompressedImagesHideAliasedWrites`), whose image takes host-transfer usage, which the driver keeps uncompressed in the heap's bytes (`metal2vulkan::device::DriverFact::HostTransferImagesKeepTheirBytes`). Also, on any device, a - single-sample colour texture whose first image takes more bytes or a coarser alignment of the - heap than Metal's answer, where this one fits the answer: it lies in the heap's bytes in place of - a shadow of them. Cost: the texture's image + single-sample colour texture Metal keeps compressed, or whose layout Metal's model does not state, + whose first image takes more bytes or a coarser alignment of the heap than Metal's answer, where + this one fits the answer: it lies in the heap's bytes in place of a shadow of them. Cost: the + texture's image is kept uncompressed, so writes through the heap's buffers and textures over its bytes show in it as Metal's do: a clear of it loses the driver's fast clear (334.5 us where a compressed 2048x2048 RGBA8Unorm image's took 4.1 us on an RPL-S), while its copies, sampling and blending @@ -2307,7 +2308,9 @@ bound. optimal image does for the texture. Also, on any device, a single-sample colour texture whose first image takes more bytes or a coarser alignment of the heap than Metal's answer, where no image of host-transfer usage fits the answer and a linear one does: it lies in the heap's bytes - in place of a shadow of them. Cost: the texture's image is linear, so writes through the + in place of a shadow of them. Of a texture Metal keeps uncompressed, whose bytes are Metal's + tiles, only a linear image whose every element lies where those tiles place it (a level of one + element or one row), and no image of host-transfer usage. Cost: the texture's image is linear, so writes through the heap's buffers and textures over its bytes show in it as Metal's do: its reads and writes go without the optimal tiling's locality and compression (3.9 to 9.6 times the host-transfer image's time for copies, clears and draws of a 2048x2048 RGBA8Unorm texture on an RPL-S). diff --git a/docs/FAST-PATHS.md b/docs/FAST-PATHS.md index 41a1c9dd8..4b601d657 100644 --- a/docs/FAST-PATHS.md +++ b/docs/FAST-PATHS.md @@ -348,6 +348,22 @@ recorded here. theirs on every device. On MoltenVK on Apple's GPUs, which drops the barrier and whose such draws race under load (`DriverFact::InterlockedDrawsRaceUnderLoad`), the later draw begins a render pass instance of its own instead (a known gap below). +- **A heap texture Metal keeps uncompressed is a shadow of Metal's tiles where no image in place + lays its elements there.** Metal lays such a texture's bytes out in its tiles + (`texture/heap_tiled.rs`). Where the device's image of it takes more of the heap than Metal's + answer, an image that fits takes its place in the heap's bytes where Metal compresses the + texture (its bytes are no layout of its texels) or its layout is not modelled + (`heap-texture-host-transfer`, `heap-texture-linear`); of a texture Metal keeps uncompressed, + only a linear image whose every element lies where Metal's tiles place it does, announced with + no layout (a level of one element or one row: a 1x1 texture, a one-level 1D one; + `texture/heap.rs`, `rows_lie_in_metal_tiles`). Every other such texture is a shadow of Metal's + tiles (`shadowed-texture`). On ANV (Iris Xe of RPL-P, Mesa 26.2.6), of the shapes a guest's + compositor made in its heaps (`runtime_lane::heap_shadow_costs`), those are the `RGBA16Float` + arrays of 3x3 to 10x10; the ones Metal compresses and the 1x1 lie in place. A 1x1 one + measured as a shadow there took 35.9 µs of GPU time a frame that clears it in a pass and + blits it, against 8.1 µs in place and 12.1 µs outside a heap, and 16.9 µs a frame that only + blits it, against 3.7 and 3.9 (`heap_shadow_costs`); the shapes from 3x3 to 10x10 are not + measured apart. - **A shadow over bytes another writer may write is merged back, not copied back.** Metal writes only the texels a command writes, and another writer writing bytes no command touches while a command buffer runs is valid under its contract. On an M3 Max under macOS 27.0.1, a CPU write to