diff --git a/crates/metal2vulkan-conformance/README.md b/crates/metal2vulkan-conformance/README.md index fa7b24490..6dc65866f 100644 --- a/crates/metal2vulkan-conformance/README.md +++ b/crates/metal2vulkan-conformance/README.md @@ -318,8 +318,6 @@ random on honest work. Each reason is written at its site in `cost.rs` with the other side is thread arrival cannot be deterministic while that side is not; - one that moves when something has sat **past its quiet period**, which is a question about elapsed time; -- `device_memory_allocated`, the bytes of blocks whose size follows **how long the device's - earlier makings took** (smaller after one took longer than 8 ms); - `completed_waits`, which charges a case for waits belonging to whatever ran before it. A count in the `SPARED` table is gated from below only while it is gated at all: `racy` wins, so a diff --git a/crates/metal2vulkan-conformance/src/cost.rs b/crates/metal2vulkan-conformance/src/cost.rs index 4c9ba8cc5..fa70d3b4c 100644 --- a/crates/metal2vulkan-conformance/src/cost.rs +++ b/crates/metal2vulkan-conformance/src/cost.rs @@ -163,8 +163,7 @@ const RELEASED: &str = "what a release got round to destroying, which runs on wh /// can: `addressable_buffers_made`, `pooled_memory_blocks_made`, `arena_pools_made`, /// `device_memory_allocated`, `creation_pipelines_made`, `variant_pipelines_made`, /// `shader_modules_made` and `pipeline_layouts_made` read at or above their in-set reading in every -/// case that ran alone, so company only lowers them. (`device_memory_allocated` is reported anyway, -/// for a reason of its own: [`BLOCK_SIZE`].) +/// case that ran alone, so company only lowers them. /// /// That is a fact about those eight counts and not a law about `_made` counts, and the contrast the /// measurement now takes is what tells one from the other. Two counts an earlier version of this @@ -459,21 +458,6 @@ const FOLDED: &str = of its own, which the submission path decides from what the queue did with work submitted \ before this case"; -/// Why `device_memory_allocated` is reported and never gated: the runtime makes its later pooled -/// blocks of plain memory smaller on a device where making one took longer than 8 ms -/// (`memory.rs`'s `MAKING_BOUND`), so the bytes a case allocates follow how long an earlier making -/// took, which is how fast the device made memory at that moment and not the case's work. -/// -/// Its partner `pooled_memory_blocks_made` stays gated, on a measurement: with that size held at -/// its 16 MiB floor from the start, eight runs of the whole set (1233 cases) on the M3 Max moved -/// none of its gated bounds and none of its ceilings, and put no case over a bound, where this -/// count's gated bound moved in one case (201326592 in the record, 50331648 measured). A size that -/// changes partway through a run, between 64 MiB and that floor, is unmeasured. -const BLOCK_SIZE: &str = "bytes in blocks whose size follows how long the device's earlier \ - makings of such blocks took (smaller after one took longer than 8 ms), which is how fast \ - the device made memory at that moment and not the case's work. Measured: with the size \ - held at its 16 MiB floor, one case read 50331648 where its record holds 201326592"; - /// Why a count of an object made because no spare was free is reported and never gated. const POOLED: &str = "an object made because no spare was free, where a spare comes back on \ another thread: which case has to make one depends on when that thread returned the one \ @@ -507,9 +491,8 @@ const POOLED: &str = "an object made because no spare was free, where a spare co /// replays of a larger case set — which reads like a regression and is not one. See [`BORROWED`]. /// `slot_returns` beside it stays gated: it counts work items, one a command buffer, and has held /// still alone and in both case sets. -const RACY: [(&str, &str); 46] = [ +const RACY: [(&str, &str); 45] = [ ("fences_made", POOLED), - ("device_memory_allocated", BLOCK_SIZE), // What is alive, parked or waiting at the instant the counts were read. ("memory_blocks_live", INSTANTANEOUS), ("empty_memory_blocks_live", INSTANTANEOUS), @@ -647,8 +630,8 @@ const RACY: [(&str, &str); 46] = [ /// It passed the direction test — 385 cases, 0 below — and fails the other test a bound has to /// pass: it counts *bytes*, so the two shapes differ by 268,435,456 where the largest of these /// object counts differs by 8. A bound of 256 MiB on a case that allocates nothing in company is a -/// number no regression can reach, and a bound that cannot fail is worse than no bound. It is -/// reported, never gated, for that and for a reason of its own ([`BLOCK_SIZE`]). +/// number no regression can reach, and a bound that cannot fail is worse than no bound. It stays +/// reported, with both readings, where a reader can see it. /// /// **A count of bytes can never take a row here**, which is the general form of the paragraph /// above and is held by `tests::no_monotone_bound_is_a_count_of_bytes` rather than left to whoever diff --git a/crates/metal2vulkan-conformance/src/tests.rs b/crates/metal2vulkan-conformance/src/tests.rs index a52649b68..37f618817 100644 --- a/crates/metal2vulkan-conformance/src/tests.rs +++ b/crates/metal2vulkan-conformance/src/tests.rs @@ -5118,10 +5118,6 @@ fn a_count_that_says_which_thread_arrived_first_is_never_gated() { // does what a case allocates even though what the pool hands back does not. assert!(racy("encoder_command_buffers_begun").is_none()); assert!(racy("pooled_memory_blocks_made").is_none()); - // The bytes those blocks hold are reported: their size follows how long the device's earlier - // makings took, and with it held at its 16 MiB floor one case's reading went from 201326592 to - // 50331648 over the whole set, where no gated bound of the block count moved. - assert!(racy("device_memory_allocated").is_some()); // A free by any cause but the quiet period stays gated by its own name. for count in [ "memory_frees.dedicated", diff --git a/crates/metal2vulkan-runtime/src/memory.rs b/crates/metal2vulkan-runtime/src/memory.rs index 7a407e6b4..0f878a8c5 100644 --- a/crates/metal2vulkan-runtime/src/memory.rs +++ b/crates/metal2vulkan-runtime/src/memory.rs @@ -5,18 +5,9 @@ //! made outside a heap, and later a Metal heap (step 7: a heap is one block, its resources placed //! at offsets). //! - **Pooling.** Resources share blocks of [`BLOCK_BYTES`], so `maxMemoryAllocationCount` (4096 -//! on many devices) stays out of reach. A request larger than half a block takes a dedicated -//! block of its own size. Where a block of plain memory (allocated with no export) took longer -//! than [`MAKING_BOUND`] to make, the device's later pooled blocks of plain memory are made of -//! the largest power of two its rate makes within the bound with a sixteenth of it besides -//! ([`PLAIN_BLOCK_SLACK`]), the power of two at least [`MIN_PLAIN_BLOCK_BYTES`] -//! ([`Memory::plain_block_made`]), a placement larger than such a block taking one of the -//! least power of two so made that holds it: on RADV such a block shares the reservation of -//! the process's buffer objects, and its making holds every submission of the process for as -//! long as it runs (a Radeon 780M whose free memory lay in single pages took 9 to 27 ms at the -//! median for 64 MiB; `docs/FAST-PATHS.md`'s known gaps). -//! The blocks of exportable buffers keep their size: each is a buffer object of its own -//! reservation, whose making holds no submission. +//! on many devices) stays out of reach; a block of images holds a sixteenth besides +//! ([`IMAGE_BLOCK_SLACK`]), so that four images of a quarter of a block fit in one. A request +//! larger than half a block takes a dedicated block of its own size. //! - **Kept for reuse.** A block that empties is kept for the next placements rather than freed: //! a pooled one while fewer than [`KEPT_EMPTY_BLOCKS`] empty ones are kept in its pool, and //! past that, as a dedicated one of the runtime's own memory, while the empty blocks kept in its @@ -198,12 +189,6 @@ mod ready; /// The size of a pooled block, at most the device's `maxMemoryAllocationSize`. pub(super) const BLOCK_BYTES: u64 = 64 << 20; -/// The longest a making of a block of plain memory may take before the device's later pooled -/// blocks of plain memory are made smaller ([`Memory::plain_block_made`]): half a frame at 60 Hz. -/// On RADV such a making holds every submission of the process for as long as it runs (the module -/// docs), so a frame submitted meanwhile is late by what is left of it. -pub(super) const MAKING_BOUND: Duration = Duration::from_millis(8); - /// The longest a block's own allocation may take, its pages filled through an exportable /// allocation first (the module docs, "Blocks filled exportable first"), for the fill to count as /// having spared the submissions (`WorkCounts::plain_block_fills_saved`): one that took the fill's @@ -212,20 +197,12 @@ pub(super) const MAKING_BOUND: Duration = Duration::from_millis(8); /// (about 10 ms). const FILL_SAVED_BELOW: Duration = Duration::from_millis(1); -/// The smallest power of two a pooled block of plain memory is made of -/// ([`Memory::plain_block_made`]), its [`PLAIN_BLOCK_SLACK`] besides. -pub(super) const MIN_PLAIN_BLOCK_BYTES: u64 = 16 << 20; - -/// What a pooled block of plain memory made smaller than [`Memory::block_bytes`] holds past the -/// power of two it is made of, as a fraction of that power: a sixteenth ([`pooled_block_bytes`]). -/// A driver's image takes more than its texels: RADV places a `Private` `RGBA8Unorm` texture of -/// 1024 x 1024 (4 MiB of texels) in 4 MiB and 16 KiB on a Radeon 780M and 4 MiB and 16,408 bytes -/// on an RX 550, each at an alignment of 64 KiB, so a block of 16 MiB held three of them, not -/// four, and the textures of a guest's scroll took a third more blocks than their texels fill. -/// With a sixteenth besides, a block holds four images of a quarter of its power of two whose -/// metadata and alignment take up to 256 KiB each, two of a half up to 512 KiB, and one of the -/// whole up to 1 MiB. -pub(super) const PLAIN_BLOCK_SLACK: u64 = 16; +/// What a pooled block of images holds past [`BLOCK_BYTES`], as a fraction of it: a sixteenth +/// ([`Memory::pooled_bytes`]). A driver's image takes more than its texels: RADV on a Radeon 780M +/// and Iris Xe's driver place a `Private` `RGBA8Unorm` texture of 1024 x 1024 (4 MiB of texels) +/// in 4 MiB and 16 KiB, at an alignment of 64 KiB. With a sixteenth besides, a block holds four +/// images of a quarter of a block whose metadata and alignment take up to 1 MiB each. +pub(super) const IMAGE_BLOCK_SLACK: u64 = 16; /// The empty pooled blocks a pool keeps for its next placements whatever its heap's budget /// ([`Pool::release`], [`Memory::kept_budget`]). In a pool the encodings place in, one of them is @@ -908,9 +885,6 @@ pub(super) struct Pool { kept_bytes: u64, /// When it last grew: a pooled block added to it while it held another ([`Pool::grew`]). grew: Option, - /// The bytes of the largest block a placement larger than its blocks took within - /// [`KEPT_EMPTY_FOR`] of the last such placement, and when that was ([`Pool::took_large`]). - large: Option<(u64, Instant)>, } #[derive(Debug)] @@ -964,7 +938,6 @@ impl Default for Pool { freed_bytes: 0, kept_bytes: 0, grew: None, - large: None, } } } @@ -1324,46 +1297,16 @@ impl Pool { self.grew } - /// A placement larger than its blocks took a pooled block of `bytes` at `now` - /// ([`pooled_block_bytes`]): blocks of that size are made ahead for it while such placements - /// are recent (`memory/ready.rs`). - fn took_large(&mut self, bytes: u64, now: Instant) { - let recent = self.large(now).unwrap_or(0); - self.large = Some((bytes.max(recent), now)); - } - - /// The bytes of the largest block a placement larger than its blocks took within - /// [`KEPT_EMPTY_FOR`] before `now`, of the placements since one came after a longer gap. - fn large(&self, now: Instant) -> Option { - let (bytes, at) = self.large?; - (now.saturating_duration_since(at) < KEPT_EMPTY_FOR).then_some(bytes) - } - /// Whether it holds a pooled block. fn holds_pooled(&self) -> bool { self.blocks.iter().flatten().any(|block| !block.dedicated) } /// Whether it holds a pooled block, its blocks of `bytes`, and lacks the room its next block - /// is made ahead below ([`Pool::ahead_room`]): near its next block, which is made ahead + /// is made ahead below ([`ahead_room`]): near its next block, which is made ahead /// (`memory/ready.rs`). fn near_next(&mut self, bytes: u64) -> bool { - let room = self.ahead_room(bytes); - self.holds_pooled() && !self.has_room(room) - } - - /// The longest free range below which it gets its next block made ahead, its blocks of - /// `bytes` ([`ahead_room`]): three quarters of the largest of `bytes` and its pooled blocks. - /// A pool still filling a block made before its blocks of plain memory were made smaller - /// ([`Memory::plain_block_made`]) keeps its next block ahead as it did for that block: by three - /// quarters of the small block, a pool on a Radeon 780M whose one 64 MiB block had 12.4 MiB - /// left kept none ahead, and its next texture of 2560 x 1440 (15.1 MiB) waited for its block - /// (`tests::blocks_ahead`'s mixed sizes, told of a slow making at its fourth texture). - fn ahead_room(&self, bytes: u64) -> u64 { - let pooled = (self.blocks.iter().flatten()) - .filter(|block| !block.dedicated) - .map(|block| block.size); - ahead_room(pooled.fold(bytes, u64::max)) + self.holds_pooled() && !self.has_room(ahead_room(bytes)) } /// Every block's payload, emptying the pool. @@ -1999,11 +1942,9 @@ pub(super) struct Memory { /// The buffers' pools by memory type, then the images' ([`Memory::pool`]). pools: Vec>, block_bytes: u64, - /// The power of two a pooled block of plain memory is made of now, its [`PLAIN_BLOCK_SLACK`] - /// besides ([`pooled_block_bytes`]): [`Memory::block_bytes`], made smaller at each making - /// that took longer than [`MAKING_BOUND`], down to [`MIN_PLAIN_BLOCK_BYTES`] - /// ([`Memory::plain_block_made`]). - plain_block_bytes: u64, + /// A pooled block of images' size: [`Memory::block_bytes`] and its [`IMAGE_BLOCK_SLACK`], + /// at most the device's largest allocation. + image_block_bytes: u64, /// Blocks are allocated with `VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT`: the device enabled /// `bufferDeviceAddress`, so buffers carry device addresses. device_address: bool, @@ -2256,7 +2197,8 @@ impl Memory { .collect(), types, block_bytes: BLOCK_BYTES.min(max_allocation.max(1)), - plain_block_bytes: BLOCK_BYTES.min(max_allocation.max(1)), + image_block_bytes: (BLOCK_BYTES + BLOCK_BYTES / IMAGE_BLOCK_SLACK) + .min(max_allocation.max(1)), device_address, address_types: None, fd_address_types: None, @@ -2367,6 +2309,13 @@ impl Memory { self.fill_types = types; } + /// The memory types whose pooled blocks of plain memory are filled through an exportable + /// allocation first ([`Memory::fill_plain_blocks`]), as bits, for the crate's device tests. + #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] + pub(super) fn fill_types(&self) -> u32 { + self.fill_types + } + /// Make the blocks of [`Holds::PageBuffers`] of the memory types `types` names (as bits) of /// pages the runtime maps and imports by their pointer from now on, each a multiple of /// `unit` bytes long, where it names any, else note why not (the memory log says which), as @@ -2776,59 +2725,20 @@ impl Memory { grew || pool.near_next(bytes) } - /// The blocks `pool` keeps made ahead (`memory/ready.rs`), its blocks of `bytes`: as many of - /// `bytes` as come to one block of [`Memory::block_bytes`] or more, at least one, so that a - /// pool whose blocks of plain memory are made smaller ([`Memory::plain_block_made`]) keeps - /// at least the bytes ahead it kept before (four of 17 MiB for one of 64 MiB); and one of the - /// bytes of the largest block its placements larger than its blocks took lately - /// ([`Pool::large`]), where they did. - fn ahead_sizes(&mut self, pool: (Holds, u32), bytes: u64) -> (Option, u64) { - let bytes = bytes.max(1); - let large = - (self.pool(pool.0, pool.1).large(Instant::now())).filter(|&large| large > bytes); - (large, self.block_bytes.div_ceil(bytes).max(1)) - } - - /// The blocks made ahead for `pool` a call that needs a block of `least` bytes or more takes - /// ([`ready::Need`]): one below the bytes of its placements larger than its blocks lately - /// ([`Pool::large`]) leaves blocks of those bytes to them. - fn need(&mut self, pool: (Holds, u32), least: u64) -> ready::Need { - let large = self.pool(pool.0, pool.1).large(Instant::now()); - let most = match large { - Some(large) if least < large => large - 1, - _ => u64::MAX, - }; - ready::Need { least, most } - } - - /// Of the blocks `pool`, its blocks of `bytes`, keeps made ahead ([`ahead_sizes`]), those - /// `held` lacks (the bytes of each block made, being made and still to make): the larger - /// first. Its own blocks are counted in bytes together with its room ([`Pool::room`]): none - /// lacks while those held and its room come to their worth ([`ahead_sizes`]'s count of - /// them) or more, and once they come to less, as many as bring those held to that worth. So a - /// block just taken from them, which leaves the pool a whole block of room, is made again - /// as soon as a placement takes any of that room, not only once the pool lacks room for a - /// whole block: the room left then is less than the next creation calls' placements may - /// take before the making ends (a 31.6 MiB texture after a 64 MiB block was taken). - /// - /// [`ahead_sizes`]: Self::ahead_sizes + /// The block `pool`, its blocks of `bytes`, lacks of the one it keeps made ahead + /// (`memory/ready.rs`), `held` the bytes of each block made, being made and still to make: + /// counted in bytes together with its room ([`Pool::room`]), one where those held and its + /// room come to less than a block. So a block just taken from them, which leaves the pool a + /// whole block of room, is made again as soon as a placement takes any of that room, not only + /// once the pool lacks room for a whole block: the room left then is less than the next + /// creation calls' placements may take before the making ends (a 31.6 MiB texture after a + /// 64 MiB block was taken). fn lacking(&mut self, pool: (Holds, u32), bytes: u64, held: &[u64]) -> Vec { - let (large, count) = self.ahead_sizes(pool, bytes); - let mut lacking = Vec::new(); - if let Some(large) = large { - if !held.iter().any(|&size| size >= large) { - lacking.push(large); - } + let have: u64 = held.iter().sum(); + match self.pool(pool.0, pool.1).room().saturating_add(have) < bytes { + true => vec![bytes], + false => Vec::new(), } - // Its own blocks: those below its large placements' bytes, which those leave to them. - let below = large.unwrap_or(u64::MAX); - let have: u64 = held.iter().filter(|&&size| size < below).sum(); - let worth = count * bytes; - if self.pool(pool.0, pool.1).room().saturating_add(have) < worth { - let more = worth.saturating_sub(have) / bytes.max(1); - lacking.extend((0..more).map(|_| bytes)); - } - lacking } /// What a making ahead for `pool` is made through, once [`keep_room`] gave it. @@ -2842,9 +2752,9 @@ impl Memory { }) } - /// Keep `pool`'s blocks made ahead, its blocks of `bytes` (`memory/ready.rs`, - /// [`ahead_sizes`](Self::ahead_sizes)): those it lacks made after the blocks its thread - /// still makes, or on a new thread, once a burst of the device's queue uses ended. + /// Keep `pool`'s block made ahead, its blocks of `bytes` (`memory/ready.rs`, + /// [`lacking`](Self::lacking)): one it lacks made after the blocks its thread still makes, or + /// on a new thread, once a burst of the device's queue uses ended. fn keep_ahead(&mut self, pool: (Holds, u32), bytes: u64) { let held = match self.readying_at(pool) { Some(at) => self.readying[at].held(), @@ -2868,37 +2778,27 @@ impl Memory { } } - /// A call's wait for a block of `least` bytes or more made ahead for `pool`, its blocks of - /// `bytes` (`memory/ready.rs`; within [`need`](Self::need)), where none is made: the block - /// being made or still to make, or else one queued first for the call, its thread started - /// where it has none, the rest of the pool's blocks kept ahead after it where the pool keeps - /// them ([`growing`](Self::growing)). A pool's first block is made alone: the rest of a - /// block's worth of small blocks behind it (three of 16 MiB) waited unused for a pool that - /// stayed within that block, and went after [`KEPT_EMPTY_FOR`], to be made again - /// (`tests::reclaim_submit_bench`'s small-blocks arms on a Radeon 780M: nine such blocks a - /// device). `None` where the pool host copies place in reads a - /// block's pages now, as a page's first touch may wait behind the program's GPU work, before - /// [`keep_room`] gave the makings what they are made through, or where no thread starts. - fn wait_for(&mut self, pool: (Holds, u32), bytes: u64, least: u64) -> Option { - let need = self.need(pool, least); + /// A call's wait for a block of `least` bytes or more made ahead for `pool` + /// (`memory/ready.rs`), where none is made: the block being made or still to make, or else + /// one queued first for the call, its thread started where it has none. A pool's first block + /// is made alone. `None` where the pool host copies place in reads a block's pages now, as a + /// page's first touch may wait behind the program's GPU work, before [`keep_room`] gave the + /// makings what they are made through, or where no thread starts. + fn wait_for(&mut self, pool: (Holds, u32), least: u64) -> Option { let making = self.making(pool)?; let host_copies = self.host_copy_pool == Some(Some(pool)); match self.readying_at(pool) { Some(at) => { let readying = &mut self.readying[at]; - let waiter = readying.waiter(need, host_copies)?; - match readying.will_hold(need) || readying.queue(making, &[least], true) { + let waiter = readying.waiter(least, host_copies)?; + match readying.will_hold(least) || readying.queue(making, &[least], true) { true => Some(waiter), false => None, } } None => { - let rest = match self.growing(pool) { - true => self.lacking(pool, bytes, &[least]), - false => Vec::new(), - }; - let sizes = std::iter::once(least).chain(rest).collect(); - let (readying, waiter) = ready::Readying::start(making, pool, sizes, Some(need))?; + let sizes = [least].into(); + let (readying, waiter) = ready::Readying::start(making, pool, sizes, Some(least))?; self.readying.push(readying); waiter } @@ -2906,14 +2806,13 @@ impl Memory { } /// Add the smallest block of `least` bytes or more made ahead for `pool` and not yet added to - /// it (`memory/ready.rs`; within [`need`](Self::need)): whether one was added. A readying + /// it (`memory/ready.rs`): whether one was added. A readying /// whose thread ended and that holds no block more goes. fn add_ready(&mut self, pool: (Holds, u32), least: u64) -> bool { let Some(at) = self.readying_at(pool) else { return false; }; - let need = self.need(pool, least); - let made = self.readying[at].take_block(need); + let made = self.readying[at].take_block(least); if self.readying[at].finished() && !self.readying[at].has_block() { self.readying.swap_remove(at).end(); } @@ -3098,9 +2997,6 @@ impl Memory { { self.makings_took += block.took; } - if block.exported.is_none() && !block.fd && !block.pooled_pages { - self.plain_block_made(block.size, block.took); - } self.allocated += size; let heap = self.heap_of(type_index); if let Some((_, live)) = self.heaps.get_mut(heap) { @@ -3114,15 +3010,13 @@ impl Memory { pool.add_as(size, dedicated, block, used, zeroed) } - /// The bytes of a pooled block made for `pool` with room for half of it - /// ([`pooled_block_bytes`]). + /// The bytes of a pooled block made for `pool`: [`Memory::block_bytes`], and a block of + /// images' [`Memory::image_block_bytes`]. fn pooled_bytes(&self, pool: (Holds, u32)) -> u64 { - let types = ( - self.fd_buffer_types.unwrap_or(0), - self.page_buffer_types.unwrap_or(0), - ); - let plain = plain(pool, types.0, types.1).then_some(self.plain_block_bytes); - pooled_block_bytes(self.block_bytes, plain, 0) + match pool.0 { + Holds::Images => self.image_block_bytes, + _ => self.block_bytes, + } } /// The bytes of each live pooled block that holds `holds`, of every memory type, for the @@ -3151,19 +3045,6 @@ impl Memory { }) } - /// For each pool of `holds` that keeps blocks made ahead, its memory type's index and the bytes - /// of its blocks made ahead and not yet added, and of those still to make - /// (`memory/ready.rs`), for the crate's device tests. Each pool keeps its own: the pool host - /// copies place in ([`Memory::host_copy_pool`]) is one of images beside theirs where its - /// type differs. - #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] - pub(super) fn ahead_bytes(&self, holds: Holds) -> Vec<(u32, u64)> { - (self.readying.iter()) - .filter(|ready| ready.pool().0 == holds) - .map(|ready| (ready.pool().1, ready.outstanding_bytes())) - .collect() - } - /// Every pool that keeps blocks made ahead, with the bytes of its blocks made ahead and not /// yet added and of those still to make (`memory/ready.rs`), for the crate's device tests. #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] @@ -3197,36 +3078,6 @@ impl Memory { .collect() } - /// The bytes a pooled block of plain memory is made of now ([`Memory::plain_block_made`]), for - /// the crate's tests. - #[cfg(test)] - pub(super) fn plain_block_bytes(&self) -> u64 { - self.plain_block_bytes - } - - /// A block of plain memory of `size` bytes was made in `took` (`vkAllocateMemory`, its - /// mapping and its buffer of addresses): where that is longer than [`MAKING_BOUND`], the later - /// pooled blocks of plain memory are made of the largest power of two that the making's rate - /// (`size` in `took`) makes within the bound with its [`PLAIN_BLOCK_SLACK`] besides, where - /// that is smaller than the one they are made of now, at least [`MIN_PLAIN_BLOCK_BYTES`]. A - /// block that took that long held every submission of the process on RADV as long, and a - /// block's making there takes about as much longer as the block is larger. Never made larger - /// again: the host's state that made it slow (its free memory in single pages, no freed pages - /// at hand in the kernel's pools) comes back. - pub(super) fn plain_block_made(&mut self, size: u64, took: Duration) { - if took <= MAKING_BOUND { - return; - } - let within = u128::from(size) * MAKING_BOUND.as_nanos() / took.as_nanos(); - let within = u64::try_from(within).unwrap_or(u64::MAX); - let fits = match within.checked_ilog2() { - Some(log) if with_slack(1 << log) <= within => 1 << log, - Some(log) => 1 << log >> 1, - None => 0, - }; - self.plain_block_bytes = self.plain_block_bytes.min(fits.max(MIN_PLAIN_BLOCK_BYTES)); - } - /// What making a block takes, copied out so that the block is made with the memory's lock /// released ([`place`], [`keep_room`]). fn maker(&self) -> BlockMaker { @@ -3235,7 +3086,7 @@ impl Memory { .fold(0, |bits, (index, _)| bits | 1 << index); BlockMaker { block_bytes: self.block_bytes, - plain_block_bytes: self.plain_block_bytes, + image_block_bytes: self.image_block_bytes, host_visible, fd_types: self.fd_buffer_types.unwrap_or(0), page_types: self.page_buffer_types.unwrap_or(0), @@ -3477,14 +3328,14 @@ impl Memory { } // A block made ahead for a pool that stopped growing that long ago, where the pool has // room for three quarters of a block, so that it is no longer near its next block - // ([`Pool::ahead_room`], `memory/ready.rs`). + // ([`ahead_room`], `memory/ready.rs`). let mut at = 0; while at < self.readying.len() { let (holds, type_index) = self.readying[at].pool(); let started = self.readying[at].started(); let bytes = self.pooled_bytes((holds, type_index)); let pool = self.pool(holds, type_index); - let room = pool.ahead_room(bytes); + let room = ahead_room(bytes); let since = pool.grew(None).map_or(started, |grew| grew.max(started)); let unused = now.saturating_duration_since(since) >= KEPT_EMPTY_FOR && pool.has_room(room) @@ -3852,49 +3703,13 @@ impl Memory { } } -/// Whether the blocks of `pool` are of plain memory, allocated with no export -/// ([`BlockMaker::make`]): not those of exportable buffers ([`Holds::handle`]), nor those of -/// [`Holds::FdBuffers`] of a memory type `fd_types` names (as bits), which are allocated -/// exportable as [`FD_BLOCKS_HANDLE`], nor those of [`Holds::PageBuffers`] of a memory type -/// `page_types` names, which are pages the runtime maps and imports. -fn plain((holds, type_index): (Holds, u32), fd_types: u32, page_types: u32) -> bool { - let named = |types: u32| types & 1 << type_index != 0; - holds.handle().is_none() - && !(holds == Holds::FdBuffers && named(fd_types)) - && !(holds == Holds::PageBuffers && named(page_types)) -} - -/// The bytes of a pooled block that holds a placement of `size` bytes, at most half of -/// `block_bytes` ([`place`]): `block_bytes` where its blocks are allocated exportable (`plain` -/// `None`) or those of plain memory are made of `block_bytes`; else the power of two `plain` -/// says a pooled block of plain memory is made of now ([`Memory::plain_block_made`]), or the -/// least power of two larger that holds the placement, each with its [`PLAIN_BLOCK_SLACK`] -/// besides ([`with_slack`]), at most `block_bytes`. -pub(super) fn pooled_block_bytes(block_bytes: u64, plain: Option, size: u64) -> u64 { - match plain { - Some(plain) if plain < block_bytes => { - let holds = std::iter::successors(Some(plain), |base| base.checked_mul(2)) - .map(with_slack) - .find(|&bytes| bytes >= size); - holds.unwrap_or(block_bytes).min(block_bytes) - } - _ => block_bytes, - } -} - -/// A pooled block of plain memory made of the power of two `base`, with its [`PLAIN_BLOCK_SLACK`] -/// besides. -fn with_slack(base: u64) -> u64 { - base + base / PLAIN_BLOCK_SLACK -} - /// What making a block of the runtime's memory takes ([`Memory::maker`]): a copy of the memory's /// constants, so that the block is made with its lock released. struct BlockMaker { /// A pooled block's size ([`BLOCK_BYTES`], or the device's largest allocation). block_bytes: u64, /// As [`Memory`]'s. - plain_block_bytes: u64, + image_block_bytes: u64, /// The host-visible memory types, as bits: a block of one is mapped whole. host_visible: u32, /// The memory types whose [`Holds::FdBuffers`] blocks are allocated exportable, as bits. @@ -3916,11 +3731,12 @@ struct BlockMaker { } impl BlockMaker { - /// The bytes of a pooled block made for `pool` that holds a placement of `size` bytes, at - /// most half a block ([`place`]; [`pooled_block_bytes`]). - fn pooled_bytes(&self, pool: (Holds, u32), size: u64) -> u64 { - let plain = plain(pool, self.fd_types, self.page_types).then_some(self.plain_block_bytes); - pooled_block_bytes(self.block_bytes, plain, size) + /// The bytes of a pooled block made for `pool` ([`Memory::pooled_bytes`]). + fn pooled_bytes(&self, pool: (Holds, u32)) -> u64 { + match pool.0 { + Holds::Images => self.image_block_bytes, + _ => self.block_bytes, + } } /// A new block of `size` bytes of memory type `type_index` that holds `holds`, with a buffer @@ -4899,7 +4715,7 @@ fn place( let pool = (holds, type_index); let block_size = match dedicated { true => size, - false => maker.pooled_bytes(pool, size), + false => maker.pooled_bytes(pool), }; if fit == Fit::Pooled { let mut guard = lock(memory); @@ -4917,33 +4733,19 @@ fn place( return Ok(guard.mark_overflowed(placement, overflowing)); } } - // A pooled placement without room: a block made ahead for the pool of its block's - // size or more, rather than one of the placement's own (`memory/ready.rs`), waited for - // where none is made: the one being made or still to make, or else one the ready - // thread makes first for it. A placement larger than the pool's blocks, which takes a - // block of its own size ([`pooled_block_bytes`]), has blocks of that size kept ahead - // while such placements are recent. Made here: one of the pool host copies place in - // while that pool's making reads a block's pages, which may wait behind the - // program's GPU work, which no placement waits for. - if !dedicated { - let large = block_size > guard.pooled_bytes(pool); - if large { - guard - .pool(pool.0, pool.1) - .took_large(block_size, Instant::now()); - } - if guard.makes_ahead(pool) && take_ready(memory, guard, pool, block_size) { - let mut guard = lock(memory); - if large { - let bytes = guard.pooled_bytes(pool); - guard.keep_ahead(pool, bytes); - } - if let Some(placement) = - guard.place_pooled(device, pool, (size, align), addressed, class)? - { - ready_after_placing(&mut guard, pool, size); - return Ok(guard.mark_overflowed(placement, overflowing)); - } + // A pooled placement without room: a block made ahead for the pool, rather than one + // of the placement's own (`memory/ready.rs`), waited for where none is made: the one + // being made or still to make, or else one the ready thread makes first for it. Made + // here: one of the pool host copies place in while that pool's making reads a block's + // pages, which may wait behind the program's GPU work, which no placement waits for. + if !dedicated && guard.makes_ahead(pool) && take_ready(memory, guard, pool, block_size) + { + let mut guard = lock(memory); + if let Some(placement) = + guard.place_pooled(device, pool, (size, align), addressed, class)? + { + ready_after_placing(&mut guard, pool, size); + return Ok(guard.mark_overflowed(placement, overflowing)); } } } @@ -5078,7 +4880,7 @@ pub(super) fn keep_room( .filter(|&&(holds, _)| holds != own && holds != Holds::FdBuffers && !page(holds)); for &pool in first.chain(rest) { let addressed = pool.0.buffers().then_some(&**counts); - let bytes = maker.pooled_bytes(pool, 0); + let bytes = maker.pooled_bytes(pool); keep_pool_room(memory, device, (&maker, addressed), (pool, bytes)); ready_if_growing(&mut lock(memory), pool); } @@ -5203,8 +5005,7 @@ fn take_ready<'a>( if guard.add_ready(pool, need) { return true; } - let bytes = guard.pooled_bytes(pool); - let Some(waiter) = guard.wait_for(pool, bytes, need) else { + let Some(waiter) = guard.wait_for(pool, need) else { return false; }; drop(guard); diff --git a/crates/metal2vulkan-runtime/src/memory/ready.rs b/crates/metal2vulkan-runtime/src/memory/ready.rs index 0d272b138..ad8c314e6 100644 --- a/crates/metal2vulkan-runtime/src/memory/ready.rs +++ b/crates/metal2vulkan-runtime/src/memory/ready.rs @@ -37,22 +37,13 @@ //! like a guest's scroll on the 780M (from 20 to 63 live blocks of 64 MiB in about 20 s, about 4 //! a second) finds a block made when it needs one; and, grown or not, once the pool is near its //! next block (`Pool::near_next`: it holds a pooled block and lacks room for three quarters of -//! one, of the largest it holds, `Pool::ahead_room`, a quarter of a block before the half block -//! `keep_room` keeps), so that its first growth, and the first after a pause, finds one made -//! too, where a guest's +//! one, `memory::ahead_room`, a quarter of a block before the half block `keep_room` keeps), so +//! that its first growth, and the first after a pause, finds one made too, where a guest's //! scroll on a Radeon 780M made its buffers' pool's first growth in place, on the guest's //! thread (`tests::reclaim_submit_bench`'s scroll arm: of each phase's 8 blocks, the first was //! made in place in three runs out of three, quiet and fragmented, and none is now). A pool -//! keeps a block's worth of bytes ahead: as many of its blocks as come to one block of -//! `memory::BLOCK_BYTES` or more (one of 64 MiB; four where its blocks of plain memory are made -//! of 17 MiB after a slow making, `Memory::plain_block_made`); and, while its placements larger -//! than its blocks are recent (the last within `KEPT_EMPTY_FOR`), each of which takes a block of -//! its own size (`memory::pooled_block_bytes`), one block of the largest such size besides -//! them, which a call that needs one of the pool's own blocks leaves to those placements, so -//! that a burst of textures that outruns the makings of the pool's own blocks does not take it -//! (`tests::blocks_ahead`). Its own blocks are counted in bytes with its room -//! (`Memory::lacking`): it lacks them once those made ahead and the longest free range of its -//! blocks come to less than their worth, and then as many as bring those made ahead to it. So +//! keeps one block ahead, counted in bytes with its room (`Memory::lacking`): it lacks one once +//! the blocks made ahead and the longest free range of its blocks come to less than a block. So //! the block a call just took, which leaves a whole block of room, is made again as soon as a //! placement takes any of that room, not once the pool lacks room for a whole block: on an RX 550 //! a 31.6 MiB texture placed in a 64 MiB block just taken left less than the half block the next @@ -60,28 +51,23 @@ //! (`tests::blocks_ahead`'s mixed sizes, at textures 8, 16 and 24 of 32). A placement of a //! quarter of a block or more starts the making there and then (`memory::place`), not at the //! next creation call. They are made one after another once a burst ended; those it lacks are -//! queued after the blocks its thread still makes, or made on a new thread where that ended. So each making stays as short as its block, and the pool's growth -//! still finds its blocks made: with one block of 16 MiB ahead at a time, a guest's scroll on a -//! Radeon 780M whose blocks were made so made 82 to 114 blocks of images on its own threads and -//! waited for 110 to 159 of those made ahead. It keeps them for as long as it stays near its -//! next block; none for a pool with room for three quarters of a block. And for the host -//! copies' pool once that lacks room for half a block, the first by the device's first creation -//! call, before the program queued work. A pool of exportable buffers, which the creation calls -//! themselves place in, gets its blocks started the same way once it grew or is near its next -//! block, so that the creation call that finds no room there takes a block made ahead rather -//! than make one on the program's thread (on a Radeon 780M a creation call that made such a -//! 64 MiB block itself took 10.0 to 15.0 ms in three of four phases of -//! `tests::reclaim_submit_bench`, quiet and fragmented, and none took over 0.3 ms with the -//! blocks made ahead); none of its blocks is made by a creation call that places nothing there. +//! queued after the blocks its thread still makes, or made on a new thread where that ended. It +//! keeps them for as long as it stays near its next block; none for a pool with room for three +//! quarters of a block. And for the host copies' pool once that lacks room for half a block, +//! the first by the device's first creation call, before the program queued work. A pool of +//! exportable buffers, which the creation calls themselves place in, gets its blocks started +//! the same way once it grew or is near its next block, so that the creation call that finds +//! no room there takes a block made ahead rather than make one on the program's thread (on a +//! Radeon 780M a creation call that made such a 64 MiB block itself took 10.0 to 15.0 ms in +//! three of four phases of `tests::reclaim_submit_bench`, quiet and fragmented, and none took +//! over 0.3 ms with the blocks made ahead); none of its blocks is made by a creation call that places nothing there. //! - **Added where room is needed.** A creation call that finds such a pool without room for //! half a block (`memory::keep_room`), and a placement that finds no room (`memory::place`), //! add the pool's smallest block made ahead of the size they need. Where none is made they wait //! for the one being made or still to make, or else for one the pool's thread makes first for -//! them, the thread started where the pool has none, the rest of its block's worth made after -//! it where the pool grows (`Memory::growing`; a pool's first block is made alone, as the rest -//! behind it waited unused where the pool stayed within it): no two threads make blocks for the -//! same pool, none is made only to be freed, and a call -//! makes no block of a pool whose blocks are made ahead where a making can serve it. A making +//! them, the thread started where the pool has none: no two threads make blocks for the same +//! pool, none is made only to be freed, and a call makes no block of a pool whose blocks are +//! made ahead where a making can serve it. A making //! still waiting for a burst's end when a call comes allocates at once, so that the call waits //! for the allocation alone, never for the program's own submissions to pause; while a call //! waits the thread reads no page, the pages left unread faulting in at their first touch, as a @@ -194,30 +180,16 @@ struct State { } impl State { - /// Whether a block of bytes within `need` is made. - fn holds(&self, need: Need) -> bool { - self.made.iter().any(|made| need.fits(made.block.size)) + /// Whether a block of `least` bytes or more is made. + fn holds(&self, least: u64) -> bool { + self.made.iter().any(|made| made.block.size >= least) } - /// Whether a block of bytes within `need` is made, being made or still to make. - fn will_hold(&self, need: Need) -> bool { - self.holds(need) - || self.making.is_some_and(|bytes| need.fits(bytes)) - || self.to_make.iter().any(|&bytes| need.fits(bytes)) - } -} - -/// The bytes of a block a call can take: `least` or more, `most` at most. -#[derive(Clone, Copy, Debug)] -pub(super) struct Need { - pub(super) least: u64, - pub(super) most: u64, -} - -impl Need { - /// Whether a block of `bytes` is within it. - fn fits(self, bytes: u64) -> bool { - (self.least..=self.most).contains(&bytes) + /// Whether a block of `least` bytes or more is made, being made or still to make. + fn will_hold(&self, least: u64) -> bool { + self.holds(least) + || self.making.is_some_and(|bytes| bytes >= least) + || self.to_make.iter().any(|&bytes| bytes >= least) } } @@ -231,21 +203,21 @@ pub(super) struct Made { pub(super) waited_for: bool, } -/// A call's wait for a readying's block of bytes within `need` ([`Readying::waiter`]), with no +/// A call's wait for a readying's block of `least` bytes or more ([`Readying::waiter`]), with no /// lock of the memory held: counted among the waiting from its making to its drop, so that the /// thread reads no page meanwhile. pub(super) struct Waiter { shared: Arc, - need: Need, + least: u64, } impl Waiter { - /// A wait on `shared` for a block of bytes within `need`, counted from now. - fn new(shared: &Arc, need: Need) -> Waiter { + /// A wait on `shared` for a block of `least` bytes or more, counted from now. + fn new(shared: &Arc, least: u64) -> Waiter { shared.waiting.fetch_add(1, Ordering::SeqCst); Waiter { shared: Arc::clone(shared), - need, + least, } } @@ -257,10 +229,10 @@ impl Waiter { .go .compare_exchange(WAIT, NOW, Ordering::AcqRel, Ordering::Acquire); let mut state = lock(&shared.state); - while !state.holds(self.need) && !state.ended { + while !state.holds(self.least) && !state.ended { state = (shared.changed.wait(state)).unwrap_or_else(PoisonError::into_inner); } - state.holds(self.need) + state.holds(self.least) } } @@ -282,13 +254,13 @@ pub(super) struct MadeWith { impl Readying { /// Start making blocks of `sizes` bytes for `pool`, one after another, on a thread of its own: /// once a burst of the device's queue uses ended, or at once for a call that waits for a - /// block of bytes within `need`, whose wait it gives back. `None` where the host cannot start + /// block of `need` bytes or more, whose wait it gives back. `None` where the host cannot start /// a thread. pub(super) fn start( making: MadeWith, pool: (Holds, u32), sizes: VecDeque, - need: Option, + need: Option, ) -> Option<(Readying, Option)> { let go = match need { Some(_) => NOW, @@ -383,9 +355,9 @@ impl Readying { !lock(&self.shared.state).made.is_empty() } - /// Whether a block of bytes within `need` is made, being made or still to make. - pub(super) fn will_hold(&self, need: Need) -> bool { - lock(&self.shared.state).will_hold(need) + /// Whether a block of `least` bytes or more is made, being made or still to make. + pub(super) fn will_hold(&self, least: u64) -> bool { + lock(&self.shared.state).will_hold(least) } /// The bytes of each of its blocks made and not yet added, being made, and still to make. @@ -412,21 +384,21 @@ impl Readying { self.held().iter().sum() } - /// Its smallest block made and not yet added of bytes within `need`, taken. - pub(super) fn take_block(&self, need: Need) -> Option { + /// Its smallest block made and not yet added of `least` bytes or more, taken. + pub(super) fn take_block(&self, least: u64) -> Option { let mut state = lock(&self.shared.state); let at = (state.made.iter().enumerate()) - .filter(|(_, made)| need.fits(made.block.size)) + .filter(|(_, made)| made.block.size >= least) .min_by_key(|(_, made)| made.block.size) .map(|(at, _)| at)?; state.made.remove(at) } - /// A wait for its block of bytes within `need`, to run with no lock of the memory held. + /// A wait for its block of `least` bytes or more, to run with no lock of the memory held. /// `None` where `unless_reading` and its thread reads a block's pages now: a page's first /// touch may wait behind the program's GPU work (the module docs). - pub(super) fn waiter(&self, need: Need, unless_reading: bool) -> Option { - let waiter = Waiter::new(&self.shared, need); + pub(super) fn waiter(&self, least: u64, unless_reading: bool) -> Option { + let waiter = Waiter::new(&self.shared, least); // Counted first: a thread that begins its reads after this sees the wait and reads none, // and one that began them before is seen here. match unless_reading && self.shared.reading.load(Ordering::SeqCst) { diff --git a/crates/metal2vulkan-runtime/src/tests/block_fills.rs b/crates/metal2vulkan-runtime/src/tests/block_fills.rs new file mode 100644 index 000000000..e4a8cc83c --- /dev/null +++ b/crates/metal2vulkan-runtime/src/tests/block_fills.rs @@ -0,0 +1,99 @@ +//! A pooled block of plain memory has its pages filled through an exportable allocation first +//! (`memory.rs`'s module docs, "Blocks filled exportable first") on a device whose driver +//! identity says its plain allocations hold its submissions +//! (`DriverFact::PlainAllocationsHoldSubmissions`) and that exports pooled memory as an opaque +//! file descriptor (`memory::fd_buffer_types`), each such block counted as filled +//! (`WorkCounts::plain_block_fills_saved` or `plain_block_fills_missed`), and on no other device. +//! The run makes `Private` textures until the pool of images made [`BLOCKS`] blocks and reads the +//! device's counts of fills. +//! +//! Device tests: compiled only under the GPU safety cfgs (`m2v_gpu`, `m2v_cpu_icd`). + +use super::freed_memory::device; +use crate::{DriverFact, ResourceOptions, Texture, TextureDescriptor, WorkCounts}; +use metal2vulkan::metal::{PixelFormat, TextureUsage}; +use std::time::{Duration, Instant}; + +/// The blocks of images the run waits for. +const BLOCKS: u64 = 3; + +/// The most textures of 4 MiB the run makes, well past what those blocks hold. +const MOST: usize = 128; + +/// The blocks of images made, ahead or in place, from `start` to `counts`. +fn image_blocks(start: &WorkCounts, counts: &WorkCounts) -> u64 { + (counts.image_blocks_made_ahead + counts.image_blocks_made_in_place) + - (start.image_blocks_made_ahead + start.image_blocks_made_in_place) +} + +#[test] +fn plain_blocks_are_filled_exportable_first_where_their_making_holds_submissions() { + let scratch = std::env::temp_dir().join(format!("m2v-block-fills-{}", std::process::id())); + std::fs::create_dir_all(&scratch).unwrap(); + let device = device(&scratch); + let holds = device + .properties() + .driver_facts + .contains(&DriverFact::PlainAllocationsHoldSubmissions); + let types = crate::device::lock(&device.shared().memory).fill_types(); + let start = device.work_counts(); + let mut held: Vec = Vec::new(); + let mut counts = start; + while image_blocks(&start, &counts) < BLOCKS { + assert!( + held.len() < MOST, + "{MOST} textures made {} blocks of images", + image_blocks(&start, &counts) + ); + let mut descriptor = + TextureDescriptor::texture_2d(PixelFormat::RGBA8Unorm, 1024, 1024, false); + descriptor.usage = TextureUsage::SHADER_READ | TextureUsage::RENDER_TARGET; + descriptor.resource_options = ResourceOptions::private(); + held.push(device.new_texture(&descriptor).unwrap()); + let at = Instant::now(); + while !crate::device::lock(&device.shared().memory).readying_ended() { + assert!( + at.elapsed() < Duration::from_secs(30), + "a making never ended" + ); + std::thread::sleep(Duration::from_millis(1)); + } + counts = device.work_counts(); + } + let saved = counts.plain_block_fills_saved - start.plain_block_fills_saved; + let missed = counts.plain_block_fills_missed - start.plain_block_fills_missed; + let blocks = image_blocks(&start, &counts); + println!( + "BLOCK-FILLS {}: plain allocations hold its submissions {holds}, blocks filled first of \ + memory types {types:#x}; of {blocks} blocks of images made, {saved} filled first and \ + made under 1 ms, {missed} filled first and not", + device.name(), + ); + match holds { + true => { + assert_ne!( + types, 0, + "a device whose plain allocations hold its submissions fills no type first" + ); + assert!( + saved + missed >= blocks, + "{blocks} blocks of images, {} filled first", + saved + missed + ); + } + false => { + assert_eq!( + types, 0, + "a device whose plain allocations hold no submission fills types first" + ); + assert_eq!( + saved + missed, + 0, + "a device whose plain allocations hold no submission filled blocks first" + ); + } + } + drop(held); + drop(device); + let _ = std::fs::remove_dir_all(&scratch); +} diff --git a/crates/metal2vulkan-runtime/src/tests/blocks_ahead.rs b/crates/metal2vulkan-runtime/src/tests/blocks_ahead.rs index b8aa607b4..7b2ead21f 100644 --- a/crates/metal2vulkan-runtime/src/tests/blocks_ahead.rs +++ b/crates/metal2vulkan-runtime/src/tests/blocks_ahead.rs @@ -20,7 +20,7 @@ use super::freed_memory::device; use crate::device::queue_quiet::QueueQuiet; -use crate::memory::{Holds, BLOCK_BYTES, MAKING_BOUND, MIN_PLAIN_BLOCK_BYTES}; +use crate::memory::Holds; use crate::{Buffer, Device, Error, ResourceOptions, Texture, TextureDescriptor, WorkCounts}; use metal2vulkan::metal::{PixelFormat, TextureUsage}; use std::time::{Duration, Instant}; @@ -46,26 +46,9 @@ const MOST: usize = 400; /// The creation calls that place nothing in the host copies' pool once its making ended. const CREATIONS: usize = 20; -/// The side of the small-blocks runs' `RGBA8Unorm` textures: 4 MiB, four to a block of 16 MiB -/// and a sixteenth. -const TEXTURE_SIDE: u64 = 1024; - -/// The large-blocks run's textures larger than a block of 16 MiB and a sixteenth: 20 MiB, each in -/// a block of 32 MiB and a sixteenth ([`LARGE_EVERY`] textures one of them), and how many it -/// makes; then the textures of [`TEXTURE_SIDE`] it makes back to back, 96 MiB, more than its own -/// blocks made ahead hold. -const LARGE_SIDES: (u64, u64) = (2560, 2048); -const BURST: usize = 24; -const LARGE_EVERY: usize = 4; -const LARGE_TEXTURES: usize = 4; - -/// The most textures the small-blocks run makes, well past what `GROWTH` blocks hold. +/// The most textures a run makes, well past what `GROWTH` blocks hold. const MOST_TEXTURES: usize = 64; -/// A pooled block of plain memory of the least size (`memory::PLAIN_BLOCK_SLACK`): 16 MiB and a -/// sixteenth. -const SMALL_BLOCK: u64 = MIN_PLAIN_BLOCK_BYTES + MIN_PLAIN_BLOCK_BYTES / 16; - /// A scratch directory for a device's shader cache, removed when dropped. struct Scratch(std::path::PathBuf); @@ -96,18 +79,6 @@ fn makings_ended(device: &Device) { } } -/// A device told of a pooled block's making that took four times `memory::MAKING_BOUND`, so that -/// it makes its pooled blocks of plain memory of the least size (`Memory::plain_block_made`). -fn small_blocks_device(scratch: &Scratch) -> Device { - let device = device(&scratch.0); - { - let mut memory = crate::device::lock(&device.shared().memory); - memory.plain_block_made(BLOCK_BYTES, MAKING_BOUND * 4); - assert_eq!(memory.plain_block_bytes(), MIN_PLAIN_BLOCK_BYTES); - } - device -} - /// A `Private` `RGBA8Unorm` texture of `width` by `height` on `device`, sampled and rendered to, /// made into `held`; then wait for the makings it started. fn texture(device: &Device, (width, height): (u64, u64), held: &mut Vec) { @@ -256,15 +227,13 @@ fn a_growing_pool_of_exportable_buffers_gets_its_new_blocks_made_ahead() { /// A pool's first block is made alone: a pool keeps blocks ahead only while it grows or is near /// its next block (`Memory::growing`), and a pool that takes one block and stays within it does -/// neither. The rest of a block's worth of small blocks once queued behind each pool's first -/// block (three of 16 MiB) waited unused and went after `KEPT_EMPTY_FOR`: on a Radeon 780M, nine -/// blocks of 16 MiB a device in `tests::reclaim_submit_bench`'s small-blocks arms, made and freed -/// for nothing. The pool host copies place in keeps its own blocks ahead from the device's first -/// creation call, by design, and is left out. +/// neither, so no block is made behind its first to wait unused and go after `KEPT_EMPTY_FOR`. +/// The pool host copies place in keeps its own blocks ahead from the device's first creation +/// call, by design, and is left out. #[test] fn a_pool_s_first_block_is_made_alone() { let scratch = Scratch::new("first-alone"); - let device = small_blocks_device(&scratch); + let device = device(&scratch.0); let buffer = device.new_buffer(64 << 10, ResourceOptions::private()); let mut held: Vec = Vec::new(); texture(&device, (256, 256), &mut held); @@ -290,81 +259,20 @@ fn a_pool_s_first_block_is_made_alone() { drop(buffer.unwrap()); } -/// A pool whose blocks of plain memory are made small after a slow making -/// (`Memory::plain_block_made`) keeps as many of them made ahead as come to one block of -/// `memory::BLOCK_BYTES` or more, at least the bytes it kept ahead before they were made small -/// (four of 17 MiB), and no creation call makes a block of the pool itself while one can be made -/// ahead: where none is made or under way, the call starts the pool's making and waits for its -/// first block, the pool's first block among them. With one small block ahead at a time, a -/// guest's creation calls on a Radeon 780M whose blocks were made of 16 MiB made 82 to 114 blocks -/// of images themselves. +/// The textures of a pool of images pack as many to a block as their texels' bytes fill: four +/// `RGBA8Unorm` textures of 2048 x 2048 (16 MiB of texels each, a quarter of `memory::BLOCK_BYTES`) +/// to a block, whatever metadata the driver's image carries past its texels within the block's +/// sixteenth besides (`memory::IMAGE_BLOCK_SLACK`). The run makes [`PACKED`] of them, one at a +/// time, and counts the pool's blocks of images, printing each image's bytes and alignment as the +/// driver asked them. #[test] -fn a_pool_of_small_blocks_keeps_a_block_s_bytes_ahead_and_no_creation_call_makes_one() { - let scratch = Scratch::new("small-blocks"); - let device = small_blocks_device(&scratch); - let start = device.work_counts(); - let blocks = |counts: &WorkCounts| { - (counts.image_blocks_made_ahead + counts.image_blocks_made_in_place) - - (start.image_blocks_made_ahead + start.image_blocks_made_in_place) - }; - let mut held: Vec = Vec::new(); - let mut counts = start; - // The most each pool of images kept ahead, by its memory type: the textures' pool, and the - // pool host copies place in where the device copies color textures on the host and its type - // differs (an Iris Xe's host-cached type), which keeps its own. - let mut most_ahead = std::collections::BTreeMap::::new(); - // One texture at a time, every making it started ended before the next: what this holds is - // where each block is made and what is kept ahead, not how soon a making ends. - while blocks(&counts) < GROWTH { - texture(&device, (TEXTURE_SIDE, TEXTURE_SIDE), &mut held); - counts = device.work_counts(); - let ahead = crate::device::lock(&device.shared().memory).ahead_bytes(Holds::Images); - for (type_index, bytes) in ahead { - let most = most_ahead.entry(type_index).or_default(); - *most = (*most).max(bytes); - } - } - let host_copies = crate::device::lock(&device.shared().memory).host_copies_pool(); - let in_place = counts.image_blocks_made_in_place - start.image_blocks_made_in_place; - let ahead = counts.image_blocks_made_ahead - start.image_blocks_made_ahead; - println!( - "BLOCKS-AHEAD {}: {} textures of 4 MiB in blocks of {} KiB; of the images' pool's {} \ - blocks, {ahead} made ahead, {in_place} in place, {} waited for; most kept ahead by \ - memory type {:?} KiB; host copies' pool {host_copies:?}", - device.name(), - held.len(), - SMALL_BLOCK >> 10, - blocks(&counts), - counts.blocks_ahead_waited_for - start.blocks_ahead_waited_for, - (most_ahead.iter()) - .map(|(&type_index, &bytes)| (type_index, bytes >> 10)) - .collect::>(), - ); - assert_eq!(in_place, 0, "a creation call made a block of images itself"); - // Four blocks of 17 MiB: the fewest that come to 64 MiB or more. - let worth = 4 * SMALL_BLOCK; - assert!( - !most_ahead.is_empty() && most_ahead.values().all(|&most| most == worth), - "a pool of images kept other than a block's worth ahead: {most_ahead:?} bytes by memory \ - type" - ); -} - -/// The textures of a pool of small blocks pack as many to a block as their texels' bytes fill: -/// four `RGBA8Unorm` textures of 1024 x 1024 (4 MiB of texels each, a quarter of the 16 MiB a -/// small block is made of, `memory::PLAIN_BLOCK_SLACK`) to a block, whatever metadata the -/// driver's image carries past its texels: RADV's take about 4 MiB and 16 KiB at an alignment of -/// 64 KiB, three to a block of 16 MiB. The run makes [`PACKED`] of them, one at a time, and counts -/// the pool's blocks of images, printing each image's bytes and alignment as the driver asked -/// them. -#[test] -fn small_blocks_hold_four_textures_of_a_quarter_block_each() { +fn a_block_of_images_holds_four_textures_of_a_quarter_block_each() { let scratch = Scratch::new("pack"); - let device = small_blocks_device(&scratch); + let device = device(&scratch.0); let start = device.work_counts(); let mut held: Vec = Vec::new(); for _ in 0..PACKED { - texture(&device, (TEXTURE_SIDE, TEXTURE_SIDE), &mut held); + texture(&device, (PACKED_SIDE, PACKED_SIDE), &mut held); } let counts = device.work_counts(); let made = (counts.image_blocks_made_ahead + counts.image_blocks_made_in_place) @@ -375,103 +283,22 @@ fn small_blocks_hold_four_textures_of_a_quarter_block_each() { let placements = memory.image_placements.clone(); drop(memory); println!( - "BLOCKS-AHEAD {}: {PACKED} textures of 1024 x 1024 in pooled blocks of {sizes:?} bytes, \ - {made} added since the first texture: {used} hold a texture; images placed by bytes and \ - alignment {placements:?}", + "BLOCKS-AHEAD {}: {PACKED} textures of {PACKED_SIDE} x {PACKED_SIDE} in pooled blocks of \ + {sizes:?} bytes, {made} added since the first texture: {used} hold a texture; images \ + placed by bytes and alignment {placements:?}", device.name(), ); assert!( used <= PACKED / 4, - "{PACKED} textures of a quarter of a small block lie in {used} blocks, not {}", + "{PACKED} textures of a quarter of a block lie in {used} blocks, not {}", PACKED / 4 ); } -/// The textures `small_blocks_hold_four_textures_of_a_quarter_block_each` makes. -const PACKED: usize = 16; - -/// A pool of small blocks whose placements larger than its blocks, each taking a block of its -/// own size (`memory::pooled_block_bytes`), are recent keeps a block of that size made ahead -/// too, which the calls that need one of the pool's own blocks leave to them: the first such -/// placement waits for the ready thread's making of its block, each later one finds its block -/// made, and a burst of the pool's own blocks' textures that outruns their makings leaves it made; -/// no creation call makes a block itself. What the pool holds made is read before each of those -/// placements, not the device's count of waits, which counts other pools' blocks too. -#[test] -fn placements_past_a_pool_s_small_blocks_find_a_block_of_their_size_made_ahead() { - let scratch = Scratch::new("large-blocks"); - let device = small_blocks_device(&scratch); - let shared = device.shared(); - let large_block = 2 * SMALL_BLOCK; - let made = || crate::device::lock(&shared.memory).ahead_made(Holds::Images); - let start = device.work_counts(); - let mut held: Vec = Vec::new(); - let mut missed = Vec::new(); - // One texture at a time, every making it started ended before the next. - for at in 0..LARGE_EVERY * LARGE_TEXTURES { - let large = at % LARGE_EVERY == LARGE_EVERY - 1; - if large && at >= LARGE_EVERY && !made().contains(&large_block) { - missed.push(at); - } - let sides = match large { - true => LARGE_SIDES, - false => (TEXTURE_SIDE, TEXTURE_SIDE), - }; - texture(&device, sides, &mut held); - } - let before_burst = made(); - // Back to back with a use of the queues held open, so that a making of the pool's own blocks - // waits for a pause the use never leaves unless a call hurries it: the calls that find none of - // them made leave the block of 34 MiB made. - let after_burst = { - let _in_use = InUse::new(&shared.queue_quiet); - for _ in 0..BURST { - let mut descriptor = TextureDescriptor::texture_2d( - PixelFormat::RGBA8Unorm, - TEXTURE_SIDE, - TEXTURE_SIDE, - false, - ); - descriptor.usage = TextureUsage::SHADER_READ | TextureUsage::RENDER_TARGET; - descriptor.resource_options = ResourceOptions::private(); - held.push(device.new_texture(&descriptor).unwrap()); - } - made() - }; - makings_ended(&device); - let counts = device.work_counts(); - let in_place = counts.image_blocks_made_in_place - start.image_blocks_made_in_place; - let sizes = crate::device::lock(&shared.memory).pooled_block_sizes(Holds::Images); - let mib = |sizes: &[u64]| sizes.iter().map(|size| size >> 20).collect::>(); - println!( - "BLOCKS-AHEAD {}: {} textures, one of 20 MiB every {LARGE_EVERY} then {BURST} back to \ - back, in blocks of {} KiB; blocks of images made ahead {}, in place {in_place}; the 20 \ - MiB textures after the first found no block of 34 MiB made at {missed:?}; made ahead \ - before the burst {:?} MiB, after it {:?} MiB; the pool's blocks {:?} MiB", - device.name(), - held.len(), - SMALL_BLOCK >> 10, - counts.image_blocks_made_ahead - start.image_blocks_made_ahead, - mib(&before_burst), - mib(&after_burst), - mib(&sizes), - ); - assert_eq!(in_place, 0, "a creation call made a block of images itself"); - assert_eq!( - sizes.iter().filter(|&&size| size == large_block).count(), - LARGE_TEXTURES, - "the 20 MiB textures did not each take a block of 34 MiB" - ); - assert!( - missed.is_empty(), - "20 MiB textures found no block of 34 MiB made ahead at {missed:?}" - ); - assert!( - after_burst.contains(&large_block), - "the burst's calls took the block of 34 MiB made ahead: {:?} MiB", - mib(&after_burst) - ); -} +/// The textures `a_block_of_images_holds_four_textures_of_a_quarter_block_each` makes, and their +/// side. +const PACKED: usize = 8; +const PACKED_SIDE: u64 = 2048; /// The sizes of the mixed-sizes run's `RGBA8Unorm` textures, in turn: six of 4 MiB, one of /// 14.1 MiB (2560 x 1440) and one of 31.6 MiB (3840 x 2160), as `tests::reclaim_submit_bench`'s @@ -494,56 +321,19 @@ const MIXED_ROUNDS: usize = 4; /// for a making they started themselves (textures 8, 16 and 24) while the pool's blocks made /// ahead were counted by whole blocks of room, and on a Radeon 780M /// `tests::reclaim_submit_bench`'s mixed arm waited for 8 of its 13 blocks of images in its quiet -/// phase. Where the device's makings were slow and its blocks of images were made smaller -/// (`Memory::plain_block_made`, lavapipe), the first texture larger than them waits for its -/// block of its own size, which nothing foretold -/// (`placements_past_a_pool_s_small_blocks_find_a_block_of_their_size_made_ahead`); no other. +/// phase. #[test] fn mixed_sizes_find_their_blocks_made_ahead() { - mixed_sizes(None); -} - -/// As `mixed_sizes_find_their_blocks_made_ahead`, the device told of a slow making -/// (`Memory::plain_block_made`) before the run's fourth texture, while its pool of images fills -/// its first block of 64 MiB: its blocks of images made smaller from then on, the pool keeps its -/// next block made ahead as it did for the block it fills (`Pool::ahead_room`). By three quarters -/// of a small block, a Radeon 780M's pool, its 64 MiB block left with 12.4 MiB, kept none ahead, -/// and its next texture of 2560 x 1440 (15.1 MiB) waited for its block (texture 11, two runs of -/// two), as it did in the memory tests' runs where a slow making of the host's came that early. -#[test] -fn mixed_sizes_after_blocks_made_smaller_find_their_blocks_made_ahead() { - mixed_sizes(Some(SMALLER_AT)); -} - -/// The texture of the mixed-sizes run before which -/// `mixed_sizes_after_blocks_made_smaller_find_their_blocks_made_ahead` tells the device of a slow -/// making. -const SMALLER_AT: usize = 4; - -/// The mixed-sizes run (`mixed_sizes_find_their_blocks_made_ahead`), the device told of a slow -/// making before texture `smaller_at` where given. -fn mixed_sizes(smaller_at: Option) { - let scratch = Scratch::new(match smaller_at { - Some(_) => "mixed-smaller", - None => "mixed", - }); + let scratch = Scratch::new("mixed"); let device = device(&scratch.0); let shared = device.shared(); let ahead = || crate::device::lock(&shared.memory).ahead_blocks(); - let plain = || crate::device::lock(&shared.memory).plain_block_bytes(); let mut held: Vec = Vec::new(); texture(&device, MIXED_SIDES[0], &mut held); let start = ahead(); - let (mut waits, mut first_large) = (Vec::new(), None); + let mut waits = Vec::new(); for at in 1..MIXED_SIDES.len() * MIXED_ROUNDS { - if smaller_at == Some(at) { - let mut memory = crate::device::lock(&shared.memory); - memory.plain_block_made(BLOCK_BYTES, MAKING_BOUND * 4); - } let (width, height) = MIXED_SIDES[at % MIXED_SIDES.len()]; - if first_large.is_none() && width * height * 4 > plain() { - first_large = Some(at); - } let before = ahead().images_waited_for; texture(&device, (width, height), &mut held); let after = ahead(); @@ -568,13 +358,14 @@ fn mixed_sizes(smaller_at: Option) { let end = ahead(); let blocks = (end.images_ahead + end.images_in_place) - (start.images_ahead + start.images_in_place); + let sizes = crate::device::lock(&shared.memory).pooled_block_sizes(Holds::Images); println!( - "BLOCKS-AHEAD {}: {} textures of mixed sizes in blocks of {} MiB; after the first, {blocks} \ - blocks of images, {} made ahead, {} waited for (at textures {waits:?}; the first larger \ - than the blocks {first_large:?}), {} in place", + "BLOCKS-AHEAD {}: {} textures of mixed sizes in blocks of {:?} KiB; after the first, \ + {blocks} blocks of images, {} made ahead, {} waited for (at textures {waits:?}), {} in \ + place", device.name(), held.len(), - plain() >> 20, + sizes.iter().map(|size| size >> 10).collect::>(), end.images_ahead - start.images_ahead, end.images_waited_for - start.images_waited_for, end.images_in_place - start.images_in_place, @@ -583,12 +374,9 @@ fn mixed_sizes(smaller_at: Option) { end.images_in_place, start.images_in_place, "a creation call made a block of images itself" ); - let unforetold: Vec = (waits.iter().copied()) - .filter(|&at| Some(at) != first_large) - .collect(); assert!( - unforetold.is_empty(), - "creation calls waited for a block of images at textures {unforetold:?}" + waits.is_empty(), + "creation calls waited for a block of images at textures {waits:?}" ); } @@ -613,8 +401,7 @@ impl Drop for InUse<'_> { /// submissions to end cuts that wait short and waits for the block's allocation alone. Each attempt /// starts once every making ended, so that the pool's next making is a new one, which waits for /// quiet: a pool's thread makes the blocks queued while it runs one after another with no wait of -/// their own, and on an RTX 5080 (its blocks made of 16 MiB after a slow making, two of the -/// test's buffers to a block) creation calls back to back beside the runtime suite's first half +/// their own, and on an RTX 5080 creation calls back to back beside the runtime suite's first half /// kept its one thread making through up to 235 calls, and through [`MOST`] beside both halves. #[test] fn a_creation_that_needs_a_block_whose_making_waits_for_quiet_waits_for_its_allocation_alone() { diff --git a/crates/metal2vulkan-runtime/src/tests/mod.rs b/crates/metal2vulkan-runtime/src/tests/mod.rs index 80d02fe20..8e778ab3a 100644 --- a/crates/metal2vulkan-runtime/src/tests/mod.rs +++ b/crates/metal2vulkan-runtime/src/tests/mod.rs @@ -40,6 +40,8 @@ mod blit_holds; mod blit_order; mod blit_plan; #[cfg(any(m2v_gpu, m2v_cpu_icd))] +mod block_fills; +#[cfg(any(m2v_gpu, m2v_cpu_icd))] mod blocks_ahead; #[cfg(any(m2v_gpu, m2v_cpu_icd))] mod buffer_tail_device; @@ -356,7 +358,6 @@ mod pipeline; mod pipeline_wait_order; #[cfg(unix)] mod pixel_format_info; -mod plain_blocks; #[cfg(any(m2v_gpu, m2v_cpu_icd))] mod point_size_notices; #[cfg(all(any(m2v_gpu, m2v_cpu_icd), target_os = "linux"))] diff --git a/crates/metal2vulkan-runtime/src/tests/plain_blocks.rs b/crates/metal2vulkan-runtime/src/tests/plain_blocks.rs deleted file mode 100644 index 9382fa118..000000000 --- a/crates/metal2vulkan-runtime/src/tests/plain_blocks.rs +++ /dev/null @@ -1,219 +0,0 @@ -//! A device whose making of a block of plain memory took longer than `memory::MAKING_BOUND` makes -//! its later pooled blocks of plain memory of the largest power of two that making's rate makes -//! within the bound with a sixteenth of it besides (`memory::PLAIN_BLOCK_SLACK`), the power of -//! two down to `memory::MIN_PLAIN_BLOCK_BYTES` (`Memory::plain_block_made`): on RADV such a -//! making holds every submission of the process for as long as it runs. A placement larger than -//! such a block, up to half of `memory::BLOCK_BYTES`, takes a block of the least power of two so -//! made that holds it, and the blocks of exportable buffers keep their size. -//! -//! The first two tests are of the memory's bookkeeping alone. The third makes textures on a device -//! told of a slow making and reads the sizes of the blocks of images it made: device tests compile -//! only under the GPU safety cfgs (`m2v_gpu`, `m2v_cpu_icd`). - -use crate::memory::{pooled_block_bytes, Memory, BLOCK_BYTES, MAKING_BOUND, MIN_PLAIN_BLOCK_BYTES}; -use ash::vk; -use std::time::Duration; - -const MIB: u64 = 1 << 20; - -/// The memory of a device of one host-visible memory type, whose largest allocation is -/// `max_allocation` bytes. -fn memory_of(max_allocation: u64) -> Memory { - let mut properties = vk::PhysicalDeviceMemoryProperties { - memory_type_count: 1, - memory_heap_count: 1, - ..Default::default() - }; - properties.memory_types[0] = vk::MemoryType { - property_flags: vk::MemoryPropertyFlags::DEVICE_LOCAL - | vk::MemoryPropertyFlags::HOST_VISIBLE - | vk::MemoryPropertyFlags::HOST_COHERENT, - heap_index: 0, - }; - properties.memory_heaps[0] = vk::MemoryHeap { - size: 8 << 30, - flags: vk::MemoryHeapFlags::DEVICE_LOCAL, - }; - Memory::new( - &properties, - max_allocation, - false, - true, - vec![0], - None, - None, - ) -} - -#[test] -fn a_making_past_the_bound_makes_the_later_plain_blocks_of_what_its_rate_makes_within_it() { - let ms = |micros: u64| Duration::from_micros(micros); - let mut memory = memory_of(u64::MAX); - assert_eq!(memory.plain_block_bytes(), BLOCK_BYTES); - // A making within the bound leaves the size. - memory.plain_block_made(BLOCK_BYTES, MAKING_BOUND); - assert_eq!(memory.plain_block_bytes(), BLOCK_BYTES); - // 64 MiB in 9.6 ms (a Radeon 780M's slowest on a quiet host, the kernel's page pools empty) - // makes 53 MiB in the bound: blocks of 32 MiB and 2 MiB. - memory.plain_block_made(BLOCK_BYTES, ms(9_600)); - assert_eq!(memory.plain_block_bytes(), 32 * MIB); - // A fast making never makes them larger again, nor a slow one whose rate makes more. - memory.plain_block_made(32 * MIB, Duration::ZERO); - assert_eq!(memory.plain_block_bytes(), 32 * MIB); - memory.plain_block_made(4 * BLOCK_BYTES, MAKING_BOUND * 2); - assert_eq!(memory.plain_block_bytes(), 32 * MIB); - // A dedicated block of an odd size: 48 MiB in twice the bound makes 24 MiB in it. - memory.plain_block_made(48 * MIB, MAKING_BOUND * 2); - assert_eq!(memory.plain_block_bytes(), 16 * MIB); - // A power of two the rate makes within the bound whose sixteenth besides it does not: 64 MiB - // in twice the bound makes 32 MiB in it, and a block of 32 MiB and 2 MiB would pass it. - let mut edge = memory_of(u64::MAX); - edge.plain_block_made(BLOCK_BYTES, MAKING_BOUND * 2); - assert_eq!(edge.plain_block_bytes(), 16 * MIB); - // Never below the least. - memory.plain_block_made(MIN_PLAIN_BLOCK_BYTES, MAKING_BOUND * 100); - assert_eq!(memory.plain_block_bytes(), MIN_PLAIN_BLOCK_BYTES); - // 64 MiB in 23.1 ms (the 780M's median with its free memory in single pages) makes 22 MiB in - // the bound: one such making takes the blocks to 16 MiB. - let mut fragmented = memory_of(u64::MAX); - fragmented.plain_block_made(BLOCK_BYTES, ms(23_100)); - assert_eq!(fragmented.plain_block_bytes(), 16 * MIB); - // A device whose largest allocation is below the least keeps its blocks of that size. - let mut small = memory_of(4 * MIB); - small.plain_block_made(4 * MIB, MAKING_BOUND * 100); - assert_eq!(small.plain_block_bytes(), 4 * MIB); -} - -#[test] -fn a_pooled_block_holds_its_placement_and_exportable_blocks_keep_their_size() { - let plain = Some(16 * MIB); - // Blocks of 16 MiB and a sixteenth: four images of 4 MiB of texels and up to 256 KiB of - // metadata and alignment each. - assert_eq!(pooled_block_bytes(BLOCK_BYTES, plain, 0), 17 * MIB); - assert_eq!(pooled_block_bytes(BLOCK_BYTES, plain, MIB), 17 * MIB); - assert_eq!(pooled_block_bytes(BLOCK_BYTES, plain, 17 * MIB), 17 * MIB); - assert_eq!( - pooled_block_bytes(BLOCK_BYTES, plain, 17 * MIB + 1), - 34 * MIB - ); - assert_eq!( - pooled_block_bytes(BLOCK_BYTES, plain, BLOCK_BYTES / 2), - 34 * MIB - ); - // A largest allocation that is no power of two bounds the block. - assert_eq!(pooled_block_bytes(48 * MIB, plain, 20 * MIB), 34 * MIB); - assert_eq!(pooled_block_bytes(33 * MIB, plain, 20 * MIB), 33 * MIB); - assert_eq!( - pooled_block_bytes(48 * MIB, Some(48 * MIB), 20 * MIB), - 48 * MIB - ); - // Blocks of plain memory not made smaller keep the block's size, with no sixteenth besides. - assert_eq!( - pooled_block_bytes(BLOCK_BYTES, Some(BLOCK_BYTES), MIB), - BLOCK_BYTES - ); - // The blocks of exportable buffers. - assert_eq!(pooled_block_bytes(BLOCK_BYTES, None, MIB), BLOCK_BYTES); -} - -#[cfg(any(m2v_gpu, m2v_cpu_icd))] -mod device { - use super::{BLOCK_BYTES, MAKING_BOUND, MIB, MIN_PLAIN_BLOCK_BYTES}; - use crate::memory::Holds; - use crate::tests::freed_memory::device; - use crate::{Device, ResourceOptions, Texture, TextureDescriptor}; - use metal2vulkan::metal::{PixelFormat, TextureUsage}; - - /// The textures each run makes at most before the image pool makes the block it waits for. - const MOST: usize = 256; - - /// A pooled block of plain memory of the least size: 16 MiB and a sixteenth. - const SMALL_BLOCK: u64 = MIN_PLAIN_BLOCK_BYTES + MIN_PLAIN_BLOCK_BYTES / 16; - - /// A `Private` `RGBA8Unorm` texture of `width` by `height`, sampled and rendered to. - fn texture(device: &Device, width: u64, height: u64) -> Texture { - let mut descriptor = - TextureDescriptor::texture_2d(PixelFormat::RGBA8Unorm, width, height, false); - descriptor.usage = TextureUsage::SHADER_READ | TextureUsage::RENDER_TARGET; - descriptor.resource_options = ResourceOptions::private(); - device.new_texture(&descriptor).unwrap() - } - - /// The device's pooled blocks of images, by size. - fn image_blocks(device: &Device) -> Vec { - let mut sizes = - crate::device::lock(&device.shared().memory).pooled_block_sizes(Holds::Images); - sizes.sort_unstable(); - sizes - } - - /// The blocks in `after` that `before` does not hold, as many times as they are more. - fn new_blocks(before: &[u64], after: &[u64]) -> Vec { - let mut left = before.to_vec(); - (after.iter()) - .filter(|size| match left.iter().position(|kept| kept == *size) { - Some(at) => { - left.swap_remove(at); - false - } - None => true, - }) - .copied() - .collect() - } - - /// Make textures of `width` by `height` until the device made a block of images of more than - /// `past` bytes: the blocks made meanwhile. - fn until_a_block( - device: &Device, - (width, height): (u64, u64), - past: u64, - held: &mut Vec, - ) -> Vec { - let before = image_blocks(device); - for _ in 0..MOST { - held.push(texture(device, width, height)); - let made = new_blocks(&before, &image_blocks(device)); - if made.iter().any(|&size| size > past) { - return made; - } - } - panic!("{MOST} textures of {width} x {height} made no block of images past {past} bytes"); - } - - #[test] - fn textures_after_a_slow_making_lie_in_smaller_blocks_or_one_that_holds_them() { - let scratch = std::env::temp_dir().join(format!("m2v-plain-blocks-{}", std::process::id())); - std::fs::create_dir_all(&scratch).unwrap(); - let device = device(&scratch); - { - // A pooled block's making that took four times the bound. - let mut memory = crate::device::lock(&device.shared().memory); - memory.plain_block_made(BLOCK_BYTES, MAKING_BOUND * 4); - assert_eq!(memory.plain_block_bytes(), MIN_PLAIN_BLOCK_BYTES); - } - let mut held = Vec::new(); - // 1 MiB textures: blocks of the least size, 16 MiB and a sixteenth. - let small = until_a_block(&device, (512, 512), 0, &mut held); - // 20 MiB ones: past that size, a block of 32 MiB and a sixteenth each. - let large = until_a_block(&device, (2560, 2048), SMALL_BLOCK, &mut held); - println!( - "PLAIN-BLOCKS {}: after a slow making, 1 MiB textures made blocks of images of {:?} \ - MiB, 20 MiB ones {:?} MiB", - device.name(), - small.iter().map(|size| size / MIB).collect::>(), - large.iter().map(|size| size / MIB).collect::>(), - ); - assert!( - small.iter().all(|&size| size == SMALL_BLOCK), - "1 MiB textures made blocks of {small:?} bytes" - ); - assert!( - large.contains(&(34 * MIB)) && large.iter().all(|&size| size <= 34 * MIB), - "20 MiB textures made blocks of {large:?} bytes" - ); - drop(held); - drop(device); - let _ = std::fs::remove_dir_all(&scratch); - } -} diff --git a/crates/metal2vulkan-runtime/src/tests/reclaim_submit_bench.rs b/crates/metal2vulkan-runtime/src/tests/reclaim_submit_bench.rs index f636484f1..0a3ef3a5c 100644 --- a/crates/metal2vulkan-runtime/src/tests/reclaim_submit_bench.rs +++ b/crates/metal2vulkan-runtime/src/tests/reclaim_submit_bench.rs @@ -54,8 +54,8 @@ //! [`IMAGE_TEXTURES`] a phase: the runtime's pool of images grows, its blocks made ahead //! (`memory/ready.rs`), plain blocks whose making holds the device's submissions on RADV. //! - **Images of mixed sizes, made by the runtime**: the same, in turn the sizes of -//! [`MIXED_SIDES`] (a frame's textures and two screen-sized ones, larger than a small block), at -//! most [`MIXED_TEXTURES`] a phase. +//! [`MIXED_SIDES`] (a frame's textures and two screen-sized ones), at most [`MIXED_TEXTURES`] a +//! phase. //! - **Images in bursts, made by the runtime**: the images arm's textures, [`BURST`] back to back //! every [`BURST_EVERY`], at most [`IMAGE_TEXTURES`] a phase: a burst needs more blocks than one, //! as a scroll's new tiles do. @@ -63,12 +63,6 @@ //! [`SCROLL_WINDOW`] newest released as it is made, as a scroll releases the tiles it left //! behind: the oldest blocks empty as the newest fill, so that the phase's churn shows what an //! emptied block costs, kept for the next placements, freed once it stayed empty, or made again. -//! - **Images, small blocks**, **Images of mixed sizes, small blocks**, **Images in bursts, -//! small blocks** and **Images scrolled, small blocks**: those four arms on a device told first of a slow making -//! (`Memory::plain_block_made`, as `tests::plain_blocks` tells it), so that its pooled blocks of -//! plain memory are 17 MiB from the start, as a host whose makings were slow made them (a -//! consumer's guest on a fragmented Radeon 780M). A liberty: the device made no such making; -//! the arms ask what the runtime does once its blocks are that small, whatever the host. //! - **System heap, 64 MiB**, **System heap, 16 MiB** and **System heap, 4 MiB**: allocations of //! the device's first memory type that is host-visible and host-coherent but not device-local or //! cached (where a unified-memory device's `Private` blocks lie, `memory.rs`, `candidates`), of @@ -192,8 +186,7 @@ const SCROLL_EVERY: Duration = Duration::from_millis(30); const IMAGE_SIDE: u64 = 1024; const IMAGE_EVERY: Duration = Duration::from_micros(16_667); const IMAGE_TEXTURES: usize = 192; -/// The burst arm's textures back to back (64 MiB of texels, four blocks of 17 MiB), and the gap -/// between bursts. +/// The burst arm's textures back to back (64 MiB of texels), and the gap between bursts. const BURST: usize = 16; const BURST_EVERY: Duration = Duration::from_millis(500); /// The scrolled arm's live textures: three bursts' (192 MiB of texels). @@ -999,20 +992,9 @@ enum Arm { /// Run the arm `label` (the module docs). fn arm(label: &str, arm: Arm) { - arm_with(label, arm, false); -} - -/// Run the arm `label` (the module docs), on a device told first of a pooled block's making that -/// took four times `memory::MAKING_BOUND` where `small` (`Memory::plain_block_made`), so that its -/// pooled blocks of plain memory are of the least size from the start. -fn arm_with(label: &str, arm: Arm, small: bool) { use vk::MemoryPropertyFlags as P; let scratch = Scratch::new(); let device = device(&scratch.0); - if small { - let mut memory = crate::device::lock(&device.shared().memory); - memory.plain_block_made(crate::memory::BLOCK_BYTES, crate::memory::MAKING_BOUND * 4); - } if device.shared().host_import.is_err() { eprintln!("RECLAIM-SUBMIT: the device imports no host memory here: not run"); return; @@ -1115,10 +1097,6 @@ fn arm_with(label: &str, arm: Arm, small: bool) { &mut made, ); buddies("after the pressed phase"); - eprintln!( - "RECLAIM-SUBMIT {label}: pooled blocks of plain memory made of {} MiB at the end", - crate::device::lock(&device.shared().memory).plain_block_bytes() >> 20 - ); drop(pressing); drop((source, middle, out, made.buffers, made.textures)); for memory in made.raw { @@ -1581,34 +1559,6 @@ fn reclaim_submit_bench_images_scrolled() { arm("images scrolled, made by the runtime", Arm::ImagesScrolled); } -#[test] -#[ignore = "a measurement that presses the host's memory: run alone on its host by name"] -fn reclaim_submit_bench_images_small_blocks() { - let label = "images, made by the runtime, small blocks"; - arm_with(label, Arm::Images, true); -} - -#[test] -#[ignore = "a measurement that presses the host's memory: run alone on its host by name"] -fn reclaim_submit_bench_images_mixed_small_blocks() { - let label = "images of mixed sizes, made by the runtime, small blocks"; - arm_with(label, Arm::ImagesMixed, true); -} - -#[test] -#[ignore = "a measurement that presses the host's memory: run alone on its host by name"] -fn reclaim_submit_bench_images_bursts_small_blocks() { - let label = "images in bursts, made by the runtime, small blocks"; - arm_with(label, Arm::ImagesBursts, true); -} - -#[test] -#[ignore = "a measurement that presses the host's memory: run alone on its host by name"] -fn reclaim_submit_bench_images_scrolled_small_blocks() { - let label = "images scrolled, made by the runtime, small blocks"; - arm_with(label, Arm::ImagesScrolled, true); -} - #[test] #[ignore = "a measurement that presses the host's memory: run alone on its host by name"] fn reclaim_submit_bench_exportable() { diff --git a/docs/FAST-PATHS.md b/docs/FAST-PATHS.md index dc092b680..2c483fedf 100644 --- a/docs/FAST-PATHS.md +++ b/docs/FAST-PATHS.md @@ -962,9 +962,9 @@ driver's. Each is open work. for each command buffer. Metal's command buffers wait for no such making. Not announced. - **On NVIDIA, a command buffer submitted while the runtime makes or frees a memory block completes as that call ends; emptied blocks are kept so that a returning working set makes none again.** - The runtime's memory blocks (`memory.rs`: pooled blocks of 64 MiB, or smaller where a making - took longer than 8 ms (the row on plain blocks below), blocks of their own for placements past - half of 64 MiB, and the blocks exportable buffers share) are made with + The runtime's memory blocks (`memory.rs`: pooled blocks of 64 MiB, 68 MiB for images (the row on + plain blocks below), blocks of their own for placements past half of 64 MiB, and the blocks + exportable buffers share) are made with `vkAllocateMemory` and freed with `vkFreeMemory`, which hold every submission on NVIDIA's driver (the row above has their times). A block that empties is kept for the next placements: past its pool's two pooled ones, while the empty blocks kept in its heap stay within an eighth of the @@ -988,22 +988,17 @@ driver's. Each is open work. clip still makes its blocks: 16 allocations, against 44 when each picture had an allocation of its own, with 3 to 5 commits waiting 1 ms or more (longest 10.9 to 19.6 ms): its blocks' `vkAllocateMemory` holds every submission. A pool that grew, and one near its next block (it - holds a pooled block and lacks room for three quarters of one, of the largest it holds, its first - growth among them), gets - a block's worth of bytes made ahead (`memory/ready.rs`; the pools of exportable buffers, which - hold the pictures, among them): as many of its blocks as come to one 64 MiB block or more - (four of 17 MiB in a plain pool of smaller blocks), and while its - placements larger than a plain pool's smaller blocks are recent, one block of their size - besides, one `vkAllocateMemory` each, right after a burst of the device's submissions ended. - Its own blocks are counted in bytes with its free room: they are made again once those made - ahead and its room come to less than a block's worth, a placement of a quarter of a block or - more starting their making at once rather than at the next creation call. A - creation call that needs one while its making still waits for that end makes it at once and - waits for it, as for a block made in place, and one that finds none of its size made waits for - the ready thread to make it first. A pool near its next block keeps those blocks at rest for as - long as it stays so: 64 MiB a pool at most (68 MiB of 17 MiB blocks), and one block of its - large placements' size more (34 MiB) while those are recent, counted against the kept empty blocks' budget. Metal's command buffers wait for no allocation. Not - announced. + holds a pooled block and lacks room for three quarters of one, its first growth among them), + gets one block made ahead (`memory/ready.rs`; the pools of exportable buffers, which hold the + pictures, among them), one `vkAllocateMemory`, right after a burst of the device's submissions + ended. It is counted in bytes with the pool's free room: made again once the block made ahead + and that room come to less than a block, a placement of a quarter of a block or more starting + its making at once rather than at the next creation call. A creation call that needs one while + its making still waits for that end makes it at once and waits for it, as for a block made in + place, and one that finds none made waits for the ready thread to make it first. A pool near its + next block keeps that block at rest for as long as it stays so, 64 MiB a pool at most (68 MiB + for images), counted against the kept empty blocks' budget. Metal's command buffers wait for no + allocation. Not announced. - **With unified memory, `Private` memory lies in the system heap's types before the device-local ones, its buffers' blocks there allocated exportable but for buffers that declare their padding unobserved: about 1 µs a submission for each such block held.** Where the device has unified memory and a heap that is not @@ -1075,59 +1070,72 @@ driver's. Each is open work. every type is device-local (ANV, MoltenVK, lavapipe) and those without unified memory place as before, in plain blocks. No switch: no answer of Metal's changes. Not announced. - **On RADV, a command buffer submitted while the runtime makes a block of plain memory waits for - that making; a device whose making of such a block took longer than 8 ms makes its later - pooled ones smaller, down to 17 MiB.** A block allocated with no export (`memory.rs`: the + that making; pooled blocks stay 64 MiB.** A block allocated with no export (`memory.rs`: the blocks of images, of heaps, of buffers that declare their padding unobserved, and of every buffer where the device's buffers lie in plain blocks; not the runtime's own pages, which it imports) shares the reservation of the process's buffer objects on RADV, and its `vkAllocateMemory` holds every submission of the process while the kernel fills its pages (the - row above). Where such a making (`vkAllocateMemory`, its mapping and its buffer of addresses) - takes longer than `MAKING_BOUND` (8 ms, half a frame at 60 Hz), the device's later pooled - blocks of plain memory are made of the largest power of two that making's rate makes within - it with a sixteenth of it besides (`PLAIN_BLOCK_SLACK`), the power of two at least - `MIN_PLAIN_BLOCK_BYTES` (16 MiB, so 17 MiB blocks; `Memory::plain_block_made`), and a - placement larger than such a block, up to 32 MiB, takes a pooled block of the least power of - two so made that holds it (34 MiB); past 32 MiB it takes a block of its own where no pooled block has room, as before, which - smaller blocks have less often. The size is never made larger again, after a single slow - making too (a host's passing load): the rule follows each device's own makings, on every - driver. On a Radeon 780M (RADV PHOENIX, Mesa 26.2.6), the kernel's page pools emptied before - each run (through debugfs, the measurement's method alone: with freed pages in them a block - of 16 to 64 MiB took 0.1 to 0.3 ms), a `Private` texture made every 16.7 ms beside a command - buffer committed about every millisecond (`tests::reclaim_submit_bench`, two runs of each arm - against the base, interleaved): with 1024x1024 textures, the base's 64 MiB blocks took 9.4 and - 9.8 ms at the median on a quiet host and 26.6 and 12.7 ms on one whose free memory lay in - single pages (the slowest 38.5 ms), and left 13 and 13 turnarounds of 8 ms or more a phase on - each (8 and 4 of 17 ms or more on the second, the slowest 40.0 ms); the rule took the blocks to - 32 MiB after the first making (5.3 ms at the median) and to 16 MiB on the fragmented host (3.6 - and 3.1 ms, the slowest 12.4 ms), and left 0 and 0 on the quiet host and 16 and 7 on the - fragmented one, none of 17 ms or more (the slowest 14.3 ms); the slowest creation call took 0.6 - and 3.4 ms there against 24.9 and 22.9 ms. With a frame's textures mixed with 2560x1440 and - 3840x2160 ones, 1 and 0 against 14 and 14 on the quiet host, and 14 and 11 (none of 17 ms or - more, the slowest 16.0 ms) against 13 and 13 (9 and 5, the slowest 32.3 ms) on the fragmented - one; each 3840x2160 texture, a little over 32 MiB, took a block of its own made on its - creating thread (12 a phase, 10.4 and 11.4 ms at the median on the fragmented host), where the - base placed it in the room of a 64 MiB block, and the slowest creation call took 16.4 and 15.6 - ms against 26.2 and 26.1 ms. The 16 MiB makings that still took 8 ms or more are the host's - fragmentation at the least size. The trade: more allocations, 26 a phase on the quiet host and - 60 on the fragmented one where the base made 13, each a `VkDeviceMemory` the device's - `maxMemoryAllocationCount` counts (Vulkan's least is 4096, 68 GiB of 17 MiB blocks), and a - texture between 17 and 34 MiB takes a block of 34 MiB. On the 780M - `vkQueueSubmit` took 0.121 to 0.136 ms each with the rule's 26 to 60 blocks a phase, and 0.119 - to 0.140 ms with the base's 13 (the 1024x1024 arm's phases). Whether a driver that names every - allocation in each submission pays for more blocks is unaudited: ANV and NVIDIA were not - measured with them. A device whose 64 MiB - makings take longer than 8 ms makes its blocks smaller whether or not a making holds its - submissions: NVIDIA's `vkAllocateMemory` takes about 11 ms for 64 MiB (the GPU pool row above, - where it holds every submission too), so its blocks are expected to be 32 MiB there. On the M3 - Max (MoltenVK 1.4.2), over the conformance suite's cost measurement (eight rounds of 1233 - cases), a 64 MiB block took 1.1 ms at the median and 1.6 ms at the slowest, and blocks of their - own of 256 MiB and 1 GiB up to 17 and 21 ms, whose rate keeps 64 MiB: its blocks stayed 64 MiB. - One of 61 makings of 64 MiB took 8.15 ms among tests that press the host's memory, which takes - that device's blocks to 32 MiB. So the conformance suite's cost gate reports - `device_memory_allocated` and no longer gates it: with the size held at 16 MiB, that cost - measurement moved its gated bound in one case (192 MiB to 48 MiB) and none of - `pooled_memory_blocks_made`'s, which stays gated. No switch: no answer of Metal's changes. Not - announced. + row above), unless the next row's fill left those pages at hand. Pooled blocks are 64 MiB on + every device, and a block of images 68 MiB: a sixteenth besides (`IMAGE_BLOCK_SLACK`), since a + driver's image takes more than its texels (RADV on a Radeon 780M and ANV on an Iris Xe place a + `Private` `RGBA8Unorm` texture of 1024x1024 in 4 MiB and 16 KiB, at an alignment of 64 KiB), so + that four images of a quarter of a block fit in one. On a Radeon 780M (RADV PHOENIX, Mesa + 26.2.6), the kernel's page pools emptied before each run (through debugfs, the measurement's + method alone: with freed pages in them a block of 16 to 64 MiB took 0.1 to 0.3 ms), a `Private` + texture made every 16.7 ms beside a command buffer committed about every millisecond + (`tests::reclaim_submit_bench`, two runs of each arm), a 64 MiB making took 10 to 12 ms on a + quiet host and 10 to 31 ms on one whose free memory lay in single pages, 90 to 96% of it on a + CPU inside `vkAllocateMemory` (the kernel's page allocation, clearing and compaction; its + mapping 0.02 to 0.1 ms), and each held the submissions as long: with textures of 1024x1024, of + mixed sizes and in bursts, 12 to 14 turnarounds of 8 ms or more a phase (up to 5 of 17 ms or + more, the slowest 32.1 ms), 13 to 15 makings a phase holding 125 to 201 ms in all. Smaller + blocks shorten each hold and add makings: with blocks of 17 MiB, 0 to 8 turnarounds of 8 ms or + more a phase (none of 17 ms, the slowest 14.5 ms), 45 to 55 makings a phase holding 138 to + 230 ms in all, and each texture past 17 MiB in a block of its own. No switch: no answer of + Metal's changes. Not announced. +- **On RADV on a Radeon 780M, a block of plain memory has its pages filled through an exportable + allocation first, so that its own making holds no submission; this relies on the kernel + recycling freed pages, and is performance only.** On a device whose driver identity carries + `DriverFact::PlainAllocationsHoldSubmissions` (RADV on the Radeon 780M, measured: the row + above) and that exports pooled memory as an opaque file descriptor (`memory.rs`'s + `fd_buffer_types`: the types of a heap that is not device-local, with unified memory), each + pooled block of plain memory of such a type is made after an allocation of its size and type + exportable as an opaque file descriptor, freed at once (`Memory::fill_plain_blocks`, + `BlockMaker::make_as`). That allocation is a buffer object of its own reservation, so the + kernel fills its pages while it holds no submission; its free returns them to amdgpu's TTM page + pool, and the block's own allocation takes them from there. The dependency, plainly: amdgpu + and TTM return a freed buffer object's pages to their pool, which is the kernel's behaviour and + no Vulkan guarantee. Where the kernel hands the block other pages (the pool emptied by its + shrinker, or the pages taken by another allocation meanwhile), the block's allocation fills + them and holds the submissions, a plain making as without the fill; the block is the same + plain block either way. `WorkCounts::plain_block_fills_saved` counts the fills whose block was + then allocated in under 1 ms (`FILL_SAVED_BELOW`), `plain_block_fills_missed` the others, so + a host's runs show whether its kernel recycled the pages. On a Radeon 780M (RADV PHOENIX, Mesa + 26.2.6, Linux 7.3.1), the kernel's page pools emptied before each run, the arms of the row + above, two runs each, without the fill and with it (turnarounds of 8 ms or more a phase, of + 17 ms or more, the slowest, and the makings' `vkAllocateMemory` in all; the makings the same, + 13 to 15 a phase, 3 to 5 in the scrolled arm's quiet phase): + + | Arm, phase | Without: 8 ms, 17 ms, slowest, held | With: 8 ms, 17 ms, slowest, held | + |---|---|---| + | 1024x1024, quiet | 13 and 13, 0, 10.9 ms, 126 to 132 ms | 0 and 0, 0, 1.5 ms, 1.4 ms | + | 1024x1024, fragmented | 13 and 12, 1 and 1, 27.5 ms, 135 to 139 ms | 1 and 0, 0, 8.8 ms, 2.6 to 11.1 ms | + | Bursts, quiet | 12 and 12, 0, 11.2 ms, 125 to 127 ms | 0 and 0, 0, 1.0 ms, 1.7 to 1.8 ms | + | Bursts, fragmented | 13 and 13, 1 and 0, 17.6 ms, 133 to 135 ms | 1 and 0, 0, 13.8 ms, 2.2 to 16.9 ms | + | Mixed sizes, quiet | 13 and 13, 0, 11.6 ms, 136 to 141 ms | 0 and 0, 0, 1.6 ms, 1.5 to 1.6 ms | + | Mixed sizes, fragmented | 13 and 14, 3 and 5, 32.1 ms, 184 to 201 ms | 1 and 2, 0, 9.8 ms, 11.8 to 20.9 ms | + | Scrolled, quiet | 2 and 3, 0, 11.6 ms, 36 to 38 ms | 0 and 0, 0, 1.3 ms, 0.7 ms | + + The turnarounds of 8 ms or more left with the fill are its misses: 1 or 2 makings of a + fragmented phase's 13 or 14 whose block filled its own pages (8.6 to 14.0 ms). The cost is the + making thread's (the ready thread, off every submission's way): the exportable allocation (10 + to 13 ms for 64 MiB) and its free (3.6 to 5.9 ms, clearing the pages for the pool) besides the + block's own, so that a block's making took 45 to 74% longer on the quiet host (about 13.7 ms + against 9.3 ms) and 33 to 96% longer on the fragmented one. The plain making it replaces ran + 90 to 96% on a CPU; how much of the fill's time is on a CPU was not measured apart. Every other + device makes its plain blocks with no fill: lavapipe, ANV on an Iris Xe and NVIDIA's driver + have no such fact. No switch: no answer of Metal's changes. Not announced. + - **Making and releasing an event on NVIDIA take 0.1 to 0.6 ms of the calling thread.** `new_event` and `new_shared_event` each make one timeline semaphore (`vkCreateSemaphore`, `event.rs`), and an event's release destroys it where it goes. On the RTX 5080 Laptop GPU both