@moku-labs/game 0.15.76 → 0.15.78

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.
@@ -15037,7 +15037,116 @@ function installRebindingRenderGroupPipe(pixi) {
15037
15037
  };
15038
15038
  }
15039
15039
  //#endregion
15040
+ //#region src/plugins/renderer/reasons.ts
15041
+ /**
15042
+ * @file renderer plugin — the reasons a frame is drawn and a canvas pass begins, in ring order: the monitor stores a
15043
+ * reason by its index. A plain module of the plugin root, so the monitor reads the order without importing the demand
15044
+ * module's run-time code (L1), and `host/render-pass.ts` names a begin without importing the monitor; `DemandReason`
15045
+ * in `demand/types.ts` is derived from it.
15046
+ */
15047
+ /**
15048
+ * Every reason in ring order: the monitor stores the index (spec 11 `FrameColumns.reason`), 255 for a frame without a
15049
+ * decision. New reasons are only ever appended (block 3B: `"overlay"`, `"retake"` after `"none"`), so stored indices
15050
+ * keep their meaning. There is no whole-frame reason for `renderer.invalidate`: it always names an entity
15051
+ * (LEAD-FIXES-4). A root export, so a reader of the ring names a reason without building a record.
15052
+ *
15053
+ * @example
15054
+ * ```ts
15055
+ * // An overlay names why the newest frame of a debug build was drawn: a piece moved, a counted change mark.
15056
+ * const ring = app.renderer.monitor.frames();
15057
+ * DEMAND_REASONS[ring.columns.reason[ring.newest] ?? 255]; // "mark"
15058
+ * ```
15059
+ */
15060
+ const DEMAND_REASONS = [
15061
+ "always",
15062
+ "first",
15063
+ "resize",
15064
+ "restore",
15065
+ "layers",
15066
+ "debug",
15067
+ "wake",
15068
+ "capture",
15069
+ "request",
15070
+ "mark",
15071
+ "verify",
15072
+ "none",
15073
+ "overlay",
15074
+ "retake"
15075
+ ];
15076
+ /**
15077
+ * The reasons a canvas pass began, by their index in the pass ring's `restart` column: new ones are only ever appended.
15078
+ * A root export, so a reader of the ring names a reason without building a record.
15079
+ *
15080
+ * @example
15081
+ * ```ts
15082
+ * // The editor's pass strip says why the newest pass of a debug build began.
15083
+ * const { passes } = app.renderer.monitor.frames();
15084
+ * CANVAS_RESTARTS[passes.restart[passes.newest] ?? 0]; // "filter"
15085
+ * ```
15086
+ */
15087
+ const CANVAS_RESTARTS = [
15088
+ "none",
15089
+ "first",
15090
+ "filter",
15091
+ "mask",
15092
+ "depth",
15093
+ "empty"
15094
+ ];
15095
+ /** The index of each reason in `CANVAS_RESTARTS`: what the lazy canvas pass hands the monitor, no string per pass. */
15096
+ const RESTART = {
15097
+ none: 0,
15098
+ first: 1,
15099
+ filter: 2,
15100
+ mask: 3,
15101
+ depth: 4,
15102
+ empty: 5
15103
+ };
15104
+ //#endregion
15040
15105
  //#region src/plugins/renderer/host/render-pass.ts
15106
+ /**
15107
+ * @file renderer/host — the lazy canvas pass of WebGPU (B3 of change 2026-10-18-memory-render). Pixi 8.22 begins the
15108
+ * canvas's render pass when a render starts (`RenderTargetSystem.renderStart` → `GpuRenderTargetAdaptor
15109
+ * .startRenderPass`, a clear and a store). A frame whose first instruction is a filter ends that pass at once with no
15110
+ * draw in it (`FilterSystem` binds its input), and the filter's apply begins it again with a load: on a tiled GPU (the
15111
+ * Mali of a Galaxy A26) the frame pays a store and a reload of the whole canvas for nothing. And every pass Pixi begins
15112
+ * on a target that is not transient stores and loads its depth-stencil attachment, which the canvas has from its
15113
+ * first stencil mask on, so every filter break also stores and reloads stencil and depth that nothing reads.
15114
+ *
15115
+ * Three classes fix both through Pixi's registry, no patch: a subclass of `GpuRenderTargetSystem` whose adaptor (a
15116
+ * subclass of `GpuRenderTargetAdaptor`) defers a pass on the canvas, and a subclass of `PipelineSystem` that begins a
15117
+ * deferred pass when the first draw asks for its pipeline. In Pixi 8.22 every command recorded into a pass is preceded
15118
+ * by a call to the pipeline system: a draw by `getPipeline` (`GpuEncoderSystem.draw`) or `getBufferNamesToBind`
15119
+ * (`setGeometry`, the first call of a batch and of a graphics draw), a stencil reference by `setStencilMode`
15120
+ * (`GpuStencilSystem`), a render bundle by `bundleStateKey`. The encoder itself stays Pixi's, or the counting one of
15121
+ * the monitor, so a pass that never began is never counted.
15122
+ *
15123
+ * The canvas pass. A bind of the canvas with no pass open on it begins nothing: it ends the open pass, as Pixi's begin
15124
+ * would, and keeps the clear it asked for, owed. The pass begins at the first draw, with the owed clear, so a frame
15125
+ * clears its canvas exactly once, in the pass that draws first. A canvas bound with no draw before another target is
15126
+ * bound begins nothing at all; its clear waits for the next bind of the canvas. A read of the canvas (a backdrop
15127
+ * filter's copy) pays the owed clear first. At the end of the frame (`renderEnd`) an owed clear is paid, and a canvas
15128
+ * that saw no pass at all gets one, so a frame that never draws on it still clears and presents it, as Pixi's does. A
15129
+ * canvas with multisampling is left to Pixi (its restore copies the canvas).
15130
+ *
15131
+ * The depth-stencil rule, for the canvas only. Pixi's stencil masks count: a push draws the mask with `increment`
15132
+ * where the stencil equals the depth of the stack, its pop draws the same instructions with `decrement`, so with no
15133
+ * mask open the stencil is 0 everywhere a draw tests it. A canvas pass therefore loads the stencil only while a mask
15134
+ * is open on the canvas (`maskStackIndex > 0`), and clears it to 0 otherwise. It stores the stencil while a mask is
15135
+ * open, or when a mask was pushed on the canvas in this frame or the one before; else it discards it. A mask pushed
15136
+ * into a pass that discards (the first mask after frames without one) begins the pass again first, with the stencil
15137
+ * cleared and stored, so a mask that spans a filter break never loses what it drew. Depth is read only by a pipeline
15138
+ * that tests it and written only by one that writes it; Pixi's 2D pipes draw with `State.for2d()`, which does
15139
+ * neither, so the canvas clears and discards its depth until the first pipeline that tests or writes depth, which
15140
+ * begins the pass again with the depth cleared and stored, and stores it from then on (only `GpuEncoderSystem.draw`
15141
+ * carries such a state, and it asks for the pipeline before it sets anything, so the new pass misses nothing). A copy
15142
+ * of the canvas's depth keeps it too, from then on.
15143
+ *
15144
+ * The target change. A bind that changes the target makes Pixi's stencil system set its mode and its reference, and the
15145
+ * reference is a command of the pass. A render whose root canvas was not the last target bound (the first frame, a
15146
+ * frame after a kept picture was taken) would so begin its canvas pass at once. The render target system marks the
15147
+ * canvas bound before Pixi binds it, so that bind changes nothing, and the adaptor tells the stencil system right
15148
+ * after the pass began; a mask pushed first begins it before the stencil system reads its target.
15149
+ */
15041
15150
  /** Pixi's `CLEAR.NONE`. */
15042
15151
  const CLEAR_NONE = 0;
15043
15152
  /** Pixi's `CLEAR.ALL`: colour, depth and stencil. */
@@ -15055,15 +15164,18 @@ function clearBits(clear) {
15055
15164
  if (clear === false) return CLEAR_NONE;
15056
15165
  return clear;
15057
15166
  }
15167
+ /** The listener of a stage nobody listens to. */
15168
+ function noListener() {}
15058
15169
  /**
15059
15170
  * Builds the classes of the lazy canvas pass from the module object, at call time, because the bases arrive with the
15060
15171
  * lazily loaded module. Each system keeps its base's `static extension` object as it is, so the registry files it
15061
15172
  * under the same type and name. They cost one test of two booleans per pipeline request, and nothing else per draw.
15062
15173
  *
15063
15174
  * @param pixi - The loaded Pixi module.
15175
+ * @param canvasBegan - Told of every canvas pass that really began, with its reason; the file never imports the monitor.
15064
15176
  * @returns The render target system and the pipeline system.
15065
15177
  */
