Skip to main content

Crate crcbl_render

Crate crcbl_render 

Source
Expand description

Renderer: the 3D frame — meshes, materials, lights, effects — built on crcbl-frame’s render graph and UI pass, everything above the HAL seam.

The graph, the transient pool, the texture uploads, the pass timers and the UI pass are crcbl_frame’s, re-exported here under the paths they have always had (graph, transient, texture, timing, ui_pass), so a program that draws only a UI can depend on that crate alone.

camera + light ──▶ ForwardRenderer ──adds passes──▶ RenderGraph
                                                         │ compile()
                                                         ▼
                           ordered passes + exact barriers + transients
                                                         │ execute()
                                                         ▼
                                       crcbl-hal ──▶ crcbl-vk / null / …

§The one rule

No manual barriers outside the graph, ever — stage 2 §2.4, and it is the reason this crate exists rather than the frame loop living in each sample. Passes say what they read and write; graph::RenderGraph::compile works out the transitions, the layout changes, the transient aliasing and the final states, and graph::CompiledGraph::execute is the only code in the engine that calls pipeline_barrier during a frame.

The barriers outside it are the startup uploads: mesh_pool’s staging copy into the geometry pools, texture’s for every image (ui_pass’s glyph atlas and sprite_pass’s sheets), and draw_gen’s copy zeroing the LOD hysteresis state, which is device-local because a shader writes it and so cannot be zeroed by a host write. Each runs before any frame exists and has no graph to belong to; each is called out at the call site. The one that also runs later is texture’s — between two frames, never inside one, on an image no frame names yet, and blocking until its copy lands — when ForwardRenderer::replace_page reloads a material page or ForwardRenderer::set_grass replaces a field. There are no others, and a barrier recorded during a frame from anywhere but graph::CompiledGraph::execute is a bug.

§Nothing here knows a backend

This crate depends on crcbl-hal, crcbl-core, crcbl-frame, crcbl-shaders, glam, and the two description-only crates whose data it turns into pixels — crcbl-ui for ui_pass’s draw list and crcbl-sprite for sprite_pass’s sample modes, neither of which depends on a backend or on this crate. It contains no ash, no crcbl-vk, and no #[cfg(target_os = …)], per the HAL rules in docs/notes/backends.md — which also name the render graph specifically as living above the seam rather than in it. The graph compiles identically against NullBackend, which is what makes the graph-compile suite docs/notes/process.md calls a non-negotiable anchor run on every machine, with no ICD in the room.

§Two tiers, one renderer

Topic 03’s rule is that the lesser path (once “Tier B”) is a constraint on data layout, not a separate renderer, and no pass here reads a push constant. forward’s camera has been in a uniform buffer since P1 for exactly that reason; sprite_pass followed it; and ui_pass — which draws every sample’s HUD, and which WebGPU’s lack of push constants had made this crate’s one permutation axis, with a ConstantDelivery enum and a second .slang — joined them in 2026-08.

So the tier costs one indirection where a push constant would have served, and buys one artifact per shader, one code path per pass, and nothing to select between at device-open time. ui_pass’s own docs carry the trade in full, including what the split had cost.

§What this crate is not, at P1

No backend registry (see below), no material system, no scene, no scheduler. material_table is §3.2’s table and only that — a row of factors and one base-colour texture layer that an instance’s id selects; the authoring, templates, permutations and the other texture slots a material system means are docs/plan/37-materials.md’s and are not here.

The one thing on that list that has since moved whole is culling: cull is §3.3’s frustum test and the CPU reference cull.slang is checked against, draw_gen runs that shader and turns its survivors into indirect draw arguments, and forward draws from those rather than recording a draw per object. The graph is still a linear pass list with computed barriers, which is what §2.4’s risk list asks for by name: “No multi-queue scheduling, no reordering. Resist.”

§The registry deliberately did not move here

crcbl-vk’s crate docs floated moving the GPU backend registry into this crate at P1.3. It did not move, because it would make crcbl-render depend on crcbl-vk — and crcbl-vk’s end-to-end suite depends on crcbl-render, since the only honest way to test a render graph against real Vulkan is to run the real graph. That is a dependency cycle through dev-dependencies: legal in Cargo, and a confusing thing to have created in exchange for moving four lines out of the crate whose entire job is to be the one name a game depends on. The registry stays in crcbl.

§Example

use crcbl_hal::null::NullInstance;
use crcbl_hal::{DeviceDesc, Instance, QueueKind, ResourceState};
use crcbl_render::graph::RenderGraph;
use crcbl_render::transient::{TransientImageDesc, TransientPool};

