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(render): resizing a viewport no longer piles up a set of render targets for every size it passes through
yhh155a618ebd18
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 3d9de7c2b..1bc7b4def 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,6 +16,7 @@ published separately; it ships inside the editor.### Added+- **The editor lets go of a generated world while the game plays.** The game runs in a realm of its own that builds its own copy of a generated world; the editor's copy is released for as long as it runs and made again on Stop, so the two are not held together.- **Plants are instances of one mesh.** A generated world's and a `PlacedFoliage`'s plants no longer merge their vertices a cell at a time: a new `MeshInstances` component places one resident mesh at many places (sixty-four bytes a plant), and the engine culls each plant against the view, takes a cheaper mesh past a distance and draws none past another, as one instanced draw that cells sharing a mesh and a material merge into. The geometry exists once however many plants there are, so a planet's plants take a tenth of the memory and a fraction of the draws, and a cell is grown in microseconds instead of a few milliseconds.- **A project can keep folders out of its asset database.** `assetExclude` in the project manifest names folders (a source-art repository, docs, a server) the asset scan does not index, does not write a `.meta` into and the editor does not watch.- **Small plants need not cast a shadow.** A plant part takes `castShadows: false`, so ground cover too small to be worth a shadow-map draw is left out of the shadow pass.@@ -74,6 +75,7 @@ published separately; it ships inside the editor.### Fixed+- **Resizing a viewport no longer piles up render targets.** A viewport dragged or docked through many sizes borrowed a full set of targets (the scene, its depth, the post chain) at each size and left each idle for two seconds before freeing it, which grew the GPU process to ten gigabytes in a few seconds and lost the graphics context. Targets nobody borrows are now kept within a budget of 256 MB, the longest idle first.- **Many placed objects no longer crash the renderer.** The texture that holds every object's record in a frame grew by doubling but was created from storage sized to the frame's need, so a frame with many objects read past its end and the engine aborted with `memory access out of bounds`; stopping then reported one warning for every entity. The texture is created from storage as tall as itself, and an aborted engine is reported once.- **A cloud's shadow stays where the cloud is.** The shadow a sky's clouds cast on the scene added the camera's position to the cloud's, so it slid across the ground as the camera moved while the cloud in the sky stood still; it is taken from the same place the sky draws the cloud from.- **A leaf or a blade of grass no longer has a pale edge.** A cutout texture (one with a Mip Coverage) has the colour of its solid texels carried into its clear ones when it is cooked, as a model's cutouts already did: what an artist leaves under alpha 0, often white, was averaged in at every leaf's edge by the filter and the mips. The source image is not touched.diff --git a/desktop b/desktopindex e5c073298..3e2986799 160000--- a/desktop+++ b/desktop@@ -1 +1 @@-Subproject commit e5c073298407fcf86bfb1717874d5379d8c1b895+Subproject commit 3e2986799950a44f583a289930c7497b3160f22cdiff --git a/examples/ecs-basics/tsconfig.json b/examples/ecs-basics/tsconfig.jsonindex 105dd19fa..2935d11cc 100644--- a/examples/ecs-basics/tsconfig.json+++ b/examples/ecs-basics/tsconfig.json@@ -12,6 +12,33 @@"rootDir": ".","paths": {"esengine": ["./.esengine/sdk/index.d.ts"],+ "esengine/spine": ["./.esengine/sdk/spine/index.d.ts"],+ "esengine/tilemap": ["./.esengine/sdk/tilemap/index.d.ts"],+ "esengine/terrain": ["./.esengine/sdk/terrain/index.d.ts"],+ "esengine/timeline": ["./.esengine/sdk/timeline/index.d.ts"],+ "esengine/fx-basic": ["./.esengine/sdk/fx-basic/index.d.ts"],+ "esengine/fx-atmosphere": ["./.esengine/sdk/fx-atmosphere/index.d.ts"],+ "esengine/fx-lighting": ["./.esengine/sdk/fx-lighting/index.d.ts"],+ "esengine/foliage": ["./.esengine/sdk/foliage/index.d.ts"],+ "esengine/worldgen": ["./.esengine/sdk/worldgen/index.d.ts"],+ "esengine/water": ["./.esengine/sdk/water/index.d.ts"],+ "esengine/spline": ["./.esengine/sdk/spline/index.d.ts"],+ "esengine/character-shaders": ["./.esengine/sdk/character-shaders/index.d.ts"],+ "esengine/logic": ["./.esengine/sdk/logic/index.d.ts"],+ "esengine/debug-channel": ["./.esengine/sdk/debug-channel/index.d.ts"],+ "esengine/ai": ["./.esengine/sdk/ai/index.d.ts"],+ "esengine/replication": ["./.esengine/sdk/net/replication/index.d.ts"],+ "esengine/gameplay": ["./.esengine/sdk/gameplay/index.d.ts"],+ "esengine/dragonbones": ["./.esengine/sdk/dragonbones/index.d.ts"],+ "esengine/physics": ["./.esengine/sdk/physics/index.d.ts"],+ "esengine/physics3d": ["./.esengine/sdk/physics3d/index.d.ts"],+ "esengine/douyin": ["./.esengine/sdk/douyin/index.d.ts"],+ "esengine/kuaishou": ["./.esengine/sdk/kuaishou/index.d.ts"],+ "esengine/bilibili": ["./.esengine/sdk/bilibili/index.d.ts"],+ "esengine/quickgame": ["./.esengine/sdk/quickgame/index.d.ts"],+ "esengine/alipay": ["./.esengine/sdk/alipay/index.d.ts"],+ "esengine/huawei": ["./.esengine/sdk/huawei/index.d.ts"],+ "esengine/openpaas": ["./.esengine/sdk/openpaas/index.d.ts"],"estella-plugin-*": ["./.esengine/packages/*"],"esengine/wasm": ["./.esengine/sdk/wasm.d.ts"]}diff --git a/examples/terrain-water/tsconfig.json b/examples/terrain-water/tsconfig.jsonindex b139bb0df..820149aa4 100644--- a/examples/terrain-water/tsconfig.json+++ b/examples/terrain-water/tsconfig.json@@ -14,6 +14,7 @@"esengine": ["./.esengine/sdk/index.d.ts"],+ "esengine/worldgen": ["./.esengine/sdk/worldgen/index.d.ts"],"esengine/spine": ["./.esengine/sdk/spine/index.d.ts"],"esengine/tilemap": ["./.esengine/sdk/tilemap/index.d.ts"],"esengine/terrain": ["./.esengine/sdk/terrain/index.d.ts"],diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.mdindex 486ad4540..ebe36e47b 100644--- a/sdk/etc/index.api.md+++ b/sdk/etc/index.api.md@@ -7356,6 +7356,7 @@ set: <T>(id: string, def: ChunkLayer<T>) => voidstateAt: (id: string, x: number, z: number) => ChunkState | nullstatus: (id: string) => ChunkLayerStatus | nullstep: (hasTime: () => boolean) => void+suspended: booleanstatic new (): ProceduralChunksstatic prototype: ProceduralChunks```diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.mdindex fdf3bcfac..478a3ba00 100644--- a/sdk/etc/index.native.api.md+++ b/sdk/etc/index.native.api.md@@ -7559,6 +7559,7 @@ set: <T>(id: string, def: ChunkLayer<T>) => voidstateAt: (id: string, x: number, z: number) => ChunkState | nullstatus: (id: string) => ChunkLayerStatus | nullstep: (hasTime: () => boolean) => void+suspended: booleanstatic new (): ProceduralChunksstatic prototype: ProceduralChunks```diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.mdindex 89648e452..4524c04cf 100644--- a/sdk/etc/index.node.api.md+++ b/sdk/etc/index.node.api.md@@ -7351,6 +7351,7 @@ set: <T>(id: string, def: ChunkLayer<T>) => voidstateAt: (id: string, x: number, z: number) => ChunkState | nullstatus: (id: string) => ChunkLayerStatus | nullstep: (hasTime: () => boolean) => void+suspended: booleanstatic new (): ProceduralChunksstatic prototype: ProceduralChunks```diff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.mdindex f2654a543..7f595c697 100644--- a/sdk/etc/minigame.api.md+++ b/sdk/etc/minigame.api.md@@ -7644,6 +7644,7 @@ set: <T>(id: string, def: ChunkLayer<T>) => voidstateAt: (id: string, x: number, z: number) => ChunkState | nullstatus: (id: string) => ChunkLayerStatus | nullstep: (hasTime: () => boolean) => void+suspended: booleanstatic new (): ProceduralChunksstatic prototype: ProceduralChunks```diff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.mdindex 2e91e2d0f..d891f77c7 100644--- a/sdk/etc/wechat.api.md+++ b/sdk/etc/wechat.api.md@@ -7358,6 +7358,7 @@ set: <T>(id: string, def: ChunkLayer<T>) => voidstateAt: (id: string, x: number, z: number) => ChunkState | nullstatus: (id: string) => ChunkLayerStatus | nullstep: (hasTime: () => boolean) => void+suspended: booleanstatic new (): ProceduralChunksstatic prototype: ProceduralChunks```diff --git a/sdk/src/residency/chunks.ts b/sdk/src/residency/chunks.tsindex cf97eae18..b239da2ad 100644--- a/sdk/src/residency/chunks.ts+++ b/sdk/src/residency/chunks.ts@@ -106,6 +106,8 @@ export class ProceduralChunks {private readonly layers_ = new Map<string, Layer<unknown>>();/** @internal Set by the plugin: the world's own sources, sampled once a frame. */sources_: () => ChunkSource[] = () => [];+ /** True while something else is showing this world (the editor's play realm has its own): no place is wanted, so every chunk is let go. */+ suspended = false;/** Adds a layer under `id`, or takes the new definition of one already there (its chunks stay and follow the new generation). */set<T>(id: string, def: ChunkLayer<T>): void {@@ -184,7 +186,7 @@ export class ProceduralChunks {* stands in at once and the rest while `hasTime` says so.*/step(hasTime: () => boolean): void {- const world = this.sources_();+ const world = this.suspended ? [] : this.sources_();const wanted: { layer: Layer<unknown>; cx: number; cz: number; dist: number }[] = [];for (const layer of this.layers_.values()) {const d = layer.def;diff --git a/src/esengine/renderer/graph/TargetPool.cpp b/src/esengine/renderer/graph/TargetPool.cppindex 941b65584..da0df2cca 100644--- a/src/esengine/renderer/graph/TargetPool.cpp+++ b/src/esengine/renderer/graph/TargetPool.cpp@@ -146,6 +146,23 @@ void TargetPool::age() {++entry.generation;}}+ // A viewport that is being resized borrows a new shape every tick and leaves the last one idle: two seconds of that is a hundred+ // sets of targets. What sits idle past the budget goes at once, the longest idle first, whatever its age.+ u64 idleBytes = 0;+ for (const auto& entry : entries_) {+ if (entry.fbo && !entry.inUse) idleBytes += static_cast<u64>(entry.shape.width) * entry.shape.height * texelBytes(entry.shape);+ }+ while (idleBytes > kIdleByteBudget) {+ Entry* oldest = nullptr;+ for (auto& entry : entries_) {+ if (entry.fbo && !entry.inUse && (!oldest || entry.idle > oldest->idle)) oldest = &entry;+ }+ if (!oldest) break;+ idleBytes -= static_cast<u64>(oldest->shape.width) * oldest->shape.height * texelBytes(oldest->shape);+ oldest->fbo.reset();+ oldest->idle = 0;+ ++oldest->generation;+ }}void TargetPool::clear() {diff --git a/src/esengine/renderer/graph/TargetPool.hpp b/src/esengine/renderer/graph/TargetPool.hppindex daae346dc..7eb2988ad 100644--- a/src/esengine/renderer/graph/TargetPool.hpp+++ b/src/esengine/renderer/graph/TargetPool.hpp@@ -121,6 +121,9 @@ public:*/static constexpr u32 kIdleTicksBeforeEvict = 120;+ /** @brief Bytes of unborrowed targets the pool keeps, whatever their age: past it the longest idle are destroyed. */+ static constexpr u64 kIdleByteBudget = 256ull * 1024 * 1024;+private:struct Entry {Unique<Framebuffer> fbo;diff --git a/tests/renderer/test_render_graph.cpp b/tests/renderer/test_render_graph.cppindex 9037b1c40..217b8166f 100644--- a/tests/renderer/test_render_graph.cpp+++ b/tests/renderer/test_render_graph.cpp@@ -410,6 +410,24 @@ int main() {CHECK(pool.count() == 0, "and once given back it ages out like anything else");}+ // --- a resize leaves a target of every size behind, and the pool does not keep them all ---+ {+ MockGfxDevice d;+ rg::TargetPool pool(d);+ rg::TargetShape shape;+ shape.format = GfxPixelFormat::RGBA16F;+ // A window dragged through two hundred sizes, one borrowed and given back each tick.+ for (u32 size = 0; size < 200; ++size) {+ shape.width = 1000 + size * 3;+ shape.height = 800 + size * 2;+ pool.release(pool.acquire(shape));+ pool.age();+ }+ CHECK(pool.bytes() <= rg::TargetPool::kIdleByteBudget + 64ull * 1024 * 1024,+ "idle targets are kept within a byte budget, not for two seconds each");+ CHECK(pool.count() < 200, "and the sizes the window has left are gone");+ }+// --- a handle outliving its target names nothing, not the next thing ---{MockGfxDevice d;diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex f6e6fa9db..d3840ba61 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -2900,6 +2900,10 @@ export const NOTED = {{"note":"Many placed objects no longer crash the renderer."},"fix(terrain): the paint weights stay exported from the terrain plugin module":{"internal":"A re-export the module split dropped."},+ "fix(render): resizing a viewport no longer piles up a set of render targets for every size it passes through":+ {"note":"Resizing a viewport no longer piles up render targets."},+ "feat(editor): the edit world lets go of a generated world while the game plays":+ {"note":"The editor lets go of a generated world while the game plays."},"feat(assets): a project names folders its asset database leaves alone":{"note":"A project can keep folders out of its asset database."},"feat(worldgen): a plant part may cast no shadow, and far cells are capped at two cells wide":