Engine tour

The big picture

RASM is a stack of a few layers. The application talks to one class, Renderer (or Engine, a Renderer that also opens its window), and gets small handles back. Under it, RenderContext turns handles into GPU objects, and rhi::Device hides the graphics API. Vulkan is the only backend today.

This is the first stop of a three-page tour of the engine. It shows the parts and how they fit together. Each idea behind a part (handles, bindless, culling, ...) has its own guide, linked where it comes up.

CPU work GPU work GPU buffer / memory

In short

  • Layers: application → Renderer → RenderContext → rhi::Device → VulkanDevice → GPU. Engine is a Renderer that also opens its window with SDL.
  • Applications include only include/rasm/. Everything in src/ is private.
  • Every object is a handle: Handle with an index and a generation. Each table has a HandlePool, which reuses freed indices with a new generation.
  • CPU objects (entities, meshes, materials, cameras, lights, scenes) live in Renderer's registry. GPU objects (buffers, textures, pipelines, ...) live in RenderContext's tables.
  • Shaders, pipelines and descriptor set layouts are deduplicated by their descriptor. Buffers and textures are always new.

1The layers

Each layer only talks to the one under it. The arrows show what crosses each boundary: handles at the top, rhi:: pointers in the middle, native Vulkan calls at the bottom.

Application examples/NN_name/main.cpp handles Renderer (or Engine) rasm/renderer.h handles RenderContext rasm/render/renderContext.h rhi:: pointers rhi::Device src/rhi/device.h virtual calls VulkanDevice src/rhi/vulkan/ Vulkan calls GPU RenderGraph passes, barriers own graph Creates objects and gets handles back. Calls render(), or runs its own render graph. C API (rasm/rasm_c.h, src/c/): C, Python, C#, Rust CPU objects in its registry, the frame loop, asset loads, the GPU scene tables, scene passes. Handle → rhi object tables, dedup caches, the layout of each texture, render targets, bindless. Backend-neutral interface: resources, command buffers, the queues, the swapchain, fences. Vulkan through volk, vk-bootstrap and VMA. Also VulkanCommandBuffer, Queue, Swapchain. Runs what the queues submitted.
Every frame that draws the scene runs a render graph: render() runs one that Renderer keeps (ViewGraph), or the application builds its own and adds the scene with addScenePasses and the tone map with addToneMapPass. The graph calls Renderer for the frame and the passes, records the barriers between them, and gives each pass the RenderContext to record with. See Render graphs. Why there is an rhi::Device layer at all is in Graphics APIs and the RHI.

Not every call goes all the way down. Follow three calls and see where each one stops.

engine layer (CPU) GPU the layer the call is in the way back
Pick a call and press "Next step" until it returns. createEntity stops at Renderer. createBuffer goes down to VulkanDevice and comes back with a handle. Only render reaches the GPU, and only when the frame is submitted.
LayerKnowsDoes not know
Rendererscenes, entities, meshes, materials, cameras, lights; the frame loop; its windows, through a Platformany Vulkan type; SDL (only Engine passes the SDL platform)
RenderContexthandles and the rhi:: object behind each one; the layout each texture is in (TextureStates); the bindless setscenes, entities, the frame loop, the Renderer
rhi::Deviceneutral resources, command buffers, the graphics queue and an optional compute queue, the swapchainhandles, which backend is under it
VulkanDeviceVkDevice and its function table (volk), VMA, vk-bootstraphandles, the engine

Engine or Renderer: pick your pieces

An application that owns its window, its event loop or its data (an editor, a map viewer, a server that renders images) creates a Renderer. An application that wants everything made for it creates an Engine. The arrows go one way: nothing points back up.

