crcbl-render 0.2.1

Crucible renderer: the 3D frame on crcbl-frame — meshes, materials, lights, effects
Documentation
//! 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.
//!
//! ```text
//! 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`](crcbl_hal::CommandEncoder::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`](forward::ForwardRenderer::replace_page)
//! reloads a material page or
//! [`ForwardRenderer::set_grass`](forward::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`](crcbl_hal::null), 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);
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```

// The frame core's modules, under the paths this crate has always given them:
// the graph, the transient pool, the texture uploads, the mip chains and the
// frame counters live in `crcbl-frame`, which a program that draws only a UI
// depends on without the rest of this crate.
pub use crcbl_frame::{counters, graph, mip, texture, transient};

mod atlas_view;
mod bind_group_cache;
mod bloom;
pub mod camera;
pub mod cluster_pool;
mod contact_shadows;
pub mod cull;
pub mod cull_stats;
pub mod debug_draw;
pub mod draw_gen;
pub mod effects;
mod exposure;
pub mod fly;
pub mod forward;
mod fxaa;
pub mod grass;
pub mod grid;
pub mod hiz;
pub mod instance_pool;
pub mod layers;
pub mod light;
pub mod light_grid;
pub mod material_table;
pub mod menu;
pub mod mesh_pool;
pub mod nine_slice;
pub mod occlusion_cull;
pub mod orbit;
pub mod pass_stats;
mod probe;

/// The GPU pass that fills a probe's visibility map: a depth cube per probe,
/// resolved into the octahedral layer `mesh.slang` reads.
mod probe_capture;

/// The compute pass that reads the irradiance probes' reflective
/// shadow map into every probe row of a volume the scene asked to be updated.
mod probe_gather;

/// The static geometry a probe's visibility map is captured from, and the
/// console variable that decides whether the frame reads one.
mod probe_visibility;

mod cmaa2;
/// 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.
pub mod rsm;
pub mod scene;
pub mod shadow;
pub mod skinning;
mod sky_pass;
mod split;
pub mod sprite_pass;
mod ssao;
mod ssr;
pub mod stack;
pub mod targets;
pub mod timing;
pub mod ui_pass;
mod upscale;
mod volumetric;
mod water;

pub use camera::{Atmosphere, Camera, DirectionalLight, Fog, Projection, Sky, ViewRay};
pub use cluster_pool::{ClusterPool, ClusterRange};
pub use counters::{FrameCounters, INDIRECT, UNKNOWN};
/// 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.
///
/// [`NineSlice`] and [`Rect`] are here for the same reason —
/// [`NineSliceSource`]'s fields are spelled in both.
pub use crcbl_sprite::{NineSlice, Rect, SampleMode};
/// 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.
pub use crcbl_ui::menu::{Menu, MenuItem, MenuItemLayout, MenuLayout, MenuSkin, MenuStyle};
pub use crcbl_ui::text::FontAtlas;
/// Re-exported for the same reason as [`Menu`]: [`MenuSkin`]'s buttons are a
/// [`ButtonSkin`] drawn per [`ButtonState`], and its insets are
/// [`SkinInsets`].
pub use crcbl_ui::{ButtonSkin, ButtonState, SkinInsets};
/// 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.
pub use crcbl_water::{BodyError, Medium, WaterBody};
pub use cull::{Aabb, Frustum, visible_instances};
pub use cull_stats::{ClusterCull, CullStats, CullStatsRing, OcclusionCull};
pub use debug_draw::{DebugDraw, DebugVertex, frustum_corners};
pub use draw_gen::{
    DrawGen, DrawGenDesc, FrameCull, GeneratedDraws, OcclusionFrame, PyramidInputs, Selection,
};
pub use effects::{Antialiasing, EffectOverride, EffectRequest, RenderEffects, ray_tracing_note};
pub use exposure::{ExposureAdaptation, ExposureBuffers};
pub use fly::{Flyer, LOOK, SPEED, TURN};
pub use forward::{
    DEFAULT_ANISOTROPY, DebugView, EXPOSURE_MAX, EXPOSURE_MIN, ForwardOverlayTargets,
    ForwardRenderer, FrameTargets, MAX_VIEWS, MIN_RENDER_SCALE, SCENE_CLEAR, SHADOW_LOD_BIAS,
    SkinnedInstanceDesc, ViewBackground, ViewDesc, ViewId, ViewLighting, ViewMask, ViewTarget,
};
pub use graph::{
    Attachment, BufferId, CompiledGraph, CompiledPass, GraphBarriers, GraphBufferBarrier,
    GraphError, GraphImageBarrier, ImageId, ImportField, ImportedBuffer, ImportedImage,
    InitialClaim, PassBuilder, PassContext, PassKind, RenderGraph,
};
pub use instance_pool::{
    Instance, InstanceHandle, InstancePool, InstancePoolDesc, InstancePoolError,
};
pub use layers::{Layer, LayerStack, Parallax};
pub use light::{Light, PointLight, RectLight, SpotLight, sun_row};
pub use light_grid::{FROXEL_CAPACITY, FrameView, Grid, LightGrid, LightGridDesc};
pub use material_table::{
    Material, MaterialHandle, MaterialTable, MaterialTableDesc, MaterialTableError,
};
pub use menu::menu_skin;
pub use mesh_pool::{
    Mesh, MeshHandle, MeshPool, MeshPoolDesc, MeshPoolError, MeshRange, MeshUpload, UPLOAD_TIMEOUT,
};
pub use nine_slice::{NineQuads, NineSliceSource, SliceQuad};
pub use occlusion_cull::OcclusionCulling;
pub use orbit::OrbitCamera;
pub use pass_stats::PassStats;
pub use scene::{
    Capacities, Geometry, InstanceDesc, MeshDesc, PageDesc, PageKind, ProbeGrid, ProbeUpdate,
    SceneBoundsError, SceneDesc,
};
pub use shadow::Cascades;
pub use skinning::{
    SkinRange, SkinnedMesh, SkinnedRegion, Skinning, SkinningDesc, SkinningError, blend,
    normal_basis, skin_vertex,
};
pub use sprite_pass::{
    ATLAS_FORMAT, ATLAS_FORMATS, AtlasDesc, AtlasSlot, CONSTANTS_SIZE, INSTANCE_STRIDE,
    SAMPLE_PIXEL, SAMPLE_SMOOTH, SheetDesc, SheetError, SheetId, SlotCopy, Sprite, SpriteConstants,
    SpriteInstance, SpriteRenderer, sheet_lane,
};
pub use ssao::{r_ssao_bent_normals, r_ssao_blur_passes, r_ssao_slices};
pub use stack::{
    AmbientOcclusionPass, AntialiasingPass, AutoExposurePass, BloomPass, CameraStack,
    ContactShadowsPass, ReflectionsPass, ShadowsPass, StackError, VolumetricFogPass,
};
pub use texture::{
    ClearedTextureDesc, TexturePatch, UploadedTexture, upload_cleared_texture, upload_texture,
    upload_texture_layers, upload_texture_mip_layers,
};
pub use timing::{FrameTimings, MAX_TIMED_PASSES, PassTimers, PassTiming};
pub use transient::{TransientBufferDesc, TransientImageDesc, TransientPool, TransientUse};
pub use ui_pass::{UiRenderer, UiTexture};
pub use volumetric::FroxelBuffers;

/// Everything this crate exposes to the debug console.
///
/// One list per crate, gathered by the engine at one seam — debug-console
/// decision 2 in `docs/notes/tooling.md`, whose worked example in the plan was
/// this crate. It holds [`debug_draw::r_debug_draw`], the switch the debug draw
/// layer reads once a frame, the occlusion chain's own — `ssao::r_ssao_slices`
/// and `ssao::r_ssao_blur_passes`, which `crate::ssao`'s header argues are two
/// variables rather than one quality knob, `ssao::r_ssao_intensity` and
/// `ssao::r_ssao_radius`, which that header argues are not on their ladder at
/// all because neither moves the budget, and `ssao::r_ssao_bent_normals`, which
/// is the one of them that is on by default because it is the rung rather than
/// a purchase on top of it, and `ssao::r_ssao_split`, which is not a knob on the
/// effect at all but the comparison seam `crate::split` describes — and the
/// shadow cadence's two,
/// `shadow::r_shadow_cadence` and `shadow::r_shadow_faces`, which
/// `crate::shadow`'s cadence module argues are two for the same kind of reason:
/// how long a map may be held and how many may be redrawn at once are different
/// purchases — and the shadow filter's two, `shadow::r_shadow_filter` and
/// `shadow::r_shadow_split`, which are that module's answer to the occlusion
/// chain's technique pair: which rung of topic 45's filter
/// ladder runs, and the seam that puts it beside the one that ships — and the
/// sun's two bias counts, `shadow::r_shadow_bias` and
/// `shadow::r_shadow_normal_offset`, which are two variables for the reason
/// topic 45's seventh decision gives: one moves the compared
/// depth towards the light and the other moves the receiver sideways along its
/// own normal, so acne and peter-panning are pulled by different numbers and a
/// single knob could not show the pair moving against each other.
/// `tests/console_table.rs` is
/// what keeps this list in step with what the source actually declares.
#[must_use]
pub fn console_table() -> crcbl_console::Table {
    crcbl_console::table![
        debug_draw::r_debug_draw,
        ssao::r_ssao_slices,
        ssao::r_ssao_blur_passes,
        ssao::r_ssao_intensity,
        ssao::r_ssao_bent_normals,
        ssao::r_ssao_radius,
        ssao::r_ssao_technique,
        ssao::r_ssao_split,
        occlusion_cull::r_occlusion_cull,
        occlusion_cull::r_small_feature_px,
        probe_visibility::r_probe_visibility,
        rsm::r_probe_bounce,
        shadow::r_shadow_cadence,
        shadow::r_shadow_faces,
        shadow::r_shadow_filter,
        shadow::r_shadow_split,
        shadow::r_shadow_bias,
        shadow::r_shadow_normal_offset
    ]
}