Skip to main content

Module present

Module present 

Source
Expand description

The present pass: the engine’s premultiplied frame, converted for a swapchain that stores STRAIGHT alpha.

Every engine pipeline blends and writes premultiplied alpha (see super::pipelines), which is exactly what an opaque swapchain — or a premultiplied-expecting translucent one, Android’s Inherit — wants. The one composite alpha mode that disagrees is iOS’s PostMultiplied: it reads the frame’s (C·a, a) as (C, a), so every partial-alpha pixel presents too dark. UnpremultiplyPass is what serves that surface — the frame is rendered into an intermediate of the host’s own and one full-screen triangle writes (rgb / max(a, ALPHA_FLOOR), a) into the swapchain, in unpremultiply.wgsl.

A render pass, never a compute one. The conversion is a fragment write into an ordinary RENDER_ATTACHMENT colour target: neither a compute stage nor a storage texture (E1/E2), both of which the engine refuses by design and neither of which a downlevel target offers. A swapchain configured for this tier carries RENDER_ATTACHMENT and nothing else, so a storage write into it is not merely disallowed by the rules — it is unavailable.

The host decides, the pass states the rule. Which surfaces need it is UnpremultiplyPass::selected_by: an OutputAlpha::Straight swapchain does, an OutputAlpha::Premultiplied one does not. Note the split that implies for a host on this arm — the intermediate the engine renders into really does hold premultiplied pixels, so it is described to crate::EngineRenderer::encode as OutputAlpha::Premultiplied (which is what makes the frame’s base colour clear in the same convention as everything drawn over it); Straight describes the swapchain this pass then writes, not the buffer it reads.

A plain copy, for a frame that has to read itself back. A frame carrying a backdrop blur reads a region of its own target back into a page (crate::renderer::RegionCopyMode), which a swapchain — RENDER_ATTACHMENT only, never widened — cannot be read back from. CopyPresentPass serves that frame on an opaque or premultiplied surface: the host renders it into an intermediate of the swapchain’s own format and this pass copies it across, one full-screen quad through the engine’s own region-copy program (copy.wgsl), sharing the conversion pass’s plumbing — a pass the caller records into its own encoder, clearing a fresh swapchain image, reading one sampled texture. It costs one full-screen fragment pass on exactly the frames that carry a backdrop; a straight-alpha surface already renders every frame into an intermediate and needs no second pass.

The caller owns the encoder. UnpremultiplyPass::record records into a wgpu::CommandEncoder it is handed and never submits, the same single-submit contract frust_gpu::encoder states and crate::EngineRenderer::encode keeps: the frame’s own passes and this one land in one command buffer, in order, against the texture about to be presented.

Structs§

CopyPresentPass
The plain present pass for one surface: the frame, rendered into an intermediate of the swapchain’s own format, copied into the swapchain unconverted (see the module doc’s A plain copy).
UnpremultiplyPass
The straight-alpha present pass for one surface: a pipeline built for that surface’s own format plus the bind-group layout its program derived.

Constants§

ALPHA_FLOOR
The floor the shader divides by, mirroring its own ALPHA_FLOOR constant.
UNPREMULTIPLY
The conversion program, loaded from the shader directory like every other engine module so frust_gpu::lint::lint_wgsl_dir sees every line the GPU compiles.
UNPREMULTIPLY_NAME
The name UNPREMULTIPLY is registered under in this pass’s own shader library.