rt: blocks are ranges of 16 MiB allocations; the block-maker thread allocates only while a class's free bytes run low

The pool handed a take of up to a block length a whole pooled block and kept one ready block per
class, which the block-maker thread made again as soon as a take used it. A 16-byte Shared buffer
took the ready block, and the 16 MiB allocation that followed held the consumer's next pipeline
creation for its whole length on NVIDIA's driver.

Now each block is a range of one of its class's allocations, with its own VkBuffer:
- A take is a kept block of its length, else the first free range that fits, else the start of an
  allocation made in the call: 16 MiB, or the block's own length where that is longer. Lengths
  round up to 64 KiB (or bufferImageGranularity); a block starts at its length rounded up to a
  power of two, up to 2 MiB.
- Device::new makes one 16 MiB allocation per class. After that, the block-maker thread makes
  another only while the class's free bytes are under 8 MiB. A take never waits on it for memory.
- A take that no free range fits, while the class keeps blocks of other lengths, allocates at once.
  It also asks the block-maker thread to give those blocks' bytes back, after the consumer's hook.
  Only when its own allocation fails does it wait for those bytes, then look for a free range once
  more.
- An allocation holding no live block is idle. A class keeps its idle allocations while their
  bytes plus those of its allocations in use stay at or under the most bytes it had in use over the
  last 10 seconds, and within an eighth of its memory type's heap. Past that it frees the oldest,
  except the reserve that keeps 8 MiB free. The rule runs at takes and give-backs on an injectable
  clock; there is no timer.
- Removed: the dedicated path, fits-and-fills-half, the 256 and 128 MiB idle bounds and the 64 MiB
  Private block.
- Metrics: blocks_reused replaces dedicated_blocks_reused. New metrics: block_bytes_made, and the
  vkAllocateMemory time on the consumer's threads (count, total, longest) apart from the
  block-maker thread's.

Tests:
- Unit: rounding, base alignment, and the window and surplus rule.
- On device:
  - the first allocations, and the trigger at 8 MiB free;
  - kept blocks taken again with their number, address and mapping;
  - an allocation beside kept blocks of other lengths, with their bytes given back;
  - the failed-allocation path, at an answered maxMemoryAllocationCount;
  - idle allocations following the window down, the reserve kept;
  - a seeded 300-step stress of mixed takes and releases across both classes, each step under a
    one-minute timeout.
- Tests that took a block of 1 byte and used more of it now take what they use.
- The replay's rt counters read the new metrics.

Verified: cargo fmt; api_signatures blessed; REFUSALS.md regenerated. Clippy, the suites and the
device legs follow as potluck jobs.
This commit is contained in:
Anees Iqbal committed 2026-11-17 23:59:05 -08:00
1 parent cee11ce35e
commit d1e9062b5f
19 files changed
+1771 -901

No files matched your search

