---
title: "GPU2D"
description: "Portable 2D blit / fill / blend operations against framebuffer surfaces."
source: https://docs.alplab.ai/sdk/api/gpu2d
---

# `<alp/gpu2d.h>` — 2D Graphics Acceleration

Portable 2D **blit / fill / blend** operations against framebuffer surfaces.

Zephyr has no portable 2D-accelerator driver class, and the Alif Ensemble parts carry a hardware 2D engine. Without a portable surface, a customer migrating from V2N to AEN would silently lose that acceleration. This header exists so customer code compiles — and runs — on every SoM, taking the hardware path where one exists and a CPU path everywhere else.

## Header

```c
#include <alp/gpu2d.h>
```

## Quick example

```c
alp_gpu2d_t *g = alp_gpu2d_open();

const alp_gpu2d_surface_t fb = {
    .base         = framebuffer,
    .width        = 800,
    .height       = 480,
    .stride_bytes = 800 * 4,
    .format       = ALP_GPU2D_FMT_ARGB8888,
};

alp_gpu2d_fill_rect(g, &fb, 10, 10, 100, 50, 0xFFFF0000);  // red
alp_gpu2d_close(g);
```

## Which SoMs have GPU2D silicon?

The 2D engine on the Alif Ensemble is the **TES D/AVE 2D** block (Alif markets it as "GPU2D"). Per the SoC metadata, it is present on the Ensemble E6, E7 and E8:

| SoM | SoC | 2D silicon? |
|-----|-----|-------------|
| **E1M-AEN601** | Alif Ensemble E6 | ✅ D/AVE 2D |
| **E1M-AEN701** | Alif Ensemble E7 | ✅ D/AVE 2D |
| **E1M-AEN801 / E1M-AEN803** | Alif Ensemble E8 | ✅ D/AVE 2D |
| E1M-AEN301 / AEN401 / AEN501 | Ensemble E3 / E4 / E5 | ❌ |
| E1M-V2N101/102/103, E1M-V2M101/102/103 | Renesas RZ/V2N | ❌ no D/AVE 2D — but the Mali-G31 GPU can serve this surface on Linux (see below) |

