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.
In short
- Layers: application →
Renderer→RenderContext→rhi::Device→VulkanDevice→ GPU.Engineis aRendererthat also opens its window with SDL. - Applications include only
include/rasm/. Everything insrc/is private. - Every object is a handle:
Handlewith anindexand ageneration. Each table has aHandlePool, 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 inRenderContext'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.
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.
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.| Layer | Knows | Does not know |
|---|---|---|
Renderer | scenes, entities, meshes, materials, cameras, lights; the frame loop; its windows, through a Platform | any Vulkan type; SDL (only Engine passes the SDL platform) |
RenderContext | handles and the rhi:: object behind each one; the layout each texture is in (TextureStates); the bindless set | scenes, entities, the frame loop, the Renderer |
rhi::Device | neutral resources, command buffers, the graphics queue and an optional compute queue, the swapchain | handles, which backend is under it |
VulkanDevice | VkDevice and its function table (volk), VMA, vk-bootstrap | handles, 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 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 want | Create | Example |
|---|---|---|
| a window, input and file loading made for you | Engine with PlatformType::SDL (link rasm::rasm) | examples/00_hello_scene |
| to draw into your own window, with your event loop, and load files | Renderer 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 Zig | the 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.
| Folder | Holds | Main files |
|---|---|---|
include/rasm/ | the public API: Renderer, Engine, handles, plain types | rasm.h, renderer.h, engine.h, handle.h, types.h |
include/rasm/render/ | the low-level public API | renderContext.h, renderGraph.h, resource.h |
src/core/ | handle manager, file reading | handle.cpp, utils.cpp |
src/platform/ | The window and its input (SDL3, the application's window, or none when headless), the input events, paths | platform.h, sdlPlatform.cpp, nativePlatform.cpp, headlessPlatform.cpp, input.cpp, paths.cpp |
src/assets/ | mesh, texture and material loading, glTF and OBJ import, mesh LODs | mesh.cpp, meshImport.cpp, meshLod.cpp, texture.cpp, material.cpp |
src/scene/ | scenes, entities, cameras, lights, transforms | scene.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 structs | gpuScene.cpp, viewGraph.cpp, gpuTable.cpp, geometryPool.cpp, shaderCompiler.cpp |
src/rhi/ | RenderContext, the rhi::Device interface, uploads, texture layouts | renderContext.cpp, device.h, uploadManager.cpp, textureStates.cpp |
src/rhi/vulkan/ | the Vulkan backend | vulkanDevice.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_renderer | cApi.cpp, cRenderer.cpp, cScene.cpp, cLoader.cpp |
shaders/lib/, shaders/passes/ | Slang modules and pass entry points, compiled at run time | core.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 libraries | handleTests.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
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".
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.
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
- Take a handle.
registry.entityHandles.allocate()gives{3, 1}, or index 0 whenMAX_ENTITIES− 1 are alive: then warn and return an invalid handle. - Store the object.
registry.entitiesgrows to the pool'ssize, thenentities[3]= the newEntity. - Queue its rows. With a mesh:
queueInstanceRows, so the GPU scene gives it rows later.
GPU object: createBuffer
- Make the object first.
device->createBuffer(desc)returns anrhi::Bufferpointer, or null on failure (then an invalid handle). - Take a handle.
buffers.handles.allocate()gives{5, 1}. - Store the pointer.
buffers.objects[5]= that pointer. - Look it up later. Every later call checks the generation, and logs an error for a destroyed or unknown handle.
| Owner | Type | Limit | Where the limit is |
|---|---|---|---|
Renderer registry | Entity | MAX_ENTITIES = 262144 (262143 usable) | rasm/entity.h |
Mesh | no count limit; its sub-meshes stop at EngineConfig::geometryPoolSubMeshes = 16384 rows, its data at the other pool sizes | rasm/types.h | |
Material | EngineConfig::maxMaterials = 4096 alive at once | rasm/types.h | |
Camera | MAX_CAMERAS = 32 (31 usable) | rasm/engine.h | |
Light | EngineConfig::maxLights = 16384 | rasm/types.h | |
Scene | MAX_SCENES = 16 (15 usable) | rasm/scene.h | |
RenderContext tables | buffers, 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.
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.
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).The same shader descriptor, twice
One object. The second call returns the cached handle.
The same buffer descriptor, twice
Two objects, two handles. Each caller writes its own data.
| Call | Deduplicated? | Cache and hash |
|---|---|---|
createShader | yes | shaderDescCache, ShaderDescHash |
createPipeline | yes (graphics and compute) | pipelineDescCache, PipelineDescHash |
createBindlessDescriptorSetLayout | yes | descriptorSetLayoutDescCache, BindlessDescriptorSetLayoutDescHash |
createBuffer, createTexture | no | cache at the asset level: loadTexture caches by path and format |
createDescriptorPool, allocateDescriptorSet | no | — |
createRenderTarget | no | makes 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
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.| Object | Holds | Shared? |
|---|---|---|
Scene | lists of EntityHandle, CameraHandle, LightHandle | an entity can be in several scenes |
Entity | a MeshHandle, a MaterialHandle, a Transform | — |
Mesh | state (LOADING, READY, FAILED) and SubMeshes | many entities can use one mesh |
SubMesh | a MeshGeometry range in the pool, the glTF node transform, a material | — |
Material | MaterialType, texture handles per PbrSlot, params indexed by PbrParam, doubleSided | many entities and sub-meshes |
Camera | CameraProjection, CameraController, current and target Transform | a camera can be in several scenes |
Light | LightType, color, position, direction, intensity, range | a 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.
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.
| Example | Parts it uses | Read |
|---|---|---|
00_hello_scene | loadMesh, loadTexture, createEntity, render | stop 2, stop 3, GPU-driven rendering |
01_render_graph | RenderGraph, createRenderTarget, addScenePasses, createPipeline | Render graphs, Transient memory, History buffers, Multiple render targets |
02_gltf | loadGLTF, sub-meshes, material rows | Streaming assets, PBR, Bindless |
03_instances | createMesh, updateTransform, updateMaterial, EngineConfig::asyncCompute | stop 3, GPU memory and uploads, Async compute |
04_compute | addComputePass, createComputePipeline | Buffer device addresses, GPU synchronization |
05_city | culling, Hi-Z, LODs, fillTexture | Frustum and occlusion culling, LOD selection |
06_shadows | addShadowPasses with ShadowDesc, addScenePasses with the SceneShadow, readDepth on depth-only targets, addToneMapPass | Shadow mapping, Render graphs, Tone mapping |
07_lights | LightType::SPOT, addShadowPasses for directional, spot and point lights, addScenePasses with three shadows | Spot and point light shadows, PBR |
11_many_lights | 1024 moving point and spot lights (updateLight), EngineConfig::clusteredLighting, FrameStats | Clustered lighting |
23_large_world | double 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 origin | Large worlds, Cascaded shadows, TAA |
24_map_tiles | TileStreamer: 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 view | Tile 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
| What | Where |
|---|---|
Handles, HandlePool | include/rasm/handle.h, src/core/handle.cpp |
| The registry | Renderer::Registry in include/rasm/engine.h |
| Create CPU objects | src/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 tables | RenderContext::Impl in src/rhi/renderContext.cpp |
| Descriptors | include/rasm/render/resource.h |
| Dedup hashes | src/rhi/resource.cpp |
| Texture layouts | TextureStates in src/rhi/textureStates.cpp, used by RenderContext::transitionImageLayout |
| Pick the backend | rhi::createDevice in src/rhi/device.cpp |
| Source list | target_sources(rasm ...) in src/CMakeLists.txt: .cpp files; every header in include/ is found by a glob and installed |
| Examples | one folder each, such as examples/05_city/main.cpp, listed with rasm_add_example in examples/CMakeLists.txt |
9Rules when you change it
- 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,PipelineDescorBindlessDescriptorSetLayoutDescmust also be folded into its hash insrc/rhi/resource.cpp. createBufferandcreateTexturealways 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/.cpppair in its layer's folder, and its.cppgoes intotarget_sources(rasm ...)insrc/CMakeLists.txt. A header ininclude/rasm/needs no list entry: it is found and installed by itself. - A new dependency linked to
rasmalso needs afind_dependencyline incmake/rasmConfig.cmake.in, becauserasmis a static library. - No templates in RASM code.
Handleinrasm/handle.his the only exception.