emblema-hal 0.7.1

Rendering hardware abstraction layer for emblema.
Documentation

emblema

A 2D vector renderer in pure Rust, from desktop GPUs down to embedded panels with no compositor.

crates.io docs.rs CI MSRV 1.85 License: BSD-3-Clause

Frosted glass panels with a progress ring, a line chart, bars, a donut chart and toggles, drawn by emblema

Ninety frames from examples/showcase.rs: gradients, blurred layers, backdrop blur, shadows, arcs, dashes and clips, redrawn from scratch every frame. Rendered by this crate, unretouched.

emblema draws the dart:ui Canvas surface over Vulkan 1.1 or GLES 3.0. Paths are tessellated on the CPU, so there is no compute-shader requirement. The shapes an interface draws most -- rounded rects, circles, ellipses and their blurred shadows -- are evaluated per pixel, and glyphs are quads sampled from an atlas. Presentation is a separate axis: into a window, or straight to a KMS plane with no compositor at all.

Why

  • No compute shader requirement. Paths are tessellated on the CPU and the common shapes are evaluated in the fragment shader; the GPU only rasterizes triangles. Runs correctly on every Vulkan 1.1+ device and every GLES 3.0 device, including embedded GPUs where compute is weak or driver support is immature.
  • Predictable frame times. Shaders are compiled ahead of time, and the pipelines a first frame needs can be built before it (Context::prepare_pipelines), so no frame waits on a driver's compile; no driver-specific compute paths.
  • First-class direct scanout. Most 2D renderers assume a windowing system exists. Here, rendering straight to a KMS plane with no compositor is a supported and tested configuration rather than an exercise left to the reader.
  • Pure-Rust source tree. Every dependency compiles from Rust source. No C or C++ toolchain, no pkg-config, no system headers at build time, which keeps cross-compilation to aarch64 and riscv64 boards trivial.

Measured on boards

Interface frame Before After
Raspberry Pi 5 (V3D) 16.07 ms 5.19 ms draws confined to pixels no later opaque draw replaces
Adreno 640 27.2 ms 11.0 ms the same change
Raspberry Pi 5 −34 % rectangles tessellated rather than evaluated as a distance field
VisionFive 2 (riscv64) −30 % the same change

Neither change alters a picture. The conditions they were taken under are in docs/on-a-board.md.

Quick start

[dependencies]
emblema = "0.7.1"
use emblema::{BackendPreference, Canvas, Color, Context, Extent2D, Paint, PixelFormat, Rect};

// The backend is chosen at run time, so one binary serves a board with a
// working Vulkan driver and one where only GLES is usable.
let mut ctx = Context::new(BackendPreference::Auto)?;

let size = Extent2D::new(256, 256);
let mut surface = ctx.create_surface(size, PixelFormat::Rgba8Unorm)?;

let mut canvas = Canvas::new(size);
canvas.clear(Color::WHITE);
canvas.draw_rect(
    Rect::new(32.0, 32.0, 224.0, 224.0),
    &Paint::fill(Color::rgba8(0, 120, 220, 255)),
)?;

// Recording is separate from submitting, so a whole frame is described
// before any of it reaches the GPU and every shape shares one pass.
ctx.draw(&mut surface, &canvas.finish())?;
let pixels = ctx.read(&mut surface)?;

// Destroyed explicitly, because nothing here frees a GPU object on drop. A
// surface still alive when its context goes is a child outliving its device,
// which the validation layer reports as an error rather than a leak.
ctx.destroy_surface(surface);

Two examples draw a whole frame through the public API and write a binary PPM, which needs no encoder (magick out.ppm out.png converts it):

cargo run -p emblema --example showcase -- showcase.ppm   # the picture above, still
cargo run -p emblema --example frame -- frame.ppm         # a light-theme interface with glyphs and an image

