pub struct VkOpaqueFd { /* private fields */ }Expand description
Vulkan opaque-fd export via VK_KHR_external_memory_fd.
fd is Arc<OwnedFd> — Clone bumps the Arc; last drop closes the
fd via std’s OwnedFd::drop. Producers handing this off to an
ownership-transferring importer (vkAllocateMemory with
VkImportMemoryFdInfoKHR, cuImportExternalMemory with OPAQUE_FD)
MUST call OwnedFd::try_clone() and pass the dup — see the
module-level “FD/handle consumer rule”.
Implementations§
Source§impl VkOpaqueFd
impl VkOpaqueFd
Sourcepub fn new(
fd: OwnedFd,
desc: VkOpaqueExportDesc,
) -> Result<Self, InvalidHandleError>
pub fn new( fd: OwnedFd, desc: VkOpaqueExportDesc, ) -> Result<Self, InvalidHandleError>
Adopt a freshly-minted OwnedFd (typically the
VkMemoryGetFdInfoKHR result) plus its VkOpaqueExportDesc.
Use Self::from_shared_fd instead whenever the producer
already holds a long-lived Arc<OwnedFd> per pool slot — see its
doc for why per-frame fd identity is load-bearing.
Construct from a pre-existing Arc<OwnedFd> — the producer’s
shared reference is preserved end-to-end without an
intermediate dup(2). This is the stable-identity
constructor: every per-frame carrier built from the same
producer slot has the same Arc::as_ptr identity AND the
same underlying raw fd value, which keeps the
glImportMemoryFdEXT / vkAllocateMemory(VkImportMemoryFdInfoKHR)
import idempotent per-slot.
Use this whenever the producer has a long-lived
Arc<OwnedFd> per pool slot (e.g. an FFmpeg-Vulkan intermediate
pool, or a camera-RAW SDK decoder’s worker pool). Use
Self::new only when you’re handing the carrier a
freshly-minted OwnedFd whose ownership the carrier should adopt.
Why this matters on NVIDIA Windows GL:
glImportMemoryWin32HandleEXT (and its Fd sibling) refuses
the SECOND import of the same underlying kernel memory
object — returns GL_INVALID_OPERATION (“already imported”).
Each dup(2) / DuplicateHandle creates a fresh raw value
that points to the SAME underlying object; NVIDIA’s driver
tracks the underlying object, not the per-fd integer, and
rejects the second import. Per-frame fd-dup therefore breaks
a GL bridge’s “mint once, cache forever” strategy. This
constructor sidesteps that entirely.
§Errors
Rejects a zero desc.size and a degenerate desc extent. Every
other field is inert metadata the importer reads back verbatim —
see VkOpaqueExportDesc.
Sourcepub fn with_plane_format(self, plane_format: PlaneFormat) -> Self
pub fn with_plane_format(self, plane_format: PlaneFormat) -> Self
Attach a per-plane storage format hint. Use when the exported
memory backs a single plane of a multi-plane format (e.g. NV12
luma alone) — the consumer-side importer maps this directly to
the wgpu single-channel texture format instead of trying to
re-derive it from Self::format.
Sourcepub fn with_vk_image_usage(self, usage: u32) -> Self
pub fn with_vk_image_usage(self, usage: u32) -> Self
Attach the producer-side VkImageUsageFlags. Required for
Vulkan→Vulkan OPAQUE imports so the consumer’s
VkImageCreateInfo matches exactly — see field doc.
Sourcepub fn with_acquire_timeline(self, timeline: VkAcquireTimeline) -> Self
pub fn with_acquire_timeline(self, timeline: VkAcquireTimeline) -> Self
Attach a GPU-side acquire-sync timeline — see
VkAcquireTimeline. When stamped, the consumer is expected to
chain a GPU wait on the producer’s exported TIMELINE semaphore
at the carried value before its first read; the producer
elides its own CPU-side post-wait. Unstamped carriers
guarantee CPU-visibility of the memory on hand-off.
Sourcepub fn with_acquire_binary(self, binary: VkAcquireBinary) -> Self
pub fn with_acquire_binary(self, binary: VkAcquireBinary) -> Self
Attach a per-frame fresh BINARY acquire semaphore — see
VkAcquireBinary. Used as a fallback when the consumer
can’t wire the timeline-import path (typical NVIDIA Windows
GL combo where GL_NV_timeline_semaphore + OPAQUE_WIN32
returns GL_INVALID_VALUE and D3D12_FENCE export is
IMPORTABLE-only). Consumer dispatch order: timeline first,
binary second; either successful wait acks its own capability
channel and triggers producer-side post-wait elision.
Sourcepub fn with_acquire_release(self, release: VkSlotRelease) -> Self
pub fn with_acquire_release(self, release: VkSlotRelease) -> Self
Attach a consumer→producer slot-release back-pressure gate
— see VkSlotRelease field docs.
pub fn fd(&self) -> &Arc<OwnedFd> ⓘ
Sourcepub fn desc(&self) -> &VkOpaqueExportDesc
pub fn desc(&self) -> &VkOpaqueExportDesc
The whole validated export descriptor, as handed to
Self::from_shared_fd. Re-emitting a carrier over a duped fd
is VkOpaqueFd::new(dup, *src.desc()) — no field-by-field
re-assembly, so a new descriptor field cannot be silently
dropped on the way through.
pub fn size(&self) -> u64
Sourcepub fn memory_type_index(&self) -> u32
pub fn memory_type_index(&self) -> u32
VkMemoryAllocateInfo::memoryTypeIndex the producer allocated
with — the importer MUST pass this exact index (see
VkOpaqueExportDesc::memory_type_index for the two VUs).
pub fn offset(&self) -> u64
pub fn dedicated(&self) -> bool
pub fn width(&self) -> u32
pub fn height(&self) -> u32
pub fn format(&self) -> PixelFormat
Sourcepub fn plane_format(&self) -> Option<PlaneFormat>
pub fn plane_format(&self) -> Option<PlaneFormat>
Per-plane storage hint set via Self::with_plane_format.
Consumers prefer this over Self::format when present.
Sourcepub fn vk_image_usage(&self) -> Option<u32>
pub fn vk_image_usage(&self) -> Option<u32>
Producer-side VkImageUsageFlags set via
Self::with_vk_image_usage. Consumers mirror this on the
import-side VkImage to keep VkImageCreateInfo identical.
Sourcepub fn acquire_timeline(&self) -> Option<&VkAcquireTimeline>
pub fn acquire_timeline(&self) -> Option<&VkAcquireTimeline>
Producer-side acquire-sync timeline. See
Self::with_acquire_timeline / VkAcquireTimeline.
Sourcepub fn acquire_binary(&self) -> Option<&VkAcquireBinary>
pub fn acquire_binary(&self) -> Option<&VkAcquireBinary>
Producer-side per-frame fresh BINARY acquire semaphore. See
Self::with_acquire_binary / VkAcquireBinary.
Sourcepub fn acquire_release(&self) -> Option<&VkSlotRelease>
pub fn acquire_release(&self) -> Option<&VkSlotRelease>
Consumer→producer slot-release back-pressure gate. See
Self::with_acquire_release / VkSlotRelease.