15066
- function createLazyCanvasClasses(pixi) {
15178
+ function createLazyCanvasClasses(pixi, canvasBegan = noListener) {
15067
15179
  /**
15068
15180
  * Pixi's WebGPU adaptor, which begins a pass on the canvas at its first draw and sets the canvas's stencil and depth
15069
15181
  * operations by the rule of the file. One per renderer.
@@ -15169,7 +15281,7 @@ function createLazyCanvasClasses(pixi) {
15169
15281
  const bits = clearBits(clear);
15170
15282
  if (this.canvas !== void 0 && this.canvas !== renderTarget) this.settleCanvas();
15171
15283
  if (bits === CLEAR_NONE && this.isOpen(renderTarget)) {
15172
- this.beginCanvas(renderTarget, CLEAR_NONE, void 0, viewport);
15284
+ this.beginCanvas(renderTarget, CLEAR_NONE, void 0, viewport, RESTART.filter);
15173
15285
  return;
15174
15286
  }
15175
15287
  this.finishRenderPass();
@@ -15226,7 +15338,7 @@ function createLazyCanvasClasses(pixi) {
15226
15338
  this.canvas = void 0;
15227
15339
  this.owed = CLEAR_NONE;
15228
15340
  this.owedColorSet = false;
15229
- this.beginCanvas(target, bits, color, this.view);
15341
+ this.beginCanvas(target, bits, color, this.view, this.acquired ? RESTART.filter : RESTART.first);
15230
15342
  }
15231
15343
  /**
15232
15344
  * A pipeline that tests or writes depth was asked for: the canvas keeps its depth from now on, and an open canvas
@@ -15235,7 +15347,7 @@ function createLazyCanvasClasses(pixi) {
15235
15347
  useDepth() {
15236
15348
  this.depthUsed = true;
15237
15349
  const canvas = this.openCanvas;
15238
- if (canvas?.depthStencilAttachment !== void 0 && !this.keepDepth && this.passOpen()) this.restart(canvas);
15350
+ if (canvas?.depthStencilAttachment !== void 0 && !this.keepDepth && this.passOpen()) this.restart(canvas, RESTART.depth);
15239
15351
  }
15240
15352
  /**
15241
15353
  * A stencil mask is about to be pushed on the bound target: on the canvas, the stencil is kept from now on.
@@ -15254,7 +15366,7 @@ function createLazyCanvasClasses(pixi) {
15254
15366
  */
15255
15367
  maskPushed(target) {
15256
15368
  if (this.changeOwed && this.pending && this.canvas === target) this.beginPending();
15257
- else if (this.openCanvas === target && !this.keepStencil && this.passOpen()) this.restart(target);
15369
+ else if (this.openCanvas === target && !this.keepStencil && this.passOpen()) this.restart(target, RESTART.mask);
15258
15370
  }
15259
15371
  /**
15260
15372
  * The end of a render call: pays the clear the canvas owes, gives a canvas that saw no pass one, so the frame
@@ -15337,8 +15449,9 @@ function createLazyCanvasClasses(pixi) {
15337
15449
  * @param bits - The `CLEAR` bits.
15338
15450
  * @param color - The clear colour, when one was given.
15339
15451
  * @param viewport - The viewport.
15452
+ * @param restart - Why it begins, an index into `CANVAS_RESTARTS`.
15340
15453
  */
15341
- beginCanvas(target, bits, color, viewport) {
15454
+ beginCanvas(target, bits, color, viewport, restart) {
15342
15455
  const gpu = this.gpu;
15343
15456
  const targets = this.targets;
15344
15457
  if (gpu === void 0 || targets === void 0) return;
@@ -15347,7 +15460,7 @@ function createLazyCanvasClasses(pixi) {
15347
15460
  if (viewport !== this.view) this.view.copyFrom(viewport);
15348
15461
  super.startRenderPass(target, bits, color, viewport, 0, 0);
15349
15462
  this.openCanvas = target;
15350
- if (gpu.encoder.renderPassEncoder !== before) this.began(target, targets);
15463
+ if (gpu.encoder.renderPassEncoder !== before) this.began(target, targets, restart);
15351
15464
  }
15352
15465
  /**
15353
15466
  * Sets the stencil and depth operations of the rule on the canvas's depth-stencil attachment, made first when
@@ -15369,13 +15482,16 @@ function createLazyCanvasClasses(pixi) {
15369
15482
  attachment.depthStoreOp = this.planDepth ? "store" : "discard";
15370
15483
  }
15371
15484
  /**
15372
- * Records a canvas pass that really began (Pixi did not reuse the open one), and tells the stencil system of the
15373
- * canvas when the root bind owes it the change, now that there is a pass to set its reference on.
15485
+ * Records a canvas pass that really began (Pixi did not reuse the open one), tells the listener why, and tells the
15486
+ * stencil system of the canvas when the root bind owes it the change, now that there is a pass to set its reference
15487
+ * on.
15374
15488
  *
15375
15489
  * @param target - The canvas.
15376
15490
  * @param targets - The render target system.
15491
+ * @param restart - Why it began, an index into `CANVAS_RESTARTS`.
15377
15492
  */
15378
- began(target, targets) {
15493
+ began(target, targets, restart) {
15494
+ canvasBegan(restart);
15379
15495
  this.acquired = true;
15380
15496
  this.keepStencil = this.planStencil;
15381
15497
  this.keepDepth = this.planDepth;
@@ -15395,7 +15511,7 @@ function createLazyCanvasClasses(pixi) {
15395
15511
  const color = this.owedColorSet ? this.owedColor : void 0;
15396
15512
  this.owed = CLEAR_NONE;
15397
15513
  this.owedColorSet = false;
15398
- this.beginCanvas(target, bits, color, this.view);
15514
+ this.beginCanvas(target, bits, color, this.view, RESTART.empty);
15399
15515
  this.finishRenderPass();
15400
15516
  }
15401
15517
  /**
@@ -15413,13 +15529,14 @@ function createLazyCanvasClasses(pixi) {
15413
15529
  * reference again: a new pass starts from 0, and Pixi sets it only when the mode or the target changes.
15414
15530
  *
15415
15531
  * @param target - The canvas.
15532
+ * @param restart - Why it begins again: `RESTART.mask` or `RESTART.depth`.
15416
15533
  */
15417
- restart(target) {
15534
+ restart(target, restart) {
15418
15535
  const gpu = this.gpu;
15419
15536
  const targets = this.targets;
15420
15537
  if (gpu === void 0 || targets === void 0) return;
15421
15538
  this.finishRenderPass();
15422
- this.beginCanvas(target, CLEAR_NONE, void 0, this.view);
15539
+ this.beginCanvas(target, CLEAR_NONE, void 0, this.view, restart);
15423
15540
  gpu.encoder.setStencilReference(targets.getGpuRenderTarget(target).stencilReference);
15424
15541
  }
15425
15542
  }
@@ -15556,11 +15673,12 @@ function createLazyCanvasClasses(pixi) {
15556
15673
  * Pixi's own classes back, the stencil system again last.
15557
15674
  *
15558
15675
  * @param pixi - The loaded Pixi module.
15676
+ * @param canvasBegan - Told of every canvas pass that really began, with its reason.
15559
15677
  * @returns The remover.
15560
15678
  * @throws {TypeError} When the module has none of the classes to subclass.
15561
15679
  */
15562
- function installLazyCanvasPass(pixi) {
15563
- const lazy = createLazyCanvasClasses(pixi);
15680
+ function installLazyCanvasPass(pixi, canvasBegan = noListener) {
15681
+ const lazy = createLazyCanvasClasses(pixi, canvasBegan);
15564
15682
  pixi.extensions.remove(pixi.GpuRenderTargetSystem, pixi.GpuStencilSystem, pixi.PipelineSystem);
15565
15683
  pixi.extensions.add(lazy.targets, pixi.GpuStencilSystem, lazy.pipeline);
15566
15684
  return () => {
@@ -16297,7 +16415,8 @@ function createHostState() {
16297
16415
  kept: emptyWeakSet$3(),
16298
16416
  pixelsFailed: false,
16299
16417
  pool: createPoolState(),
16300
- onTrim: []
16418
+ onTrim: [],
16419
+ onCanvasPass: void 0
16301
16420
  };
16302
16421
  }
16303
16422
  //#endregion
@@ -16419,7 +16538,9 @@ function installRenderPass(ctx, pixi) {
16419
16538
  const state = ctx.state.host;
16420
16539
  if (state.uninstallRenderPass !== void 0) return;
16421
16540
  try {
16422
- state.uninstallRenderPass = installLazyCanvasPass(pixi);
16541
+ state.uninstallRenderPass = installLazyCanvasPass(pixi, (restart) => {
16542
+ state.onCanvasPass?.(restart);
16543
+ });
16423
16544
  } catch (error) {
16424
16545
  ctx.log.warn("renderer: the canvas pass begins at render start", { error });
16425
16546
  }
@@ -16541,6 +16662,7 @@ function stopHost(state) {
16541
16662
  state.onLoss.length = 0;
16542
16663
  state.onResolutionChange.length = 0;
16543
16664
  state.onTrim.length = 0;
16665
+ state.onCanvasPass = void 0;
16544
16666
  state.pool = createPoolState();
16545
16667
  state.resolution.pending = void 0;
16546
16668
  state.kind = "none";
@@ -17096,6 +17218,9 @@ function createHostApi(ctx, deps) {
17096
17218
  onTrim: (fn) => {
17097
17219
  state.onTrim.push(fn);
17098
17220
  },
17221
+ onCanvasPass: (fn) => {
17222
+ state.onCanvasPass = fn;
17223
+ },
17099
17224
  init: async () => {
17100
17225
  const mount = resolveMount(ctx);
17101
17226
  if (mount === void 0) return;
@@ -17412,7 +17537,7 @@ function matricesOf(kctx) {
17412
17537
  * @param top - The view's top.
17413
17538
  * @returns The label, `view` when it has none.
17414
17539
  */
17415
- function labelOf$3(top) {
17540
+ function labelOf$4(top) {
17416
17541
  const label = top.label;
17417
17542
  return label === null || label === "" ? "view" : label;
17418
17543
  }
@@ -17591,7 +17716,7 @@ function renderStage1(kctx, pixi, matrices, record) {
17591
17716
  width: key[KEY.w1] ?? 0,
17592
17717
  height: key[KEY.h1] ?? 0,
17593
17718
  resolution: rs
17594
- }, `kept:${labelOf$3(top)}#1`);
17719
+ }, `kept:${labelOf$4(top)}#1`);
17595
17720
  record.s1 = s1;
17596
17721
  matrices.m1.set(key[KEY.a] ?? 1, key[KEY.b] ?? 0, key[KEY.c] ?? 0, key[KEY.d] ?? 1, (key[KEY.tx] ?? 0) - (key[KEY.X0] ?? 0), (key[KEY.ty] ?? 0) - (key[KEY.Y0] ?? 0));
17597
17722
  const group = top.isRenderGroup;
@@ -17619,7 +17744,7 @@ function standInOf(pixi, record) {
17619
17744
  const s1 = record.s1 ?? pixi.Texture.EMPTY;
17620
17745
  if (record.standIn === void 0 || record.standIn.destroyed) {
17621
17746
  record.standIn = new pixi.Sprite(s1);
17622
- record.standIn.label = `kept:${labelOf$3(record.top)}#3`;
17747
+ record.standIn.label = `kept:${labelOf$4(record.top)}#3`;
17623
17748
  } else if (record.standIn.texture !== s1) record.standIn.texture = s1;
17624
17749
  return record.standIn;
17625
17750
  }
@@ -17642,7 +17767,7 @@ function outputOf(kctx, pixi, record, resolution, padding) {
17642
17767
  width: (key[KEY.w1] ?? 0) + 2 * Ps,
17643
17768
  height: (key[KEY.h1] ?? 0) + 2 * Ps,
17644
17769
  resolution
17645
- }, `kept:${labelOf$3(record.top)}#3`);
17770
+ }, `kept:${labelOf$4(record.top)}#3`);
17646
17771
  return record.s3;
17647
17772
  }
17648
17773
  /**
@@ -17669,7 +17794,7 @@ function keeperOf(pixi, record, resolution, padding) {
17669
17794
  const s1 = record.s1 ?? pixi.Texture.EMPTY;
17670
17795
  if (record.keeperStandIn === void 0 || record.keeperStandIn.destroyed) {
17671
17796
  record.keeperStandIn = new pixi.Sprite(s1);
17672
- record.keeperStandIn.label = `kept:${labelOf$3(record.top)}#2`;
17797
+ record.keeperStandIn.label = `kept:${labelOf$4(record.top)}#2`;
17673
17798
  record.keeperStandIn.filters = [record.keeper];
17674
17799
  } else if (record.keeperStandIn.texture !== s1) record.keeperStandIn.texture = s1;
17675
17800
  return record.keeperStandIn;
@@ -17709,7 +17834,7 @@ function sizeTargets(kctx, pixi, record, scales, padding) {
17709
17834
  width,
17710
17835
  height,
17711
17836
  resolution: rs * scale
17712
- }, `kept:${labelOf$3(record.top)}#2.${index}`);
17837
+ }, `kept:${labelOf$4(record.top)}#2.${index}`);
17713
17838
  for (const extra of record.s2.splice(scales.length)) dropTexture(kctx, extra);
17714
17839
  }
17715
17840
  /**
@@ -17882,6 +18007,7 @@ function makeRoom(kctx, extra, taking, goLive) {
17882
18007
  * @param goLive - Draws it live.
17883
18008
  */
17884
18009
  function evict$1(kctx, record, goLive) {
18010
+ kctx.state.frameEvicted += 1;
17885
18011
  if (record.mode === "kept") goLive(record);
17886
18012
  endLoan(record.s2Of);
17887
18013
  if (record.s1 !== void 0) dropTexture(kctx, record.s1);
@@ -18384,6 +18510,13 @@ function createKeptState(config) {
18384
18510
  takesWindow: 0,
18385
18511
  refreshesOpen: 0,
18386
18512
  frameTakes: 0,
18513
+ frameEvicted: 0,
18514
+ frameRefused: 0,
18515
+ evictedWindow: 0,
18516
+ refusedWindow: 0,
18517
+ windowStart: 0,
18518
+ windowEnd: -1,
18519
+ windowNext: 0,
18387
18520
  drawnPictures: 0,
18388
18521
  on: allowed && config.debug.kept !== false,
18389
18522
  allowed,
@@ -18480,6 +18613,13 @@ function stopKept(state) {
18480
18613
  state.takesWindow = 0;
18481
18614
  state.refreshesOpen = 0;
18482
18615
  state.frameTakes = 0;
18616
+ state.frameEvicted = 0;
18617
+ state.frameRefused = 0;
18618
+ state.evictedWindow = 0;
18619
+ state.refusedWindow = 0;
18620
+ state.windowStart = 0;
18621
+ state.windowEnd = -1;
18622
+ state.windowNext = 0;
18483
18623
  state.flushPasses = 0;
18484
18624
  state.drawnPictures = 0;
18485
18625
  state.firstTakes = 0;
@@ -18490,6 +18630,75 @@ function stopKept(state) {
18490
18630
  state.verifySkipped = 0;
18491
18631
  state.bypassed = false;
18492
18632
  }
18633
+ //#endregion
18634
+ //#region src/plugins/renderer/kept/types.ts
18635
+ /** The reasons a view is drawn live: a record stores `WHY_LIVE[why - 1]`'s index, 0 while kept. Appended only. */
18636
+ const WHY_LIVE = [
18637
+ "off",
18638
+ "backdrop",
18639
+ "filter-blend",
18640
+ "cache-false",
18641
+ "hidden",
18642
+ "faded-out",
18643
+ "top-blend",
18644
+ "ancestor-tint",
18645
+ "ancestor-blend",
18646
+ "ancestor-hidden",
18647
+ "placed-under-filter",
18648
+ "blend-below",
18649
+ "display",
18650
+ "waiting",
18651
+ "alpha-due",
18652
+ "churn",
18653
+ "budget",
18654
+ "idle"
18655
+ ];
18656
+ /** The reasons of a take: a record stores `RETAKE_WHY[retakeWhy - 1]`'s index, 0 before its first. Appended only. */
18657
+ const RETAKE_WHY = [
18658
+ "first",
18659
+ "mark",
18660
+ "inner-first",
18661
+ "resolution",
18662
+ "settle",
18663
+ "scale-limit",
18664
+ "canvas",
18665
+ "filter",
18666
+ "chain",
18667
+ "placed-move"
18668
+ ];
18669
+ /** The 1-based index of each reason of `WHY_LIVE` the step writes: a number on the record, no string per frame. */
18670
+ const WHY = {
18671
+ off: 1,
18672
+ backdrop: 2,
18673
+ filterBlend: 3,
18674
+ hidden: 5,
18675
+ fadedOut: 6,
18676
+ topBlend: 7,
18677
+ ancestorTint: 8,
18678
+ ancestorBlend: 9,
18679
+ ancestorHidden: 10,
18680
+ placedUnderFilter: 11,
18681
+ blendBelow: 12,
18682
+ display: 13,
18683
+ waiting: 14,
18684
+ alphaDue: 15,
18685
+ churn: 16,
18686
+ budget: 17,
18687
+ idle: 18
18688
+ };
18689
+ /** The 1-based index of each reason of `RETAKE_WHY`: a number on the record, no string per frame. */
18690
+ const RETAKE = {
18691
+ first: 1,
18692
+ mark: 2,
18693
+ innerFirst: 3,
18694
+ resolution: 4,
18695
+ settle: 5,
18696
+ scaleLimit: 6,
18697
+ canvas: 7,
18698
+ filter: 8,
18699
+ chain: 9,
18700
+ placedMove: 10
18701
+ };
18493
18702
  /** The reasons an ancestor may be hidden by and still draw the view: an overlay's range, a kept ancestor's picture. */
18494
18703
  const DRAWN_ANYWAY = ["freeze", "kept"];
18495
18704
  /** The tint of a container that tints nothing. */
@@ -18599,19 +18808,20 @@ function refusalHolds(state, record) {
18599
18808
  return record.refused > 0 && state.bytes - state.poolBytes + record.refused - record.bytes > state.budget;
18600
18809
  }
18601
18810
  /**
18602
- * Tells whether a first take waits for the next frame (F114): a stack drawn direct never does; a view drawn live while
18603
- * a crowd of them waits only when `CROWD_TAKES` were taken in this frame already (F119); any other waits when this
18604
- * frame took one already or an alpha is due.
18811
+ * Tells whether a first take waits for the next frame, and why (F114): a stack drawn direct never does; a view drawn
18812
+ * live while a crowd of them waits only when `CROWD_TAKES` were taken in this frame already (F119); any other waits when
18813
+ * an alpha is due or this frame took one already.
18605
18814
  *
18606
18815
  * @param state - The kept state.
18607
18816
  * @param direct - The stack draws direct.
18608
18817
  * @param live - The view is drawn live in this frame.
18609
- * @returns True when it waits.
18818
+ * @returns The `WHY` it waits for, 0 when it does not.
18610
18819
  */
18611
18820
  function heldBack(state, direct, live) {
18612
- if (direct) return false;
18613
- if (live && state.liveWaiting >= 4) return state.firstTakes >= 10;
18614
- return state.firstTakes > 0 || state.alphaDue;
18821
+ if (direct) return 0;
18822
+ if (live && state.liveWaiting >= 4) return state.firstTakes >= 10 ? WHY.waiting : 0;
18823
+ if (state.alphaDue) return WHY.alphaDue;
18824
+ return state.firstTakes > 0 ? WHY.waiting : 0;
18615
18825
  }
18616
18826
  /**
18617
18827
  * Tells whether a view is drawn live in the stage pass of this frame (F119): every ancestor up to the stage is
@@ -18650,15 +18860,16 @@ function holdsFilters(node) {
18650
18860
  * Tells whether the filters of a stack draw like a picture: none reads the backdrop, every one blends normally.
18651
18861
  *
18652
18862
  * @param slots - The record's slots.
18653
- * @returns True when they do.
18863
+ * @returns 0 when they do, else the `WHY` of the first that does not.
18654
18864
  */
18655
- function plainFilters(slots) {
18865
+ function filtersWhy(slots) {
18656
18866
  for (let index = 0; index < slots.length; index += 1) {
18657
18867
  const filter = slots[index]?.filter;
18658
- if (filter === void 0) continue;
18659
- if (filter.enabled && (filter.blendRequired || !plainBlend(filter.blendMode))) return false;
18868
+ if (filter === void 0 || !filter.enabled) continue;
18869
+ if (filter.blendRequired) return WHY.backdrop;
18870
+ if (!plainBlend(filter.blendMode)) return WHY.filterBlend;
18660
18871
  }
18661
- return true;
18872
+ return 0;
18662
18873
  }
18663
18874
  /**
18664
18875
  * The filters `sync` keeps for an entity, as `setFilters` stored them.
@@ -18684,18 +18895,6 @@ function topDrawn(sync, view) {
18684
18895
  return !(hiddenBy(view, "empty") && view.wrapper === void 0);
18685
18896
  }
18686
18897
  /**
18687
- * Tells whether an ancestor draws what is under it as a picture would: visible, untinted, blending normally. Its alpha
18688
- * is not read (F113): the quad hangs in the top's parent and Pixi multiplies it by the ancestors' alpha, while stage 1
18689
- * renders the top as a root without them. A fading ancestor so draws the picture at `A·F(x)`, live draws `F(A·x)`: the
18690
- * same for an alpha-linear filter, the whole picture faded for one that is not.
18691
- *
18692
- * @param node - The ancestor.
18693
- * @returns True when it does.
18694
- */
18695
- function drawsPlain(node) {
18696
- return node.visible && node.tint === WHITE$2 && plainBlend(node.blendMode);
18697
- }
18698
- /**
18699
18898
  * Tells whether an ancestor is drawn: renderable, or hidden only by an overlay's range or a kept ancestor's picture,
18700
18899
  * which draw it anyway.
18701
18900
  *
@@ -18719,37 +18918,61 @@ function filtersPlaced(kctx, record, node) {
18719
18918
  return record.category === "placed" && (holdsFilters(node) || kctx.state.byTop.get(node)?.mode === "kept");
18720
18919
  }
18721
18920
  /**
18722
- * Tells whether every ancestor up to the stage draws the view as a picture would: visible, untinted (its alpha is not
18723
- * read, F113), blending normally, drawn (an overlay's range and a kept ancestor's picture count), and for a placed filter without a filter
18724
- * above it (its canvas position would not be the canvas pixel live).
18921
+ * Tells whether an ancestor draws what is under it as a picture would: visible, untinted, blending normally, drawn (an
18922
+ * overlay's range and a kept ancestor's picture count), and for a placed filter holding no filter (its canvas position
18923
+ * would not be the canvas pixel live). Its alpha is not read (F113): the quad hangs in the top's parent and Pixi
18924
+ * multiplies it by the ancestors' alpha, while stage 1 renders the top as a root without them. A fading ancestor so
18925
+ * draws the picture at `A·F(x)`, live draws `F(A·x)`: the same for an alpha-linear filter, the whole picture faded for
18926
+ * one that is not.
18927
+ *
18928
+ * @param kctx - The kept context.
18929
+ * @param record - The record.
18930
+ * @param node - The ancestor.
18931
+ * @returns 0 when it does, else the `WHY` it does not.
18932
+ */
18933
+ function ancestorWhy(kctx, record, node) {
18934
+ if (!node.visible) return WHY.ancestorHidden;
18935
+ if (node.tint !== WHITE$2) return WHY.ancestorTint;
18936
+ if (!plainBlend(node.blendMode)) return WHY.ancestorBlend;
18937
+ if (!drawnAnyway(kctx, node)) return WHY.ancestorHidden;
18938
+ return filtersPlaced(kctx, record, node) ? WHY.placedUnderFilter : 0;
18939
+ }
18940
+ /**
18941
+ * Tells whether every ancestor up to the stage draws the view as a picture would (`ancestorWhy`).
18725
18942
  *
18726
18943
  * @param kctx - The kept context.
18727
18944
  * @param record - The record.
18728
18945
  * @param stage - The stage of the application.
18729
- * @returns True when they do.
18946
+ * @returns 0 when they do, else the `WHY` of the first that does not.
18730
18947
  */
18731
- function ancestorsPlain(kctx, record, stage) {
18948
+ function ancestorsWhy(kctx, record, stage) {
18732
18949
  for (let node = record.top.parent; node !== stage; node = node.parent) {
18733
- if (node === null) return false;
18734
- if (!drawsPlain(node) || !drawnAnyway(kctx, node) || filtersPlaced(kctx, record, node)) return false;
18950
+ if (node === null) return WHY.ancestorHidden;
18951
+ const why = ancestorWhy(kctx, record, node);
18952
+ if (why !== 0) return why;
18735
18953
  }
18736
- return true;
18954
+ return 0;
18737
18955
  }
18738
18956
  /**
18739
- * Whether a record may be kept this frame (P4.1): an enabled filter, filters that draw like a picture, a top and a
18740
- * visual that blend normally (the visual sits inside the wrapper of a kept bare view, D4), a top that is drawn,
18741
- * ancestors that draw it as a picture would, and the switch on.
18957
+ * Whether a record may be kept this frame (P4.1): the switch on, an enabled filter, filters that draw like a picture, a
18958
+ * top and a visual that blend normally (the visual sits inside the wrapper of a kept bare view, D4), a top that is
18959
+ * drawn, ancestors that draw it as a picture would.
18742
18960
  *
18743
18961
  * @param kctx - The kept context.
18744
18962
  * @param record - The record.
18745
18963
  * @param view - Its view.
18746
18964
  * @param stack - The stack of this frame.
18747
- * @returns True when it may be kept.
18965
+ * @returns 0 when it may be kept, else the `WHY` of the first check that failed.
18748
18966
  */
18749
18967
  function eligible(kctx, record, view, stack) {
18750
- const { top } = record;
18751
18968
  const stage = kctx.host.stage();
18752
- return keepingOn(kctx) && stage !== void 0 && stack.enabled > 0 && plainFilters(record.slots) && drawsAsPicture(top, view) && topDrawn(kctx.sync, view) && ancestorsPlain(kctx, record, stage);
18969
+ if (!keepingOn(kctx) || stage === void 0 || stack.enabled === 0) return WHY.off;
18970
+ const filters = filtersWhy(record.slots);
18971
+ if (filters !== 0) return filters;
18972
+ const picture = pictureWhy(record.top, view);
18973
+ if (picture !== 0) return picture;
18974
+ if (!topDrawn(kctx.sync, view)) return WHY.hidden;
18975
+ return ancestorsWhy(kctx, record, stage);
18753
18976
  }
18754
18977
  /**
18755
18978
  * Tells whether the kept cache may keep anything this frame: switched on and not bypassed.
@@ -18766,10 +18989,11 @@ function keepingOn(kctx) {
18766
18989
  *
18767
18990
  * @param top - The record's top.
18768
18991
  * @param view - Its view.
18769
- * @returns True when they do.
18992
+ * @returns 0 when they do, else the `WHY` they do not.
18770
18993
  */
18771
- function drawsAsPicture(top, view) {
18772
- return top.visible && top.alpha > 0 && plainBlend(top.blendMode) && plainBlend(view.object.blendMode);
18994
+ function pictureWhy(top, view) {
18995
+ if (top.visible && top.alpha > 0) return plainBlend(top.blendMode) && plainBlend(view.object.blendMode) ? 0 : WHY.topBlend;
18996
+ return WHY.fadedOut;
18773
18997
  }
18774
18998
  /**
18775
18999
  * Tells whether a node under a top blends otherwise than normally, at any depth (F68): drawn into a picture, it would
@@ -18801,7 +19025,7 @@ function blendedBelow(kctx, record) {
18801
19025
  if (!blendsBelow(record.top)) return false;
18802
19026
  record.blended = true;
18803
19027
  const { warnedBlend } = kctx.state;
18804
- const label = labelOf$3(record.top);
19028
+ const label = labelOf$4(record.top);
18805
19029
  if (!warnedBlend.has(label)) {
18806
19030
  warnedBlend.add(label);
18807
19031
  kctx.ctx.log.warn("renderer:kept-blend", { picture: label });
@@ -18880,7 +19104,14 @@ function createRecord$1(kctx, pixi, entity, view, slots, category) {
18880
19104
  spared: false,
18881
19105
  idle: false,
18882
19106
  alphaDue: false,
18883
- alphaMissed: false
19107
+ alphaMissed: false,
19108
+ idleSeen: false,
19109
+ why: WHY.waiting,
19110
+ calmIn: 2,
19111
+ markBy: 0,
19112
+ retakeWhy: 0,
19113
+ retakeBy: 0,
19114
+ retakeAt: 0
18884
19115
  };
18885
19116
  const { state } = kctx;
18886
19117
  state.records.push(record);
@@ -19065,6 +19296,7 @@ function writeTakeKeys(record, now, box) {
19065
19296
  */
19066
19297
  function refuseIdle(record) {
19067
19298
  record.idle = true;
19299
+ record.idleSeen = true;
19068
19300
  return false;
19069
19301
  }
19070
19302
  /**
@@ -19085,7 +19317,8 @@ function refuseIdle(record) {
19085
19317
  */
19086
19318
  function takePicture(kctx, pixi, matrices, record, view, now, turned = false) {
19087
19319
  const { top } = record;
19088
- if (!kctx.ctx.config.onDemand && holdsDisplay(kctx, top)) return refuseIdle(record);
19320
+ record.displays = !kctx.ctx.config.onDemand && holdsDisplay(kctx, top);
19321
+ if (record.displays) return refuseIdle(record);
19089
19322
  if (blendedBelow(kctx, record)) return false;
19090
19323
  const drawn = drawnBounds(pixi, top);
19091
19324
  if (!drawn.isValid) return refuseIdle(record);
@@ -19116,7 +19349,8 @@ function takePicture(kctx, pixi, matrices, record, view, now, turned = false) {
19116
19349
  });
19117
19350
  if (!makeRoom(kctx, needed - record.bytes, record, (kept) => goLive(kctx, kept, kctx.ctx.state.sync.views.get(kept.entity), true))) {
19118
19351
  record.refused = needed;
19119
- warnRefused(kctx, labelOf$3(top));
19352
+ kctx.state.frameRefused += 1;
19353
+ warnRefused(kctx, labelOf$4(top));
19120
19354
  return false;
19121
19355
  }
19122
19356
  record.refused = 0;
@@ -19333,7 +19567,7 @@ function placeQuad(sync, pixi, matrices, record, view) {
19333
19567
  const alpha = (record.direct ? NOW.alpha : 1) * top.alpha;
19334
19568
  if (record.quad === void 0 || record.quad.destroyed) {
19335
19569
  record.quad = new pixi.Sprite(output);
19336
- record.quad.label = `kept:${labelOf$3(top)}`;
19570
+ record.quad.label = `kept:${labelOf$4(top)}`;
19337
19571
  }
19338
19572
  const quad = record.quad;
19339
19573
  if (quad.texture !== output) quad.texture = output;
@@ -19375,6 +19609,9 @@ function toKept(kctx, record, view) {
19375
19609
  record.mode = "kept";
19376
19610
  record.calm = false;
19377
19611
  record.churn = 0;
19612
+ record.why = 0;
19613
+ record.calmIn = 0;
19614
+ record.idleSeen = false;
19378
19615
  kctx.sync.swapHidden(kctx.hidden, view, "kept", true);
19379
19616
  }
19380
19617
  /**
@@ -19451,6 +19688,40 @@ function waitOf(record) {
19451
19688
  return drawsDirect(NOW) ? 0 : 2;
19452
19689
  }
19453
19690
  /**
19691
+ * Notes why a live record that may be kept is not taken in this frame, from what the policy keeps on it: a `Display`
19692
+ * found under its top, a take that rendered nothing or a cut under a move, a refused take, a glow under the top, else
19693
+ * the still frames it waits for. A move offers a take again but changes neither of the first two: they stand until a
19694
+ * change under the top, so a moving view does not flip to a wait.
19695
+ *
19696
+ * @param state - The kept state.
19697
+ * @param record - The record, live.
19698
+ * @param changed - It changed in this frame.
19699
+ * @param turned - Its linear part moved in this frame.
19700
+ */
19701
+ function noteHeld(state, record, changed, turned) {
19702
+ record.calmIn = 0;
19703
+ if (record.displays === true) record.why = WHY.display;
19704
+ else if (record.idleSeen || turned && record.cut) record.why = WHY.idle;
19705
+ else if (refusalHolds(state, record)) record.why = WHY.budget;
19706
+ else if (record.blended) record.why = WHY.blendBelow;
19707
+ else {
19708
+ record.why = record.calm ? WHY.churn : WHY.waiting;
19709
+ record.calmIn = Math.max(waitOf(record) - record.still, changed ? 1 : 0);
19710
+ }
19711
+ }
19712
+ /**
19713
+ * Notes what a take was for, in numbers: `why()` names them when it is asked. A mark's reasons keep who marked.
19714
+ *
19715
+ * @param kctx - The kept context.
19716
+ * @param record - The record.
19717
+ * @param why - The `RETAKE` of the take.
19718
+ */
19719
+ function noteTake(kctx, record, why) {
19720
+ record.retakeWhy = why;
19721
+ record.retakeBy = why === RETAKE.mark || why === RETAKE.innerFirst ? record.markBy : 0;
19722
+ record.retakeAt = kctx.state.frame;
19723
+ }
19724
+ /**
19454
19725
  * Marks every kept record above a record that was just first taken: their retake in this flush is not churn (F114),
19455
19726
  * so the inner takes spread over frames do not drop the outer picture to live.
19456
19727
  *
@@ -19484,18 +19755,26 @@ function stepLive(kctx, pixi, matrices, record, view) {
19484
19755
  writeSeen(record, NOW);
19485
19756
  record.still = changed ? 0 : record.still + 1;
19486
19757
  if (moved) record.idle = false;
19487
- if (changed || record.still < waitOf(record) || record.idle) return;
19488
- if (refusalHolds(state, record)) return;
19489
- if (blendedBelow(kctx, record)) return;
19490
- if (heldBack(state, drawsDirect(NOW), drawnLive(kctx, record))) return;
19758
+ if (changed || record.still < waitOf(record) || record.idle || refusalHolds(state, record) || blendedBelow(kctx, record)) {
19759
+ noteHeld(state, record, changed, turned);
19760
+ return;
19761
+ }
19762
+ const held = heldBack(state, drawsDirect(NOW), drawnLive(kctx, record));
19763
+ if (held !== 0) {
19764
+ record.why = held;
19765
+ record.calmIn = 0;
19766
+ return;
19767
+ }
19491
19768
  wrapBare(kctx, record, view);
19492
19769
  if (!takePicture(kctx, pixi, matrices, record, view, NOW, turned)) {
19493
19770
  record.still = 0;
19771
+ noteHeld(state, record, false, turned);
19494
19772
  return;
19495
19773
  }
19496
19774
  state.firstTakes += 1;
19497
19775
  record.takenAt = state.frame;
19498
19776
  toKept(kctx, record, view);
19777
+ noteTake(kctx, record, RETAKE.first);
19499
19778
  spareAbove(kctx, record);
19500
19779
  }
19501
19780
  /**
@@ -19506,9 +19785,15 @@ function stepLive(kctx, pixi, matrices, record, view) {
19506
19785
  * @param matrices - The scratch matrices.
19507
19786
  * @param record - The record, kept.
19508
19787
  * @param view - Its view.
19788
+ * @param why - The `RETAKE` of the take.
19509
19789
  */
19510
- function retakeOrGoLive(kctx, pixi, matrices, record, view) {
19511
- if (!takePicture(kctx, pixi, matrices, record, view, NOW)) goLive(kctx, record, view, true);
19790
+ function retakeOrGoLive(kctx, pixi, matrices, record, view, why) {
19791
+ if (takePicture(kctx, pixi, matrices, record, view, NOW)) {
19792
+ noteTake(kctx, record, why);
19793
+ return;
19794
+ }
19795
+ goLive(kctx, record, view, true);
19796
+ noteHeld(kctx.state, record, false, false);
19512
19797
  }
19513
19798
  /**
19514
19799
  * A stage-1 change of a kept record (P4.3): retaken, or after three in a row drawn live and calm, so it stands still
@@ -19519,16 +19804,41 @@ function retakeOrGoLive(kctx, pixi, matrices, record, view) {
19519
19804
  * @param matrices - The scratch matrices.
19520
19805
  * @param record - The record, kept.
19521
19806
  * @param view - Its view.
19807
+ * @param why - The `RETAKE` of a retake.
19522
19808
  */
19523
- function churn(kctx, pixi, matrices, record, view) {
19809
+ function churn(kctx, pixi, matrices, record, view, why) {
19524
19810
  record.churn += 1;
19525
19811
  if (record.churn < 3) {
19526
- retakeOrGoLive(kctx, pixi, matrices, record, view);
19812
+ retakeOrGoLive(kctx, pixi, matrices, record, view, why);
19527
19813
  return;
19528
19814
  }
19529
19815
  goLive(kctx, record, view, true);
19530
19816
  record.calm = true;
19531
19817
  writeSeen(record, NOW);
19818
+ noteHeld(kctx.state, record, false, false);
19819
+ }
19820
+ /**
19821
+ * What a retake of a kept record owes itself to: a new stack resolution, a change under its top, or a linear part it may
19822
+ * not be drawn at.
19823
+ *
19824
+ * @param record - The record, kept, about to be retaken.
19825
+ * @returns The `RETAKE`.
19826
+ */
19827
+ function retakeWhy(record) {
19828
+ if (record.key[KEY.rs] !== NOW.rs) return RETAKE.resolution;
19829
+ if (record.dirtyS1) return RETAKE.mark;
19830
+ return record.cut || record.category === "placed" ? RETAKE.placedMove : RETAKE.scaleLimit;
19831
+ }
19832
+ /**
19833
+ * What a refresh of a kept record owes itself to, read before the render writes its keys.
19834
+ *
19835
+ * @param record - The record, kept.
19836
+ * @param chain - Stage 2 is redone too.
19837
+ * @returns The `RETAKE`.
19838
+ */
19839
+ function refreshWhy(record, chain) {
19840
+ if (chain) return RETAKE.chain;
19841
+ return NOW.r === record.key[KEY.r] ? RETAKE.filter : RETAKE.resolution;
19532
19842
  }
19533
19843
  /**
19534
19844
  * Notes a move of a kept record: a quad that left its picture's texel grid owes one settle retake at rest, and asks
@@ -19571,21 +19881,21 @@ function stepKept$1(kctx, pixi, matrices, record, view) {
19571
19881
  writeSeen(record, NOW);
19572
19882
  const retake = record.dirtyS1 || scaled && !scalable(record);
19573
19883
  if (retake && record.spared && !scaled) {
19574
- retakeOrGoLive(kctx, pixi, matrices, record, view);
19884
+ retakeOrGoLive(kctx, pixi, matrices, record, view, RETAKE.innerFirst);
19575
19885
  return;
19576
19886
  }
19577
19887
  if (retake) {
19578
- churn(kctx, pixi, matrices, record, view);
19888
+ churn(kctx, pixi, matrices, record, view, retakeWhy(record));
19579
19889
  return;
19580
19890
  }
19581
19891
  const moved = turned || NOW.tx !== key[KEY.lastTx] || NOW.ty !== key[KEY.lastTy];
19582
19892
  if (record.cut && (moved || canvasChanged(kctx, key))) {
19583
- churn(kctx, pixi, matrices, record, view);
19893
+ churn(kctx, pixi, matrices, record, view, RETAKE.canvas);
19584
19894
  return;
19585
19895
  }
19586
19896
  record.churn = 0;
19587
19897
  if (!moved && record.settle) {
19588
- retakeOrGoLive(kctx, pixi, matrices, record, view);
19898
+ retakeOrGoLive(kctx, pixi, matrices, record, view, RETAKE.settle);
19589
19899
  return;
19590
19900
  }
19591
19901
  refresh$1(kctx, pixi, matrices, record);
@@ -19622,6 +19932,7 @@ function refresh$1(kctx, pixi, matrices, record) {
19622
19932
  padding: NOW.P
19623
19933
  });
19624
19934
  if (!stageThreeOwed) return;
19935
+ noteTake(kctx, record, refreshWhy(record, stageTwoOwed));
19625
19936
  record.direct = false;
19626
19937
  renderStage3(kctx, pixi, matrices, record, NOW);
19627
19938
  account(kctx, record);
@@ -19699,7 +20010,7 @@ function markAlphaDue(kctx, pixi) {
19699
20010
  if (record === void 0 || view === void 0 || !mayBeDue(kctx, record)) continue;
19700
20011
  readStack(record.slots, resolution, pixi.AlphaFilter, DUE);
19701
20012
  const direct = drawsDirectAt(DUE, resolution);
19702
- record.alphaDue = direct && eligible(kctx, record, view, DUE);
20013
+ record.alphaDue = direct && eligible(kctx, record, view, DUE) === 0;
19703
20014
  state.alphaDue ||= record.alphaDue;
19704
20015
  if (!direct && drawnLive(kctx, record)) state.liveWaiting += 1;
19705
20016
  }
@@ -19732,16 +20043,20 @@ function stepRecord(kctx, pixi, matrices, record, view) {
19732
20043
  record.blended = false;
19733
20044
  record.idle = false;
19734
20045
  record.alphaMissed = false;
20046
+ record.displays = void 0;
20047
+ record.idleSeen = false;
19735
20048
  }
19736
20049
  NOW.r = kctx.host.resolution();
19737
20050
  readStack(record.slots, NOW.r, pixi.AlphaFilter, NOW);
19738
- if (eligible(kctx, record, view, NOW)) stepEligible(kctx, pixi, matrices, record, view);
19739
- else stepIneligible(kctx, record, view);
20051
+ const why = eligible(kctx, record, view, NOW);
20052
+ if (why === 0) stepEligible(kctx, pixi, matrices, record, view);
20053
+ else stepIneligible(kctx, record, view, why);
19740
20054
  if (drawingChanged(kctx, record, BEFORE)) dirtyAbove(kctx, record);
19741
20055
  record.quiet = record.dirtyS1 ? 0 : record.quiet + 1;
19742
20056
  record.dirtyS1 = false;
19743
20057
  record.dirtyS2 = false;
19744
20058
  record.dirtyS3 = false;
20059
+ record.markBy = 0;
19745
20060
  record.spared = false;
19746
20061
  if (record.alphaDue && record.mode !== "kept") record.alphaMissed = true;
19747
20062
  record.alphaDue = false;
@@ -19776,13 +20091,16 @@ function stepEligible(kctx, pixi, matrices, record, view) {
19776
20091
  * @param kctx - The kept context.
19777
20092
  * @param record - The record.
19778
20093
  * @param view - Its view.
20094
+ * @param why - The `WHY` of the check that failed.
19779
20095
  */
19780
- function stepIneligible(kctx, record, view) {
20096
+ function stepIneligible(kctx, record, view, why) {
19781
20097
  if (record.mode === "kept") {
19782
20098
  goLive(kctx, record, view, true);
19783
20099
  if (kctx.state.frame - record.takenAt <= 1) record.calm = true;
19784
20100
  }
19785
20101
  record.still = 0;
20102
+ record.why = why;
20103
+ record.calmIn = 0;
19786
20104
  }
19787
20105
  /**
19788
20106
  * Tells whether a range picture draws a node: the node, or a node above it, is one of the range's entries.
@@ -19805,7 +20123,10 @@ function rangeHolds$1(entries, node) {
19805
20123
  function dirtyAbove(kctx, record) {
19806
20124
  for (let node = record.top.parent; node !== null; node = node.parent) {
19807
20125
  const above = kctx.state.byTop.get(node);
19808
- if (above !== void 0) above.dirtyS1 = true;
20126
+ if (above !== void 0) {
20127
+ above.dirtyS1 = true;
20128
+ above.markBy = record.entity;
20129
+ }
19809
20130
  }
19810
20131
  for (const range of kctx.state.ranges.values()) if (rangeHolds$1(range.entries, record.top)) range.due = true;
19811
20132
  }
@@ -19992,7 +20313,126 @@ function verifyPictures(kctx, bypass, recover) {
19992
20313
  kctx.demand.request();
19993
20314
  }
19994
20315
  //#endregion
20316
+ //#region src/plugins/renderer/kept/why.ts
20317
+ /**
20318
+ * Adds the entities of a subtree to a set, depth first: the order Pixi draws them in.
20319
+ *
20320
+ * @param node - The top of the subtree.
20321
+ * @param entityOf - The entity of each object of a view.
20322
+ * @param order - Where they go, each once.
20323
+ */
20324
+ function collectDrawOrder(node, entityOf, order) {
20325
+ const entity = entityOf.get(node);
20326
+ if (entity !== void 0) order.add(entity);
20327
+ for (const child of node.children) collectDrawOrder(child, entityOf, order);
20328
+ }
20329
+ /**
20330
+ * The label of an entity's view now.
20331
+ *
20332
+ * @param sync - The sync state.
20333
+ * @param entity - The entity.
20334
+ * @returns The label of its display object, `null` without a view.
20335
+ */
20336
+ function labelOf$3(sync, entity) {
20337
+ return sync.views.get(entity)?.object.label ?? null;
20338
+ }
20339
+ /**
20340
+ * The last take of a record, while it fell in the last closed window.
20341
+ *
20342
+ * @param kctx - The kept context.
20343
+ * @param record - The record.
20344
+ * @returns The take, or `null`.
20345
+ */
20346
+ function lastTake(kctx, record) {
20347
+ const { state } = kctx;
20348
+ const why = RETAKE_WHY[record.retakeWhy - 1];
20349
+ if (why === void 0 || record.retakeAt < state.windowStart) return null;
20350
+ if (record.retakeAt > state.windowEnd) return null;
20351
+ return {
20352
+ why,
20353
+ by: labelOf$3(kctx.ctx.state.sync, record.retakeBy)
20354
+ };
20355
+ }
20356
+ /**
20357
+ * The entry of a view with a record. A live record no step told a reason yet, as an evicted one, waits for its next.
20358
+ *
20359
+ * @param kctx - The kept context.
20360
+ * @param record - The record.
20361
+ * @param view - The label of its view.
20362
+ * @returns The entry.
20363
+ */
20364
+ function recordEntry(kctx, record, view) {
20365
+ const retake = lastTake(kctx, record);
20366
+ if (record.mode === "kept") return {
20367
+ view,
20368
+ mode: record.direct ? "direct" : "kept",
20369
+ reason: null,
20370
+ calmIn: 0,
20371
+ retake
20372
+ };
20373
+ const why = record.why === 0 ? WHY.waiting : record.why;
20374
+ return {
20375
+ view,
20376
+ mode: "live",
20377
+ reason: WHY_LIVE[why - 1] ?? null,
20378
+ calmIn: record.calmIn,
20379
+ retake
20380
+ };
20381
+ }
20382
+ /**
20383
+ * The entry of a view the cache keeps no record of: a slot it may not keep, a filter that reads the backdrop.
20384
+ *
20385
+ * @param slots - The view's slots.
20386
+ * @param view - The label of its view.
20387
+ * @returns The entry.
20388
+ */
20389
+ function slotsEntry(slots, view) {
20390
+ return {
20391
+ view,
20392
+ mode: "live",
20393
+ reason: slots.some((slot) => slot.filter.enabled && slot.filter.blendRequired) ? "backdrop" : "cache-false",
20394
+ calmIn: 0,
20395
+ retake: null
20396
+ };
20397
+ }
20398
+ /**
20399
+ * The entry of an entity, when it has a view and an enabled filter.
20400
+ *
20401
+ * @param kctx - The kept context.
20402
+ * @param entity - The entity.
20403
+ * @param view - Its view.
20404
+ * @returns The entry, or `undefined`.
20405
+ */
20406
+ function entryOf$1(kctx, entity, view) {
20407
+ const slots = kctx.ctx.state.sync.filters.get(entity);
20408
+ if (view === void 0 || slots === void 0) return void 0;
20409
+ if (!slots.some((slot) => slot.filter.enabled)) return void 0;
20410
+ const record = kctx.state.byEntity.get(entity);
20411
+ return record === void 0 ? slotsEntry(slots, view.object.label) : recordEntry(kctx, record, view.object.label);
20412
+ }
20413
+ /**
20414
+ * Why every filtered view is drawn as it is, in draw order; a view outside the stage comes after those in it.
20415
+ *
20416
+ * @param kctx - The kept context.
20417
+ * @returns A fresh array, one entry per view with an enabled filter.
20418
+ */
20419
+ function whyReport(kctx) {
20420
+ const sync = kctx.ctx.state.sync;
20421
+ const stage = kctx.host.stage();
20422
+ const order = /* @__PURE__ */ new Set();
20423
+ const entries = [];
20424
+ if (stage !== void 0) collectDrawOrder(stage, sync.entityOf, order);
20425
+ for (const entity of sync.filters.keys()) order.add(entity);
20426
+ for (const entity of order) {
20427
+ const entry = entryOf$1(kctx, entity, sync.views.get(entity));
20428
+ if (entry !== void 0) entries.push(entry);
20429
+ }
20430
+ return entries;
20431
+ }
20432
+ //#endregion
19995
20433
  //#region src/plugins/renderer/kept/api.ts
20434
+ /** What `why()` answers in every build but an agent build. */
20435
+ const NO_WHY = Object.freeze([]);
19996
20436
  /**
19997
20437
  * The category a slot list lets the cache keep it under: the worst of its slots, `undefined` for an empty list, a
19998
20438
  * `"screen"` slot or a slot that names none (a game's own slot is drawn live).
@@ -20037,6 +20477,16 @@ function renew(kctx, pixi, record) {
20037
20477
  return true;
20038
20478
  }
20039
20479
  /**
20480
+ * Notes a change of a record's subtree, and who marked it.
20481
+ *
20482
+ * @param record - The record.
20483
+ * @param entity - The marked entity.
20484
+ */
20485
+ function changed(record, entity) {
20486
+ record.dirtyS1 = true;
20487
+ record.markBy = entity;
20488
+ }
20489
+ /**
20040
20490
  * Steps every record of a drawn frame, in the list's order (inner first): a record whose top changed is renewed, and
20041
20491
  * its new record steps later in the same loop.
20042
20492
  *
@@ -20144,15 +20594,15 @@ function createKeptApi(ctx, deps) {
20144
20594
  const own = state.byTop.get(top);
20145
20595
  if (own !== void 0) {
20146
20596
  const demand = deps.demand;
20147
- if (demand.visual().has(entity) || demand.loose().has(entity)) own.dirtyS1 = true;
20597
+ if (demand.visual().has(entity) || demand.loose().has(entity)) changed(own, entity);
20148
20598
  if (demand.published().has(entity)) {
20149
20599
  own.dirtyS3 = true;
20150
- if (view.kind === "Display" || view.kind === "adapter") own.dirtyS1 = true;
20600
+ if (view.kind === "Display" || view.kind === "adapter") changed(own, entity);
20151
20601
  }
20152
20602
  }
20153
20603
  for (let node = top.parent; node !== null; node = node.parent) {
20154
20604
  const above = state.byTop.get(node);
20155
- if (above !== void 0) above.dirtyS1 = true;
20605
+ if (above !== void 0) changed(above, entity);
20156
20606
  }
20157
20607
  };
20158
20608
  return {
@@ -20207,7 +20657,11 @@ function createKeptApi(ctx, deps) {
20207
20657
  markAlphaDue(kctx, pixi);
20208
20658
  stepRecords(kctx, pixi, matrices);
20209
20659
  state.calm = false;
20210
- } else for (const record of state.records) if (record.mode === "kept") live(record);
20660
+ } else for (const record of state.records) {
20661
+ if (record.mode === "kept") live(record);
20662
+ record.why = WHY.off;
20663
+ record.calmIn = 0;
20664
+ }
20211
20665
  flushRanges(kctx);
20212
20666
  },
20213
20667
  after: () => {
@@ -20229,12 +20683,25 @@ function createKeptApi(ctx, deps) {
20229
20683
  stats: () => ({
20230
20684
  pictures: state.drawnPictures,
20231
20685
  mb: roundTo(state.bytes / BYTES_PER_MB$1, 2),
20232
- retakes: state.takesWindow
20686
+ retakes: state.takesWindow,
20687
+ evicted: state.evictedWindow,
20688
+ refused: state.refusedWindow
20233
20689
  }),
20690
+ why: () => {
20691
+ if (typeof __MOKU_GAME_AGENT__ !== "undefined" && __MOKU_GAME_AGENT__) return whyReport(kctx);
20692
+ return NO_WHY;
20693
+ },
20234
20694
  drainTakes: () => {
20235
20695
  const takes = state.takesOpen;
20236
20696
  state.takesWindow = takes;
20237
20697
  state.takesOpen = 0;
20698
+ state.evictedWindow = state.frameEvicted;
20699
+ state.frameEvicted = 0;
20700
+ state.refusedWindow = state.frameRefused;
20701
+ state.frameRefused = 0;
20702
+ state.windowStart = state.windowNext;
20703
+ state.windowEnd = state.frame;
20704
+ state.windowNext = state.frame + 1;
20238
20705
  return takes;
20239
20706
  },
20240
20707
  drainRefreshes: () => {
@@ -20425,42 +20892,6 @@ function stopDemand(state) {
20425
20892
  state.verify.reference = void 0;
20426
20893
  }
20427
20894
  //#endregion
20428
- //#region src/plugins/renderer/reasons.ts
20429
- /**
20430
- * @file renderer plugin — the reasons a frame is drawn, in ring order: the monitor stores a reason by its index. A
20431
- * plain module of the plugin root, so the monitor reads the order without importing the demand module's run-time code
20432
- * (L1); `DemandReason` in `demand/types.ts` is derived from it.
20433
- */
20434
- /**
20435
- * Every reason in ring order: the monitor stores the index (spec 11 `FrameColumns.reason`), 255 for a frame without a
20436
- * decision. New reasons are only ever appended (block 3B: `"overlay"`, `"retake"` after `"none"`), so stored indices
20437
- * keep their meaning. There is no whole-frame reason for `renderer.invalidate`: it always names an entity
20438
- * (LEAD-FIXES-4). A root export, so a reader of the ring names a reason without building a record.
20439
- *
20440
- * @example
20441
- * ```ts
20442
- * // An overlay names why the newest frame of a debug build was drawn: a piece moved, a counted change mark.
20443
- * const ring = app.renderer.monitor.frames();
20444
- * DEMAND_REASONS[ring.columns.reason[ring.newest] ?? 255]; // "mark"
20445
- * ```
20446
- */
20447
- const DEMAND_REASONS = [
20448
- "always",
20449
- "first",
20450
- "resize",
20451
- "restore",
20452
- "layers",
20453
- "debug",
20454
- "wake",
20455
- "capture",
20456
- "request",
20457
- "mark",
20458
- "verify",
20459
- "none",
20460
- "overlay",
20461
- "retake"
20462
- ];
20463
- //#endregion
20464
20895
  //#region src/plugins/renderer/monitor/log-types.ts
20465
20896
  /**
20466
20897
  * The version every line carries as `v`.
@@ -20638,7 +21069,8 @@ const COUNT = {
20638
21069
  marks: 7,
20639
21070
  rebuilds: 8,
20640
21071
  targetsCreated: 9,
20641
- targetsDestroyed: 10
21072
+ targetsDestroyed: 10,
21073
+ canvas: 11
20642
21074
  };
20643
21075
  /**
20644
21076
  * What this application measures, as bits of `PerfState.measuring`. Not public.
@@ -21395,7 +21827,8 @@ function createPasses(capacity) {
21395
21827
  kind2: new Uint8Array(capacity),
21396
21828
  drawsAt: new Uint16Array(capacity),
21397
21829
  format: Array.from({ length: capacity }).fill(null),
21398
- resolution: new Float32Array(capacity).fill(NaN)
21830
+ resolution: new Float32Array(capacity).fill(NaN),
21831
+ restart: new Uint8Array(capacity)
21399
21832
  };
21400
21833
  }
21401
21834
  /**
@@ -21606,6 +22039,7 @@ function writePass(passes, frame, index, kind, stencil, width, height, label) {
21606
22039
  passes.drawsAt[slot] = 0;
21607
22040
  passes.format[slot] = null;
21608
22041
  passes.resolution[slot] = NaN;
22042
+ passes.restart[slot] = 0;
21609
22043
  passes.newest = slot;
21610
22044
  passes.size = Math.min(passes.size + 1, passes.capacity);
21611
22045
  passes.written = sequence + 1;
@@ -21825,7 +22259,7 @@ function splitDraws(found, total) {
21825
22259
  /**
21826
22260
  * The render passes of a frame still in the pass ring, in their order, with their detail: the entity whose filter drew
21827
22261
  * each and its view's label, the filter kind, the draws, the target's format and resolution, whether it was a kept
21828
- * picture's.
22262
+ * picture's, and for a canvas pass why it began.
21829
22263
  *
21830
22264
  * @param ring - The ring.
21831
22265
  * @param frame - The frame number.
@@ -21845,6 +22279,7 @@ function passesOf$1(ring, frame, total = NaN, viewOf = () => null) {
21845
22279
  const label = passes.label[slot] ?? null;
21846
22280
  const owner = cellU32(passes.owner, slot);
21847
22281
  const kind2 = cellU8(passes.kind2, slot);
22282
+ const restart = CANVAS_RESTARTS[cellU8(passes.restart, slot)] ?? "none";
21848
22283
  found.unshift({
21849
22284
  index: cellU8(passes.index, slot),
21850
22285
  kind: PASS_KINDS[cellU8(passes.kind, slot)] ?? "texture",
@@ -21859,7 +22294,8 @@ function passesOf$1(ring, frame, total = NaN, viewOf = () => null) {
21859
22294
  draws: cellU16(passes.drawsAt, slot),
21860
22295
  format: passes.format[slot] ?? null,
21861
22296
  resolution: measured(cellF32(passes.resolution, slot)),
21862
- kept: label?.startsWith(KEPT_PREFIX) === true
22297
+ kept: label?.startsWith(KEPT_PREFIX) === true,
22298
+ ...restart === "none" ? {} : { restart }
21863
22299
  });
21864
22300
  }
21865
22301
  splitDraws(found, total);
@@ -22487,6 +22923,11 @@ function createMonitorState(config) {
22487
22923
  open: 0,
22488
22924
  max: 0
22489
22925
  },
22926
+ canvas: {
22927
+ last: 0,
22928
+ open: 0,
22929
+ max: 0
22930
+ },
22490
22931
  passDetach: []
22491
22932
  };
22492
22933
  }
@@ -24384,6 +24825,20 @@ function writeDetail(pc, target, kind) {
24384
24825
  writePassDetail(pc.perf.ring.passes, filter ? sinks.filterOwner : 0, filter ? sinks.filterKind + 1 : 0, sinks.draws.frame, target.colorTexture?.source);
24385
24826
  }
24386
24827
  /**
24828
+ * Writes why the canvas pass just begun began into its slot of the pass ring: the counting encoder wrote the slot when
24829
+ * the pass began, before the lazy canvas pass told the monitor. Only while the slot was written: with the `passes`
24830
+ * section off the newest slot is an older pass's.
24831
+ *
24832
+ * @param pc - The perf context.
24833
+ * @param restart - The reason, an index into `CANVAS_RESTARTS`.
24834
+ */
24835
+ function noteRestart(pc, restart) {
24836
+ const { sinks } = pc;
24837
+ if (sinks.passes === void 0 || (sinks.sections & SECTION.passes) === 0) return;
24838
+ const { passes } = pc.perf.ring;
24839
+ passes.restart[passes.newest] = restart;
24840
+ }
24841
+ /**
24387
24842
  * Creates the WebGPU pass sink the counting encoder calls: each pass of a frame goes into the pass ring, with the
24388
24843
  * frame number and its index in the frame, while the `passes` section is on, and gets the timer's timestamp writes
24389
24844
  * when there is a timer and the `gpu` section is on (a pass the ring does not keep has the number -1).
@@ -24411,8 +24866,9 @@ function createPassSink(pc, timer, canvas) {
24411
24866
  /**
24412
24867
  * Counts the WebGL passes of every frame on Pixi's public runners: a target change emitted by `bind` is one pass; at
24413
24868
  * `renderStart` (added after Pixi's systems, so the root is bound by then) the root is one pass when `bind` emitted
24414
- * nothing, because the previous render call ended on the root. Only inside a frame. Every build counts (F8); `record`
24415
- * also writes each pass into the ring of an agent build. Stencil is not measured on WebGL.
24869
+ * nothing, because the previous render call ended on the root. A pass on the canvas counts as a canvas pass too. Only
24870
+ * inside a frame. Every build counts (F8); `record` also writes each pass into the ring of an agent build. Stencil is
24871
+ * not measured on WebGL.
24416
24872
  *
24417
24873
  * @param renderer - Pixi's WebGL renderer.
24418
24874
  * @param sinks - The sinks the count goes into.
@@ -24430,6 +24886,7 @@ function countGlPasses(renderer, sinks, record) {
24430
24886
  const { counts } = sinks;
24431
24887
  const index = cellF64(counts, COUNT.passes);
24432
24888
  counts[COUNT.passes] = index + 1;
24889
+ if (target.isRoot) counts[COUNT.canvas] = cellF64(counts, COUNT.canvas) + 1;
24433
24890
  record?.(target, index);
24434
24891
  };
24435
24892
  const prerender = {
@@ -25192,7 +25649,7 @@ function openWindow(state) {
25192
25649
  }
25193
25650
  /**
25194
25651
  * Turns the open window into the reported numbers and opens the next one: the most passes of a
25195
- * frame in it become `renderPassesMax`.
25652
+ * frame in it become `renderPassesMax`, the most canvas passes `canvasPassesMax`.
25196
25653
  *
25197
25654
  * @param state - The monitor branch of the plugin state.
25198
25655
  */
@@ -25204,6 +25661,8 @@ function closeWindow(state) {
25204
25661
  state.rebuilds = state.rebuildsOpen * WINDOW_MS / state.windowMs;
25205
25662
  state.passes.max = state.passes.open;
25206
25663
  state.passes.open = 0;
25664
+ state.canvas.max = state.canvas.open;
25665
+ state.canvas.open = 0;
25207
25666
  openWindow(state);
25208
25667
  }
25209
25668
  /**
@@ -25267,6 +25726,9 @@ function resetWindow(state) {
25267
25726
  state.passes.last = 0;
25268
25727
  state.passes.open = 0;
25269
25728
  state.passes.max = 0;
25729
+ state.canvas.last = 0;
25730
+ state.canvas.open = 0;
25731
+ state.canvas.max = 0;
25270
25732
  }
25271
25733
  //#endregion
25272
25734
  //#region src/plugins/renderer/monitor/api.ts
@@ -25320,7 +25782,7 @@ function takesResolution(value) {
25320
25782
  function createMonitorApi(ctx, deps) {
25321
25783
  const state = ctx.state.monitor;
25322
25784
  const clock = ctx.deps.clock;
25323
- const { passes, sinks } = state;
25785
+ const { canvas, passes, sinks } = state;
25324
25786
  const mctx = {
25325
25787
  ctx,
25326
25788
  deps
@@ -25339,18 +25801,42 @@ function createMonitorApi(ctx, deps) {
25339
25801
  */
25340
25802
  const measured = (counted) => sinks.measuring && counted > 0 ? counted : deps.sync.renderPasses();
25341
25803
  /**
25342
- * Closes the pass count of a frame: a drawn frame whose passes a counter saw is the new `renderPasses`; a skipped
25343
- * frame keeps both numbers. The frame closes here, except in an agent build, whose commit closes it after the
25344
- * record is written.
25804
+ * A measured canvas pass number, or the estimate of the filter slots where nothing counted one: headless, a test
25805
+ * stage, a canvas with multisampling, which Pixi begins itself.
25806
+ *
25807
+ * @param counted - The measured number; 0 before a counter saw one.
25808
+ * @returns The number `stats()` reports.
25809
+ */
25810
+ const measuredCanvas = (counted) => counted > 0 ? counted : deps.sync.canvasPasses();
25811
+ /**
25812
+ * Hears a canvas pass that really began on WebGPU, in every build: one increment inside a frame, and in an agent
25813
+ * build its reason in the pass ring. Made once: `host/render-pass.ts` calls it through the host's state.
25814
+ *
25815
+ * @param restart - The reason, an index into `CANVAS_RESTARTS`.
25816
+ */
25817
+ const canvasBegan = (restart) => {
25818
+ if (!sinks.inFrame) return;
25819
+ sinks.counts[COUNT.canvas] = cellF64(sinks.counts, COUNT.canvas) + 1;
25820
+ if (typeof __MOKU_GAME_AGENT__ !== "undefined" && __MOKU_GAME_AGENT__ && pc !== void 0) noteRestart(pc, restart);
25821
+ };
25822
+ /**
25823
+ * Closes the pass counts of a frame: a drawn frame whose passes a counter saw is the new `renderPasses` and
25824
+ * `canvasPasses`; a skipped frame keeps the numbers. The frame closes here, except in an agent build, whose commit
25825
+ * closes it after the record is written.
25345
25826
  *
25346
25827
  * @param drawn - True when the render phase drew the frame.
25347
25828
  */
25348
25829
  const notePasses = (drawn) => {
25349
25830
  const count = cellF64(sinks.counts, COUNT.passes);
25831
+ const canvasCount = cellF64(sinks.counts, COUNT.canvas);
25350
25832
  if (drawn && count > 0) {
25351
25833
  passes.last = count;
25352
25834
  passes.open = Math.max(passes.open, count);
25353
25835
  }
25836
+ if (drawn && canvasCount > 0) {
25837
+ canvas.last = canvasCount;
25838
+ canvas.open = Math.max(canvas.open, canvasCount);
25839
+ }
25354
25840
  if (pc === void 0) sinks.inFrame = false;
25355
25841
  };
25356
25842
  /**
@@ -25384,6 +25870,8 @@ function createMonitorApi(ctx, deps) {
25384
25870
  pooled: counts.pooled,
25385
25871
  renderPasses: measured(passes.last),
25386
25872
  renderPassesMax: measured(passes.max),
25873
+ canvasPasses: measuredCanvas(canvas.last),
25874
+ canvasPassesMax: measuredCanvas(canvas.max),
25387
25875
  kept: deps.kept.stats()
25388
25876
  };
25389
25877
  if ((typeof __MOKU_GAME_DEV__ === "undefined" || !__MOKU_GAME_DEV__) && (typeof __MOKU_GAME_AGENT__ === "undefined" || !__MOKU_GAME_AGENT__)) return stats;
@@ -25440,6 +25928,7 @@ function createMonitorApi(ctx, deps) {
25440
25928
  if (beginStaged(state)) deps.kept.drainTakes();
25441
25929
  state.draws.frame = 0;
25442
25930
  sinks.counts[COUNT.passes] = 0;
25931
+ sinks.counts[COUNT.canvas] = 0;
25443
25932
  sinks.inFrame = true;
25444
25933
  if (typeof __MOKU_GAME_AGENT__ !== "undefined" && __MOKU_GAME_AGENT__ && pc !== void 0) openFrame(pc.sinks);
25445
25934
  },
@@ -25465,6 +25954,7 @@ function createMonitorApi(ctx, deps) {
25465
25954
  }
25466
25955
  },
25467
25956
  attachPasses: () => {
25957
+ deps.host.onCanvasPass(canvasBegan);
25468
25958
  if (typeof __MOKU_GAME_AGENT__ !== "undefined" && __MOKU_GAME_AGENT__) return;
25469
25959
  for (const off of state.passDetach) off();
25470
25960
  state.passDetach.length = 0;
@@ -26344,6 +26834,39 @@ function countFiltered(state, kept) {
26344
26834
  walk.kept = void 0;
26345
26835
  for (let index = cache.count; index < before; index += 1) cache.filters[index] = void 0;
26346
26836
  }
26837
+ /** What the count of the views drawn live reads while it walks the filters: set before the walk, one at a time. */
26838
+ const breaks = {
26839
+ sync: void 0,
26840
+ count: 0
26841
+ };
26842
+ /**
26843
+ * Adds a view drawn live with an enabled filter to the walk's count: it breaks the canvas pass once. A view drawn from
26844
+ * its kept picture is hidden for the stage pass, and so is what hangs inside it: neither is drawn.
26845
+ *
26846
+ * @param slots - The filters of the view.
26847
+ * @param entity - The entity.
26848
+ */
26849
+ function addBreak(slots, entity) {
26850
+ const { sync } = breaks;
26851
+ if (sync?.root === void 0) return;
26852
+ if (isDrawn(sync.views.get(entity), sync.root) && passesOf(slots) > 0) breaks.count += 1;
26853
+ }
26854
+ /**
26855
+ * The canvas passes of a frame where nothing counts them: 1 for the frame, plus one break for every view drawn live
26856
+ * under the root with an enabled filter, by the walk of `renderPassesOf`. Counted at every call, not through the cache
26857
+ * of `renderPassesOf`, which a take does not move: `stats()` reads it, never a frame.
26858
+ *
26859
+ * @param state - The sync branch of the plugin state.
26860
+ * @returns The canvas passes; 0 while inert.
26861
+ */
26862
+ function canvasPassesOf(state) {
26863
+ if (state.root === void 0) return 0;
26864
+ breaks.sync = state;
26865
+ breaks.count = 0;
26866
+ state.filters.forEach(addBreak);
26867
+ breaks.sync = void 0;
26868
+ return 1 + breaks.count;
26869
+ }
26347
26870
  /**
26348
26871
  * Tells whether a filter of the count was switched on or off since, by its field alone.
26349
26872
  *
@@ -34212,6 +34735,7 @@ function createSyncApi(ctx, deps) {
34212
34735
  }
34213
34736
  },
34214
34737
  overlays: () => overlayReports(sctx),
34738
+ why: () => deps.kept.why(),
34215
34739
  state: () => ({
34216
34740
  ...state.debug,
34217
34741
  verifyFrames: deps.demand.verifying(),
@@ -34229,6 +34753,7 @@ function createSyncApi(ctx, deps) {
34229
34753
  drop: () => dropLeave(sctx)
34230
34754
  },
34231
34755
  renderPasses: () => renderPassesOf(state, ctx.state.kept),
34756
+ canvasPasses: () => canvasPassesOf(state),
34232
34757
  root: () => state.root,
34233
34758
  layerContainer: (name) => layerContainer(state, name),
34234
34759
  layerOf: (entity) => layerOf$1(sctx, entity),
@@ -36980,8 +37505,10 @@ function unfileAdditive(actx, track) {
36980
37505
  if (tracks?.delete(track) === true && tracks.size === 0) actx.state.additive.delete(track.entity);
36981
37506
  }
36982
37507
  /**
36983
- * Reads the start values of a track, once, when its delay has ended. The base of a field another
36984
- * track already drives is used, so an additive offset is never folded into a start value.
37508
+ * Reads the start values of a track, once, when its delay has ended. The base of a field an
37509
+ * additive track adds to is used, so an offset is never folded into a start value. With no offset
37510
+ * on the field the stored value is the truth: a pose written after the last track wrote stands
37511
+ * there, and it becomes the base (F127).
36985
37512
  *
36986
37513
  * @param actx - Domain context of the anim plugin.
36987
37514
  * @param track - The track that is about to write.
@@ -36997,9 +37524,11 @@ function beginTrack(actx, track, stored) {
36997
37524
  const base = actx.state.bases.get(key);
36998
37525
  const current = stored[field];
36999
37526
  const read = typeof current === "number" ? current : track.targets[slot] ?? 0;
37000
- const value = base === void 0 ? read : cellValue(base);
37001
- track.starts[slot] = value;
37002
- if (base === void 0) setBase(actx, key, value);
37527
+ if (base !== void 0 && actx.state.offsets.has(key)) track.starts[slot] = cellValue(base);
37528
+ else {
37529
+ track.starts[slot] = read;
37530
+ setBase(actx, key, read);
37531
+ }
37003
37532
  }
37004
37533
  }
37005
37534
  /**
@@ -70960,4 +71489,4 @@ const screen = [
70960
71489
  uiPlugin
70961
71490
  ];
70962
71491
  //#endregion
70963
- export { sfx as $, flowPlugin as $t, types_exports$10 as A, Glow as At, defineMotion as B, Animation as Bt, types_exports$3 as C, messageDuration as Ct, types_exports$7 as D, Blur as Dt, types_exports$6 as E, Alpha as Et, types_exports$15 as F, audioPlugin as Ft, external as G, MONITOR_SECTIONS as Gt, platformPlugin as H, rendererPlugin as Ht, types_exports$16 as I, scenesPlugin as It, mark as J, PERF_LOG_VERSION as Jt, frames as K, PERF_CAUSES as Kt, types_exports$17 as L, assetsPlugin as Lt, types_exports$12 as M, Outline as Mt, types_exports$13 as N, defineFilter as Nt, types_exports$8 as O, ColorMatrix as Ot, types_exports$14 as P, debugPlugin as Pt, set as Q, worldPlugin as Qt, uiPlugin as R, animPlugin as Rt, types_exports$2 as S, messageArgument as St, types_exports$5 as T, Emitter as Tt, HAPTIC_KINDS as U, PASS_KINDS as Ut, textPlugin as V, Frames as Vt, defineAnimation as W, frameAt as Wt, play$1 as X, SHADER_WHATS as Xt, parallel as Y, PROBLEM_RULES as Yt, sequence as Z, DEMAND_REASONS as Zt, defineBundles as _, Tappable as _t, cubicBezier as a, type as an, use as at, types_exports as b, Traced as bt, hint as c, lifecyclePlugin as cn, Draggable as ct, defineScene as d, Hovered as dt, refuseStart as en, spawn as et, tr as f, Pointer as ft, music as g, Swipeable as gt, defineEmitter as h, Pressed as ht, screen as i, to as in, tween as it, types_exports$11 as j, Noise as jt, types_exports$9 as k, Displacement as kt, schedule as l, timePlugin as ln, DropTarget as lt, flattenFeatures as m, Pressable as mt, createPlugin as n, exit as nn, stagger as nt, defineEffect as o, modelPlugin as on, wait as ot, defineFeature as p, PointerOver as pt, haptic as q, PERF_GAP_BUCKETS as qt, defineGame as r, slot as rn, stopSfx as rt, guide as s, SaveUnreadableError as sn, inputPlugin as st, createApp as t, contribution as tn, spawned as tt, projection as u, clockPlugin as un, Held as ut, load as v, Touchable as vt, types_exports$4 as w, effectsPlugin as wt, types_exports$1 as x, i18nPlugin as xt, ready as y, Traceable as yt, resolve as z, AnimPlayer as zt };
71492
+ export { sfx as $, worldPlugin as $t, types_exports$10 as A, Glow as At, defineMotion as B, Animation as Bt, types_exports$3 as C, messageDuration as Ct, types_exports$7 as D, Blur as Dt, types_exports$6 as E, Alpha as Et, types_exports$15 as F, audioPlugin as Ft, external as G, MONITOR_SECTIONS as Gt, platformPlugin as H, rendererPlugin as Ht, types_exports$16 as I, scenesPlugin as It, mark as J, PERF_LOG_VERSION as Jt, frames as K, PERF_CAUSES as Kt, types_exports$17 as L, assetsPlugin as Lt, types_exports$12 as M, Outline as Mt, types_exports$13 as N, defineFilter as Nt, types_exports$8 as O, ColorMatrix as Ot, types_exports$14 as P, debugPlugin as Pt, set as Q, DEMAND_REASONS as Qt, uiPlugin as R, animPlugin as Rt, types_exports$2 as S, messageArgument as St, types_exports$5 as T, Emitter as Tt, HAPTIC_KINDS as U, PASS_KINDS as Ut, textPlugin as V, Frames as Vt, defineAnimation as W, frameAt as Wt, play$1 as X, SHADER_WHATS as Xt, parallel as Y, PROBLEM_RULES as Yt, sequence as Z, CANVAS_RESTARTS as Zt, defineBundles as _, Tappable as _t, cubicBezier as a, to as an, use as at, types_exports as b, Traced as bt, hint as c, SaveUnreadableError as cn, Draggable as ct, defineScene as d, clockPlugin as dn, Hovered as dt, flowPlugin as en, spawn as et, tr as f, Pointer as ft, music as g, Swipeable as gt, defineEmitter as h, Pressed as ht, screen as i, slot as in, tween as it, types_exports$11 as j, Noise as jt, types_exports$9 as k, Displacement as kt, schedule as l, lifecyclePlugin as ln, DropTarget as lt, flattenFeatures as m, Pressable as mt, createPlugin as n, contribution as nn, stagger as nt, defineEffect as o, type as on, wait as ot, defineFeature as p, PointerOver as pt, haptic as q, PERF_GAP_BUCKETS as qt, defineGame as r, exit as rn, stopSfx as rt, guide as s, modelPlugin as sn, inputPlugin as st, createApp as t, refuseStart as tn, spawned as tt, projection as u, timePlugin as un, Held as ut, load as v, Touchable as vt, types_exports$4 as w, effectsPlugin as wt, types_exports$1 as x, i18nPlugin as xt, ready as y, Traceable as yt, resolve as z, AnimPlayer as zt };