Give showcase a frame count as well and it draws that many frames of the loop above through one context and one surface -- showcase-000.ppm onward, ready for magick -delay 5 -loop 0 frames/*.ppm showcase.webp:

mkdir -p frames && cargo run --release -p emblema --example showcase -- frames/showcase.ppm 90

And one draws a moving scene straight to a panel, with no compositor. It takes DRM master, so nothing else may be driving the display; cargo xtask drm says whether this machine can:

cargo run --release -p emblema-present-drm --example panel

What it draws

Status: early development. Everything marked done renders on both backends and is verified against real hardware and a software reference.

Feature Status
Fills, strokes, antialiasing ✅
Linear, radial, sweep and conical gradients, any number of stops, clamp/repeat/mirror/decal tiling ✅
Porter-Duff blend modes ✅
All fifteen advanced blend modes ✅ where the device offers the extension (Vulkan advanced blend, GL_KHR_blend_equation_advanced); reported unavailable elsewhere, never approximated
Clipping to rectangles and arbitrary paths, nested and antialiased ✅
Images as a paint: four tile modes, source rectangles (sprite sheets, nine-patch), tint ✅
Dashed strokes, measured along the curve ✅
Elliptical arcs ✅
Save layers: group opacity, layer-wide blend modes, blur, backdrop blur ✅
Shadows ✅
Glyph atlas: packing, eviction, growth, one draw per run ✅ bring your own rasterizer
Windowed presentation (Vulkan swapchain, EGL window surface) ✅ caller supplies the surface
Direct KMS scanout from Vulkan 🟡 partial, see below
Direct KMS scanout from GLES ⏳ planned
Impeller C API (libimpeller) ⏳ barely started

The test corpus, one tile per scene

cargo xtask gallery renders this sheet on your own device.

How much of a renderer this is

docs/parity.md is the operation-by-operation comparison against the dart:ui Canvas and Paint surface — the contract a Flutter-class renderer owes, and a more useful yardstick than any one implementation's internals. It distinguishes what exists from what a caller could assemble, and every row claiming something works names the scene or test that renders it.

docs/non-parity.md is the other half of that question. Upstream Impeller is what this project decides against for what a renderer must express, and not for how it is reached: strategy answers to the devices this one targets, which are not the devices upstream targets. So the places the two knowingly differ are worth finding in one list rather than inferring from a diff. Each entry says what differs, why, and what the difference costs. A filled path is the clearest — stencil-then-cover there, triangulated here, so that one binary serves any Vulkan 1.1 or GLES 3.0 device. The deepest is that this pipeline works in linear light and upstream's does not, which is why a comparison against upstream can only be a comparison of shape wherever two colors are mixed.

The shape of it

Two orthogonal axes. The rendering HAL answers how draw commands become pixels in a GPU image. Presentation answers how a finished image reaches the display, and how the frame loop is paced. DRM/KMS is a presentation target alongside windowed surfaces, not a third rendering backend.

WSI (windowed) DRM (direct scanout)
Vulkan ✅ VkSwapchainKHR 🟡 VkImage → dma-buf export → drm-rs FB → commit, or a GBM buffer the display allocated, imported
GLES ✅ EGL window surface ⏳ planned

Three of the four are built. GLES to direct scanout is not. GLES already runs with no window system -- EGL on the GBM platform, rendering offscreen -- but it cannot yet draw into a buffer a display scans out: it imports no dma-buf, and there is no gbm_surface route.

The windowed column works today against a surface the caller supplies. The scanout column is partial: the frame loop above KMS is implemented and tested — the buffer ring, fence plumbing, and format and modifier negotiation — and dma-buf export from Vulkan is real. A buffer this renderer allocates, draws into and exports is accepted by a display controller as a framebuffer, the mode is set, and frames flip in turn.

That is checked two ways rather than one. On a workstation it is the virtual KMS driver, because a compositor holds master on any card driving a display. On a Raspberry Pi 5 it is the hardware: no display server runs there, so the tests can take master, and all thirty-nine in emblema-present-drm pass there — including the six that take master and set a mode and commit a frame — on vc4 with v3d as a separate render node, which is the split render and display topology the virtual driver stands in for. Re-run on 2026-10-03; nothing in the three device binaries reported a skip, which matters because a skipped test passes and would read the same from here. The render fence rides each commit, so the kernel latches the flip when rendering completes and the frame loop blocks on nothing, except on a commit that also sets the mode: the virtual driver will not complete one with a fence attached, which happens once per output.

What keeps the column partial is therefore not the absence of real hardware. It is what neither lane reaches — writeback and CRC readback, resize storms, hotplug — and the quirks only a rack of boards finds: IOMMU faults, compressed-format corner cases, scaler limits.

And one structural choice. By default this renderer allocates the scanout buffer and asks the display to accept it, and some display controllers cannot: a Pi 4's will not import render-node memory without an IOMMU, and an i.MX8M Plus's Vulkan export is scatter-gather where its controller needs contiguous memory. DrmScanoutTarget::with_gbm, behind the gbm feature, turns the arrangement around: GBM allocates on the display's own device, in a layout the display accepts, and Vulkan imports it and draws. On a Pi 5 both paths present to the panel. The GBM path is also how a Pi 4 drives its DSI panel, which is where 0.4.0's fix to it was found. It is a choice the caller makes, not a fallback taken automatically, and it is untried on the i.MX8M Plus. docs/on-a-board.md has the board results.

cargo xtask drm says whether a given machine could run that lane.

Building

Requires a Rust toolchain; no other build dependencies. MSRV is 1.85, which is where edition 2024 stabilized and is a floor the dependency graph sets rather than the code. CI builds the workspace on exactly that toolchain, so this figure is checked. CONTRIBUTING.md explains how that floor relates to the pinned toolchain and to Yocto's releases.

cargo build                                   # default: vulkan + WSI
cargo build --features gles,present-egl       # GLES into an EGL window
cargo build --features vulkan,drm             # Vulkan rendering, KMS scanout
cargo build --features gbm                    # ...into buffers GBM allocates (Rust 1.94.1+)
cargo build --features vulkan,gles,drm        # one binary that picks at runtime
cargo build --features gpu                    # buffers and textures for a caller's own pipelines
cargo test

The two axes are named separately because they are separate. drm names no backend and composes with either, which is the orthogonality the whole design rests on. present-wsi and present-egl each imply a backend, not because the axes are coupled but because a Vulkan swapchain is Vulkan's own object and an EGL surface is GLES's. Feature flags live on the emblema facade crate, since a virtual workspace root cannot declare them.

Layout

crates/
  emblema               public facade; carries the feature flags
  emblema-core         drawing API: Canvas, Paint, Color, recording, execution
  emblema-entity       entity and contents layer -- coverage only, not yet routed
  emblema-geometry     path types, flattening, tessellation, stroking, dashing
  emblema-renderer     render pass encoding, generic over the HAL
  emblema-text         glyph atlas packing and placement; bring your own rasterizer
  emblema-hal          rendering HAL trait
  emblema-hal-vulkan   Vulkan backend (first-class)
  emblema-hal-gles     GLES 3.0 backend
  emblema-present      presentation trait, format negotiation
  emblema-present-vk   Vulkan WSI swapchain target
  emblema-present-egl  EGL window-surface target
  emblema-present-drm  DRM/KMS scanout target
  emblema-shaders      WGSL sources, build-time translation via naga
  emblema-testkit      shared test harness
  emblema-capi         Impeller C API (libimpeller), ABI-compatible
xtask/                  device runs, golden management, CI reproduction
docs/                   architecture

Scope

Bring your own text shaping and layout (cosmic-text, parley), font parsing (ttf-parser, swash), image decoding (image), and SVG parsing (usvg). Scene graph, retained mode, animation, and 3D are out of scope, as is GLES 2.0.

This is a renderer, not a compositor: it draws to planes it is given. Multi-client composition belongs elsewhere. KMS internals belong outside it, and which outside differs by concern: connector and plane probing is drm-rs's, while EDID parsing, mode selection policy, session and seat handoff, and hotplug detection are the application's or its session manager's — drm-rs reports the modes but does not choose one, and hotplug needs udev, which nothing here uses.

Impeller C API

emblema-capi builds libimpeller, intended as an ABI-compatible implementation of upstream Impeller's C API so that a consumer linking that API could link this instead without recompiling. It is barely started: version negotiation is the only entry point, and the rest waits on a vendored copy of the upstream header — guessing an enum value or a struct layout would produce a library that links and then corrupts memory.

It is not a drop-in for Impeller inside the Flutter Engine build: the engine compiles Impeller's C++ sources directly rather than consuming them across this boundary, and no Rust library can present a compatible C++ ABI. The C API serves embedders. See docs/architecture.md for where parity is partial and how it is verified.

Documentation

  • docs/architecture.md -- the design and the rules that govern the codebase: the HAL and presentation split, the Vulkan-first policy, explicit synchronization, the ownership boundary with drm-rs, format and modifier negotiation, the shader pipeline, dependency purity, and the testing model. Read it before proposing structural changes.
  • docs/on-a-board.md -- cross-building the suite and running it on a real device, and what doing so has found.
  • docs/parity.md and docs/non-parity.md -- what this draws compared with dart:ui, and where it knowingly differs from upstream Impeller.
  • docs.rs/emblema -- the API, built with every feature, so the GLES backend and both presentation paths are documented whatever a caller enables.

Releases

The prepared release is 0.7.1, and until it is pushed the dependency in the quick start will not resolve. cargo xtask release prints the order it goes up in and what each step needs.

emblema 0.7.0 is on crates.io, as are the thirteen crates it is assembled from. CHANGELOG.md says what changed since 0.2.0, the first release under this name.

emblema 0.0.0 and 0.0.1 also exist and contain no API: they reserved the name ahead of this release. Nothing should depend on either.

The old name is still up and will not move again: impeller-rs 0.1.0 and thirteen impeller-* crates, published 2026-09-21 before the rename. They are a snapshot of this project from that day, and crates.io does not delete, so they stay as a record. 0.2.0 is a hundred and two merges past them, which is why the number starts again rather than continuing theirs.

Fourteen of this workspace's seventeen crates publish; emblema-capi, emblema-testkit and xtask refuse, each saying why in its own manifest and each one line from changing its mind. CONTRIBUTING.md has how a release is made.

The links in this file are absolute because it is also the crate's page on crates.io, where a relative one resolves here and 404s there.

Contributing

Contributions are welcome. CONTRIBUTING.md has the checks to run before committing -- cargo xtask gate is all of them as one exit code -- why a green gate is not a green CI and how to run what CI runs, and the conventions commit messages follow.

License

BSD 3-Clause. See LICENSE.

This matches the Flutter Engine, home of the C++ Impeller whose architecture this project takes as its reference. Any code ported from there retains its original copyright notice alongside this project's: each such file says so at its top, and LICENSE-THIRD-PARTY reproduces the Flutter Engine's and Skia's licenses in full. Every crate packages the licenses that cover it.

A product that ships a binary built on this also ships its dependencies, and most of their licenses -- MIT, Apache-2.0, Unicode-3.0 -- ask for their notices to go with it. cargo deny list names each one, and cargo-about gathers their texts into one file to put beside the binary.