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(gates): a GPU that came up cannot be blamed for what the engine did after
esengine9e72c9d0266c
diff --git a/tools/lib/deadGpu.mjs b/tools/lib/deadGpu.mjsindex 3c6ee09a8..580a0b3ef 100644--- a/tools/lib/deadGpu.mjs+++ b/tools/lib/deadGpu.mjs@@ -117,6 +117,24 @@ export function resultMeasured(result) {return !(result.ok === false && Boolean(result.error) && !result.capture);}+/**+ * The runner's own words for a GPU that DID come up. OUTRANKS every heuristic+ * here, which guess a cause from a failure where this reads the cause itself:+ * an emptied readback is `ok:false` with no capture, which {@link resultMeasured}+ * calls "no measurement" and the policy would then blame on a dead GPU.+ */+export function gpuCameUp(output) {+ return /webgpu adapter:\s*\S/i.test(output) && /WebGPU device injected/i.test(output);+}++/**+ * The device arrived and then went. Still an outage rather than the subject's+ * fault, so it survives the veto above — "came up" is not "stayed up".+ */+function gpuWentAway(output) {+ return /GPU device lost/.test(output);+}+/*** Whether this attempt reached a verdict at all. `measured` is the run's own* answer and wins, except that a run whose engine could not draw has measured@@ -124,6 +142,10 @@ export function resultMeasured(result) {*/function reachedNoVerdict(last) {const output = last.output ?? '';+ // A GPU that demonstrably arrived and did not go makes every later failure+ // the subject's own — including a capture that came back empty, which is a+ // statement ABOUT the frame and not the absence of one to judge.+ if (gpuCameUp(output) && !gpuWentAway(output)) return false;if (engineCouldNotDraw(output)) return true;if (typeof last.measured === 'boolean') return !last.measured;return gpuNeverCameUp(output);diff --git a/tools/tests/dead-gpu.test.ts b/tools/tests/dead-gpu.test.tsindex 1794e8cd4..8b00505c0 100644--- a/tools/tests/dead-gpu.test.ts+++ b/tools/tests/dead-gpu.test.ts@@ -11,10 +11,16 @@import { describe, it, expect } from 'vitest';// @ts-expect-error — a .mjs tool module, typed by its own JSDocimport { retryOnDeadGpu, gpuNeverCameUp, deadGpuVerdict, engineCouldNotDraw, resultMeasured,- launchNeverHappened } from '../lib/deadGpu.mjs';+ launchNeverHappened, gpuCameUp } from '../lib/deadGpu.mjs';const DEAD = 'Exiting GPU process due to errors during initialization';const BLANK = 'painted=true live=false errors=0';+/** What the runner prints when the device DID arrive, on the two lines above the+ * failure. Verbatim from the run that exposed the frame-lifecycle regression. */+const GPU_UP = '[renderer] [engine] webgpu adapter: apple metal-3 (default)\n'+ + "[renderer] [wasm] [INFO ] WebGPU device injected for '#canvas' (640x360)";+/** The regression's own shape: a device that came up, and a readback that did not. */+const EMPTY_CAPTURE = `${GPU_UP}\ncaptureViewportPixels: no pixels — the engine refused the readback`;/** Drive the policy over a scripted sequence of attempt outputs; `null` = success. */function run(outputs: Array<string | null>) {@@ -84,7 +90,47 @@ describe('resultMeasured', () => {});});+describe('gpuCameUp', () => {+ it('reads the two lines that say a device arrived', () => {+ expect(gpuCameUp(GPU_UP)).toBe(true);+ expect(gpuCameUp(EMPTY_CAPTURE)).toBe(true);+ });++ it('an adapter alone is not a device', () => {+ expect(gpuCameUp('[renderer] [engine] webgpu adapter: apple metal-3 (default)')).toBe(false);+ });++ it('says nothing about a runner that printed neither', () => {+ expect(gpuCameUp(DEAD)).toBe(false);+ expect(gpuCameUp(BLANK)).toBe(false);+ });+});+describe('retryOnDeadGpu', () => {+ it('an empty capture from a device that CAME UP is the subject\u2019s failure', () => {+ // `measured: false` is the half that makes this invisible: an error with+ // no capture is what resultMeasured calls "no measurement", and without+ // the veto the policy retries six times and blames the runner.+ const r = runReporting([{ ok: false, output: EMPTY_CAPTURE, measured: false }]);+ expect(r.ok).toBe(false);+ expect(r.attempts).toBe(1);+ expect(r.notes).toEqual([]);+ expect(r.gpuDied).toBeUndefined();+ });++ it('still retries when the device that came up was then LOST', () => {+ // "Came up" is not "stayed up": a device that goes mid-run took the+ // measurement with it, and that is the runner's story after all.+ const r = runReporting([+ { ok: false, output: `${GPU_UP}\nGPU device lost`, measured: false },+ { ok: true },+ ]);+ expect(r.ok).toBe(true);+ expect(r.attempts).toBe(2);+ expect(r.notes).toEqual([true]);+ });++it('a game that draws nothing fails on the first attempt', () => {// The whole point: no retry may stand between a black frame and a red gate.const r = run([BLANK]);