A texture over an exportable buffer (exported_memory.rs) was a PREINITIALIZED linear
image, or a DRM_FORMAT_MOD_LINEAR one, with no VkExternalMemoryImageCreateInfo, bound in
memory allocated with VkExportMemoryAllocateInfo: VUID-vkBindImageMemory-memory-02728
("it must include at least one of the handles set in
VkExternalMemoryImageCreateInfo::handleTypes"). RADV and NVIDIA tolerate it; the layer
does not.
What changed:
- memory.rs: Memory::bound_memory reads a placement's own record (the block's export,
import, own pages or read-only view, a guest RAM chunk's handle, a dma-buf import) and
answers the handle type an image bound there names: none for memory of no export, the
export's handle for a shared exported block, HOST_ALLOCATION or DMA_BUF for imports, and
no image for a buffer's dedicated allocation (VUID-vkBindImageMemory-memory-10926) or the
caller's memory. Buffer::bound_memory answers it for a buffer (a heap buffer's, its heap's).
- texture.rs alias_unbound decides the image from that record, not the route: over exported
memory the device's linear image made for the handle type (external_linear_image, the
former host_linear_image generalized), else the DRM_FORMAT_MOD_LINEAR one made for it
(ModifierMemory::Exported). Either is made UNDEFINED (VUID-VkImageCreateInfo-pNext-01443),
so its first move may discard the bytes, which only the device's check may vouch for.
- in_place.rs: two check classes, PagesClass::ExportedFd and ExportedDmaBuf. Their buffer
is an exportable Shared buffer of that handle type in a shared block; their textures take
the product's image. A texture over exported memory takes its image where the policy and
those verdicts pass for its accesses; before them it is a CheckPending shadow that moves
in place at the next quiet commit, as over the pooled memory (storage_form.rs now moves
any class over the runtime's own memory). No LinearCost bound there: another API writes
those bytes.
- The image format query (VkPhysicalDeviceExternalImageFormatInfo) must answer the handle
type exportable (importable for imports) without DEDICATED_ONLY, for the linear and the
DRM_FORMAT_MOD_LINEAR image alike; else the texture is a shadow, its notice naming the
query's refusal. A dedicated allocation keeps the shadow, its notice naming 10926.
- ycbcr_planes.rs: the two-plane image is PREINITIALIZED with no handle type, so it takes
only memory whose record says no export or import (KeptTexels::Memory elsewhere).
- in_place::CHECK_VERSION 12 -> 13: the record holds two more classes, so every driver's
check runs once more.
Checked and unchanged: heap.rs's images (heaps are never exported; over host pages they are
HOST_ALLOCATION images, over a copy in device memory a shadow or an Own linear image), the
in-place images over host pages and copies (HOST_ALLOCATION over imports, Own over device
copies), and the runtime's own images in Holds::Images/Buffers blocks.
The placement rule (in_place.rs, "The runtime's exported memory"): per texture (per plane),
the texels' offset in the memory (the buffer's first byte, or its aligned_byte, at a
multiple of 256 there, plus the texture's offset) must be a multiple of
VkMemoryRequirements::alignment from vkGetImageMemoryRequirements for the image made for the
handle type of the texture's format, extent and usage; vkGetImageSubresourceLayout of its
first subresource must answer offset 0 and Metal's rowPitch; its size must stay inside the
buffer. The linear image first, then the DRM_FORMAT_MOD_LINEAR one with its own alignment.
Test: tests/exported_textures.rs, an NV12 picture's R8 3840x2160 and RG8 1920x1080 planes at
32 and 8294432 of an exportable buffer laid with aligned_byte(32), opaque fd and dma-buf,
Private and Shared, under the validation layer: a shadow first, both moved in place after
settle_in_place_checks, readback equal, in place at once after, no layer message.
dma_buf_export settles the checks before its plane textures. Not yet run: this commit is
for the build and the device runs.
(cherry picked from commit 40872fbb4748cbd228c06c27dc0cd63ca2d0a5ec)