Hold a heap texture to the heap's base only where an image of it binds there
Content: the tree of `development` at bb29a64948, unchanged.
This commit is contained in:
1 parent
88d1a345f2
commit
25653b5b1b
7 files changed
+173
-27
No files matched your search
@@ -1157,9 +1157,11 @@ pub enum RuntimeGap {
|
||||
/// The device's `maxBufferSize`.
|
||||
max_buffer_size: u64,
|
||||
},
|
||||
/// A heap texture whose image needs an alignment past the heap memory's base alignment
|
||||
/// (256 KiB): no offset in the heap is sure to meet it. The base is the largest image
|
||||
/// alignment measured (an RX 7900 XTX's multisample images under RADV).
|
||||
/// A heap texture an image of binds into the heap's own memory whose image needs an alignment
|
||||
/// past that memory's base alignment (256 KiB): no offset in the heap is sure to meet it. The
|
||||
/// base is the largest image alignment measured (an RX 7900 XTX's multisample images under
|
||||
/// RADV). A texture whose every image lies in memory of its own instead binds nothing there
|
||||
/// and is not refused with it, whatever alignment it answers.
|
||||
HeapTextureAlignment {
|
||||
/// The alignment the image needs, in bytes.
|
||||
alignment: u64,
|
||||
|
||||
@@ -657,15 +657,18 @@ fn a_heap_texture_is_held_to_metal_s_answer_by_its_image_or_by_a_shadow() {
|
||||
/// such an image is placed, not refused: RADV's on an RX 7900 XTX (Mesa 26.0.8), 128 KiB for a
|
||||
/// `D16`, `D32F` or `D32FS8` image of 8 x 8 texels or more and 256 KiB for a multisample image from
|
||||
/// about 128 x 128 texels, and the Radeon 780M's 64 KiB under the same driver (the alignments alone
|
||||
/// were measured; the sizes here stand in). An alignment past the base is refused typed.
|
||||
/// were measured; the sizes here stand in). An alignment past the base is refused typed, for a
|
||||
/// texture an image of binds into the heap's memory (`AliasRoute::Direct` here; the sibling test
|
||||
/// covers the routes that bind nothing there).
|
||||
#[test]
|
||||
fn every_image_alignment_measured_fits_a_heap_s_base() {
|
||||
use crate::error::{Error, RuntimeGap};
|
||||
use crate::memory::BLOCK_BYTES;
|
||||
use crate::texture::heap::{check_heap_base, heap_extent, HEAP_BASE_ALIGNMENT};
|
||||
use crate::texture::heap::{check_heap_base, heap_extent, AliasRoute, HEAP_BASE_ALIGNMENT};
|
||||
use crate::texture::ImagePlacement;
|
||||
use ash::vk::MemoryRequirements;
|
||||
use std::collections::BTreeSet;
|
||||
let bound = AliasRoute::Direct;
|
||||
let pages = ImagePlacement::new(1, &BTreeSet::new());
|
||||
for alignment in [64 << 10, 128 << 10, 256 << 10] {
|
||||
let image = MemoryRequirements {
|
||||
@@ -675,11 +678,15 @@ fn every_image_alignment_measured_fits_a_heap_s_base() {
|
||||
};
|
||||
let (answer, _) = heap_extent(&image, None, pages);
|
||||
assert_eq!(answer.align, alignment);
|
||||
assert_eq!(check_heap_base(answer.align), Ok(()), "{alignment:#x}");
|
||||
assert_eq!(
|
||||
check_heap_base(bound, None, answer.align),
|
||||
Ok(()),
|
||||
"{alignment:#x}"
|
||||
);
|
||||
}
|
||||
let past = 2 * HEAP_BASE_ALIGNMENT;
|
||||
assert_eq!(
|
||||
check_heap_base(past),
|
||||
check_heap_base(bound, None, past),
|
||||
Err(Error::NotImplemented(RuntimeGap::HeapTextureAlignment {
|
||||
alignment: past
|
||||
}))
|
||||
@@ -689,6 +696,97 @@ fn every_image_alignment_measured_fits_a_heap_s_base() {
|
||||
assert!((BLOCK_BYTES / 2).is_multiple_of(HEAP_BASE_ALIGNMENT));
|
||||
}
|
||||
|
||||
/// The heap's base holds only a texture an image of binds into the heap's own memory
|
||||
/// (`texture/heap.rs`'s `holds_heap_base`): a heap's memory starts at a multiple of
|
||||
/// `HEAP_BASE_ALIGNMENT` alone, so an image whose alignment passes it has no offset there to bind
|
||||
/// at, while a texture whose every image lies in memory of its own binds nothing there — the
|
||||
/// heap's bytes hold its own layout and the encoders move its elements, or nothing of them
|
||||
/// (`AliasRoute::Unaliased`) — and is made wherever the heap's memory starts, as `placement_align`
|
||||
/// already holds its offset to Metal's alignment alone. Refusing it would refuse a texture Metal
|
||||
/// makes: the answer that trips the base is the image's own, which the query hands back widened
|
||||
/// past Metal's (`heap-texture-larger-than-metal`) for a texture no shadow holds, and a
|
||||
/// multisample depth image already asks 256 KiB on RADV.
|
||||
///
|
||||
/// A depth twin's image always binds to the heap's memory (`heap_image` of `Mine::Twin` reaches
|
||||
/// neither shadow route), so a texture held with one is held to the base whatever its own route
|
||||
/// says.
|
||||
///
|
||||
/// `AliasRoute::Shadow` counts among the routes the base holds, as `in_own_memory` has it, though
|
||||
/// `heap_texture_at` makes its image in memory of its own too: the route is reached only on a
|
||||
/// driver that lays depth and stencil images apart from their memory (MoltenVK, measured), whose
|
||||
/// image alignments are Metal's and well inside the base, so no texture is refused for it. The
|
||||
/// rule that would loosen it is `placement_align`'s, not this one's.
|
||||
#[test]
|
||||
fn the_heap_s_base_holds_only_a_texture_whose_image_binds_to_its_memory() {
|
||||
use crate::error::{Error, RuntimeGap};
|
||||
use crate::texture::heap::{check_heap_base, AliasRoute, HEAP_BASE_ALIGNMENT};
|
||||
// The alignment a RADV multisample depth image asks past the base, which the query hands
|
||||
// back for a texture no shadow holds to Metal's answer.
|
||||
let past = 2 * HEAP_BASE_ALIGNMENT;
|
||||
let refused = Err(Error::NotImplemented(RuntimeGap::HeapTextureAlignment {
|
||||
alignment: past,
|
||||
}));
|
||||
let holds_base = |route, twin| check_heap_base(route, twin, past) == refused;
|
||||
let own = [
|
||||
AliasRoute::Tiled,
|
||||
AliasRoute::Lossless,
|
||||
AliasRoute::MemoryShadow,
|
||||
AliasRoute::Planes,
|
||||
AliasRoute::Unaliased,
|
||||
];
|
||||
let bound = [
|
||||
AliasRoute::Direct,
|
||||
AliasRoute::HostTransfer,
|
||||
AliasRoute::Linear,
|
||||
AliasRoute::Hidden,
|
||||
AliasRoute::Compressed,
|
||||
AliasRoute::Shadow,
|
||||
AliasRoute::Apart,
|
||||
];
|
||||
for route in own {
|
||||
assert!(route.in_own_memory(), "{route:?}");
|
||||
assert_eq!(check_heap_base(route, None, past), Ok(()), "{route:?}");
|
||||
// A depth twin of such a texture binds to the heap's memory, so the base holds it.
|
||||
assert!(holds_base(route, Some(AliasRoute::Direct)), "{route:?}");
|
||||
assert!(holds_base(route, Some(AliasRoute::Apart)), "{route:?}");
|
||||
// An alignment the base meets is no refusal either way.
|
||||
assert_eq!(
|
||||
check_heap_base(route, None, HEAP_BASE_ALIGNMENT),
|
||||
Ok(()),
|
||||
"{route:?}"
|
||||
);
|
||||
}
|
||||
for route in bound {
|
||||
assert!(!route.in_own_memory(), "{route:?}");
|
||||
assert!(holds_base(route, None), "{route:?}");
|
||||
assert!(holds_base(route, Some(AliasRoute::Direct)), "{route:?}");
|
||||
assert_eq!(
|
||||
check_heap_base(route, None, HEAP_BASE_ALIGNMENT),
|
||||
Ok(()),
|
||||
"{route:?}"
|
||||
);
|
||||
}
|
||||
// Every route joins one list or the other, and a new one breaks this match rather than
|
||||
// falling silently into the refusing side.
|
||||
let listed = |route: AliasRoute| match route {
|
||||
AliasRoute::Direct
|
||||
| AliasRoute::HostTransfer
|
||||
| AliasRoute::Linear
|
||||
| AliasRoute::Hidden
|
||||
| AliasRoute::Compressed
|
||||
| AliasRoute::Shadow
|
||||
| AliasRoute::Apart => bound.contains(&route),
|
||||
AliasRoute::MemoryShadow
|
||||
| AliasRoute::Unaliased
|
||||
| AliasRoute::Planes
|
||||
| AliasRoute::Tiled
|
||||
| AliasRoute::Lossless => own.contains(&route),
|
||||
};
|
||||
for &route in own.iter().chain(&bound) {
|
||||
assert!(listed(route), "{route:?} is in neither list");
|
||||
}
|
||||
}
|
||||
|
||||
/// A placement offset is held to Metal's own alignment, not this device's answer, for a texture
|
||||
/// whose image lies in memory of its own, and to the answer's for one whose image binds to the
|
||||
/// heap's memory there (`texture/heap.rs`'s `placement_align`). A Navi31 4-sample `Depth32Float`
|
||||
|
||||
@@ -90,10 +90,17 @@
|
||||
//! sizes that image as Metal's `PixelFormatView` texture, so its answer is Metal's. Metal also
|
||||
//! drops a depth or stencil texture's metadata with it off, which no Vulkan request reaches on
|
||||
//! MoltenVK ([`DriverFact::DepthStencilImagesStayGpuOptimized`]): there the texture is a shadow
|
||||
//! of Metal's tiles in the heap's bytes (below) and answers Metal's size; where no such shadow
|
||||
//! serves it (a multisample texture whose samples the device does not move, a depth twin, a
|
||||
//! layout not measured), the answer stays the optimized texture's, larger than Metal's, and the
|
||||
//! device announces `optimized-depth-stencil-texture` once.
|
||||
//! of Metal's tiles in the heap's bytes (below), which answers Metal's size and lays its texels
|
||||
//! out as Metal does. Where no such shadow serves it — a multisample texture whose samples the
|
||||
//! device does not move, a texture whose levels of all its parts pass the moves one shadow holds
|
||||
//! (`HeapTiledCopies::fit`: 16, so a two-aspect texture of 9 levels asks 18) or whose moves pass
|
||||
//! the device's limits, a depth twin, a layout not measured — its image keeps that layout, so
|
||||
//! the heap's bytes are not Metal's layout of its texels, and the device announces
|
||||
//! `optimized-depth-stencil-texture` once. The **answer** there is Metal's own still wherever
|
||||
//! the runtime models it and the texture is held to it ([`held_to_metal`]: a shadow of the
|
||||
//! heap's bytes in rows, or an image apart from them that takes none of its bytes, such as a
|
||||
//! multisample texture's); it is the larger of the images' and Metal's only for a texture no
|
||||
//! shadow holds to Metal's answer, a depth twin among them, which is the cost that notice names.
|
||||
//! - **The heap's memory.** A heap's buffer lies at a multiple of [`HEAP_BASE_ALIGNMENT`] of its
|
||||
//! memory (256 KiB, the largest image alignment measured), of a type optimal images take where
|
||||
//! its storage class has one, else of one linear images take ([`HeapTypes::heap_memory`],
|
||||
@@ -101,10 +108,12 @@
|
||||
//! to half a pooled block it takes whole units of the base of a pooled block; past that, a block
|
||||
//! of its own of its own size (`buffer.rs`'s `placed`), so the largest heap stays one allocation
|
||||
//! of the device. A heap over host pages starts at offset 0 of its own import
|
||||
//! (`HeapProblem::HostMemoryAlignment`), which meets any alignment. A texture whose alignment
|
||||
//! exceeds that base, or whose image the heap's memory type does not take, is refused typed
|
||||
//! (`RuntimeGap::HeapTextureAlignment`, `HeapTextureMemory`), by the query and the call alike
|
||||
//! where the cause is the descriptor.
|
||||
//! (`HeapProblem::HostMemoryAlignment`), which meets any alignment. A texture an image of binds
|
||||
//! into that memory ([`holds_heap_base`]) whose alignment exceeds the base, or whose image the
|
||||
//! heap's memory type does not take, is refused typed (`RuntimeGap::HeapTextureAlignment`,
|
||||
//! `HeapTextureMemory`), by the query and the call alike where the cause is the descriptor. A
|
||||
//! texture whose every image lies in memory of its own binds nothing there and is held to no
|
||||
//! base, as its placement offset is held to Metal's alignment alone ([`placement_align`]).
|
||||
//! - **Linear images**. A texture whose optimal image does not take the heap's memory (any texture
|
||||
//! of a `Shared` heap on the RTX 3090, whose optimal images take no host-visible memory; a depth
|
||||
//! texture of one on MoltenVK) is a linear image there, used only where it can do all the optimal
|
||||
@@ -245,8 +254,9 @@ use std::ptr::NonNull;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::{Arc, Mutex, OnceLock};
|
||||
|
||||
/// The alignment of a heap's memory: a heap texture whose answered alignment exceeds it is
|
||||
/// refused (`RuntimeGap::HeapTextureAlignment`, [`check_heap_base`]). It is the largest image
|
||||
/// The alignment of a heap's memory: a heap texture an image of binds into that memory
|
||||
/// ([`holds_heap_base`]) whose answered alignment exceeds it is refused
|
||||
/// (`RuntimeGap::HeapTextureAlignment`, [`check_heap_base`]). It is the largest image
|
||||
/// alignment measured: RADV on an RX 7900 XTX (Mesa 26.0.8) asks 128 KiB of a `D16`, `D32F` or
|
||||
/// `D32FS8` image of 8 x 8 texels or more and 256 KiB of a multisample depth, stencil or color
|
||||
/// image from about 128 x 128 texels, where the Radeon 780M under the same driver asks at most
|
||||
@@ -1295,10 +1305,34 @@ pub(crate) fn held_to_metal(
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a heap texture of alignment `align` lies at a multiple of it wherever a heap's memory
|
||||
/// starts: refused past [`HEAP_BASE_ALIGNMENT`] (`RuntimeGap::HeapTextureAlignment`).
|
||||
pub(crate) fn check_heap_base(align: u64) -> Result<(), Error> {
|
||||
if align > HEAP_BASE_ALIGNMENT {
|
||||
/// Whether a heap texture whose own image takes `route`, held with a depth twin of `twin`, is
|
||||
/// held to the heap's base at all ([`check_heap_base`]): an image of it binds into the heap's own
|
||||
/// memory, which starts at a multiple of [`HEAP_BASE_ALIGNMENT`] alone, so an image whose
|
||||
/// alignment passes that base has no offset there to bind at.
|
||||
///
|
||||
/// A texture whose every image lies in memory of its own ([`AliasRoute::in_own_memory`]) binds
|
||||
/// nothing to the heap's memory: the heap's bytes hold the texture's own layout there and the
|
||||
/// encoders move its elements to and from the image, or nothing of them
|
||||
/// ([`AliasRoute::Unaliased`]). Wherever the heap's memory starts, such a texture is made, so the
|
||||
/// alignment it answers is no bound on the base and refusing it would refuse a texture Metal
|
||||
/// makes — the rule [`placement_align`] follows for the offset inside the heap. A depth twin's
|
||||
/// image always binds to the heap's memory (`heap_image` of `Mine::Twin` reaches neither shadow
|
||||
/// route), and a texture held with one is never a shadow of its bytes (`shadows: twin.is_none()`),
|
||||
/// so one image of a twinned texture binds either way.
|
||||
fn holds_heap_base(route: AliasRoute, twin: Option<AliasRoute>) -> bool {
|
||||
!route.in_own_memory() || twin.is_some_and(|twin| !twin.in_own_memory())
|
||||
}
|
||||
|
||||
/// Whether a heap texture whose own image takes `route`, held with a depth twin of `twin`, and
|
||||
/// whose answer is of alignment `align`, lies at a multiple of that alignment wherever a heap's
|
||||
/// memory starts: refused past [`HEAP_BASE_ALIGNMENT`] (`RuntimeGap::HeapTextureAlignment`) where
|
||||
/// an image of it binds into the heap's memory and nowhere else ([`holds_heap_base`]).
|
||||
pub(crate) fn check_heap_base(
|
||||
route: AliasRoute,
|
||||
twin: Option<AliasRoute>,
|
||||
align: u64,
|
||||
) -> Result<(), Error> {
|
||||
if holds_heap_base(route, twin) && align > HEAP_BASE_ALIGNMENT {
|
||||
return Err(Error::NotImplemented(RuntimeGap::HeapTextureAlignment {
|
||||
alignment: align,
|
||||
}));
|
||||
@@ -1888,7 +1922,13 @@ impl Device {
|
||||
metal_layout = tiles;
|
||||
}
|
||||
}
|
||||
check_heap_base(size_and_align.align)?;
|
||||
// Only a texture an image of binds into the heap's own memory is held to the heap's base,
|
||||
// and the routes decide that (`holds_heap_base`).
|
||||
check_heap_base(
|
||||
image.route,
|
||||
twin.as_ref().map(|twin| twin.route),
|
||||
size_and_align.align,
|
||||
)?;
|
||||
// The size answered is the optimized texture's where the driver keeps the layout, but for
|
||||
// a shadow of Metal's tiles.
|
||||
if image.route != AliasRoute::Tiled {
|
||||
|
||||
@@ -10,8 +10,11 @@
|
||||
//! format, at least that answer: every answer holds Metal's where it is measured, and Metal keeps
|
||||
//! such a texture of `PixelFormatView` usage compressed), which MoltenVK makes a
|
||||
//! `PixelFormatView` Metal texture where it is a color one: Metal's answer for the texture with
|
||||
//! the property off. A depth or stencil texture's metadata no Vulkan request drops there, so its
|
||||
//! answer is Metal's for the texture with the property on.
|
||||
//! the property off. A depth or stencil texture's metadata no Vulkan request drops there, so the
|
||||
//! device's image of it is the property-on texture's; the answer is still Metal's own for the
|
||||
//! descriptor as given, the property-off number, where a shadow of the heap's bytes holds the
|
||||
//! texture to it (16384 for the single-sample 64x64 `Depth32Float` one, where Metal answers
|
||||
//! 16512 with the property on).
|
||||
//! - **Placement.** A texture fits at every multiple of the answered alignment of a placement
|
||||
//! heap, its `heap_offset` that offset; an offset off the alignment, bytes past the heap's end,
|
||||
//! another storage or CPU cache mode and the other heap type's call are refused `Invalid`, as
|
||||
|
||||
Vendored
+1
-1
@@ -93,7 +93,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 449;
|
||||
/// 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 = 1587;
|
||||
pub const RUNTIME_VERSION: u32 = 1588;
|
||||
|
||||
/// The digest of the sources this build of the crate was compiled from: SHA-256, as lowercase hex,
|
||||
/// of the manifest, the build script, and exactly the files the crate roots' module tree compiles
|
||||
|
||||
+4
-1
@@ -3298,7 +3298,10 @@ each item named states the rule in full.
|
||||
placement heap's `newTextureWithDescriptor:offset:` is held to Metal's own alignment, not that
|
||||
answer, for a texture whose image lies in memory of its own (a shadow of the heap's bytes, a
|
||||
multisample texture's samples in Metal's tiles): no image binds to the heap's memory there, so
|
||||
every offset Metal makes the texture at makes it here.
|
||||
every offset Metal makes the texture at makes it here, and such a texture is held to no
|
||||
alignment bound of the heap's memory base either, whatever alignment it answers. A texture an
|
||||
image of does bind into that memory is refused `NotImplemented(HeapTextureAlignment)` where its
|
||||
answer passes the base (256 KiB, the largest image alignment measured).
|
||||
- **A heap's texture answers the size that placed it** (`Texture::allocated_size`, Metal's
|
||||
`allocatedSize`): the size query's answer for its descriptor, a view's its texture's, as Metal
|
||||
answers; `None` for a texture outside a heap, whose Metal answer the runtime does not model.
|
||||
|
||||
+1
-1
@@ -166,7 +166,7 @@ Columns:
|
||||
| `SparseHeaps` | Sparse heaps and their textures | every device (runtime piece not built) | 3: `crates/metal2vulkan-runtime/src/sparse/encoder.rs (first_slice)`, `crates/metal2vulkan-runtime/src/texture.rs (make_aliasable)` (+1) | `rare`: sparse heaps |
|
||||
| `SparseTileMaps` | What the runtime's emulation of sparse textures does not build yet | every device (runtime piece not built) | 4: `crates/metal2vulkan-runtime/src/binding.rs (slot_tile_map)`, `crates/metal2vulkan-runtime/src/sparse/texture.rs (sparse_refusal)` (+1) | `rare`: sparse texture emulation's unbuilt pieces |
|
||||
| `HeapPastMaxBufferSize` | A heap larger than the device's `maxBufferSize`, which the device can allocate | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/heap.rs (heap_size)` | `rare`: a heap past maxBufferSize |
|
||||
| `HeapTextureAlignment` | A heap texture whose image needs an alignment past the heap memory's base alignment (256 KiB) | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/texture/heap.rs (check_heap_base)` | `rare`: a heap texture needing more than 256 KiB alignment |
|
||||
| `HeapTextureAlignment` | A heap texture an image of binds into the heap's own memory whose image needs an alignment past that memory's base alignment (256 KiB) | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/texture/heap.rs (check_heap_base)` | `rare`: a heap texture needing more than 256 KiB alignment |
|
||||
| `HeapTextureMemory` | A heap texture whose image the heap's memory type does not take | every device (runtime piece not built) | 4: `crates/metal2vulkan-runtime/src/texture/heap.rs (heap_plan)`, `crates/metal2vulkan-runtime/src/texture/heap.rs (host_heap_plan)` (+2) | `app`: a heap texture the heap's memory type does not take |
|
||||
| `FunctionTablePastMaxBufferLength` | A visible-function table of more entries than one buffer of the device's `max_buffer_length` holds words for, or than its size word holds | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/function_table.rs (past_limit)` | `none`: a function table past one buffer |
|
||||
| `IndirectCommandBufferPastMaxBufferLength` | An indirect command buffer of more commands than one buffer of the device's `max_buffer_length` holds the records of | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/indirect_command_buffer.rs (new_indirect_command_buffer)` | `none`: an ICB past one buffer |
|
||||
|
||||
Reference in new issue
Block a user