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.

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§

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.