Heap textures Metal keeps compressed over host pages take the image over the pages

On RADV, a texture placed in a no-copy heap over dma-buf pages never reached the dma-buf image
path (runtime_lane::dma_buf_imports: four tests counted (0, 0) images and fallbacks where they
expect (1, 0) or (0, 1), on the Radeon 780M, jobs 4456 runs 1 and 2). Two causes:
- heap_plan makes a texture whose optimal image does not fit Metal's answer a shadow of the
  tiles Metal lays it in uncompressed (HeapLayout::Uncompressed) where Metal keeps it losslessly
  compressed, and host_heap_plan returned that shadow at once for any Tiled route, so the image
  over the pages (a DRM_FORMAT_MOD_LINEAR image over a dma-buf of its own pages, or a linear
  image over pointer pages) was never asked. Metal's bytes of such a texture are no layout of
  its texels, so the driver's rows serve it as well as those tiles do, with no copy: now that
  image where it serves, and the uncompressed tiles in a copied heap or where none serves. A
  texture Metal tiles keeps the shadow of Metal's tiles, as before.
- dma_buf_heap_plan held the natural image's memory alignment to the heap's answer (Metal's 128
  bytes, finer than RADV's 256-byte plane rule). The image's import is its own, bound at its
  start, so no heap offset is held to it; its plane offset is the texels' offset in their first
  page, which the driver takes or refuses as the texture is made (the shadow, counted and
  announced, where it refuses), as dma_buf.rs documents. NaturalLayout's unread alignment goes.

Both routes announce heap-texture-lossless-layout per texture, as before. The tests that failed
are the four dma_buf_imports heap texture tests; the evidence is their run on RADV after this.

(cherry picked from commit 28555cdec39555657339d74bef72298b9d84e2ca)
This commit is contained in:
Anees Iqbal committed 2026-11-07 11:49:38 -08:00
1 parent 5c430a6ef1
commit 01cf2d8553
2 files changed
+32 -14

No files matched your search

+5 -4
View File
@@ -27,7 +27,10 @@
//! - **The bytes.** The runtime never maps a dma-buf: `contents` stays the caller's pointer, and
//! the CPU's writes through it and the GPU's through the imports meet in the same pages with no
//! flush or invalidate (the types are host-coherent).
//! - **Textures** placed in a heap over such pages (and their views), where the device also lists
//! - **Textures** placed in a heap over such pages (and their views) that Metal does not tile
//! there (one it keeps losslessly compressed, one of a format or shape whose tiles are not
//! measured: `texture/heap.rs`; one Metal tiles is a shadow of its elements in Metal's tiles),
//! where the device also lists
//! `VK_EXT_image_drm_format_modifier` and `VK_EXT_queue_family_foreign` (enabled beside the
//! route, `create.rs`'s `dma_buf_image_names`), are each an image of `DRM_FORMAT_MOD_LINEAR` made
//! for dma-bufs and bound to a dedicated import (`VkMemoryDedicatedAllocateInfo`) of the one
@@ -816,12 +819,11 @@ pub(super) struct DmaBufImage {
/// The layout the driver gives a `DRM_FORMAT_MOD_LINEAR` image of its own choosing
/// ([`Device::dma_buf_natural_layout`]): its plane's row and array pitches, and its memory's
/// bytes and alignment, from the plane's first byte.
/// bytes from the plane's first byte.
pub(super) struct NaturalLayout {
pub(super) row_pitch: u64,
pub(super) slice_pitch: u64,
pub(super) size: u64,
pub(super) alignment: u64,
}
/// The one memory plane of an image of `DRM_FORMAT_MOD_LINEAR`, whose layout Vulkan reports
@@ -1273,7 +1275,6 @@ impl Device {
row_pitch: report.row_pitch,
slice_pitch: report.array_pitch,
size: requirements.size,
alignment: requirements.alignment,
}))
}
+27 -10
View File
@@ -2357,7 +2357,11 @@ impl Device {
/// A texture of a plain format Metal lays out tiled (`HeapLayout::Tiled`) is a shadow of its
/// elements tiled in the heap's bytes (`AliasRoute::Tiled`, `heap_tiled.rs`), where its optimal
/// image takes copies and the moves fit the device; elsewhere it takes the routes above,
/// announced untiled when it is made.
/// announced untiled when it is made. One Metal keeps losslessly compressed, whose bytes on
/// Metal are no layout of its texels, takes the image over the pages above where one serves
/// (in the driver's rows, with no copy), and the shadow of its uncompressed tiles planned for
/// it (`HeapLayout::Uncompressed`) in a copied heap or where none serves; announced
/// `heap-texture-lossless-layout` either way.
///
/// A multisample texture is a shadow of its samples in Metal's tiles (`AliasRoute::Tiled`, a
/// compressed one's uncompressed tiles, [`sample_tiles`](Self::sample_tiles)), where one
@@ -2405,8 +2409,13 @@ impl Device {
};
return Ok(HeapPlan { image, ..p });
}
// A shadow of Metal's tiles serves it over host pages as in any heap.
if p.image.route == AliasRoute::Tiled {
// A shadow of Metal's tiles serves it over host pages as in any heap. One of the tiles a
// texture Metal keeps losslessly compressed lays out in uncompressed
// (`HeapLayout::Uncompressed`: Metal's bytes are no layout of its texels) serves it in a
// copied heap, and where no image over the pages does (below); one that does serves it
// with no copy, its rows no less Metal's layout than those tiles.
let uncompressed = matches!(p.metal_layout, HeapLayout::Uncompressed(_));
if p.image.route == AliasRoute::Tiled && (!uncompressed || bytes.copied()) {
return Ok(p);
}
// A copied heap's bytes the GPU uses lie in a copy of the caller's pages (`copied.rs`),
@@ -2487,6 +2496,11 @@ impl Device {
}
}
}
// Where no linear image serves: the shadow of the uncompressed tiles planned, else one
// of the bytes in rows.
if p.image.route == AliasRoute::Tiled {
return Ok(p);
}
let image = self.memory_shadow(linear, &p)?;
Ok(HeapPlan { image, ..p })
}
@@ -2495,8 +2509,11 @@ impl Device {
/// (`dma_buf.rs`), `linear` its plan: an image of the driver's `DRM_FORMAT_MOD_LINEAR` layout
/// ([`Device::dma_buf_natural_layout`]) at the texture's offset, made and bound to a dedicated
/// import of a dma-buf of its own pages as the texture is made (`heap_texture_at`), where the
/// device makes one of the plan and its bytes and alignment fit the heap's answer; else a
/// shadow of the heap's bytes ([`dma_buf_heap_shadow`](Self::dma_buf_heap_shadow)).
/// device makes one of the plan and its bytes fit the heap's answer; else a shadow of the
/// heap's bytes ([`dma_buf_heap_shadow`](Self::dma_buf_heap_shadow)). Its memory's alignment
/// binds no offset of the heap's: the import is the image's own, bound at its start, its
/// plane at the texels' offset in their first page, which the driver takes or refuses as the
/// texture is made (RADV: a multiple of 256 bytes), the shadow taken where it refuses.
#[cfg(unix)]
fn dma_buf_heap_plan(
&self,
@@ -2504,9 +2521,9 @@ impl Device {
p: &HeapPlan,
facts: &crate::image_plan::ImageFacts<'_>,
) -> Result<HeapImage, Error> {
let SizeAndAlign { size, align } = p.size_and_align;
let size = p.size_and_align.size;
let why = match self.dma_buf_natural_layout(&linear, facts)? {
Ok(natural) if natural.size <= size && natural.alignment <= align => {
Ok(natural) if natural.size <= size => {
return Ok(HeapImage {
plan: linear,
tiling: vk::ImageTiling::DRM_FORMAT_MODIFIER_EXT,
@@ -2516,9 +2533,9 @@ impl Device {
});
}
Ok(natural) => format!(
"the driver's DRM_FORMAT_MOD_LINEAR image of it takes {} bytes at an alignment \
of {}, past the {size} at {align} the heap answers",
natural.size, natural.alignment
"the driver's DRM_FORMAT_MOD_LINEAR image of it takes {} bytes, past the {size} \
the heap answers",
natural.size
),
Err(why) => why,
};