Engine final: picks the platform, overrides nothing your program its window, its loop, its meshes AssetLoader files on workers: glTF, OBJ, KTX2, HDR Renderer scene objects, GPU scene, frame, UI, swapchains owns is a creates one and a loader, if it reads files loads Platform SDL from Engine; native or headless RenderContext made from a RenderContextDesc rhi::Device Vulkan today windows, events GPU objects The arrows go down only: the Renderer knows no AssetLoader and no Engine, RenderContext no Renderer.
Engine is a Renderer that passes the SDL platform when EngineConfig::platform is SDL (with NATIVE or HEADLESS it does what a Renderer does) and owns an AssetLoader. A Renderer alone takes the native platform (RendererConfig::nativeWindow) or the headless one. The renderer finishes a loader's loads at the start of each frame through LoadHooks, an interface of its own, so it links no loader: rasm::renderer is one library, rasm::rasm (Engine, SDL, AssetLoader) another. The renderer must outlive its loader. Renderer has no virtual function but its destructor, so a frame makes no virtual call for this split. Scenes, entities and the other scene objects stay the Renderer's: the GPU tables mirror them row by row.
You wantCreateExample
a window, input and file loading made for youEngine with PlatformType::SDL (link rasm::rasm)examples/00_hello_scene
to draw into your own window, with your event loop, and load filesRenderer with RendererConfig::nativeWindow, and an AssetLoader (link rasm::rasm)examples/19_embedding
images only, from your own data (a server, thumbnails, tests)Renderer with no nativeWindow (link only rasm::renderer: no SDL3, no file libraries)examples/21_renderer
RASM from C, or from Python, C#, Rust or Zigthe C API, rasm/rasm_c.h: the shared library rasm_c (rasm::c), or rasm_c_renderer for the renderer alone (C API, A stable C ABI)examples/22_c_api; a frame of your own from C: examples/33_c_render_graph

The renderer's work is split over many .cpp files of Renderer methods; the loader's is AssetLoader::Impl (src/assets/assetLoader.cpp and the *Load.cpp files), and Engine's is src/engine.cpp. The next section shows which folder holds which part.

2The source folders

The map shows the four groups of folders. The table under it lists the main files of each.

