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
fix(renderer): preserve depth bias and buffer identity in batch merges
yhhb4ac36d70793
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 93e975abb..ab1b3f196 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -24,6 +24,8 @@ published separately; it ships inside the editor.### Fixed+- **Batch merging preserves depth bias and geometry bindings.** Non-instanced commands with different depth offsets, vertex/index buffers or vertex layouts now stay separate, preventing one draw from inheriting another's GPU state even when their index ranges are adjacent.+- **Sorted 2D batches join across emission index gaps.** Compatible transient quads reuse contiguous index ranges in painter order even when their producers emitted them apart, reducing UI and text draw calls without combining different clipping states or external buffers. Mixed sprite/text batches retain their original per-type entity statistics.- **Runtime hierarchy inspection follows native parent additions and removals.** The tree and selected details use current component membership before reading a parent, so native edits appear immediately even when the SDK's cached hierarchy membership is stale. Detaching a node clears its parent instead of reporting the empty getter's sentinel; disabled nodes remain included.diff --git a/src/esengine/renderer/draw/DrawCommand.hpp b/src/esengine/renderer/draw/DrawCommand.hppindex 1e6facd14..eb2256371 100644--- a/src/esengine/renderer/draw/DrawCommand.hpp+++ b/src/esengine/renderer/draw/DrawCommand.hpp@@ -372,7 +372,6 @@ struct DrawCommand {if (shader_id != next.shader_id) return BatchBreak::Shader;if (material_id != next.material_id) return BatchBreak::Material;if (cull != next.cull) return BatchBreak::Cull;- if (depth_bias != next.depth_bias) return BatchBreak::Cull;if (depth_bias != next.depth_bias) return BatchBreak::Cull;if (state_flags != next.state_flags) return BatchBreak::State;if (state_flags & CMD_STATE_SCISSOR) {@@ -385,7 +384,8 @@ struct DrawCommand {}if (shader_id != next.shader_id) return BatchBreak::Shader;if (blend_mode != next.blend_mode) return BatchBreak::Blend;- if (layout_id != next.layout_id) return BatchBreak::Layout;+ if (layout_id != next.layout_id || vertex_buffer != next.vertex_buffer+ || index_buffer != next.index_buffer || vertex_layout != next.vertex_layout) return BatchBreak::Layout;// Same material handle => same uniforms/textures; different ones must not// coalesce. material_id 0 (no material) shares the path's defaults, so they still merge.if (material_id != next.material_id) return BatchBreak::Material;@@ -401,6 +401,7 @@ struct DrawCommand {if (depth_test != next.depth_test) return BatchBreak::Depth;if (depth_write != next.depth_write) return BatchBreak::Depth;if (cull != next.cull) return BatchBreak::Cull;+ if (depth_bias != next.depth_bias) return BatchBreak::Cull;if (state_flags != next.state_flags) return BatchBreak::State;if (state_flags & CMD_STATE_SCISSOR) {if (scissor != next.scissor) return BatchBreak::Scissor;@@ -419,4 +420,4 @@ struct DrawCommand {}};-} // namespace esengine\ No newline at end of file+} // namespace esenginediff --git a/tests/renderer/test_batch_builder.cpp b/tests/renderer/test_batch_builder.cppindex abe8e6e8a..1d34e888f 100644--- a/tests/renderer/test_batch_builder.cpp+++ b/tests/renderer/test_batch_builder.cpp@@ -280,6 +280,33 @@ TEST_CASE("finalize: external Batch buffers retain their separate index ranges")CHECK(h.pool.indicesUsed(LayoutId::Batch) == 12);}+TEST_CASE("merge identity: depth bias and geometry bindings must agree") {+ DrawCommand a{}, b{};+ a.shader_id = b.shader_id = 7;+ a.index_count = b.index_count = 6;+ b.index_offset = 6;+ CHECK(a.canMergeWith(b));+ SUBCASE("depth bias") {+ b.depth_bias = 1;+ CHECK_FALSE(a.canMergeWith(b));+ }+ SUBCASE("vertex buffer") {+ a.vertex_buffer = static_cast<BufferHandle>(11);+ b.vertex_buffer = static_cast<BufferHandle>(12);+ CHECK_FALSE(a.canMergeWith(b));+ }+ SUBCASE("index buffer") {+ a.index_buffer = static_cast<BufferHandle>(11);+ b.index_buffer = static_cast<BufferHandle>(12);+ CHECK_FALSE(a.canMergeWith(b));+ }+ SUBCASE("vertex layout") {+ a.vertex_layout = static_cast<VertexLayoutHandle>(11);+ b.vertex_layout = static_cast<VertexLayoutHandle>(12);+ CHECK_FALSE(a.canMergeWith(b));+ }+}+TEST_CASE("finalize: different streams never coalesce; instanced draws stay one per emitter") {Harness h;BatchVertex quad[4] = {};diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex c615a3b27..ec2ab2804 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -32,6 +32,8 @@ export const NOTED = {{ note: 'Mobile controls share InputMap and device capability results.' },'feat(examples): refresh sprite rendering with CC0 space art':{ note: 'Sprite rendering has a complete space art example.' },+ 'fix(renderer): preserve depth bias and buffer identity in batch merges':+ { note: 'Batch merging preserves depth bias and geometry bindings.' },'perf(renderer): coalesce sorted 2d batch index gaps':{ note: 'Sorted 2D batches join across emission index gaps.' },'fix(inspector): read current native parent membership in runtime snapshots':