Expand description
wgpu backend for custom Aetna hosts.
Most applications should implement aetna_core::App and run it
through aetna-winit-wgpu. Use this crate directly when you are
writing your own host, embedding Aetna into an existing wgpu
renderer, or producing headless render artifacts.
The public entry point is Runner. It owns:
- GPU resources: pipelines, buffers, text atlas, and icon atlas.
- Backend-agnostic interaction state shared through
aetna_core::runtime::RunnerCore. - A snapshot of the last laid-out tree so input arriving between frames hit-tests against the geometry the user can see.
§Custom host loop
The runner does not own the device, queue, swapchain, window, or
event loop. A host creates those resources, forwards input into the
runner, builds a fresh El tree, prepares GPU buffers, and renders:
use aetna_core::prelude::*;
use aetna_wgpu::Runner;
let mut runner = Runner::new(&device, &queue, surface_format);
runner.set_surface_size(surface_width, surface_height);
// Per frame:
app.before_build();
let theme = app.theme();
let mut tree = app.build(&aetna_core::BuildCx::new(&theme));
runner.set_hotkeys(app.hotkeys());
runner.set_theme(theme);
runner.prepare(&device, &queue, &mut tree, viewport, scale_factor);
runner.render(&device, &mut encoder, target_texture, target_view, None, load_op);prepare is split from render/draw so all queue.write_buffer
calls and atlas uploads happen before render-pass recording, matching
wgpu’s expected order. Coordinates passed to pointer methods are
logical pixels; render targets are physical pixels, so pass the host
scale factor to Runner::prepare.
Use Runner::render when Aetna should own pass boundaries. This is
required for backdrop-sampling custom shaders. Use Runner::draw
only when you are already inside a host-owned pass and do not need
backdrop sampling.
§Custom shaders
Call Runner::register_shader with a name and WGSL source. The
shader’s vertex/fragment must use the shared instance layout — see
shaders/rounded_rect.wgsl (in aetna-core) for the canonical
example. Bind the shader at a node via
El::shader(ShaderBinding::custom(name).with(...)). Per-instance
uniforms map to three generic vec4 slots:
| Uniform key | Slot (@location) | Accepted types |
|---|---|---|
vec_a | 2 | Color (rgba 0..1) or Vec4 |
vec_b | 3 | Color or Vec4 |
vec_c | 4 | Vec4 (or fall back to scalar f32 packed in .x) |
Stock rounded_rect reuses the same layout but reads its own named
uniforms (fill, stroke, stroke_width, radius, shadow).
Structs§
- Layout
Prepared - What [
RunnerCore::prepare_layout] returns: the resolvedDrawOplist plus the redraw deadlines split into two lanes (seePrepareResultfor the lane semantics). - Msaa
Target - A multisampled color attachment.
- Pointer
Move - Outcome of a pointer-move dispatch through
[
RunnerCore::pointer_moved] (or its backend wrappers). - Prepare
Result - Reported back from each backend’s
prepare(...)per frame. - Prepare
Timings - Per-stage CPU timing inside each backend’s
prepare. Cheap to compute (a handful ofInstant::now()calls per frame) and useful for finding the dominant cost when frame budget is tight. - Runner
- Wgpu runtime owned by the host. One instance per surface/format.
- Wgpu
AppTexture - Concrete wgpu-side
AppTextureBackend. Holds the texture + view + a cached id so the runtime can downcast and pull what it needs without re-creating views per frame.
Enums§
- Paint
Item - Sequencing entry for the recorded paint stream.
Functions§
- app_
texture - Wrap an app-allocated
wgpu::Texturefor compositing via aaetna_core::tree::surfacewidget.