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(render): a frame whose shadow casters, lights and camera are those of the frame that drew the shadow map does not collect the map again - before the shadow collect, each casting plugin gives one number for what it would read (the mesh plugin: whether any caster's Transform, MeshRenderer or the components beside it changed since it last looked, found from the stamps alone, and the material, mesh and program revisions), and with the views and the camera they decide whether the collect would come back with the key the atlas holds; with the change audit on the collect is made anyway and a different key is counted

yhh4385ca487d49
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c57d455d0..909285f7a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -54,6 +54,7 @@ published separately; it ships inside the editor.
- **A model's report is its steps as written, and names a step that undoes a decimate.** `report.steps` of a baked model listed every plain step its repeats came to, by an index among those: a spruce of thirteen rows of branches reported a hundred and thirty-eight steps, most the same line, and none under the index `model_edit` takes. It is now one entry for each step as written, by that index, a repeat counted once with how many steps it `made`, and each entry says the `triangles` the mesh had after it. And a step that splits faces to carry its own detail (a stain by a pattern, a displace, a sculpt) after a `decimate` took the decimate's triangles back in silence: a rock thinned to 1100 came out at 214,534, under the 300,000 the report calls heavy, and a field of them would have been gigabytes. The report now warns of each such step, with what it was given, what it left and which decimate it undid, and says how to keep the detail (before the decimate, carried by `normalBake`) or bound it (`detail`). The test also notes what the advice costs: a pattern stained before a decimate leaves colour seams the decimate will not cross, so it is `normalBake`'s `color: true` that carries it.
- **A playable's start-screen bar moves through the whole boot.** The bar's stages were weighed for a web page, most of whose start is fetching the engine. A playable has the engine inlined, so its bar stood at 82% within a second and crawled to 95% over the twenty-five that followed. A playable now weighs its own stages (the scene's is four fifths of the bar), and that stage is followed in three stretches: assets being read and made (eased by the clock, since nothing counts them), shaders compiled against the most seen compiling, and the world prepared against the most its makers said was left. For that, a hold given to `holdShaderWarmup` may answer a number (pages, cells) where it answered yes, and `warmShaders` passes the sum to `onProgress`; Terrain and Foliage count theirs. One lake scene's bar went from 18% to 95% over its 22 seconds, with one stretch of four seconds standing still. `attachSplash` takes the weights.
- **An effect chain keeps its uniform buffers from frame to frame.** A camera's post-process chain is said again every frame, and each of its passes made a uniform buffer for its parameters and deleted it when the chain was cleared: seventeen buffers created and seventeen deleted every frame for a lake scene with a volume's usual effects, counted in the GL calls of an exported page. The buffers of a cleared chain are now taken over by the passes of the next chain that need one the same size, and one that nothing has taken in eight clears is deleted. The same scene creates none in a steady frame.
+- **A still shadow map is not collected again.** A frame whose shadow map held what it would draw no longer drew it, but still walked every caster to find that out. Before the walk, each plugin that casts now gives one number for what its walk would read, and the frame adds the shadow views, the camera and the device's state: when that matches the number of the frame that drew the map, the walk is skipped and the map stands. The mesh plugin's number moves when a caster's Transform is written (found by a pass over the Transform stamps, so a camera or a sprite moving does not count), when a MeshRenderer, MeshSkin, MeshMorph, MeshInstances, LODGroup, Billboard, Impostor or MeshLightmap is written, added or removed, when an entity is enabled or disabled, and when a material, a mesh or a mesh program is changed or built (`MaterialStore::revision`, `ResourceManager::meshesRevision`, new). A scene with a level-of-detail group always walks: what a group casts follows the levels the camera settled on in its last frames. With the change audit on the walk is always made, and a matching number with a different result is logged and counted (`render.shadow.inputsStale`); `render.shadow.collectSkipped` says a frame skipped it. On Bistro at 640x360 the shadow declaration went from 12.7% of the sampled frame to 0.3%, the collect from 0.5 to 0.3 ms and the renderer's CPU time from 1.0 to 0.8 ms. With the audit on, 20 examples found no frame whose inputs matched while its walk differed; Bistro, Dusk Fort, Lighting 3D and Neon Ascension skip it, and where a frame cannot, `render.shadow.collectWhy` and `render.mesh.castChanged` say why (a caster that moves, a skin's joints, a level-of-detail group). With the scan of the casters' Transforms taken out, device-quality and cyber-rooftop reported every audited frame.
- **A mesh's draw keeps what no view changes.** Every view of every frame derived each mesh's world box, model matrix, normal matrix, material lookups and program facts again, and looked up its motion pose three times in a hash map. What does not depend on the view is now kept per entity and used until something it came from changes: the entity's Transform or MeshRenderer is written (its change stamp), its mesh is realized again (the mesh's revision), its material changes or any material is added or removed (`MaterialStore::revision`, new), a Billboard, MeshInstances, LODGroup, Impostor, MeshSkin or MeshMorph is added to or taken from it, or the render origin moves. A mesh with one of those components, a parallax, or a view that overrides the look (wireframe, clay, weights) is derived every walk as before. The motion pass now passes over a static mesh that did not move before culling it. With the change audit on, every kept draw is compared with a fresh derivation and a difference is logged (`render.mesh.proxy.stale`); `render.mesh.proxy.kept` and `.built` count the draws kept and derived again. On Bistro (1,143 meshes) the mesh collect's share of the sampled frame went from 23% to 16%, and the motion pass's walk to nothing measurable. With the audit on, 26 examples (Bistro, physics, streaming worlds, terrain, a rig) found no kept draw that differed; with the check of the Transform's stamp taken out, physics-3d reported 365. A renderer that walks another registry (a scene loaded again) keeps nothing from the last one (`Registry::identity`, new).
- **A run of mesh draws is one call on WebGL2.** Consecutive mesh draws that differ only in which range of a shared buffer they draw and which objects they place (the same program, material, textures and state) were each a call of their own, with two blocks bound for each: where its objects' records start, and the light probes its objects stand in. Where the browser offers `WEBGL_multi_draw`, such a run is now one call: a block staged once for the run says, for each draw, where its records and its instances' probes begin, and the vertex stage finds its own by `gl_DrawID`. A run of draws that carry probe light shares one probe block, so it holds at most as many objects as that block does. WebGPU, and a browser without the extension, draw as before. On Bistro at 640x360 the instanced draw calls a frame went from 538 to 71 plus 73 multi-draw calls, uniform-range binds from 1,022 to 276, and the WebGL calls from about 3,100 to about 1,920; the renderer's CPU time went from 1.2 to 1.1 ms. `render.multiDraw.calls` counts the runs drawn.
- **Meshes of one vertex shape share their buffers.** Every mesh was given a vertex buffer, an index buffer and a vertex layout of its own, and a layout is part of a pipeline's key: a scene of five hundred meshes switched vertex arrays five hundred times a frame, and pipelines with them, though most of its meshes had the same few shapes of vertex. Meshes loaded from an asset now take ranges of shared pages, one page set per vertex shape (pages start at 1 MB and double, so a small game pays for little), and a run of them is drawn without switching vertex array, buffers or pipeline. Indices are rebased onto the page when a mesh is placed, since WebGL2 has no base vertex; a mesh with morph targets (whose deltas are found by vertex number) and a mesh built in the running game keep buffers of their own. After a lost device a page is rebuilt from its meshes' sources, each into a page of the new device. On Bistro at 640x360 the vertex-array binds a frame went from 540 to 55 and the WebGL calls from 3,627 to 3,102, and the renderer's CPU time from 1.6-1.8 ms to 1.2 ms in three runs each (the frame, which something else bounds at this size, stayed at 6.0 ms). `ResourceManager::meshPageCount` and `meshPageBytes` say what the pages hold.
diff --git a/src/esengine/ecs/Registry.hpp b/src/esengine/ecs/Registry.hpp
index 6990cce3b..01dde9184 100644
--- a/src/esengine/ecs/Registry.hpp
+++ b/src/esengine/ecs/Registry.hpp
@@ -220,6 +220,31 @@ public:
return pool && tickAfter(pool->lastChangedTick(), tick);
}
+ /**
+ * @brief Calls @p visit(entity) for each T written or added after @p tick, until it returns true; returns whether one did.
+ * @details A pass over the stamps alone, which sit in one array beside the components: the answer to "did any of the many
+ * that changed matter to me" without a lookup per component. A removal leaves nothing to visit (anyChangedSince
+ * sees it).
+ */
+ template<typename T, typename Visit>
+ bool anyChangedSinceWhere(u32 tick, Visit&& visit) const {
+ const auto* pool = getPool<T>();
+ if (!pool || !tickAfter(pool->lastChangedTick(), tick)) return false;
+ const u32* stamps = pool->changeTicks();
+ const auto& entities = pool->entities();
+ for (usize i = 0, n = entities.size(); i < n; ++i) {
+ if (tickAfter(stamps[i], tick) && visit(entities[i])) return true;
+ }
+ return false;
+ }
+
+ /** @brief How many entities have a T. */
+ template<typename T>
+ usize countOf() const {
+ const auto* pool = getPool<T>();
+ return pool ? pool->size() : 0;
+ }
+
/** @brief The tick of the latest write, addition or removal of any T; 0 when there has been none. */
template<typename T>
u32 lastChangedTick() const {
diff --git a/src/esengine/renderer/RenderTypePlugin.hpp b/src/esengine/renderer/RenderTypePlugin.hpp
index 878c857a5..8f6077c8d 100644
--- a/src/esengine/renderer/RenderTypePlugin.hpp
+++ b/src/esengine/renderer/RenderTypePlugin.hpp
@@ -507,6 +507,14 @@ public:
* depth — so the default is no, and a plugin that casts says so.
*/
virtual bool castsShadows() const { return false; }
+ /**
+ * @brief For a plugin that casts: one number for everything its depth collect reads apart from the shadow views and the
+ * frame's camera, so a frame whose number, views and camera match those of the frame that drew the shadow map
+ * need not collect it again.
+ * @return False when it cannot vouch for what it would read (the frame then collects). Asked once a frame, before the
+ * shadow collect; a plugin may keep what it needs between calls.
+ */
+ virtual bool castInputs(RenderFrameContext& /*ctx*/, ecs::Registry& /*registry*/, u64& /*key*/) { return false; }
/// Whether the Motion collect asks this plugin: what it draws can move by itself, and the picture
/// after it needs to know by how much.
virtual bool drawsMotion() const { return false; }
diff --git a/src/esengine/renderer/frame/RenderFrame.cpp b/src/esengine/renderer/frame/RenderFrame.cpp
index 18898e6dc..c39bef55d 100644
--- a/src/esengine/renderer/frame/RenderFrame.cpp
+++ b/src/esengine/renderer/frame/RenderFrame.cpp
@@ -2562,9 +2562,44 @@ void RenderFrame::declareShadowPass(ecs::Registry& registry) {
// Collected now rather than when the pass runs: whether it runs at all is decided by what it would draw. (Before the camera's
// own collect, as the casters' level of detail always assumed: they cast what the camera settled on last frame.)
- u64 key = 0;
- const bool trusted = collectShadowViews(registry, key);
- shadow_reused_ = trusted && shadow_drawn_valid_ && key == shadow_drawn_key_;
+ // First what the collect would read. The same as what the collect that drew the atlas read, it would come back with the key
+ // the atlas holds, and is not made. With the change audit on it is made all the same, and a different key is a bug: something
+ // the collect reads that the inputs do not say.
+ u64 inputs = 0;
+ const bool vouched = shadowInputs(registry, inputs);
+ const bool inputsMatch = vouched && shadow_drawn_valid_ && shadow_drawn_inputs_valid_ && inputs == shadow_drawn_inputs_;
+ const bool skipped = inputsMatch && !registry.changeAuditEnabled();
+ if (skipped) {
+ shadow_reused_ = true;
+ } else {
+ u64 key = 0;
+ const bool trusted = collectShadowViews(registry, key);
+ shadow_reused_ = trusted && shadow_drawn_valid_ && key == shadow_drawn_key_;
+ if (inputsMatch && !shadow_reused_) {
+ ++shadow_inputs_stale_;
+ if (!warned_shadow_inputs_) {
+ warned_shadow_inputs_ = true;
+ ES_LOG_WARN("change audit: the shadow collect's inputs were those of the frame that drew the atlas, but it drew"
+ " something else - it reads something its inputs do not say");
+ }
+ }
+ if (shadow_reused_) {
+ // The atlas stands, and now also for these inputs.
+ shadow_drawn_inputs_ = inputs;
+ shadow_drawn_inputs_valid_ = vouched;
+ } else {
+ shadow_pending_key_ = key;
+ shadow_pending_trusted_ = trusted;
+ shadow_pending_inputs_ = inputs;
+ shadow_pending_inputs_valid_ = vouched;
+ }
+ }
+ ES_PROFILE_COUNTER("render.shadow.collectSkipped", skipped ? 1u : 0u);
+ // Why a frame could not skip it: 1 a caster could not vouch, 2 the atlas cannot be trusted to stand (a compute-written record, a
+ // material that moves its vertices), 4 the inputs moved (the plugin says which of its own did: render.mesh.castChanged).
+ ES_PROFILE_COUNTER("render.shadow.collectWhy", skipped ? 0u : (!vouched ? 1u : 0u) | (!shadow_drawn_valid_ ? 2u : 0u)
+ | (vouched && shadow_drawn_inputs_valid_ && inputs != shadow_drawn_inputs_ ? 4u : 0u));
+ ES_PROFILE_COUNTER("render.shadow.inputsStale", shadow_inputs_stale_);
ES_PROFILE_COUNTER("render.shadow.reused", shadow_reused_ ? 1u : 0u);
if (shadow_reused_) {
// What this frame drew (nothing) and, apart from it, what the atlas it reads holds: the maps and draws of the frame that drew it.
@@ -2577,8 +2612,6 @@ void RenderFrame::declareShadowPass(ecs::Registry& registry) {
// Recorded by the pass when it runs, not here: a pass the graph culls drew nothing, and its key would vouch for an atlas
// that never held what it says.
shadow_drawn_valid_ = false;
- shadow_pending_key_ = key;
- shadow_pending_trusted_ = trusted;
}
rg::PassDesc shadow;
@@ -2692,6 +2725,48 @@ void RenderFrame::releaseShadowFrameUbos() {
shadow_frame_ubos_.clear();
}
+bool RenderFrame::shadowInputs(ecs::Registry& registry, u64& key) {
+ u64 h = 0xcbf29ce484222325ull;
+ const auto mix = [&h](u64 v) { h ^= v + 0x9e3779b97f4a7c15ull + (h << 6) + (h >> 2); };
+ const auto words = [&mix](const void* data, usize bytes) {
+ const auto* p = static_cast<const u8*>(data);
+ usize at = 0;
+ for (; at + 8 <= bytes; at += 8) { u64 w; std::memcpy(&w, p + at, 8); mix(w); }
+ u64 tail = 0;
+ if (at < bytes) { std::memcpy(&tail, p + at, bytes - at); mix(tail); }
+ };
+ // Every caster is asked, whether or not an earlier one vouched: each keeps its own look at what changed.
+ bool vouched = true;
+ auto ctx = makeContext();
+ ctx.purpose = RenderPurpose::ShadowDepth;
+ for (auto& plugin : plugins_) {
+ if (!plugin->castsShadows()) continue;
+ u64 part = 0;
+ if (!plugin->castInputs(ctx, registry, part)) vouched = false;
+ mix(part);
+ }
+ // What the collect reads besides the casters: where each square is and what it looks through, the camera (a sun's casters are
+ // culled to what can shade what it sees), and what makes the same handles draw something else.
+ mix(device_.deviceGeneration());
+ mix(device_.geometryWrites());
+ mix(static_cast<u64>(shadow_target_ ? static_cast<u32>(shadow_target_->handle()) : 0u));
+ mix(shadow_views_.size());
+ for (const ShadowView& view : shadow_views_) {
+ words(&view.view_projection, sizeof(glm::mat4));
+ mix((static_cast<u64>(view.x) << 32) | view.y);
+ mix(view.size);
+ mix(view.sun ? 1u : 0u);
+ words(&view.ray, sizeof(view.ray));
+ words(&view.floorY, sizeof(view.floorY));
+ words(&view.reachCap, sizeof(view.reachCap));
+ }
+ words(&view_projection_, sizeof(glm::mat4));
+ mix(shadow_receiver_cull_ ? 1u : 0u);
+ mix(view_id_);
+ key = h;
+ return vouched;
+}
+
bool RenderFrame::collectShadowViews(ecs::Registry& registry, u64& key) {
u32 shadowCastersCulled = 0;
const usize viewCount = shadow_views_.size();
@@ -2801,6 +2876,8 @@ void RenderFrame::executeShadowPass() {
const usize viewCount = shadow_views_.size();
shadow_drawn_key_ = shadow_pending_key_;
shadow_drawn_valid_ = shadow_pending_trusted_;
+ shadow_drawn_inputs_ = shadow_pending_inputs_;
+ shadow_drawn_inputs_valid_ = shadow_pending_inputs_valid_;
shadow_pool_.upload();
for (usize vi = 0; vi < viewCount; ++vi) {
diff --git a/src/esengine/renderer/frame/RenderFrame.hpp b/src/esengine/renderer/frame/RenderFrame.hpp
index 15efe7fff..6594215e4 100644
--- a/src/esengine/renderer/frame/RenderFrame.hpp
+++ b/src/esengine/renderer/frame/RenderFrame.hpp
@@ -1225,6 +1225,17 @@ private:
bool shadow_pending_trusted_ = false;
/// The frame's own answer, from collectShadowViews to the pass that draws (or does not).
bool shadow_reused_ = false;
+ /// What the collect that made shadow_drawn_key_ read (shadowInputs), when every caster vouched for it: a frame whose inputs
+ /// match need not collect at all, since the collect would come back with the key the atlas already holds.
+ u64 shadow_drawn_inputs_ = 0;
+ bool shadow_drawn_inputs_valid_ = false;
+ u64 shadow_pending_inputs_ = 0;
+ bool shadow_pending_inputs_valid_ = false;
+ /// Frames the change audit found the inputs matching while the collect did not (render.shadow.inputsStale): a bug.
+ u32 shadow_inputs_stale_ = 0;
+ bool warned_shadow_inputs_ = false;
+ /** @brief One number for what the shadow collect reads, or false when a caster cannot say. */
+ bool shadowInputs(ecs::Registry& registry, u64& key);
u32 shadow_casters_culled_ = 0;
/// The maps and draws the atlas holds, from the frame that last drew it (render.shadow.heldTiles / heldDraws).
u32 shadow_held_tiles_ = 0;
diff --git a/src/esengine/renderer/plugins/MeshPlugin.cpp b/src/esengine/renderer/plugins/MeshPlugin.cpp
index 3b1da07e6..68d7d5904 100644
--- a/src/esengine/renderer/plugins/MeshPlugin.cpp
+++ b/src/esengine/renderer/plugins/MeshPlugin.cpp
@@ -391,6 +391,7 @@ void MeshPlugin::init(RenderFrameContext& ctx) {
proxies_.clear();
proxy_slot_.clear();
++proxy_epoch_;
+ ++cast_serial_;
// The base variant now, so a broken shader is a boot-time failure rather than
// one that waits for the first mesh; the rest compile when a draw asks.
meshProgram(ctx, 0);
@@ -417,6 +418,7 @@ u32 MeshPlugin::meshProgram(RenderFrameContext& ctx, u32 variant) {
// that needs a variant pays for it. WHICH one is the other half — a readiness
// that missed a requirement is named by the key that had to be built late.
++compiled_this_frame_;
+ ++programs_built_;
last_compiled_variant_ = variant;
std::vector<std::string> features;
@@ -592,6 +594,65 @@ void MeshPlugin::trackPose(Pose& pose, const RenderFrameContext& ctx, const glm:
pose.origin = renderOrigin();
}
+bool MeshPlugin::castInputs(RenderFrameContext& ctx, ecs::Registry& registry, u64& key) {
+ const u32 now = registry.beginChangeRead();
+ // Why the casters changed, one bit a reason (render.mesh.castChanged): what a frame that could not keep its shadow map reads.
+ u32 why = 0;
+ if (registry.identity() != cast_registry_) why |= 1u;
+ if (registry.activityEpoch() != cast_activity_) why |= 2u;
+ if (why == 0) {
+ const u32 since = cast_tick_;
+ // A write to anything a caster is described by, or one added or removed: these are rare enough to take whole.
+ if (registry.anyChangedSince<ecs::MeshRenderer>(since)) why |= 4u;
+ if (registry.anyChangedSince<ecs::MeshSkin>(since) || registry.anyChangedSince<ecs::MeshMorph>(since)) why |= 8u;
+ if (registry.anyChangedSince<ecs::MeshInstances>(since) || registry.anyChangedSince<ecs::LODGroup>(since)
+ || registry.anyChangedSince<ecs::Billboard>(since) || registry.anyChangedSince<ecs::Impostor>(since)
+ || registry.anyChangedSince<ecs::MeshLightmap>(since)) {
+ why |= 16u;
+ }
+ // Transforms move all the time, most of them not a caster's (a camera, a sprite). A removal is not visited, but takes a
+ // mesh's Transform only with its entity, whose MeshRenderer goes too. A skin is placed by its joints, which are anyone.
+ if (why == 0 && registry.countOf<ecs::MeshSkin>() > 0) {
+ if (registry.anyChangedSince<ecs::Transform>(since)) why |= 32u;
+ } else if (why == 0) {
+ if (registry.anyChangedSinceWhere<ecs::Transform>(since, [&](Entity e) { return registry.has<ecs::MeshRenderer>(e); })) {
+ why |= 64u;
+ }
+ }
+ }
+ if (registry.countOf<ecs::LODGroup>() > 0) why |= 128u;
+ ES_PROFILE_COUNTER("render.mesh.castChanged", why);
+ if (why & 127u) ++cast_serial_;
+ cast_registry_ = registry.identity();
+ cast_activity_ = registry.activityEpoch();
+ cast_tick_ = now;
+ // A group casts the level the camera settled on in its last frames, which moves with no write at all.
+ if (registry.countOf<ecs::LODGroup>() > 0) return false;
+
+ u64 h = 0xcbf29ce484222325ull;
+ const auto mix = [&h](u64 v) { h ^= v + 0x9e3779b97f4a7c15ull + (h << 6) + (h >> 2); };
+ mix(cast_serial_);
+ mix(registry.identity());
+ mix(ctx.materials ? ctx.materials->revision() : 0);
+ mix(ctx.materials ? ctx.materials->builtVariantCount() : 0);
+ mix(ctx.resources.meshesRevision());
+ mix(programs_built_);
+ mix(ctx.render_context.programEpoch());
+ mix(ctx.environment_texture_id != 0 ? 1u : 0u);
+ mix(ctx.batch_shader_id);
+ mix(ctx.white_texture_id);
+ const glm::dvec3 origin = renderOrigin();
+ u64 bits[3];
+ std::memcpy(bits, &origin, sizeof(bits));
+ mix(bits[0]); mix(bits[1]); mix(bits[2]);
+ // Distance-limited placements measure from the scene camera, in a shadow map too.
+ u32 eye[3];
+ std::memcpy(eye, &ctx.view_eye, sizeof(eye));
+ mix(ctx.has_view_eye ? (static_cast<u64>(eye[0]) << 32 | eye[1]) ^ (static_cast<u64>(eye[2]) << 16) : 0u);
+ key = h;
+ return true;
+}
+
void MeshPlugin::deriveProxy(RenderCollectContext& collect, MeshProxy& proxy, Entity entity, const ecs::MeshRenderer& mesh,
ecs::Transform& transform, u8 present, u32 now) {
auto& ctx = collect.frame_context;
diff --git a/src/esengine/renderer/plugins/MeshPlugin.hpp b/src/esengine/renderer/plugins/MeshPlugin.hpp
index 8d43ead8b..4cb99848b 100644
--- a/src/esengine/renderer/plugins/MeshPlugin.hpp
+++ b/src/esengine/renderer/plugins/MeshPlugin.hpp
@@ -37,6 +37,7 @@ public:
/// renderable's shadow is ShadowCaster2D's to cast, not the map's.
bool castsShadows() const override { return true; }
bool drawsMotion() const override { return true; }
+ bool castInputs(RenderFrameContext& ctx, ecs::Registry& registry, u64& key) override;
void collect(RenderCollectContext& ctx) override;
RenderPrewarmResult prewarm(RenderFrameContext& ctx, ecs::Registry& registry,
const Entity* entities, u32 count, bool shadowPasses) override;
@@ -157,6 +158,13 @@ private:
ecs::Transform& transform, u32 now, u32 rulesChangedAt);
void deriveProxy(RenderCollectContext& collect, MeshProxy& proxy, Entity entity, const ecs::MeshRenderer& mesh,
ecs::Transform& transform, u8 present, u32 now);
+ /// castInputs: the registry and tick it last looked at, and a count it moves whenever what a caster is changed since.
+ u64 cast_registry_ = 0;
+ u32 cast_tick_ = 0;
+ u32 cast_activity_ = 0;
+ u64 cast_serial_ = 0;
+ /// Programs this plugin has built: a caster asked for one not built before is drawn by another program than last time.
+ u32 programs_built_ = 0;
bool warned_material_ = false; ///< A material on resident geometry is said once.
bool warned_bones_ = false; ///< A skin over the pose budget is said once.
bool warned_lod_ = false; ///< A group that cannot be honoured is said once.
diff --git a/src/esengine/resource/ResourceManager.cpp b/src/esengine/resource/ResourceManager.cpp
index 020a0a072..b8fb14eaf 100644
--- a/src/esengine/resource/ResourceManager.cpp
+++ b/src/esengine/resource/ResourceManager.cpp
@@ -725,6 +725,7 @@ bool ResourceManager::realizeMesh(Mesh& mesh, ConstSpan<u8> vertexBytes, ConstSp
}
mesh.vertexCount = vertexStride > 0 ? static_cast<u32>(vertexBytes.size()) / vertexStride : 0;
mesh.revision = nextRevision();
+ meshes_revision_ = mesh.revision;
// The shapes, last: geometry that draws is worth having even when the deltas
// behind it are refused, and the refusal leaves a mesh in its authored shape
@@ -882,6 +883,7 @@ void ResourceManager::releaseMeshGeometry(VertexBufferHandle vertices, IndexBuff
void ResourceManager::releaseMesh(MeshHandle handle) {
Mesh* mesh = meshes_.get(handle);
if (!mesh) return;
+ meshes_revision_ = nextRevision();
releaseMeshGeometry(mesh->vertices, mesh->indices, mesh->layout, mesh->arenaPage, mesh->arenaFirstVertex,
mesh->vertexCount, mesh->firstIndex, mesh->indexCount);
releaseIndexBuffer(mesh->edges);
diff --git a/src/esengine/resource/ResourceManager.hpp b/src/esengine/resource/ResourceManager.hpp
index c2b0c4510..a261b6d5d 100644
--- a/src/esengine/resource/ResourceManager.hpp
+++ b/src/esengine/resource/ResourceManager.hpp
@@ -542,6 +542,12 @@ public:
/** @brief Releases a mesh and the buffers it owns. */
void releaseMesh(MeshHandle handle);
+ /**
+ * @brief Changes whenever any mesh is realized (each takes a new Mesh::revision) or released: while it holds, every mesh a
+ * reader looked at is the one it was.
+ */
+ u64 meshesRevision() const { return meshes_revision_; }
+
/**
* @brief Replayable meshes whose geometry the device is still waiting for.
* @details Read off the device's ledger, so the list empties exactly when a
@@ -739,6 +745,8 @@ private:
ResourcePool<Mesh> meshes_;
/// The pages meshes of one vertex shape share (see MeshArena).
MeshArena meshArena_;
+ /// See meshesRevision().
+ u64 meshes_revision_ = 0;
/** Gives back what a mesh's geometry holds, its own buffers and layout or its place in a page; the edges are apart. */
void releaseMeshGeometry(VertexBufferHandle vertices, IndexBufferHandle indices, VertexLayoutHandle layout,
u32 arenaPage, u32 arenaFirstVertex, u32 vertexCount, u32 firstIndex, u32 indexCount);
diff --git a/tests/ecs/test_change_stamps.cpp b/tests/ecs/test_change_stamps.cpp
index abc489ea6..b91206800 100644
--- a/tests/ecs/test_change_stamps.cpp
+++ b/tests/ecs/test_change_stamps.cpp
@@ -72,6 +72,26 @@ int main() {
other = Registry{};
CHECK(other.identity() != kept && other.identity() != r.identity(), "and one assigned over another brings its own");
+ // Which of the many that changed: visited by stamp, stopped at the first the visitor wants.
+ {
+ Registry w;
+ const Entity p = w.create(), q = w.create(), s = w.create();
+ w.emplace<Pos>(p); w.emplace<Pos>(q); w.emplace<Pos>(s);
+ w.emplace<Rank>(q);
+ CHECK(w.countOf<Pos>() == 3 && w.countOf<Rank>() == 1 && w.countOf<Listed>() == 0, "countOf counts a pool");
+ const u32 look = w.beginChangeRead();
+ int visited = 0;
+ CHECK(!w.anyChangedSinceWhere<Pos>(look, [&](Entity) { ++visited; return true; }) && visited == 0,
+ "nothing written since, nothing visited");
+ w.patch<Pos>(p);
+ w.patch<Pos>(s);
+ visited = 0;
+ CHECK(!w.anyChangedSinceWhere<Pos>(look, [&](Entity e) { ++visited; return w.has<Rank>(e); }) && visited == 2,
+ "each written one is visited, and none of them is what the visitor wants");
+ w.patch<Pos>(q);
+ CHECK(w.anyChangedSinceWhere<Pos>(look, [&](Entity e) { return w.has<Rank>(e); }), "until one is");
+ }
+
const u32 later = r.beginChangeRead();
r.emplaceOrReplace<Pos>(a);
r.emplaceOrReplace<Pos>(a);
diff --git a/tests/resource/test_mesh_recovery.cpp b/tests/resource/test_mesh_recovery.cpp
index 90a8e1026..3d1148fda 100644
--- a/tests/resource/test_mesh_recovery.cpp
+++ b/tests/resource/test_mesh_recovery.cpp
@@ -285,6 +285,16 @@ int main() {
rematerializeWide(rm, a);
d.createBufferSucceeds = true;
CHECK(rm.getMesh(a)->revision == standing, "a rebuild that failed leaves it as it was");
+
+ // The store's own: the latest realization, or a release.
+ CHECK(rm.meshesRevision() == standing, "the meshes' revision is the last one realized");
+ rm.getMesh(b);
+ CHECK(rm.meshesRevision() == standing, "a look at one changes nothing");
+ rm.releaseMesh(b);
+ CHECK(rm.meshesRevision() != standing, "a release moves it");
+ const u64 released = rm.meshesRevision();
+ rm.releaseMesh(b);
+ CHECK(rm.meshesRevision() == released, "a mesh already gone does not");
}
// --- A texture's revision moves when the device is given new content or sampling for it ---
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 312b21513..fbdf992ae 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -4856,4 +4856,6 @@ export const NOTED = {
{"note": "A terrain's surface can be baked into a runtime virtual texture."},
"perf(render): a mesh's draw keeps what no view changes between frames - where it stands, its world box, its model and normal matrices, its material's say over culling and its program facts are derived once and kept until its Transform or MeshRenderer is written, its mesh realized again, its material changed or the render origin moves; a static mesh that did not move is passed over by the motion pass before its cull, and the change audit checks every kept draw against a fresh one":
{"note": "A mesh's draw keeps what no view changes."},
+ "perf(render): a frame whose shadow casters, lights and camera are those of the frame that drew the shadow map does not collect the map again - before the shadow collect, each casting plugin gives one number for what it would read (the mesh plugin: whether any caster's Transform, MeshRenderer or the components beside it changed since it last looked, found from the stamps alone, and the material, mesh and program revisions), and with the views and the camera they decide whether the collect would come back with the key the atlas holds; with the change audit on the collect is made anyway and a different key is counted":
+ {"note": "A still shadow map is not collected again."},
};