+36 -26
View File
@@ -86,24 +86,29 @@ in its memory.
the block's `BlockInfo` (its number, class, length, device address and, for Shared, its host
address). One `VkBuffer` spans each block, with every buffer usage and a device address.
Nothing in a block is exportable.
- Up to its class's `MemoryClass::block_len`, 16 MiB of Shared memory and 64 MiB of Private on
every device, a block is pooled. `Device::new` makes one block of each class before it returns,
and the block-maker thread keeps one of each class ready after that, made off every caller's
path, so a take waits only when none is ready. No block is so made beside the consumer's first
calls: on an RTX 3090 (NVIDIA's Linux driver), a pipeline state's creation right after
`Device::new` waited 47 to 61 ms behind the allocation of a first 256 MiB Shared block's memory.
A driver may hold the device's other calls for the whole of a block's allocation, longer for
more bytes, so the lengths are short: there a creation beside a Shared block's making took 6 to
8 ms at 16 MiB (40 to 45 ms at 256 MiB), and 3.4 to 4.6 ms beside a 64 MiB Private block's. 16
MiB is the largest piece a guest's allocator takes for its buffers; at 64 MiB a texture or a
Managed buffer's device copy of 32 MiB takes a pooled Private block. Past its class's length a
block is dedicated: the length rounded up to 64 KiB, made in the call, up to the device's
`maxMemoryAllocationSize` and `maxBufferSize` (`Limit::BlockLen` past them).
- A block is a range of one of the device's allocations of its class, with a `VkBuffer` of its
own bound there: the length asked rounded up to 64 KiB (to `bufferImageGranularity` where that is
larger), at an offset that is a multiple of that length rounded up to a power of two, up to 2
MiB. A take is, in order: a kept block of its length (below), a free range of the class's
allocations, the first that fits, else the start of an allocation made in the call, of
`MemoryClass::block_len` (16 MiB of either class) or the block's length where that is longer, up
to the device's `maxMemoryAllocationSize` and `maxBufferSize` (`Limit::BlockLen` past them). Its
rest serves later takes.
- `Device::new` makes one allocation of each class before it returns. After that the block-maker
thread makes a class's next allocation of 16 MiB, off every caller's path, while the class's free
bytes are fewer than 8 MiB, and at no other time: a take that leaves more free sets nothing off
beside the consumer's next calls. A driver may hold the device's other calls for the whole of an
allocation, longer for more bytes: on an RTX 3090 (NVIDIA's Linux driver) a pipeline state's
creation beside a Shared allocation's making took 6 to 8 ms at 16 MiB and 40 to 45 ms at 256
MiB; on an RTX 2080 a compute pipeline's creation waited out the whole 3.4 ms of a 16 MiB Shared
allocation made beside it. `Metrics::consumer_allocation_nanos` and
`consumer_allocation_max_nanos` count the time of allocations made on the consumer's threads,
and `maker_allocation_nanos` those of the block-maker thread.
- A Private allocation takes the device-local Private type. Where that allocation itself fails
out of device memory (never a budget poll), it takes the next memory type the resource allows,
in the device's order: `BlockInfo::device_local` is false for such a block, and
`Gauges::spilled_bytes` counts the bytes until they are freed. A spilled pooled block is freed
when given back, so the pool's next block tries device-local memory again. Textures are not
`Gauges::spilled_bytes` counts the bytes until they are freed. A spilled allocation is freed
once its last block is given back, so the next tries device-local memory again. Textures are not
placed in a spilled block: a texture then takes an allocation of its own, which spills in the
same way where the image allows another type. A Managed buffer whose device copy finds no
device-local room is its Shared range, as on a unified device, for its life.
@@ -120,16 +125,20 @@ in its memory.
- Dropping a block's last handle gives the block back; `Device::release_block` consumes a handle,
that drop made explicit. Clones of a handle share one claim, so dropping one of two gives nothing
back. It takes effect once no buffer, command buffer or upload using the block remains. The
block-maker thread then zeroes it and keeps it idle, pooled or dedicated, with the same number,
address and mapping, as its class's latest idle block. Each class keeps at most a bound of idle
bytes, 256 MiB of Shared memory and 128 MiB of Private, beside its ready block, which is a
reserve outside the bound: past it the oldest kept block is freed (after
`BlockMappings::unmap`), and a block longer than the bound is freed at once. A take past the
pooled length takes a kept dedicated block that it fits and fills at least half of
(`Metrics::dedicated_blocks_reused`) before it allocates, so a program that makes and releases
large buffers frame after frame pays the allocation, and the driver's hold on the device's other
calls that comes with it, once. `Gauges::shared_idle_bytes` and `Gauges::private_idle_bytes`
count what is kept. Once the last handle is gone the block's number names nothing
block-maker thread then zeroes it and keeps it, with the same number, address and mapping, for a
later take of its length (`Metrics::blocks_reused`). A take that no free range fits while the
class keeps blocks of other lengths makes its allocation at once, and the block-maker thread then
gives those blocks' bytes back to their allocations, after `BlockMappings::unmap` of each; only
where the take's allocation fails does it wait for those bytes and take a range of them. An
allocation that holds no block anyone holds is idle. The device keeps a class's idle allocations
while their bytes and those of its allocations in use stay at or under the most bytes it had in
use over the last 10 seconds, and within an eighth of the heap of the class's memory type; past
that it frees the oldest, after `BlockMappings::unmap` of each block kept in them, except those
the class's free bytes need to stay at 8 MiB or more. The rule runs as blocks are taken and given
back, never on a timer: a program that goes quiet keeps its idle allocations until its next take
or release, or until the device is torn down. `Gauges::shared_idle_bytes` and
`Gauges::private_idle_bytes` count the idle bytes. Once the last handle is gone the block's
number names nothing
(`Error::NoSuchBlock`), and numbers are never reused during the device's life. The device's
teardown frees every block still claimed, after the consumer's `BlockMappings::unmap` returned
for it; a handle dropped after that does nothing.
@@ -152,7 +161,8 @@ in its memory.
which `contents` answers. The device's memory-type query picks its form. Where the Shared type
is device-local, the buffer is its bytes, as a Shared buffer is, and `did_modify_range` does
nothing. Elsewhere shaders reach a device copy at `gpu_address`: a place in a copy block, a
Private block of the pool (a dedicated one past 64 MiB) that holds device copies alone. Its
Private block of the pool of 16 MiB (of the copy's own length past that) that holds device
copies alone. Its
first `copied` bytes are copied from the consumer's and the rest zeroed, in the upload.
`Buffer::did_modify_range(start, length)` marks a range changed (`Refusal::ModifiedRange` past
the buffer): the upload copies it into the device copy as it goes, ahead of every command buffer
+64 -17
View File
@@ -17,8 +17,8 @@ pub(crate) enum Metric {
PipelinesCreated,
/// [`Metrics::blocks_made`].
BlocksMade,
/// [`Metrics::dedicated_blocks_reused`].
DedicatedBlocksReused,
/// [`Metrics::blocks_reused`].
BlocksReused,
/// [`Metrics::dispatches_without_effects`].
DispatchesWithoutEffects,
/// [`Metrics::translations`].
@@ -101,8 +101,13 @@ struct Atomics {
first_use_wait_nanos: AtomicU64,
first_use_wait_max_nanos: AtomicU64,
blocks_made: AtomicU64,
block_bytes_made: AtomicU64,
consumer_allocations: AtomicU64,
consumer_allocation_nanos: AtomicU64,
consumer_allocation_max_nanos: AtomicU64,
maker_allocation_nanos: AtomicU64,
dispatches_without_effects: AtomicU64,
dedicated_blocks_reused: AtomicU64,
blocks_reused: AtomicU64,
translations: AtomicU64,
translations_loaded: AtomicU64,
ring_writes: AtomicU64,
@@ -155,7 +160,7 @@ impl Counters {
Metric::Barriers => &a.barriers,
Metric::PipelinesCreated => &a.pipelines_created,
Metric::BlocksMade => &a.blocks_made,
Metric::DedicatedBlocksReused => &a.dedicated_blocks_reused,
Metric::BlocksReused => &a.blocks_reused,
Metric::DispatchesWithoutEffects => &a.dispatches_without_effects,
Metric::Translations => &a.translations,
Metric::TranslationsLoaded => &a.translations_loaded,
@@ -192,6 +197,24 @@ impl Counters {
self.atomics.submit_infos.fetch_add(infos, Relaxed);
}
/// An allocation of `bytes` made for blocks ([`Metrics::block_bytes_made`]).
pub(crate) fn allocated(&self, bytes: u64) {
self.atomics.block_bytes_made.fetch_add(bytes, Relaxed);
}
/// A `vkAllocateMemory` that took `nanos` nanoseconds, on the block-maker thread where
/// `maker`, else on a thread of the consumer's ([`Metrics::consumer_allocation_nanos`]).
pub(crate) fn allocation_time(&self, nanos: u64, maker: bool) {
let a = &self.atomics;
if maker {
a.maker_allocation_nanos.fetch_add(nanos, Relaxed);
} else {
a.consumer_allocations.fetch_add(1, Relaxed);
a.consumer_allocation_nanos.fetch_add(nanos, Relaxed);
a.consumer_allocation_max_nanos.fetch_max(nanos, Relaxed);
}
}
/// `bytes` more copied for a call ([`Metrics::bytes_copied`]).
pub(crate) fn copied(&self, bytes: u64) {
self.atomics.bytes_copied.fetch_add(bytes, Relaxed);
@@ -290,7 +313,12 @@ impl Counters {
first_use_wait_nanos: a.first_use_wait_nanos.load(Relaxed),
first_use_wait_max_nanos: a.first_use_wait_max_nanos.load(Relaxed),
blocks_made: a.blocks_made.load(Relaxed),
dedicated_blocks_reused: a.dedicated_blocks_reused.load(Relaxed),
block_bytes_made: a.block_bytes_made.load(Relaxed),
consumer_allocations: a.consumer_allocations.load(Relaxed),
consumer_allocation_nanos: a.consumer_allocation_nanos.load(Relaxed),
consumer_allocation_max_nanos: a.consumer_allocation_max_nanos.load(Relaxed),
maker_allocation_nanos: a.maker_allocation_nanos.load(Relaxed),
blocks_reused: a.blocks_reused.load(Relaxed),
dispatches_without_effects: a.dispatches_without_effects.load(Relaxed),
translations: a.translations.load(Relaxed),
translations_loaded: a.translations_loaded.load(Relaxed),
@@ -367,13 +395,30 @@ pub struct Metrics {
/// The longest first-use wait, in nanoseconds; a maximum since the device was made, so the
/// difference of two reads does not apply to it.
pub first_use_wait_max_nanos: u64,
/// `VkDeviceMemory` allocations made: pooled blocks (the texture blocks among them) and
/// dedicated ones, the zero source and the parameter ring's blocks.
/// `VkDeviceMemory` allocations made: the allocations blocks are ranges of (the texture
/// blocks among them), the zero source and the parameter ring's blocks.
pub blocks_made: u64,
/// Dedicated blocks taken again: a request past its class's pooled length that took a
/// dedicated block given back and kept idle, which it fits and fills at least half of,
/// instead of a new allocation.
pub dedicated_blocks_reused: u64,
/// Bytes of the allocations blocks are ranges of, made: what the device allocated for
/// blocks, by the block-maker thread or in a take. The difference of two reads is what a
/// frame allocated.
pub block_bytes_made: u64,
/// `vkAllocateMemory` calls made on the consumer's threads, inside its calls: the device's
/// making, takes that no free range fits, textures' allocations of their own, the staging
/// region and the parameter ring's blocks. A driver may hold the device's other calls for an
/// allocation's whole length.
pub consumer_allocations: u64,
/// The nanoseconds of [`host_time`](crate::host_time) those calls took, in total.
pub consumer_allocation_nanos: u64,
/// The longest of those calls, in nanoseconds; a maximum since the device was made, so the
/// difference of two reads does not apply to it.
pub consumer_allocation_max_nanos: u64,
/// The nanoseconds of [`host_time`](crate::host_time) the block-maker thread's
/// `vkAllocateMemory` calls took, in total: allocations made ahead of need, off the
/// consumer's threads.
pub maker_allocation_nanos: u64,
/// Blocks taken again: a take of the length of a block given back and kept, which took that
/// block with its number, address and mapping, and no new range or allocation.
pub blocks_reused: u64,
/// Dispatches of a kernel that writes no memory (`PipelineInterface::writes_memory`),
/// direct and indirect: each was checked as Metal checks it, and nothing was recorded, bound
/// or read for it, as it has no effect a program can observe.
@@ -458,8 +503,8 @@ pub struct Gauges {
/// Occupied indices of set 1's arrays: one for each texture made at an index and each sampler
/// state.
pub descriptor_slots: u64,
/// Live `VkDeviceMemory` allocations: blocks the consumer holds, blocks ready or idle in the
/// pool, and the runtime's own.
/// Live `VkDeviceMemory` allocations: those blocks are ranges of, the idle ones among them,
/// and the runtime's own.
pub blocks: u64,
/// Events and shared events (timeline semaphores).
pub events: u64,
@@ -471,10 +516,12 @@ pub struct Gauges {
/// was out of memory: blocks whose [`BlockInfo::device_local`](crate::BlockInfo) is false and
/// textures' allocations of their own.
pub spilled_bytes: u64,
/// Bytes of idle Shared blocks the pool keeps, pooled and dedicated, zeroed, that no one
/// holds: the ready block and at most the class's bound of 256 MiB beside it.
/// Bytes of idle Shared allocations, which hold no block anyone holds: those the idle rule
/// keeps (at most the most bytes of Shared allocations in use over the last 10 seconds less
/// those in use now, and an eighth of the heap), and the reserve that keeps the free bytes at
/// 8 MiB or more.
pub shared_idle_bytes: u64,
/// Bytes of idle Private blocks the pool keeps, pooled and dedicated, zeroed, that no one
/// holds: the ready block and at most the class's bound of 128 MiB beside it.
/// Bytes of idle Private allocations, as [`shared_idle_bytes`](Self::shared_idle_bytes) for
/// Shared ones.
pub private_idle_bytes: u64,
}
+44 -43
View File
@@ -271,9 +271,9 @@ impl Device {
/// of the consumer's extensions ([`DeviceOptions::extensions`]) the device offers with the
/// features the consumer needs, and chooses its memory types on it. It takes one queue of the floor's queue
/// family for the runtime and, where that family has a second queue, a queue for presenting;
/// where it has one, presenting shares the runtime's queue and its lock. It makes one block of
/// each memory class ready, then starts the block-maker thread, which keeps one of each ready
/// after that, the submit thread and the completion thread.
/// where it has one, presenting shares the runtime's queue and its lock. It makes one
/// allocation of each memory class for blocks, then starts the block-maker thread, which makes
/// another while a class's free bytes run low, the submit thread and the completion thread.
///
/// Err: [`Error::BelowFloor`] with every item the device lacks; [`Error::Vulkan`] where a
/// Vulkan call fails; [`Limit::MemoryAllocations`](crate::Limit::MemoryAllocations) at a
@@ -429,7 +429,13 @@ impl Device {
.fold(0, |bits, (index, _)| bits | 1 << index);
let work = Work::new(counters.clone());
let pool = Pool::new(options.block_mappings, counters.clone());
let heap = |memory_type: u32| {
let memory = &capabilities.memory;
let heap = memory.memory_types_as_slice()[memory_type as usize].heap_index;
memory.memory_heaps_as_slice()[heap as usize].size
};
let heaps = [heap(memory_types.private), heap(memory_types.shared)];
let pool = Pool::new(options.block_mappings, counters.clone(), heaps, granularity);
let core = Arc::new(Core {
instance,
physical: raw,
@@ -551,21 +557,27 @@ impl Device {
self.shared.core.counters.clone()
}
/// No Metal counterpart: takes a block of `class` memory at least `len` bytes long, for the
/// consumer to place buffers in: a handle ([`Block`]) whose last drop gives it back.
/// No Metal counterpart: takes a block of `class` memory of `len` bytes rounded up to 64 KiB
/// (to the device's `bufferImageGranularity` where that is larger), for the consumer to place
/// buffers in: a handle ([`Block`]) whose last drop gives it back. A block is a range of one
/// of the device's allocations, with a `VkBuffer` of its own.
///
/// For `len` up to the class's [`MemoryClass::block_len`] (16 MiB Shared, 64 MiB Private) it
/// is a pooled block of that length. The device's making makes one of each class, and the
/// block-maker thread makes the next ones ahead of need, off every caller's path, so this
/// call waits only when no block of the class is ready. Past it, it is a dedicated block of
/// `len` rounded up to 64 KiB: one given back earlier and kept idle that it fits and fills at
/// least half of ([`Metrics::dedicated_blocks_reused`](crate::Metrics::dedicated_blocks_reused)),
/// with that block's number, address and mapping, or else one made in this call.
/// It is, in order: a block of that length given back earlier and kept, with its number,
/// address and mapping ([`Metrics::blocks_reused`](crate::Metrics::blocks_reused)); a free
/// range of the class's allocations, the first that fits; else the start of an allocation
/// made in this call, of [`MemoryClass::block_len`] (16 MiB) or the block's length where that
/// is longer, whose rest later blocks share. The block-maker thread makes a class's next
/// allocation of 16 MiB off every caller's path while the class's free bytes are fewer than 8
/// MiB, so a take that leaves more free sets nothing off beside the consumer's next calls.
/// Where a take finds no free range and the class keeps blocks of other lengths, the
/// block-maker thread then gives their bytes back to their allocations, after
/// [`BlockMappings::unmap`]; the take waits for that only where its own allocation fails, and
/// then takes a range of those bytes where one fits.
///
/// Every block reads zero, as Metal's new buffers do, whether new or taken again: a Shared
/// block is zeroed through its mapping, which also makes each page resident before the block
/// is handed out, and a Private block by a GPU fill. A pooled block released and taken again
/// keeps its number, address and mapping.
/// Every block reads zero, as Metal's new buffers do, whether new or taken again: an
/// allocation is zeroed as it is made, a block's bytes as it is given back, a Shared one
/// through the mapping (which also makes each page resident before the block is handed out)
/// and a Private one by a GPU fill.
///
/// Err: [`Limit::BlockLen`](crate::Limit::BlockLen) past the device's largest allocation or
/// buffer; [`Limit::BlockIds`](crate::Limit::BlockIds);
@@ -622,12 +634,15 @@ impl Device {
/// handle, made explicit ([`Block`]).
///
/// It takes effect once no [`Buffer`](crate::Buffer) of the block remains and every command
/// buffer that used it has retired. The block-maker thread then zeroes it and keeps it idle,
/// pooled or dedicated, with the same number, address and mapping, freeing the class's oldest
/// kept blocks past its bound (256 MiB Shared, 128 MiB Private, beside the ready block) after
/// [`BlockMappings::unmap`], and at once a block longer than the bound. A kept dedicated
/// block serves a later [`take_block`](Device::take_block) past the pooled length that it
/// fits and that fills at least half of it.
/// buffer that used it has retired. The block-maker thread then zeroes it and keeps it, with
/// the same number, address and mapping, for a later [`take_block`](Device::take_block) of its
/// length. An allocation none of whose blocks is held is idle, and one that holds a block is
/// in use: the device keeps a class's idle allocations while their bytes and those of its
/// allocations in use stay at or under the most bytes it had in use over the last 10 seconds,
/// and within an eighth of its memory type's heap, and frees the oldest past that, after
/// [`BlockMappings::unmap`] of each block kept in it.
/// The rule runs as blocks are taken and given back, never on a timer: a program that goes
/// quiet keeps its idle allocations until its next take or release.
///
/// Err: [`Refusal::OtherDevice`] for another device's block, whose handle is dropped all the
/// same.
@@ -1028,21 +1043,12 @@ impl Core {
self.device_local & (1 << self.memory_types.shared) != 0
}
/// A block of `class` for `len` bytes: a pooled one up to the class's block length, else a
/// dedicated one of `len` rounded up to 64 KiB: an idle one the pool kept that [`memory::fits`]
/// it, or one made in the call.
/// A block of `class` for `len` bytes ([`Pool::take`]).
///
/// Err: what [`Pool::take`] and [`memory::make`] return;
/// [`Limit::BlockLen`](crate::Limit::BlockLen) past the device's longest block.
/// Err: what [`Pool::take`] returns; [`Limit::BlockLen`](crate::Limit::BlockLen) past the
/// device's longest allocation or buffer.
pub(crate) fn take_memory(&self, class: MemoryClass, len: u64) -> Result<Memory, Error> {
if len <= class.block_len() {
return self.pool.take(class);
}
let len = memory::dedicated_len(len, self.max_block_len)?;
match self.pool.take_held(class, len) {
Some(memory) => Ok(memory),
None => memory::make(self, class, len, self.pool.number()?, false),
}
self.pool.take(self, class, len, self.max_block_len)
}
/// Quiesced or torn down.
@@ -1119,13 +1125,8 @@ impl Drop for Core {
unsafe { region.free(self) };
}
let placed = (self.places.remaining().into_iter()).chain(self.copies.remaining());
for memory in placed
.collect::<Vec<_>>()
.into_iter()
.chain(self.pool.remaining())
{
memory::free(self, memory);
}
let placed = placed.collect();
memory::free_all(self, placed);
let pools = std::mem::take(
self.query_pools
.get_mut()
File diff suppressed because it is too large. Load diff
+33 -15
View File
@@ -4,11 +4,12 @@
//! buffer lies beside an optimal image in one allocation.
//!
//! A place is a resource's bytes at a multiple of its alignment: the first that fits, in the
//! blocks in the order they were taken; where none fits, the next block comes from the pool, or,
//! for a place longer than a pooled block, a dedicated block of its own. A place is free again once
//! its resource is freed, after every command buffer and upload that used it retired. One empty
//! pooled block of a set is kept for the next place; another that empties, and a dedicated block
//! once empty, goes back to the pool, which zeroes and keeps a pooled block or frees it.
//! blocks in the order they were taken; where none fits, the next block comes from the pool: of
//! the class's block length ([`MemoryClass::block_len`]), or of the place's own length where that
//! is longer. A place is free again once its resource is freed, after every command buffer and
//! upload that used it retired. One empty block of the block length is kept for the next place;
//! another block that empties goes back to the pool, which zeroes and keeps it for a take of its
//! length.
//!
//! An image in a texture block is optimal. The block's own `VkBuffer`, which spans it, aliases the
//! images (Vulkan's memory aliasing), and only the pool uses it: to zero the block before it is
@@ -20,6 +21,9 @@ use crate::error::Error;
use crate::memory::{BlockId, Memory, MemoryClass};
use std::sync::{Mutex, PoisonError};
/// The length of the blocks a set takes for places no longer than it.
const BLOCK_LEN: u64 = MemoryClass::Private.block_len();
/// One set of blocks.
pub(crate) struct Places {
blocks: Mutex<Vec<PlaceBlock>>,
@@ -48,8 +52,8 @@ impl Places {
}
/// A place of `len` bytes at a multiple of `align`, a power of two, and its block. Where no
/// block has room, a Private block is taken, without the lock: from the pool, or a dedicated
/// one for a place longer than a pooled block.
/// block has room, a Private block is taken from the pool, without the lock: of the block
/// length, or of `len` where that is longer.
///
/// Err: what [`Core::take_memory`] returns.
pub(crate) fn place(
@@ -61,7 +65,8 @@ impl Places {
let mut blocks = lock(&self.blocks);
loop {
for block in blocks.iter_mut() {
if let Some(offset) = block.free.take(len, align) {
// The image's alignment holds in the allocation the block is a range of.
if let Some(offset) = block.free.take_from(len, align, block.memory.base()) {
block.live += 1;
let place = Place {
block: block.memory.id,
@@ -72,7 +77,7 @@ impl Places {
}
}
drop(blocks);
let memory = core.take_memory(MemoryClass::Private, len)?;
let memory = core.take_memory(MemoryClass::Private, len.max(BLOCK_LEN))?;
// A block that spilled out of device-local memory holds no place: textures then take
// memory of their own, and a Managed buffer its Shared range.
if memory.spilled() {
@@ -88,8 +93,8 @@ impl Places {
}
}
/// Frees `place`. Where its block empties and is dedicated, or another pooled block of the
/// set is empty, the block goes back to the pool.
/// Frees `place`. Where its block empties and is longer than the block length, or another
/// block of the set of that length is empty, the block goes back to the pool.
pub(crate) fn release(&self, core: &Core, place: Place) {
let mut blocks = lock(&self.blocks);
let Some(index) = (blocks.iter()).position(|block| block.memory.id == place.block) else {
@@ -98,9 +103,9 @@ impl Places {
let block = &mut blocks[index];
block.free.give(place.offset, place.len);
block.live -= 1;
let empty = |block: &PlaceBlock| block.live == 0 && block.memory.pooled();
let surplus =
!block.memory.pooled() || blocks.iter().filter(|block| empty(block)).count() > 1;
let standard = |block: &PlaceBlock| block.memory.len == BLOCK_LEN;
let empty = |block: &PlaceBlock| block.live == 0 && standard(block);
let surplus = !standard(block) || blocks.iter().filter(|block| empty(block)).count() > 1;
if blocks[index].live == 0 && surplus {
let emptied = blocks.remove(index);
drop(blocks);
@@ -140,8 +145,16 @@ impl Ranges {
/// Takes `len` bytes, more than 0, at the first offset that is a multiple of `align`, a power
/// of two, with the bytes free from it; `None` where there is none.
pub(crate) fn take(&mut self, len: u64, align: u64) -> Option<u64> {
self.take_from(len, align, 0)
}
/// Takes `len` bytes, more than 0, at the first offset that lies `base` bytes past a multiple
/// of `align`, a power of two, less `base`, with the bytes free from it: the first offset
/// aligned where the ranges start `base` bytes into something larger. `None` where there is
/// none.
pub(crate) fn take_from(&mut self, len: u64, align: u64, base: u64) -> Option<u64> {
let (index, at) = (self.free.iter().enumerate()).find_map(|(index, &(start, end))| {
let at = start.checked_next_multiple_of(align)?;
let at = start.checked_add(base)?.checked_next_multiple_of(align)? - base;
(at.checked_add(len)? <= end).then_some((index, at))
})?;
let (start, end) = self.free[index];
@@ -177,6 +190,11 @@ impl Ranges {
}
}
/// The bytes free.
pub(crate) fn bytes(&self) -> u64 {
self.free.iter().map(|&(start, end)| end - start).sum()
}
/// For the tests: the free ranges.
#[cfg(test)]
pub(crate) fn free(&self) -> &[(u64, u64)] {
+4 -4
View File
@@ -1690,13 +1690,13 @@ pub(crate) mod on_device {
});
}
/// Returns once the pool holds a ready block of each class again: the block-maker thread
/// makes one after a block is taken, a Private one zeroed in a submission of its own, which a
/// Returns once the block-maker thread has nothing to make: it makes an allocation of a
/// class whose free bytes run low, a Private one zeroed in a submission of its own, which a
/// count of a test's own work must not take in.
pub(crate) fn settled(device: &Device) {
within("a ready block of each class", || {
within("8 MiB free in each class", || {
let pool = &device.core().pool;
pool.idle(MemoryClass::Private) > 0 && pool.idle(MemoryClass::Shared) > 0
pool.stocked(MemoryClass::Private) && pool.stocked(MemoryClass::Shared)
});
}
+30 -41
View File
@@ -915,14 +915,14 @@ pub(crate) mod on_device {
}
/// A Private buffer of a whole block, for work that keeps the GPU busy. It returns once the
/// block-maker thread has made the next ready Private block, whose zero fill is a submission
/// of its own, so the submissions a test counts after it are its command buffers'.
/// block-maker thread has made any Private allocation the take set off, whose zero fill is a
/// submission of its own, so the submissions a test counts after it are its command buffers'.
fn private(device: &Device) -> Buffer {
let block = device
.take_block(MemoryClass::Private, 1)
.take_block(MemoryClass::Private, MemoryClass::Private.block_len())
.expect("a Private block");
within("the next ready Private block", || {
device.core().pool.idle(MemoryClass::Private) > 0
within("8 MiB of Private memory free", || {
device.core().pool.stocked(MemoryClass::Private)
});
device
.new_buffer(block.id, 0, MemoryClass::Private.block_len(), false)
@@ -1655,20 +1655,14 @@ pub(crate) mod on_device {
}
/// A block whose last handle drops, with no `release_block`, while a held command buffer uses
/// it: its number names nothing at once, and the block stays live until the command buffer
/// completes, then is freed. It is a dedicated block, which the pool does not keep, so the
/// live allocations fall back to where they were.
/// it: its number names nothing at once, and the block stays out of the pool until the
/// command buffer completes, then comes back to it.
#[test]
fn every_device_frees_a_dropped_block_once_its_last_command_buffer_retires() {
fn every_device_gives_back_a_dropped_block_once_its_last_command_buffer_retires() {
each_device("block_drop", |name, _, device| {
let counters = device.counters();
let f = shared_event(&device);
let queue = queue(&device);
crate::tests::blit::on_device::settled(&device);
let before = counters.gauges().blocks;
// Longer than the class's idle bound, so it is freed once given back.
let len = MemoryClass::Shared.idle_bound() + 1;
let block = (device.take_block(MemoryClass::Shared, len)).expect("a dedicated block");
let block = (device.take_block(MemoryClass::Shared, 1)).expect("a Shared block");
let id = block.id;
let buffer = (device.new_buffer(id, 0, 4096, false)).expect("a buffer");
let held = queue.command_buffer().expect("a command buffer");
@@ -1681,50 +1675,42 @@ pub(crate) mod on_device {
"{name}: the dropped block's number"
);
thread::sleep(Duration::from_millis(50));
assert_eq!(
counters.gauges().blocks,
before + 1,
"{name}: live while in use"
);
let pool = &device.core().pool;
assert!(!pool.holds(id), "{name}: back while in use");
f.set_signaled_value(1);
finished(name, &held);
within("the dropped block freed", || {
counters.gauges().blocks == before
});
within("the dropped block's return", || pool.holds(id));
drop((f, queue, device));
});
}
/// Clones of a block's handle share one claim: dropping one of two gives nothing back, and
/// the block's number still names it; releasing the other frees it. A handle that outlives
/// its device finds its block freed by the teardown, every gauge zero, and its drop does
/// nothing.
/// the block's number still names it; releasing the other gives it back. A handle that
/// outlives its device finds its block freed by the teardown, every gauge zero, and its drop
/// does nothing.
#[test]
fn every_device_frees_a_block_at_its_last_clone_and_at_teardown() {
fn every_device_gives_back_a_block_at_its_last_clone_and_frees_it_at_teardown() {
each_device("block_clones", |name, _, device| {
let counters = device.counters();
crate::tests::blit::on_device::settled(&device);
let before = counters.gauges().blocks;
// Longer than the class's idle bound, so it is freed once given back.
let len = MemoryClass::Shared.idle_bound() + 1;
let block = (device.take_block(MemoryClass::Shared, len)).expect("a dedicated block");
let pool = &device.core().pool;
let block = (device.take_block(MemoryClass::Shared, 1)).expect("a Shared block");
let id = block.id;
let clone = block.clone();
drop(block);
thread::sleep(Duration::from_millis(50));
assert_eq!(
counters.gauges().blocks,
before + 1,
"{name}: one of two clones dropped"
assert!(
!pool.holds(id),
"{name}: back with one of two clones dropped"
);
let buffer = (device.new_buffer(clone.id, 0, 256, false))
.unwrap_or_else(|error| panic!("{name}: the clone's number: {error}"));
drop(buffer);
device.release_block(clone).expect("a release");
within("the block freed at its last clone", || {
counters.gauges().blocks == before
});
within("the block back at its last clone", || pool.holds(id));
let kept = (device.take_block(MemoryClass::Shared, len)).expect("a dedicated block");
let kept = (device
.take_block(MemoryClass::Shared, 2 * MemoryClass::Shared.block_len()))
.expect("a long block");
drop(device);
within("the teardown", || counters.gauges() == Gauges::default());
drop(kept);
@@ -1789,7 +1775,10 @@ pub(crate) mod on_device {
.take_block(MemoryClass::Shared, MemoryClass::Shared.block_len())
.expect("a Shared block");
let released: Vec<_> = (0..3)
.map(|_| device.take_block(MemoryClass::Shared, 1).expect("a block"))
.map(|_| {
(device.take_block(MemoryClass::Shared, MemoryClass::Shared.block_len()))
.expect("a block")
})
.collect();
let address = block.contents.expect("contents").as_ptr() as usize;
*lock(&READER) = Some(thread::spawn(move || {
+3 -4
View File
@@ -31,11 +31,10 @@ mod on_device {
each_device("heap", |name, _, device| {
let core = device.core();
let counters = device.counters();
let block = (device.take_block(MemoryClass::Private, 1))
let block = (device.take_block(MemoryClass::Private, MemoryClass::Private.block_len()))
.unwrap_or_else(|error| panic!("{name}: {error}"));
wait_until("a ready block of each class", || {
core.pool.idle(MemoryClass::Private) == 1
&& core.pool.idle(MemoryClass::Shared) == 1
wait_until("8 MiB free in each class", || {
core.pool.stocked(MemoryClass::Private) && core.pool.stocked(MemoryClass::Shared)
});
let blocks = counters.gauges().blocks;
let heap = HeapRange {
+1 -1
View File
@@ -96,7 +96,7 @@ mod on_device {
let core = device.core();
let copied = !core.shared_is_device_local();
let counters = device.counters();
let cpu = (device.take_block(MemoryClass::Shared, 1))
let cpu = (device.take_block(MemoryClass::Shared, 2 * LEN))
.unwrap_or_else(|error| panic!("{name}: {error}"));
let into = (device.new_buffer(cpu.id, LEN, LEN, true))
.unwrap_or_else(|error| panic!("{name}: {error}"));
File diff suppressed because it is too large. Load diff
+5 -6
View File
@@ -73,15 +73,14 @@ mod on_device {
.collect()
}
/// The device's live allocations once the block-maker thread holds a ready block of each
/// class, refilling off this thread any a take used, and the texture blocks among them.
/// The device's live allocations once the block-maker thread has nothing to make (8 MiB free
/// in each class), and the texture blocks among them.
fn settled(name: &str, core: &Core) -> (u64, usize) {
let deadline = Instant::now() + Duration::from_secs(120);
while core.pool.idle(MemoryClass::Private) == 0 || core.pool.idle(MemoryClass::Shared) == 0
{
while !core.pool.stocked(MemoryClass::Private) || !core.pool.stocked(MemoryClass::Shared) {
assert!(
Instant::now() < deadline,
"{name}: a ready block of each class"
"{name}: 8 MiB free in each class"
);
thread::sleep(Duration::from_millis(1));
}
@@ -128,7 +127,7 @@ mod on_device {
let counters = device.counters();
let core = device.core();
let cpu = (device.take_block(MemoryClass::Shared, 1))
let cpu = (device.take_block(MemoryClass::Shared, AT + LEN))
.unwrap_or_else(|error| panic!("{name}: {error}"));
let buffer = (device.new_buffer(cpu.id, AT, LEN, true))
.unwrap_or_else(|error| panic!("{name}: {error}"));
+36 -28
View File
@@ -3,8 +3,9 @@
//! blocks of the pool with no allocation of their own: a block's worth of 1 MiB textures takes
//! one block and then a second, releasing them gives one back to the pool and keeps the other,
//! textures made and released in that block allocate nothing, and every gauge reads zero after
//! teardown; pooled blocks are 16 MiB Shared and 64 MiB Private, and a texture of 32 MiB takes a
//! place in one.
//! teardown; the pool's allocations are 16 MiB of either class, a take is a range of one rounded
//! up to 64 KiB, a longer take an allocation of its own, and a texture of 32 MiB takes a texture
//! block of its own length.
use crate::places::Ranges;
@@ -115,9 +116,8 @@ mod on_device {
.unwrap_or_else(|error| panic!("{name}: {error}"));
let core = device.core();
let counters = device.counters();
wait_until("a ready block of each class", || {
core.pool.idle(MemoryClass::Private) == 1
&& core.pool.idle(MemoryClass::Shared) == 1
wait_until("8 MiB free in each class", || {
core.pool.stocked(MemoryClass::Private) && core.pool.stocked(MemoryClass::Shared)
});
let base = counters.gauges().blocks;
let made = counters.metrics().blocks_made;
@@ -147,19 +147,19 @@ mod on_device {
in_first > MemoryClass::Private.block_len() / MIB / 2,
"{name}: the first block held {in_first} textures of 1 MiB"
);
// Each block the pool's ready one, which the pool made again.
wait_until("the pool's two blocks made again", || {
// Each block an allocation whole, after which the block-maker thread made the next.
wait_until("the pool's next two allocations", || {
counters.metrics().blocks_made == made + 2
});
assert_eq!(counters.gauges().blocks, base + 2, "{name}: two blocks");
// Released: one block back to the pool, which keeps it idle; one kept for textures.
// Released: one block back to the pool, which keeps it; one kept for textures.
drop(textures);
wait_until("the textures freed", || {
counters.gauges().textures == 0 && core.places.blocks() == 1
});
wait_until("the block back in the pool", || {
core.pool.idle(MemoryClass::Private) == 2
core.pool.kept(MemoryClass::Private) == 1
});
assert_eq!(counters.gauges().blocks, base + 2, "{name}: after release");
@@ -198,11 +198,12 @@ mod on_device {
}
}
/// Pooled blocks are 16 MiB of Shared memory and 64 MiB of Private, on every device: a take
/// up to its class's length is a pooled block of that length, one past it a dedicated block,
/// and a texture of 32 MiB is placed in a texture block, with no allocation of its own.
/// The pool's allocations are 16 MiB of either class, on every device: a take of a byte is a
/// range of one rounded up to 64 KiB (to `bufferImageGranularity` where that is larger) and
/// allocates nothing; a take longer than an allocation makes one of its own length, rounded
/// up the same way; and a texture of 32 MiB is placed in a texture block of its own length.
#[test]
fn every_device_pools_16_mib_shared_and_64_mib_private_blocks() {
fn every_device_takes_blocks_from_16_mib_allocations() {
const MIB: u64 = 1 << 20;
let instance = Instance::new(&[]).expect("an instance at the floor");
let devices = devices_of_the_cfgs_kind(&instance);
@@ -212,22 +213,29 @@ mod on_device {
.unwrap_or_else(|error| panic!("{name}: {error}"));
let core = device.core();
let counters = device.counters();
for (class, len) in [
(MemoryClass::Shared, 16 * MIB),
(MemoryClass::Private, 64 * MIB),
] {
assert_eq!(class.block_len(), len, "{name}: {class:?}");
let pooled = (device.take_block(class, len))
.unwrap_or_else(|error| panic!("{name}: a pooled {class:?} block: {error}"));
assert_eq!(pooled.len, len, "{name}: a pooled {class:?} block");
let dedicated = (device.take_block(class, len + 1))
.unwrap_or_else(|error| panic!("{name}: a dedicated {class:?} block: {error}"));
assert_eq!(
dedicated.len,
len + (64 << 10),
"{name}: a dedicated {class:?} block"
for class in [MemoryClass::Shared, MemoryClass::Private] {
assert_eq!(class.block_len(), 16 * MIB, "{name}: {class:?}");
let made = counters.metrics().blocks_made;
let small = (device.take_block(class, 1))
.unwrap_or_else(|error| panic!("{name}: a small {class:?} block: {error}"));
assert!(
small.len.is_multiple_of(64 << 10) && small.len < MIB,
"{name}: a small {class:?} block of {} bytes",
small.len
);
for block in [pooled, dedicated] {
let long = (device.take_block(class, 16 * MIB + 1))
.unwrap_or_else(|error| panic!("{name}: a long {class:?} block: {error}"));
assert!(
long.len > 16 * MIB && long.len.is_multiple_of(64 << 10),
"{name}: a long {class:?} block of {} bytes",
long.len
);
assert_eq!(
counters.metrics().blocks_made,
made + 1,
"{name}: the long {class:?} block's allocation alone"
);
for block in [small, long] {
(device.release_block(block))
.unwrap_or_else(|error| panic!("{name}: a release: {error}"));
}
+11 -10
View File
@@ -28,12 +28,12 @@ mod on_device {
each_device("spill", |name, _, device| {
let core = device.core();
let counters = device.counters();
wait_until("a ready block of each class", || {
core.pool.idle(MemoryClass::Private) == 1
&& core.pool.idle(MemoryClass::Shared) == 1
wait_until("8 MiB free in each class", || {
core.pool.stocked(MemoryClass::Private) && core.pool.stocked(MemoryClass::Shared)
});
// A dedicated Private block, made in the call, whose device-local allocation fails.
// A Private block longer than an allocation, which makes its own in the call, whose
// device-local allocation fails.
core.fail_private.store(1, Relaxed);
let spilled =
device.take_block(MemoryClass::Private, MemoryClass::Private.block_len() + 1);
@@ -60,14 +60,15 @@ mod on_device {
return;
}
// Every Private-type allocation fails from here: the ready block, made before, is
// device-local; the pool's next one spills.
// Every Private-type allocation fails from here: the first allocation, made before, is
// device-local; the next, which the block-maker thread makes once a block takes the
// first whole, spills.
core.fail_private.store(u32::MAX, Relaxed);
let plain = (device.take_block(MemoryClass::Private, 1))
let plain = (device.take_block(MemoryClass::Private, MemoryClass::Private.block_len()))
.unwrap_or_else(|error| panic!("{name}: {error}"));
assert!(plain.device_local, "{name}: the ready block");
wait_until("the pool's spilled block", || {
core.pool.idle(MemoryClass::Private) == 1
assert!(plain.device_local, "{name}: the first allocation");
wait_until("the pool's spilled allocation", || {
core.pool.stocked(MemoryClass::Private)
&& counters.gauges().spilled_bytes >= MemoryClass::Private.block_len()
});
+7 -8
View File
@@ -61,23 +61,22 @@ mod on_device {
.unwrap_or_else(|error| panic!("{name}: {error}"));
let core = device.core();
let counters = device.counters();
// The pool's ready blocks, which the block-maker thread makes after the device.
wait_until("a ready block of each class", || {
core.pool.idle(MemoryClass::Private) == 1
&& core.pool.idle(MemoryClass::Shared) == 1
// The pool's first allocations, which the device's making makes.
wait_until("8 MiB free in each class", || {
core.pool.stocked(MemoryClass::Private) && core.pool.stocked(MemoryClass::Shared)
});
device
.grant_indices(IndexClass::Texture, 4096, 8)
.unwrap_or_else(|error| panic!("{name}: {error}"));
let submissions = || counters.metrics().submissions;
// The first texture takes the ready Private block as its texture block, which the pool
// makes again, zeroing it in a submission of its own.
// The first texture's texture block takes the first Private allocation whole, and the
// block-maker thread makes the next, zeroing it in a submission of its own.
drop(
(device.new_texture(&square(256), Some(4096)))
.unwrap_or_else(|error| panic!("{name}: {error}")),
);
wait_until("the pool's block made again", || {
core.pool.idle(MemoryClass::Private) == 1 && counters.gauges().textures == 0
wait_until("the next Private allocation", || {
core.pool.stocked(MemoryClass::Private) && counters.gauges().textures == 0
});
let base = counters.gauges().blocks;
+22 -11
View File
@@ -702,6 +702,7 @@ impl Device {
Source::Heap(block, heap, offset) => {
let bind = Bind::Heap {
memory: block.memory.device_memory(),
base: block.memory.base(),
block_len: block.memory.len,
heap,
offset,
@@ -722,6 +723,7 @@ impl Device {
};
let bind = Bind::InPlace {
memory: memory.device_memory(),
base: memory.base(),
memory_type: core.memory_type(class),
block_len: memory.len,
at: at + offset,
@@ -1377,19 +1379,22 @@ enum Source<'a> {
enum Bind {
/// A place in a texture block, or memory of its own.
Pooled,
/// A linear image, made preinitialized, at `at` in a block whose memory is `memory`, of type
/// `memory_type` and of `block_len` bytes, where the device lays its rows `bytes_per_row`
/// apart from there.
/// A linear image, made preinitialized, at `at` in a block at `base` in the allocation
/// `memory`, of type `memory_type` and of `block_len` bytes, where the device lays its rows
/// `bytes_per_row` apart from there.
InPlace {
memory: vk::DeviceMemory,
base: u64,
memory_type: u32,
block_len: u64,
at: u64,
bytes_per_row: u64,
},
/// `offset` in `heap`, whose block's memory is `memory`, of `block_len` bytes.
/// `offset` in `heap`, whose block of `block_len` bytes lies at `base` in the allocation
/// `memory`.
Heap {
memory: vk::DeviceMemory,
base: u64,
block_len: u64,
heap: HeapRange,
offset: u64,
@@ -1482,9 +1487,9 @@ impl Made {
let requirements = needs.memory_requirements;
let bits = requirements.memory_type_bits;
// A place in a texture block where the image takes the blocks' memory type and the device
// does not require an allocation of its own for it (preferring one is no reason).
// does not require an allocation of its own for it (preferring one is no reason): one of
// its own length where it is longer than a block.
let placed = dedicated.requires_dedicated_allocation == vk::FALSE
&& requirements.size <= MemoryClass::Private.block_len()
&& bits & (1 << core.memory_type(MemoryClass::Private)) != 0;
// Where the device-local memory has no texture block left, memory of its own.
let pooled = match placed && matches!(bind, Bind::Pooled) {
@@ -1497,6 +1502,7 @@ impl Made {
};
let (backing, memory, offset) = if let Bind::InPlace {
memory,
base,
memory_type,
block_len,
at,
@@ -1514,7 +1520,7 @@ impl Made {
&& layout.row_pitch == bytes_per_row
&& dedicated.requires_dedicated_allocation == vk::FALSE
&& bits & (1 << memory_type) != 0
&& at.is_multiple_of(requirements.alignment)
&& (base + at).is_multiple_of(requirements.alignment)
&& at
.checked_add(requirements.size)
.is_some_and(|end| end <= block_len);
@@ -1523,9 +1529,10 @@ impl Made {
pixel_format: d.pixel_format,
}));
}
(Backing::InBlock, memory, at)
(Backing::InBlock, memory, base + at)
} else if let Bind::Heap {
memory,
base,
block_len,
heap,
offset,
@@ -1543,13 +1550,17 @@ impl Made {
let end = offset.checked_add(fit.size);
let fits = heap_end.is_some_and(|heap_end| heap_end <= block_len)
&& end.is_some_and(|end| end <= heap.len)
&& at.is_some_and(|at| at.is_multiple_of(fit.align));
&& at.is_some_and(|at| (base + at).is_multiple_of(fit.align));
match (fits, at) {
(true, Some(at)) => (Backing::InBlock, memory, at),
(true, Some(at)) => (Backing::InBlock, memory, base + at),
_ => return Err(refused),
}
} else if let Some((place, block)) = pooled {
(Backing::Placed(place), block.device_memory(), place.offset)
(
Backing::Placed(place),
block.device_memory(),
block.base() + place.offset,
)
} else {
// Vulkan gives every image of no external handle type a device-local type.
let local = bits & core.device_local;
@@ -1490,7 +1490,14 @@ impl Backend for NewRuntime {
("first_use_waits", metrics.first_use_waits),
("first_use_wait_nanos", metrics.first_use_wait_nanos),
("blocks_made", metrics.blocks_made),
("dedicated_blocks_reused", metrics.dedicated_blocks_reused),
("block_bytes_made", metrics.block_bytes_made),
("blocks_reused", metrics.blocks_reused),
("consumer_allocations", metrics.consumer_allocations),
(
"consumer_allocation_nanos",
metrics.consumer_allocation_nanos,
),
("maker_allocation_nanos", metrics.maker_allocation_nanos),
(
"dispatches_without_effects",
metrics.dispatches_without_effects,
+6 -1
View File
@@ -2302,12 +2302,16 @@ field metal2vulkan-rt::IndexGrant.class pub class: IndexClass
field metal2vulkan-rt::IndexGrant.count pub count: u32
field metal2vulkan-rt::IndexGrant.first pub first: u32
field metal2vulkan-rt::Metrics.barriers pub barriers: u64
field metal2vulkan-rt::Metrics.block_bytes_made pub block_bytes_made: u64
field metal2vulkan-rt::Metrics.blocks_made pub blocks_made: u64
field metal2vulkan-rt::Metrics.blocks_reused pub blocks_reused: u64
field metal2vulkan-rt::Metrics.bytes_copied pub bytes_copied: u64
field metal2vulkan-rt::Metrics.cache_bytes_written pub cache_bytes_written: u64
field metal2vulkan-rt::Metrics.commit_lock_wait_max_nanos pub commit_lock_wait_max_nanos: u64
field metal2vulkan-rt::Metrics.commit_lock_wait_nanos pub commit_lock_wait_nanos: u64
field metal2vulkan-rt::Metrics.dedicated_blocks_reused pub dedicated_blocks_reused: u64
field metal2vulkan-rt::Metrics.consumer_allocation_max_nanos pub consumer_allocation_max_nanos: u64
field metal2vulkan-rt::Metrics.consumer_allocation_nanos pub consumer_allocation_nanos: u64
field metal2vulkan-rt::Metrics.consumer_allocations pub consumer_allocations: u64
field metal2vulkan-rt::Metrics.dispatches_without_effects pub dispatches_without_effects: u64
field metal2vulkan-rt::Metrics.first_use_wait_max_nanos pub first_use_wait_max_nanos: u64
field metal2vulkan-rt::Metrics.first_use_wait_nanos pub first_use_wait_nanos: u64
@@ -2315,6 +2319,7 @@ field metal2vulkan-rt::Metrics.first_use_waits pub first_use_waits: u64
field metal2vulkan-rt::Metrics.forced_flushes_across_queues pub forced_flushes_across_queues: u64
field metal2vulkan-rt::Metrics.groups_beside_another_queue pub groups_beside_another_queue: u64
field metal2vulkan-rt::Metrics.lone_submissions_across_queues pub lone_submissions_across_queues: u64
field metal2vulkan-rt::Metrics.maker_allocation_nanos pub maker_allocation_nanos: u64
field metal2vulkan-rt::Metrics.over_copies pub over_copies: u64
field metal2vulkan-rt::Metrics.passes pub passes: u64
field metal2vulkan-rt::Metrics.pipelines_created pub pipelines_created: u64
Can't render this file because it is too large.
+2 -2
View File
@@ -665,7 +665,7 @@ Columns:
| Variant | What it blocks | Where | Basis | Sites | Reach |
|---|---|---|---|---|---|
| `BlockLen` | A block longer than one allocation and one buffer hold on the device (`Device::take_block` past `maxMemoryAllocationSize` or `maxBufferSize`) | at the device's limit | `device`: the device's `maxMemoryAllocationSize` and `maxBufferSize` | 1: `crates/metal2vulkan-rt/src/memory.rs (dedicated_len)` | `-` |
| `BlockLen` | A block longer than one allocation and one buffer hold on the device (`Device::take_block` past `maxMemoryAllocationSize` or `maxBufferSize`) | at the device's limit | `device`: the device's `maxMemoryAllocationSize` and `maxBufferSize` | 1: `crates/metal2vulkan-rt/src/memory.rs (round)` | `-` |
| `BlockIds` | A block after every block number has been used (`Device::take_block`) | every device (a public call's own check of its arguments) | `ours`: block numbers are 32 bits | 1: `crates/metal2vulkan-rt/src/memory.rs (number)` | `-` |
| `ThreadgroupShape` | A threadgroup longer on an axis than the device's `maxComputeWorkGroupSize` (the floor holds 1,024 by 1,024 by 64), where the threadgroup is the... | at the device's limit | `device`: the device's `maxComputeWorkGroupSize` | 1: `crates/metal2vulkan-rt/src/encoder.rs (dispatch)` | `-` |
| `ThreadgroupMemory` | A dispatch whose threadgroup memory, the kernel's own and the lengths set (each rounded up to 16 bytes), is past the device's... | at the device's limit | `device`: the device's `maxComputeSharedMemorySize` | 1: `crates/metal2vulkan-rt/src/encoder.rs (dispatch)` | `-` |
@@ -1235,7 +1235,7 @@ Each refusal's sites, with the function that builds it.
- `rt:Refusal::AttachmentUsage`: `crates/metal2vulkan-rt/src/texture.rs (attachment)`
- `rt:Refusal::AttachmentPlace`: `crates/metal2vulkan-rt/src/texture.rs (attachment)`
- `rt:Refusal::AttachmentFormat`: `crates/metal2vulkan-rt/src/pass.rs (check, 2 sites)`
- `rt:Limit::BlockLen`: `crates/metal2vulkan-rt/src/memory.rs (dedicated_len)`
- `rt:Limit::BlockLen`: `crates/metal2vulkan-rt/src/memory.rs (round)`
- `rt:Limit::BlockIds`: `crates/metal2vulkan-rt/src/memory.rs (number)`
- `rt:Limit::ThreadgroupShape`: `crates/metal2vulkan-rt/src/encoder.rs (dispatch)`
- `rt:Limit::ThreadgroupMemory`: `crates/metal2vulkan-rt/src/encoder.rs (dispatch)`
+1 -1
View File
@@ -476,7 +476,7 @@ their times and memory compare. `command-replay dump --stream FILE` prints the c
The counts are among its executed counters. A play with any of them above zero is no gate
result: `report.txt` says so on a `skipped` line. It places buffers of their own in the
runtime's pooled blocks (16 MiB Shared, 64 MiB Private; a longer one in a block of its own), a
runtime's blocks of 16 MiB of either class (a longer one in a block of its own), a
range freed for reuse once every command buffer committed before its release completed, gives
the runtime back a block or heap of the stream at its release (`release_block`), and gives
textures and sampler states indices from the whole of each index class. Its readback serves