Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

perf(renderer): cull bulk draws before staging geometry

yhh9ab324d57e4e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8bc7598b6..3edb81b36 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,8 @@ published separately; it ships inside the editor.
### Fixed
+- **Camera-excluded bulk draws skip transient geometry.** Batch and shape submissions check the camera mask before copying vertices or rebasing indices. SortingGroup layers and explicit culling bits keep their existing behavior; resident-vertex submissions skip excluded indices without discarding geometry owned by their caller.
+
- **Full texture batches avoid unused index copies.** Sorted 2D commands start a separate draw before copying indices when their new texture exceeds the available sampler slots, including slots reserved for masks. Existing textures still join full batches, preserving painter order and reducing transient index upload work.
## [0.80.0] - 2026-10-14
diff --git a/src/esengine/renderer/draw/BatchBuilder.cpp b/src/esengine/renderer/draw/BatchBuilder.cpp
index e23b6762c..d0b665777 100644
--- a/src/esengine/renderer/draw/BatchBuilder.cpp
+++ b/src/esengine/renderer/draw/BatchBuilder.cpp
@@ -24,12 +24,18 @@ namespace {
// the allocation across the frame, mirroring DrawList::sorted_scratch_.
std::vector<u32> g_indexScratch;
+bool submissionVisible(const DrawList& drawList, const BatchDrawKey& key) {
+ if (key.cullBit) return drawList.layerVisible(key.cullBit);
+ const auto identity = drawList.sortIdentity(key.entity.id(), key.layer, key.order);
+ return drawList.layerVisible(DrawList::layerBit(identity.layer));
+}
+
template <typename IndexT>
void pushBatchCommandImpl(TransientBufferPool& pool, DrawList& drawList, const ClipState& clips,
u32 vertexByteOffset, u32 vertexCount,
const IndexT* localIndices, u32 indexCount,
const BatchDrawKey& key) {
- if (indexCount == 0 || clips.isEmptyScissor(key.entity)) return;
+ if (indexCount == 0 || clips.isEmptyScissor(key.entity) || !submissionVisible(drawList, key)) return;
u32 baseVertex = vertexByteOffset / pool.vertexStride(key.layoutId);
g_indexScratch.resize(indexCount);
@@ -184,7 +190,8 @@ void appendIndexedDraw(TransientBufferPool& pool, DrawList& drawList, const Clip
const void* verts, u32 vertexCount,
const u32* localIndices, u32 indexCount,
const BatchDrawKey& key) {
- if (vertexCount == 0 || indexCount == 0 || clips.isEmptyScissor(key.entity)) return;
+ if (vertexCount == 0 || indexCount == 0 || clips.isEmptyScissor(key.entity)
+ || !submissionVisible(drawList, key)) return;
u32 vertexByteOffset = pool.appendVertices(
key.layoutId, verts, vertexCount * pool.vertexStride(key.layoutId));
pushBatchCommandImpl(pool, drawList, clips, vertexByteOffset, vertexCount, localIndices, indexCount, key);
diff --git a/tests/renderer/test_batch_builder.cpp b/tests/renderer/test_batch_builder.cpp
index f2317d8ab..ece4a1b32 100644
--- a/tests/renderer/test_batch_builder.cpp
+++ b/tests/renderer/test_batch_builder.cpp
@@ -235,6 +235,63 @@ TEST_CASE("finalize: sorted Batch index gaps merge in painter order with their t
CHECK(verts[8].texIndex == 1);
}
+TEST_CASE("camera mask: excluded bulk geometry does not enter transient streams") {
+ for (LayoutId layout : {LayoutId::Batch, LayoutId::Shape}) {
+ Harness h;
+ h.list.setCullingMask(1u << 6);
+ auto hidden = quadKey(1, 4);
+ hidden.layoutId = layout;
+ BatchVertex quad[4] = {};
+ TestShapeVertex shape[4] = {};
+ const void* verts = layout == LayoutId::Batch ? static_cast<const void*>(quad)
+ : static_cast<const void*>(shape);
+ for (u32 i = 0; i < 10000; ++i) {
+ appendIndexedDraw(h.pool, h.list, h.clips, verts, 4, BATCH_QUAD_INDICES, 6, hidden);
+ }
+ CHECK(h.list.commandCount() == 0);
+ CHECK(h.pool.vertexBytesUsed(layout) == 0);
+ CHECK(h.pool.indicesUsed(layout) == 0);
+
+ h.list.setSortingGroup(31, {6, 0, false, 0});
+ hidden.entity = Entity(31);
+ appendIndexedDraw(h.pool, h.list, h.clips, verts, 4, BATCH_QUAD_INDICES, 6, hidden);
+ CHECK(h.list.commandCount() == 1);
+ CHECK(h.pool.vertexBytesUsed(layout) == 4 * h.pool.vertexStride(layout));
+ CHECK(h.pool.indicesUsed(layout) == 6);
+ }
+}
+
+TEST_CASE("camera mask: resident geometry skips excluded indices with both source widths") {
+ Harness h;
+ h.list.setCullingMask(1u << 6);
+ BatchVertex quad[4] = {};
+ const u32 offset = h.pool.appendVertices(LayoutId::Batch, quad, sizeof(quad));
+ const u16 indices16[] = {0, 1, 2, 2, 3, 0};
+ auto hidden = quadKey(1, 4);
+ pushBatchCommand(h.pool, h.list, h.clips, offset, 4, BATCH_QUAD_INDICES, 6, hidden);
+ pushBatchCommand(h.pool, h.list, h.clips, offset, 4, indices16, 6, hidden);
+ CHECK(h.pool.indicesUsed(LayoutId::Batch) == 0);
+ CHECK(h.pool.vertexBytesUsed(LayoutId::Batch) == sizeof(quad));
+ CHECK(h.list.commandCount() == 0);
+ hidden.cullBit = 1u << 6;
+ pushBatchCommand(h.pool, h.list, h.clips, offset, 4, indices16, 6, hidden);
+ CHECK(h.pool.indicesUsed(LayoutId::Batch) == 6);
+ CHECK(h.list.commandCount() == 1);
+ auto excludedGroup = quadKey(1, 6);
+ excludedGroup.entity = Entity(32);
+ h.list.setSortingGroup(32, {4, 0, false, 0});
+ appendQuad(h.pool, h.list, h.clips, quad, excludedGroup);
+ auto excludedBit = quadKey(1, 6);
+ excludedBit.cullBit = 1u << 4;
+ appendQuad(h.pool, h.list, h.clips, quad, excludedBit);
+ CHECK(h.pool.vertexBytesUsed(LayoutId::Batch) == sizeof(quad));
+ CHECK(h.pool.indicesUsed(LayoutId::Batch) == 6);
+ CHECK(h.list.commandCount() == 1);
+ appendQuad(h.pool, h.list, h.clips, quad, quadKey(1, -1));
+ CHECK(h.pool.indicesUsed(LayoutId::Batch) == 12);
+ CHECK(h.list.commandCount() == 2);
+}
+
TEST_CASE("finalize: full texture slots reject index copies but allow existing textures") {
for (bool masked : {false, true}) {
for (bool reuse : {false, true}) {
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 5110b3980..683c6b2d7 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -28,6 +28,8 @@ export const NOTES_FLOOR = 'v0.65.0';
* the reader recognises anyway.
*/
export const NOTED = {
+ 'perf(renderer): cull bulk draws before staging geometry':
+ { note: 'Camera-excluded bulk draws skip transient geometry.' },
'perf(renderer): reject full texture runs before copying indices':
{ note: 'Full texture batches avoid unused index copies.' },
'fix(examples): distinguish motion requests from sensor samples':