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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
perf(renderer): skip hidden text and skeletal vertex conversion
yhh8bf1689745f9
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 3edb81b36..0b23e944a 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,6 +16,8 @@ published separately; it ships inside the editor.### Fixed+- **Hidden text and skeletal batches skip vertex conversion.** Camera masks and empty scissors are checked before transforming caller-provided vertices, allocating transient storage or resolving shaders. The same visibility helper preserves SortingGroup layers and explicit text culling bits; visible batches retain their original geometry and per-type statistics.+- **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.diff --git a/src/esengine/renderer/draw/BatchBuilder.cpp b/src/esengine/renderer/draw/BatchBuilder.cppindex d0b665777..c91f93a4a 100644--- a/src/esengine/renderer/draw/BatchBuilder.cpp+++ b/src/esengine/renderer/draw/BatchBuilder.cpp@@ -16,6 +16,14 @@namespace esengine {+bool batchEntityVisible(const DrawList& drawList, const ClipState& clips,+ Entity entity, i32 layer, u32 cullBit) {+ if (clips.isEmptyScissor(entity)) return false;+ if (cullBit) return drawList.layerVisible(cullBit);+ const auto identity = drawList.sortIdentity(entity.id(), layer, 0);+ return drawList.layerVisible(DrawList::layerBit(identity.layer));+}+namespace {// Reused across calls so offsetting local indices into the target stream costs no@@ -24,18 +32,12 @@ 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) || !submissionVisible(drawList, key)) return;+ if (indexCount == 0 || !batchEntityVisible(drawList, clips, key.entity, key.layer, key.cullBit)) return;u32 baseVertex = vertexByteOffset / pool.vertexStride(key.layoutId);g_indexScratch.resize(indexCount);@@ -190,8 +192,8 @@ void appendIndexedDraw(TransientBufferPool& pool, DrawList& drawList, const Clipconst void* verts, u32 vertexCount,const u32* localIndices, u32 indexCount,const BatchDrawKey& key) {- if (vertexCount == 0 || indexCount == 0 || clips.isEmptyScissor(key.entity)- || !submissionVisible(drawList, key)) return;+ if (vertexCount == 0 || indexCount == 0+ || !batchEntityVisible(drawList, clips, key.entity, key.layer, key.cullBit)) 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/src/esengine/renderer/draw/BatchBuilder.hpp b/src/esengine/renderer/draw/BatchBuilder.hppindex c2ff85412..16dcbcbcf 100644--- a/src/esengine/renderer/draw/BatchBuilder.hpp+++ b/src/esengine/renderer/draw/BatchBuilder.hpp@@ -151,6 +151,11 @@ struct BatchDrawKey {u32 lightmapTextureId = 0;};+/// Check before formatting caller-owned vertices, using the same group layer,+/// explicit camera bit and empty-scissor rules as batch submission.+bool batchEntityVisible(const DrawList& drawList, const ClipState& clips,+ Entity entity, i32 layer, u32 cullBit = 0);+/*** @brief Atomic primitive: assemble + clip + push one DrawCommand for an index range ALREADY* written into (or, for instanced draws, static in) the key's stream.diff --git a/src/esengine/renderer/frame/RenderFrameSubmit.cpp b/src/esengine/renderer/frame/RenderFrameSubmit.cppindex 7b5baf9be..e7d426e92 100644--- a/src/esengine/renderer/frame/RenderFrameSubmit.cpp+++ b/src/esengine/renderer/frame/RenderFrameSubmit.cpp@@ -47,7 +47,8 @@ void RenderFrame::submitTextBatch(u32 textureId, const f32* transform16,Entity entity, i32 layer, f32 depth, bool sdf, u32 cullBit) {- if (vertexCount <= 0 || indexCount <= 0) return;+ if (vertexCount <= 0 || indexCount <= 0+ || !batchEntityVisible(draw_list_, clip_state_, entity, layer, cullBit)) return;glm::mat4 model = glm::make_mat4(transform16);@@ -87,7 +88,8 @@ void RenderFrame::submitSkeletalBatch(const f32* transform16,Entity entity, i32 layer, f32 depth, u32 materialId, bool premultipliedColor) {- if (vertexCount <= 0 || indexCount <= 0) return;+ if (vertexCount <= 0 || indexCount <= 0+ || !batchEntityVisible(draw_list_, clip_state_, entity, layer)) return;constexpr i32 FLOATS_PER_VERTEX = 8;glm::mat4 model = glm::make_mat4(transform16);diff --git a/tests/renderer/test_batch_builder.cpp b/tests/renderer/test_batch_builder.cppindex ece4a1b32..565248c8d 100644--- a/tests/renderer/test_batch_builder.cpp+++ b/tests/renderer/test_batch_builder.cpp@@ -14,6 +14,9 @@#include "esengine/renderer/draw/DrawList.hpp"#include "esengine/renderer/store/MaterialStore.hpp"#include "esengine/renderer/rhi/TransientBufferPool.hpp"+#include "esengine/renderer/frame/RenderFrame.hpp"+#include "esengine/renderer/frame/RenderContext.hpp"+#include "esengine/resource/ResourceManager.hpp"#include <functional>#include <utility>@@ -235,6 +238,38 @@ TEST_CASE("finalize: sorted Batch index gaps merge in painter order with their tCHECK(verts[8].texIndex == 1);}+TEST_CASE("camera mask: hidden text and skeletal submissions upload no geometry") {+ MockGfxDevice device;+ RenderContext context(device);+ resource::ResourceManager resources;+ RenderFrame frame(device, context, resources);+ frame.init(64, 64);+ const glm::mat4 transform(1.0f);+ const f32 text[36] = {};+ const f32 skeletal[32] = {};+ const u16 indices[] = {0, 1, 2, 2, 3, 0};+ frame.begin(transform);+ frame.setCullingMask(1u << 6);+ const int uploads = device.updateBufferCalls;+ for (u32 i = 0; i < 1000; ++i) {+ frame.submitTextBatch(text, 4, indices, 6, 1, &transform[0][0], Entity(1), 4, 0, false);+ frame.submitSkeletalBatch(skeletal, 4, indices, 6, 1, 0, &transform[0][0], Entity(2), 4, 0, 0, false);+ }+ frame.flush();+ CHECK(frame.stats().draw_calls == 0);+ CHECK(device.updateBufferCalls == uploads);+ frame.end();+ frame.begin(transform);+ frame.setCullingMask(1u << 6);+ frame.submitTextBatch(text, 4, indices, 6, 1, &transform[0][0], Entity(1), 4, 0, false, 1u << 6);+ frame.submitSkeletalBatch(skeletal, 4, indices, 6, 1, 0, &transform[0][0], Entity(2), 6, 0, 0, false);+ frame.flush();+ CHECK(frame.stats().sprites == 0);+ CHECK(frame.stats().text == 1);+ CHECK(frame.stats().skeletal == 1);+ CHECK(frame.stats().triangles == 4);+}+TEST_CASE("camera mask: excluded bulk geometry does not enter transient streams") {for (LayoutId layout : {LayoutId::Batch, LayoutId::Shape}) {Harness h;diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 683c6b2d7..b07aa173a 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): skip hidden text and skeletal vertex conversion':+ { note: 'Hidden text and skeletal batches skip vertex conversion.' },'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':