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.

fix(gates): a readback that never happened is not a verdict about the scene

esengine26f51ab01ee3
diff --git a/tools/lib/deadGpu.mjs b/tools/lib/deadGpu.mjs
index ccbc16da3..13c506155 100644
--- a/tools/lib/deadGpu.mjs
+++ b/tools/lib/deadGpu.mjs
@@ -78,6 +78,17 @@ export function engineCouldNotDraw(output) {
.test(output);
}
+/**
+ * Whether a driver's structured result is a MEASUREMENT or the harness saying it
+ * could not take one: an error with no capture beside it is the latter, since a
+ * verdict about the subject always carries the frame it judged. Here, not in a
+ * runner, for the reason the header gives.
+ */
+export function resultMeasured(result) {
+ if (result === null || result === undefined) return false;
+ return !(result.ok === false && Boolean(result.error) && !result.capture);
+}
+
/**
* 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
diff --git a/tools/tests/dead-gpu.test.ts b/tools/tests/dead-gpu.test.ts
index e931758f4..e73f86c2c 100644
--- a/tools/tests/dead-gpu.test.ts
+++ b/tools/tests/dead-gpu.test.ts
@@ -10,7 +10,7 @@
*/
import { describe, it, expect } from 'vitest';
// @ts-expect-error — a .mjs tool module, typed by its own JSDoc
-import { retryOnDeadGpu, gpuNeverCameUp, deadGpuVerdict, engineCouldNotDraw } from '../lib/deadGpu.mjs';
+import { retryOnDeadGpu, gpuNeverCameUp, deadGpuVerdict, engineCouldNotDraw, resultMeasured } from '../lib/deadGpu.mjs';
const DEAD = 'Exiting GPU process due to errors during initialization';
const BLANK = 'painted=true live=false errors=0';
@@ -58,6 +58,31 @@ describe('gpuNeverCameUp', () => {
});
});
+describe('resultMeasured', () => {
+ it('reads a result with a capture as a measurement, whatever its verdict', () => {
+ expect(resultMeasured({ ok: true, capture: { rendered: true } })).toBe(true);
+ // The property the whole policy rests on: a scene that drew the wrong
+ // pixels HAS measured, and must not be handed a retry to hide behind.
+ expect(resultMeasured({ ok: false, capture: { rendered: true }, expect: { ok: false } })).toBe(true);
+ });
+
+ it('reads an error with no capture as the harness failing to measure', () => {
+ // What a lost GL context leaves: the readback throws, so there is no frame
+ // to judge and nothing about the scene has been established.
+ expect(resultMeasured({ ok: false, error: 'captureViewportPixels: no pixels' })).toBe(false);
+ });
+
+ it('has nothing to read when the driver printed no result at all', () => {
+ expect(resultMeasured(null)).toBe(false);
+ expect(resultMeasured(undefined)).toBe(false);
+ });
+
+ it('takes a capture over an error when a result carries both', () => {
+ // A run that captured and then tripped over something else still measured.
+ expect(resultMeasured({ ok: false, error: 'late failure', capture: { rendered: true } })).toBe(true);
+ });
+});
+
describe('retryOnDeadGpu', () => {
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.
@@ -170,6 +195,33 @@ describe('retryOnDeadGpu', () => {
expect(r.notes).toEqual([true]);
});
+ it('retakes a measurement the harness could not take, and stops when it can', () => {
+ // The runner loses the first launch's GL context and holds it after that,
+ // which had every run's FIRST scene red while the hundred behind it passed.
+ let attempts = 0;
+ const r = retryOnDeadGpu(() => {
+ attempts++;
+ const result = attempts === 1
+ ? { ok: false, error: 'captureViewportPixels: no pixels' }
+ : { ok: true, capture: { rendered: true } };
+ return { ok: result.ok, output: '', measured: resultMeasured(result), drew: result.capture?.rendered };
+ }, () => {}, 0);
+ expect(attempts).toBe(2);
+ expect(r.ok).toBe(true);
+ expect(r.retried).toBe(true);
+ });
+
+ it('does not retake a measurement that happened and disagreed', () => {
+ let attempts = 0;
+ const r = retryOnDeadGpu(() => {
+ attempts++;
+ const result = { ok: false, capture: { rendered: true }, expect: { ok: false } };
+ return { ok: false, output: '', measured: resultMeasured(result), drew: true };
+ }, () => {}, 0);
+ expect(attempts).toBe(1);
+ expect(r.gpuDied).toBeFalsy();
+ });
+
it('gives up at the cap and says the GPU is why', () => {
const r = run([DEAD]);
expect(r.ok).toBe(false);
diff --git a/tools/verify-render.mjs b/tools/verify-render.mjs
index da7c2df82..9ad5c38f0 100644
--- a/tools/verify-render.mjs
+++ b/tools/verify-render.mjs
@@ -15,7 +15,7 @@ import path from 'node:path';
import { existsSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { TIERS, SCENES, scenesAtTier, sceneWatchdogMs } from './renderScenes.mjs';
-import { retryOnDeadGpu, deadGpuVerdict } from './lib/deadGpu.mjs';
+import { retryOnDeadGpu, deadGpuVerdict, resultMeasured } from './lib/deadGpu.mjs';
import { runTool } from './lib/runTool.mjs';
import { requireCurrentEngine } from './lib/engineBuild.mjs';
@@ -194,7 +194,7 @@ function runScene(scene) {
ok: r.status === 0,
out,
ms: Date.now() - at,
- measured: result !== null,
+ measured: resultMeasured(result),
drew: result?.capture?.rendered,
verdict: r.timedOut
? 'the run never reached its own watchdog and was killed'