@moku-labs/game 0.15.122 → 0.15.124
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app/page.d.mts +1 -1
- package/dist/app/system.d.mts +3 -3
- package/dist/app.d.mts +3 -3
- package/dist/app.mjs +1 -1
- package/dist/{assets-BRTUagOC.mjs → assets-D6LmjgQc.mjs} +13 -5
- package/dist/assets.d.mts +1 -1
- package/dist/assets.mjs +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/{commands-BMeGOWws.d.mts → commands-CslgzXLW.d.mts} +5 -5
- package/dist/control.d.mts +4 -4
- package/dist/{define-h7SEyejf.d.mts → define-DAFwIXpT.d.mts} +2 -2
- package/dist/{headless-CwH40XSw.d.mts → headless-w-BqXOjQ.d.mts} +1 -1
- package/dist/{index-BhMPDwA9.d.mts → index-DY9NpxeK.d.mts} +3 -3
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +1 -1
- package/dist/inspect.d.mts +6 -6
- package/dist/jsx-dev-runtime.d.mts +1 -1
- package/dist/jsx-runtime.d.mts +1 -1
- package/dist/{runtime-BoK0QMVt.d.mts → runtime-DbfmnXM8.d.mts} +1 -1
- package/dist/{src-uuF4Ry3D.mjs → src-DAwGHTaM.mjs} +492 -183
- package/dist/testing.d.mts +4 -4
- package/dist/testing.mjs +1 -1
- package/dist/{types-wsgkqOXF.d.mts → types-B2oay3bJ.d.mts} +2 -2
- package/dist/{types-B3OYUVNR.d.mts → types-BelqIB0P.d.mts} +2 -2
- package/dist/{types-DuGiHe3k.d.mts → types-CUQ-ig2E.d.mts} +67 -6
- package/dist/{types-Dpd8geJW.d.mts → types-Cbtr2GAO.d.mts} +1 -1
- package/dist/{types-Lh8Ql5Lv.d.mts → types-eIlzV3Jf.d.mts} +4 -4
- package/dist/{visual-BN0LF0W1.d.mts → visual-VvIFdrWq.d.mts} +6 -6
- package/dist/visual.d.mts +1 -1
- package/dist/visual.mjs +11 -5
- package/package.json +1 -1
|
@@ -15181,6 +15181,155 @@ function createDemandApi(ctx, deps) {
|
|
|
15181
15181
|
};
|
|
15182
15182
|
}
|
|
15183
15183
|
//#endregion
|
|
15184
|
+
//#region src/plugins/renderer/host/readback.ts
|
|
15185
|
+
/** Bytes of one pixel: the engine loads PNG and WebP only, so every source is 8-bit RGBA. */
|
|
15186
|
+
const BYTES_PER_PIXEL$2 = 4;
|
|
15187
|
+
/**
|
|
15188
|
+
* Estimates the GPU bytes of one texture source: 4 bytes per pixel, every mip level, a level never
|
|
15189
|
+
* smaller than one pixel.
|
|
15190
|
+
*
|
|
15191
|
+
* @param source - The size fields of a Pixi `TextureSource`.
|
|
15192
|
+
* @param source.pixelWidth - Width in real pixels.
|
|
15193
|
+
* @param source.pixelHeight - Height in real pixels.
|
|
15194
|
+
* @param source.mipLevelCount - Mip levels, 1 without mipmaps.
|
|
15195
|
+
* @returns The estimated bytes.
|
|
15196
|
+
* @example
|
|
15197
|
+
* ```ts
|
|
15198
|
+
* sourceBytes({ pixelWidth: 4, pixelHeight: 4, mipLevelCount: 3 }); // 84: 16 + 4 + 1 pixels
|
|
15199
|
+
* ```
|
|
15200
|
+
*/
|
|
15201
|
+
function sourceBytes(source) {
|
|
15202
|
+
let pixels = 0;
|
|
15203
|
+
let width = source.pixelWidth;
|
|
15204
|
+
let height = source.pixelHeight;
|
|
15205
|
+
for (let level = 0; level < Math.max(1, source.mipLevelCount); level += 1) {
|
|
15206
|
+
pixels += width * height;
|
|
15207
|
+
width = Math.max(1, Math.floor(width / 2));
|
|
15208
|
+
height = Math.max(1, Math.floor(height / 2));
|
|
15209
|
+
}
|
|
15210
|
+
return pixels * BYTES_PER_PIXEL$2;
|
|
15211
|
+
}
|
|
15212
|
+
/**
|
|
15213
|
+
* Tells a render target from art: Pixi gives a target no upload method and no resource.
|
|
15214
|
+
*
|
|
15215
|
+
* @param source - The upload fields of a Pixi `TextureSource`.
|
|
15216
|
+
* @param source.uploadMethodId - How Pixi uploads it; `"unknown"` for a render target.
|
|
15217
|
+
* @param source.resource - What it uploads; none for a render target.
|
|
15218
|
+
* @returns True for a render target.
|
|
15219
|
+
* @example
|
|
15220
|
+
* ```ts
|
|
15221
|
+
* isTarget({ uploadMethodId: "unknown", resource: null }); // true
|
|
15222
|
+
* ```
|
|
15223
|
+
*/
|
|
15224
|
+
function isTarget$3(source) {
|
|
15225
|
+
return source.uploadMethodId === "unknown" && (source.resource === null || source.resource === void 0);
|
|
15226
|
+
}
|
|
15227
|
+
/**
|
|
15228
|
+
* Counts the texture sources the GPU holds and sums their estimated bytes, split three ways: a
|
|
15229
|
+
* source with no upload method and no resource is a render target (a filter texture, a picture
|
|
15230
|
+
* Pixi renders into), one the engine keeps as a picture is kept, every other source is art.
|
|
15231
|
+
* Pixi's `managedTextures` exists on the WebGPU and the WebGL texture system alike (checked in
|
|
15232
|
+
* 8.22); Pixi's canvas renderer keeps no GPU texture and answers zero. Both systems answer
|
|
15233
|
+
* `Object.values` of a `GCManagedHash`, which keeps a `null` slot for every unloaded source, so
|
|
15234
|
+
* only the live sources are counted. An indexed walk: no array is made.
|
|
15235
|
+
*
|
|
15236
|
+
* @param app - The application that draws.
|
|
15237
|
+
* @param kept - The sources the engine keeps as pictures.
|
|
15238
|
+
* @returns The count, the bytes and their split.
|
|
15239
|
+
*/
|
|
15240
|
+
function textureUsage(app, kept) {
|
|
15241
|
+
const system = app.renderer.texture;
|
|
15242
|
+
const usage = {
|
|
15243
|
+
count: 0,
|
|
15244
|
+
bytes: 0,
|
|
15245
|
+
art: 0,
|
|
15246
|
+
targets: 0,
|
|
15247
|
+
kept: 0
|
|
15248
|
+
};
|
|
15249
|
+
if (!("managedTextures" in system)) return usage;
|
|
15250
|
+
const sources = system.managedTextures;
|
|
15251
|
+
const total = sources.length;
|
|
15252
|
+
for (let index = 0; index < total; index += 1) {
|
|
15253
|
+
const source = sources[index];
|
|
15254
|
+
if (!source) continue;
|
|
15255
|
+
const bytes = sourceBytes(source);
|
|
15256
|
+
usage.count += 1;
|
|
15257
|
+
usage.bytes += bytes;
|
|
15258
|
+
if (kept.has(source)) usage.kept += bytes;
|
|
15259
|
+
else if (isTarget$3(source)) usage.targets += bytes;
|
|
15260
|
+
else usage.art += bytes;
|
|
15261
|
+
}
|
|
15262
|
+
return usage;
|
|
15263
|
+
}
|
|
15264
|
+
/**
|
|
15265
|
+
* Hides containers for the length of one synchronous call and shows them again right after it,
|
|
15266
|
+
* also when it throws. A container hidden already stays hidden.
|
|
15267
|
+
*
|
|
15268
|
+
* @param hidden - The containers to hide.
|
|
15269
|
+
* @param work - The call; it runs with them hidden.
|
|
15270
|
+
* @returns What the call returned.
|
|
15271
|
+
*/
|
|
15272
|
+
function withHidden(hidden, work) {
|
|
15273
|
+
const shown = hidden.filter((container) => container.visible);
|
|
15274
|
+
for (const container of shown) container.visible = false;
|
|
15275
|
+
try {
|
|
15276
|
+
return work();
|
|
15277
|
+
} finally {
|
|
15278
|
+
for (const container of shown) container.visible = true;
|
|
15279
|
+
}
|
|
15280
|
+
}
|
|
15281
|
+
/**
|
|
15282
|
+
* Draws the stage into a PNG over the whole canvas, bars included, with Pixi's extract system.
|
|
15283
|
+
* Pixi renders the stage synchronously inside the call and encodes afterwards, so the containers
|
|
15284
|
+
* in `hidden` are hidden around the call alone: no drawn frame sees them hidden. A failed read is
|
|
15285
|
+
* logged and answers `undefined`, so a caller never has to catch.
|
|
15286
|
+
*
|
|
15287
|
+
* @param ctx - Domain context of the renderer plugin.
|
|
15288
|
+
* @param app - The application that draws.
|
|
15289
|
+
* @param hidden - The layer containers to leave out of the picture.
|
|
15290
|
+
* @returns A `data:image/png;base64,…` URL, or `undefined` when Pixi could not read the frame.
|
|
15291
|
+
*/
|
|
15292
|
+
async function extractStage(ctx, app, hidden) {
|
|
15293
|
+
try {
|
|
15294
|
+
return await withHidden(hidden, () => app.renderer.extract.base64({
|
|
15295
|
+
target: app.stage,
|
|
15296
|
+
frame: app.screen,
|
|
15297
|
+
clearColor: ctx.config.background,
|
|
15298
|
+
format: "png"
|
|
15299
|
+
}));
|
|
15300
|
+
} catch (error) {
|
|
15301
|
+
ctx.log.error("renderer: capture failed", { error });
|
|
15302
|
+
return;
|
|
15303
|
+
}
|
|
15304
|
+
}
|
|
15305
|
+
/** The resolution the pixel oracle reads the stage at: a quarter of the pixels, a 2-px change still shows. */
|
|
15306
|
+
const ORACLE_RESOLUTION = .5;
|
|
15307
|
+
/**
|
|
15308
|
+
* Draws the stage live into RGBA pixels with Pixi's extract system, framed as a capture is, at
|
|
15309
|
+
* half resolution. A failed read is logged once per application state and answers `undefined`.
|
|
15310
|
+
*
|
|
15311
|
+
* @param ctx - Domain context of the renderer plugin.
|
|
15312
|
+
* @param app - The application that draws.
|
|
15313
|
+
* @param resolution - Device pixels per CSS pixel of the read; half by default.
|
|
15314
|
+
* @returns The pixels, or `undefined` when Pixi could not read them.
|
|
15315
|
+
*/
|
|
15316
|
+
function readPixels(ctx, app, resolution = ORACLE_RESOLUTION) {
|
|
15317
|
+
try {
|
|
15318
|
+
return app.renderer.extract.pixels({
|
|
15319
|
+
target: app.stage,
|
|
15320
|
+
frame: app.screen,
|
|
15321
|
+
clearColor: ctx.config.background,
|
|
15322
|
+
resolution
|
|
15323
|
+
}).pixels;
|
|
15324
|
+
} catch (error) {
|
|
15325
|
+
if (!ctx.state.host.pixelsFailed) {
|
|
15326
|
+
ctx.state.host.pixelsFailed = true;
|
|
15327
|
+
ctx.log.error("renderer: pixel read failed", { error });
|
|
15328
|
+
}
|
|
15329
|
+
return;
|
|
15330
|
+
}
|
|
15331
|
+
}
|
|
15332
|
+
//#endregion
|
|
15184
15333
|
//#region src/plugins/renderer/host/device.ts
|
|
15185
15334
|
/**
|
|
15186
15335
|
* The GPU device of the application that draws now. Only a WebGPU application has one; a lost
|
|
@@ -15207,8 +15356,9 @@ function liveGl(state) {
|
|
|
15207
15356
|
return "gl" in app.renderer ? app.renderer.gl : void 0;
|
|
15208
15357
|
}
|
|
15209
15358
|
/**
|
|
15210
|
-
* Starts a loss: the renderer stops drawing, the game pauses and the event goes out
|
|
15211
|
-
* while the plugin is already down, or
|
|
15359
|
+
* Starts a loss: the renderer stops drawing, the game pauses and the event goes out; then the `decideLoss` callbacks
|
|
15360
|
+
* hear it, and one that answers true marks the page as leaving (F189). A loss while the plugin is already down, or
|
|
15361
|
+
* while a restore runs, is ignored.
|
|
15212
15362
|
*
|
|
15213
15363
|
* @param ctx - Domain context of the renderer plugin.
|
|
15214
15364
|
* @param kind - Which backend lost its device.
|
|
@@ -15218,6 +15368,11 @@ function liveGl(state) {
|
|
|
15218
15368
|
function beginLoss(ctx, kind, reason) {
|
|
15219
15369
|
const state = ctx.state.host;
|
|
15220
15370
|
if (!state.ready || state.restoring) return false;
|
|
15371
|
+
const info = {
|
|
15372
|
+
kind,
|
|
15373
|
+
reason,
|
|
15374
|
+
textureBytes: state.app === void 0 ? 0 : textureUsage(state.app, state.kept).bytes
|
|
15375
|
+
};
|
|
15221
15376
|
state.ready = false;
|
|
15222
15377
|
state.restoring = true;
|
|
15223
15378
|
ctx.deps.lifecycle.push("device-lost");
|
|
@@ -15225,10 +15380,12 @@ function beginLoss(ctx, kind, reason) {
|
|
|
15225
15380
|
kind,
|
|
15226
15381
|
reason
|
|
15227
15382
|
});
|
|
15383
|
+
for (const decide of state.lossDeciders) if (decide(info)) state.leaving = true;
|
|
15228
15384
|
return true;
|
|
15229
15385
|
}
|
|
15230
15386
|
/**
|
|
15231
|
-
* Ends a restore: the renderer draws again and the pause reason goes.
|
|
15387
|
+
* Ends a restore: the renderer draws again and the pause reason goes. A page that leaves after the loss (F189)
|
|
15388
|
+
* restores nothing. The `onRestore` callbacks
|
|
15232
15389
|
* run first: after a WebGPU restore the whole display tree is new and they rebuild it; after a
|
|
15233
15390
|
* WebGL restore the tree stands, but the canvas and every render texture came back empty, so they
|
|
15234
15391
|
* ask for a whole frame and the pictures again.
|
|
@@ -15238,7 +15395,7 @@ function beginLoss(ctx, kind, reason) {
|
|
|
15238
15395
|
*/
|
|
15239
15396
|
function finishRestore(ctx, rebuild) {
|
|
15240
15397
|
const state = ctx.state.host;
|
|
15241
|
-
if (!state.restoring) return;
|
|
15398
|
+
if (!state.restoring || state.leaving) return;
|
|
15242
15399
|
state.ready = true;
|
|
15243
15400
|
state.restoring = false;
|
|
15244
15401
|
for (const fn of state.onRestore) fn(rebuild);
|
|
@@ -15259,6 +15416,7 @@ function watchDevice(ctx, restart) {
|
|
|
15259
15416
|
const onLost = async (info) => {
|
|
15260
15417
|
if (ctx.state.host.app !== app) return;
|
|
15261
15418
|
if (!beginLoss(ctx, "webgpu", info.reason)) return;
|
|
15419
|
+
if (ctx.state.host.leaving) return;
|
|
15262
15420
|
if (await restart()) finishRestore(ctx, true);
|
|
15263
15421
|
};
|
|
15264
15422
|
app.renderer.gpu.device.lost.then(onLost).catch((error) => ctx.log.error("renderer: restore failed", { error }));
|
|
@@ -16752,7 +16910,8 @@ function createPoolState() {
|
|
|
16752
16910
|
lastDrawnAt: void 0,
|
|
16753
16911
|
sceneAt: void 0,
|
|
16754
16912
|
restDone: false,
|
|
16755
|
-
baseline: 0
|
|
16913
|
+
baseline: 0,
|
|
16914
|
+
held: []
|
|
16756
16915
|
};
|
|
16757
16916
|
}
|
|
16758
16917
|
/**
|
|
@@ -16774,6 +16933,8 @@ function createHostState() {
|
|
|
16774
16933
|
restoring: false,
|
|
16775
16934
|
onReady: [],
|
|
16776
16935
|
onRestore: [],
|
|
16936
|
+
lossDeciders: [],
|
|
16937
|
+
leaving: false,
|
|
16777
16938
|
onLoss: [],
|
|
16778
16939
|
cleanups: [],
|
|
16779
16940
|
unsupported: void 0,
|
|
@@ -17015,7 +17176,8 @@ function destroyApplication(state) {
|
|
|
17015
17176
|
* Undoes everything `init` created. Works on the state alone, because `onStop` has no context.
|
|
17016
17177
|
* `ready` drops first, so a device that goes away during the teardown is ignored. The draw
|
|
17017
17178
|
* counter, the batched text, the render-group pipe and the lazy canvas pass swap Pixi's own classes back, so the next
|
|
17018
|
-
* application on the page starts from them. The pool trim starts over and its listeners go
|
|
17179
|
+
* application on the page starts from them. The pool trim starts over and its listeners go, and the targets a trim
|
|
17180
|
+
* still held are destroyed (a filter that still binds one warns once, at teardown); Pixi's pool itself is left.
|
|
17019
17181
|
*
|
|
17020
17182
|
* @param state - The host branch of the plugin state.
|
|
17021
17183
|
*/
|
|
@@ -17039,10 +17201,12 @@ function stopHost(state) {
|
|
|
17039
17201
|
state.unsupported = void 0;
|
|
17040
17202
|
state.onReady.length = 0;
|
|
17041
17203
|
state.onRestore.length = 0;
|
|
17204
|
+
state.lossDeciders.length = 0;
|
|
17042
17205
|
state.onLoss.length = 0;
|
|
17043
17206
|
state.onResolutionChange.length = 0;
|
|
17044
17207
|
state.onTrim.length = 0;
|
|
17045
17208
|
state.onCanvasPass = void 0;
|
|
17209
|
+
for (const texture of state.pool.held) texture.destroy(true);
|
|
17046
17210
|
state.pool = createPoolState();
|
|
17047
17211
|
state.resolution.pending = void 0;
|
|
17048
17212
|
state.kind = "none";
|
|
@@ -17060,7 +17224,7 @@ function stopHost(state) {
|
|
|
17060
17224
|
* bounds (slot -1) boxes a reader's doubles the same way, for every caller: a slot that may not exist is checked first.
|
|
17061
17225
|
*/
|
|
17062
17226
|
/** Bytes of one MiB. */
|
|
17063
|
-
const BYTES_PER_MB$
|
|
17227
|
+
const BYTES_PER_MB$2 = 1048576;
|
|
17064
17228
|
/**
|
|
17065
17229
|
* Rounds a number to a fixed count of decimals, so a counter reads well in a panel and a log line stays short.
|
|
17066
17230
|
*
|
|
@@ -17161,161 +17325,12 @@ function cellU8(column, index) {
|
|
|
17161
17325
|
return column[index] ?? NaN;
|
|
17162
17326
|
}
|
|
17163
17327
|
//#endregion
|
|
17164
|
-
//#region src/plugins/renderer/host/readback.ts
|
|
17165
|
-
/** Bytes of one pixel: the engine loads PNG and WebP only, so every source is 8-bit RGBA. */
|
|
17166
|
-
const BYTES_PER_PIXEL$2 = 4;
|
|
17167
|
-
/**
|
|
17168
|
-
* Estimates the GPU bytes of one texture source: 4 bytes per pixel, every mip level, a level never
|
|
17169
|
-
* smaller than one pixel.
|
|
17170
|
-
*
|
|
17171
|
-
* @param source - The size fields of a Pixi `TextureSource`.
|
|
17172
|
-
* @param source.pixelWidth - Width in real pixels.
|
|
17173
|
-
* @param source.pixelHeight - Height in real pixels.
|
|
17174
|
-
* @param source.mipLevelCount - Mip levels, 1 without mipmaps.
|
|
17175
|
-
* @returns The estimated bytes.
|
|
17176
|
-
* @example
|
|
17177
|
-
* ```ts
|
|
17178
|
-
* sourceBytes({ pixelWidth: 4, pixelHeight: 4, mipLevelCount: 3 }); // 84: 16 + 4 + 1 pixels
|
|
17179
|
-
* ```
|
|
17180
|
-
*/
|
|
17181
|
-
function sourceBytes(source) {
|
|
17182
|
-
let pixels = 0;
|
|
17183
|
-
let width = source.pixelWidth;
|
|
17184
|
-
let height = source.pixelHeight;
|
|
17185
|
-
for (let level = 0; level < Math.max(1, source.mipLevelCount); level += 1) {
|
|
17186
|
-
pixels += width * height;
|
|
17187
|
-
width = Math.max(1, Math.floor(width / 2));
|
|
17188
|
-
height = Math.max(1, Math.floor(height / 2));
|
|
17189
|
-
}
|
|
17190
|
-
return pixels * BYTES_PER_PIXEL$2;
|
|
17191
|
-
}
|
|
17192
|
-
/**
|
|
17193
|
-
* Tells a render target from art: Pixi gives a target no upload method and no resource.
|
|
17194
|
-
*
|
|
17195
|
-
* @param source - The upload fields of a Pixi `TextureSource`.
|
|
17196
|
-
* @param source.uploadMethodId - How Pixi uploads it; `"unknown"` for a render target.
|
|
17197
|
-
* @param source.resource - What it uploads; none for a render target.
|
|
17198
|
-
* @returns True for a render target.
|
|
17199
|
-
* @example
|
|
17200
|
-
* ```ts
|
|
17201
|
-
* isTarget({ uploadMethodId: "unknown", resource: null }); // true
|
|
17202
|
-
* ```
|
|
17203
|
-
*/
|
|
17204
|
-
function isTarget$3(source) {
|
|
17205
|
-
return source.uploadMethodId === "unknown" && (source.resource === null || source.resource === void 0);
|
|
17206
|
-
}
|
|
17207
|
-
/**
|
|
17208
|
-
* Counts the texture sources the GPU holds and sums their estimated bytes, split three ways: a
|
|
17209
|
-
* source with no upload method and no resource is a render target (a filter texture, a picture
|
|
17210
|
-
* Pixi renders into), one the engine keeps as a picture is kept, every other source is art.
|
|
17211
|
-
* Pixi's `managedTextures` exists on the WebGPU and the WebGL texture system alike (checked in
|
|
17212
|
-
* 8.22); Pixi's canvas renderer keeps no GPU texture and answers zero. Both systems answer
|
|
17213
|
-
* `Object.values` of a `GCManagedHash`, which keeps a `null` slot for every unloaded source, so
|
|
17214
|
-
* only the live sources are counted. An indexed walk: no array is made.
|
|
17215
|
-
*
|
|
17216
|
-
* @param app - The application that draws.
|
|
17217
|
-
* @param kept - The sources the engine keeps as pictures.
|
|
17218
|
-
* @returns The count, the bytes and their split.
|
|
17219
|
-
*/
|
|
17220
|
-
function textureUsage(app, kept) {
|
|
17221
|
-
const system = app.renderer.texture;
|
|
17222
|
-
const usage = {
|
|
17223
|
-
count: 0,
|
|
17224
|
-
bytes: 0,
|
|
17225
|
-
art: 0,
|
|
17226
|
-
targets: 0,
|
|
17227
|
-
kept: 0
|
|
17228
|
-
};
|
|
17229
|
-
if (!("managedTextures" in system)) return usage;
|
|
17230
|
-
const sources = system.managedTextures;
|
|
17231
|
-
const total = sources.length;
|
|
17232
|
-
for (let index = 0; index < total; index += 1) {
|
|
17233
|
-
const source = sources[index];
|
|
17234
|
-
if (!source) continue;
|
|
17235
|
-
const bytes = sourceBytes(source);
|
|
17236
|
-
usage.count += 1;
|
|
17237
|
-
usage.bytes += bytes;
|
|
17238
|
-
if (kept.has(source)) usage.kept += bytes;
|
|
17239
|
-
else if (isTarget$3(source)) usage.targets += bytes;
|
|
17240
|
-
else usage.art += bytes;
|
|
17241
|
-
}
|
|
17242
|
-
return usage;
|
|
17243
|
-
}
|
|
17244
|
-
/**
|
|
17245
|
-
* Hides containers for the length of one synchronous call and shows them again right after it,
|
|
17246
|
-
* also when it throws. A container hidden already stays hidden.
|
|
17247
|
-
*
|
|
17248
|
-
* @param hidden - The containers to hide.
|
|
17249
|
-
* @param work - The call; it runs with them hidden.
|
|
17250
|
-
* @returns What the call returned.
|
|
17251
|
-
*/
|
|
17252
|
-
function withHidden(hidden, work) {
|
|
17253
|
-
const shown = hidden.filter((container) => container.visible);
|
|
17254
|
-
for (const container of shown) container.visible = false;
|
|
17255
|
-
try {
|
|
17256
|
-
return work();
|
|
17257
|
-
} finally {
|
|
17258
|
-
for (const container of shown) container.visible = true;
|
|
17259
|
-
}
|
|
17260
|
-
}
|
|
17261
|
-
/**
|
|
17262
|
-
* Draws the stage into a PNG over the whole canvas, bars included, with Pixi's extract system.
|
|
17263
|
-
* Pixi renders the stage synchronously inside the call and encodes afterwards, so the containers
|
|
17264
|
-
* in `hidden` are hidden around the call alone: no drawn frame sees them hidden. A failed read is
|
|
17265
|
-
* logged and answers `undefined`, so a caller never has to catch.
|
|
17266
|
-
*
|
|
17267
|
-
* @param ctx - Domain context of the renderer plugin.
|
|
17268
|
-
* @param app - The application that draws.
|
|
17269
|
-
* @param hidden - The layer containers to leave out of the picture.
|
|
17270
|
-
* @returns A `data:image/png;base64,…` URL, or `undefined` when Pixi could not read the frame.
|
|
17271
|
-
*/
|
|
17272
|
-
async function extractStage(ctx, app, hidden) {
|
|
17273
|
-
try {
|
|
17274
|
-
return await withHidden(hidden, () => app.renderer.extract.base64({
|
|
17275
|
-
target: app.stage,
|
|
17276
|
-
frame: app.screen,
|
|
17277
|
-
clearColor: ctx.config.background,
|
|
17278
|
-
format: "png"
|
|
17279
|
-
}));
|
|
17280
|
-
} catch (error) {
|
|
17281
|
-
ctx.log.error("renderer: capture failed", { error });
|
|
17282
|
-
return;
|
|
17283
|
-
}
|
|
17284
|
-
}
|
|
17285
|
-
/** The resolution the pixel oracle reads the stage at: a quarter of the pixels, a 2-px change still shows. */
|
|
17286
|
-
const ORACLE_RESOLUTION = .5;
|
|
17287
|
-
/**
|
|
17288
|
-
* Draws the stage live into RGBA pixels with Pixi's extract system, framed as a capture is, at
|
|
17289
|
-
* half resolution. A failed read is logged once per application state and answers `undefined`.
|
|
17290
|
-
*
|
|
17291
|
-
* @param ctx - Domain context of the renderer plugin.
|
|
17292
|
-
* @param app - The application that draws.
|
|
17293
|
-
* @param resolution - Device pixels per CSS pixel of the read; half by default.
|
|
17294
|
-
* @returns The pixels, or `undefined` when Pixi could not read them.
|
|
17295
|
-
*/
|
|
17296
|
-
function readPixels(ctx, app, resolution = ORACLE_RESOLUTION) {
|
|
17297
|
-
try {
|
|
17298
|
-
return app.renderer.extract.pixels({
|
|
17299
|
-
target: app.stage,
|
|
17300
|
-
frame: app.screen,
|
|
17301
|
-
clearColor: ctx.config.background,
|
|
17302
|
-
resolution
|
|
17303
|
-
}).pixels;
|
|
17304
|
-
} catch (error) {
|
|
17305
|
-
if (!ctx.state.host.pixelsFailed) {
|
|
17306
|
-
ctx.state.host.pixelsFailed = true;
|
|
17307
|
-
ctx.log.error("renderer: pixel read failed", { error });
|
|
17308
|
-
}
|
|
17309
|
-
return;
|
|
17310
|
-
}
|
|
17311
|
-
}
|
|
17312
|
-
//#endregion
|
|
17313
17328
|
//#region src/plugins/renderer/host/pool.ts
|
|
17314
17329
|
/**
|
|
17315
17330
|
* @file renderer/host — the pool trim (C14): gives back the idle render targets Pixi's global `TexturePool` keeps,
|
|
17316
|
-
* strictly between frames
|
|
17317
|
-
* change, and on a pause. The trim reaches the monitor of an agent build through the
|
|
17318
|
-
* `onTrim`, so this file never imports the monitor (LEAD-FIXES-3 O24).
|
|
17331
|
+
* strictly between frames. A target a shader still binds waits for the frame that lets it go (F187). A trim runs at
|
|
17332
|
+
* rest, `restMs` after a scene change, and on a pause. The trim reaches the monitor of an agent build through the
|
|
17333
|
+
* listeners it registers with `onTrim`, so this file never imports the monitor (LEAD-FIXES-3 O24).
|
|
17319
17334
|
*/
|
|
17320
17335
|
/**
|
|
17321
17336
|
* The bytes of the render targets the GPU holds now: the `targets` share of `host.textures()`. One walk of Pixi's
|
|
@@ -17343,9 +17358,63 @@ function dueReason(pool, config, now, drawn) {
|
|
|
17343
17358
|
return pool.sceneAt !== void 0 && now - pool.sceneAt >= config.restMs ? "scene" : void 0;
|
|
17344
17359
|
}
|
|
17345
17360
|
/**
|
|
17346
|
-
*
|
|
17347
|
-
*
|
|
17348
|
-
*
|
|
17361
|
+
* Tells whether a bind group of a shader still holds a texture's source: a bind group listens to its resources'
|
|
17362
|
+
* `change`, and lets go when it is given another resource or is destroyed. Pixi warns when a source it holds is
|
|
17363
|
+
* destroyed, and nulls the binding.
|
|
17364
|
+
*
|
|
17365
|
+
* @param texture - A pooled texture.
|
|
17366
|
+
* @returns True while a bind group holds its source.
|
|
17367
|
+
*/
|
|
17368
|
+
function isBound(texture) {
|
|
17369
|
+
return texture.source.listenerCount("change") > 0;
|
|
17370
|
+
}
|
|
17371
|
+
/**
|
|
17372
|
+
* Gives back the idle textures of Pixi's pool (F187): one that no bind group holds is destroyed, one a filter or an
|
|
17373
|
+
* effect still binds goes to `held` and is destroyed once nothing binds it. Pixi then forgets every idle texture,
|
|
17374
|
+
* destroying none. Without the buckets Pixi 8 keeps, the pool is cleared the old way, every idle texture destroyed.
|
|
17375
|
+
*
|
|
17376
|
+
* @param pixi - The module the renderer loaded.
|
|
17377
|
+
* @param held - The targets waiting for their bind groups to let go.
|
|
17378
|
+
*/
|
|
17379
|
+
function clearPool(pixi, held) {
|
|
17380
|
+
const buckets = pixi.TexturePool._buckets;
|
|
17381
|
+
if (!(buckets instanceof Map)) {
|
|
17382
|
+
pixi.TexturePool.clear(true);
|
|
17383
|
+
return;
|
|
17384
|
+
}
|
|
17385
|
+
for (const textures of buckets.values()) for (const texture of textures) if (isBound(texture)) held.push(texture);
|
|
17386
|
+
else texture.destroy(true);
|
|
17387
|
+
pixi.TexturePool.clear(false);
|
|
17388
|
+
}
|
|
17389
|
+
/**
|
|
17390
|
+
* Destroys every held target no bind group holds any more, after the frame that let it go; the others wait. The
|
|
17391
|
+
* baseline drops by what each one held, so the growth the next trim measures is new growth only. Removes by swapping
|
|
17392
|
+
* with the last, so the list keeps its store.
|
|
17393
|
+
*
|
|
17394
|
+
* @param pool - The pool branch of the host state: its held targets and its baseline.
|
|
17395
|
+
*/
|
|
17396
|
+
function releaseHeld(pool) {
|
|
17397
|
+
const { held } = pool;
|
|
17398
|
+
let index = 0;
|
|
17399
|
+
while (index < held.length) {
|
|
17400
|
+
const texture = held[index];
|
|
17401
|
+
if (texture !== void 0 && isBound(texture)) {
|
|
17402
|
+
index += 1;
|
|
17403
|
+
continue;
|
|
17404
|
+
}
|
|
17405
|
+
if (texture !== void 0) {
|
|
17406
|
+
pool.baseline = Math.max(0, pool.baseline - sourceBytes(texture.source));
|
|
17407
|
+
texture.destroy(true);
|
|
17408
|
+
}
|
|
17409
|
+
const last = held.pop();
|
|
17410
|
+
if (index < held.length && last !== void 0) held[index] = last;
|
|
17411
|
+
}
|
|
17412
|
+
}
|
|
17413
|
+
/**
|
|
17414
|
+
* Trims the pool now: every idle texture of every bucket is destroyed, or held until no bind group holds it (F187); a
|
|
17415
|
+
* texture handed out survives and is destroyed when it comes back. The new baseline is what the targets hold after it;
|
|
17416
|
+
* the rest and the scene change are done. Logged in every build (rare: at most once per rest, scene change or pause);
|
|
17417
|
+
* an agent build tells the listeners.
|
|
17349
17418
|
*
|
|
17350
17419
|
* @param ctx - Domain context of the renderer plugin.
|
|
17351
17420
|
* @param reason - Why: a rest, a scene change, a pause.
|
|
@@ -17356,9 +17425,9 @@ function trimPool(ctx, reason) {
|
|
|
17356
17425
|
const { app, pixi } = state;
|
|
17357
17426
|
if (!state.ready || pixi === void 0 || app === void 0) return 0;
|
|
17358
17427
|
const before = targetBytes(app, state.kept);
|
|
17359
|
-
pixi.
|
|
17428
|
+
clearPool(pixi, state.pool.held);
|
|
17360
17429
|
const after = targetBytes(app, state.kept);
|
|
17361
|
-
const freedMb = roundTo((before - after) / BYTES_PER_MB$
|
|
17430
|
+
const freedMb = roundTo((before - after) / BYTES_PER_MB$2, 2);
|
|
17362
17431
|
state.pool.baseline = after;
|
|
17363
17432
|
state.pool.restDone = true;
|
|
17364
17433
|
state.pool.sceneAt = void 0;
|
|
@@ -17382,6 +17451,7 @@ function afterFrame(ctx, drawn) {
|
|
|
17382
17451
|
const app = state.app;
|
|
17383
17452
|
if (config === false || !state.ready || app === void 0) return;
|
|
17384
17453
|
const pool = state.pool;
|
|
17454
|
+
if (pool.held.length > 0) releaseHeld(pool);
|
|
17385
17455
|
const now = ctx.deps.clock.now();
|
|
17386
17456
|
if (drawn) {
|
|
17387
17457
|
pool.lastDrawnAt = now;
|
|
@@ -17500,6 +17570,9 @@ function createHostApi(ctx, deps) {
|
|
|
17500
17570
|
onReady: (fn) => {
|
|
17501
17571
|
state.onReady.push(fn);
|
|
17502
17572
|
},
|
|
17573
|
+
decideLoss: (fn) => {
|
|
17574
|
+
state.lossDeciders.push(fn);
|
|
17575
|
+
},
|
|
17503
17576
|
onRestore: (fn) => {
|
|
17504
17577
|
state.onRestore.push(fn);
|
|
17505
17578
|
},
|
|
@@ -17544,6 +17617,12 @@ function createHostApi(ctx, deps) {
|
|
|
17544
17617
|
});
|
|
17545
17618
|
return true;
|
|
17546
17619
|
},
|
|
17620
|
+
onGpu: (source) => {
|
|
17621
|
+
const app = state.app;
|
|
17622
|
+
if (!state.ready || app === void 0) return false;
|
|
17623
|
+
const slot = source._gpuData[app.renderer.uid];
|
|
17624
|
+
return slot !== void 0 && slot !== null;
|
|
17625
|
+
},
|
|
17547
17626
|
initSource: (source) => {
|
|
17548
17627
|
const app = state.app;
|
|
17549
17628
|
if (!state.ready || app === void 0) return;
|
|
@@ -18148,7 +18227,7 @@ function renderStage1(kctx, pixi, matrices, record) {
|
|
|
18148
18227
|
* @param record - The record, `s1` set.
|
|
18149
18228
|
* @returns The stand-in.
|
|
18150
18229
|
*/
|
|
18151
|
-
function standInOf(pixi, record) {
|
|
18230
|
+
function standInOf$1(pixi, record) {
|
|
18152
18231
|
const s1 = record.s1 ?? pixi.Texture.EMPTY;
|
|
18153
18232
|
if (record.standIn === void 0 || record.standIn.destroyed) {
|
|
18154
18233
|
record.standIn = new pixi.Sprite(s1);
|
|
@@ -18352,7 +18431,7 @@ function readsPlace(record) {
|
|
|
18352
18431
|
function renderStage3(kctx, pixi, matrices, record, now) {
|
|
18353
18432
|
const { key } = record;
|
|
18354
18433
|
const output = outputOf(kctx, pixi, record, now.r, now.P);
|
|
18355
|
-
const standIn = standInOf(pixi, record);
|
|
18434
|
+
const standIn = standInOf$1(pixi, record);
|
|
18356
18435
|
const Ps = key[KEY.Ps] ?? 0;
|
|
18357
18436
|
if (readsPlace(record)) setOrigins(record.slots, (key[KEY.X0] ?? 0) - Ps + now.tx - (key[KEY.tx] ?? 0), (key[KEY.Y0] ?? 0) - Ps + now.ty - (key[KEY.ty] ?? 0));
|
|
18358
18437
|
matrices.m3.set(1, 0, 0, 1, Ps, Ps);
|
|
@@ -18461,7 +18540,7 @@ function warnRefused(kctx, label) {
|
|
|
18461
18540
|
if (state.warnedBudget) return;
|
|
18462
18541
|
state.warnedBudget = true;
|
|
18463
18542
|
kctx.ctx.log.warn("renderer:kept-budget", {
|
|
18464
|
-
mb: roundTo(state.bytes / BYTES_PER_MB$
|
|
18543
|
+
mb: roundTo(state.bytes / BYTES_PER_MB$2, 2),
|
|
18465
18544
|
keptMb: kctx.ctx.config.keptMb,
|
|
18466
18545
|
refused: label
|
|
18467
18546
|
});
|
|
@@ -19400,7 +19479,7 @@ function createKeptState(config) {
|
|
|
19400
19479
|
frame: 0,
|
|
19401
19480
|
unsorted: false,
|
|
19402
19481
|
bytes: 0,
|
|
19403
|
-
budget: config.keptMb * BYTES_PER_MB$
|
|
19482
|
+
budget: config.keptMb * BYTES_PER_MB$2,
|
|
19404
19483
|
takesOpen: 0,
|
|
19405
19484
|
takesWindow: 0,
|
|
19406
19485
|
refreshesOpen: 0,
|
|
@@ -20220,7 +20299,7 @@ function neededBytes(record, now, box) {
|
|
|
20220
20299
|
* @param view - Its view.
|
|
20221
20300
|
*/
|
|
20222
20301
|
function handFilters(kctx, pixi, record, view) {
|
|
20223
|
-
const standIn = standInOf(pixi, record);
|
|
20302
|
+
const standIn = standInOf$1(pixi, record);
|
|
20224
20303
|
kctx.sync.clearFilters(record.top);
|
|
20225
20304
|
kctx.sync.applyFilters(view, filtersOf$1(kctx.ctx.state.sync, record.entity), noMark$1, standIn);
|
|
20226
20305
|
}
|
|
@@ -22119,7 +22198,7 @@ function createKeptApi(ctx, deps) {
|
|
|
22119
22198
|
sprite: (id) => spriteOf$1(kctx, id),
|
|
22120
22199
|
stats: () => ({
|
|
22121
22200
|
pictures: state.drawnPictures,
|
|
22122
|
-
mb: roundTo(state.bytes / BYTES_PER_MB$
|
|
22201
|
+
mb: roundTo(state.bytes / BYTES_PER_MB$2, 2),
|
|
22123
22202
|
retakes: state.takesWindow,
|
|
22124
22203
|
evicted: state.evictedWindow,
|
|
22125
22204
|
refused: state.refusedWindow
|
|
@@ -22330,6 +22409,137 @@ function stopDemand(state) {
|
|
|
22330
22409
|
state.verify.reference = void 0;
|
|
22331
22410
|
}
|
|
22332
22411
|
//#endregion
|
|
22412
|
+
//#region src/plugins/renderer/loss.ts
|
|
22413
|
+
/** The `localStorage` key of the kept records. */
|
|
22414
|
+
const LOSS_KEY = "moku-game:gpu-losses";
|
|
22415
|
+
/** Bytes in a megabyte. */
|
|
22416
|
+
const BYTES_PER_MB$1 = 1048576;
|
|
22417
|
+
/** Milliseconds in a second. */
|
|
22418
|
+
const MS_PER_S = 1e3;
|
|
22419
|
+
/**
|
|
22420
|
+
* Seconds since the page started: the wall clock against the page's time origin.
|
|
22421
|
+
*
|
|
22422
|
+
* @param now - The wall clock in milliseconds.
|
|
22423
|
+
* @returns The seconds, to one decimal; 0 where the page has no time origin.
|
|
22424
|
+
*/
|
|
22425
|
+
function uptimeOf(now) {
|
|
22426
|
+
const origin = globalThis.performance?.timeOrigin;
|
|
22427
|
+
return origin === void 0 ? 0 : tenth((now - origin) / MS_PER_S);
|
|
22428
|
+
}
|
|
22429
|
+
/**
|
|
22430
|
+
* Rounds to one decimal.
|
|
22431
|
+
*
|
|
22432
|
+
* @param value - A number.
|
|
22433
|
+
* @returns The number to one decimal.
|
|
22434
|
+
* @example
|
|
22435
|
+
* ```ts
|
|
22436
|
+
* tenth(12.345); // 12.3
|
|
22437
|
+
* ```
|
|
22438
|
+
*/
|
|
22439
|
+
function tenth(value) {
|
|
22440
|
+
return Math.round(value * 10) / 10;
|
|
22441
|
+
}
|
|
22442
|
+
/**
|
|
22443
|
+
* The JS heap in use, in megabytes, where the browser tells it: `performance.memory` of Chromium. WebKit has none.
|
|
22444
|
+
*
|
|
22445
|
+
* @returns The megabytes, or `undefined`: the record is kept without it.
|
|
22446
|
+
*/
|
|
22447
|
+
function heapMb$1() {
|
|
22448
|
+
const used = (globalThis.performance?.memory)?.usedJSHeapSize;
|
|
22449
|
+
return typeof used === "number" ? tenth(used / BYTES_PER_MB$1) : void 0;
|
|
22450
|
+
}
|
|
22451
|
+
/**
|
|
22452
|
+
* The flow path the game stands on, or `""` before the graph runs.
|
|
22453
|
+
*
|
|
22454
|
+
* @param ctx - Domain context of the renderer plugin.
|
|
22455
|
+
* @returns The path.
|
|
22456
|
+
*/
|
|
22457
|
+
function pathOf$1(ctx) {
|
|
22458
|
+
try {
|
|
22459
|
+
return ctx.deps.flow.state().path;
|
|
22460
|
+
} catch {
|
|
22461
|
+
return "";
|
|
22462
|
+
}
|
|
22463
|
+
}
|
|
22464
|
+
/**
|
|
22465
|
+
* Reads the kept records. Anything that is not a list, and a storage that throws, reads as none.
|
|
22466
|
+
*
|
|
22467
|
+
* @returns The records, oldest first.
|
|
22468
|
+
*/
|
|
22469
|
+
function readLosses() {
|
|
22470
|
+
try {
|
|
22471
|
+
const text = globalThis.localStorage?.getItem(LOSS_KEY);
|
|
22472
|
+
const parsed = text === null || text === void 0 ? [] : JSON.parse(text);
|
|
22473
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
22474
|
+
} catch {
|
|
22475
|
+
return [];
|
|
22476
|
+
}
|
|
22477
|
+
}
|
|
22478
|
+
/**
|
|
22479
|
+
* Keeps the newest records. A storage that refuses the write (private mode, full) keeps nothing: the log still has
|
|
22480
|
+
* the loss.
|
|
22481
|
+
*
|
|
22482
|
+
* @param records - The records, oldest first.
|
|
22483
|
+
*/
|
|
22484
|
+
function writeLosses(records) {
|
|
22485
|
+
try {
|
|
22486
|
+
globalThis.localStorage?.setItem(LOSS_KEY, JSON.stringify(records.slice(-10)));
|
|
22487
|
+
} catch {}
|
|
22488
|
+
}
|
|
22489
|
+
/**
|
|
22490
|
+
* Reloads the page. Headless and in a test there is no page, so nothing happens.
|
|
22491
|
+
*/
|
|
22492
|
+
function reloadPage$2() {
|
|
22493
|
+
globalThis.location?.reload();
|
|
22494
|
+
}
|
|
22495
|
+
/**
|
|
22496
|
+
* Records a lost device and decides whether the page leaves: it reloads when textures had their decoded image freed,
|
|
22497
|
+
* since they cannot be uploaded to a new device; without any, the renderer restores as before. The `decideLoss`
|
|
22498
|
+
* callback of the plugin root.
|
|
22499
|
+
*
|
|
22500
|
+
* @param ctx - Domain context of the renderer plugin.
|
|
22501
|
+
* @param info - What was lost and the texture bytes the lost application held.
|
|
22502
|
+
* @param freed - How many textures hold the stand-in instead of their decoded image.
|
|
22503
|
+
* @param reload - Reloads the page; a test passes a spy.
|
|
22504
|
+
* @returns True when the page reloads.
|
|
22505
|
+
*/
|
|
22506
|
+
function leaveAfterLoss(ctx, info, freed, reload = reloadPage$2) {
|
|
22507
|
+
const reloaded = freed > 0;
|
|
22508
|
+
const now = ctx.deps.clock.now();
|
|
22509
|
+
const record = {
|
|
22510
|
+
at: now,
|
|
22511
|
+
uptimeS: uptimeOf(now),
|
|
22512
|
+
kind: info.kind,
|
|
22513
|
+
reason: info.reason,
|
|
22514
|
+
path: pathOf$1(ctx),
|
|
22515
|
+
textureMb: tenth(info.textureBytes / BYTES_PER_MB$1),
|
|
22516
|
+
heapMb: heapMb$1(),
|
|
22517
|
+
freed,
|
|
22518
|
+
reloaded,
|
|
22519
|
+
reported: false
|
|
22520
|
+
};
|
|
22521
|
+
ctx.log.error("renderer:gpu-lost", record);
|
|
22522
|
+
writeLosses([...readLosses(), record]);
|
|
22523
|
+
if (reloaded) reload();
|
|
22524
|
+
return reloaded;
|
|
22525
|
+
}
|
|
22526
|
+
/**
|
|
22527
|
+
* Logs every kept loss no start has reported yet, once: the line a phone shows after the reload a loss caused. Called
|
|
22528
|
+
* when the renderer starts.
|
|
22529
|
+
*
|
|
22530
|
+
* @param ctx - Domain context of the renderer plugin.
|
|
22531
|
+
*/
|
|
22532
|
+
function reportLosses(ctx) {
|
|
22533
|
+
const records = readLosses();
|
|
22534
|
+
const unreported = records.filter((record) => record.reported !== true);
|
|
22535
|
+
if (unreported.length === 0) return;
|
|
22536
|
+
for (const record of unreported) ctx.log.warn("renderer:gpu-lost-before", record);
|
|
22537
|
+
writeLosses(records.map((record) => ({
|
|
22538
|
+
...record,
|
|
22539
|
+
reported: true
|
|
22540
|
+
})));
|
|
22541
|
+
}
|
|
22542
|
+
//#endregion
|
|
22333
22543
|
//#region src/plugins/renderer/monitor/log-types.ts
|
|
22334
22544
|
/**
|
|
22335
22545
|
* The version every line carries as `v`.
|
|
@@ -22769,7 +22979,7 @@ function usedHeapBytes() {
|
|
|
22769
22979
|
*/
|
|
22770
22980
|
function heapMb() {
|
|
22771
22981
|
const bytes = usedHeapBytes();
|
|
22772
|
-
return Number.isNaN(bytes) ? null : roundTo(bytes / BYTES_PER_MB$
|
|
22982
|
+
return Number.isNaN(bytes) ? null : roundTo(bytes / BYTES_PER_MB$2, 2);
|
|
22773
22983
|
}
|
|
22774
22984
|
//#endregion
|
|
22775
22985
|
//#region src/plugins/renderer/monitor/problems.ts
|
|
@@ -25134,16 +25344,16 @@ function sampleLine(pc, start, end) {
|
|
|
25134
25344
|
heapMb: (sections & SECTION.memory) === 0 ? null : heapMb(),
|
|
25135
25345
|
kept: {
|
|
25136
25346
|
pictures: totals.keptMax,
|
|
25137
|
-
mb: roundTo(pc.ctx.state.kept.bytes / BYTES_PER_MB$
|
|
25347
|
+
mb: roundTo(pc.ctx.state.kept.bytes / BYTES_PER_MB$2, 2),
|
|
25138
25348
|
retakes: totals.retakes,
|
|
25139
25349
|
refreshes: deps.kept.drainRefreshes()
|
|
25140
25350
|
},
|
|
25141
25351
|
textures: {
|
|
25142
25352
|
count: usage.count,
|
|
25143
|
-
mb: ms(usage.bytes / BYTES_PER_MB$
|
|
25144
|
-
art: ms(usage.art / BYTES_PER_MB$
|
|
25145
|
-
targets: ms(usage.targets / BYTES_PER_MB$
|
|
25146
|
-
kept: ms(usage.kept / BYTES_PER_MB$
|
|
25353
|
+
mb: ms(usage.bytes / BYTES_PER_MB$2),
|
|
25354
|
+
art: ms(usage.art / BYTES_PER_MB$2),
|
|
25355
|
+
targets: ms(usage.targets / BYTES_PER_MB$2),
|
|
25356
|
+
kept: ms(usage.kept / BYTES_PER_MB$2)
|
|
25147
25357
|
},
|
|
25148
25358
|
views: views.views,
|
|
25149
25359
|
pooled: views.pooled,
|
|
@@ -25693,7 +25903,7 @@ function writeEvent(pc, name, detail) {
|
|
|
25693
25903
|
/** A flush once a second of page clock. */
|
|
25694
25904
|
const FLUSH_MS = 1e3;
|
|
25695
25905
|
/** A heap drop of at least this many bytes between two commits hints at a collection. */
|
|
25696
|
-
const GC_DROP_BYTES = .5 * BYTES_PER_MB$
|
|
25906
|
+
const GC_DROP_BYTES = .5 * BYTES_PER_MB$2;
|
|
25697
25907
|
/** Pixels per megapixel. */
|
|
25698
25908
|
const PIXELS_PER_MPX = 1e6;
|
|
25699
25909
|
/** The most skipped frames the 8-bit `skipped` column holds; more are written as this. */
|
|
@@ -25741,7 +25951,7 @@ function writePasses(pc, slot) {
|
|
|
25741
25951
|
c.filterApplies[slot] = counted ? cellF64(counts, COUNT.filterApplies) : NaN;
|
|
25742
25952
|
c.filterMpx[slot] = counted ? cellF64(counts, COUNT.filterPixels) / PIXELS_PER_MPX : NaN;
|
|
25743
25953
|
c.uploads[slot] = counted ? cellF64(counts, COUNT.uploads) : NaN;
|
|
25744
|
-
c.uploadMb[slot] = counted ? cellF64(counts, COUNT.uploadBytes) / BYTES_PER_MB$
|
|
25954
|
+
c.uploadMb[slot] = counted ? cellF64(counts, COUNT.uploadBytes) / BYTES_PER_MB$2 : NaN;
|
|
25745
25955
|
c.rebuilds[slot] = perf.produced === 0 ? NaN : cellF64(counts, COUNT.rebuilds);
|
|
25746
25956
|
const targets = (bits & MEASURE.targets) !== 0;
|
|
25747
25957
|
c.targetsCreated[slot] = targets ? cellF64(counts, COUNT.targetsCreated) : NaN;
|
|
@@ -27298,11 +27508,11 @@ function createMonitorApi(ctx, deps) {
|
|
|
27298
27508
|
drawn: drawing ? roundTo(state.drawnFps, 1) : 0,
|
|
27299
27509
|
frameMs: roundTo(state.frameMs, 2),
|
|
27300
27510
|
textures: usage.count,
|
|
27301
|
-
textureMb: roundTo(usage.bytes / BYTES_PER_MB$
|
|
27511
|
+
textureMb: roundTo(usage.bytes / BYTES_PER_MB$2, 2),
|
|
27302
27512
|
textureMbSplit: {
|
|
27303
|
-
art: roundTo(usage.art / BYTES_PER_MB$
|
|
27304
|
-
targets: roundTo(usage.targets / BYTES_PER_MB$
|
|
27305
|
-
kept: roundTo(usage.kept / BYTES_PER_MB$
|
|
27513
|
+
art: roundTo(usage.art / BYTES_PER_MB$2, 2),
|
|
27514
|
+
targets: roundTo(usage.targets / BYTES_PER_MB$2, 2),
|
|
27515
|
+
kept: roundTo(usage.kept / BYTES_PER_MB$2, 2)
|
|
27306
27516
|
},
|
|
27307
27517
|
views: counts.views,
|
|
27308
27518
|
pooled: counts.pooled,
|
|
@@ -30799,6 +31009,83 @@ function paintShape(object, value, color) {
|
|
|
30799
31009
|
strokeShape(object, value);
|
|
30800
31010
|
}
|
|
30801
31011
|
//#endregion
|
|
31012
|
+
//#region src/plugins/renderer/sync/release.ts
|
|
31013
|
+
/**
|
|
31014
|
+
* Tells whether a decoded image can be freed: an `ImageBitmap` has `close`, an `<img>` element has none.
|
|
31015
|
+
*
|
|
31016
|
+
* @param image - The decoded image.
|
|
31017
|
+
* @returns True for an image with `close`.
|
|
31018
|
+
*/
|
|
31019
|
+
function isClosable(image) {
|
|
31020
|
+
return typeof image === "object" && image !== null && "close" in image && typeof image.close === "function";
|
|
31021
|
+
}
|
|
31022
|
+
/**
|
|
31023
|
+
* The 1x1 transparent image every freed source holds, made once per renderer: a canvas with a 2d context, which both
|
|
31024
|
+
* `copyExternalImageToTexture` and `texSubImage2D` take.
|
|
31025
|
+
*
|
|
31026
|
+
* @param release - The release branch of the sync state.
|
|
31027
|
+
* @returns The stand-in.
|
|
31028
|
+
*/
|
|
31029
|
+
function standInOf(release) {
|
|
31030
|
+
if (release.standIn !== void 0) return release.standIn;
|
|
31031
|
+
const canvas = new OffscreenCanvas(1, 1);
|
|
31032
|
+
canvas.getContext("2d");
|
|
31033
|
+
release.standIn = canvas;
|
|
31034
|
+
return canvas;
|
|
31035
|
+
}
|
|
31036
|
+
/**
|
|
31037
|
+
* Remembers a new source of `textures.create` whose decoded image can be freed: it waits for its upload. An image that
|
|
31038
|
+
* cannot be closed, or a runtime without `OffscreenCanvas`, keeps its image.
|
|
31039
|
+
*
|
|
31040
|
+
* @param state - The sync branch of the plugin state.
|
|
31041
|
+
* @param source - The source just made.
|
|
31042
|
+
*/
|
|
31043
|
+
function holdImage(state, source) {
|
|
31044
|
+
if (!isClosable(source.resource) || typeof OffscreenCanvas === "undefined") return;
|
|
31045
|
+
state.release.pending.push(source);
|
|
31046
|
+
}
|
|
31047
|
+
/**
|
|
31048
|
+
* Frees the decoded images Pixi has on the GPU now: each bitmap is closed and its source gets the stand-in. A source
|
|
31049
|
+
* not uploaded yet keeps waiting, and one destroyed meanwhile leaves the list. Runs after the stage pass of a drawn
|
|
31050
|
+
* frame; one compare while nothing waits, and no allocation while sources wait (the body of the sync module's
|
|
31051
|
+
* `releaseStep`).
|
|
31052
|
+
*
|
|
31053
|
+
* @param sctx - Domain context of the sync module.
|
|
31054
|
+
*/
|
|
31055
|
+
function releaseStep(sctx) {
|
|
31056
|
+
const { release } = sctx.ctx.state.sync;
|
|
31057
|
+
const pending = release.pending;
|
|
31058
|
+
if (pending.length === 0) return;
|
|
31059
|
+
let kept = 0;
|
|
31060
|
+
for (let index = 0; index < pending.length; index += 1) {
|
|
31061
|
+
const source = pending[index];
|
|
31062
|
+
if (source === void 0 || source.destroyed) continue;
|
|
31063
|
+
if (!sctx.deps.host.onGpu(source)) {
|
|
31064
|
+
pending[kept] = source;
|
|
31065
|
+
kept += 1;
|
|
31066
|
+
continue;
|
|
31067
|
+
}
|
|
31068
|
+
const image = source.resource;
|
|
31069
|
+
source.resource = standInOf(release);
|
|
31070
|
+
release.freed.add(source);
|
|
31071
|
+
if (isClosable(image)) image.close();
|
|
31072
|
+
}
|
|
31073
|
+
pending.length = kept;
|
|
31074
|
+
}
|
|
31075
|
+
/**
|
|
31076
|
+
* Frees the decoded image of a source that goes before its upload, at once instead of at the next collection, and
|
|
31077
|
+
* forgets a freed one. A freed source holds the stand-in and closes nothing.
|
|
31078
|
+
*
|
|
31079
|
+
* @param state - The sync branch of the plugin state.
|
|
31080
|
+
* @param source - The source of a texture being destroyed.
|
|
31081
|
+
*/
|
|
31082
|
+
function dropImage(state, source) {
|
|
31083
|
+
const { release } = state;
|
|
31084
|
+
if (release.freed.delete(source)) return;
|
|
31085
|
+
const image = source.resource;
|
|
31086
|
+
if (isClosable(image)) image.close();
|
|
31087
|
+
}
|
|
31088
|
+
//#endregion
|
|
30802
31089
|
//#region src/plugins/renderer/sync/textures.ts
|
|
30803
31090
|
/** The colour a missing texture is drawn in. */
|
|
30804
31091
|
const PLACEHOLDER_TINT = 16711935;
|
|
@@ -30921,6 +31208,7 @@ function createTexture(sctx, image, options) {
|
|
|
30921
31208
|
}) : pixi.Texture.from(image);
|
|
30922
31209
|
const nine = options?.nine;
|
|
30923
31210
|
base.source.autoGarbageCollect = false;
|
|
31211
|
+
holdImage(sctx.ctx.state.sync, base.source);
|
|
30924
31212
|
if (nine === void 0) return base;
|
|
30925
31213
|
const bordered = new pixi.Texture({
|
|
30926
31214
|
source: base.source,
|
|
@@ -31088,6 +31376,7 @@ function destroyTexture(state, texture) {
|
|
|
31088
31376
|
texture.destroy(false);
|
|
31089
31377
|
return;
|
|
31090
31378
|
}
|
|
31379
|
+
dropImage(state, texture.source);
|
|
31091
31380
|
destroyWhole(texture);
|
|
31092
31381
|
}
|
|
31093
31382
|
//#endregion
|
|
@@ -34011,7 +34300,8 @@ function withDeps$8(ctx) {
|
|
|
34011
34300
|
* drawn and clears them; a drawn frame draws the probes of the warm-up onto the canvas first (F4: the
|
|
34012
34301
|
* stage pass clears them, in the same task, so they never show), then uploads the queued texture sources (F60), then
|
|
34013
34302
|
* the kept pictures (`kept.flush`, so the canvas stays one pass, E7), then the stage, then a shot of the frame just drawn
|
|
34014
|
-
* while the canvas texture holds it (`shots.after`, never of the heat map), then
|
|
34303
|
+
* while the canvas texture holds it (`shots.after`, never of the heat map), then, when Pixi drew it, the decoded images
|
|
34304
|
+
* now on the GPU are freed (`sync.releaseStep`, F189), then the pixel leg of the kept oracle;
|
|
34015
34305
|
* `demand` settles the
|
|
34016
34306
|
* frame (the dev check, the pixel oracle), and `monitor` closes it and hands a drawn one to a
|
|
34017
34307
|
* waiting capture; last, `host` trims Pixi's texture pool when a rest or a scene change is due. The display objects
|
|
@@ -34055,6 +34345,7 @@ function renderFrame(ctx, modules) {
|
|
|
34055
34345
|
if (rendered) {
|
|
34056
34346
|
ctx.deps.time.frameDrawn();
|
|
34057
34347
|
if (probed || uploaded || built) ctx.deps.time.frameProbed();
|
|
34348
|
+
modules.sync.releaseStep();
|
|
34058
34349
|
}
|
|
34059
34350
|
modules.kept.after();
|
|
34060
34351
|
}
|
|
@@ -34077,6 +34368,7 @@ function renderFrame(ctx, modules) {
|
|
|
34077
34368
|
async function startRenderer(ctx) {
|
|
34078
34369
|
const rendererCtx = withDeps$8(ctx);
|
|
34079
34370
|
const modules = createModules$1(rendererCtx);
|
|
34371
|
+
reportLosses(rendererCtx);
|
|
34080
34372
|
modules.host.onResolution(() => modules.demand.whole("resize"));
|
|
34081
34373
|
modules.host.onReady(() => {
|
|
34082
34374
|
modules.viewport.start();
|
|
@@ -34090,6 +34382,7 @@ async function startRenderer(ctx) {
|
|
|
34090
34382
|
modules.sync.forget();
|
|
34091
34383
|
modules.shots.forget();
|
|
34092
34384
|
});
|
|
34385
|
+
modules.host.decideLoss((info) => leaveAfterLoss(rendererCtx, info, modules.sync.freedCount()));
|
|
34093
34386
|
modules.host.onRestore((rebuilt) => {
|
|
34094
34387
|
modules.demand.whole("restore");
|
|
34095
34388
|
if (!rebuilt) return;
|
|
@@ -37340,6 +37633,8 @@ function createSyncApi(ctx, deps) {
|
|
|
37340
37633
|
warmStep: () => warmStep(sctx),
|
|
37341
37634
|
takeBuildWork: () => takeBuildWork(state.aside),
|
|
37342
37635
|
uploadStep: () => uploadStep(sctx),
|
|
37636
|
+
releaseStep: () => releaseStep(sctx),
|
|
37637
|
+
freedCount: () => state.release.freed.size,
|
|
37343
37638
|
onWarm: (fn) => {
|
|
37344
37639
|
state.warm.listeners.push(fn);
|
|
37345
37640
|
},
|
|
@@ -38174,6 +38469,19 @@ function createUploadState() {
|
|
|
38174
38469
|
return upload;
|
|
38175
38470
|
}
|
|
38176
38471
|
/**
|
|
38472
|
+
* Creates the empty release branch: no bitmap waits, none was freed, no stand-in made yet. Its own non-exported
|
|
38473
|
+
* function, as `emptyMap`.
|
|
38474
|
+
*
|
|
38475
|
+
* @returns The release branch of the sync state.
|
|
38476
|
+
*/
|
|
38477
|
+
function createReleaseState() {
|
|
38478
|
+
return {
|
|
38479
|
+
pending: [],
|
|
38480
|
+
freed: emptySet$4(),
|
|
38481
|
+
standIn: void 0
|
|
38482
|
+
};
|
|
38483
|
+
}
|
|
38484
|
+
/**
|
|
38177
38485
|
* Creates the empty aside queue of a scene build: nothing waits for a view. Its own non-exported function, as
|
|
38178
38486
|
* `emptyMap`.
|
|
38179
38487
|
*
|
|
@@ -38232,6 +38540,7 @@ function createSyncState(debug) {
|
|
|
38232
38540
|
viewlessEntries: false,
|
|
38233
38541
|
warm: createWarmState(),
|
|
38234
38542
|
upload: createUploadState(),
|
|
38543
|
+
release: createReleaseState(),
|
|
38235
38544
|
hollowClass: void 0,
|
|
38236
38545
|
filterKinds: emptyWeakMap$1(),
|
|
38237
38546
|
filterOwners: emptyWeakMap$1(),
|