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): reject full texture runs before copying indices
yhhcccf1e539255
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 73337e035..8bc7598b6 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -14,6 +14,10 @@ published separately; it ships inside the editor.## [Unreleased]+### Fixed++- **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### Changeddiff --git a/src/esengine/renderer/draw/DrawList.cpp b/src/esengine/renderer/draw/DrawList.cppindex e0c5b9043..9ccdb0209 100644--- a/src/esengine/renderer/draw/DrawList.cpp+++ b/src/esengine/renderer/draw/DrawList.cpp@@ -147,6 +147,17 @@ void DrawList::finalize(TransientBufferPool& pool) {if (writeIdx > 0) {DrawCommand& head = commands_[writeIdx - 1];blocker = head.mergeBlocker(commands_[i]);+ // Reject a new sampler before moving indices: a full run cannot+ // use that copy. Existing samplers still fit at the slot ceiling.+ if ((blocker == BatchBreak::None || blocker == BatchBreak::IndexGap)+ && head.layout_id == LayoutId::Batch && commands_[i].texture_count >= 1+ && head.texture_count >= MAX_CMD_TEXTURE_SLOTS - mask_2d_slots_) {+ const auto* begin = head.texture_ids;+ const auto* end = begin + head.texture_count;+ if (std::find(begin, end, commands_[i].texture_ids[0]) == end) {+ blocker = BatchBreak::TextureSlots;+ }+ }if (blocker == BatchBreak::IndexGap && head.layout_id == LayoutId::Batch&& joinBatchIndexRanges(pool, head, commands_[i])) {blocker = head.mergeBlocker(commands_[i]);diff --git a/tests/renderer/test_batch_builder.cpp b/tests/renderer/test_batch_builder.cppindex 1d34e888f..f2317d8ab 100644--- a/tests/renderer/test_batch_builder.cpp+++ b/tests/renderer/test_batch_builder.cpp@@ -235,6 +235,34 @@ TEST_CASE("finalize: sorted Batch index gaps merge in painter order with their tCHECK(verts[8].texIndex == 1);}+TEST_CASE("finalize: full texture slots reject index copies but allow existing textures") {+ for (bool masked : {false, true}) {+ for (bool reuse : {false, true}) {+ Harness h;+ if (masked) {+ h.list.reserveMask2DSlots(1);+ h.list.setMask2DTexture(7, 123);+ }+ const u32 budget = MAX_CMD_TEXTURE_SLOTS - (masked ? 1 : 0);+ BatchVertex quad[4] = {};+ appendQuad(h.pool, h.list, h.clips, quad, quadKey(reuse ? 1 : 99, 2));+ for (u32 texture = 1; texture <= budget; ++texture) {+ appendQuad(h.pool, h.list, h.clips, quad, quadKey(texture, 1));+ }+ const u32 emitted = h.pool.indicesUsed(LayoutId::Batch);+ h.list.finalize(h.pool);+ CHECK(h.list.mergedDrawCallCount() == (reuse ? 1 : 2));+ CHECK(h.pool.indicesUsed(LayoutId::Batch) == emitted + (reuse ? 6 : 0));+ CHECK(h.list.command(0).texture_count == budget);+ CHECK(h.list.command(0).index_count == (budget + (reuse ? 1 : 0)) * 6);+ if (!reuse) {+ CHECK(h.list.command(1).index_offset == 0);+ CHECK(h.list.command(1).break_reason == BatchBreak::TextureSlots);+ }+ }+ }+}+TEST_CASE("index range copies survive staging growth and reject unwritten sources") {MockGfxDevice device;TransientBufferPool pool{device};diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex ec2ab2804..5110b3980 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): reject full texture runs before copying indices':+ { note: 'Full texture batches avoid unused index copies.' },'fix(examples): distinguish motion requests from sensor samples':{ note: 'Mobile controls share InputMap and device capability results.' },'feat(examples): refresh sprite rendering with CC0 space art':