Lumina
GPU rendering engine — 21 sub-crates for math, shaders, pipelines, render graphs, and UI.
Architecture Overview
Lumina is Helix's GPU graphics pipeline — a complete rendering framework built from scratch across 18 sub-crates and 200+ source files. It spans the full stack from SPIR-V shader compilation to PBR rendering, ray tracing, and UI composition.
Sub-Crate Stack
Sub-Crate Inventory
| Crate | Files | Description |
|---|---|---|
lumina-core | ~100 | GPU resources: buffers, commands, descriptors, devices, pipelines, textures, sync |
lumina-math | ~10 | Vector/matrix math (vec2/3/4, mat3/4), quaternions, transforms |
lumina-shader | ~15 | Shader compilation: compiler, module, reflection, variants |
lumina-ir | ~20 | Intermediate representation: instructions, blocks, functions, SSA, CFG, optimizer |
lumina-spirv | ~15 | SPIR-V binary: builder, disassembler, instruction encoding, optimizer, validator |
lumina-derive | ~10 | Proc macros: shader codegen, SPIR-V generation, vertex layout derivation |
lumina-render | ~20 | Rendering: frame management, render graph, passes, culling, GI, hybrid rendering |
lumina-pipeline | ~10 | Pipeline state: cache, descriptor layout, reflection, specialization constants |
lumina-material | ~10 | Material system: PBR, procedural, shader graphs, texture sampling, layers |
lumina-mesh | ~15 | Geometry: meshlets, cluster LOD, BLAS acceleration, virtual geometry, streaming |
lumina-backend | ~15 | Vulkan backend: bindless resources, ray tracing pipelines, mesh shaders |
lumina-sync | ~8 | GPU sync: fences, semaphores, barriers, timeline semaphores, workload tracking |
lumina-memory | ~10 | GPU memory: allocator, pool, staging buffers, streaming, virtual allocation |
lumina-debug | ~10 | Debug tools: frame capture, logger, GPU markers, perf counters, validation layers |
lumina-scene | ~15 | Scene graph: ECS integration, transforms, frustum culling, instancing, LOD, streaming |
lumina-3d | ~10 | 3D rendering: atmosphere, camera, GI, lighting, PBR shading, post-processing, shadows |
lumina-ui | ~15 | UI framework: animation, immediate mode, input, layout, retained mode, widgets, themes |
lumina-tools | ~10 | Dev tools: AI optimizer, hot reload, live metrics, predictive analysis, time travel debug |
lumina-inspector | ~10 | Inspector: frame capture, memory analysis, pipeline state, shader debug, timeline |
Handle System
Lumina uses a type-safe handle system for GPU resources to prevent use-after-free and dangling references:
Each handle contains a generation counter that is incremented when a resource is freed. Accessing a handle with a stale generation returns an error instead of undefined behavior.
Resource Types
| Handle Type | GPU Resource |
|---|---|
Handle<Buffer> | GPU buffer (vertex, index, uniform, storage) |
Handle<Texture> | GPU texture (1D, 2D, 3D, cube, array) |
Handle<Sampler> | Texture sampler state |
Handle<Pipeline> | Graphics/compute pipeline state object |
Handle<RenderPass> | Render pass with subpasses and attachments |
Handle<Framebuffer> | Framebuffer with color/depth attachments |
Handle<Shader> | Compiled shader module |
Handle<DescriptorSet> | Descriptor set binding resources to shaders |
Math Library
lumina-math provides GPU-optimized math types:
Types
| Type | Size | Components |
|---|---|---|
Vec2 | 8B | x, y |
Vec3 | 12B | x, y, z |
Vec4 | 16B | x, y, z, w |
Mat3 | 36B | 3x3 matrix |
Mat4 | 64B | 4x4 matrix |
Quat | 16B | Quaternion rotation |
Transform | 80B | Position + Rotation + Scale |
AABB | 24B | Axis-aligned bounding box |
Frustum | 96B | 6 planes for culling |
All types implement Copy, Clone, PartialEq, and SIMD-accelerated operations where available.
Render Pipeline
The rendering pipeline processes frames through a configurable graph:
Frame Lifecycle
Render Graph
The render graph is a directed acyclic graph of render passes with automatic resource management:
Features
- Automatic barrier insertion — resource transitions (read → write) are handled automatically
- Transient resource allocation — textures used only within the frame are allocated from a pool and recycled
- Pass culling — passes whose outputs are unused are removed
- Parallel command recording — independent passes record commands in parallel
Shader Compilation
The shader pipeline compiles high-level shader code to GPU-executable SPIR-V:
SPIR-V Module
IR Optimization Passes
| Pass | Description |
|---|---|
| Dead Code Elimination | Remove unreachable instructions |
| Constant Folding | Evaluate constant expressions at compile time |
| Function Inlining | Inline small functions |
| Loop Unrolling | Unroll small constant-count loops |
| Common Subexpression Elimination | Remove redundant computations |
Magma GPU Driver
The Magma driver (drivers/gpu/magma/, 52+ sub-crates, 61 source files in the main tree) provides the hardware interface between Lumina and the GPU.
Sub-Crate Architecture
Hardware Abstraction
GPU Memory Management
Magma manages VRAM using a buddy allocator:
| Region | Type | Purpose |
|---|---|---|
| VRAM | Device-local | Textures, render targets, vertex buffers |
| System RAM | Host-visible | Staging buffers, uniform buffers |
| BAR | CPU-visible VRAM | Direct CPU access to VRAM (NVIDIA ReBAR) |
API Support
| API | Version | Features |
|---|---|---|
| Vulkan | 1.3 | Ray tracing, mesh shaders, bindless, dynamic rendering |
| OpenGL | 4.6 | Compatibility — context, buffer, shader, pipeline, framebuffer |
GPU Synchronization
Lumina provides multiple synchronization primitives for GPU-CPU and GPU-GPU coordination:
Primitives
| Primitive | Scope | Description |
|---|---|---|
Fence | CPU ↔ GPU | CPU waits for GPU work to complete |
Semaphore | GPU ↔ GPU | Queue-to-queue synchronization |
Barrier | Within pass | Memory/execution dependency within a command buffer |
TimelineSemaphore | GPU ↔ GPU | Monotonic counter-based sync (Vulkan 1.2+) |
Workload Tracking
Codebase Scale
| Metric | Value |
|---|---|
| Lumina sub-crates | 18 |
| Magma sub-crates | 52+ |
| Total source files | 270+ |
| Estimated total lines | 50,000+ |
| Shader pipeline stages | 5 (source → parse → IR → optimize → SPIR-V) |
| Render pass types | Shadow, G-buffer, Lighting, Post-process, UI |
| GPU sync primitives | 4 (Fence, Semaphore, Barrier, Timeline) |
| Supported GPU APIs | 2 (Vulkan 1.3, OpenGL 4.6) |