let instance = NullInstance::gpu_driven();
let adapter = instance.adapters().remove(0);
let device = instance.create_device(&DeviceDesc::for_adapter(adapter.id))?;
let queue = device.queue(QueueKind::Graphics).expect("always present");

// The pool outlives the graph: it owns the physical images, and it is what
// remembers what the last frame left them in.
let mut pool = TransientPool::new();

let mut graph = RenderGraph::new(queue);
let scene = graph.create_image("scene", crcbl_render::targets::scene_color((64, 48)));
graph
    .add_render_pass("clear")
    .clear_color(scene, [0.0, 0.0, 0.0, 1.0])
    .execute(|_| {});

let compiled = graph.compile(&pool)?;
assert_eq!(compiled.passes().len(), 1);
// Nothing has ever used this pool, so the transient really is undefined and
// the graph transitions it before use. A second frame through the same pool
// would start from `ColorAttachment` — which is the barrier that orders it
// after this one.
let barriers = compiled.passes()[0].barriers();
assert_eq!(barriers.images[0].from, ResourceState::Undefined);
assert_eq!(barriers.images[0].to, ResourceState::ColorAttachment);

Re-exports§

pub use camera::Atmosphere;
pub use camera::Camera;
pub use camera::DirectionalLight;
pub use camera::Fog;
pub use camera::Projection;
pub use camera::Sky;
pub use camera::ViewRay;
pub use cluster_pool::ClusterPool;
pub use cluster_pool::ClusterRange;
pub use cull::Aabb;
pub use cull::Frustum;
pub use cull::visible_instances;
pub use cull_stats::ClusterCull;
pub use cull_stats::CullStats;
pub use cull_stats::CullStatsRing;
pub use cull_stats::OcclusionCull;
pub use debug_draw::DebugDraw;
pub use debug_draw::DebugVertex;
pub use debug_draw::frustum_corners;
pub use draw_gen::DrawGen;
pub use draw_gen::DrawGenDesc;
pub use draw_gen::FrameCull;
pub use draw_gen::GeneratedDraws;
pub use draw_gen::OcclusionFrame;
pub use draw_gen::PyramidInputs;
pub use draw_gen::Selection;
pub use effects::Antialiasing;
pub use effects::EffectOverride;
pub use effects::EffectRequest;
pub use effects::RenderEffects;
pub use effects::ray_tracing_note;
pub use fly::Flyer;
pub use fly::LOOK;
pub use fly::SPEED;
pub use fly::TURN;
pub use forward::DEFAULT_ANISOTROPY;
pub use forward::DebugView;
pub use forward::EXPOSURE_MAX;
pub use forward::EXPOSURE_MIN;
pub use forward::ForwardOverlayTargets;
pub use forward::ForwardRenderer;
pub use forward::FrameTargets;
pub use forward::MAX_VIEWS;
pub use forward::MIN_RENDER_SCALE;
pub use forward::SCENE_CLEAR;
pub use forward::SHADOW_LOD_BIAS;
pub use forward::SkinnedInstanceDesc;
pub use forward::ViewBackground;
pub use forward::ViewDesc;
pub use forward::ViewId;
pub use forward::ViewLighting;
pub use forward::ViewMask;
pub use forward::ViewTarget;
pub use instance_pool::Instance;
pub use instance_pool::InstanceHandle;
pub use instance_pool::InstancePool;
pub use instance_pool::InstancePoolDesc;
pub use instance_pool::InstancePoolError;
pub use layers::Layer;
pub use layers::LayerStack;
pub use layers::Parallax;
pub use light::Light;
pub use light::PointLight;
pub use light::RectLight;
pub use light::SpotLight;
pub use light::sun_row;
pub use light_grid::FROXEL_CAPACITY;
pub use light_grid::FrameView;
pub use light_grid::Grid;
pub use light_grid::LightGrid;
pub use light_grid::LightGridDesc;
pub use material_table::Material;
pub use material_table::MaterialHandle;
pub use material_table::MaterialTable;
pub use material_table::MaterialTableDesc;
pub use material_table::MaterialTableError;
pub use menu::menu_skin;
pub use mesh_pool::Mesh;
pub use mesh_pool::MeshHandle;
pub use mesh_pool::MeshPool;
pub use mesh_pool::MeshPoolDesc;
pub use mesh_pool::MeshPoolError;
pub use mesh_pool::MeshRange;
pub use mesh_pool::MeshUpload;
pub use mesh_pool::UPLOAD_TIMEOUT;
pub use nine_slice::NineQuads;
pub use nine_slice::NineSliceSource;
pub use nine_slice::SliceQuad;
pub use occlusion_cull::OcclusionCulling;
pub use orbit::OrbitCamera;
pub use pass_stats::PassStats;
pub use scene::Capacities;
pub use scene::Geometry;
pub use scene::InstanceDesc;
pub use scene::MeshDesc;
pub use scene::PageDesc;
pub use scene::PageKind;
pub use scene::ProbeGrid;
pub use scene::ProbeUpdate;
pub use scene::SceneBoundsError;
pub use scene::SceneDesc;
pub use shadow::Cascades;
pub use skinning::SkinRange;
pub use skinning::SkinnedMesh;
pub use skinning::SkinnedRegion;
pub use skinning::Skinning;
pub use skinning::SkinningDesc;
pub use skinning::SkinningError;
pub use skinning::blend;
pub use skinning::normal_basis;
pub use skinning::skin_vertex;
pub use sprite_pass::ATLAS_FORMAT;
pub use sprite_pass::ATLAS_FORMATS;
pub use sprite_pass::AtlasDesc;
pub use sprite_pass::AtlasSlot;
pub use sprite_pass::CONSTANTS_SIZE;
pub use sprite_pass::INSTANCE_STRIDE;
pub use sprite_pass::SAMPLE_PIXEL;
pub use sprite_pass::SAMPLE_SMOOTH;
pub use sprite_pass::SheetDesc;
pub use sprite_pass::SheetError;
pub use sprite_pass::SheetId;
pub use sprite_pass::SlotCopy;
pub use sprite_pass::Sprite;
pub use sprite_pass::SpriteConstants;
pub use sprite_pass::SpriteInstance;
pub use sprite_pass::SpriteRenderer;
pub use sprite_pass::sheet_lane;
pub use stack::AmbientOcclusionPass;
pub use stack::AntialiasingPass;
pub use stack::AutoExposurePass;
pub use stack::BloomPass;
pub use stack::CameraStack;
pub use stack::ContactShadowsPass;
pub use stack::ReflectionsPass;
pub use stack::ShadowsPass;
pub use stack::StackError;
pub use stack::VolumetricFogPass;
pub use timing::MAX_TIMED_PASSES;
pub use ui_pass::UiRenderer;

