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(gi): half the probe rows on a phone, and a continuous probe filter - GI on a Snapdragon 8 Elite 20.5 -> 6.4 ms
yhhc5fd8e7b0b59
diff --git a/docs/GI_LUMEN_DESIGN.md b/docs/GI_LUMEN_DESIGN.mdindex 0ee2a4da1..de52a64a4 100644--- a/docs/GI_LUMEN_DESIGN.md+++ b/docs/GI_LUMEN_DESIGN.md@@ -156,6 +156,24 @@下一步:手机降温、空闲时,按 `u_skip` = 8(场景已上传,什么都不声明)、3(只有应用)、16(只有卡面和探针,无应用通道)各跑一次,每次 16 s,中间间隔 30 s。+### 5.3.2 那约 15 ms 找到了(2026-11-11)++之前的 `u_skip` 没有声明、没传进原生,先前那几行扣除数无效;声明之后重跑(同一台手机,帧 p50,关掉 GI 是 7.7):++| 配置 | 帧 | 比上一行 |+|---|---|---|+| 开着 GI 但场景没喂 / 什么都不声明 | 9.4–9.9 | G-buffer 约 +2 |+| 只有应用通道 | 11.7 | +2.3 |+| 卡面 + 应用 | 12.5 | 卡面约 +0.8 |+| 探针 + 应用 | 22.6 | **探针约 +10.9** |+| 全部(默认) | 23.3 | |++探针占了大头,而且不随光线数线性走:每 8 条追 1 条(光线减到 1/4)只省 3.7 ms,探针间距 14→28(探针数 1/4)省 8 ms。拆开是约 4.9 ms 随光线数、约 5.9 ms 随**探针数**(每探针一个 64 线程的工作组加两次共享内存归约,固定开销在手机上很大)。++改动:+- 安卓上探针行数取 45(1200 高时间距 28)而不是 90,探针数为桌面的 1/4;`u_probeSpacing` 可手动指定。手机上 GI 从 20.5 ms 降到 **约 6.4 ms**(帧 14.1,关 GI 为 7.7)。+- 间距变大后画面出现 28 像素的方块:原因不是噪点而是权重在探针集合切换处不连续(最近四个探针之外的、权重还有 0.375 的探针,在跨过 tile 边界时被突然丢掉)。改为最近四个用双线性权重(在 tile 远端恰为 0),只有这四个都不合用时(两面墙的夹角)才用 16 个探针的宽帐篷。方块消失,桌面对 Cycles 的占比不变。+## 5.4 成本断言(2026-11-11)`node tools/gi/check-gi-cost.mjs`(门禁 `gi-cost`,本地范围)。一帧的成本是“工作量 × 设备上每份工作的代价”,第二个因子是设备的(同一份工作,RTX 3 ms,手机 20 ms),第一个因子是引擎的,在 `DynamicGI` 派发通道的地方计数(`DynamicGIStats`,经 `postprocess_giStats` 读回,页面里是 `window.__estellaGIStats()`),两边一样,所以在 GPU 快得看不出差别的机器上也能拦住回归。diff --git a/sdk/src/postprocess/effects.ts b/sdk/src/postprocess/effects.tsindex 417a8effc..d477ca0d6 100644--- a/sdk/src/postprocess/effects.ts+++ b/sdk/src/postprocess/effects.ts@@ -584,6 +584,8 @@ registerEffect({// 0 fits one field to the whole scene. A size (world units) makes three levels, each four times the last, that follow the camera: the// finest holds what is near the eye at this resolution and the others carry the far scene, so a world larger than one window works.// Measuring: skip the cards (1), the probes (2), the apply (4), declare nothing (8), or stop before the apply (16), to read what the rest costs.+ // Pixels between probes; 0 keeps about 160 x 90 of them whatever the size of the picture.+ { name: 'u_probeSpacing', label: 'Probe Spacing', min: 0, max: 64, step: 1, defaultValue: 0 },{ name: 'u_skip', label: 'Skip Passes (profiling)', min: 0, max: 63, step: 1, defaultValue: 0 },{ name: 'u_cellSize', label: 'Field Cell Size', min: 0, max: 1000, step: 0.1, defaultValue: 0, worldUnits: 1 },],diff --git a/src/esengine/renderer/frame/DynamicGI.cpp b/src/esengine/renderer/frame/DynamicGI.cppindex 68e8aa03d..08d96ab7e 100644--- a/src/esengine/renderer/frame/DynamicGI.cpp+++ b/src/esengine/renderer/frame/DynamicGI.cpp@@ -465,11 +465,11 @@ const char* kApply = R"WGSL(@group(0) @binding(12) var probeGeo : texture_2d<f32>;// What one probe says about the pixel at pos facing n: its light by the normal, and how much it should count (plane, then normal).-fn probeTerm(tile : vec2i, q : vec2f, pos : vec3f, n : vec3f, eye : f32, e : ptr<function, vec3f>, w : ptr<function, vec2f>) -> bool {+fn probeTerm(tile : vec2i, q : vec2f, radius : f32, pos : vec3f, n : vec3f, eye : f32, e : ptr<function, vec3f>, w : ptr<function, vec2f>) -> bool {let geo1 = textureLoad(probeGeo, vec2i(tile.x * 2 + 1, tile.y), 0);if (geo1.w < 0.5) { return false; }let d = abs(vec2f(tile) - q);- let tent = max(1.0 - d.x / 1.6, 0.0) * max(1.0 - d.y / 1.6, 0.0);+ let tent = max(1.0 - d.x / radius, 0.0) * max(1.0 - d.y / radius, 0.0);if (tent <= 0.0) { return false; }let geo0 = textureLoad(probeGeo, vec2i(tile.x * 2, tile.y), 0);let plane = abs(dot(n, geo0.xyz - pos)) / (0.02 * eye);@@ -509,19 +509,37 @@ fn main(@builtin(global_invocation_id) id : vec3u) {var total = 0.0;var Erelaxed = vec3f(0.0);var totalRelaxed = 0.0;- for (var k = 0; k < 16; k = k + 1) {- let near = (k & 3) >= 1 && (k & 3) <= 2 && (k >> 2) >= 1 && (k >> 2) <= 2;- if (!near && total > 0.15) { continue; }- let tile = q0 + vec2i(k & 3, k >> 2) - vec2i(1);+ // The four nearest with a bilinear weight, which is nothing at a tile's far edge: that the weights go to zero exactly where the set of+ // probes changes is what keeps the picture from showing the probe grid as squares. Only where those four are on another plane or face+ // another way (the corner of two walls) are the sixteen round them asked, with a wider tent.+ for (var k = 0; k < 4; k = k + 1) {+ let tile = q0 + vec2i(k & 1, k >> 1);if (any(tile < vec2i(0)) || any(tile >= tiles)) { continue; }var e = vec3f(0.0);var w = vec2f(0.0);- if (!probeTerm(tile, q, pos, n, eye, &e, &w)) { continue; }+ if (!probeTerm(tile, q, 1.0, pos, n, eye, &e, &w)) { continue; }E = E + e * w.x;total = total + w.x;Erelaxed = Erelaxed + e * w.y;totalRelaxed = totalRelaxed + w.y;}+ if (total <= 0.15) {+ E = vec3f(0.0);+ total = 0.0;+ Erelaxed = vec3f(0.0);+ totalRelaxed = 0.0;+ for (var k = 0; k < 16; k = k + 1) {+ let tile = q0 + vec2i(k & 3, k >> 2) - vec2i(1);+ if (any(tile < vec2i(0)) || any(tile >= tiles)) { continue; }+ var e = vec3f(0.0);+ var w = vec2f(0.0);+ if (!probeTerm(tile, q, 1.6, pos, n, eye, &e, &w)) { continue; }+ E = E + e * w.x;+ total = total + w.x;+ Erelaxed = Erelaxed + e * w.y;+ totalRelaxed = totalRelaxed + w.y;+ }+ }if (total > 0.05) { E = E / total; } else if (totalRelaxed > 1e-5) { E = Erelaxed / totalRelaxed; } else { E = vec3f(0.0); }textureStore(outTex, p, vec4f(scene.rgb + albedo.rgb * E * gi.sdf.w, scene.a));}@@ -673,7 +691,15 @@ rg::ResourceId DynamicGI::declare(rg::RenderGraph& graph, rg::ResourceId input,if (!upload()) return input;if (params.skip & 8u) return input; // measuring: nothing declared at all// About 160 x 90 probes whatever the size of the picture: 8 pixels apart at 720p, 12 at 1080p, 16 at 1440p. Their cost is in their number.- probeSpacing_ = std::clamp(((height + 89) / 90 + 1) / 2 * 2, 8u, 32u);+ // On a phone half as many rows: the pass costs per probe (a workgroup of 64 rays and its reduction) and a phone has the most pixels+ // and the least to spend, 11 ms of a 23 on a Snapdragon 8 Elite at 160 x 90 probes against 3 at half of that along each axis.+#if defined(__ANDROID__)+ constexpr u32 kProbeRows = 45;+#else+ constexpr u32 kProbeRows = 90;+#endif+ probeSpacing_ = params.probeSpacing > 0 ? std::clamp(params.probeSpacing, 4u, 64u)+ : std::clamp(((height + kProbeRows - 1) / kProbeRows + 1) / 2 * 2, 8u, 32u);const u32 tilesX = (width + probeSpacing_ - 1) / probeSpacing_, tilesY = (height + probeSpacing_ - 1) / probeSpacing_;if (!ensureProbes(tilesX, tilesY)) return input;diff --git a/src/esengine/renderer/frame/DynamicGI.hpp b/src/esengine/renderer/frame/DynamicGI.hppindex 8d20e969f..30ddafff0 100644--- a/src/esengine/renderer/frame/DynamicGI.hpp+++ b/src/esengine/renderer/frame/DynamicGI.hpp@@ -43,6 +43,8 @@ struct DynamicGIParams {u32 probeStride = 2;/// For measuring: skip the cards (1), the probes (2) or the apply (4), to read what the rest of the frame costs.u32 skip = 0;+ /// Pixels between probes: 0 picks about 160 x 90 probes whatever the picture size.+ u32 probeSpacing = 0;};/**diff --git a/src/esengine/renderer/frame/PostProcessPipeline.cpp b/src/esengine/renderer/frame/PostProcessPipeline.cppindex 9f1a93b0b..89487f79b 100644--- a/src/esengine/renderer/frame/PostProcessPipeline.cpp+++ b/src/esengine/renderer/frame/PostProcessPipeline.cpp@@ -1339,6 +1339,7 @@ void PostProcessPipeline::runChain(std::vector<PostProcessPass>& passes, rg::Resgi.cardSlices = static_cast<u32>(std::max(get("u_cardSlices", static_cast<f32>(gi.cardSlices)), 1.0f));gi.probeStride = static_cast<u32>(std::max(get("u_probeStride", static_cast<f32>(gi.probeStride)), 1.0f));gi.skip = static_cast<u32>(std::max(get("u_skip", 0.0f), 0.0f));+ gi.probeSpacing = static_cast<u32>(std::max(get("u_probeSpacing", 0.0f), 0.0f));auto& cache = dynamic_gis_[temporalKey_];if (!cache) {if (dynamic_gis_.size() > 4) {