pub struct SurfaceFactory { /* private fields */ }Expand description
A cheap, cloneable handle to a wgpu::Instance used to create a surface on
a different thread than the one that owns the renderer.
§Why this exists
wgpu surface creation reads the platform window handle, which several
windowing backends (notably winit on macOS/AppKit) only make available on
the main/UI thread. A render-thread split therefore cannot create the
surface where the renderer lives; instead the UI thread creates a
DetachedSurface via this factory and hands it across to the render
thread, which configures it there. A wgpu::Instance is Send + Sync + Clone (Arc-backed) and a Surface it produces stays compatible with any
adapter/device the cloned instance requests, so the two threads share one
instance with no unsafe.
The mobile shells do not need this: they receive a platform-created surface
pointer and go through
create_android_surface /
create_metal_surface instead.
Implementations§
Source§impl SurfaceFactory
impl SurfaceFactory
Sourcepub fn new(instance: &Instance) -> SurfaceFactory
pub fn new(instance: &Instance) -> SurfaceFactory
Clones instance into a factory that can be moved to the UI thread.
Sourcepub fn create_detached_surface(
&self,
target: impl Into<SurfaceTarget<'static>>,
) -> Result<DetachedSurface, Error>
pub fn create_detached_surface( &self, target: impl Into<SurfaceTarget<'static>>, ) -> Result<DetachedSurface, Error>
Create a DetachedSurface from a window handle on the calling
thread — call this on the thread the windowing backend requires (the
main/UI thread for winit). The returned surface is Send and may then be
moved to the render thread and configured there.
This performs only the window-handle-dependent step (surface creation); the device and the swapchain configuration are both built later, on the configuring thread, so nothing here touches a GPU device.
Trait Implementations§
Source§impl Clone for SurfaceFactory
impl Clone for SurfaceFactory
Source§fn clone(&self) -> SurfaceFactory
fn clone(&self) -> SurfaceFactory
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more