Modules§

camera
Cameras, and the reversed-Z projection matrices that are the engine’s whole depth convention.
cluster_pool
The cluster buffers mesh_cluster.slang reads: §3.5’s meshlets, resident on the GPU.
counters
What one frame’s passes actually recorded: draws, instances, triangles.
cull
Frustum culling: an axis-aligned box, six half-spaces, and the reference implementation cull.slang is checked against.
cull_stats
The culling statistics, off the GPU and onto a ring of readback slots.
debug_draw
The debug draw layer: an immediate-mode buffer of world-space line segments, drawn pre-tonemap in HDR.
draw_gen
GPU draw generation: the cull dispatch, the draw-argument dispatch, and the buffers between them.
effects
Which render effects a frame draws, and topic 39’s four-layer order that decides it.
fly
The free-fly camera: keys and mouse deltas in, a Camera out.
forward
The frame milestones 3, 4 and 5 draw: a lit mesh into an HDR target, then a tonemap into whatever the caller is presenting to.
graph
The render graph: passes declare what they touch, and the graph works out the barriers.
grass
docs/plan/57-grass.md rungs G1, G2 and G3: a field of grass, generated by compute and drawn beside the opaque frame as cards, as mesh blades, as shells, or as any mix of the three.
grid
The infinite ground grid: one full-screen pass that ray-casts the plane y = 0 and blends its cell lines over the scene.
hiz
Topic 47’s Hi-Z pyramid (docs/notes/rendering.md): the depth reduction crate::ssr’s march climbs instead of stepping at a fixed stride.
instance_pool
The instance array: one storage-buffer element per drawable object, written by delta upload — the changed elements only, coalesced into runs.
layers
Parallax layers: which band of the world a sprite is drawn in, and how much of the camera’s motion that band takes.
light
The lights a frame carries, and the rows they become.
light_grid
The light list and the froxel grid a compute pass assigns it to.
material_table
The material table: one storage-buffer row per material, and the id an instance carries to select one.
menu
The menu’s art: a nine-sliced window frame, a three-state button skin, and the scrim behind both — registered into the UI’s image atlas.
mesh_pool
Global geometry pools: one vertex buffer, one index buffer, and a mesh that is three integers.
mip
The base-colour page’s mip chain, built on the host at import.
nine_slice
Nine-slice: one frame drawn at any size with its corners left alone.
occlusion_cull
Topic 03 §3.3’s occlusion cull: the farthest-depth pyramid it reads, and the switches that turn it on.
orbit
The orbit camera: turning drags into a Camera, and nothing else.
pass_stats
What each pass costs over a run, rather than what one latent frame cost.
rsm
The reflective shadow map: the sun’s near cascade drawn a second time as what it reflects, where it is and which way it faces. The reflective shadow maps: the sun’s near cascade and every shadowed punctual light’s faces, drawn a second time as what they reflect, where they are and which way they face.
scene
What is resident in a frame, as host-side data an application writes and ForwardRenderer::with_scene consumes.
shadow
Where each shadow map looks, and how far: the sun’s cascades, a spot light’s cone and a point light’s six faces.
skinning
The skinning prepass: joint palettes and bind-pose vertices in, skinned vertices written back into a transient region of the same vertex pool.
sprite_pass
Sprite pass: instanced, world-space, alpha-blended quads cut out of sheets.
stack
The camera layer of crate::effects’ four-layer order, as a file.
targets
The transients a frame of this renderer has, described once.
texture
One texture upload, for every format and every caller.
timing
Per-pass GPU timestamps — crcbl_frame::timing, re-exported — and how many passes this crate’s renderers record.
transient
The transient resource pool: graph-owned images and buffers, reused across frames and aliased within one.
ui_pass
The engine’s UI pass: crcbl_frame’s, with the engine’s menu art in its image atlas from the first frame.

