From 69033afcd4584185216a1c4686a2a0e8f2f69ff8 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Thu, 3 Dec 2026 08:30:39 -0800 Subject: [PATCH] rt: a Shared heap's texture on a device without unified memory is an image of its own The L21 ruling, the third use of rule 2's unified-memory query (Vulkan's device type). On an integrated or CPU device a Shared heap's image texture lies in its heap, as before. Elsewhere it is an optimal image of its own in device memory, made as new_texture makes one but not zeroed (Metal's heap textures are not), and its heap range is left unused. Before, a discrete device either refused the placement (Gap::HeapTexture where its optimal images take no Shared type: the RTX 2080 and 3090 on NVIDIA 620.70.06) or bound the image in system memory, which every read crossed the link for (97 times a Private heap's time on an RX 7900 XTX, job m3-max-79841). How: heap_source decides by core.unified_memory() and the block's class. The own form checks the placement against heap_texture_size_and_align's answers by the same rule the in-heap form uses (heap_place, factored out of make: a heap range past its block, a texture past the heap's end, a byte off the alignment are Refusal::HeapTexturePlace), then makes Source::HeapOwn: Bind::Pooled (a place in a texture block or an allocation of its own, which spills as a texture's does), the heap's hazard id kept, no alias Placement, and Under::Heap with at None, so use_heap still covers it (heap_block) and blits see no shared span (bound). Texture buffers and textures over heap buffers are untouched. Docs: AGENTS.md rule 2's unified sentence gains the clause (the count stays fourteen); the runtime README's heap text and known gaps (the device memory sum beside the heap's block, where it runs out, and the earlier speed row); new_heap_texture(_for_views), heap_texture_size_and_align, has_unified_memory and Gap::HeapTexture docs; docs/API.md and the conformance heap-size side's step 2; docs/REFUSALS.md regenerated (HeapTexturePlace's site is heap_place). RUNTIME_VERSION 2564 (renumbered at landing: development held 2563). runtime-sources.sha256 unchanged (guard PASS, m3-max-84127). Verified: red FAIL / new PASS on the RTX 3090 (build m3-max-84138, run 84144), the RX 7900 XTX (84137, 84221; rt suite under m2v_gpu 993 passed, 4 skipped, 84222) and the Iris Xe (84227, 84238); CPU suites 84127 (conformance + rt 1279 passed, 2 skipped); clippy plain 84180, m2v_gpu 84172, m2v_cpu_icd 84181, rustdoc + api-docs 84182, all EXIT=0; states-only play on lavapipe 84256 equal to the base (gb-3090-r2 10643 render / 15299 compute, windrag-780m-b4-um790 8972 / 225, 0 refused). The consumer's arm64 guest walk on the RTX 3090 at pin S (m3-max-84046) asked for no texture on a Shared heap, so the evidence is the device tests and timing. --- AGENTS.md | 9 +- .../src/rt_side/heap_sizes.rs | 9 +- crates/metal2vulkan-runtime/README.md | 52 ++++--- crates/metal2vulkan-runtime/src/device.rs | 8 +- crates/metal2vulkan-runtime/src/error.rs | 5 +- crates/metal2vulkan-runtime/src/texture.rs | 130 +++++++++++++----- crates/metal2vulkan/src/cache/mod.rs | 2 +- docs/API.md | 6 +- docs/REFUSALS.md | 4 +- 9 files changed, 156 insertions(+), 69 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index a9a21c574..727042d02 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -62,10 +62,13 @@ order, and a lower one never overrides a higher one. atomics, 64-bit floats, SIMD groups (the subgroup size range with its stages and operations, and maximal reconvergence), unified memory (decided by Vulkan's physical device type alone: one copy of a Managed buffer on an integrated or CPU - device, two elsewhere, and a texture over a host-pointer import in place on an integrated or + device, two elsewhere; a texture over a host-pointer import in place on an integrated or CPU device, after one counted copy pair at its making, and through its per-use counted copy - elsewhere), the attachment feedback loop (a device without it reads a render - target through a counted copy of that target, recorded as a known gap), run-time texel + elsewhere; and a Shared heap's image texture in its heap on an integrated or CPU device, and + elsewhere an optimal image of its own in device memory, its heap range left unused, whose + device memory beside the heap's block is recorded as a known gap), the attachment feedback + loop (a device without it reads a render target through a counted copy of that target, + recorded as a known gap), run-time texel offsets (a device with the maintenance8 feature takes a run-time texel offset as the sampling or read instruction's own operand; a device without it branches over the offset's values, and that branch's compile time is recorded as a known gap), the push window (the device's diff --git a/crates/metal2vulkan-conformance/src/rt_side/heap_sizes.rs b/crates/metal2vulkan-conformance/src/rt_side/heap_sizes.rs index 03946321f..ce45550e6 100644 --- a/crates/metal2vulkan-conformance/src/rt_side/heap_sizes.rs +++ b/crates/metal2vulkan-conformance/src/rt_side/heap_sizes.rs @@ -8,8 +8,9 @@ //! //! 1. the alignment is a power of two, for every query; //! 2. for a Private or Shared query, a heap of its storage mode, `align + size` bytes, takes a -//! texture of the descriptor at offset `align` (a Shared one where the device's image of it -//! takes the Shared memory type; it is held to the first alone where the placement is +//! texture of the descriptor at offset `align` (a Shared one on a device without unified +//! memory, as an image of its own, and on one with it where the device's image of it takes +//! the Shared memory type; it is held to the first alone where the placement is //! `Gap::HeapTexture`); //! 3. there, where the runtime moves the format's bytes, level 0's first slice written from a //! buffer reads back unchanged: a `Depth32Float` slice's bytes are depths within `[0, 1]`, the @@ -55,8 +56,8 @@ pub(super) fn hold( let index = on.texture_index(descriptor.pixel_format, descriptor.usage); let texture = match on.device.new_heap_texture(descriptor, index, heap, align) { Ok(texture) => texture, - // A device whose image of the descriptor takes no Shared memory type sizes it, and places - // none of it in a Shared heap: the answer is held to step 1 there. + // A device with unified memory whose image of the descriptor takes no Shared memory type + // sizes it, and places none of it in a Shared heap: the answer is held to step 1 there. Err(rt::Error::Unsupported(rt::Gap::HeapTexture { .. })) if query.storage == Storage::Shared => { diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index 99591cc29..af02fd2af 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -1976,12 +1976,22 @@ made, with no lock, and never rewritten for layouts. answers differ by device, so the consumer places by this device's, and are the same for every storage mode. An image the device requires an allocation of its own for, or whose memory types leave out the heap's (`VkMemoryRequirements::memoryTypeBits`), is `Gap::HeapTexture`: at the - size query, the Private type; at the placement, the block's class's type. + size query, the Private type; at the placement, the block's class's type (a Shared heap's on a + device without unified memory, below: the size query's answer). `Device::new_heap_texture(descriptor, index, heap, offset)` binds the texture's image at that offset in the heap, where the consumer's own placement put it: no allocation and no texture block, the bytes those the memory holds, as Metal does not zero heap textures. In a Shared - block the image is the device's optimal image, bound in the Shared type's memory as one in a - Private block is in the Private type's. The host reaches its texels as any texture's, through + block on a device with unified memory (`Device::has_unified_memory`, Vulkan's device type + integrated or CPU) the image is the device's optimal image, bound in the Shared type's memory + as one in a Private block is in the Private type's. On a device without it, whose Shared memory + is system memory it reaches across its link, a Shared heap's texture is an optimal image of + its own in device memory, made as `Device::new_texture` makes one but not zeroed, and its range + in the heap is left unused: it takes a place in a texture block or an allocation of its own, + which spills as a texture's does, it aliases no other resource of the heap, and no write of + another moves it from undefined. Its placement is checked against + `heap_texture_size_and_align`'s answers as one in the heap is, its uses take the heap's id in + the hazard sets, a `use_heap` of its heap covers it, and it holds the block, as one in the heap + does (the known gaps of textures). The host reaches its texels as any texture's, through `Texture::replace_region` and `Texture::get_bytes`, whose copies go through the GPU and flush or invalidate only their own staging bytes. The block's mapping over the image holds the device's own layout, which Metal's texture states nothing of, so the image's range needs no flush or @@ -2543,21 +2553,27 @@ made, with no lock, and never rewritten for layouts. - `Device::pixel_format_info` answers as an Apple M3 Max under macOS 27.0.1, which describes none of the values from 630 to 645 (`BGRA10Unorm`, its packed, sRGB, PQ and HLG forms, `R10UintX6`, `RG10UintX12` and the rest); an Apple M4 under that release describes them. -- A texture in a Shared heap is placed only where the device's optimal image of it takes the Shared - memory type with no allocation of its own; elsewhere its placement is `Gap::HeapTexture`, which - the consumer counts. lavapipe, the Radeon 780M and the Iris Xe (Mesa 26.2.6) take it (jobs - m3-max-79654, m3-max-79685 and m3-max-79854); the RTX 2080 (NVIDIA 620.70.06) does not, so a - Shared heap's texture is that gap there (job m3-max-79682), and is expected to be on the RTX 3090, - which runs the same driver and was not run. -- On a discrete device whose images take the Shared type, a Shared heap's texture lies in system - memory, and every read and write of it crosses the device's link; nothing is copied. A Mac whose - Metal makes Shared heap textures has unified memory, where no such cost arises. Measured on the - RX 7900 XTX (RADV, Mesa 26.2.6) behind a PCIe 4.0 x4 link (job m3-max-79841): a kernel sampled a - 4096 by 4096 `RGBA16Float` texture of incompressible texels, 10 times over in each command - buffer. A command buffer took 203.1 ms with the texture in a Shared heap and 2.10 ms with it in - a Private heap, 97 times as long, about 6.6 GB/s against 640 GB/s. Each figure is the median of - 7 command buffers, the two alternated in one job, and they ranged 203.08 to 203.18 ms and - 2.093 to 2.103 ms. +- On a device with unified memory, a texture in a Shared heap is placed only where the device's + optimal image of it takes the Shared memory type with no allocation of its own; elsewhere its + placement is `Gap::HeapTexture`, which the consumer counts. lavapipe, the Radeon 780M and the + Iris Xe (Mesa 26.2.6) take it (jobs m3-max-79654, m3-max-79685 and m3-max-79854). A device + without unified memory makes it as an image of its own (below), whether or not its images take + the Shared type. +- On a device without unified memory, a Shared heap's texture is an image of its own in device + memory, and its range in the heap is left unused, where a Mac whose Metal makes Shared heap + textures has unified memory and the heap's memory is the textures'. So the device memory a + program's Shared heaps' textures take is the sum of their images' sizes, on top of the heaps' + blocks, which are system memory the consumer took: their bytes are held twice, once unused. + Where device memory runs out, such an image spills as any texture's does (a Private allocation's + rule, above): it takes the next memory type the image allows, in the device's order, and its + make fails out of device memory only once each of those types is out too, where Metal's + placement in a heap whose memory it already holds takes no memory. Before this form, the image + lay in the heap's system memory, where every read and write crossed the link: on the RX 7900 XTX + (RADV, Mesa 26.2.6) behind a PCIe 4.0 x4 link (job m3-max-79841) a kernel that sampled a 4096 by + 4096 `RGBA16Float` texture of incompressible texels, 10 times over in each command buffer, took + 203.1 ms a command buffer with the texture in a Shared heap and 2.10 ms with it in a Private + heap, 97 times as long, about 6.6 GB/s against 640 GB/s (each figure the median of 7 command + buffers, the two alternated in one job, ranging 203.08 to 203.18 ms and 2.093 to 2.103 ms). - A heap texture whose bytes another resource of its heap wrote moves out of `VK_IMAGE_LAYOUT_UNDEFINED` before its next use that writes it (`Metrics::heap_moves`), as Vulkan's memory aliasing asks: "each of those image subresources must have its layout diff --git a/crates/metal2vulkan-runtime/src/device.rs b/crates/metal2vulkan-runtime/src/device.rs index 77887e8df..4fb07c198 100644 --- a/crates/metal2vulkan-runtime/src/device.rs +++ b/crates/metal2vulkan-runtime/src/device.rs @@ -1043,7 +1043,8 @@ impl Device { /// `hasUnifiedMemory`: true where Vulkan's device type is integrated or CPU, false for a /// discrete or virtual GPU. On a discrete GPU, `Shared` memory is system memory the GPU reads - /// across its bus, as on a Mac with a discrete GPU. + /// across its bus, as on a Mac with a discrete GPU, and a Shared heap's texture is an image of + /// its own in device memory ([`Device::new_heap_texture`]). pub fn has_unified_memory(&self) -> bool { self.shared.core.unified_memory } @@ -1826,8 +1827,9 @@ impl Core { } /// Whether Vulkan's device type is integrated or CPU ([`Device::has_unified_memory`]): then a - /// Managed buffer is its Shared range, with no device copy; else every Managed buffer keeps - /// one. + /// Managed buffer is its Shared range, with no device copy, and a Shared heap's texture lies in + /// its heap; else every Managed buffer keeps one, and a Shared heap's texture is an image of + /// its own ([`Device::new_heap_texture`]). pub(crate) fn unified_memory(&self) -> bool { self.unified_memory } diff --git a/crates/metal2vulkan-runtime/src/error.rs b/crates/metal2vulkan-runtime/src/error.rs index fb3a0569d..ddfee1a9c 100644 --- a/crates/metal2vulkan-runtime/src/error.rs +++ b/crates/metal2vulkan-runtime/src/error.rs @@ -1521,8 +1521,9 @@ pub enum Gap { /// (`VUID-vkBindImageMemory-memory-10926`), or one whose image the device requires an /// allocation of its own for, or that does not take the memory type of its heap's class /// (`VkMemoryRequirements::memoryTypeBits`): the block's where it is placed, the Private type - /// at the size query. The RTX 2080's optimal images (NVIDIA 620.70.06) take no Shared type, so - /// a Shared heap's texture is this gap there. + /// at the size query and at a Shared heap's placement on a device without unified memory, + /// whose texture is an image of its own + /// ([`Device::has_unified_memory`](crate::Device::has_unified_memory)). /// /// Basis: ours (heap textures are built for Private and Shared heaps of placeable images). HeapTexture { diff --git a/crates/metal2vulkan-runtime/src/texture.rs b/crates/metal2vulkan-runtime/src/texture.rs index f5c9282c1..2c7f1a947 100644 --- a/crates/metal2vulkan-runtime/src/texture.rs +++ b/crates/metal2vulkan-runtime/src/texture.rs @@ -727,8 +727,10 @@ pub(crate) struct ResolveCopy { /// What holds the memory an image lies in that is not its own. enum Under { - /// A heap texture's block, and the image's first byte there. - Heap { block: Arc, at: u64 }, + /// A heap texture's block, and the image's first byte there; `None` for a Shared heap's + /// texture on a device without unified memory, whose image is one of its own + /// ([`Device::new_heap_texture`]). + Heap { block: Arc, at: Option }, /// The buffer a texture over a buffer lies over: its block, or its device copy. Buffer { _buffer: Buffer }, /// A surface plane's image in place ([`Device::new_exported_surface`]): the opaque @@ -1482,8 +1484,10 @@ impl Device { /// rounded up to, and the alignment raised to, the device's buffer-image granularity, so that /// a buffer placed by the same answers never shares a granularity page with the texture. /// - /// The answer is the same for every storage mode: a texture whose image does not take the - /// Shared memory type is sized here and refused where it is placed in a Shared heap + /// The answer is the same for every storage mode. On a device with unified memory + /// ([`Device::has_unified_memory`]), a texture whose image does not take the Shared memory type + /// is sized here and refused where it is placed in a Shared heap; elsewhere a Shared heap's + /// texture is an image of its own, placed in the heap by these answers /// ([`Device::new_heap_texture`]). /// /// A texture buffer ([`TextureType::TextureBuffer`]) has no image: its answer is its texels' @@ -1629,12 +1633,18 @@ impl Device { /// holds the block. /// /// The heap's block is Private or Shared, as Metal's heap is: in either, the image is the - /// device's optimal one, bound in the block's memory alike. The host reaches a Shared heap's - /// texture as any texture's, through [`Texture::replace_region`] and [`Texture::get_bytes`], - /// whose copies go through the GPU; the block's mapping over the image holds the device's own - /// layout, which Metal's texture states nothing of. On a discrete device, whose Shared memory - /// is system memory, the image's reads and writes cross the device's bus (the crate's README, - /// the known gaps of textures). + /// device's optimal one. In a Private heap, and in a Shared heap on a device with unified + /// memory ([`Device::has_unified_memory`]: an integrated GPU or a CPU device), it is bound in + /// the block's memory. On a device without it, whose Shared memory is system memory the + /// device reaches across its bus, a Shared heap's texture is an image of its own in device + /// memory, as [`Device::new_texture`] makes one, and its range in the heap is left unused: + /// it allocates, it aliases nothing in the heap, and its bytes are its own, not zeroed, as + /// Metal's heap textures are not; its place in the heap is checked as one in the heap's + /// memory is, and its uses take the heap's id as one there does (the crate's README, the + /// known gaps of textures). The host reaches a Shared heap's texture as any texture's, + /// through [`Texture::replace_region`] and [`Texture::get_bytes`], whose copies go through + /// the GPU; where it lies in the block, the block's mapping over the image holds the device's + /// own layout, which Metal's texture states nothing of. /// /// A texture buffer ([`TextureType::TextureBuffer`]) is made in place in the heap's bytes, as /// Metal's is: a buffer of its texels' bytes is placed at `offset` as @@ -1650,7 +1660,8 @@ impl Device { /// consumer does not hold; [`Gap::HeapTexture`] for an image in an exported block /// ([`Device::new_exported_block`](crate::Device::new_exported_block)), or an image the device /// requires an allocation of its own for or that does not take the memory type of the block's - /// class (the Private or the Shared type); [`Refusal::HeapTexturePlace`] for a heap range that + /// class (the Private or the Shared type; for a Shared heap's image of its own, as + /// [`Device::heap_texture_size_and_align`]); [`Refusal::HeapTexturePlace`] for a heap range that /// leaves its block, or a texture that does not fit in the heap at `offset` or is not aligned /// there as the device requires ([`Device::heap_texture_size_and_align`]). pub fn new_heap_texture( @@ -1670,7 +1681,9 @@ impl Device { /// `MTLHeap`'s `newTextureWithDescriptor:offset:`, for a texture reached through its views /// alone: a texture as [`Device::new_texture_for_views`] makes it, its image bound at /// `offset` in `heap` as [`Device::new_heap_texture`] binds one, by the same rule. Nothing is - /// allocated, and the bytes are those the heap's memory holds there; its uses, and its + /// allocated, and the bytes are those the heap's memory holds there, but for a Shared heap's + /// texture on a device without unified memory, an image of its own as + /// [`Device::new_heap_texture`] makes one there; its uses, and its /// views', take the heap's id in the compute encoders' hazard sets, and the texture holds the /// block. Where Metal's heap texture has a `gpuResourceID` of its own, this one has none, as /// [`Device::new_texture_for_views`] says: shaders reach it through its views @@ -1693,10 +1706,15 @@ impl Device { } /// The source of a texture placed at `offset` in `heap`: the heap's block, which the consumer - /// holds and which is a Private or Shared block of the pool's memory. + /// holds and which is a Private or Shared block of the pool's memory. On a device without + /// unified memory (rule 2's unified-memory query, [`Device::has_unified_memory`]), a Shared + /// heap's texture is an image of its own, its place in the heap checked against the size + /// query's answers ([`Device::heap_texture_size_and_align`]) as an image in the heap's memory + /// is against its own. /// - /// Err: [`Error::NoSuchBlock`]; [`Gap::HeapTexture`] for an exported block, whose memory is - /// dedicated to its buffer (`VUID-vkBindImageMemory-memory-10926`). + /// Err: [`Error::NoSuchBlock`]; for an image of its own, [`Device::heap_texture_size_and_align`]'s + /// errors and [`Refusal::HeapTexturePlace`]; else [`Gap::HeapTexture`] for an exported block, + /// whose memory is dedicated to its buffer (`VUID-vkBindImageMemory-memory-10926`). fn heap_source( &self, descriptor: &TextureDescriptor, @@ -1704,6 +1722,12 @@ impl Device { offset: u64, ) -> Result, Error> { let block = self.block(heap.block)?; + if block.memory.class == MemoryClass::Shared && !self.core().unified_memory() { + let fit = self.heap_texture_size_and_align(descriptor)?; + let (base, block_len) = (block.memory.base(), block.memory.len); + heap_place(heap, offset, fit, base, block_len)?; + return Ok(Source::HeapOwn(block, heap)); + } if block.memory.own.is_some() { return Err(Error::Unsupported(Gap::HeapTexture { pixel_format: descriptor.pixel_format, @@ -1988,6 +2012,9 @@ impl Device { Some(core.heap_ids.of(core, heap.block, heap.offset)), Some(heap.offset.saturating_add(*offset)), ), + Source::HeapOwn(_, heap) => { + (Some(core.heap_ids.of(core, heap.block, heap.offset)), None) + } _ => (None, None), }; // Over a buffer in place, the memory its image lies in (`check_over`). @@ -1998,7 +2025,9 @@ impl Device { _ => Unplaced::Copy, }; let (named, first, home) = match &source { - Source::Plain | Source::Heap(..) => (None, vk::ImageLayout::UNDEFINED, plan.home()), + Source::Plain | Source::Heap(..) | Source::HeapOwn(..) => { + (None, vk::ImageLayout::UNDEFINED, plan.home()) + } Source::Managed(bytes, places) => { check_places(&d, plan.unit, bytes, places)?; let named = Named { @@ -2051,8 +2080,17 @@ impl Device { offset, }; let at = heap.offset.saturating_add(offset); - (bind, Some(Under::Heap { block, at })) + ( + bind, + Some(Under::Heap { + block, + at: Some(at), + }), + ) } + // On a device without unified memory, an image of its own in device memory + // (`heap_source`); the texture holds the heap's block, as one in it does. + Source::HeapOwn(block, _) => (Bind::Pooled, Some(Under::Heap { block, at: None })), Source::Over(..) if named .as_ref() @@ -3994,6 +4032,9 @@ enum Source<'a> { Managed(&'a Buffer, &'a [BytesPlace]), /// A block, a heap's range of it, and the texture's offset in the heap. Heap(Arc, HeapRange, u64), + /// A Shared heap's block and range, for an image of its own in device memory, on a device + /// without unified memory ([`Device::new_heap_texture`]). + HeapOwn(Arc, HeapRange), /// A buffer, the texture's offset in it, its rows' pitch, and what the making does where the /// device's linear image does not take it. Over(&'a Buffer, u64, u64, Unplaced), @@ -4097,6 +4138,38 @@ fn heap_fit( }) } +/// The byte in its block's memory where a heap texture of `fit` at `offset` in `heap` lies: its +/// block's memory starts at `base` in the allocation and is `block_len` bytes long. +/// +/// Err: [`Refusal::HeapTexturePlace`] for a heap range that leaves its block, or a texture past +/// the heap's end or whose byte is off `fit`'s alignment. +fn heap_place( + heap: HeapRange, + offset: u64, + fit: SizeAndAlign, + base: u64, + block_len: u64, +) -> Result { + let heap_end = heap.offset.checked_add(heap.len); + let at = (heap.offset.checked_add(offset)).and_then(|at| base.checked_add(at)); + let end = offset.checked_add(fit.size); + match at { + Some(at) + if heap_end.is_some_and(|heap_end| heap_end <= block_len) + && end.is_some_and(|end| end <= heap.len) + && at.is_multiple_of(fit.align) => + { + Ok(at) + } + _ => Err(Error::Refused(Refusal::HeapTexturePlace { + offset, + size: fit.size, + align: fit.align, + heap_len: heap.len, + })), + } +} + /// What [`make`] has made so far. #[derive(Default)] struct Made { @@ -4174,22 +4247,8 @@ impl Made { { let dedicated = dedicated.requires_dedicated_allocation != vk::FALSE; let fit = heap_fit(core, d, class, &requirements, dedicated)?; - let refused = Error::Refused(Refusal::HeapTexturePlace { - offset, - size: fit.size, - align: fit.align, - heap_len: heap.len, - }); - let heap_end = heap.offset.checked_add(heap.len); - let at = heap.offset.checked_add(offset); - 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| (base + at).is_multiple_of(fit.align)); - match (fits, at) { - (true, Some(at)) => (Backing::InBlock, memory, base + at), - _ => return Err(refused.into()), - } + let at = heap_place(heap, offset, fit, base, block_len)?; + (Backing::InBlock, memory, at) } else if let Some((place, block)) = pooled { ( Backing::Placed(place), @@ -6730,7 +6789,10 @@ pub(crate) trait TextureObject { fn bound(&self) -> Option { let image = self.object().image_of()?; let (buffer, base) = match &image._under { - Some(Under::Heap { block, at }) => block.memory.range(*at), + Some(Under::Heap { + block, + at: Some(at), + }) => block.memory.range(*at), _ => self.in_place().map(|rows| (rows.buffer, rows.offset))?, }; Some(crate::blit::Span { diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index e5ec52370..282c7679f 100644 --- a/crates/metal2vulkan/src/cache/mod.rs +++ b/crates/metal2vulkan/src/cache/mod.rs @@ -93,7 +93,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 606; /// changes no behaviour, and then updates that hash alone with the commit saying why, or changes /// behaviour and also bumps this version. The commit that bumps it says what changed; this comment /// keeps no history. -pub const RUNTIME_VERSION: u32 = 2563; +pub const RUNTIME_VERSION: u32 = 2564; /// Writes a digest as lowercase hex. pub(crate) fn write_hex(f: &mut fmt::Formatter<'_>, name: &str, hash: &Hash256) -> fmt::Result { diff --git a/docs/API.md b/docs/API.md index 0c2d7973a..9707d7479 100644 --- a/docs/API.md +++ b/docs/API.md @@ -2793,8 +2793,10 @@ named states the rule in full. numbers with Metal's; it holds each answer to three steps: (1) the alignment is a power of two; (2) a Private descriptor's texture is made at offset `align` in a heap of `align + size` bytes; (3) there, level 0's first slice written from a buffer reads back unchanged. A Shared descriptor - is held to the same steps in a heap of a Shared block where the device's image takes the Shared - memory type, and to step 1 where its placement there is `Gap::HeapTexture`. A Managed or + is held to the same steps in a heap of a Shared block where the runtime makes it there (on a + device without unified memory always, as an image of its own; on one with it where the + device's image takes the Shared memory type), and to step 1 where its placement there is + `Gap::HeapTexture`. A Managed or Memoryless descriptor is held to step 1 alone, as no heap of either mode is made. A descriptor whose bytes the runtime does not move (depth and stencil both, multisample, `Depth32Float`) is held to steps 1 and 2. diff --git a/docs/REFUSALS.md b/docs/REFUSALS.md index 2d528d7f1..ada30da27 100644 --- a/docs/REFUSALS.md +++ b/docs/REFUSALS.md @@ -293,7 +293,7 @@ Columns: | `RestoreFenceRefused` | A texture in place over host memory's import whose make the caller's `RestoreFence` refused | every device (a public call's own check of its arguments) | `ours`: the caller's own fence refuses its own make; Metal has no span to fence | 1: `crates/metal2vulkan-runtime/src/texture.rs (texture)` | `-` | | `TextureBufferAlignment` | A texture buffer (`MTLTextureTypeTextureBuffer`) over a buffer (`Buffer::new_texture`) whose offset is not a multiple of the device's minimum... | every device (a public call's own check of its arguments) | `metal-documented`: `MTLDevice.h`: `minimumTextureBufferAlignmentForPixelFormat:` "Returns the minimum alignment required for offset and rowBytes when creating a texture buffer from a buffer" | 1: `crates/metal2vulkan-runtime/src/texture.rs (texel_texture)` | `-` | | `TextureBufferNotOverBuffer` | A texture buffer (`MTLTextureTypeTextureBuffer`) made other than over a buffer or in a heap | every device (a public call's own check of its arguments) | `ours`: a texture buffer's texels are a buffer's bytes, read through a buffer view of the buffer; the runtime places no buffer of its own outside the consumer's heaps | 1: `crates/metal2vulkan-runtime/src/texture.rs (shape)` | `-` | -| `HeapTexturePlace` | A heap texture whose image, or a texture buffer's texels, do not lie in its heap (`Device::new_heap_texture`, `Device::new_heap_texture_for_views`) | every device (a public call's own check of its arguments) | `ours`: an image bound past its heap's range would take memory the heap does not hold, and Vulkan binds an image only at its alignment, and views a texel buffer only at its offset alignment | 2: `crates/metal2vulkan-runtime/src/texture.rs (heap_texels)`, `crates/metal2vulkan-runtime/src/texture.rs (make)` | `-` | +| `HeapTexturePlace` | A heap texture whose image, or a texture buffer's texels, do not lie in its heap (`Device::new_heap_texture`, `Device::new_heap_texture_for_views`) | every device (a public call's own check of its arguments) | `ours`: an image bound past its heap's range would take memory the heap does not hold, and Vulkan binds an image only at its alignment, and views a texel buffer only at its offset alignment | 2: `crates/metal2vulkan-runtime/src/texture.rs (heap_place)`, `crates/metal2vulkan-runtime/src/texture.rs (heap_texels)` | `-` | | `DrawableDescriptor` | A drawable's texture (`Device::new_drawable_texture`) of a descriptor that is not a 2D texture of one level of the swapchain's image extent, or... | every device (a public call's own check of its arguments) | `ours`: the texture is the swapchain's image, which the descriptor states | 1: `crates/metal2vulkan-runtime/src/texture.rs (new_drawable_texture)` | `-` | | `DrawableFormat` | A drawable's texture (`Device::new_drawable_texture`) over a swapchain whose image format is not the one the runtime holds the descriptor's pixel... | every device (a public call's own check of its arguments) | `ours`: the texture's views and copies read the image in the format the runtime holds the pixel format in | 1: `crates/metal2vulkan-runtime/src/texture.rs (new_drawable_texture)` | `-` | | `DrawableUsage` | A drawable's texture (`Device::new_drawable_texture`) over a swapchain whose image usage lacks some of what the runtime's own texture of the... | every device (a public call's own check of its arguments) | `ours`: each of the texture's uses takes its image's usage | 1: `crates/metal2vulkan-runtime/src/texture.rs (new_drawable_texture)` | `-` | @@ -600,7 +600,7 @@ Each refusal's sites, with the function that builds it. - `rt:Refusal::RestoreFenceRefused`: `crates/metal2vulkan-runtime/src/texture.rs (texture)` - `rt:Refusal::TextureBufferAlignment`: `crates/metal2vulkan-runtime/src/texture.rs (texel_texture)` - `rt:Refusal::TextureBufferNotOverBuffer`: `crates/metal2vulkan-runtime/src/texture.rs (shape)` -- `rt:Refusal::HeapTexturePlace`: `crates/metal2vulkan-runtime/src/texture.rs (heap_texels)`; `crates/metal2vulkan-runtime/src/texture.rs (make)` +- `rt:Refusal::HeapTexturePlace`: `crates/metal2vulkan-runtime/src/texture.rs (heap_place)`; `crates/metal2vulkan-runtime/src/texture.rs (heap_texels)` - `rt:Refusal::DrawableDescriptor`: `crates/metal2vulkan-runtime/src/texture.rs (new_drawable_texture)` - `rt:Refusal::DrawableFormat`: `crates/metal2vulkan-runtime/src/texture.rs (new_drawable_texture)` - `rt:Refusal::DrawableUsage`: `crates/metal2vulkan-runtime/src/texture.rs (new_drawable_texture)`