# RASM Development Plan

This plan turns RASM from a working GPU-driven prototype into an engine that can be embedded in indie games, visualization tools and map engines. Item IDs such as `B1` and `D4` refer to [code_review.md](code_review.md). The current design is described in [architecture.md](architecture.md).

## Guiding principles

1. **Examples drive features.** Every phase ends with at least one new or updated example that exercises it. (This keeps item 2 of the original plan.)
2. **GPU-driven by default.** The CPU uploads changes and records a handful of commands, and the GPU decides what to draw. CPU cost must not grow with the number of instances.
3. **Validation-clean is part of "done".** Every example runs without validation messages, in both Debug and Release.
4. **Portable by construction.** New shader and RHI code is written against the capability tiers below, so the Metal, D3D12 and WebGPU backends don't require rewrites.
5. **Embeddable.** The engine must work without owning the window, the event loop, the asset pipeline or the process working directory.

## Capability tiers (target for the RHI)

| Feature | Tier A: Vulkan 1.3+, D3D12 SM6.6, Metal 3 | Tier B: WebGPU (core) |
|---|---|---|
| Resource access | Bindless descriptor heaps or arrays | Bind groups per pass and per material, texture arrays or atlases |
| GPU data | Bindless buffers (BDA on Vulkan/Metal, descriptor-heap structured buffers on D3D12) | Storage buffers bound per pass |
| Indirect draws | Multi-draw indirect + draw count | `drawIndexedIndirect` per draw (or the multi-draw extension where present) |
| Per-draw constants | Push constants / root constants | Small uniform buffer + dynamic offset |
| Compute culling | Yes | Yes |
| Mesh shaders | Optional (Vulkan/D3D12/Metal 3) | No |

The engine's **data model** (GPU scene tables, instance and material indices, draw lists) is the same across tiers. Only the *binding* and *submission* layer differs. This is why `D12` must be solved before a second backend is started.

---

## Phase 0: Stabilize what exists

Goal: fix correctness bugs before building anything on top.

- [x] Remove desc-based dedup for buffers and textures. Keep it only for immutable objects keyed on their full state (`B1`, done 2026-10-26).
- [x] Zero-initialize `ResourceDesc` (`B18`, done 2026-10-26).
- [x] Set GLM and VMA configuration macros in CMake. Fix the depth range (`B2`, `C7`, done 2026-10-26).
- [x] Always enable `VK_EXT_debug_utils` when it is available, and guard the naming calls (`B3`).
- [x] Make acquire/present robust: handle out-of-date and suboptimal swapchains, reset the fence after a successful acquire, skip frames while minimized, and drop leaked depth textures and stale swapchain handles (`B4`, `B5`, `B17`, done 2026-10-27).
- [x] Cache glTF materials and textures per model. Add a default material (`B7`, `B8`, done 2026-10-27).
- [x] glTF geometry: generate indices for non-indexed primitives, skip non-triangle modes with a warning, and validate strides and buffer views (`B6`, done 2026-10-27).
- [x] Implement `UNLIT` through a per-model material id in the uber shader. Delete the `loadMaterials` declaration and the spot-light enum value (`B9`, `B14`, `B15`). Make empty scenes work (`B16`). Fix `submit` wait stages (`B11`) and the Slang options leak (`B12`) (done 2026-10-31).
- [x] Remove the legacy path (`render`/`compileScene`/offscreen frame) and port `01_render_graph` to the GPU-driven path with a fixed render-target flow (`D10`, `B10`, done 2026-11-01).
- [x] Call `validateRasmStructs` in debug builds, checking the shader layouts behind the `pc` pointers (`C6`, done 2026-11-01).
- [x] Add Tracy frame marks and zones for frame, prepare, upload and submit, with the client in on-demand mode (`D16`, done 2026-11-01).

**Exit criteria:** all examples run validation-clean in Debug and Release (with `enableValidation = false`), survive resize and minimize, and a model with 100+ primitives sharing materials loads within the limits.

## Phase 1: Foundations

Goal: the structural changes that every later feature depends on. They get much harder to make later.

### 1.1 Project structure and public API
- [x] Split public and private headers. `include/rasm/` contains no Vulkan, VMA, vk-bootstrap, Slang, tinygltf, SDL or spdlog headers, and `src/` and the backend libraries are PRIVATE (`D2`, review §1, done 2026-11-01).
- [x] Restructure the source tree into `core/`, `platform/`, `assets/`, `scene/`, `renderer/`, `rhi/vulkan/`, and shaders into `lib/` and `passes/` (review §1, done 2026-10-26).
- [x] CMake: `src/` and `examples/` subdirectories, the `rasm` target with alias `rasm::rasm`, the `RASM_BUILD_EXAMPLES` option, and the `rasm_add_example()` helper.
- [x] Put the `*_IMPLEMENTATION` defines in one translation unit, `src/thirdparty_impl.cpp` (`C10`).
- [x] Install and export targets (`find_package(rasm)`). Add `RASM_BUILD_TESTS` together with the first tests (done 2026-11-01).
- [x] Locate assets and shaders through configuration: `EngineConfig::assetRoot`, `EngineConfig::shaderDir` with a `RASM_SHADER_DIR` default beside the executable (`D11`, done 2026-11-01).
- [x] Commit a `.clang-format` and normalize formatting in a dedicated commit (`C2`, done 2026-11-01).
- [x] Apply the naming fixes in their own commit: `registery`, `metallicRoughtness`, `compiledShader`, the snake_case `VulkanContext` members, the PascalCase GPU enums and `RenderGraph::CreateTexture` (`C1`, done 2026-11-01).