Structs§

BufferId
A virtual buffer inside one graph. See ImageId.
ButtonSkin
Re-exported for the same reason as Menu: MenuSkin’s buttons are a ButtonSkin drawn per ButtonState, and its insets are SkinInsets. The art a skinned button draws: one nine-sliced image per ButtonState.
ClearedTextureDesc
The image upload_cleared_texture creates, and what goes on it.
CompiledGraph
A compiled graph: ordered passes, exact barriers, and a transient plan.
CompiledPass
One pass, after compilation.
ExposureAdaptation
How far one frame’s exposure may travel toward the one its histogram asks for.
ExposureBuffers
The buffers one frame’s measurement lives in.
FontAtlas
A simple monospace bitmap font atlas.
FrameCounters
Draw calls, instances and triangles one frame recorded.
FrameTimings
A whole frame’s per-pass costs.
FroxelBuffers
The buffers one frame’s froxel column lives in.
GraphBarriers
One batch of barriers, emitted as a single pipeline_barrier call.
GraphBufferBarrier
A barrier the graph computed, in terms of a virtual buffer.
GraphImageBarrier
A barrier the graph computed, in terms of a virtual image.
ImageId
A virtual image inside one graph.
ImportedBuffer
A buffer the graph did not create, and does not own.
ImportedImage
An image the graph did not create, and does not own.
Medium
Re-exported because ForwardRenderer::set_water is spelled in them, on SampleMode’s terms below: a caller setting water should not need a dependency of its own to name what it sets. What light meets inside a body of water, per colour channel.
Menu
Re-exported for the same reason: menu_skin returns a MenuSkin, and a caller that can name this crate’s menu art should not have to add a second dependency to lay out and draw the menu it skins. It is also what lets an end-to-end suite that depends on this crate take a golden image of the real menu rather than of a replica. A modal menu: a title, some items, and which one is selected.
MenuItem
Re-exported for the same reason: menu_skin returns a MenuSkin, and a caller that can name this crate’s menu art should not have to add a second dependency to lay out and draw the menu it skins. It is also what lets an end-to-end suite that depends on this crate take a golden image of the real menu rather than of a replica. One line of a menu: what it says, what key does it, and what it is called.
MenuItemLayout
Re-exported for the same reason: menu_skin returns a MenuSkin, and a caller that can name this crate’s menu art should not have to add a second dependency to lay out and draw the menu it skins. It is also what lets an end-to-end suite that depends on this crate take a golden image of the real menu rather than of a replica. Where one item landed.
MenuLayout
Re-exported for the same reason: menu_skin returns a MenuSkin, and a caller that can name this crate’s menu art should not have to add a second dependency to lay out and draw the menu it skins. It is also what lets an end-to-end suite that depends on this crate take a golden image of the real menu rather than of a replica. One frame’s placement of a menu: the panel, the title and every button, in screen pixels.
MenuSkin
Re-exported for the same reason: menu_skin returns a MenuSkin, and a caller that can name this crate’s menu art should not have to add a second dependency to lay out and draw the menu it skins. It is also what lets an end-to-end suite that depends on this crate take a golden image of the real menu rather than of a replica. The pictures a menu is drawn with: a window frame, a button frame per state and the scrim behind them, all registered in one ImageAtlas.
MenuStyle
Re-exported for the same reason: menu_skin returns a MenuSkin, and a caller that can name this crate’s menu art should not have to add a second dependency to lay out and draw the menu it skins. It is also what lets an end-to-end suite that depends on this crate take a golden image of the real menu rather than of a replica. Every length a menu is laid out with, in pixels.
NineSlice
Re-exported because SheetDesc::sample is spelled in it: a crate whose public API names a foreign type and does not export it is one every caller has to add a dependency for.
PassBuilder
Declares one pass. #[must_use] because a builder that is dropped rather than executed adds nothing to the graph, and a silently missing pass is a long afternoon.
PassContext
What a pass body is handed.
PassTimers
A ring of timestamp query sets, one per frame in flight plus two; see the module docs.
PassTiming
What one pass cost on the GPU.
Rect
Re-exported because SheetDesc::sample is spelled in it: a crate whose public API names a foreign type and does not export it is one every caller has to add a dependency for.
RenderGraph
A frame’s worth of passes, before compilation.
SkinInsets
Re-exported for the same reason as Menu: MenuSkin’s buttons are a ButtonSkin drawn per ButtonState, and its insets are SkinInsets. The fixed corner insets of a nine-slice button skin, in screen pixels.
TexturePatch
Texels written over an upload_cleared_texture image as it is created: a width by height rectangle of layer layer, its top-left texel at x, y.
TransientBufferDesc
What a graph-owned buffer should be.
TransientImageDesc
What a graph-owned image should be.
TransientPool
Physical backing for the graph’s transients.
TransientUse
What the last frame to use a pooled resource left it in.
UiTexture
One texture a frame’s draw list names, as the render graph knows it — what UiRenderer::add_passes_with_textures takes.
UploadedTexture
A texture that has been uploaded: the image, and the view callers bind.
WaterBody
Re-exported because ForwardRenderer::set_water is spelled in them, on SampleMode’s terms below: a caller setting water should not need a dependency of its own to name what it sets. One body of water: a closed outline on the XZ plane, the height its surface sits at, and what it is made of.