`ALP_HAS(GPU2D)` / `ALP_HAS(DAVE2D)` from [`<alp/cap.h>`](https://docs.alplab.ai/sdk/api/capabilities) are the portable way to ask.

:::caution[The D/AVE 2D backend needs a proprietary pack, and is first-run only]
v0.17.0 ran the D/AVE 2D backend on AEN silicon for the first time: on an E1M-AEN803 (M55-HE), fill, blit and the `REPLACE` / `SRC_OVER` blends match the software fallback (`SRC_OVER` within 1 per channel). `ADDITIVE` and `MULTIPLY` are served by the software fallback. The public header still labels the backend bench-unverified, and only that one module has run it — treat it as early.

Constraints found on silicon:

- The engine is an AXI master with no address translation, so surfaces (and the driver heap) must sit at **globally visible** addresses — SRAM0 on the M55-HE, **not DTCM**.
- The backend requires `CONFIG_DCACHE`; with the D-cache off, the software fallback serves `<alp/gpu2d.h>` instead.

The backend is gated behind `CONFIG_ALP_SDK_GPU2D_ALIF_DAVE2D`, which the build sets only when Alif's **proprietary** D/AVE 2D driver pack (`AlifSemiconductor::Dave2DDriver`) is on the include path. That pack is pulled at build time and is **not vendored into the SDK** — unless you supply it, the software fallback is what runs, on every SoM including AEN.
:::

## Backends

| Backend | `silicon_ref` | Priority | Status |
|---------|---------------|----------|--------|
| `dave2d_e6` / `dave2d_e7` / `dave2d_e8` | `"alif:ensemble:e6"` / `"e7"` / `"e8"` | 100 | Requires the proprietary pack; first silicon run on E8 (see above). Advertises `ALP_INSTANCE_CAP_REPORTED` and `ALP_INSTANCE_CAP_DMA`. |
| `yocto_gles` | `"*"` (Linux only) | 50 | **New in v0.17.0.** The RZ/V2N Mali-G31 through the vendor EGL / GLES stack. Opt-in at build time with `ALP_SDK_USE_GPU2D_GLES` (found via pkg-config `egl` + `glesv2`). Falls back to the CPU path per op, or entirely when no GPU context exists. **Bench-unverified.** |
| `sw_fallback` | `"*"` | 0 | Portable CPU fill/blit/blend, tested on `native_sim`. |

One D/AVE 2D row per SKU that actually carries the engine, at priority 100 so the registry prefers it over the wildcard fallback **on those parts only** — see the [selection rules](https://docs.alplab.ai/sdk/api/backend#selection-rules). With the pack absent, those rows are not compiled at all and the priority-0 wildcard wins everywhere.

The software fallback is what V2N without the GPU stack and `ALP_OS=yocto` Linux builds use, and it implements **all five pixel formats**.

Plain-CMake **bare-metal** builds are the exception: there is no backend registry on that path yet, so they link a NOSUPPORT stub — `alp_gpu2d_open()` returns `NULL` with `ALP_ERR_NOSUPPORT` and every op returns `ALP_ERR_NOSUPPORT`.

## Functions

| Call | Returns |
|------|---------|
| `alp_gpu2d_open(void)` | `alp_gpu2d_t *`, or `NULL` with [`alp_last_error()`](https://docs.alplab.ai/sdk/api/peripheral) set. With the software fallback enabled (the default, `CONFIG_ALP_SDK_GPU2D_SW_FALLBACK`) **open succeeds on every SoM** — there is no NOSUPPORT case at open time. `NULL` means either no backend compiled in at all (`ALP_ERR_NOT_PRESENT_ON_THIS_SOC`) or the handle pool is exhausted (`ALP_ERR_NOMEM`). |
| `alp_gpu2d_fill_rect(handle, dst, x, y, w, h, argb_color)` | `ALP_OK` / `ALP_ERR_NOT_READY` / `ALP_ERR_INVAL` / `ALP_ERR_OUT_OF_RANGE` / `ALP_ERR_NOSUPPORT`, and since v0.17.0 `ALP_ERR_TIMEOUT` when the engine did not go idle (backend-dependent). Rect is **clipped** to `dst`'s dimensions. |
| `alp_gpu2d_blit(handle, src, sx, sy, dst, dx, dy, w, h)` | Same set (including `ALP_ERR_TIMEOUT`). Copy with no blend; converts format when `src->format != dst->format` and both are in the backend's supported set, else `ALP_ERR_NOSUPPORT`. |
| `alp_gpu2d_blend(handle, src, sx, sy, dst, dx, dy, w, h, mode)` | Same set. Alpha-blends per `mode`. |
| `alp_gpu2d_close(handle)` | `void`. `NULL` is a no-op. |
| `alp_gpu2d_capabilities(const alp_gpu2d_t *handle)` | `const alp_capabilities_t *`, valid for the handle's lifetime; `NULL` handle → `NULL`. See [instance capabilities](https://docs.alplab.ai/sdk/api/capabilities#instance-level-what-can-this-handle-do). |

:::note[The handle pool defaults to ONE]
The 2D engine is a system-wide singleton, so a second `alp_gpu2d_open()` before `alp_gpu2d_close()` fails with `ALP_ERR_NOMEM` rather than aliasing the live handle. The pool size is the `CONFIG_ALP_SDK_MAX_GPU2D_HANDLES` compile-time override — there is **no Kconfig entry** for it today; define it on the build.
:::

The colour passed to `fill_rect` is always ARGB8888 and the backend converts: RGB565 ignores the high 16 bits, A8 takes only the high byte (alpha).

## Concurrency

The singleton handle is reentrant under a shared driver mutex, but **callers must serialise** `fill_rect` / `blit` / `blend` issuance themselves — the software fallback writes caller memory directly, and the D/AVE 2D HAL's display-list builder is not itself thread-safe.

## Blit overlap contract

Pixels are processed **top-to-bottom, left-to-right**. An overlapping same-buffer copy toward *earlier* memory (`dy < sy`, or `dy == sy` with `dx <= sx`) is safe. A copy toward *later* memory may read pixels the op already wrote — backends do not reverse-iterate. Callers needing overlap-safe moves in both directions must use distinct buffers.

## Surface descriptor

`alp_gpu2d_surface_t` lives in caller memory and is copied internally per operation, so you can reuse or modify the struct between calls.

| Field | Type | Notes |
|-------|------|-------|
| `base` | `void *` | Pointer to the **top-left pixel** (no header byte). |
| `width` / `height` | `uint32_t` | Dimensions in pixels. |
| `stride_bytes` | `uint32_t` | Bytes from one row's start to the next (`= width * bytes-per-pixel` when tightly packed). |
| `format` | `alp_gpu2d_format_t` | See below. |

### Pixel formats

Backends honour the subset their hardware supports; unsupported formats return `ALP_ERR_NOSUPPORT`.

| Format | Value | Layout |
|--------|-------|--------|
| `ALP_GPU2D_FMT_A8` | `0` | 8-bit alpha only — useful for masks |
| `ALP_GPU2D_FMT_RGB565` | `1` | 16-bit, R:G:B = 5:6:5 |
| `ALP_GPU2D_FMT_RGB888` | `2` | 24-bit packed; **backend-defined byte order** |
| `ALP_GPU2D_FMT_ARGB8888` | `3` | 32-bit, A:R:G:B = 8:8:8:8 (the D/AVE 2D default) |
| `ALP_GPU2D_FMT_RGBA8888` | `4` | 32-bit, R:G:B:A = 8:8:8:8 (alternate ordering) |

:::warning[Renumbered in v0.17.0]
`alp_gpu2d_format_t` was renumbered so `RGB565` / `RGB888` / `ARGB8888` carry the same values as the `alp_pixfmt_t` members of the same name — a display's advertised format can now be passed straight to a GPU2D surface without being silently relabelled. `ALP_GPU2D_FMT_A8` moved `2` → `0`, `RGB888` `3` → `2`, `ARGB8888` `0` → `3`; `RGB565` (`1`) and `RGBA8888` (`4`) are unchanged. Code using the names only needs a rebuild; anything that stored the raw numbers must be updated.
:::

### Blend modes

Colours are **straight (non-premultiplied) alpha**.

| Mode | Formula |
|------|---------|
| `ALP_GPU2D_BLEND_REPLACE` | `dst = src` (no blend) |
| `ALP_GPU2D_BLEND_SRC_OVER` | `dst = src*src.a + dst*(1-src.a)` — a transparent `src` leaves `dst` untouched; an opaque `src` replaces it |
| `ALP_GPU2D_BLEND_ADDITIVE` | `dst = src + dst` (clamped) |
| `ALP_GPU2D_BLEND_MULTIPLY` | `dst = src * dst` |

Blended channels may differ by 1 between backends: the software fallback divides by 255 with rounding, the D/AVE 2D engine scales by 1/256 (`0x80FF0000` over `0xFF0000FF` gives red `0x80` in software, `0x7F` on the engine), and the GLES backend blends in the GPU's own fixed-point precision. `REPLACE`, fills and copies are exact everywhere.

## ABI status

`[ABI-EXPERIMENTAL]` — new in v0.5 (AEN audit headline gap). A portable surface, but only one silicon family populates it today. Pin your SDK to a specific commit if you depend on it.

## See also

- [`<alp/display.h>`](https://docs.alplab.ai/sdk/api/display) — the display subsystem that owns the framebuffer
- [`<alp/gui.h>`](https://docs.alplab.ai/sdk/api/gui) — LVGL with Alp defaults
- [`<alp/cap.h>`](https://docs.alplab.ai/sdk/api/capabilities) — `ALP_HAS(GPU2D)` / `ALP_HAS(DAVE2D)` gating
- [`<alp/backend.h>`](https://docs.alplab.ai/sdk/api/backend) — why the fallback wins when the pack is absent
