From 03db73b32ce4bb6d07e9aac8cbc1bc326f76ec7e Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Tue, 3 Nov 2026 18:04:13 -0800 Subject: [PATCH] Count a block texture's CPU copies on a staging-queue device as that queue makes them `block_cpu_copies_stage_their_writes_and_read_where_the_device_copies_on_the_host` had arms for a device that copies blocks on the host and for one that serves reads from a host shadow, and none for a device with a staging queue, whose block textures take neither: it failed on the RTX 5080 Laptop GPU before the staging queue's copies were queued (4bbafa667d: writes 0/4/0, reads 0/4/0, three runs of three) and after (writes 0/0/0, reads 0/4/0). The new arm holds what the queued copies give there: no write makes a submission, and each read makes one on the staging queue, which carries the write queued before it. Also rewraps two doc paragraphs of the staging copies' past 100 columns. Verified: on the RTX 5080 Laptop GPU the test passes 3 of 3 runs (writes 0/0/0, reads 0/4/0); on the M3 Max (no staging queue, the shadow arm) it passes among 64 runtime tests (posted_frees, freed_memory, teardown_threads, cpu_copy_layouts, event). (cherry picked from commit 7649ad0d7d4a60987b1783354023aee629cf7505) --- .../src/tests/cpu_copy_layouts.rs | 34 +++++++++++++------ .../src/texture/first_move.rs | 11 +++--- .../src/texture/staging_copy.rs | 6 ++-- 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/crates/metal2vulkan-runtime/src/tests/cpu_copy_layouts.rs b/crates/metal2vulkan-runtime/src/tests/cpu_copy_layouts.rs index 6ef855723..fb1ad5ba4 100644 --- a/crates/metal2vulkan-runtime/src/tests/cpu_copy_layouts.rs +++ b/crates/metal2vulkan-runtime/src/tests/cpu_copy_layouts.rs @@ -276,11 +276,14 @@ fn two_plane_cpu_copies_wait_for_no_submission_where_a_textures_do() { } /// A block-compressed texture's `replaceRegion` waits for no submission on any device: the copy /// is staged for the device's next submission (`texture/first_move.rs`) where the image takes no -/// host copies, and runs on the host where it does. Its `getBytes` waits for none either where -/// the device copies such an image's blocks on the host, and for one between all of them where a -/// driver that copies a host-transfer image out of its memory as the memory is bound takes block -/// formats off that path (`RuntimeDriverDefect::HostTransferImagesCopiedAtBind`, MoltenVK): the -/// first read makes a host shadow of the image's texels and every read after it comes out of that +/// host copies, queued for the staging queue's next submission where the image copies there +/// (`texture/staging_copy.rs`), and runs on the host where it does. Its `getBytes` waits for none +/// either where the device copies such an image's blocks on the host; for one each on the +/// staging queue, which carries the copies queued before it, where the image copies there; and +/// for one between all of them where a driver that copies a host-transfer image out of its memory +/// as the memory is bound takes block formats off that path +/// (`RuntimeDriverDefect::HostTransferImagesCopiedAtBind`, MoltenVK): the first read makes a host +/// shadow of the image's texels and every read after it comes out of that /// (`texture/host_shadow.rs`, whose own tests hold the shadow's rules). /// /// The levels here are small and few, so the staged copies stay under the bound past which a @@ -340,17 +343,26 @@ fn block_cpu_copies_stage_their_writes_and_read_where_the_device_copies_on_the_h waited, 0, "a block-compressed texture's `replaceRegion` waited for an internal submission" ); - // Where the device reads such an image's blocks on the host, so does `getBytes`; elsewhere - // the levels' reads share the one submission the first of them makes its shadow by. - match read_host > 0 { - true => assert_eq!( + // Where the device reads such an image's blocks on the host, so does `getBytes`; where it + // copies on its staging queue, each write is queued there and each read's submission carries + // the write before it; elsewhere the levels' reads share the one submission the first of them + // makes its shadow by. + match (read_host > 0, device.has_staging_queue()) { + (true, _) => assert_eq!( [read_host, read_waited], [levels, 0], "a block-compressed texture's `getBytes` waited for an internal submission" ), - false => assert_eq!( + (false, true) => assert_eq!( + [staged, read_staged, read_waited], + [0, levels, 0], + "a block-compressed texture's {levels} writes queued for the staging queue and each \ + read's one submission there" + ), + (false, false) => assert_eq!( read_waited, 1, - "a block-compressed texture's {levels} `getBytes` calls took more than the one submission the first of them makes its host shadow by" + "a block-compressed texture's {levels} `getBytes` calls took more than the one \ + submission the first of them makes its host shadow by" ), } } diff --git a/crates/metal2vulkan-runtime/src/texture/first_move.rs b/crates/metal2vulkan-runtime/src/texture/first_move.rs index 5758741b5..5e064efb5 100644 --- a/crates/metal2vulkan-runtime/src/texture/first_move.rs +++ b/crates/metal2vulkan-runtime/src/texture/first_move.rs @@ -19,11 +19,12 @@ //! one's (`rebind.rs`). The image (or stand-in) is registered weakly once it is shared //! ([`FirstMoves::register`]); an image that copies on the device's staging queue queues its //! move and zeros there instead, which every submission of the device's makes there before its -//! own (`texture/staging_copy.rs`, [`FirstMoves::queue_staging`]). An image over a dma-buf of its own pages (`dma_buf.rs`) starts -//! `UNDEFINED` too, and its move is an acquire from `VK_QUEUE_FAMILY_FOREIGN_EXT` for the -//! device's queue family (`VK_QUEUE_FAMILY_IGNORED` where its images are concurrent among -//! several), from `GENERAL` (which keeps its bytes, as Vulkan's foreign images keep theirs only -//! through such an acquire) to `GENERAL` ([`FirstMove::acquired`]); it rests there. +//! own (`texture/staging_copy.rs`, [`FirstMoves::queue_staging`]). An image over a dma-buf of +//! its own pages (`dma_buf.rs`) starts `UNDEFINED` too, and its move is an acquire from +//! `VK_QUEUE_FAMILY_FOREIGN_EXT` for the device's queue family (`VK_QUEUE_FAMILY_IGNORED` where +//! its images are concurrent among several), from `GENERAL` (which keeps its bytes, as Vulkan's +//! foreign images keep theirs only through such an acquire) to `GENERAL` +//! ([`FirstMove::acquired`]); it rests there. //! A new buffer whose bytes the host cannot write (`Private`, and a //! `Managed` buffer's device copy) notes its fill with zeros ([`FirstFill`]) the same way //! (`Buffer::clear_first`), and a new `Private` buffer made with bytes then the copy of a staging diff --git a/crates/metal2vulkan-runtime/src/texture/staging_copy.rs b/crates/metal2vulkan-runtime/src/texture/staging_copy.rs index b22b14a2d..7e8bb2a80 100644 --- a/crates/metal2vulkan-runtime/src/texture/staging_copy.rs +++ b/crates/metal2vulkan-runtime/src/texture/staging_copy.rs @@ -509,9 +509,9 @@ impl Image { /// staging queue's next submission (the module docs); the image [takes staging /// copies](Self::takes_staging_copies), and `keeper` is what holds it (itself, or the texture /// whose decoded twin it is). Whether it did: not while it presents a stand-in, and then - /// `fill` is not called. Where the image's `VkImage` was handed out (`Texture::vk_image`), whose - /// user the runtime does not see, or the work queued passed its bound, the submission is - /// made now and waited for. + /// `fill` is not called. Where the image's `VkImage` was handed out (`Texture::vk_image`), + /// whose user the runtime does not see, or the work queued passed its bound, the submission + /// is made now and waited for. pub(super) fn staging_write( &self, keeper: &Arc,