Enums§

Attachment
How a pass attaches an image, if it attaches it at all.
BodyError
Re-exported because ForwardRenderer::set_water is spelled in them, on SampleMode’s terms below: a caller setting water should not need a dependency of its own to name what it sets. Why a WaterBody cannot be meshed.
ButtonState
Re-exported for the same reason as Menu: MenuSkin’s buttons are a ButtonSkin drawn per ButtonState, and its insets are SkinInsets. Button interaction state (computed externally from mouse input).
GraphError
Why a graph could not be compiled.
ImportField
Which field of a repeated import declaration disagreed with the first one.
InitialClaim
What backs an importer’s claim about ImportedImage::initial.
PassKind
Which scope a pass opens.
SampleMode
Re-exported because SheetDesc::sample is spelled in it: a crate whose public API names a foreign type and does not export it is one every caller has to add a dependency for.

Constants§

INDIRECT
How a counter with no honest number spells itself.
MIN_SSR_RESOLUTION
The smallest share of the scene extent the march runs at: the reciprocal of ssr::MAX_BLOCK, the widest block ssr.slang walks for a nearest surface.
UNKNOWN
How the cluster counter with no number spells itself.

Statics§

r_ssao_bent_normals
r_ssao_blur_passes
r_ssao_slices
r_ssr_resolution

Functions§

console_table
Everything this crate exposes to the debug console.
upload_cleared_texture
Creates a sampled colour image whose every texel is zero, with patches written over it, and returns it with a full view.
upload_texture
Uploads a 2D colour texture via a staging-buffer copy, and returns the image and a view onto it.
upload_texture_layers
Uploads several equally-sized layers into one D2Array colour image, and returns it with an array view onto every layer.
upload_texture_mip_layers
upload_texture_layers with a mip chain behind every layer: one D2Array image whose level count is the chain’s length, and an array view onto every level of every layer.