### 1.2 RHI
- [x] Define a backend-neutral device interface: device, buffer, texture, sampler, pipeline, command buffer, queue, swapchain, fence/timeline. Move all `Vk*` code behind it (`D1`, done 2026-11-02). The platform's Vulkan surface hook remains until `D7`.
- [x] Use typed descriptors (`BufferDesc`, `TextureDesc`, `PipelineDesc`, …) with defaulted equality and a real hash combine (`D5`, done 2026-11-02).
- [x] Store objects in generational pools. Make `destroy*` APIs available for every object, with destruction deferred until the GPU has finished the frames that use them (`D4`, `P4`, done 2026-11-22). Every object has a destroy call (`destroyEntity`, `removeEntityFromScene`, `destroyMesh` with its import's materials and textures, `destroyMaterial`, `destroyTexture`, `destroyLight`, `removeLightFromScene`, `destroyEnvironment`, `destroyCamera`, `destroyScene`, `destroyBuffer`, `destroyRenderTarget`); pools reuse ranges with `RangeAllocator`; `EngineConfig::maxMaterials` (`D34`); `getPoolStats`; example `17_streaming` streams tiles in and out with flat pools. Open: the remaining waits (`D35`), defragmenting. Earlier, 2026-11-22: every handle comes from a `HandlePool` (free list, generation bump, stale handles refused), `RenderContext` tables are vectors indexed by handle (`P4`, done), and textures, buffers and render targets are destroyed through a release queue tied to the frame, compute and upload fences, which also reuses bindless slots (`B25`, done); `Engine::destroyTexture`, `destroyBuffer`, `destroyRenderTarget`; example `17_streaming`. Open: destroy calls for meshes (and their geometry pool ranges), materials (`D34`), entities, cameras, lights, scenes and environments (`D22`), with row and range reuse; the remaining waits (`D35`).
- [x] Use a single shared pipeline layout (the bindless set + push-constant range), a `VkPipelineCache` persisted to disk, and an on-disk SPIR-V cache keyed by source hash (`P8`, done 2026-11-22). `EngineConfig::cacheDir` (beside the executable, else the user's local cache folder; `""` for none); SPIR-V entries under a 128-bit key of every input, with the struct layouts `validateRasmStructs` checks on a hit; a checked, merged, atomically written pipeline cache per GPU; `pushConstants` without a stage; `--no-cache` for the examples. `09_gltf_materials` starts in 1.02 s warm instead of 2.43 s. Open: one Slang module for both stages of a pipeline (`P23`).
- [x] Load Vulkan functions at run time with volk instead of linking `vulkan-1.dll`: a clear error when the loader is missing or older than 1.3, or no GPU has Vulkan 1.4, device calls without the loader's trampoline, and unit tests that start without a Vulkan loader (`D24`, done 2026-11-22).

### 1.3 Memory and uploads
- [x] Keep static data in device-local memory. Add an upload manager with a staging ring buffer, batched copies and timeline-semaphore completion (`P1`, done 2026-11-04).
- [x] Optional dedicated transfer queue for uploads, with semaphore waits in `SubmitDesc` (done 2026-11-15) and queue-family ownership transfers. It pays off once loading is asynchronous (`D13`, `P6`, done 2026-11-22). `EngineConfig::transferQueue` (on): a load's copies run on a queue family that only copies where the GPU has one (NVIDIA, AMD), else on the graphics queue by the same code; a load's data is used only once its copies are done, so frames never wait for copies in flight; buffers are shared by every family, a texture filled from the staging ring is released by the transfer queue and acquired by the graphics queue; the release queue waits for the load uploads too; `FrameStats::uploadGpuMs`; staging rings without the device-address bit, in system memory unless all of video memory is host-visible (`P10`); a load's texture filled in 4 MiB parts that stop at a full ring (`P24`, texture part). `tools/load_bench.py` (Release, headless, RTX 3060): with a busy GPU (4.5 ms frames) loads end 6 to 11 % sooner, with an idle one the same; the longest frame while the PNG Flight Helmet loads 9.2 → 5.0 ms. Open: uploads recorded off the main thread (`D13`), a model's geometry in parts (`P24`).
- [x] Texture upload: use host image copy when it is supported, otherwise staging. Generate mips on the GPU or with a worker thread. Use a small shared sampler set (done 2026-11-04) (`P2`, done 2026-11-22). `hostImageCopy` is optional; a format is copied on the host only where the driver keeps the image's best layout and lets it use the memory types of a copied image (off on the RTX 3060, whose driver keeps such images in host-visible memory and stalled the GPU while textures loaded; on for lavapipe), else through the staging ring. Mips are made on the worker (sRGB in linear light with alpha weighting, glTF normal maps renormalized); a model's textures are filled one at a time under `LOAD_BUDGET`; sampled textures are sub-allocated (`P22`) and `VRAMStats::vramAllocated` counts them. Example `10_ktx2_textures --measure` (and `--staging`): the longest frame while loading is 10 ms instead of 206 ms for the PNG Flight Helmet, 6 instead of 280 ms for Sponza. A glTF's images get their mips on several workers since `P14` (done 2026-11-22, below). Open: a model's geometry or one texture still finishes in one frame (`P24`). GPU mip generation stays an option (`docs/guides/texture-uploads.html`).
- [x] Load assets asynchronously on worker threads, and release CPU-side asset data after upload (`P6`, done 2026-11-04).
- [x] Run every load on one bounded worker pool with a memory budget, and a glTF's images and LODs as jobs of their own (`P21`, `P14`, done 2026-11-22). `EngineConfig::loadThreads` (0: the hardware threads minus one) and `loadMemoryBudget` (512 MiB: a load starts only when its decoded bytes fit next to what started loads and results waiting for upload hold); child jobs run first, and the last child finishes its load, so no job waits for another; destroying a mesh, texture or environment drops its load; `Engine::getLoadStats` and a Loads line in the RASM window. `10_ktx2_textures --measure` (Release, headless, RTX 3060): Flight Helmet KTX2 535 → 110 ms, PNG 931 → 191 ms, Sponza 1052 → 200 ms; `17_streaming --burst` (300 images in one frame): peak private memory 3519 → 2964 MiB, at most 512 MiB decoded; `tools/load_bench.py`. Open: a priority per load (the queue is FIFO), 16-bit images (`D36`), workers that compete with the main thread (`P25`).
- [x] Custom allocators: per-frame linear allocators for transient CPU data, pool allocators for registries. (Original item 4; scope these to measured hot spots.) (`P26`, `P27`, done 2026-11-23: measured, the allocators themselves are **not needed**.) A counting `operator new` (Release, headless, frames 500 to 1500 of every example) found at most 24 allocations per steady frame (`05_city`, 259 KB, 5.4 µs of a 1.36 ms frame), all from four causes; they are fixed, and every example's steady frame now makes none, which `rasm_image_tests` checks. A per-frame arena: not needed, no transient data is left for it. Pool allocators for registries: not needed, the registries are `HandlePool`s over vectors (`D4`), and creating and destroying objects while `17_streaming` streams costs about 7 allocations a frame in the engine, a few µs. The measured hot spot was elsewhere: freeing a finished load's decoded data on the main thread, 1.2 ms per frame of the 300-image burst; it is freed on a worker now (`Engine::freeOnWorker`), and the burst loads in 335 ms instead of 413 (`docs/guides/frame-allocations.html`).

### 1.4 Conventions
- [x] Use a right-handed Y-up world. Flip Y with a negative-height viewport, stop mirroring geometry, enable back-face culling, and honor glTF `doubleSided` (`D8`, done 2026-11-04).
- [x] Use reversed-Z with an infinite far plane by default. The depth format becomes `D32_SFLOAT`, without stencil unless it is requested (done 2026-11-04).

### 1.5 Quality
- [x] Extend `rasm_tests` to glTF import (done 2026-11-04) and to the handle pools (done 2026-11-22: `HandlePool` and the release queue, `D4`). Handles, descriptor equality and hashing, render-graph sorting, transforms, camera math and glTF import are covered (`D17`).
- [x] Set up CI: build Windows and macOS presets on every PR, and run unit tests (`D17`, done 2026-11-04). Add image tests once headless rendering exists (phase 4; done 2026-11-22: the Windows job runs the golden-image tests on lavapipe).

**Exit criteria:** examples build against `rasm::rasm` from an install tree, using only public headers. Core code contains no `Vk*` identifiers. Objects can be created and destroyed at runtime without leaks under validation.

## Phase 2: The GPU-driven scene

Goal: make RASM's core promise hold at scale.

- [x] **GPU scene tables** (`D6`, `P3`, `P7`):
  - a persistent geometry pool (a sub-allocator inside mega vertex and index buffers, uploaded once per mesh). The pool and a geometry table with per-sub-mesh bounds are done (2026-11-07). Freeing and reusing ranges is done (2026-11-22, `D4`): a `RangeAllocator` per stream and for the table rows, freed through the release queue.
  - an instance table (transform, mesh index, material index, bounds) and a material table (done 2026-11-07; the bounds are in the geometry table),
  - per-frame upload of only the dirty ranges (done 2026-11-07, example `03_instances`).
- [x] Separate *mesh* from *instance*, so entities that share a mesh share its geometry (`P3`, done 2026-11-07).
- [x] Compute pipelines and compute passes in the RHI (done 2026-11-07, example `04_compute`). Compute writes buffers only, and samples textures through the bindless set (done 2026-11-07). Storage images (done 2026-11-21, for the environment bake, outside the render graph); render graph compute passes that write textures (done 2026-11-21: storage render targets, `RenderTargetDesc::storage`, and storage textures, moved to `STORAGE` and back to `SAMPLED` by the graph).
- [x] **GPU frustum culling**: a compute pass that writes a compacted draw list, followed by `vkCmdDrawIndexedIndirectCount` (done 2026-11-07).
- [x] **Occlusion culling**: a two-pass hierarchical-Z scheme (draw what was visible last frame, build Hi-Z, cull and draw the rest) (done 2026-11-07, `EngineConfig::occlusionCulling`). The Hi-Z is a buffer pyramid built by compute from the sampled depth, so it needs no storage images.
- [x] LOD selection on the GPU, from per-mesh LOD ranges and screen-space error (done 2026-11-07, `EngineConfig::meshLods` and `lodErrorPixels`). LODs are built with meshoptimizer as meshes load and share the mesh's vertices. Reordering the vertices for coarse-LOD fetch locality, and streaming LODs in and out of the pool (the pool frees ranges since `D4`), are still open.
- [x] Optional: meshlets with cluster culling, and a mesh-shader path where available (a Tier-A extra; keep the vertex-pulling path as the baseline; done 2026-11-23). Every LOD of a sub-mesh of 1024 triangles or more (not skinned or morphed, `D37`) gets meshlets of 64 vertices and 124 triangles on its load job, stored as ranges of the LOD's indices in a meshlet stream of the geometry pool (`EngineConfig::geometryPoolMeshlets`); with `EngineConfig::meshletPath` = `VERTEX_PULLING` (`Engine::setMeshletPath`) a visible draw with 8 meshlets or more is culled per meshlet (frustum, normal cone in object space, Hi-Z with a visibility bit per meshlet and view) in every view, and its visible meshlets are packed in order and drawn by indirect draws; `maxViewMeshlets` budget, `DebugView::MESHLETS`, meshlet stats, image tests that compare both paths. Example `18_meshlets` (`--bench`), `--meshlets` and `--bench` in `05_city`. The mesh-shader path (`MeshletPath::MESH_SHADERS`, `VK_EXT_mesh_shader` where the GPU has it, else vertex pulling): `taskMain` culls each chunk inside the draw pass and launches a mesh workgroup per visible meshlet, which reads the meshlet's own vertices and packed triangles (`EngineConfig::geometryPoolMeshletData`); every view kind, MASK with alpha-to-coverage, motion vectors, MSAA, the debug views and frozen culling; `mesh_*` image tests. Measured (RTX 3060, 1080p, `P28`): mesh shaders cost about 1% with LODs (1.97 → 1.99 ms) and save up to 30% on dense meshes (1.71 → 1.19 ms), vertex pulling costs 11% with LODs, so the default is `MeshletPath::AUTO` (mesh shaders where available, else off). The stats split "LOD saved" and "Meshlets saved" (`FrameStats::trianglesVisibleLod`). Open: meshlets of skinned and morphed meshes (`D37`).
- [x] Stats overlay: frame time, GPU time per pass, triangles, instances drawn/culled, memory. (Original item 8; done 2026-11-07, `EngineConfig::showStats` or F1, on in example `03_instances`.)

**Exit criteria:** a "city" example with ≥ 100k instances renders with CPU frame time independent of instance count. Culling statistics are visible on screen. (Example `05_city`, done 2026-11-07: 145.6k instances, about 1 ms of CPU per frame in Release, GPU-bound.)

## Phase 3: A real render graph

Goal: passes describe what they use, and the graph does the synchronization and memory work (`D9`).

- [x] Track resource state and generate barriers and layout transitions automatically (done 2026-11-07). Textures keep their state in `RenderContext`, and the graph orders each declared buffer by its last write and the reads since, across frames. A pass must declare every buffer it uses: an undeclared one gets no barrier.
- [x] Imported resources (swapchain, history buffers) and transient resources with lifetime-based memory aliasing (`D9`, done 2026-11-13). `PassBuilder::writeSwapchain`, history render targets read with `readPrevious`, transient render targets placed in shared heaps by their lifetimes (`rhi::packAliased`), and targets sized from the window (`RenderTargetDesc::swapchainScale`).
- [x] Per-pass attachment load and store ops (no implicit clears) and multiple color attachments (done 2026-11-13). `AttachmentOps`, set by the graph so that later passes on a target load what earlier ones drew; up to `MAX_COLOR_ATTACHMENTS` colors per render target, with pipelines from `Engine::createPipeline(name, source, renderTarget)`. Resolve moved to the MSAA item in phase 4, since it only serves multisampled targets.
- [x] Graph-driven frame: the forward/culling pipeline from phase 2 becomes a set of graph passes, and `Engine::render` moves behind `Renderer::render(view)` (`D9`, `D18`, done 2026-11-13). `Engine::addScenePasses` adds a scene view's culling, draw, Hi-Z, late culling and late draw passes to any graph; the barriers inside the Hi-Z build and between the count and write dispatches of culling stay inside their passes.
- [x] Async compute: run culling and Hi-Z on a compute queue where available, with cross-queue synchronization generated by the graph (`D13`, done 2026-11-15). `RenderGraph::addAsyncComputePass`, `EngineConfig::asyncCompute`. Off by default: on the scene passes alone the handoffs between the queues cost a little more than the overlap saves (`P11`).
- [x] Graph debugging: dump the pass graph and resource lifetimes, and give every pass a GPU timestamp (done 2026-11-07, shown in the stats overlay). `RenderGraph::dump` lists the passes in the order they run, with their reads, writes, attachment ops and the passes that wait for them, then a lifetime table with a column per pass; F3 logs it for the graph `Engine::render` runs (done 2026-11-15).

**Exit criteria:** a multi-pass example (shadow + forward + post) contains no hand-written barriers. (Example `06_shadows`, done 2026-11-15: a depth-only shadow map drawn by `addScenePasses` from a light camera, the forward view that samples it through `SceneShadow`, and a post pass; validation-clean with synchronization validation.)

## Phase 4: Rendering features

Goal: production look and completeness for glTF content. The order is roughly by value to the target users.

- [x] An HDR color target plus a separate tone-map pass (ACES or AgX) with exposure. Remove Reinhard from the material shader. (Done 2026-11-20: the scene passes draw into a `SCENE_COLOR_FORMAT` (`R16G16B16A16_SFLOAT`) target, and `Engine::addToneMapPass` maps it to the swapchain with AgX and `Camera::exposure`.)
- [x] **Shadows**: cascaded shadow maps for directional lights, and spot and point light shadows. Add real spot lights (`B15`). Done 2026-11-20: cascades for a directional light (`Engine::addShadowPasses`, `ShadowDesc`, example `06_shadows`), up to `MAX_SHADOW_CASCADES` (4) depth-only maps fitted to slices of the camera's view, which replace the single map from a light camera the application placed (done 2026-11-15). `LightType::SPOT` with glTF cone angles; a spot light's shadow is one perspective map, and a point light's is a cube texture (`RenderTargetDesc::cube`) drawn by one scene view per face. A view reads up to `MAX_VIEW_SHADOWS` (4) shadowed lights (`addScenePasses` takes a list), and `MAX_SCENE_VIEWS` is 16 (example `07_lights`).
- [x] **Image-based lighting**: an environment map, prefiltered specular, irradiance and a BRDF LUT. Done 2026-11-21: `Engine::loadEnvironment` takes an equirectangular `.hdr`, and the first frame after it decodes bakes, on the GPU before the graph, a cube with mips, a GGX specular cube of 6 roughness mips (filtered importance sampling) and a 32² irradiance cube; a 128² BRDF LUT is baked once per engine. `setSceneEnvironment` (`SceneEnvironment{environment, intensity, rotation, sky}`) lights a scene with the split sum in `shadePBR` and draws it as the sky. The RHI got storage images for it (`TextureUsage::SAMPLED_STORAGE`, the `STORAGE` state, binding 1 of the bindless set). Example `08_ibl`. Open: destroying an environment (`D22`, after `D4`), shadowed environment light and specular occlusion (`D23`).
- [x] **glTF completeness** (done 2026-11-21):
  - alpha modes (`MASK` as a cut-out, and `BLEND` as a sorted transparent pass; done 2026-11-21: `Material::alphaMode` and `alphaCutoff`, a pipeline per alpha mode, the `Transparent` pass after the sky with the blend run sorted back to front by a GPU bitonic sort, and hashed alpha for `BLEND` in shadow maps. Alpha-to-coverage moved to the MSAA item; cut-outs still thin out in the far mips, `D25`),
  - vertex colors (tangents done 2026-10-27; colors done 2026-11-21: `COLOR_0` and `createMesh(vertices, indices, colors)` into an optional color stream of the geometry pool, `packVertexColor`),
  - `KHR_texture_transform`, `KHR_materials_emissive_strength`, `KHR_mesh_quantization` (done 2026-11-21, with a check of `extensionsRequired`; a rotated normal map keeps the authored tangent frame, `D26`), example `09_gltf_materials`,
  - KTX2/Basis textures (done 2026-11-21: `.ktx2` through `loadTexture` and glTF `KHR_texture_basisu`, transcoded on the worker with libktx to BC7/BC5/BC4, ASTC 4×4 or ETC2/EAC, whichever the device samples, RGBA8 as the fallback, with the file's mips; block formats in `Format`, `supportsTextureFormat`, `fillTexture` with every level, a staging path for formats without host image copy (`P2`), two-channel normal maps (`MATERIAL_NORMAL_XY`), example `10_ktx2_textures`: the Flight Helmet in 68.6 MiB instead of 272.6 MiB).
- [x] **Many lights**: clustered forward lighting. Remove the fixed `MAX_LIGHTS = 8`. (Done 2026-11-21: lights live in a GPU light table of `EngineConfig::maxLights` rows (16384 by default), written only when a light changes (`updateLight`, `getLight`). Each shaded view sorts its scene's local lights (point and spot lights with a range) into 16 × 9 × 24 clusters on the GPU in its first cull pass, in two levels (per screen tile, then per cluster) and in a fixed order, and `shadePBR` shades the view's shadowed lights, the global lights (directional, or without a range) and its pixel's cluster, at most `MAX_CLUSTER_LIGHTS` (256). The clusters need no depth buffer, so the `Transparent` pass and a later MSAA target use them as they are. `EngineConfig::clusteredLighting` = false shades every light at every pixel, with the same image. Example `11_many_lights`: 4096 lights take 0.31 ms of assignment and 4.5 ms of draw passes at 1080p (RTX 3060), against 231 ms with every light at every pixel. A light beyond a view's `MAX_VIEW_SHADOWS` shadowed ones has no shadow. Open: far clusters crowd with many short lights (`P15`).)
- [x] Anti-aliasing (MSAA option, with the resolve in a pass of the graph (done 2026-11-21: `RenderTargetDesc::samples`, pipelines per sample count, the Hi-Z from every depth sample, `Engine::addMsaaResolvePass` weighting each sample by 1 / (1 + luminance) so bright edges stay smooth, `EngineConfig::antiAliasing`, examples `09_gltf_materials` and `02_gltf` with `--aa`), and TAA (done 2026-11-21: `InstanceData::previousWorld` written in the sync, a `MOTION_FORMAT` motion color, Halton (2, 3) jitter per view, `Engine::addTaaPass` with nearest-depth motion, Catmull-Rom history, YCoCg variance clipping and brightness weights, a −1 texture mip bias, `resetCameraHistory` and a reset on camera jumps, deterministic; `AntiAliasing::TAA`; 0.37 ms at 1080p on an RTX 3060; `D27`)), bloom (done 2026-11-21: `Engine::addBloomPasses`, 11 compute passes of Jimenez's down and up chain into transient storage render targets, 1/2 to 1/64 of the source, stopping at the last level of at least 2 x 2; `addToneMapPass` mixes it in by `Camera::bloomStrength`; `EngineConfig::bloom`, off by default; example `09_gltf_materials`: 0.37 ms at 1080p on an RTX 3060). With MSAA, glTF `MASK` turns on alpha-to-coverage: the mask pipeline outputs a sharpened alpha, `(alpha - cutoff) / fwidth(alpha) + 0.5`, instead of discarding, so cut-out edges are smooth and keep the material's cutoff (done 2026-11-21).
- [x] Skinning and animation, morph targets (done 2026-11-22). Node animation is done (2026-11-21): glTF clips (STEP, LINEAR with slerp, CUBICSPLINE) on the nodes that move a mesh, posed on the GPU by an `Animate` pass, one group per playing entity, which every view and shadow map reads through `getWorldMatrix`; `setAnimationTime` (the clock is the application's; the GPU adds only the seconds since a base that moves every 64 s, within 0.1 ms after a day), `playAnimation`, `stopAnimation`, `getAnimations`, `findAnimation`, `ALL_ANIMATION_CLIPS`; motion vectors from the other slot's transforms; example `12_animation`. `Animate` takes 0.17 ms for 10000 playing entities (30k nodes, RTX 3060), and the CPU cost does not grow with them. Skinning is done (2026-11-21): `JOINTS_0` / `WEIGHTS_0` (and more sets: the 4 largest, renormalized) in a 16 B skin stream of the geometry pool, the skins' joints and inverse bind matrices, a skinned mesh placed by its joints and not its node; the `Animate` pass writes the joint matrices and each skinned sub-mesh's bounds (the joints' spheres moved by their matrices, used by every view's culling), and a `Skin` compute pass writes every skinned vertex once per frame into one buffer per frame slot (128 B per vertex per playing entity, growing by itself), which every view and shadow map draws and the other slot gives TAA's motion; example `13_skinning` (CesiumMan, three foxes playing their clips by name, RiggedFigure). `Skin` takes 0.29 ms for 0.34M skinned vertices and 2.1 ms for 3.28M (1000 CesiumMan, RTX 3060), the shadow cascades add none, and the CPU cost does not grow with the entities. A skinned mesh that plays nothing stands in its skeleton's rest pose (`D30`, done). Morph targets are done (2026-11-22): each primitive's `POSITION`, `NORMAL` and `TANGENT` deltas (sparse accessors too) in a target-major morph stream of the geometry pool (`EngineConfig::geometryPoolMorphs`, 24 B per vertex and target: float positions, half-float normals and tangents; MorphStressTest takes 282 KiB, and its normal deltas lose at most 6.2 · 10⁻⁶ as halves), the rest weights (node, else mesh) and target names, the `weights` path of clips (STEP, LINEAR, CUBICSPLINE), and `setMorphWeights` / `clearMorphWeights` / `getMorphTargetNames` for weights from the application; the `Animate` pass writes each entity's weights and grows its bounds by Σ |w| · r, and the `Skin` pass adds the deltas of the targets whose weight is not 0 before it skins, also for a mesh with no skin; example `14_morph_targets` (MorphStressTest, AnimatedMorphCube, SimpleMorph, a cube driven by a sine). `Skin` takes 0.88 ms for 1000 MorphStressTest (1.5M morphed vertices) with all 8 weights at 0, 0.92 ms with 4 active and 1.11 ms with 8, and 1.87 / 2.11 ms for 2000 (RTX 3060, 1080p): a target at weight 0 costs nothing, and the CPU cost does not grow with the entities. Open: attachments to nodes (`D28`), skipping still or unseen entities (`P18`), LODs that see the skin weights and the morph deltas (`D29`), normals of morphed primitives that have none (`B32`), packed weight keys (`P20`).
- [x] Dear ImGui integration (behind an option) with debug views: normals, UVs, overdraw, culling, buffers (original item 9; done 2026-11-22). The integration is done (2026-11-22): Dear ImGui from vcpkg (the `imgui` port with `sdl3-binding`, a manifest feature that the CMake option `RASM_IMGUI`, on by default, turns on; linked PUBLIC and static, so the application's `ImGui::` calls share RASM's context), and `EngineConfig::ui` at runtime (off: nothing runs). ImGui's draw lists are drawn by a renderer of RASM's own through the RHI, so later backends get it for free: vertex pulling from per-slot buffers, 16-byte push constants, bindless textures through ImGui's texture protocol, a scissor per command, in the `UI` pass (`Engine::addUiPass`, after the tone map, or from `endFrame` when a graph has none), and through a UNORM view of the sRGB swapchain (`VK_KHR_swapchain_mutable_format`) so the colors blend as ImGui expects (else in linear light, `D31`). Input comes through ImGui's SDL3 backend, only in `src/platform/uiPlatform.cpp`, so `D7` can replace it; the camera ignores what the UI captures. F1 shows the RASM window (the frame stats, the forced LOD, the graph dump) in place of the stats overlay, which stays for programs without the UI. `Engine::setUiCallback` adds the application's windows and `getUiTexture` shows any texture with `ImGui::Image`; example `15_debug_ui`: with the RASM window, an application window and an image, the `UI` pass takes 0.12 ms of GPU and the `UI` zone 0.17 ms of CPU (Release, 1280 × 720, RTX 3060), and with `ui` off neither exists. The debug views are done too (2026-11-22): `Engine::setDebugView` with `DebugView::NORMALS`, `UVS`, `OVERDRAW`, `LODS`, `CULLING` or `LIGHT_COUNT`, and `Engine::setCullingFrozen`, in the RASM window or from the application. Each view is `rasm.slang`'s `fragMain` compiled with `RASM_DEBUG_VIEW` the first time it is chosen (the normal shaders have no branch, the CPU one compare per draw run, and the GPU timers with `DebugView::NONE` are those of main within noise); overdraw adds 1 per fragment with `BlendMode::ADDITIVE`, the culling view adds ghosts of the culled draws, a box around each one's bounding sphere (`PipelineDesc::depthTest` off), and the tone map shows the values as they are or the counts as a heat color. Freezing keeps a view's frustum, LOD camera and visibility, runs only the early pass, and draws the frozen frustum on the UI; `cull.slang` is unchanged. `15_debug_ui` and `05_city` take `--debug-view` and `--freeze-culling`. A view's GPU frame is 4.1 to 4.4 ms against 5.0 ms shaded (`09` at 1080p, Release, RTX 3060), and the ghost boxes take 0.6 ms in `05_city` (1.7 ms frozen). The buffer inspector is done too (2026-11-22): the RASM window's Buffers section lists the resources of the graph that runs (each render target's colors and its depth, so the HDR color, motion, TAA history, MSAA resolve, bloom levels, shadow cascades and point-light cube faces, plus each scene view's Hi-Z levels and light clusters) and shows the picked one, with a face, sample, channel, level or slice. An Inspect compute pass, placed by the graph right after the pass that last writes the resource (so it also works for aliased transient targets), converts it into a 1024² `RGBA16F` picture: HDR color with an exposure, one channel as gray, reversed-Z depth as view depth, motion as a hue, counts as heat; `ImGui::Image` shows it. Nothing picked or the section closed: no pass, and the GPU timers of `09` equal main's. One copy costs 0.14 to 0.35 ms at 1080p (Release, RTX 3060). The GPU tables section lists the tables (rows used, bytes, rows sent this frame) and an entity's rows field by field, with names, types and offsets from Slang reflection and values from each `GpuTable`'s CPU copy (what was uploaded, not a readback). `Engine::setInspection` picks from code; `09_gltf_materials` and `11_many_lights` take `--inspect`. Logged: `D32`.
- [x] Headless/offscreen rendering with readback (done 2026-11-22: `EngineConfig::platform = PlatformType::HEADLESS` runs with no window and no SDL, behind a private `Platform` interface that is the first step of `D7`, and renders into an offscreen swapchain of the device's own textures. `Engine::readFrame` and `readTexture` copy the frame or a readable texture (`RenderTargetDesc::readable`) back at the end of a frame, tracked by the frame fence, so `isReadbackReady` turns true two frames later and `takeReadback` converts the texels to `RGBA8_SRGB` or `RGBA32_FLOAT`; `writePng` saves them. The examples take `--wait-for-loads`, which `verify-change` passes (`C16`), and `--headless --frames N --out <png>` (done 2026-11-22: every example runs headless and writes frame N through `readFrame`, the UI included, with no input; `verify-change` runs them so, and `--fixed-step` sets `EngineConfig::fixedDeltaTime`, `C15`). Example `16_headless`), which enables golden-image tests in CI (done 2026-11-22: `rasm_image_tests` renders 15 scenes headless at 512 × 288 (DamagedHelmet under IBL with cascades, Sponza, AlphaBlendModeTest at 1 and 4 samples, TAA, bloom, skinning, morph targets, node animation, 1024 lights, spot and point shadows, KTX2, texture transforms and vertex colors, the normals view, and a determinism check) and compares them with goldens in `tests/golden/lavapipe/`: a pixel differs when a channel is off by more than 3/255, a test fails when more than 0.1% of the pixels differ. `tools/image_tests.py --lavapipe` fetches lavapipe (Mesa 26.3.0) and Sponza, both SHA-256 pinned, and runs them; the Windows CI job runs it after the Release tests (about 1 minute with the asset cache: 50 to 80 s for the tests, 8 s for the cache and lavapipe). Measured noise: the largest difference was 0 in every test, between two runs in one job, between two CI runs, and against a run with each test in its own process (all on an AMD EPYC 7763), so T and F are a margin for runners on other CPUs. The tests found `B33` on their first run: `discard` was an `OpKill` with texture samples after it, which crashed lavapipe; it now demotes the lane to a helper. Guide `docs/guides/image-tests.html`).

**Exit criteria:** the Khronos glTF sample models (DamagedHelmet, Sponza, AlphaBlendModeTest, …) render correctly under IBL with shadows, and image tests guard regressions.

*Status 2026-11-22:* met, with two limits. The sample models render correctly under IBL with shadows, and 15 image tests guard them in CI on lavapipe. The environment light is not shadowed (`D23`): Sponza's atrium and the ground under the models get the full sky light, so the image is correct for today's lighting model, not for a shadowed sky. The goldens are lavapipe's only; real GPUs are checked by `verify-change` baselines, and macOS CI runs no image tests. The runner renders all 15 tests in one engine, since meshes have no count limit (`D33`, fixed 2026-11-22).

## Phase 5: Integration for the target audiences

### Embedding (all audiences)
- [x] A platform layer the application can replace: create the engine from a native window or surface handle, or headless (headless done 2026-11-22, `PlatformType::HEADLESS`). The application owns the event loop and feeds input (`D7`). Done 2026-11-24: `PlatformType::NATIVE` draws into the application's window from `EngineConfig::nativeWindow` (an `HWND`, a `CAMetalLayer`, an X11 or XCB window, a Wayland surface), whose surface the device makes in `createVulkanSurface`; the SDL platform passes its own window the same way, so SDL no longer loads Vulkan. All input is one stream of `InputEvent`s (`rasm/input.h`: a key's meaning and its position, mouse, wheel, text, focus), from the SDL platform or from `Engine::addInputEvent`, applied in `beginFrame` to Dear ImGui (no ImGui platform backend any more) and to the camera; `setWindowSize` and `setWindowContentScale` give the size in points and pixels and the display's scale, and the UI follows a display-scale change. The SDL platform does the UI's cursor shapes, clipboard and text input through `Platform` hooks, and captures the mouse during a drag. The queue keeps its capacity, so a steady frame still makes no heap allocation. Example `19_embedding`: an SDL3 window the application owns; `--headless` renders into a hidden window with a scripted drag, click and typing, identical to the same script on a headless engine (`--no-window`). Guide `docs/guides/platform-layer.html`. Open: the IME window's position (`D38`), SDL video drivers without a native handle such as `kmsdrm` (`D39`); several windows are the next item.
- [x] Optional camera controller helpers that the application drives instead of the engine (`D7`, done 2026-11-24). `CameraRig` with `createCameraRig` and `updateCameraRig` (`rasm/cameraController.h`) and `CameraInputState` with `addCameraInputEvent` and `takeCameraInput` for an `InputArea` (`rasm/cameraInput.h`) are plain structs and free functions with no `Engine`, ready for the C API; the engine's built-in path calls the same ones. `CameraController::Type::NONE` keeps `beginFrame` off a camera the application moves. `Engine::pollEvents()` runs once per frame and may be called before `render`, so `getInputEvents`, `getCameraInput`, `getUiInputCapture` and `getDeltaTime` give the frame's input with no delay, also on the SDL platform. `examples/05_city` flies its own rig on the engine's input, `examples/19_embedding` feeds its own `CameraInputState` and switches orbit and fly with F. Guide: `docs/guides/camera-controllers.html` ("Who runs the controller").
- [x] Multiple views and windows, viewports and render-to-texture as first-class features (done 2026-11-24). Views, viewports and render to texture: `Engine::render(views, count)` draws a list of `View`s (`rasm/view.h`), each a scene, a camera and a `ViewOutput`: a `ViewRect` of the window, as fractions whose edges `getViewPixels` rounds so touching views share them, or a color `target`, a view texture that a material or `ImGui::Image` samples. A view keeps its HDR target, scene view and TAA history while its camera and output target stay in the list, wherever it is, so editing the list resets no other view; a frame with the same list allocates nothing. Views draw in list order (a later rect over an earlier one), and each view's scene passes, and the UI, read the view textures listed before them, so they see this frame's picture. `View::bloom` and `View::antiAliasing` override `EngineConfig`'s. The low-level parts: `addToneMapPass`'s `ViewOutput`, `addScenePasses`'s `sampled` and `addUiPass`'s `shown` view textures, color-only render targets, kept targets that start cleared, and `Engine::resizeRenderTarget`, which keeps texture handles and bindless slots and waits only for the frames in flight (`D35`). `MAX_SCENE_VIEWS` and `MAX_CAMERAS` are 32 (`D20`). `getInputArea` gives each view's camera its own input. Example `20_views` (split screen, a map in the corner, four views, a TV showing a security camera, `--bench`), image test `views`, guide `docs/guides/multiple-views.html`. Measured (RTX 3060, 1920 × 1080, TAA and bloom on the big views): 1.27 ms for one view with a map and a 320 × 180 view texture, 1.50 ms split in two, 1.42 ms in four quarters. Windows (`D7`): `Engine::addWindow(WindowDesc)` gives an SDL window, an application's window (`NATIVE`) or an offscreen image (`HEADLESS`) a swapchain of its own (a surface of its own, present support checked), `removeWindow` destroys it after a wait for the device, and `getWindow`, `setWindowSize(window, ...)`, `setWindowContentScale(window, ...)` and `readFrame(window)` take it. One submit waits for every acquired window's image and presents them all; a minimized window sits a frame out, and the frame is skipped only when no window can show. `PassBuilder::writeSwapchain(window)` and `ViewOutput::window` name a window; a pass or view whose window has no image or was removed draws nothing. `InputEvent::window` tags every event; the SDL platform reports a second window's close as `InputEventType::WINDOW_CLOSE` and the main window's as quit, with focus per window. Examples `19_embedding` (two windows of the application's, hidden under `--headless`) and `20_views` (a second SDL window, offscreen under `--headless`) write each window's frame; image test `views_window2`. Open: shadows in `render(views, count)`, mips for view textures (`D40`), Dear ImGui in more than one window (`D31` (3)).
- [x] Split subsystems so integrators can use only the renderer: `Platform`, `AssetManager`, `Scene`, `Renderer`, `rhi::Device` (`D3`, done 2026-11-24). `rasm::Renderer` (`rasm/renderer.h`) is the renderer without `Engine`, on the application's window or offscreen, with no SDL; `rasm::AssetLoader(Renderer&)` (`rasm/assetLoader.h`) loads files on its workers into any renderer, which reaches it only through `LoadHooks` and must outlive it; `Engine` is a `final` `Renderer` that picks its `Platform` and owns an `AssetLoader`, its API unchanged (`getConfig` gives the `EngineConfig`); `RendererConfig` and `AssetLoaderConfig` are `EngineConfig`'s parts; `RenderContext` is made from a `RenderContextDesc` and owns the bindless set. Two libraries: `rasm::renderer` (no SDL3, tinygltf, tinyobjloader, libktx) and `rasm::rasm`, both installed, with `find_package(rasm COMPONENTS renderer)`. Examples `21_renderer` (a Renderer alone, linked to `rasm::renderer` only) and `19_embedding` (a Renderer and an AssetLoader on the application's SDL3 windows). `Scene` stays part of the Renderer by decision: the GPU tables mirror the objects row by row, and a separate Scene would only add change lists without a use case. The import types left the public `mesh.h` (`D2`).
- [x] **A C API** (`rasm_c.h`), a stable C ABI facade over the C++ core, for bindings in other languages. (Original item 5. I recommend this rather than rewriting the engine in C without the STL: it gives the same portability and keeps C++ productivity inside the engine.) Done 2026-11-25: `include/rasm/rasm_c.h` (version 1.0) and the shared libraries `rasm_c` (`rasm::c`: renderer, `Engine`, `AssetLoader`) and `rasm_c_renderer` (`rasm::c_renderer`: the renderer alone), installed as the component `c` with the shaders beside them. Opaque pointers, handles as `{ uint64_t id; }` (`generation << 32 | index`; `HandlePool` retires a slot at `MAX_HANDLE_GENERATION`), `uint32_t` enums and booleans, sized structs with `_init` functions, `RASM_CALL`, error codes with a per-thread `rasm_get_last_error` and `rasm_set_log_callback`, a version check at creation, relative paths against the library's folder (`rasm_get_base_path`). Covered: lifecycle, scenes, entities, meshes from memory and files, materials, textures from memory and files, lights, cameras, environments, the single-view frame, readback into `rasm_image` and PNG. Example `22_c_api` (C99); `tools/check_install.py` checks installed C++ and C consumers, the exports, and a Python ctypes run in CI. Version 1.1 (PR 2) appended windows, input events (one by index), `rasm_render_views` with sized `rasm_view` arrays converted on the stack, render targets for view textures, camera controllers with `rasm_camera_rig` and `rasm_camera_input_state`, animation and morph weights, and frame, pool and load stats; `22_c_api` draws three views (a map into a view texture) and turns its trackball with synthetic mouse events.
- [x] **The rest of the C++ API in C** (done 2026-11-28, three PRs): the render graph and custom passes, `RenderContext` and buffers, shadows in `render(views)`, Dear ImGui and `setUiCallback`, the buffer inspector, GPU timers and the debug views. They need a callback ABI (a C function and its user data called during recording) and command-buffer handles, or C UI bindings. Three PRs, each complete on its own.
  - **PR 1, the render graph and custom passes (C API 1.17).** Done 2026-11-28. `rasm_render_graph` (create, destroy, `create_render_target`, `compile`, `execute`: a whole frame, `dump`) with RASM's passes (`rasm_render_graph_add_shadow_passes` returns a graph-local `rasm_shadow`, `_add_scene_passes`, `_add_msaa_resolve_pass`, `_add_taa_pass`, `_add_bloom_passes`, `_add_tone_map_pass` with a sized `rasm_view_output`, `_add_ui_pass`) and the application's (`rasm_render_graph_add_pass`: a `rasm_pass_desc` with a type, a list of `rasm_pass_resource` accesses in place of the setup lambda, and a `rasm_pass_callback` with `user_data` in place of the execute lambda). The callback ABI (`docs/guides/stable-c-abi.html#callbacks`): the callback runs on the thread of `execute`, during it, once a frame the pass runs; its `rasm_commands` (one per graph, so a frame allocates nothing) is active only during the call, and every `rasm_cmd_` call checks that and that it fits the pass (bind pipeline with the bindless set, push constants up to 16 B, viewport, scissor, cull mode, draw, indexed and indirect draws, dispatch and indirect dispatch, barriers in compute passes, GPU timers, the output's size). While a graph records, calls that start a frame, change a graph or free what the frame uses are refused (`checkNotRecording`), and `execute` then returns `RASM_ERROR_FAILED`; a callback must return normally. Destroying a renderer or engine detaches its graphs (their calls fail, destroy frees them). Also buffers (`rasm_create_buffer`, write, read, device address), pipelines from Slang or SPIR-V with blend, depth and topology (`rasm_create_pipeline`, through the new C++ `Renderer::createShader`), bindless slots, a render target's current, previous and depth textures, the GPU timers by index, and seven fields at the end of `rasm_render_target_desc`. Example `33_c_render_graph` (C99): shadows, scene, TAA, bloom and tone map, then a compute histogram, a 1 x 1 history target that eases the mean brightness, and a grade pass whose parameters sit in a buffer behind an address in its push constants; headless it checks the bins, the history copies and the timers. `ctypes_smoke.py` draws a pass whose callback is a Python function. Logged: the tile streamer's destroy order (`D57`).
  - **PR 2, views and debugging (1.18).** Done 2026-11-28. Shadows in `render(views)`, in C++ too: `View` has `ShadowDesc shadows[MAX_VIEW_SHADOWS]` (4) and `shadowCount` (`ShadowDesc` got an `operator==`, so a changed list rebuilds the view graph), and `ViewGraph::addView` adds `addShadowPasses` for each before the view's scene passes, cascades and LODs fitted to that view's camera (`D20` counts their scene views). Nothing is shared across cameras but memory: the `ViewGraph` keeps a `ShadowSet` per light, map size and map count (a second view of one camera gets its own), persistent across graphs, which views of different cameras draw in turn: each view's first pass on a map clears it (`Pass::clearsOutput`), and the graph's write-after-read edges run it after every reader of the view before (its `Scene 1`, `Scene 2`, `Transparent` and the Hi-Z of its cascades); sync validation is clean on `20_views` (layout changes, TAA, `--msaa`, `--async-compute`), and its main window is bit-identical with a set per view. A set no view uses is destroyed through the release queue. The maps keep their handles, so a rebuilt graph keeps every shadow scene view (`20_views`' layout changes: 0 new views for the views that stay). `MAX_GPU_TIMERS` is 256 (`D21`), since layout 3 with shadows has about 160 passes. Cost (Release, 1920 × 1080, RTX 3060): a view without shadows costs what it did (05, 20, 22, 26 and 31 within 0.01 ms of `main`); four 2048 cascades about 0.6 ms per view (`20_views` layout 2: 1.55 ms without, 3.25 ms with three shadowed views). C API 1.18: `rasm_view` gets `shadow_count` and a `shadows` pointer (sized `rasm_shadow_desc`s, read during the call), then `rasm_set_debug_view` / `rasm_get_debug_view`, `rasm_set_culling_frozen`, `rasm_set_meshlet_path` / `rasm_get_meshlet_path`, and the sized `rasm_inspection` with `rasm_set_inspection` and `rasm_get_inspection` (`src/c/cDebug.cpp`); `Renderer::getDebugView` in C++. Examples: `20_views` (`--no-shadows`, `--msaa`), `22_c_api` (the main view with the sun and the point light's cube, the maps with one cascade; `--no-shadows`, `--bench`), `33_c_render_graph --debug-view normals`; image test `views_shadows`; `ctypes_smoke.py` draws two shadowed views and checks the debug calls. Logged: exports draw no view shadows (`D58`).
  - **PR 3, the UI (1.19).** Done 2026-11-28. `rasm_set_ui_callback(renderer, rasm_ui_callback, user_data)`: called each frame between `ImGui::NewFrame` and `ImGui::Render`, on the frame's thread, inside a `Recording` guard, so the calls a pass callback may not make are refused there too (`rasm_set_ui_callback` itself as well); `rasm_get_ui_texture` (`getUiTexture`). No ImGui wrapper is shipped: `rasm_get_imgui_context` (`Renderer::getUiContext`, new in C++), `rasm_get_imgui_allocator_functions` and `rasm_get_imgui_version` let a binding's own Dear ImGui (cimgui, ImGui.NET, imgui-rs) call its `SetAllocatorFunctions` and `SetCurrentContext` and draw into RASM's frame; `rasm_check_imgui_layout(version, io, style, vec2, vec4, drawVert, drawIdx)` compares `IMGUI_CHECKVERSION`'s sizes with RASM's (`findUiLayoutMismatch`) and returns an error naming the first difference instead of asserting. cimgui's headers are generated with `IMGUI_DISABLE_OBSOLETE_FUNCTIONS` (`ImGuiIO` 3000 bytes, 3032 with the obsolete fields), so RASM's Dear ImGui is now built with it too, through the overlay port `ports/imgui` (vcpkg's port at `VCPKG_COMMIT`, one change), and stock cimgui-based bindings match; C++ code that used ImGui's obsolete names must use the current ones. `createUi` replaces `IMGUI_CHECKVERSION` with the same check against the linked library (the distance from `GetIO` to `GetPlatformIO`), so an application linking an ImGui built otherwise gets an error and the UI off, not an assert. Example `33_c_render_graph` with `-DRASM_C_IMGUI_EXAMPLE=ON` (on in CI, which runs it headless on lavapipe): cimgui at its 1.92.6 commit, built against vcpkg's ImGui into a shared library of its own (`cmake/RasmCimgui.cmake`, never linked into RASM), draws a slider window from C; headless, a scripted click moves the vignette slider through RASM's input, and the run checks the title bar's pixels and the callback count. `ctypes_smoke.py` sets a Python UI callback and checks the version, the layout check and the refused calls; with `--cimgui` (passed by `check_install.py` when the build has it) Python draws a window through cimgui. Concept guide `docs/guides/library-copies.html` ("Two copies of one library", with a lab of the context's layout in two copies).

### Map engines
- [x] Large-world precision: double-precision transforms on the CPU, camera-relative rendering (subtract the camera origin on the CPU, float offsets on the GPU), and reversed-Z (from phase 1) (done 2026-11-25). The C++ part: `Transform::position`, `Light::position` and the trackball's `center` are `glm::dvec3`, and each view draws in its camera's render space. The GPU rows keep each position as a high and a low float (`InstanceData`, 160 B; `gfx::Light`, 68 B), and every view subtracts its own origin from them (`subtractSplit`, kept in order by an OR with a zero the compiler cannot know, since the NVIDIA driver regroups across `NoContraction`), so a moving camera rewrites no row: 1.34 ms per frame with 12 000 entities and a flying camera, as on `main`. Shadow cascades snap to the world's texel grid in doubles; motion keeps the last view-projection in world space and the last translation as a difference; frozen culling moves its planes with the origin. Reversed-Z was already done. Example `23_large_world` places its scene at Paris in Earth-centred coordinates (6370 km out) in a local east-up-south frame, and `--compare` checks it against the same scene at the origin (0.04% of the pixels differ, at shadow edges; 62.8% before); image tests `far_shadows`, `far_skinning`, `far_taa`. Guide `docs/guides/large-world-precision.html`. The C API (1.2): `rasm_dvec3`, `rasm_transform_d` and the `_d` calls for entities, cameras, lights and rigs, `position_d` and `track_ball_center_d` that add to the float fields, `rasm_to_render_position` and `rasm_to_world_position`; a 1.1 program keeps working. A local frame (`D42`): `SceneEnvironment::orientation` turns the sky and its light, and `CameraController::FreeFly::up` the free-fly camera, so `23_large_world` draws its sky level in the east-up-south frame at Paris and flies around the ellipsoid's normal (`--compare` still 0 pixels off at frame 120). A written limit: glTF node translations stay floats, in their mesh's space.
- [x] Tile streaming: asynchronous load and destroy of meshes and textures under a memory budget (builds on `D4`, phase 1.3). Load and destroy are done (2026-11-22: `D4`, `getPoolStats`, example `17_streaming`). Done 2026-11-25: `rasm::TileStreamer` (`rasm/tileStreamer.h`, in `rasm::renderer`) keeps a scene's tiles under a byte budget. The application owns its tree (`createTile` with a parent, a sphere in doubles, a geometric error, `TileRefine::REPLACE` or `ADD`) and walks it each frame with `getScreenError` (the largest over the views of `setViews`, `selectLod`'s rule); `update(cut)` wants the cut and its ancestors, ranks each tile by its parent's error at its own bounds, measures what tiles hold (textures: their allocation, `RenderContext::getTextureMemoryBytes`; meshes: their share of the geometry pools) and every fixed pool, drops unwanted tiles oldest first, then wanted ones of a lower rank, hands out the tiles to load (`getTilesToLoad`, `setTileContent`: the content is the streamer's from then on, from `createMesh` or an `AssetLoader`), cancels unwanted loads, and draws each wanted tile once ready or its nearest ready ancestor in its place, all within `maxLoadsPerFrame`, `maxLoadsInFlight` and `maxDropsPerFrame`. The automatic budget is 80% of the device-local budget (`VK_EXT_memory_budget`) left after everything else. The policy is plain data (`TileResidency`, `tests/tileResidencyTests.cpp`). Bindless slots are a field now, `RendererConfig::maxBindlessTextures` (16384 by default, lowered to the device's limit). C API 1.3: `rasm_tile_streamer_*`, `max_bindless_textures`; `22_c_api` streams its ground. Example `24_map_tiles`: a 32 km quadtree of terrain tiles (made on the example's server threads) and glTF landmarks (under empty `ADD` tiles), a camera that flies low, climbs to 6 km and dives, and a map view; it checks the budget every frame and that no wanted tile is a hole (48 MiB held over 1500 frames, `update` 0.04 ms on average, the longest frame 2.6 ms, Release, RTX 3060). Image test `tile_streaming`. Guide `docs/guides/tile-streaming.html`. Open: one drawn set per scene (`D43`), `createMesh`'s meshlets on the main thread (`P30`).
- [x] Vector rendering: anti-aliased wide lines, polygons, points and SDF text and labels. Terrain from heightmap tiles. (done 2026-11-25) *Partly done 2026-11-25 (1 of 3):* terrain from height map tiles. A tile is an entity with a `MaterialType::TERRAIN` material (`TerrainMaterial`: an `R16_UNORM` or `R32_SFLOAT` heights texture of (cells + 3)² samples with a border of one, `heightScale`, `heightOffset`, `minHeight`, `maxHeight`, `skirt`, `sphereRadius`) on the grid every tile of its size shares (`Renderer::getTerrainMesh`, no LODs, no meshlets), so no tile builds a mesh (`P30` no longer applies to terrain). `Renderer::createTerrainTile` makes both; `getTerrainTransform` stretches the grid's unit box to the tile's box, so culling sees the real bounds. The vertex stage of the main and shadow passes lifts each vertex (`shaders/lib/terrain.slang`), with a skirt under each edge for the cracks between levels, normals from central differences that match across edges, imagery as base color with a sub-rect, and a curvature of d² / 2R for tiles on a planet (`D44` for whole-globe roots). `sampleTerrainHeight` and `getTerrainPosition` give the drawn surface on the CPU, bit-equal on shared edges with a power-of-two scale. C API 1.4 (`rasm_create_terrain_tile`, ...). `24_map_tiles` streams terrain tiles of 32 × 32 cells (2.4 KiB of heights each, against 31 KiB for its 16 × 16-cell meshes before); 48 MiB over 1500 frames, `update` 0.03 ms on average, the longest frame 2.6 ms (Release, RTX 3060). Image tests `terrain`, `far_terrain`. Guide `docs/guides/terrain.html`. *Partly done 2026-11-25 (2 of 3):* lines, polygons and points. The builders (`rasm/vector.h`: `addVectorLines` with miter, bevel and round joins and butt, square and round caps, `addVectorPolygons` with holes through earcut, `addVectorPoints` with an optional icon atlas, `buildVectorMesh`) run on any thread and write anchors and offsets; a `MaterialType::VECTOR` material (`VectorMaterial`: color, width in pixels or metres, across the screen or in the ground's plane, dashes, an outline, `drawOrder`, tested or overlay) spreads them in the vertex stage, at least one pixel wide (thinner fades), smooths the edges by the distance to them, writes its own motion for TAA, and sorts in the Transparent pass by `drawOrder` first. Draped features are cut on a terrain tile's grid and lifted by `sampleTerrainHeight`'s rule. Culling pads each vector draw's sphere by its width in pixels at its distance, per view (frustum and Hi-Z), leaves vectors out of shadow maps and never occludes an overlay. `P30` is fixed: `buildMesh` on any thread and `createMesh(MeshBuild&&)`, which only uploads. C API 1.5. Example `25_vector_map` (a city's vector tiles on 3 server threads, two views; the longest frame 1.6 ms, Release, RTX 3060); `24_map_tiles` drapes roads and lakes on its terrain. Image tests `vectors`, `vectors_msaa4`, `vectors_taa`. Guide `docs/guides/vector-rendering.html`. *Done 2026-11-25 (3 of 3):* text and labels. A font is a signed distance field atlas (`FontAtlas`: one byte a texel, glyph metrics, kerning pairs), built from a TrueType/OpenType file by `AssetLoader::loadFont` / `buildFontAtlas` with stb_truetype (no new dependency) in `rasm::rasm`; `Renderer::createFont` takes any atlas with that contract, so a `rasm::renderer` program brings its own and MSDF needs only a shader change. `addVectorLabels` lays UTF-8 text out on any thread (codepoints, kerning, lines, `LabelAnchor`, an offset) into glyph quads, the halo's before the fill's; a `VECTOR` material with a `font` draws them across the screen from their world anchor, in pixels or metres, with a halo of its own color and width, unjittered and with the anchor's motion so MSAA and TAA keep them sharp, hidden by depth like points, and culled with a pad of `MAX_LABEL_REACH` ems. Each shaded view places its labels every frame on the CPU (`placeLabels`: priority, then last frame's winners, then a fixed order; a grid of 8 px cells; a 0.25 s fade; no heap allocation in a steady frame) and uploads an alpha per label slot. Labels are tile content like any mesh. C API 1.6. `25_vector_map` names its places and districts in both views (the longest frame still 1.6 ms, Release, RTX 3060). Image tests `labels`, `labels_msaa4`, `labels_taa`, `far_labels`. Guide `docs/guides/text-and-labels.html`. Open: `D45`, `D46` (shaping), `D47` (placement does not know depth), `B34` (fonts are trusted); `P31` stays open (labels add no pipeline).
- [x] Picking: an ID buffer pass with readback, giving the entity and the world position. (done 2026-11-25) `Renderer::pick(view, PickDesc)` (or the scene, camera and target of an application's graph) asks what a view drew under a rect of its pixels (`MAX_PICK_SIZE` 256 a side; `getViewPixel` turns a mouse position into one). The next `endFrame` culls the view's draw list with the rect's own frustum (`countMain` and `writeMain` with the view's unjittered SceneData) and draws the few draws that touch it with `rasm.slang`'s vertex stage and `pickMain` into two `R32G32B32A32_UINT` targets the size of the rect, the viewport shifted so the view's pixels land on them: one sample, no jitter, the view's LODs, terrain, skinning, morphs, vector widths and label alphas. `isPickReady` / `takePick` give, a couple of frames later and with no stall, a `PickHit` per entity sub-mesh and vector feature: its pixel count, its pixel nearest the centre, the world position in doubles (render space plus the view's origin: within 0.2 mm 6 000 km from the origin), the normal and flags (feature, label, overlay, terrain, back face). `PickDesc::minAlpha` (0.5) decides see-through surfaces and vector features; `PickDesc::skip` looks through meshes, see-through meshes, terrain, vectors, labels or overlays. Instance rows map to entities through a per-slot CPU table (`InstanceOwners`), so a row reused at once still names the destroyed entity (`Renderer::isAlive`). 0 ms while nobody picks; a 1 × 1 pick 0.15 ms in `05_city --pick` (145 000 entities), 0.03 ms in `26_picking` (RTX 3060, Release). C API 1.7 (`rasm_pick_view`, `rasm_take_pick`, ...). Example `26_picking` (hover, click and box picks in a TAA view and an MSAA map, scripted checks far from the origin, a destroyed entity's row reused); image tests `picking`, `picking_msaa4`, `picking_taa`, `far_picking`. Guide `docs/guides/picking.html`. Open: `D48` (bigger boxes), `D47` (labels, with a note on a probe pass), `P31` (three more pipelines on the first pick).

### Visualization tools
- [x] Point clouds and instanced glyphs, lines and grids, and orthographic views (already partly supported, done 2026-11-26). Five PRs, in this order: (1) orthographic views and the reference grid, (2) colormaps and point clouds, (2b) a compute rasterizer for small points, (3) point-cloud streaming and LAS/LAZ, (4) instanced glyphs and data lines. *Partly done 2026-11-25 (1 of 5):* orthographic views first-class and reference grids. The GPU side already handled orthographic cameras (LOD without a depth plane, Hi-Z, meshlet cones, cascades, light clusters, TAA, the sky, vector widths in pixels, tile errors, picks); the image tests `ortho` and `ortho_taa` now draw the picking scene through an orthographic box (shadows, Hi-Z, terrain, skinning, vectors and labels in pixels, a bounded grid) and check its picks. Controls: `CameraInput` has a pan drag (`panStart`, `panEnd`) and the `pointer`; `CameraInputState::buttons` (`CameraButtons`, `CameraDrag`) maps each mouse button and Shift + left to an orbit, a pan or nothing (left orbits, right, middle and Shift + left pan), `Renderer::setCameraButtons` the engine's; a trackball pans its center by the projection's size at it, the wheel scales its radius by `CAMERA_WHEEL_ZOOM` (0.9) a step (never under `MIN_TRACK_BALL_RADIUS`) or, through `updateCameraRig(rig, projection, input)`, an orthographic box at the pointer, which stays on the same point; `Renderer::updateCamera` passes the camera's projection. The trackball orbits from the drag's motion: `OrbitStyle::TURNTABLE` by default (yaw around `TrackBall::up`, pitch short of the poles, no roll, the same at the center and the edge) or `ARCBALL` (Holroyd's sphere and hyperbola, smooth past the rim); `InputEvent::dx`, `dy` carry the motion, and `Renderer::setMouseGrab` (`Platform::setMouseGrab`, SDL's relative mouse mode) lets a drag go on past the window's edge, by itself for the engine's camera input. Reference grids (`rasm/grid.h`, `Renderer::setCameraGrid`): per camera, so each viewport has its own plane; one triangle in the `Transparent` pass before the blend run, a ray per pixel to the plane with its depth tested, lines in pixels (Ben Golus' pristine grid), three levels of `cellSize` × `subdivisions`^k blended per pixel, colored axes, an extent, grazing and distance fades, and the camera's place on the plane split in doubles into whole cells modulo a power of `subdivisions` and a rest, so the lines are exact 6 000 km out (`gfx::GridData` in `SceneData`, 2224 B). C API 1.8 (`rasm_grid`, `rasm_camera_buttons`, `rasm_camera_rig_update_projection`, pan and pointer in `rasm_camera_input`); `22_c_api` gives its map a grid. Example `27_cad_views`: a part in a perspective view and top, front and side orthographic views, each with its grid, dimension lines and labels, left-button pan and zoom at the pointer, scripted checks (the zoom keeps the point under the pointer, picks in two orthographic views) and `--far` (0 pixels off against the origin). 0.22 ms for four grids at 1920 × 1080, three views with 4× MSAA (RTX 3060, Release). Image tests `grid`, `grid_ortho`, `grid_msaa4`, `grid_taa`, `far_grid`. Guides `docs/guides/reference-grid.html` and the pan and zoom section of `camera-controllers.html`. Open: `D49` (the zoom reads the stored box's aspect), a perspective zoom toward the point under the pointer (needs its depth: a pick), the grid is not pickable and has no out-of-plane axis. *Partly done 2026-11-25 (2 of 5):* colormaps and point clouds in GPU memory. Colormaps: `Renderer::createColormap(colors, count)` (1 to `COLORMAP_SIZE` linear colors, resampled) or `createColormap(ColormapPreset)` (viridis, turbo, magma, inferno, plasma, cividis from matplotlib's tables, gray) makes a 256 × 1 sRGB texture in a `LINEAR_CLAMP` slot; `ScalarRange` (min, max, log, clamp) in `rasm/colormap.h`. Points: `buildPointCloudChunk(PointCloudChunkDesc)` on any thread → `MeshBuild`, `createMesh` uploads it into the geometry pool's point stream (`RendererConfig::geometryPoolPoints`, 8 B units, made with the first chunk): a 48 B header, then 8 B a point (16-bit x, y, z in the chunk's box and a 16-bit scalar), 12 B with RGBA8 colors; the points in a Morton order read in bit-reversed steps, so every prefix is an even sample; `Mesh::pointOrder` (2 B a point on the CPU) turns a drawn index back into the desc's for `PickHit::feature` (`PICK_HIT_POINT`, `PICK_SKIP_POINTS`). Each chunk (up to `MAX_POINT_CHUNK_POINTS`, 65 536) is an entity with a `MaterialType::POINTS` material (`PointMaterial`: color, size in pixels or metres, `SQUARE` / `ROUND` / `SPHERE`, `COLOR` or `SCALAR` through a colormap and range, `density`), so culling, render space and picking come with it. A point run of its own in the draw list (`MAX_DRAW_RUNS` 7 → 8) with its own pipeline (`shaders/passes/points.slang`): **one triangle a point** (3 vertices from a shared index range 0, 1, 2, …, cut to the square or disc in the fragment stage, 12–16% faster than a 6-vertex quad), `SV_DepthLessEqual` for the sphere's depth (3% on every point), alpha-to-coverage under MSAA, the centre's motion under TAA. LOD by prefix: the cull pass's `selectPointCount` (the one place a chunk's count is chosen) keeps k = min(N, ⌈`density` × D² / a⌉) points, D the chunk's sphere on screen, a the point's area (π/4 of the square when round); `density` 2 by default: in the top view of 4 M points, density 0.5 leaves 6.5% of the ground empty, 1 leaves 0.3% (1.3% without the π/4), 2 none. Points cast no shadow; debug views draw them shaded. C API 1.10 (`rasm_build_point_cloud_chunk`, `rasm_create_colormap`, `rasm_point_material` in `rasm_material_desc`, `geometry_pool_points`). Example `28_point_cloud`: a synthetic LiDAR scan (hills, buildings, trees) 6 000 km from the origin, chunks of 32 m built on worker threads, colored by height through turbo, a perspective TAA view and an orthographic 4× MSAA top view, a scripted orbit and a pick check (the picked point 0.1 mm from the scan's). Measured (RTX 3060, Release, 1920 × 1080 in the two views): **1.07 ns per drawn point**, linear in points and nearly the same for 1 and 2 pixel points; 4 M points draw 3.76 M a frame in 3.99 ms (scene pass), 50 M points 3.6 M in 3.8 ms, every point of 10 M (17.0 M drawn) 18.2 ms, of 20 M (33.3 M) 36.7 ms, of 50 M (82.2 M) 101.5 ms. Image tests `points`, `points_msaa4`, `points_taa`, `points_ortho`, `far_points`. Guide `docs/guides/point-clouds.html`. *Partly done 2026-11-25 (3 of 5):* a compute rasterizer for small points (PR 2b, `P32`). The cull pass sends a chunk to it when its points are `POINT_RASTER_MAX_SIZE` (2) pixels or less at its nearest point and it draws at least `POINT_RASTER_MIN_DENSITY` (0.125) points per pixel of its rect on screen (`isRasterChunk`, `appendPointBatches`: batches of 1024 points, the rect grown with atomics); a thread per point writes the pixels its square covers with a 64-bit `InterlockedMax` of depth << 32 | instance row << 16 | point (Schütz et al. 2021) into a per-view buffer (`SceneView::pointRaster`: a 48 B header, the batches, 8 B a pixel), after the view's last cull; a resolve quad over the rect, before the sky in the last draw pass, writes each pixel's color, depth and motion, so meshes, labels, the grid and TAA compose with the points. Both paths take the same pixels (centre in the square, snapped to 1/256 pixel), so a chunk switches paths unseen; under MSAA small points cover whole pixels on both paths (`points_msaa4` golden updated: no more partly covered pixels showing the background). The resolve fills the LOD's single-pixel holes of thinned chunks from their 8 neighbours (at least 6 filled, depths within 5 %): the top view of `28_point_cloud` ends with no hole (main 0.001 %, 0.044 % without the fill), the perspective view with 0.025 % (main 0.027 %), for 0.025 ms; silhouettes and the data's own gaps stay. `shaderBufferInt64Atomics` is enabled where present (`RenderContext::hasBufferInt64Atomics`); `RendererConfig::computePoints` / `Renderer::setComputePoints` (C API 1.11) turn the path off. Picks stay on the triangles, which take the same pixels. Measured (RTX 3060, Release, two views at 1920 × 1080): 0.081 ns per point of 1 pixel against 0.86 by triangles (10.6×), 0.28 against 1.14 at 2 pixels (4.1×); every point of 20 M (33.5 M drawn, 1 pixel) 3.31 ms against 30.5 ms; 4 M at the default density 1.09 ms against 4.02 ms (GPU frame 1.63 against 4.53). Image tests `points_triangles`, `points_msaa4_triangles`, `points_taa_triangles`. Example `28_point_cloud --triangles`. The guide's new section "Small points by compute" and lab. *Partly done 2026-11-25 (4 of 5):* point cloud streaming (PR 3). `buildPointCloudOctree` (`rasm/pointCloudOctree.h`, any thread) builds Potree's octree of points in doubles: the points sorted by a 63-bit Morton code of their cube, each node the point nearest the centre of each cell of a 128³ grid over its cube (coarser past `maxNodePoints`, 16 384), its children the rest, a node with no more points left a leaf with them all; points stored as float offsets from the node's centre, the node's spacing measured from its points (`measurePointSpacing`: the cell size at which they take half as many cells as there are points) and never more than its parent's, `geometricError` its spacing (0 for a leaf), bounds nested, `indices` back to the desc. Each node is a `TileStreamer` tile with `TileRefine::ADD` and, when handed out, a chunk (`getPointCloudNodeChunk`, `buildPointCloudChunk` on a worker) on an entity at its cube's centre; the streamer counts a chunk's point pool units in its bytes and the pool as a unit of its own (`TileUnit::POINTS`, `PoolStats::points`). No popping: `PointChunkLod` (`Renderer::setPointChunkLod`, a word in the chunk's instance row) fades a chunk in and out by its prefix (`drawn`) and, per octant, shrinks an adaptive parent's points back as a finer chunk fills in (`finer`); frames where nodes come in or go change no more pixels than frames where none do. Adaptive size (`PointSizeMode::ADAPTIVE`, `PointMaterial::maxSize`, the chunk's spacing in its header): a point grows from where its chunk stops covering the ground `density` times at its size, √(4 / density) times faster, so near the camera a sparse sample closes and far chunks keep their size and the compute path, which sizes points with the same `getPointDiameter`. `AssetLoader::loadPointCloud` reads LAS 1.0 to 1.4, point formats 0 to 10, with RASM's own reader (scale and offset to doubles, colors, a chosen scalar, the WKT, `zUpToYUp`) and LAZ through LASzip (vcpkg's `laszip` 3.5 is Apache-2.0; `cmake/Findlaszip.cmake`, a `find_dependency` in `rasmConfig.cmake.in`). C API 1.12. Example `29_point_streaming`: a synthetic LiDAR tile of 8 M points (1 km near Paris, ECEF) written as LAS at its first start, read at 48 M points/s, its octree (1739 nodes) built at 6.3 M points/s, streamed under 48 of its 92 MiB in a flight at 14 m/s with a perspective TAA view and an orthographic 4× MSAA one: the budget held (peak 48.00 MiB), 1219 loads and 462 drops in 1425 frames, the cut and update 0.11 ms a frame, a pick 0.2 mm from the file's point; 5.8 ms of GPU frame at 1920 × 1080 with adaptive points and `density` 3 (3.3 with fixed points, which leave the ground open; `P33`). Found and fixed on the way: a view's point raster buffer was made again at each new chunk count, 40 to 90 ms stalls (`P34`). `28_point_cloud --adaptive`. Image test `points_adaptive`. Guide `docs/guides/point-octree.html` with two labs. Open: the octree is built in memory (`D51`), adaptive points near the camera leave the compute path (`P33`). *Done 2026-11-26 (5 of 5):* instanced glyphs and data lines (PR 4). Glyph chunks: `buildGlyphChunk` (`rasm/glyphs.h`, any thread) puts up to `MAX_GLYPH_CHUNK_GLYPHS` (65 536) glyphs in the point pool, 16 B a glyph (a float position from the entity's double origin, and an RGBA8 color or a scalar), 8 B more with orientations (four snorm16) and 8 B more with scales (half floats); `GlyphChunkDesc::shape` names the mesh drawn per glyph (its first sub-mesh, with its LODs), and `buildGlyphShape` makes an arrow, a sphere or a cube with LODs of its own (16, 8, 4 segments; an arrow's last without caps), as `buildMesh` builds none under 1024 triangles. A chunk is an entity with a `MaterialType::GLYPHS` material (`GlyphMaterial`: its own colors, or its scalars through a colormap and a `ScalarRange`; shaded as PBR), whose row rides in the point run: no new draw run, `SceneData` keeps its offsets (`gfx::GlyphCullHeader` and the glyph pointers at its end, 2368 B). The cull keeps a chunk in view (`appendGlyphChunk`), then a compute pass after the view's last cull (`shaders/passes/glyphCull.slang`) tests each glyph against the frustum and the Hi-Z, picks its shape's LOD by its size on screen, takes its place per LOD with groupshared counts and one atomic per LOD and group, and writes the visible ones into a compacted list with a draw command per chunk and LOD; the last draw pass draws them all with one `drawIndexedIndirectCount` (`rasm.slang` with `RASM_GLYPHS`, `getInstanceIndex`). Picks cull the glyphs again into the pick's own buffer: `PICK_HIT_GLYPH`, the feature is the glyph's index in the desc (`PICK_SKIP_GLYPHS`). `FrameStats::glyphs`, `glyphsVisible`; GPU timers `Glyph Cull`, `Glyphs`. Data lines: `addVectorLines(..., featureIds, colors, scalars)` gives each point a color or a scalar (`VectorGeometry::colors`); `VectorMaterial::colorMode` `SCALAR` maps the interpolated scalar per pixel through `colormap` and `range`. C API 1.14. Example `30_glyphs`: the ABC flow in a box 240 m wide, 6 000 km from the origin, 295 K arrows (jittered in their cells, sized and colored by speed through viridis) and 768 streamlines colored by speed through plasma, a perspective TAA view and an orthographic 4× MSAA view, a scripted orbit and zoom and a pick check (the hit lies on the picked arrow); `--glyphs N`, `--shape`, `--wall`. Measured (RTX 3060, Release, 1920 × 1080): 0.59 M glyphs tested and 0.26 M drawn a frame, the cull 0.20 ms (0.33 ns a glyph), the draw 4.7 ms (18 ns a glyph drawn; 11.4 ms without shape LODs), 2.36 M arrows 15.9 ms and 5.24 M 31 ms; the Hi-Z test is free and behind a wall drops 7 % more glyphs; 05, 20, 26, 28 and 29 keep their frame times. Image tests `glyphs`, `glyphs_msaa4`, `glyphs_taa`, `glyphs_ortho`, `far_glyphs`. Guide `docs/guides/instanced-glyphs.html` with two labs. Open: glyphs cast no shadow and debug views draw them shaded (`D52`), a draped band takes no per-point values (`D53`).
  - **PR 2b, a compute rasterizer for small points.** Done, see above. Not done: points cast no shadow and debug views draw them shaded (`D50`); a view drawn by triangles only (no 64-bit atomics) keeps the small triangles under MSAA, which miss a few edge samples (0.7 % of `points_msaa4`), and has no hole fill (0.04 % of the top view's pixels).
  - **PR 3, point-cloud streaming.** Done, see above. The design: a Potree-style octree whose nodes are `TileStreamer` tiles with `TileRefine::ADD` (each node a subsample, its children add detail), each node a chunk of PR 2 (`buildPointCloudChunk`, up to 65 536 points, an entity placed in doubles, so its prefix LOD still thins a node within its level; chunks of about 32 m worked well in `28_point_cloud`), built on any thread (`buildPointCloudOctree`) from points in doubles, under the streamer's byte budget, so a dataset bigger than GPU memory streams. Files in `rasm::rasm`: `AssetLoader::loadPointCloud` reads LAS with a parser of RASM's own (the header, the point formats 0 to 10, the scale and offset to doubles, ECEF or projected coordinates). LAZ needs a decoder: check the licence of vcpkg's `laszip` port first. LASzip was LGPL for a long time; take it only if the port is Apache-2.0 (or another licence that allows static linking into a closed application), with a `find_dependency` line in `cmake/rasmConfig.cmake.in`; if it is LGPL, read plain LAS and leave LAZ out or optional. Learned in PR 2: a node's bytes are 8 B a point (12 with colors) in the point pool plus 2 B a point of `Mesh::pointOrder` on the CPU (drop it, or keep it only for picks, when the streamer counts memory); the point pool is one fixed range allocator (`RendererConfig::geometryPoolPoints`), so the streamer's budget must stay under it; and the chunks' draw cost is per drawn point, so the octree's screen-space error should be tuned with `PointMaterial::density`. Example: a LiDAR tile in ECEF bigger than the budget, flown through.
  - **PR 4, instanced glyphs and data lines.** Done, see above. Not done: glyph shadows and debug views (`D52`); per-glyph motion (a glyph's data is built once, so a chunk moves only with its entity: particles that move rebuild their chunks); the draw is bound by its vertices and draws a dense volume with overdraw, in no front-to-back order. Then the next items: weighted-blended order-independent transparency for dense data (done, below), offscreen export at any resolution, and the rest of the C++ API in C.
- [x] Order-independent transparency (weighted blended) for dense data (done 2026-11-26). A `BLEND` material picks how it goes over what is behind it with `Material::blendMethod` (C: `rasm_material_desc::blend_method`, 1.15): `BlendMethod::SORTED` (the default, back to front by draw), `WEIGHTED` (McGuire and Bavoil's weighted blended order-independent transparency: exact coverage, a weighted mean color, no order and no popping) or `ADDITIVE` (light added in any order, for density and X-ray views). A `GLYPHS` material with `BLEND` is always weighted, a `VECTOR` one sorted. The weighted surfaces go into a weighted target per view (sums RGBA16F, coverage RG16F, motion RG16F with TAA), made the first frame the view has them, at the end of its last draw pass, and a composite lays their mean over the scene after the grid, before the additive and the sorted draws, so labels and UI stay on top. The weight halves every fifth of the place of a fragment between the nearest and the farthest weighted draw in view (log of the depth with perspective, the depth orthographic), measured by the cull each frame and kept steady with snapped steps, hysteresis and a 0.25 s time constant, so it works at any scale and the colors do not jump when a draw enters or leaves the view. MSAA composites per sample (sample-rate shading), TAA gets the weighted mean motion, picks hit the nearest surface whose alpha passes `minAlpha`. Example `31_oit` (nested iso-surfaces, 48 volume slices in one mesh, a see-through assembly, see-through arrows; `--sorted`, `--additive`, `--range-test`); guide `docs/guides/weighted-oit.html`. Not done: see-through point clouds (`D54`); the weighted draws break the last draw pass in two (`P36`, free on desktop GPUs).
- [x] Screenshot and offscreen export at arbitrary resolution (done 2026-11-27). `Renderer::exportView(view, ExportDesc)` (`rasm/export.h`; C: `rasm_export_view`, 1.16) draws a still of a view at any size, past the device's largest image (an 8K, a 16K, a 40 000-pixel poster), in tiles with an off-center projection (`getExportTileClip`), one jittered sample a frame in the frames of `render(...)`, and writes it as it goes: PNG 8 or 16 bits (sRGB, straight alpha) or EXR half or float (linear, premultiplied, ZIP), streamed a row of tiles at a time on a writer thread (zlib), or kept in memory for `takeExport`; `getExportProgress` never waits. No seams: a guard band of 64 pixels (384 with bloom, its reach) on 64-aligned tiles, labels placed once on the whole image and their visibility from a survey frame per tile, the weighted span the survey's union, LODs from the whole image's camera, the camera copied, a `TileStreamer` of the scene frozen from the survey on, sky and grid rays through the window. 16 samples (a 4 x 4 grid) replace TAA, MSAA off unless `ExportDesc::msaa`; `pixelScale` scales every pixel size and the LOD error; `toneMap` false gives scene-linear HDR; `transparent` drops the sky. `32_export` checks tiles against one tile (0.02 % of the pixels differ, the off-center matrix's rounding) at 3072 x 1728, far away (6 000 km) and orthographic too; `24_map_tiles --export-check` while streaming; image tests `export_*`. Not done: bloom that scales with `pixelScale` (`D55`), exports in an application's own graph and several samples a frame (`D56`); found on the way: `B39` (fixed 2026-11-27).

### Indie games
- [ ] Scene serialization and an asset cooking step (pre-processed geometry, KTX2 textures, compiled shaders).
- [ ] Animation playback API, particles (GPU compute), decals.

## Phase 6: Additional backends

Prerequisites: phase 1.2 (RHI), the `D12` shader binding abstraction, and image tests from phase 4 that compare every backend against Vulkan.

1. **Metal** (native, Metal 3: argument buffers, GPU addresses, ICBs). macOS is already a target, and this replaces the MoltenVK dependency and its feature gaps.
2. **D3D12**: SM 6.6 `ResourceDescriptorHeap` bindless, `ExecuteIndirect`, enhanced barriers. Slang → DXIL.
3. **WebGPU** (Dawn or wgpu-native, plus Emscripten for the browser): Tier B. Bind-group materials, per-draw indirect, uniform-buffer constants, Slang → WGSL. Expect the most backend-specific work here. Every other backend gets bindless and BDA, and WebGPU does not.

For each backend: device and swapchain bring-up first, then the unit and image tests, then the examples in order.

---

## Original plan, mapped

| Original item | Where it lives now |
|---|---|
| 1. Simplify the low-level API | Phase 1.1–1.2 (public/private split, RHI, typed descriptors), phase 3 (graph-driven passes) |
| 2. Example-driven development | Guiding principle 1, and every phase's exit criteria |
| 3. GPU resource management (MDI, bindless, mega buffers, uber shader) | Done for the basics. Continued in phase 2 (GPU scene tables, instancing) and phase 4 (material system on the uber shader) |
| 4. Custom CPU allocators | Phase 1.3, done: measured not needed (`P27`); the hot spot, big frees of loads, moved to workers (`P26`) |
| 5. Move to C / no STL | Phase 5: a C ABI facade instead of a rewrite (see the rationale there) |
| 6. More examples and custom passes | Every phase. Phase 3 makes custom passes practical |
| 7. GPU frustum culling | Phase 2 |
| 8. Engine statistics | Phase 0 (Tracy), phase 2 (stats overlay) |
| 9. GUI | Phase 4: Dear ImGui from vcpkg behind `RASM_IMGUI` and `EngineConfig::ui` (done), with debug views (done, with the buffer inspector) |
| 10. Open-source release | After phase 1: install/export, CI, docs, examples. Alpha after phase 2 |
| 11. Metal, D3D12, WebGPU backends | Phase 6, with groundwork in phase 1.2 and `D12` |