public · what applications include include/rasm/ Renderer, Engine, handles include/rasm/render/ the low-level API private · src/ src/core/ handle manager, file reading src/platform/ window and input (SDL3, native, headless) src/assets/ mesh, texture, material loading src/scene/ entities, cameras, lights src/renderer/ GPU scene tables, passes, graph src/rhi/ RenderContext, rhi::Device src/rhi/vulkan/ the Vulkan backend src/c/ the C API's shared libraries shaders · compiled at run time shaders/lib/ Slang modules shaders/passes/ pass entry points programs that use the library examples/ one program per feature tests/ rasm_tests: CPU code, no GPU includes the tests only: src/ is on their include path too
Applications, the examples among them, see only the public group. Section 3 shows how the public headers hide the private ones.
FolderHoldsMain files
include/rasm/the public API: Renderer, Engine, handles, plain typesrasm.h, renderer.h, engine.h, handle.h, types.h
include/rasm/render/the low-level public APIrenderContext.h, renderGraph.h, resource.h
src/core/handle manager, file readinghandle.cpp, utils.cpp
src/platform/The window and its input (SDL3, the application's window, or none when headless), the input events, pathsplatform.h, sdlPlatform.cpp, nativePlatform.cpp, headlessPlatform.cpp, input.cpp, paths.cpp
src/assets/mesh, texture and material loading, glTF and OBJ import, mesh LODsmesh.cpp, meshImport.cpp, meshLod.cpp, texture.cpp, material.cpp
src/scene/scenes, entities, cameras, lights, transformsscene.cpp, entity.cpp, camera.cpp
src/renderer/GPU scene tables, the scene passes, the tone-map pass, the graph behind render, frame stats, overlay, render graph, shader compiler, GPU structsgpuScene.cpp, viewGraph.cpp, gpuTable.cpp, geometryPool.cpp, shaderCompiler.cpp
src/rhi/RenderContext, the rhi::Device interface, uploads, texture layoutsrenderContext.cpp, device.h, uploadManager.cpp, textureStates.cpp
src/rhi/vulkan/the Vulkan backendvulkanDevice.cpp, vulkanCommandBuffer.cpp, vulkanSwapchain.cpp, vulkanQueue.cpp
src/c/the C API (include/rasm/rasm_c.h): thin functions over Renderer, Engine and AssetLoader, built into the shared libraries rasm_c and rasm_c_renderercApi.cpp, cRenderer.cpp, cScene.cpp, cLoader.cpp
shaders/lib/, shaders/passes/Slang modules and pass entry points, compiled at run timecore.slang, rasm.slang, cull.slang, hiz.slang
examples/one program per feature (section 7)examples/05_city/main.cpp, examples/CMakeLists.txt
tests/rasm_tests: doctest unit tests of CPU code, no GPU; rasm_c_tests and the C header checks, which use the C API's shared librarieshandleTests.cpp, renderGraphTests.cpp, textureStatesTests.cpp

src/thirdparty_impl.cpp is the only file that defines the *_IMPLEMENTATION macros of the single-header libraries.

3Public and private headers

Application #include "rasm/rasm.h" includes not on its include path (src/ is PRIVATE) include/rasm/ · public src/ · private engine.h std::unique_ptr<GpuScene> gpuScene; render/renderContext.h struct Impl; unique_ptr<Impl> impl; renderer/gpuScene.h struct GpuScene { ... }; rhi/renderContext.cpp struct RenderContext::Impl device, object tables, caches defined in defined in
A public header names a private type only by a forward declaration, and holds it through a pointer. So applications compile against include/rasm/ and glm only, and never see Vulkan, VMA, Slang or SDL.

Renderer holds GeometryPool, ShaderCompiler, Platform, GpuScene, FrameStatsCollector and StatsOverlay this way. RenderContext keeps its rhi::Device and all its tables in RenderContext::Impl. Private code includes private headers relative to src/, for example "rhi/vulkan/vulkanDevice.h".

The tests are the exception

rasm_tests links rasm::rasm like an application, but it also has src/ on its include path, to test private classes against a fake rhi::Device.

4Handles and the two kinds of owner

The application never holds a pointer. It holds a handle: Handle, an index and a generation. A default handle has generation == 0 and is invalid (isValid). Its tag makes each handle its own C++ type, so a MeshHandle cannot go where a TextureHandle is expected. Why handles, and what the generation is for, is in Generational handles. This section shows who owns what in RASM.

HandlePool (one per table) Handle{index, generation} indices from 1, freed ones reused, generation + 1 entityHandles buffers.handles Renderer::registry · CPU objects registry.entities[handle.index] [0] unused [1] Entity [2] Entity [3] Entity … The same for materials, cameras, meshes, lights, scenes. A capped pool hands out at most MAX_* − 1 live indices. loadedMeshes, loadedTextures: path → handle cache every lookup compares the generation first RenderContext::Impl · GPU objects vector<rhi::Xxx*>[handle.index] buffers VulkanBuffer* textures VulkanTexture* pipelines VulkanPipeline* + shaders, commandBuffers, fences, queryPools, ... a texture also keeps its bindless slot
A lookup is one compare and one array access, with no hash (P4). The table values are typed as rhi:: pointers; the objects behind them are the backend's derived structs (see Graphics APIs and the RHI).

The two owners create an object in a different order:

CPU object: createEntity

  1. Take a handle. registry.entityHandles.allocate() gives {3, 1}, or index 0 when MAX_ENTITIES − 1 are alive: then warn and return an invalid handle.
  2. Store the object. registry.entities grows to the pool's size, then entities[3] = the new Entity.
  3. Queue its rows. With a mesh: queueInstanceRows, so the GPU scene gives it rows later.

GPU object: createBuffer

  1. Make the object first. device->createBuffer(desc) returns an rhi::Buffer pointer, or null on failure (then an invalid handle).
  2. Take a handle. buffers.handles.allocate() gives {5, 1}.
  3. Store the pointer. buffers.objects[5] = that pointer.
  4. Look it up later. Every later call checks the generation, and logs an error for a destroyed or unknown handle.
OwnerTypeLimitWhere the limit is
Renderer registryEntityMAX_ENTITIES = 262144 (262143 usable)rasm/entity.h
Meshno count limit; its sub-meshes stop at EngineConfig::geometryPoolSubMeshes = 16384 rows, its data at the other pool sizesrasm/types.h
MaterialEngineConfig::maxMaterials = 4096 alive at oncerasm/types.h
CameraMAX_CAMERAS = 32 (31 usable)rasm/engine.h
LightEngineConfig::maxLights = 16384rasm/types.h
SceneMAX_SCENES = 16 (15 usable)rasm/scene.h
RenderContext tablesbuffers, textures, ...no count limit; bindless slots stop at RendererConfig::maxBindlessTextures (16384 by default, at most MAX_BINDLESS_TEXTURES and the device's limit)rasm/types.h

Indices start at 1, so slot 0 is never used. That is why 31 cameras are alive at most with MAX_CAMERAS = 32. The limits count objects alive at once: a destroyed object gives its index back.

Lifetime

Every object can be destroyed, and indices are reused (deferred destruction). A file that loadMesh can't parse keeps its index until destroyMesh.

5Descriptors and creation dedup

Each GPU resource has its own creation descriptor in rasm/render/resource.h: BufferDesc, TextureDesc, ShaderDesc, PipelineDesc, RenderTargetDesc, BindlessDescriptorSetLayoutDesc, DescriptorPoolDesc. Each has a name, default values for every field, and a defaulted operator==. You fill them with designated initializers.

createShader(desc) also pipeline, layout look up desc shaderDescCache equal return cached handle new device->createShader new handle, stored in the cache createBuffer(desc) device->createBuffer always a new handle
The cache key is the whole descriptor. Equality is the defaulted operator==, so it covers every field, including the name and the SPIR-V bytes. Buffers, textures, descriptor pools and descriptor sets have no cache: they are mutable, so two equal descs must stay two objects (B1).
createShader(desc) createShader(desc) one shader both get {4, 1}

The same shader descriptor, twice

One object. The second call returns the cached handle.

createBuffer(desc) createBuffer(desc) buffer {5, 1} buffer {6, 1}

The same buffer descriptor, twice

Two objects, two handles. Each caller writes its own data.

CallDeduplicated?Cache and hash
createShaderyesshaderDescCache, ShaderDescHash
createPipelineyes (graphics and compute)pipelineDescCache, PipelineDescHash
createBindlessDescriptorSetLayoutyesdescriptorSetLayoutDescCache, BindlessDescriptorSetLayoutDescHash
createBuffer, createTexturenocache at the asset level: loadTexture caches by path and format
createDescriptorPool, allocateDescriptorSetno—
createRenderTargetnomakes up to 4 color textures and a depth texture, one set per frame slot with history

The hashes live in src/rhi/resource.cpp. They fold the fields with hashCombine from rasm/handle.h, which depends on the order of the fields. HandleHash uses it too.

6How the user objects relate

Scene entities[] cameras[] lights[] Entity mesh material transform Camera projection, controller Light directional or point Mesh subMeshes[] Material textures[6] params[10] SubMesh geometry transform material Geometry pool vertex + index range Texture GPU image, bindless slot
Blue objects live in Renderer's registry. Amber ones are GPU memory: the textures live in RenderContext, and the geometry in the engine-wide geometry pool. The dashed arrow: a sub-mesh's own material wins over the entity's.
ObjectHoldsShared?
Scenelists of EntityHandle, CameraHandle, LightHandlean entity can be in several scenes
Entitya MeshHandle, a MaterialHandle, a Transform—
Meshstate (LOADING, READY, FAILED) and SubMeshesmany entities can use one mesh
SubMesha MeshGeometry range in the pool, the glTF node transform, a material—
MaterialMaterialType, texture handles per PbrSlot, params indexed by PbrParam, doubleSidedmany entities and sub-meshes
CameraCameraProjection, CameraController, current and target Transforma camera can be in several scenes
LightLightType, color, position, direction, intensity, rangea light can be in several scenes

An entity without a valid material, or a sub-mesh without one, draws with the default material: getMaterial resolves an invalid handle to it. On the GPU each entity becomes one instance row per sub-mesh, and a material becomes one row that names its textures by bindless slot. The GPU scene tables (stop 3) show how these objects reach the GPU. Streaming assets in the background shows how meshes and textures load, and Mesh simplification how a mesh gets its LODs.

7Follow the examples

Each example puts a few parts of the engine to work. The pictures show what each one draws. The table lists the engine parts it uses and the pages to read next to its main.cpp.

00_hello_scene

Three bunnies from one OBJ mesh and one texture, three lights.

01_render_graph

The scene into a render target, a fading trail from last frame's image, a pass with two color outputs, then the swapchain. Two of the targets share memory.

02_gltf

Three glTF models with their PBR materials.

03_instances

10 000 cubes. A few spin, new ones appear, one material pulses. Culling runs on the compute queue.

compute pass 4096 particles

04_compute

A compute pass moves 4096 particles in a buffer that a draw then reads.

05_city

A night city of about 146 000 instances. 5000 cars move every frame.

06_shadows

A bunny, pillars and a spinning cube with cascaded shadows from the sun, then a vignette pass and the tone map. No barrier in the example.

07_lights

A weak moon, a spot lamp and a point lantern, each with its own shadow, read by one view: cascades, a perspective map and a cube map.

ExampleParts it usesRead
00_hello_sceneloadMesh, loadTexture, createEntity, renderstop 2, stop 3, GPU-driven rendering
01_render_graphRenderGraph, createRenderTarget, addScenePasses, createPipelineRender graphs, Transient memory, History buffers, Multiple render targets
02_gltfloadGLTF, sub-meshes, material rowsStreaming assets, PBR, Bindless
03_instancescreateMesh, updateTransform, updateMaterial, EngineConfig::asyncComputestop 3, GPU memory and uploads, Async compute
04_computeaddComputePass, createComputePipelineBuffer device addresses, GPU synchronization
05_cityculling, Hi-Z, LODs, fillTextureFrustum and occlusion culling, LOD selection
06_shadowsaddShadowPasses with ShadowDesc, addScenePasses with the SceneShadow, readDepth on depth-only targets, addToneMapPassShadow mapping, Render graphs, Tone mapping
07_lightsLightType::SPOT, addShadowPasses for directional, spot and point lights, addScenePasses with three shadowsSpot and point light shadows, PBR
11_many_lights1024 moving point and spot lights (updateLight), EngineConfig::clusteredLighting, FrameStatsClustered lighting
23_large_worlddouble Transform and Light positions 6370 km from the origin, in a local east-up-south frame, with the sky turned into it (SceneEnvironment::orientation) and a free-fly camera around the local up (FreeFly::up); --compare checks it against the same scene at the originLarge worlds, Cascaded shadows, TAA
24_map_tilesTileStreamer: a 32 km quadtree of terrain tiles and glTF landmarks under a 48 MiB budget, parents in place of children on their way, a map viewTile streaming, LOD selection, Many views

Every example sets enableValidation, assetRoot and shaderDir, so it runs from any folder and picks up shader edits at its next start. A new one is added with rasm_add_example in examples/CMakeLists.txt.

8Where it lives in code

WhatWhere
Handles, HandlePoolinclude/rasm/handle.h, src/core/handle.cpp
The registryRenderer::Registry in include/rasm/engine.h
Create CPU objectssrc/scene/scene.cpp, src/scene/entity.cpp, src/scene/camera.cpp, src/scene/light.cpp, src/assets/mesh.cpp, src/assets/material.cpp
Handle → GPU object tablesRenderContext::Impl in src/rhi/renderContext.cpp
Descriptorsinclude/rasm/render/resource.h
Dedup hashessrc/rhi/resource.cpp
Texture layoutsTextureStates in src/rhi/textureStates.cpp, used by RenderContext::transitionImageLayout
Pick the backendrhi::createDevice in src/rhi/device.cpp
Source listtarget_sources(rasm ...) in src/CMakeLists.txt: .cpp files; every header in include/ is found by a glob and installed
Examplesone folder each, such as examples/05_city/main.cpp, listed with rasm_add_example in examples/CMakeLists.txt

9Rules when you change it

Keep these true
  • A public header never includes a private header or a backend or third-party header (except glm). Forward-declare, or use a private Impl.
  • A new field in ShaderDesc, PipelineDesc or BindlessDescriptorSetLayoutDesc must also be folded into its hash in src/rhi/resource.cpp.
  • createBuffer and createTexture always make a new resource. Cache at the asset level if you want sharing, and destroy what you replace.
  • A new part gets its own .h/.cpp pair in its layer's folder, and its .cpp goes into target_sources(rasm ...) in src/CMakeLists.txt. A header in include/rasm/ needs no list entry: it is found and installed by itself.
  • A new dependency linked to rasm also needs a find_dependency line in cmake/rasmConfig.cmake.in, because rasm is a static library.
  • No templates in RASM code. Handle in rasm/handle.h is the only exception.