Repository navigation
27 gpu
Language: English | 中文
Goal: see how one and the same EwokOS graphics stack drives four real GPU families — Broadcom VideoCore IV/VI (Raspberry Pi 1..4), VideoCore VII (Raspberry Pi 5), Qualcomm Adreno 690 (SC8280XP / 8gen3) and NVIDIA GA10B (Jetson Orin Nano) — through a shared daemon/IPC shape, per-machine shader compilers, and a CPU-first fallback contract; and know what is verified on each board today.
This chapter builds on 13 Graphics & Windows, 09 IPC and 23 Cache Maintenance. The CUDA-compatible compute layer gets its own chapter: 28 KUDA. Terminology is collected in the glossary.
EwokOS has no hosted GPU driver stack (no DRM/KMS, no mesa gallium driver, no
vendor kernel module). Every GPU is programmed directly from user space:
a machine BSP library brings the silicon up, a shared daemon (g2dd) owns
submission, and the projects/ API stacks (GLES2/EGL, Vulkan, OpenCL, KUDA)
compile shaders on the device and dispatch work over IPC. The invariant
everywhere: the CPU path is the reference; the GPU may only add speed,
never change results.
Every code reference below points at a real file:
| Layer | File |
|---|---|
| GLES2/EGL front end + engine adapter | projects/opengl/libs/gles/ |
| Shared mesa GLSL→NIR compiler front end | projects/opengl/libs/gles/pglcompiler/ |
| Vulkan runtime (CPU + GPU devices) | projects/vulkan/libs/vulkan/src/ |
| OpenCL runtime (CPU + GPU devices) | projects/opencl/libs/opencl/src/ |
| 2D/3D/CL client library (IPC verbs) | system/gui/libs/g2dclient/ |
| The shared GPU daemon | system/gui/drivers/g2dd/g2dd.c |
| Pi GPU library (V3D 2.1/4.2/7.1) |
hardwares/raspi5/system/libs/videocore/, hardwares/raspix/system/libs/videocore/
|
| Pi 5 shader compiler (V3D 7.1 QPU) | hardwares/raspi5/system/libs/v3dcompiler/ |
| Pi 4/CM4 shader compiler (V3D 4.2 QPU) | hardwares/raspix/system/libs/v3dcompiler/ |
| Adreno driver library | hardwares/qcom/8gen3/system/libs/adreno/ |
| Adreno shader compiler (ir3) | hardwares/qcom/8gen3/system/libs/adrenocompiler/ |
| GA10B driver library | hardwares/nvidia/orin.nano/system/libs/ga10b/ |
| GA10B shader compiler (sm_87 SASS) | hardwares/nvidia/orin.nano/system/libs/nvcompiler/ |
app: GLES2/EGL · Vulkan · OpenCL · KUDA (projects/*)
│ CPU back end always present; GPU back end per machine
│ on-device shader compile (pglcompiler front end + machine back end)
▼
g2dclient ── IPC (/dev/g2d) ──► g2dd daemon (system/gui)
│ bsp_g2d_* (2D) bsp_g3d_* (3D) bsp_cl_* (compute)
▼
machine BSP library (hardwares/<vendor>/<hw>)
libvideocore (Pi) libadreno (8gen3) libga10b + VIC (Orin Nano)
▼
the GPU itself: QPU array / a6xx CP+SP / GA10B GR+CE
Three properties are shared by all ports:
-
Zero copy. GPU work runs on the caller's buffers through their
physical addresses (contiguous
sys_dma/shm_contigmemory, see 05 Memory & MMU). There is no GPU MMU translation on the VideoCore path at all; Adreno's CB0 is identity-mapped (pa == iova); GA10B has a real GMMU but the driver still feeds it DMA pools. - Sticky, honest fallback. A GPU path that declines (unsupported shader shape, failed bring-up, ineligible buffer) reports failure; the API layer latches to the CPU back end. A submitted dispatch is never replayed — it may already have written the destination.
-
Cache discipline. Every dispatch brackets itself with the right
clean/invalidate sequence for its silicon (V3D L2 + TMU write combiner,
Adreno UCHE, GA10B FB);
NOCACHEcanvases skip it. See 23 Cache Maintenance.
| Machine | GPU | 2D | 3D (GLES offload) | Compute (CL / Vulkan / KUDA) | Shader compiler |
|---|---|---|---|---|---|
hardwares/raspix/ (Pi 3) |
VideoCore IV, V3D 2.1 | QPU kernels via SRQ launcher | — (no CSD on V3D 2.1; CPU fallback) | — | hand-written QPU assembly (qpuasm.py) |
hardwares/raspix/ (Pi 4/CM4) |
VideoCore VI, V3D 4.2 | QPU kernels via CSD | two-pass compute rasterizer | Vulkan GPU device via CSD; no CL/KUDA |
v3dcompiler (mesa V3D 4.2: NIR→VIR→QPU) |
hardwares/raspi5/ |
VideoCore VII, V3D 7.1 (12 QPUs) | CSD, 8 kernels, banding/tiling | two-pass compute rasterizer |
bsp_cl → V3D CSD |
v3dcompiler (mesa V3D: NIR→VIR→QPU) |
hardwares/qcom/8gen3/ |
Adreno 690 (a6xx) | adreno_2d |
two-pass compute rasterizer |
bsp_cl → CP_EXEC_CS on the CP ring; KUDA BSP |
adrenocompiler (mesa freedreno/ir3) |
hardwares/nvidia/orin.nano/ |
GA10B (Ampere, 1 GPC / 4 TPC / 8 SM, sm_87) | CE blit + VIC 2D engine | two-pass compute rasterizer | nvcc cubin → QMD launch on GR compute channels |
nvcompiler (hand-written NIR→SASS→cubin) |
The Raspberry Pi family also carries the deepest 2D acceleration (fill,
blit, alpha blend, rotate, scale, copy on ARGB8888, in place); the full
three-generation VideoCore story — mailbox firmware interface, SRQ vs CSD
launch, eligibility gates, banding/tile policy, vec4 fast path — is documented
in hardwares/README.md and not repeated here.
The shared raspix image (one binary across Pi 3/4/5) enables the GLES
offload too: its v3dcompiler is the same mesa Broadcom back end built for
V3D 4.2 (Pi 4/CM4). At init the client queries the live V3D version over
the g2d dev-cntl channel and declines to the CPU/NEON rasterizer on
unsupported silicon — Pi 3's V3D 2.1 has no CSD compute, and Pi 5 boards are
served by the dedicated raspi5 image (V3D 7.1), so enabling the GPU path
on the shared binary is safe on every raspix board.
The Pi 5 port programs the V3D 7.1 QPU array as a pure compute device: the BCM2712 binner cannot rasterize real primitives, so even 3D geometry is transformed, lit and rasterized by CSD (Compute Shader Dispatch) compute shaders.
-
Bring-up: SMS power-up + hub AXI kick; registers reached through a
SYS_MEM_MAP_NOCACHEwindow (V3D sits outside the main MMIO window); V3D clock pinned to max via the firmware mailbox. -
Compiler:
hardwares/raspi5/system/libs/v3dcompilerruns mesa'sGLSL ES 3.10 → NIR → VIR → QPUpipeline on the device. -
3D shape: a per-vertex transform pass plus a one-lane-per-triangle
raster pass, pixel-exact against the CPU rasterizer; fullscreen coverage
is tessellated into a grid mesh (one workgroup per textured triangle
wedged the GPU — see the
vkolddispfix in the top-level README). -
Compute:
bsp_cl.cdelegates tolibvideocore'svc_cl, zero-copy on shm/dma buffers; lazy, idempotent, latched bring-up. - Memory headroom: the offload framebuffer grows geometrically, so drag-to-resize collapses into a handful of reallocations instead of exhausting the contiguous pool (which would silently latch apps to CPU).
The opengl apps (teapot, gears, 3ddemo, matrix, Fireworks,
imgui_demo, ocean, ...) and the Vulkan/OpenCL demos all exercise this
path through the same front ends.
The SC8280XP port drives the Adreno 690 the way the freedreno/turnip drivers do, but entirely from user space:
-
Firmware & bring-up (
libadreno:adreno_fw.c,adreno_gmu.c,adreno_gpucc.c,adreno_rpmh.c): Qualcomm-signed zap shader, GMU and SQE firmwares are loaded from/firmware(packaged from the board's firmware partition, never committed to git); the GMU (GPU Management Unit) is booted over RPMh power domains, then the CP (Command Processor) ring is owned by the driver (adreno_ring.c). -
Compiler:
adrenocompilerpairs the shared mesa GLSL→NIR front end with mesa's freedreno/ir3 back end (adreno_backend.c), performing the compute NIR lowerings gallium normally does (system values, shared memory offsets, uniforms→UBO 0 with byte offsets). Target is fixed:fd_dev_id {690, 0x060900ff}. -
Compute dispatch:
bsp_cl.cloads the serializedadreno_prog_blob_tthroughadreno_3d_program_load(the same table the GLES path uses) and submits oneCP_EXEC_CSper NDRange;__globalarguments bind as UAV descriptors at their resolved physical bases — CB0 is identity-mapped, so this is zero copy. -
Textures: compute sampling uses the a6xx bindful model — texture
and sampler descriptors live in separate BO regions pointed at by
SP_CS_TEXMEMOBJ_BASE/SP_CS_SAMPLER_BASE, preloaded withCP_LOAD_STATE6_FRAG; an unbound sampled slot is declined back to the CPU, never silently sampled as zero. -
Gating: the whole path is opt-in via
ADRENO_ENABLE=1plus a successfuladreno_3d_init; the probe result is sticky. One hardware contract worth knowing: fullscreen compute output framebuffers must have a 64-byte-aligned row pitch — the a6xx line addressing wedges otherwise (fixed in the daemon/client contract). -
NPU: the Hexagon HTP is a separate accelerator (
libadrenonpu,apps/nputest), not part of the Adreno graphics path.
Board-verified: GLES apps, the Vulkan apps (vkteapot, vkmatrix,
vkfonts, vkolddisp), OpenCL demos, and KUDA-driven LLM inference
(28 KUDA).
Retail Tegra234 parts have the priv_sec_en fuse set, so the GPU cannot be
used without walking NVIDIA's full secure boot chain. The libga10b
driver does exactly that, in user space (details and register evidence in
ga10b-3d-handover.md):
BPMP power/clock/reset → chip detect (0x17b) → fuse topology (1 GPC/4 TPC/8 SM)
→ ACR-GSP HS boot (WPR1 carve-out) → PMU RTOS boot (+ FBQ RPC: INIT_WPR_REGION,
BOOTSTRAP_GR_FALCONS) → FECS/GPCCS HS signature → FECS ctxsw INIT_DONE
→ golden context save → per-channel compute/graphics channels
Two root-caused bring-up lessons are worth remembering: the PMU RTOS blocks on its debug-log ring until the host acks the read offset (a pure-polling driver must drain it), and the non-MIG golden context needs the global ctx buffers (pagepool / bundle cb / attrib cb) committed before the sw bundle, with per-channel addresses fixed up through a patch buffer.
On top of that foundation:
-
CE (Copy Engine) blit passes without any GR falcons — the M0 sanity
check (
ga --hw ce). -
Compute (M1): real
nvcc-produced sm_87 cubins are parsed, uploaded into a GMMU v2 VM and launched through QMD v3.0 on GR compute channels (ga10b_compute.c);vectorAdd(1024 elements, 4 blocks × 256 threads) is board-verified. The cubin parser and QMD builder are shared withprojects/kuda(28 KUDA). -
3D:
nvcompileris a hand-written pure-C NIR → sm_87 SASS back end (encoder + liveness/linear-scan register allocation + structured control flow), synthesizing a cubin that rides the same QMD path. It is validated bit-exactly against nvcc 13.5 output and by a differential warp-emulator oracle on the host. The realoceanshader compiles on-board in ~0.1 s and renders 3840×2160 at 18–23 fps;cube/teapot/3ddemo/matrixrun concurrently on the X desktop through GA10B, and theg3dtestsuite compares 7 scenes pixel-exactly against the CPU reference. -
VIC: the separate Video Image Compositor engine handles 2D
(fill/blit/scale/rotate) and is integrated into the xwin desktop
(
vic-2d-handover.md).
The base Orin port (UEFI loader, ramfs rescue shell, Ethernet) is described
in hardwares/nvidia/orin.nano/README.md.
All four 3D-capable machines share one vendored mesa GLSL→NIR front end
(projects/opengl/libs/gles/pglcompiler, upstream pin in VENDORED.txt).
Each machine selects its own back end through two variables in its
system/make.inc:
export PGL_G3D=yes # build the GPU offload path at all
PGL_G3D_COMPILER_DIR := .../libs/v3dcompiler # raspi5 (V3D 7.1) / raspix (V3D 4.2)
# .../libs/adrenocompiler # qcom/8gen3
# .../libs/nvcompiler # nvidia/orin.nanoThe engine adapter (gles/src/engine/pgl_engine.c) picks CPU vs GPU per
draw; the Vulkan and OpenCL runtimes reuse the same compiler contract
(pglcompiler.h) for their GPU devices, transpiling SPIR-V / OpenCL-C to
GLSL ES 3.10 compute first. Anything outside the GPU subset is declined,
never mis-compiled, and runs on the CPU back end with identical results.
| Platform | Build gate | What to run |
|---|---|---|
| raspi5 |
PGL_G3D=yes in hardwares/raspi5/system/make.inc (default) |
teapot, ocean, vkteapot, cltest, vktest
|
| raspix (Pi 4/CM4) |
PGL_G3D=yes in hardwares/raspix/system/make.inc (default; runtime V3D-version gate picks Pi 4) |
the same GLES demos; Vulkan apps |
| qcom/8gen3 |
PGL_G3D=yes + ADRENO_ENABLE=1 at runtime |
same GLES/Vulkan/CL apps; kuda_vec_add /lib/kuda/ops.q8b
|
| nvidia/orin.nano |
PGL_G3D=yes (default) |
ga --hw ce/pmu/compute, g3dtest, ocean, the four GLES demos |
vktest/cltest run each benchmark twice (CPU device vs GPU device) and
print a speedup table — on the Pi 5 V3D path the compute benches reach
~40–270× over the CPU interpreter, which is also the quickest way to confirm
the GPU path is really engaged (a silent CPU fallback shows ~1.0×).
Next: 28 KUDA: a CUDA-Compatible Compute Layer — the driver-API compatibility layer, its core/BSP split, and how it drives LLM inference on Adreno 690.
EwokOS OS Tutorial / EwokOS 操作系统教学
Part 1: Getting Started / 第 1 部分:起步
Part 2: The Kernel / 第 2 部分:内核
Part 3: Userland / 第 3 部分:用户态
Part 4: The Full System / 第 4 部分:完整系统
Part 5: The ewokos Series (Libraries) / 第 5 部分:ewokos 系列(库生态)
Part 6: GPU & Compute / 第 6 部分:GPU 与计算
Appendix / 附录