Skip to main content

Crate backdrop_blur_wgpu

Crate backdrop_blur_wgpu 

Source
Expand description

backdrop-blur-wgpu — the wgpu backend for backdrop_blur_core’s frosted-glass seam.

It implements BackdropBlur with a safe, WGSL pipeline: a separable Gaussian blur for small radii and dual-Kawase (down/up-sample, the production-compositor algorithm) for large radii, selected by a radius threshold, followed by a tinted, rounded-rect-masked composite. The crate is #![forbid(unsafe_code)]; the only place that could want unsafe — the GPU-uniform Pod impls — uses bytemuck derives.

§What the host provides

The own-loop host renders its UI into an offscreen intermediate and hands it to prepare as a SourceView — the texture view plus its size and color space, because a wgpu::TextureView exposes neither and the backend needs both (the size to clip/scale, the color space to know whether to sRGB-decode on sample — egui renders gamma-encoded, egui#3168). The host owns the final Target; the backend owns only the internal ping-pong scratch.

§On error handling

wgpu resource creation (textures, buffers, pipelines) does not return Result — OOM and validation faults surface through the device’s error handler, not synchronously — so this backend cannot map them to BlurError::ResourceCreation without an async error-scope pass (a candidate refinement). The error it does return synchronously is BlurError::UnsupportedTarget, checked against an allowlist before any GPU call.

Structs§

SourceView
The backdrop source: a sampleable view plus the two things a wgpu::TextureView cannot tell the backend on its own — the texture’s pixel size and its color space. The host constructs one per frame from its offscreen intermediate; it owns the view for the call’s duration.
WgpuBlur
The wgpu implementation of BackdropBlur. Holds the fixed pipeline machinery (bind-group layout, sampler, Gaussian/downsample/upsample pipelines) and the per-(size) scratch (Gaussian ping-pong + dual-Kawase pyramid) + per-target-format composite caches, so repeated frosted surfaces reuse them.
WgpuPrepared
The owned, per-call handle from prepare to record: the resolved blur (which algorithm + its bind groups), the composite bind group, and generation (so record can debug-assert the serial prepare→record contract — a stale handle would alias clobbered scratch, K1). The bind groups already hold their textures/uniforms via wgpu’s internal refcounting.

Enums§

SourceColorSpace
The color space of the backdrop the host hands in. egui renders gamma-encoded regardless of texture format (egui#3168), so its intermediate is GammaSrgb and must be decoded before the linear-light convolution. A host that renders linear uses Linear.