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
test(gi): a cost gate for the dynamic GI - the work its passes are asked to do (probe rays, cards relit, reads a pixel, bytes forced on the scene pass), counted at the dispatch and held to budgets on any machine
yhhe26875e83162
diff --git a/docs/GI_LUMEN_DESIGN.md b/docs/GI_LUMEN_DESIGN.mdindex 9bf8cad03..5690e00ca 100644--- a/docs/GI_LUMEN_DESIGN.md+++ b/docs/GI_LUMEN_DESIGN.md@@ -143,6 +143,20 @@- **未查明**:这 15 ms 在哪。候选:场景通道为 G-buffer 和反照率多写两个附件(这在 tile 型 GPU 上按带宽算很贵,体素 GI 也有);应用通道全分辨率读写 RGBA16F;探针通道的固定开销。已加 `u_skip`(1 卡面、2 探针、4 应用)用来逐项扣除,**没有跑完**:手机已经发烫,按用户的话停了。- **发热**:反复以不限帧率连续跑了几分钟,CPU 约 78–80 °C、电池 46.6 °C。之后的测量必须限时、限次,中间让手机降温。+## 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 快得看不出差别的机器上也能拦住回归。++断言(实验房间,默认设置,720p 与 1080p 各跑一次):+- 探针数约 160×90(12000–17000),**不随画面分辨率增长**;探针每帧光线数 = 探针数 × 64 / 步长;720p 每像素探针光线 ≤ 0.6。+- 卡面每帧重新点亮的只是一片(≤ 总数的 0.3)。+- 应用通道每像素的纹理读取 ≤ 25;并且门禁**数内核文本里的 `textureLoad`** 与引擎报的数比对,二者不一致就失败(给内核加一次读取而不改统计,会在这里红;已用变异验证:加一次读取,报“引擎报 24,内核是 28”)。+- 开着这个后效而被迫由场景通道多写的字节(G-buffer 8 + 反照率 4)≤ 12 B/像素;常驻显存 ≤ 64 MB(现为 11.2 MB)。++当前读数:14400 个探针,460,800 条探针光线,卡面 920/3678 一片,每像素 24 次读取,12 B/像素强加给场景通道。++它不能说明的:绝对毫秒。手机上约 15 ms 与光线数无关,那一块是带宽和附件,这里只能管住“被迫多写多少字节”和“每像素读几次”,不能说多少毫秒;每个通道的时间仍要在手机上量。+## 6. 分期每期独立可验收、可回退,期间旧 `voxelGI` 一直可用。diff --git a/sdk/src/ecs/bridge/nativeEngineApi.generated.ts b/sdk/src/ecs/bridge/nativeEngineApi.generated.tsindex 681bf8d60..cdec0c797 100644--- a/sdk/src/ecs/bridge/nativeEngineApi.generated.ts+++ b/sdk/src/ecs/bridge/nativeEngineApi.generated.ts@@ -114,6 +114,7 @@ export interface NativeEngineApi {postprocess_end?(): void;postprocess_endScreenCapture?(): void;postprocess_executeScreenPasses?(): void;+ postprocess_giStats?(dst: number, capacity: number): number;postprocess_hdrFormat?(outPtr: number): number;postprocess_hdrFormatNames?(): string;postprocess_init?(width: number, height: number): boolean;@@ -469,6 +470,7 @@ export function createNativeEngineApi(bind('postprocess_end', 'es_postprocess_end', false);bind('postprocess_endScreenCapture', 'es_postprocess_endScreenCapture', false);bind('postprocess_executeScreenPasses', 'es_postprocess_executeScreenPasses', false);+ bind('postprocess_giStats', 'es_postprocess_giStats', false);bind('postprocess_hdrFormat', 'es_postprocess_hdrFormat', false);bind('postprocess_hdrFormatNames', 'es_postprocess_hdrFormatNames', false);bind('postprocess_init', 'es_postprocess_init', false);diff --git a/sdk/src/gi/dynamicGISystem.ts b/sdk/src/gi/dynamicGISystem.tsindex eb71087e8..054c472be 100644--- a/sdk/src/gi/dynamicGISystem.ts+++ b/sdk/src/gi/dynamicGISystem.ts@@ -146,6 +146,16 @@ export function dynamicGISystem(app: App) {[Query(MeshRenderer, Transform), Query(Light, Transform), Query(PostProcessVolume), Query(Camera, Transform)],(meshes: Iterable<[Entity, MeshRendererData, TransformData]>, lights: Iterable<[Entity, LightData, TransformData]>,volumes: Iterable<[Entity, PostProcessVolumeData]>, cameras: Iterable<[Entity, CameraData, TransformData]>) => {+ // The work counters of the last frame, for a cost gate (tools/gi/check-gi-cost.mjs) and for anyone profiling: where the work is is the engine's,+ // what it costs is the device's.+ (globalThis as { __estellaGIStats?: () => number[] | null }).__estellaGIStats ??= () => {+ const core = marshallingCore(app.wasmModule ?? nativeEngineApi());+ if (!core?.postprocess_giStats) return null;+ return withScratch(core, (alloc) => {+ const ptr = alloc(64);+ return core.postprocess_giStats!(ptr, 16) === 16 ? Array.from(core.HEAPF32.subarray(ptr >> 2, (ptr >> 2) + 16)) : null;+ });+ };const effect = dynamicGIEffect(volumes);if (!effect) { lastKey = ''; follow = null; return; }// The web's module, or a device's host (which answers the same heap from its arena): the arrays cross the boundary through it.diff --git a/sdk/src/wasm.ts b/sdk/src/wasm.tsindex 2acbbc3e8..31e51f202 100644--- a/sdk/src/wasm.ts+++ b/sdk/src/wasm.ts@@ -568,6 +568,7 @@ export interface ESEngineModule {renderer_setProbeVolumeReflection?(entity: number, environmentHandle: number, slot: number): void;postprocess_pollSkyCapture?(): number;postprocess_takeSkyCapture?(dst: number, bytes: number): boolean;+ postprocess_giStats?(dst: number, capacity: number): number;postprocess_setMsaaSamples(samples: number): void;postprocess_effectiveMsaaSamples?(): number;postprocess_maxMsaaSamples?(): number;diff --git a/src/esengine/bindings/PostProcessBindings.cpp b/src/esengine/bindings/PostProcessBindings.cppindex b504981c9..1502dd8f6 100644--- a/src/esengine/bindings/PostProcessBindings.cpp+++ b/src/esengine/bindings/PostProcessBindings.cpp@@ -154,6 +154,17 @@ i32 postprocess_pollSkyCapture() {return g_postProcessPipeline ? g_postProcessPipeline->pollSkyCapture() : 2;}+u32 postprocess_giStats(uintptr_t dst, u32 capacity) {+ if (capacity < kDynamicGIStatFloats) return 0;+ f32* out = boundarySpanMut<f32>(dst, kDynamicGIStatFloats, "postprocess_giStats.out");+ if (!out) return 0;+ const DynamicGIStats& s = dynamicGIStats();+ const f32 v[kDynamicGIStatFloats] = {s.width, s.height, s.probeSpacing, s.probes, s.probeRays, s.cardPixels, s.cardPixelsRelit, s.cardRays,+ s.applyPixels, s.applyLoadsPerPixel, s.forcedAttachmentBytes, s.residentBytes, s.levels, s.lights, s.instances, s.frame};+ std::memcpy(out, v, sizeof(v));+ return kDynamicGIStatFloats;+}+bool postprocess_takeSkyCapture(uintptr_t dst, u32 bytes) {if (!g_postProcessPipeline || dst == 0) return false;const std::vector<u8>& px = g_postProcessPipeline->skyCapturePixels();diff --git a/src/esengine/bindings/PostProcessBindings.hpp b/src/esengine/bindings/PostProcessBindings.hppindex e418633b7..df3778c22 100644--- a/src/esengine/bindings/PostProcessBindings.hpp+++ b/src/esengine/bindings/PostProcessBindings.hpp@@ -66,6 +66,8 @@ void postprocess_requestSkyCapture(const std::string& passName, u32 width, u32 hi32 postprocess_pollSkyCapture();/** Copies the ready capture (RGBA8, rows bottom-up) to @p dst; false when it does not fit @p bytes or is not ready. */bool postprocess_takeSkyCapture(uintptr_t dst, u32 bytes);+/** The dynamic GI's last-frame work counters (DynamicGIStats), written as floats to @p dst; returns how many, 0 when @p capacity is short. */+u32 postprocess_giStats(uintptr_t dst, u32 capacity);void postprocess_setUniformFloat(const std::string& passName,const std::string& uniform, f32 value);void postprocess_setPassTexture(const std::string& passName,diff --git a/src/esengine/bindings/WebSDKEntry.cpp b/src/esengine/bindings/WebSDKEntry.cppindex ac33b3bba..01f5a4bb4 100644--- a/src/esengine/bindings/WebSDKEntry.cpp+++ b/src/esengine/bindings/WebSDKEntry.cpp@@ -613,6 +613,7 @@ EMSCRIPTEN_BINDINGS(esengine_renderer) {emscripten::function("postprocess_requestSkyCapture", &esengine::postprocess_requestSkyCapture);emscripten::function("postprocess_pollSkyCapture", &esengine::postprocess_pollSkyCapture);emscripten::function("postprocess_takeSkyCapture", &esengine::postprocess_takeSkyCapture);+ emscripten::function("postprocess_giStats", &esengine::postprocess_giStats);emscripten::function("postprocess_setMsaaSamples", &esengine::postprocess_setMsaaSamples);emscripten::function("postprocess_effectiveMsaaSamples", &esengine::postprocess_effectiveMsaaSamples);emscripten::function("postprocess_maxMsaaSamples", &esengine::postprocess_maxMsaaSamples);diff --git a/src/esengine/renderer/frame/DynamicGI.cpp b/src/esengine/renderer/frame/DynamicGI.cppindex 24d1c9c64..e14217f34 100644--- a/src/esengine/renderer/frame/DynamicGI.cpp+++ b/src/esengine/renderer/frame/DynamicGI.cpp@@ -17,6 +17,14 @@ DynamicGIScene& dynamicGIScene() {return scene;}+namespace {+DynamicGIStats g_stats;+}++const DynamicGIStats& dynamicGIStats() {+ return g_stats;+}+namespace {constexpr u32 kInstanceVec4 = 20;@@ -733,6 +741,9 @@ rg::ResourceId DynamicGI::declare(rg::RenderGraph& graph, rg::ResourceId input,const u32 slices = std::clamp(p.cardSlices, 1u, 4096u);const u32 chunk = (pixelCount_ + slices - 1) / slices;const u32 active = frame_ < 2 ? pixelCount_ : chunk;+ g_stats.cardPixels = static_cast<f32>(pixelCount_);+ g_stats.cardPixelsRelit = (p.skip & 1u) ? 0.0f : static_cast<f32>(active);+ g_stats.cardRays = g_stats.cardPixelsRelit * 64.0f;if (active == 0 || (p.skip & 1u)) return;device_.dispatchCompute(cardLight_, bindings, 6, std::min(active, 65535u), (active + 65534u) / 65535u);};@@ -747,6 +758,9 @@ rg::ResourceId DynamicGI::declare(rg::RenderGraph& graph, rg::ResourceId input,pass.dependencies = {scene, lit};pass.write = probed;pass.execute = [this, &graph, scene, p](const rg::PassContext&) {+ g_stats.probes = static_cast<f32>(probeTilesX_ * probeTilesY_);+ g_stats.probeSpacing = static_cast<f32>(probeSpacing_);+ g_stats.probeRays = (p.skip & 2u) ? 0.0f : g_stats.probes * 64.0f / static_cast<f32>(std::max(p.probeStride, 1u));if (p.skip & 2u) return;const TextureHandle depth = graph.depthTextureOf(scene);const TextureHandle gbuffer = graph.gbufferTextureOf(scene);@@ -785,6 +799,19 @@ rg::ResourceId DynamicGI::declare(rg::RenderGraph& graph, rg::ResourceId input,pass.dependencies = {scene, probed};pass.write = result;pass.execute = [this, &graph, scene, p](const rg::PassContext& ctx) {+ // A pixel reads the scene, the depth, the G-buffer and the albedo, and from each of the four nearest probes two geometry texels and three of light.+ g_stats.applyPixels = (p.skip & 4u) ? 0.0f : static_cast<f32>(ctx.width) * static_cast<f32>(ctx.height);+ g_stats.applyLoadsPerPixel = 4.0f + 4.0f * 5.0f;+ g_stats.width = static_cast<f32>(ctx.width);+ g_stats.height = static_cast<f32>(ctx.height);+ g_stats.forcedAttachmentBytes = static_cast<f32>(ctx.width) * static_cast<f32>(ctx.height) * 12.0f;+ g_stats.residentBytes = static_cast<f32>(sdfBytes_ + instanceBytes_ + pixelBytes_ + radianceBytes_)+ + static_cast<f32>(probeTilesX_) * static_cast<f32>(probeTilesY_) * (3.0f * 8.0f * 2.0f + 2.0f * 16.0f);+ const DynamicGIScene& sc = dynamicGIScene();+ g_stats.levels = sc.header.size() > kLevels ? sc.header[kLevels] : 0.0f;+ g_stats.lights = sc.header.size() > kLights ? sc.header[kLights] : 0.0f;+ g_stats.instances = sc.header.size() > kInstances ? sc.header[kInstances] : 0.0f;+ g_stats.frame = static_cast<f32>(frame_);if (p.skip & 4u) { ++frame_; return; }const TextureHandle depth = graph.depthTextureOf(scene);const TextureHandle gbuffer = graph.gbufferTextureOf(scene);diff --git a/src/esengine/renderer/frame/DynamicGI.hpp b/src/esengine/renderer/frame/DynamicGI.hppindex 1660074c2..8d20e969f 100644--- a/src/esengine/renderer/frame/DynamicGI.hpp+++ b/src/esengine/renderer/frame/DynamicGI.hpp@@ -60,6 +60,30 @@ struct DynamicGIScene {u32 version = 0;};+/**+ * What the last frame's passes were asked to do, counted where they are dispatched. The cost of the effect is these numbers times what a+ * ray, a texel and a byte cost on a device, and only the first factor is the engine's: a gate (tools/gi/check-gi-cost.mjs) holds them to+ * budgets on any machine, so a change that doubles the rays, or makes every pixel read twice as much, is caught where the GPU is fast.+ */+struct DynamicGIStats {+ f32 width = 0, height = 0;+ /// Pixels between probes, and how many probes there are.+ f32 probeSpacing = 0, probes = 0;+ /// Rays traced this frame by the probes (a probe has 64, one in `stride` of them a frame) and by the cards.+ f32 probeRays = 0, cardPixels = 0, cardPixelsRelit = 0, cardRays = 0;+ /// Pixels the apply pass visits, and the texture reads it makes of each (the four nearest probes; twelve more only where those fail).+ f32 applyPixels = 0, applyLoadsPerPixel = 0;+ /// What the scene pass writes only because this effect is on: the G-buffer (8 bytes a pixel) and the albedo target (4).+ f32 forcedAttachmentBytes = 0;+ /// What the effect keeps in video memory.+ f32 residentBytes = 0;+ f32 levels = 0, lights = 0, instances = 0, frame = 0;+};+constexpr u32 kDynamicGIStatFloats = 16;++/** The last frame's counters (zero before the first). */+const DynamicGIStats& dynamicGIStats();+/** The scene the next frame draws from; written by script through the bindings. */DynamicGIScene& dynamicGIScene();diff --git a/tools/gates.mjs b/tools/gates.mjsindex b99df12d3..52e24f3e0 100644--- a/tools/gates.mjs+++ b/tools/gates.mjs@@ -312,6 +312,12 @@ export const GATES = [},{ id: 'verifier-exit', run: 'node tools/check-verifier-exit.mjs', needs: 'editor' },{ id: 'render-scenes', run: 'node tools/check-render-scenes.mjs' },+ {+ id: 'gi-cost',+ run: 'node tools/gi/check-gi-cost.mjs',+ where: 'local',+ why: 'it exports the GI lab and runs it on the machine GPU for the work counters of the dynamic GI; it says so and passes where there is no WebGPU adapter, and CI has none',+ },{ id: 'release-metadata', run: 'node tools/check-release-metadata.mjs' },// A published desktop artifact has one name, declared, whitespace-free, and// still distinct once the asset store has normalised it.diff --git a/tools/gi/check-gi-cost.mjs b/tools/gi/check-gi-cost.mjsnew file mode 100644index 000000000..e615647a5--- /dev/null+++ b/tools/gi/check-gi-cost.mjs@@ -0,0 +1,131 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * The dynamic GI's cost gate: how much work its passes are asked to do, held to budgets on any machine.+ *+ * node tools/gi/check-gi-cost.mjs+ *+ * What a frame of the effect costs on a device is the work (rays traced, texels read, bytes forced on the scene pass) times what that work+ * costs there. The second factor is the device's: the phone this runs on took 20 ms for work an RTX does in 3. The first is the engine's, and+ * it is counted where the passes are dispatched (DynamicGIStats, read back through `postprocess_giStats`), so it is the same number on both. A+ * change that doubles the rays, or makes every pixel read twice as much, shows here, on the machine where the GPU is too fast to notice.+ *+ * What is held:+ * - the probes' rays a frame, and that their number does not grow with the picture (a probe count that follows the pixels is a cost that+ * follows the screen of a phone);+ * - the cards relit a frame are a slice of them, not all;+ * - the texture reads of the apply pass per pixel, which the gate also counts in the kernel text, so the number the engine reports cannot+ * drift from the kernel it describes;+ * - what the effect forces the scene pass to write, and what it keeps resident.+ *+ * Runs headless on the machine's own GPU (the lab room, exported for the web). Exits 0 with a note where there is no WebGPU adapter or no+ * Python to write the lab with: a gate that cannot run says so, and does not fail.+ */+import { spawnSync } from 'node:child_process';+import { mkdtempSync, readFileSync, rmSync } from 'node:fs';+import { tmpdir } from 'node:os';+import path from 'node:path';+import { pathToFileURL } from 'node:url';++const root = path.resolve(import.meta.dirname, '../..');++// Measured 2026-11-11 on the lab room (10 boxes, ~3.7k card pixels), default settings (cards over 4 frames, one probe ray in 2).+const BUDGET = {+ /** Probes cover about 160 x 90 of the picture whatever its size. */+ probeCount: { min: 12000, max: 17000 },+ /** A probe has 64 rays, and one in `stride` is traced a frame. */+ probeRaysPerProbe: 32,+ /** Rays per pixel of the picture at 720p: the probes' share. */+ raysPerPixel720: 0.6,+ /** A slice of the cards a frame, not all of them. */+ cardSliceOfAll: 0.3,+ /** Texture reads per pixel of the apply pass. */+ applyLoadsPerPixel: 25,+ /** Bytes per pixel the scene pass writes for this effect alone (G-buffer 8 + albedo 4). */+ forcedBytesPerPixel: 12,+ residentBytes: 64 * 1024 * 1024,+};++const failures = [];+const check = (ok, what) => { if (!ok) failures.push(what); };++function skip(why) {+ console.log(`check-gi-cost: skipped - ${why}`);+ process.exit(0);+}++// The kernel text, for the loads the apply pass makes: the ones of its own and the ones of each probe it asks.+const source = readFileSync(path.join(root, 'src/esengine/renderer/frame/DynamicGI.cpp'), 'utf8');+const applySource = source.slice(source.indexOf('const char* kApply'), source.indexOf('#else', source.indexOf('const char* kApply')));+const probeTerm = applySource.slice(applySource.indexOf('fn probeTerm'), applySource.indexOf('@compute', applySource.indexOf('fn probeTerm')));+const main = applySource.slice(applySource.indexOf('@compute'));+const loads = (text) => (text.match(/textureLoad\(/g) ?? []).length;+const mainLoads = loads(main), perProbe = loads(probeTerm);+// The geometry of a probe is read before the early-out on a probe with nothing in it; five loads a probe is what a probe that counts costs.+const modelLoads = mainLoads + 4 * perProbe;++const python = ['python', 'python3'].find((p) => spawnSync(p, ['--version']).status === 0);+if (!python) skip('no Python to write the lab with');++const work = mkdtempSync(path.join(tmpdir(), 'gi-cost-'));+const project = path.join(work, 'project');+const web = path.join(work, 'web');+try {+ const env = { ...process.env, BACKEND: 'webgpu', EFFECTS: JSON.stringify([{ type: 'dynamicGI', enabled: true, uniforms: {} }]) };+ let r = spawnSync(python, [path.join(root, 'tools/render-lab/gi_project.py'), project, 'gi_room'], { env, encoding: 'utf8' });+ if (r.status !== 0) throw new Error(`gi_project.py: ${r.stderr}`);+ spawnSync('node', [path.join(root, 'tools/asset-meta.js'), path.join(project, 'assets')], { encoding: 'utf8' });+ r = spawnSync('node', [path.join(root, 'pipeline/bin/estella.mjs'), 'export', project, '--out', web], { encoding: 'utf8', cwd: root });+ if (r.status !== 0) throw new Error(`export: ${(r.stdout + r.stderr).slice(-400)}`);++ const { chromium } = await import(pathToFileURL(path.join(root, 'node_modules/playwright/index.mjs')).href);+ const { serveHost } = await import(pathToFileURL(path.join(root, 'tools/lib/staticServer.mjs')).href);+ const server = await serveHost(web);+ const browser = await chromium.launch({ channel: 'chromium', headless: true, args: ['--enable-unsafe-webgpu', '--ignore-gpu-blocklist', '--mute-audio'] });+ const stats = {};+ try {+ for (const [w, h] of [[1280, 720], [1920, 1080]]) {+ const page = await browser.newPage({ viewport: { width: w, height: h }, deviceScaleFactor: 1 });+ await page.goto(`http://127.0.0.1:${server.address().port}/`, { waitUntil: 'load' });+ const got = await page.waitForFunction(() => {+ const s = window.__estellaGIStats?.();+ return s && s[0] > 0 && s[15] >= 6 ? s : null;+ }, null, { timeout: 90000, polling: 500 }).then((h2) => h2.jsonValue()).catch(() => null);+ await page.close();+ if (!got) skip(`the effect did not run at ${w}x${h} (no WebGPU adapter, or no compute stage)`);+ stats[`${w}x${h}`] = got;+ }+ } finally {+ await browser.close();+ server.close();+ }++ const [NAMES] = [['width', 'height', 'probeSpacing', 'probes', 'probeRays', 'cardPixels', 'cardPixelsRelit', 'cardRays', 'applyPixels', 'applyLoadsPerPixel', 'forcedAttachmentBytes', 'residentBytes', 'levels', 'lights', 'instances', 'frame']];+ const named = Object.fromEntries(Object.entries(stats).map(([k, v]) => [k, Object.fromEntries(NAMES.map((n, i) => [n, v[i]]))]));+ for (const [size, s] of Object.entries(named)) {+ console.log(`${size}: ${s.probes} probes ${s.probeSpacing} px apart, ${s.probeRays} probe rays, ${s.cardPixelsRelit}/${s.cardPixels} cards relit (${s.cardRays} rays), `+ + `${s.applyLoadsPerPixel} reads a pixel, ${(s.forcedAttachmentBytes / s.applyPixels).toFixed(0)} B a pixel forced on the scene pass, ${(s.residentBytes / 1048576).toFixed(1)} MB resident`);+ check(s.probes >= BUDGET.probeCount.min && s.probes <= BUDGET.probeCount.max, `${size}: ${s.probes} probes, expected ${BUDGET.probeCount.min}-${BUDGET.probeCount.max} whatever the size`);+ check(Math.abs(s.probeRays - s.probes * BUDGET.probeRaysPerProbe) < 1, `${size}: ${s.probeRays} probe rays, expected ${s.probes * BUDGET.probeRaysPerProbe}`);+ check(s.cardPixelsRelit <= s.cardPixels * BUDGET.cardSliceOfAll, `${size}: ${s.cardPixelsRelit} of ${s.cardPixels} cards relit in a frame, expected at most ${BUDGET.cardSliceOfAll} of them`);+ check(s.applyLoadsPerPixel <= BUDGET.applyLoadsPerPixel, `${size}: ${s.applyLoadsPerPixel} reads a pixel in the apply pass, budget ${BUDGET.applyLoadsPerPixel}`);+ check(s.applyLoadsPerPixel === modelLoads, `${size}: the engine reports ${s.applyLoadsPerPixel} reads a pixel but the kernel makes ${modelLoads} (${mainLoads} + 4 x ${perProbe}): update DynamicGIStats`);+ check(s.forcedAttachmentBytes / s.applyPixels <= BUDGET.forcedBytesPerPixel, `${size}: ${s.forcedAttachmentBytes / s.applyPixels} bytes a pixel forced on the scene pass, budget ${BUDGET.forcedBytesPerPixel}`);+ check(s.residentBytes <= BUDGET.residentBytes, `${size}: ${s.residentBytes} bytes resident, budget ${BUDGET.residentBytes}`);+ }+ const a = named['1280x720'], b = named['1920x1080'];+ check(a.probeRays / (a.width * a.height) <= BUDGET.raysPerPixel720, `720p: ${(a.probeRays / (a.width * a.height)).toFixed(3)} probe rays a pixel, budget ${BUDGET.raysPerPixel720}`);+ check(Math.abs(b.probeRays - a.probeRays) <= 0.1 * a.probeRays, `probe rays grew with the picture: ${a.probeRays} at 720p, ${b.probeRays} at 1080p`);+} catch (e) {+ rmSync(work, { recursive: true, force: true, maxRetries: 5 });+ console.error('check-gi-cost:', e instanceof Error ? e.message : String(e));+ process.exit(1);+}+rmSync(work, { recursive: true, force: true, maxRetries: 5 });++if (failures.length > 0) {+ console.error('check-gi-cost FAILED:');+ for (const f of failures) console.error(' ' + f);+ process.exit(1);+}+console.log('check-gi-cost passed');