Expand description
§wgpu-native-texture-interop
Import native GPU textures (GL framebuffers, Vulkan images, Metal IOSurfaces) into host-owned wgpu textures. This is the core library of the servo-wgpu-interop workspace.
This crate is framework-agnostic — it has no Servo dependency and can be used by any application that needs to import externally-produced GPU content into wgpu.
§What it does
A “producer” (Servo, a GL renderer, a video decoder, etc.) renders into a native GPU resource. This crate imports that resource into a wgpu::Texture owned by the host application, enabling zero-copy compositing across API boundaries.
§Platform support
| Platform | Import path | Status |
|---|---|---|
| Linux / Android | GL FBO → Vulkan external memory → wgpu | Implemented |
| macOS / iOS | IOSurface → Metal texture → wgpu | Implemented |
| Windows (Vulkan) | GL FBO → Vulkan image (NT handle) → wgpu | Implemented |
| Windows (DX12) | GL FBO → DX12 shared texture → wgpu | Builds, runtime deferred |
§Key types
HostWgpuContext— wraps the host’swgpu::Deviceandwgpu::QueueNativeFrame— platform-specific frame produced by the offscreen rendererImportedTexture— the result of importing aNativeFrameinto wgpuImportOptions— controls import behavior (format, usage flags)CapabilityMatrix— runtime query of what the current platform/driver supportsInteropBackend— detected backend (Vulkan, Metal, DX12)FrameProducer/TextureImporter— traits for the produce/import pipelineWgpuTextureImporter— defaultTextureImporterimplementationInteropSynchronizer— trait for cross-API synchronization policies
§Modules
raw_gl— surfman-independent GL import functions. UseRawGlFrameProducerfor any GL application without bringing surfman as a dependency (setdefault-features = false).surfman_gl— surfman-backed frame producer (enabled by default via thesurfmanfeature).
§Usage
For Servo embedding, pair this crate with servo-wgpu-interop-adapter which handles Servo-specific setup. For standalone GL import, see demo-raw-gl which uses the raw_gl module directly.
[dependencies]
# Full (with surfman support):
wgpu-native-texture-interop = "0.1"
# Minimal (raw GL only, no surfman):
wgpu-native-texture-interop = { version = "0.1", default-features = false }§License
Modules§
- raw_gl
- Raw GL-to-wgpu import primitives with no surfman dependency.
- surfman_
gl
Structs§
- Capability
Matrix - Reports which frame types can be imported on the current device and backend.
- Dx12
Shared Texture - A frame backed by a D3D12 resource shared via a DXGI NT handle.
- GlFramebuffer
Source - Host
Wgpu Context - Wraps a
wgpu::Deviceandwgpu::Queuetogether with the detected backend. - Implicit
Only Synchronizer - A synchronizer that accepts
SyncMechanism::NoneandSyncMechanism::ImplicitGlFlushand rejects any explicit semaphore or fence mechanism withInteropError::UnsupportedSynchronization. - Import
Options - Options that control how
WgpuTextureImporterprocesses each frame. - Imported
Texture - A successfully imported wgpu texture, ready for use in a render pipeline.
- Metal
Texture Ref - A frame backed by a
MTLTexturefrom a Metal producer. - Noop
Synchronizer - A synchronizer that does nothing. Suitable when the caller manages all synchronization externally (e.g. via a shared queue or explicit barriers).
- Producer
Capabilities - The set of
NativeFrameKinds aFrameProduceris able to emit. - Vulkan
External Image - A frame backed by a Linux DMABUF imported via Vulkan
VK_KHR_external_memory_fd+VK_EXT_image_drm_format_modifier. - Vulkan
Semaphore Synchronizer - Synchronizer that uses an external
VkSemaphorefd per frame to gate consumer submits on producer rendering completion. - Wgpu
Texture Importer - The main entry point for importing frames into wgpu textures.
Enums§
- Capability
Status - Whether a particular interop capability is available on this device.
- Interop
Backend - The wgpu graphics backend in use on the host device.
- Interop
Error - Errors that can occur during frame import or synchronization.
- Native
Frame - A frame produced by a
FrameProducer, ready to be imported by aTextureImporter. - Native
Frame Kind - Discriminant for
NativeFramevariants, without carrying the frame data. - Sync
Mechanism - Describes how the producer signals that a frame is ready and how the consumer signals that it has finished reading.
- Texture
Origin - Which corner of the texture holds row 0 of the image.
- Unsupported
Reason - Why a particular interop path is not available.
Traits§
- Frame
Producer - Produces
NativeFrames for aTextureImporterto consume. - GlFramebuffer
Source Impl - Interop
Synchronizer - Hook points called by
WgpuTextureImporteraround each frame import. - Texture
Importer - Imports a
NativeFrameinto awgpu::Texture.
Functions§
- backend_
name - Returns a human-readable name of the wgpu backend powering
device. - print_
wgpu_ backend - Logs the active wgpu backend to stderr.