From 699d9bdc1d729d1a2e573faac3fe93bdddf9e437 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Thu, 19 Nov 2026 10:33:17 -0800 Subject: [PATCH] rt surface: every allocation of a dma-buf surface's memory takes device addresses The Iris Xe (ANV, Mesa 26.2.6) refused Surface::buffer's import of a dma-buf surface with VK_ERROR_INVALID_EXTERNAL_HANDLE at vkAllocateMemory (m3-max-53411), after the fd's query and the buffer's requirements listed the type and the planes' imports into it had succeeded. The buffer's import asks device addresses, which rt's buffers need (VUID-vkBindBufferMemory-bufferDeviceAddress-03339); the allocation the dma-buf came from and the planes' imports did not. The expected cause is a driver that keeps one set of flags per payload in a device. The allocation and each plane's import now take device addresses too, one form on every device, so every allocation of one payload in the device asks the same. Verified: nothing yet; the Iris rerun decides whether this is the cause. --- crates/metal2vulkan-rt/README.md | 5 ++++- crates/metal2vulkan-rt/src/surface.rs | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/crates/metal2vulkan-rt/README.md b/crates/metal2vulkan-rt/README.md index 6d3dcad77..e8c134759 100644 --- a/crates/metal2vulkan-rt/README.md +++ b/crates/metal2vulkan-rt/README.md @@ -551,7 +551,10 @@ writes reach with no copy. What a consumer passes to get it, by handle: must take both. Each plane's image lies on its own dedicated import of the surface's dma-buf, bound at its first byte, sized to the larger of its requirement and its stated offset plus its subresource; the allocation the dma-buf came from is freed once the imports and the consumer's - handle exist, so a surface is two allocations, counted in `Gauges::surface_imports`. + handle exist, so a surface is two allocations, counted in `Gauges::surface_imports`. That + allocation and every import of it take device addresses, which the surface's buffer needs: one + payload's allocations in one device take one set of flags (ANV, of Mesa 26.2, refused a buffer's + import with device addresses beside plane imports without them). - `ExportHandle::OpaqueFd` and `ExportHandle::OpaqueWin32`: each plane's format's `LINEAR` tiling offers sampling, rendering and both copies, exportable and importable as the handle, not only in an allocation of its own. The pitch is the driver's own for each plane's `LINEAR` image: the diff --git a/crates/metal2vulkan-rt/src/surface.rs b/crates/metal2vulkan-rt/src/surface.rs index d248e5f90..92112e0bc 100644 --- a/crates/metal2vulkan-rt/src/surface.rs +++ b/crates/metal2vulkan-rt/src/surface.rs @@ -992,10 +992,16 @@ impl Device { } }; let mut export = vk::ExportMemoryAllocateInfo::default().handle_types(spec.handle.vk()); + // The allocation, each plane's import and the buffer's ([`Surface::buffer`]) take device + // addresses alike: one payload's allocations in one device take one set of flags (ANV, of + // Mesa 26.2, refused the buffer's import with device addresses beside planes' imports + // without them, `VK_ERROR_INVALID_EXTERNAL_HANDLE`). + let mut flags = address_flags(); let info = vk::MemoryAllocateInfo::default() .allocation_size(len) .memory_type_index(index) - .push_next(&mut export); + .push_next(&mut export) + .push_next(&mut flags); // SAFETY: an exportable allocation of a type every image takes, bound to nothing. let block = match unsafe { memory::allocate(device, &core.counters, core.max_allocations, &info, None) @@ -1071,11 +1077,13 @@ impl Device { .handle_type(spec.handle.vk()) .fd(fd.as_raw_fd()); let mut dedicated = vk::MemoryDedicatedAllocateInfo::default().image(image); + let mut flags = address_flags(); let info = vk::MemoryAllocateInfo::default() .allocation_size(size) .memory_type_index(import_type) .push_next(&mut import) - .push_next(&mut dedicated); + .push_next(&mut dedicated) + .push_next(&mut flags); // SAFETY: an import of the dma-buf, dedicated to the image, of a type both take, at // least the image's requirement and its stated rows. let memory = match unsafe { @@ -1351,3 +1359,9 @@ fn acquire(from: u32, to: u32, buffer: vk::Buffer) -> vk::BufferMemoryBarrier2<' .offset(0) .size(vk::WHOLE_SIZE) } + +/// The flags every allocation of a surface's memory takes: device addresses, which its buffer +/// needs (`VUID-vkBindBufferMemory-bufferDeviceAddress-03339`). +fn address_flags() -> vk::MemoryAllocateFlagsInfo<'static> { + vk::MemoryAllocateFlagsInfo::default().flags(vk::MemoryAllocateFlags::DEVICE_ADDRESS) +}