ailloli_ui_render_wgpu/
lib.rs

1//! wgpu backend for Ailloli UI: executes [`ailloli_ui_runtime::DrawCmd`] on the GPU.
2//!
3//! [`Renderer`] owns a reusable GPU context, an optional native surface
4//! attachment, text/icon caches, and stencil targets. The typical frame path is
5//! `render_layered` / `render_layered_scaled` with one [`LayerPass`] per scene
6//! layer (clip mode chosen via [`choose_clip_render_mode`]).
7//!
8//! # Rendering inside an application-owned frame
9//!
10//! Custom hosts can create resources with [`Renderer::device`] and retain control
11//! of their image, encoder, submission, and presentation. Call
12//! [`Renderer::record_layered_to_target_scaled`] with a [`BorrowedRenderTarget`]
13//! after ending the host's render pass. [`TargetLoadOp::Load`] composites the UI
14//! over the host image; [`TargetLoadOp::Clear`] intentionally replaces it.
15//! Finish and submit the encoder on [`Renderer::queue`] before recording another
16//! UI frame. No 3D commands, windowing types, or application policies are added to
17//! the retained scene protocol.
18//!
19//! The target must be a single-sampled, full-size `D2` color view on the same
20//! device and in the renderer's pipeline format. Backdrop blur and non-normal
21//! blending additionally need the matching texture with `COPY_SRC` usage.
22//! Ordinary UI can borrow a view alone. Descriptor checks return
23//! [`TargetRecordingError`]; wgpu still validates actual GPU bindings.
24//!
25//! Existing managed rendering and capture APIs retain their acquire/submit/present
26//! behavior and their [`RendererError`] type. Borrowed recording is an additive
27//! lower-level API, not a replacement for the ordinary `ailloli_ui` application
28//! builder. See the `host_composition` example for a host triangle and retained
29//! UI text recorded into the same image and command encoder.
30//!
31//! # Modules
32//!
33//! | Module | Role |
34//! |--------|------|
35//! | [`renderer`] | Main renderer and layer passes |
36//! | [`pipeline_cache`] | Device, surface, and pipeline bootstrap |
37//! | [`clip`] | Scissor / shader / stencil clip selection |
38//! | [`capture`] | Swapchain readback and PNG helpers |
39//! | [`text`] | Multi-page glyph atlas |
40//! | [`icons`] | Lucide, Devicon, and SVG raster cache |
41//! | [`plan`] | Lightweight per-layer command counts (bench / debug) |
42
43mod env_control;
44
45/// backdrop filter: backdrop region capture from swapchain.
46pub mod backdrop_capture;
47/// Frame readback types and PNG encoding helpers.
48pub mod capture;
49/// GPU clip mode selection (not in `ailloli_ui_core`).
50pub mod clip;
51/// isolated compositor: draw-command bounds for isolated offscreen regions.
52pub mod cmd_bounds;
53/// isolated compositor: post-effect chain (blur) for isolated passes.
54pub mod effect_chain;
55/// Renderer and surface errors.
56pub mod error;
57/// single-pass compositing: CPU-pure frame render plan (vertex arenas + planned layers/batches).
58pub mod frame_plan;
59/// single-pass compositing: GPU-touching frame resource preparation (atlas pin, icon cache).
60pub mod frame_prep;
61/// isolated compositor hardening: isolated offscreen budgets and downgrade policy.
62pub mod isolated_budget;
63/// isolated compositor: isolated pass planning types.
64pub mod isolated_plan;
65/// isolated compositor: offscreen texture pool.
66pub mod offscreen_pool;
67pub use backdrop_capture::BackdropTable;
68/// backdrop filter: backdrop blur pipeline.
69pub mod backdrop_blur;
70/// blend modes: Multiply / Screen composite shader.
71pub mod composite_blend;
72/// Icon rasterization and GPU texture cache.
73pub mod icons;
74/// CPU vertex builders and draw helpers.
75pub mod passes;
76/// wgpu pipelines and surface bundle.
77pub mod pipeline_cache;
78/// Per-layer draw command statistics.
79pub mod plan;
80/// Abstract render target used by host/VR entry points.
81pub mod render_target;
82/// Main GPU renderer.
83pub mod renderer;
84/// GPU resource policies (see `pipeline_cache::WgpuSurfaceBundle`).
85pub mod resources;
86/// WGSL shader sources.
87pub mod shaders;
88/// Shared depth/stencil for rounded clips.
89pub mod stencil;
90/// Glyph atlas upload and caching.
91pub mod text;
92/// Vertex formats for rects, textures, and rounded rects.
93pub mod vertices;
94
95pub use capture::{CaptureParams, CapturedFrame, CapturedFrameFormat};
96pub use clip::{choose_clip_render_mode, resolve_clip_render_plan, ClipRenderMode, RenderClipPlan};
97pub use error::{RendererError, TargetRecordingError};
98pub use frame_plan::{
99    ClipBindKind, FramePlanError, FrameRenderPlan, IsolatedPass, PipelineKind, PlannedBatch,
100    PlannedLayer, TextureBindKind,
101};
102pub use frame_prep::PreparedResources;
103pub use icons::{rasterize_svg, IconKey};
104pub use isolated_budget::{
105    IsolatedBudgetConfig, IsolatedBudgetPolicy, IsolatedDowngradeCounts, IsolatedDowngradeReason,
106};
107pub use isolated_plan::{
108    CompositeParams, IsolatedEffect, IsolatedEffectChain, OffscreenPassId, PlannedIsolatedPass,
109};
110pub use pipeline_cache::gpu_debug_enabled;
111pub use pipeline_cache::{
112    ResizeOutcome, SurfaceAttachment, SurfaceAttachmentState, SurfaceBootstrapConfig,
113    SurfaceConfigDeferredReason, SurfaceContextReuseFailure, SurfaceGpuContext,
114    SurfaceReattachOutcome, WgpuRenderContext,
115};
116pub use plan::{build_render_plan, LayerPlan, RenderPlan};
117pub use render_target::{
118    BorrowedRenderTarget, PhysicalExtent, RenderFrame, RenderTarget, TargetLoadOp,
119};
120pub use renderer::{IsolatedFrameMetrics, LayerPass, Renderer, RendererOptions};