gpu-handle-types 0.1.0

Typed, owned native GPU resource handles (Vulkan, D3D11/12, Metal, OpenGL, CUDA, OpenCL, DMA-BUF, IOSurface, AHardwareBuffer, WebGPU, ...), cross-API sync points and video pixel formats, for passing GPU resources between libraries.
Documentation
// SPDX-License-Identifier: MIT OR Apache-2.0

/// Identity of a compute backend. Used as a discriminant on error
/// variants, budget accounting, `GpuContext`, `SyncPoint`, etc.
///
/// `#[non_exhaustive]` — future backend variants can land additively.
#[non_exhaustive]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum BackendKind {
    Cpu,

    /// `wgpu::Device`-backed work submitted via `wgpu::Queue::submit`.
    /// Emitted when the sync primitive is a `wgpu::SubmissionIndex` and
    /// the producer does not expose a lower-level (Vulkan / D3D12 / Metal)
    /// handle.
    #[cfg(feature = "wgpu")]
    Wgpu,

    /// Native Vulkan submit — the producer holds a `VkDevice` and minted
    /// a `VkSemaphore` directly (typically a timeline semaphore).
    Vulkan,
    /// Native D3D12 submit — `ID3D12CommandQueue::Signal` on an
    /// `ID3D12Fence`.
    D3D12,
    /// Native D3D11 submit — `IDXGIKeyedMutex::AcquireSync` /
    /// `ReleaseSync` on a shared texture.
    D3D11,
    /// Native Metal submit — `MTLCommandQueue::commandBuffer` followed by
    /// `encodeSignalEvent` on an `MTLSharedEvent`.
    Metal,
    /// Native OpenGL — `glFenceSync` for a GL-only fence, or a GL
    /// semaphore (`glGenSemaphoresEXT`) imported from a cross-API handle.
    OpenGL,

    #[cfg(feature = "opencl")]
    OpenCl,
    #[cfg(feature = "cuda")]
    Cuda,

    /// WebCodecs encode/decode target (browser). The caller consumes /
    /// produces a `web_sys::VideoFrame` through a `VideoEncoder` /
    /// `VideoDecoder`; as a shared-allocation target it selects the
    /// OffscreenCanvas swapchain path. Gated on the `web-codecs` feature.
    #[cfg(feature = "web-codecs")]
    WebCodecs,

    /// Android AHardwareBuffer export target. The
    /// caller will consume an `AHardwareBuffer*` — NNAPI, foreign
    /// Vulkan, cross-process IPC, etc.
    #[cfg(target_os = "android")]
    AHardwareBuffer,
    /// App-window or MediaProjection VirtualDisplay presentation
    /// surface.
    #[cfg(target_os = "android")]
    AndroidPresentation,
    /// `ASurfaceControl` overlay layer.
    #[cfg(target_os = "android")]
    AndroidSurfaceControl,
    /// `AImageWriter` feeding a foreign `ImageReader`.
    #[cfg(target_os = "android")]
    AImageWriter,
    /// MediaCodec encoder input surface.
    #[cfg(target_os = "android")]
    MediaCodec,
    /// Foreign GL ES context handoff.
    #[cfg(target_os = "android")]
    ForeignGl,
    /// Foreign Vulkan device handoff.
    #[cfg(target_os = "android")]
    ForeignVulkan,
}