Read many pixels from one render in the e2e checks (#283)

On the WSL runner every __gm.pixelAt costs about 7 ms, three times as
much as on stein2. Each call renders the whole stage into a fresh
render texture and stalls until the GPU hands one pixel back. pixelRow
and several checks read hundreds of pixels that way. Module 05 spent
36.8 of its 40 s on these reads, module 04 11.3 of 20 s.

- stagePixels in src/ui/render.ts renders once around all points and
  reads them in one go. Only whole pixels at resolution 1 take that
  path. Anything else stays point by point.
- The hook __gm.pixels(points) exposes it, and pixelRow uses it.
- The loops in e2e 04, 05, 14 and 44 read their grids in one call.
- The old comment in pixelRow said a wider frame comes back resampled.
  That is not true. The colours match exactly, so the comment is gone.

Measured on the RTX (d3d12) and on stein2 (Intel, Vulkan): diff 0 at
10 680 points on each GPU. One screen row takes 4 to 18 ms instead of
2.4 to 9.9 s. The six affected modules need 32 s instead of 139 s
under WSL, faster than on stein2.

The rest of the gap is in Chromium's GPU process. perf puts three
quarters of its time in the drivers (NVIDIA D3D12, Mesa d3d12, dxg).
Four browser and Mesa settings were measured, none helped.

Tests:
- ./check.sh on melektaus-atx: 195 files, 2827 tests, CHECK EXIT 0 (+4)
- e2e 1-16,30,37,44,58 under WSL: ALL PASSED, 587 checks
- counter-check: a wrong index in stagePixels fails the unit test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
adminandClaude Opus 5.5 committed 2026-09-29 22:07:53 +02:00
1 parent 857e23c69b
commit ffedd81803
8 files changed
+132 -36

No files matched your search

+70
View File
@@ -9,6 +9,8 @@ import {
renderCount,
requestRender,
resetRenderLoop,
stagePixel,
stagePixels,
} from '../../src/ui/render';
/** A stand-in for the Pixi application: counts draws and remembers what was put on the ticker. */
@@ -208,3 +210,71 @@ describe('render loop', () => {
}
});
});
/**
* A stage whose every pixel has a colour of its own (red = x, green = y, blue = x + y), read the
* way Pixi's extract hands it back: row by row across the frame, four bytes a pixel.
*/
function fakeStage(resolution = 1) {
const frames: { x: number; y: number; width: number; height: number }[] = [];
const app = {
stage: {},
renderer: {
resolution,
extract: {
pixels({ frame }: { frame: { x: number; y: number; width: number; height: number } }) {
frames.push({ x: frame.x, y: frame.y, width: frame.width, height: frame.height });
const pixels = new Uint8ClampedArray(frame.width * frame.height * 4);
for (let row = 0; row < frame.height; row++)
for (let col = 0; col < frame.width; col++) {
const x = Math.floor(frame.x) + col;
const y = Math.floor(frame.y) + row;
pixels.set([x, y, x + y, 255], (row * frame.width + col) * 4);
}
return { pixels, width: frame.width, height: frame.height };
},
},
},
};
return { app: app as unknown as Application, frames };
}
describe('stage pixels', () => {
const scattered = [
{ x: 40, y: 7 },
{ x: 3, y: 90 },
{ x: 40, y: 7 },
{ x: 120, y: 33 },
{ x: 3, y: 7 },
];
it('reads many points from one extract, each the colour stagePixel gives it', () => {
const one = fakeStage();
const alone = scattered.map((p) => stagePixel(one.app, p.x, p.y));
const batch = fakeStage();
expect(stagePixels(batch.app, scattered)).toEqual(alone);
expect(alone[1]).toBe('#035a5d');
expect(batch.frames).toEqual([{ x: 3, y: 7, width: 118, height: 84 }]);
});
it('keeps the point-by-point read for fractions, which would sample elsewhere in a shared frame', () => {
const { app, frames } = fakeStage();
stagePixels(app, [
{ x: 10, y: 10 },
{ x: 12.5, y: 10 },
]);
expect(frames.length).toBe(2);
});
it('keeps it at a resolution other than 1, where one pixel is a block of values', () => {
const { app, frames } = fakeStage(2);
stagePixels(app, scattered);
expect(frames.length).toBe(scattered.length);
});
it('answers a single point and no point at all', () => {
const { app } = fakeStage();
expect(stagePixels(app, [{ x: 5, y: 6 }])).toEqual(['#05060b']);
expect(stagePixels(app, [])).toEqual([]);
});
});