Skip to main content

VkOpaqueFd

Struct VkOpaqueFd 

Source
pub struct VkOpaqueFd { /* private fields */ }
Available on Hermit or Unix or WASI only.
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

Source

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.

Source

pub fn from_shared_fd( fd: Arc<OwnedFd>, desc: VkOpaqueExportDesc, ) -> Result<Self, InvalidHandleError>

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn with_acquire_release(self, release: VkSlotRelease) -> Self

Attach a consumer→producer slot-release back-pressure gate — see VkSlotRelease field docs.

Source

pub fn fd(&self) -> &Arc<OwnedFd> ⓘ

Source

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.

Source

pub fn size(&self) -> u64

Source

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).

Source

pub fn offset(&self) -> u64

Source

pub fn dedicated(&self) -> bool

Source

pub fn width(&self) -> u32

Source

pub fn height(&self) -> u32

Source

pub fn format(&self) -> PixelFormat

Source

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.

Source

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.

Source

pub fn acquire_timeline(&self) -> Option<&VkAcquireTimeline>

Producer-side acquire-sync timeline. See Self::with_acquire_timeline / VkAcquireTimeline.

Source

pub fn acquire_binary(&self) -> Option<&VkAcquireBinary>

Producer-side per-frame fresh BINARY acquire semaphore. See Self::with_acquire_binary / VkAcquireBinary.

Source

pub fn acquire_release(&self) -> Option<&VkSlotRelease>

Consumer→producer slot-release back-pressure gate. See Self::with_acquire_release / VkSlotRelease.

Source

pub fn uuid(&self) -> [u8; 16]

Trait Implementations§

Source§

impl Clone for VkOpaqueFd

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for VkOpaqueFd

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> MaybeSend for T
where T: Send + ?Sized,

Source§

impl<T> MaybeSendSync for T
where T: Send + Sync + ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,