Expand description
Swapchain surfaces: creation, cross-thread hand-off, alpha-mode policy and configuration.
Three types cover the whole life of a swapchain, in the order a shell meets them:
SurfaceFactory— a cheap clone of thewgpu::Instancethat creates a surface on the thread the windowing backend requires (the main/UI thread on winit/AppKit).DetachedSurface— the created-but-unconfigured surface, opaque andSend, moved to whichever thread owns the renderer.ConfiguredSurface— the surface plus the swapchain configuration it was brought up with, and the one derived answer everything downstream keys off: whether it actually came up translucent (ConfiguredSurface::resolved_translucent).
Every decision this module makes — which composite alpha mode to resolve
(resolve_alpha_mode), which swapchain format to pick
(select_surface_format), what the configuration should be
(surface_config) — is a pure function over plain values, so it is
host-testable with neither a GPU nor a window server. Only
ConfiguredSurface::configure/ConfiguredSurface::reconfigure/
ConfiguredSurface::resize touch a live device.
§Device seam
This module speaks wgpu primitives directly — a &wgpu::Instance to
create surfaces from, a &wgpu::Device to configure them against — rather
than an owning context type. Anything that pools the instance/adapter/device
sits above these entry points and passes its handles in, so nothing here
needs to know how that pooling works.
§Render-attachment only
The swapchain is configured with RENDER_ATTACHMENT and nothing else: the
engine draws the frame through an ordinary render pass, in whichever of
SURFACE_FORMATS the platform reports first. There is no
compute-storage-write path here, so no surface has to carry
STORAGE_BINDING and no surface is pinned to a single format to satisfy a
compute target.
Structs§
- Configured
Surface - A configured swapchain surface: the surface itself, the configuration it was brought up with, and whether it actually came up translucent.
- Detached
Surface - A created-but-not-yet-configured
wgpu::Surface, produced bySurfaceFactory::create_detached_surfaceon the windowing thread and configured on the render thread. - Surface
Factory - A cheap, cloneable handle to a
wgpu::Instanceused to create a surface on a different thread than the one that owns the renderer.
Enums§
- Surface
Alpha Request - What a caller wants of the surface’s alpha, expressed without naming a
wgputype — the public, platform-independent request a shell makes.
Constants§
- SURFACE_
FORMATS - Every swapchain format
select_surface_formatwill configure a surface with — a membership set, not a preference order.
Functions§
- alpha_
mode_ is_ straight_ translucent - Whether a resolved alpha mode means “translucent, and the swapchain stores STRAIGHT alpha” — the combination the engine’s premultiplied output cannot be presented into unconverted.
- alpha_
mode_ is_ translucent - Whether a resolved
wgpu::CompositeAlphaModeactually composites the surface’s alpha against what is behind it — i.e. whether the surface really came up translucent, as opposed to what the caller requested. - alpha_
mode_ needs_ premultiply - Whether a swapchain configured with this composite alpha mode expects the pixels it is handed to be premultiplied.
- compositor_
expects_ premultiplied - Whether
backend’s compositor actually compositesmodepremultiplied, despitealpha_mode_is_straight_translucentanswering true for it — an upstream wgpu-hal truth bug specific to one backend/mode pair, not a property of the mode alone. - resolve_
alpha_ mode - Resolves a caller’s
SurfaceAlphaRequestagainst the live surface’s reportedalpha_modes, choosing the actualwgpu::CompositeAlphaModeto configure with. - select_
surface_ format - Picks the swapchain format to configure with: the first format the
surface reports that is one of
SURFACE_FORMATS. - surface_
config - Builds the
wgpu::SurfaceConfigurationa surface is brought up with.