Skip to main content

Crate aetna_wgpu

Crate aetna_wgpu 

Source
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 keySlot (@location)Accepted types
vec_a2Color (rgba 0..1) or Vec4
vec_b3Color or Vec4
vec_c4Vec4 (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§

LayoutPrepared
What [RunnerCore::prepare_layout] returns: the resolved DrawOp list plus the redraw deadlines split into two lanes (see PrepareResult for the lane semantics).
MsaaTarget
A multisampled color attachment.
PointerMove
Outcome of a pointer-move dispatch through [RunnerCore::pointer_moved] (or its backend wrappers).
PrepareResult
Reported back from each backend’s prepare(...) per frame.
PrepareTimings
Per-stage CPU timing inside each backend’s prepare. Cheap to compute (a handful of Instant::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.
WgpuAppTexture
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§

PaintItem
Sequencing entry for the recorded paint stream.

Functions§

app_texture
Wrap an app-allocated wgpu::Texture for compositing via a aetna_core::tree::surface widget.