Skip to main content

Module batch

Module batch 

Source
Expand description

§GPU buffer batching – merges per-tile geometry into per-page draw calls

The batch module is the CPU-side counterpart to the tile atlas (crate::gpu::tile_atlas). Where the atlas packs textures into shared GPU pages, this module packs geometry into shared vertex and index buffers so that every tile sharing an atlas page can be drawn with a single draw_indexed call.

§Tile batches (build_tile_batches)

Each visible tile is a textured quad (4 vertices, 6 indices). The builder looks up the tile’s AtlasRegion, computes the world-space quad corners (camera-relative, f32), remaps the UVs into the atlas sub-rectangle, and appends the vertices and indices into a per-page accumulator. After iterating all visible tiles, each non-empty page accumulator is uploaded as a single vertex + index buffer pair (TileBatch).

The renderer issues one draw_indexed per non-empty page, binding the page’s atlas texture. This reduces draw calls from N (one per tile) to P (one per atlas page, typically 1-2).

§Terrain batches (build_terrain_batches)

Same grouping strategy, but the input is TerrainMeshData instead of tile quads. Each terrain mesh has its own vertex count and index list; the builder rebases indices and remaps UVs identically to tiles.

§Vector batches (build_vector_batch)

Vector layers are already pre-tessellated by the engine into a single VectorMeshData per layer. This function converts the f64 world positions to camera-relative f32 and uploads a single vertex + index buffer pair. No atlas grouping is needed because vector geometry is not textured.

§Memory pattern

Tile and vector batch buffers are now cached across frames using invalidation-driven cache keys. Tile batches are keyed by the visible tile set (target/actual pairs), quantised camera origin, and active projection. Vector batches are keyed by layer vertex/index counts and quantised camera origin. When the key matches the previous frame, existing GPU buffers are reused without any allocation or upload. When the key differs (e.g. camera movement or tile set change), new buffers are created with BufferUsages::VERTEX / INDEX and the cache is updated.

Terrain batches (for the legacy CPU-displaced fallback path) and hillshade batches remain per-frame temporaries because the shared-grid terrain path handles its own caching through SharedTerrainGridMesh and CachedHeightTexture.

Structs§

CircleBatchEntry
GPU buffers for a circle layer rendered via SDF quads.
FillBatchEntry
GPU buffers for a dedicated fill layer.
FillExtrusionBatchEntry
GPU buffers for a single fill-extrusion layer’s tessellated mesh.
FillPatternBatchEntry
GPU buffers for a single patterned fill layer.
HeatmapBatchEntry
GPU buffers for a heatmap layer.
HillshadeBatch
GPU buffers for all terrain hillshade overlay meshes that share a single atlas page.
LineBatchEntry
GPU buffers for a single line layer’s tessellated mesh with dash data.
LinePatternBatchEntry
GPU buffers for a single patterned line layer.
SymbolBatchEntry
Prepared GPU buffers for one symbol batch.
TerrainBatch
GPU buffers for all terrain meshes that share a single atlas page.
TileBatch
GPU buffers for all flat tile quads that share a single atlas page.
TilePageBatches
Per-page tile draw buffers split by depth behavior.
VectorBatchEntry
GPU buffers for a single vector layer’s tessellated mesh.

Functions§

build_circle_batch
Build a circle batch from engine circle instance data.
build_fill_batch
Build a fill batch entry from engine-tessellated mesh data.
build_fill_extrusion_batch
Build a fill-extrusion batch entry from engine-tessellated mesh data.
build_fill_pattern_batch
Build a fill-pattern batch entry from engine mesh data.
build_heatmap_batch
Build a heatmap batch from engine heatmap point data.
build_hillshade_batches
Build terrain hillshade batches grouped by the dedicated hillshade atlas.
build_line_batch
Build a line batch entry from engine-tessellated mesh data.
build_line_pattern_batch
Build a line-pattern batch entry from engine mesh data.
build_placeholder_batches
Build a single merged VectorBatchEntry containing quads for all loading placeholders.
build_symbol_batch
Build a symbol batch from placed symbols and a populated glyph atlas.
build_terrain_batches
Build terrain batches grouped by atlas page.
build_tile_batches
Build tile batches grouped by atlas page.
build_vector_batch
Build a vector batch entry from engine-tessellated mesh data.