@moku-labs/game 0.15.85 → 0.15.86

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.
@@ -17775,7 +17775,8 @@ function standInOf(pixi, record) {
17775
17775
  }
17776
17776
  /**
17777
17777
  * The output texture of stage 3 at its size: the subtree picture padded by the stack's padding on its grid, at the
17778
- * renderer resolution. Stage 2 renders into it too, before stage 3 clears it.
17778
+ * renderer resolution. Stage 2 renders into it too, before stage 3 clears it, and a shaded record copies its picture
17779
+ * into it (`shade.ts`).
17779
17780
  *
17780
17781
  * @param kctx - The kept context.
17781
17782
  * @param pixi - The module that draws.
@@ -17785,12 +17786,18 @@ function standInOf(pixi, record) {
17785
17786
  * @returns The texture.
17786
17787
  */
17787
17788
  function outputOf(kctx, pixi, record, resolution, padding) {
17788
- const { key } = record;
17789
+ const { key, s3 } = record;
17789
17790
  const Ps = paddingOnGrid(padding, key[KEY.rs] ?? 1);
17791
+ const width = (key[KEY.w1] ?? 0) + 2 * Ps;
17792
+ const height = (key[KEY.h1] ?? 0) + 2 * Ps;
17790
17793
  key[KEY.Ps] = Ps;
17794
+ if (s3 !== void 0 && !s3.destroyed) {
17795
+ const { source } = s3;
17796
+ if (source.pixelWidth === Math.round(width * resolution) && source.pixelHeight === Math.round(height * resolution) && source.resolution === resolution) return s3;
17797
+ }
17791
17798
  record.s3 = fitTexture(kctx, pixi, record.s3, {
17792
- width: (key[KEY.w1] ?? 0) + 2 * Ps,
17793
- height: (key[KEY.h1] ?? 0) + 2 * Ps,
17799
+ width,
17800
+ height,
17794
17801
  resolution
17795
17802
  }, `kept:${labelOf$4(record.top)}#3`);
17796
17803
  return record.s3;
@@ -17923,9 +17930,12 @@ function noteStage2(record, inputs) {
17923
17930
  * @param y - The origin's y, canvas px.
17924
17931
  */
17925
17932
  function setOrigins(slots, x, y) {
17926
- for (const slot of slots) if (slot.origin !== void 0) {
17927
- slot.origin[0] = x;
17928
- slot.origin[1] = y;
17933
+ for (let index = 0; index < slots.length; index += 1) {
17934
+ const origin = slots[index]?.origin;
17935
+ if (origin !== void 0) {
17936
+ origin[0] = x;
17937
+ origin[1] = y;
17938
+ }
17929
17939
  }
17930
17940
  }
17931
17941
  /**
@@ -17940,8 +17950,8 @@ function setOrigins(slots, x, y) {
17940
17950
  * @param now - The frame's numbers.
17941
17951
  * @param now.r - The renderer resolution.
17942
17952
  * @param now.P - The padding sum of the enabled filters.
17943
- * @param now.tx - The top's translation now.
17944
- * @param now.ty - The top's translation now.
17953
+ * @param now.tx - The top's x translation now.
17954
+ * @param now.ty - The top's y translation now.
17945
17955
  * @returns True when Pixi rendered it.
17946
17956
  */
17947
17957
  function renderStage3(kctx, pixi, matrices, record, now) {
@@ -18464,6 +18474,444 @@ function drawnBounds(pixi, top) {
18464
18474
  addDrawn$1(pixi, top, into, 0, top);
18465
18475
  return into;
18466
18476
  }
18477
+ /**
18478
+ * One vector of the group, over an array the caller keeps.
18479
+ *
18480
+ * @param value - The array.
18481
+ * @returns The uniform.
18482
+ */
18483
+ function vector(value) {
18484
+ return {
18485
+ value,
18486
+ type: "vec4<f32>"
18487
+ };
18488
+ }
18489
+ /**
18490
+ * The group of the numbers a filter pass hands a body, under the names Pixi's filter system fills, and the arrays it
18491
+ * reads, typed. Static: a group that is not is uploaded on every draw, and a shaded view changes these only when it
18492
+ * moves or its picture changes size.
18493
+ *
18494
+ * @param pixi - The module that draws.
18495
+ * @returns The group, zeros, and its vectors.
18496
+ */
18497
+ function filterGlobals(pixi) {
18498
+ const vectors = {
18499
+ uInputSize: /* @__PURE__ */ new Float32Array(4),
18500
+ uInputPixel: /* @__PURE__ */ new Float32Array(4),
18501
+ uInputClamp: /* @__PURE__ */ new Float32Array(4),
18502
+ uOutputFrame: /* @__PURE__ */ new Float32Array(4),
18503
+ uGlobalFrame: /* @__PURE__ */ new Float32Array(4),
18504
+ uOutputTexture: /* @__PURE__ */ new Float32Array(4)
18505
+ };
18506
+ return {
18507
+ group: new pixi.UniformGroup({
18508
+ uInputSize: vector(vectors.uInputSize),
18509
+ uInputPixel: vector(vectors.uInputPixel),
18510
+ uInputClamp: vector(vectors.uInputClamp),
18511
+ uOutputFrame: vector(vectors.uOutputFrame),
18512
+ uGlobalFrame: vector(vectors.uGlobalFrame),
18513
+ uOutputTexture: vector(vectors.uOutputTexture)
18514
+ }, { isStatic: true }),
18515
+ vectors
18516
+ };
18517
+ }
18518
+ /**
18519
+ * The unit square of a quad program, its uvs over the whole texture: the mesh's scale gives it its size.
18520
+ *
18521
+ * @param pixi - The module that draws.
18522
+ * @returns A new geometry.
18523
+ */
18524
+ function unitQuad(pixi) {
18525
+ return new pixi.MeshGeometry({
18526
+ positions: new Float32Array([
18527
+ 0,
18528
+ 0,
18529
+ 1,
18530
+ 0,
18531
+ 1,
18532
+ 1,
18533
+ 0,
18534
+ 1
18535
+ ]),
18536
+ uvs: new Float32Array([
18537
+ 0,
18538
+ 0,
18539
+ 1,
18540
+ 0,
18541
+ 1,
18542
+ 1,
18543
+ 0,
18544
+ 1
18545
+ ]),
18546
+ indices: new Uint32Array([
18547
+ 0,
18548
+ 1,
18549
+ 2,
18550
+ 0,
18551
+ 2,
18552
+ 3
18553
+ ])
18554
+ });
18555
+ }
18556
+ /**
18557
+ * The shader of a quad over a texture. `fu` is left out for a filter that binds none: Pixi throws on an undefined
18558
+ * resource.
18559
+ *
18560
+ * @param pixi - The module that draws.
18561
+ * @param quad - The slot's quad.
18562
+ * @param gfu - The global filter uniforms.
18563
+ * @param source - The texture it reads.
18564
+ * @returns The shader.
18565
+ */
18566
+ function quadShader(pixi, quad, gfu, source) {
18567
+ const { program, fu } = quad;
18568
+ const texture = {
18569
+ gfu,
18570
+ uTexture: source,
18571
+ uSampler: source.style
18572
+ };
18573
+ return new pixi.Shader({
18574
+ gpuProgram: program,
18575
+ resources: fu === void 0 ? texture : {
18576
+ ...texture,
18577
+ fu
18578
+ }
18579
+ });
18580
+ }
18581
+ //#endregion
18582
+ //#region src/plugins/renderer/kept/shade.ts
18583
+ /**
18584
+ * @file renderer/kept — a kept view on its filter's own shader (F126 stage 2). A view whose filter numbers change would
18585
+ * pay a stage 3 pass in every frame; a shaded record draws instead through a `Mesh` that runs the filter's body over the
18586
+ * padded picture, inside the pass that draws the canvas. `s3` then holds the subtree picture copied at `translate(Ps,
18587
+ * Ps)` with no filter, one pass only when the picture, the padding or the resolution changed; a new number is drawn by
18588
+ * the mesh with no pass at all. The renderer holds no shader text: `effects` hands a built program over the slot. The
18589
+ * policy of the mode, when it is entered and left, lives in `record.ts`; this file holds what is made, bound and freed.
18590
+ * The filter's uniform group is the instance's own, read by the mesh as it stands.
18591
+ */
18592
+ /** The numbers `renderShade` wants in the group this frame, in the order of `writeGlobals`. One array: it allocates nothing. */
18593
+ const WANTED = /* @__PURE__ */ new Float32Array(24);
18594
+ /** `uOutputTexture.z` of a pass that ends on the canvas: Pixi's sign for a root target, which turns `y` over. */
18595
+ const ROOT_TARGET = -1;
18596
+ /**
18597
+ * The first enabled slot of a stack: the one slot of a stack that fits the mode.
18598
+ *
18599
+ * @param slots - The record's slots.
18600
+ * @returns The slot, or `undefined` when none is enabled.
18601
+ */
18602
+ function enabledSlot(slots) {
18603
+ for (let index = 0; index < slots.length; index += 1) {
18604
+ const slot = slots[index];
18605
+ if (slot?.filter.enabled === true) return slot;
18606
+ }
18607
+ }
18608
+ /**
18609
+ * The one unit quad of the run, made on demand.
18610
+ *
18611
+ * @param state - The kept state.
18612
+ * @param pixi - The module that draws.
18613
+ * @returns The geometry.
18614
+ */
18615
+ function geometryOf(state, pixi) {
18616
+ state.quadGeometry ??= unitQuad(pixi);
18617
+ return state.quadGeometry;
18618
+ }
18619
+ /**
18620
+ * The one sprite that copies a picture into its output, made on demand. It is only ever the root of its own render.
18621
+ *
18622
+ * @param state - The kept state.
18623
+ * @param pixi - The module that draws.
18624
+ * @returns The sprite.
18625
+ */
18626
+ function copyOf$1(state, pixi) {
18627
+ if (state.quadCopy === void 0) {
18628
+ state.quadCopy = new pixi.Sprite(pixi.Texture.EMPTY);
18629
+ state.quadCopy.label = "kept:copy";
18630
+ }
18631
+ return state.quadCopy;
18632
+ }
18633
+ /**
18634
+ * Makes the mesh of a record: no texture of its own, the shader binds the picture.
18635
+ *
18636
+ * @param kctx - The kept context.
18637
+ * @param pixi - The module that draws.
18638
+ * @param record - The record.
18639
+ * @param shader - The shader.
18640
+ * @returns The mesh.
18641
+ */
18642
+ function meshOf(kctx, pixi, record, shader) {
18643
+ const mesh = new pixi.Mesh({
18644
+ geometry: geometryOf(kctx.state, pixi),
18645
+ shader
18646
+ });
18647
+ mesh.label = `kept:${labelOf$4(record.top)}`;
18648
+ return mesh;
18649
+ }
18650
+ /**
18651
+ * Makes what a record draws through, at its first entry.
18652
+ *
18653
+ * @param kctx - The kept context.
18654
+ * @param pixi - The module that draws.
18655
+ * @param record - The record.
18656
+ * @param quad - The slot's quad.
18657
+ * @param output - The texture the record draws from.
18658
+ * @param sprite - The sprite of the record's picture.
18659
+ * @returns The shade.
18660
+ */
18661
+ function makeShade(kctx, pixi, record, quad, output, sprite) {
18662
+ const { group, vectors } = filterGlobals(pixi);
18663
+ const { source } = output;
18664
+ const shader = quadShader(pixi, quad, group, source);
18665
+ return {
18666
+ mesh: meshOf(kctx, pixi, record, shader),
18667
+ shader,
18668
+ gfu: group,
18669
+ vectors,
18670
+ sprite,
18671
+ quad,
18672
+ source,
18673
+ copied: -1,
18674
+ copiedWidth: 0,
18675
+ copiedHeight: 0
18676
+ };
18677
+ }
18678
+ /**
18679
+ * Hangs one quad in the place of another in the tree, and takes the other out.
18680
+ *
18681
+ * @param from - The quad that goes.
18682
+ * @param to - The quad that comes.
18683
+ */
18684
+ function swapQuad(from, to) {
18685
+ const parent = from.parent;
18686
+ if (parent !== null) parent.addChildAt(to, parent.getChildIndex(from));
18687
+ from.removeFromParent();
18688
+ to.visible = from.visible;
18689
+ }
18690
+ /**
18691
+ * Puts a record on its mesh: the mesh in the sprite's place, the sprite kept aside, the matrix written again, a copy
18692
+ * owed. What it draws through is made at the first entry, and an entry after that makes nothing, unless the mesh went
18693
+ * with a parent destroyed around it.
18694
+ *
18695
+ * @param kctx - The kept context.
18696
+ * @param pixi - The module that draws.
18697
+ * @param record - The record, kept, not shaded, its quad placed.
18698
+ * @param quad - The slot's quad.
18699
+ * @param now - The frame's numbers.
18700
+ * @param now.r - The renderer resolution.
18701
+ * @param now.P - The padding sum of the enabled filters.
18702
+ * @returns True when the record is on its mesh; false for a record with no sprite to take the place of.
18703
+ */
18704
+ function enterShade(kctx, pixi, record, quad, now) {
18705
+ const sprite = record.quad;
18706
+ if (!(sprite instanceof pixi.Sprite)) return false;
18707
+ const output = outputOf(kctx, pixi, record, now.r, now.P);
18708
+ const shade = record.shade ?? makeShade(kctx, pixi, record, quad, output, sprite);
18709
+ record.shade = shade;
18710
+ if (shade.mesh.destroyed) shade.mesh = meshOf(kctx, pixi, record, shade.shader);
18711
+ shade.sprite = sprite;
18712
+ swapQuad(sprite, shade.mesh);
18713
+ record.quad = shade.mesh;
18714
+ record.shaded = true;
18715
+ shade.copied = -1;
18716
+ record.key[KEY.qa] = NaN;
18717
+ return true;
18718
+ }
18719
+ /**
18720
+ * Puts a record back on its sprite: `goLive` and `goDirect` come through here first, so an eviction, a churn, an
18721
+ * ineligible frame and a stack reduced to `Alpha` all leave one way, before `s3` is dropped: a mesh never outlives its
18722
+ * binding. The sprite shows what `s3` holds next: a caller that keeps the record owes it stage 3.
18723
+ *
18724
+ * @param record - The record.
18725
+ */
18726
+ function leaveShade(record) {
18727
+ const { shade } = record;
18728
+ if (!record.shaded || shade === void 0) return;
18729
+ swapQuad(shade.mesh, shade.sprite);
18730
+ record.quad = shade.sprite;
18731
+ record.shaded = false;
18732
+ shade.copied = -1;
18733
+ record.key[KEY.qa] = NaN;
18734
+ }
18735
+ /**
18736
+ * Builds the shader again for another slot's quad: `effects` hands one per instance, so the numbers of the view's new
18737
+ * instance are bound and those of the old one, which may go at any moment, are not.
18738
+ *
18739
+ * @param pixi - The module that draws.
18740
+ * @param shade - The shade.
18741
+ * @param quad - The slot's quad now.
18742
+ * @param source - The texture it reads.
18743
+ */
18744
+ function rebuildShader(pixi, shade, quad, source) {
18745
+ const old = shade.shader;
18746
+ shade.shader = quadShader(pixi, quad, shade.gfu, source);
18747
+ shade.mesh.shader = shade.shader;
18748
+ shade.quad = quad;
18749
+ shade.source = source;
18750
+ shade.copied = -1;
18751
+ old.destroy();
18752
+ }
18753
+ /**
18754
+ * Copies a vector of `WANTED` into the group where it differs. Both sides are 32-bit numbers: a double would differ from
18755
+ * its stored value in every frame, and the group would be uploaded in every frame.
18756
+ *
18757
+ * @param target - The group's vector.
18758
+ * @param at - Where the vector starts in `WANTED`.
18759
+ * @returns True when a number differed.
18760
+ */
18761
+ function writeVector$1(target, at) {
18762
+ let differs = false;
18763
+ for (let index = 0; index < 4; index += 1) {
18764
+ const value = WANTED[at + index] ?? 0;
18765
+ if (target[index] !== value) {
18766
+ target[index] = value;
18767
+ differs = true;
18768
+ }
18769
+ }
18770
+ return differs;
18771
+ }
18772
+ /**
18773
+ * Writes the numbers a filter pass would hand the body for the padded picture at its canvas place: `uv` runs over the
18774
+ * whole texture, the frame stands at `O + Δ`, and the target is the canvas. Uploaded once, only when one differs.
18775
+ *
18776
+ * @param kctx - The kept context.
18777
+ * @param record - The record.
18778
+ * @param shade - Its shade.
18779
+ * @param source - The padded picture.
18780
+ * @param now - The frame's numbers.
18781
+ * @param now.r - The renderer resolution.
18782
+ * @param now.tx - The top's x translation now.
18783
+ * @param now.ty - The top's y translation now.
18784
+ */
18785
+ function writeGlobals(kctx, record, shade, source, now) {
18786
+ const { key } = record;
18787
+ const { width, height, pixelWidth, pixelHeight } = source;
18788
+ const screen = kctx.host.screen();
18789
+ const screenWidth = screen?.width ?? 0;
18790
+ const screenHeight = screen?.height ?? 0;
18791
+ const Ps = key[KEY.Ps] ?? 0;
18792
+ WANTED[0] = width;
18793
+ WANTED[1] = height;
18794
+ WANTED[2] = 1 / width;
18795
+ WANTED[3] = 1 / height;
18796
+ WANTED[4] = pixelWidth;
18797
+ WANTED[5] = pixelHeight;
18798
+ WANTED[6] = 1 / pixelWidth;
18799
+ WANTED[7] = 1 / pixelHeight;
18800
+ WANTED[8] = .5 / pixelWidth;
18801
+ WANTED[9] = .5 / pixelHeight;
18802
+ WANTED[10] = 1 - .5 / pixelWidth;
18803
+ WANTED[11] = 1 - .5 / pixelHeight;
18804
+ WANTED[12] = (key[KEY.X0] ?? 0) - Ps + now.tx - (key[KEY.tx] ?? 0);
18805
+ WANTED[13] = (key[KEY.Y0] ?? 0) - Ps + now.ty - (key[KEY.ty] ?? 0);
18806
+ WANTED[14] = width;
18807
+ WANTED[15] = height;
18808
+ WANTED[16] = 0;
18809
+ WANTED[17] = 0;
18810
+ WANTED[18] = screenWidth * now.r;
18811
+ WANTED[19] = screenHeight * now.r;
18812
+ WANTED[20] = screenWidth;
18813
+ WANTED[21] = screenHeight;
18814
+ WANTED[22] = ROOT_TARGET;
18815
+ WANTED[23] = 0;
18816
+ const { vectors } = shade;
18817
+ let differs = writeVector$1(vectors.uInputSize, 0);
18818
+ differs = writeVector$1(vectors.uInputPixel, 4) || differs;
18819
+ differs = writeVector$1(vectors.uInputClamp, 8) || differs;
18820
+ differs = writeVector$1(vectors.uOutputFrame, 12) || differs;
18821
+ differs = writeVector$1(vectors.uGlobalFrame, 16) || differs;
18822
+ differs = writeVector$1(vectors.uOutputTexture, 20) || differs;
18823
+ if (differs) shade.gfu.update();
18824
+ }
18825
+ /**
18826
+ * Copies the subtree picture into the output at `translate(Ps, Ps)`, no filter, a cleared target: the padded picture the
18827
+ * body reads. One pass, counted.
18828
+ *
18829
+ * @param kctx - The kept context.
18830
+ * @param pixi - The module that draws.
18831
+ * @param matrices - The scratch matrices.
18832
+ * @param record - The record, shaded, its `Ps` written.
18833
+ * @param output - The output.
18834
+ * @returns True when Pixi rendered it.
18835
+ */
18836
+ function copyPadded(kctx, pixi, matrices, record, output) {
18837
+ const { key, shade } = record;
18838
+ const copy = copyOf$1(kctx.state, pixi);
18839
+ const Ps = key[KEY.Ps] ?? 0;
18840
+ copy.texture = record.s1 ?? pixi.Texture.EMPTY;
18841
+ matrices.m3.set(1, 0, 0, 1, Ps, Ps);
18842
+ if (shade === void 0 || !kctx.host.renderTo(copy, output, matrices.m3, true)) return false;
18843
+ const { source } = output;
18844
+ kctx.state.flushPasses += 1;
18845
+ shade.copied = record.s1Version;
18846
+ shade.copiedWidth = source.pixelWidth;
18847
+ shade.copiedHeight = source.pixelHeight;
18848
+ return true;
18849
+ }
18850
+ /**
18851
+ * The frame of a shaded record: stage 3 for the mesh. The output at its size, the shader on the slot's quad and on that
18852
+ * texture, the padded picture copied when `s1`, the padding or the resolution changed (one pass, counted), the global
18853
+ * uniforms, then `keptOrigin` at 0: in the mode the place is in `uOutputFrame.xy`, so `canvasPixel` and a body that reads
18854
+ * the frame answer the same. The keys stage 3 writes. A new number needs none of it: the mesh reads the instance's own
18855
+ * uniform group. Allocates nothing while the size stands.
18856
+ *
18857
+ * @param kctx - The kept context.
18858
+ * @param pixi - The module that draws.
18859
+ * @param matrices - The scratch matrices.
18860
+ * @param record - The record, shaded, stage 1 done.
18861
+ * @param now - The frame's numbers.
18862
+ * @param now.r - The renderer resolution.
18863
+ * @param now.P - The padding sum of the enabled filters.
18864
+ * @param now.tx - The top's x translation now.
18865
+ * @param now.ty - The top's y translation now.
18866
+ * @returns True when the copy, if one was owed, rendered.
18867
+ */
18868
+ function renderShade(kctx, pixi, matrices, record, now) {
18869
+ const { key, shade } = record;
18870
+ if (shade === void 0) return false;
18871
+ const output = outputOf(kctx, pixi, record, now.r, now.P);
18872
+ const { source } = output;
18873
+ const quad = enabledSlot(record.slots)?.quad;
18874
+ if (quad !== void 0 && quad !== shade.quad) rebuildShader(pixi, shade, quad, source);
18875
+ if (source !== shade.source) {
18876
+ const { resources } = shade.shader;
18877
+ resources.uTexture = source;
18878
+ resources.uSampler = source.style;
18879
+ shade.source = source;
18880
+ shade.copied = -1;
18881
+ }
18882
+ const resized = source.pixelWidth !== shade.copiedWidth || source.pixelHeight !== shade.copiedHeight;
18883
+ if ((shade.copied !== record.s1Version || resized) && !copyPadded(kctx, pixi, matrices, record, output)) return false;
18884
+ writeGlobals(kctx, record, shade, source, now);
18885
+ setOrigins(record.slots, 0, 0);
18886
+ key[KEY.r] = now.r;
18887
+ key[KEY.P] = now.P;
18888
+ key[KEY.s3Tx] = now.tx;
18889
+ key[KEY.s3Ty] = now.ty;
18890
+ return true;
18891
+ }
18892
+ /**
18893
+ * Destroys what a record drew through. The uniform buffer goes first, by hand: Pixi's `destroy` leaves it to a collector
18894
+ * that runs after a minute. The mesh leaves the shared geometry alone.
18895
+ *
18896
+ * @param shade - The shade.
18897
+ */
18898
+ function destroyShade(shade) {
18899
+ shade.gfu.buffer?.destroy();
18900
+ shade.mesh.destroy();
18901
+ shade.shader.destroy();
18902
+ shade.sprite.destroy();
18903
+ }
18904
+ /**
18905
+ * Destroys what the shaded records of a run share; the next entry makes them again, on the device there is then.
18906
+ *
18907
+ * @param state - The kept state.
18908
+ */
18909
+ function dropQuadParts(state) {
18910
+ state.quadGeometry?.destroy(true);
18911
+ state.quadCopy?.destroy();
18912
+ state.quadGeometry = void 0;
18913
+ state.quadCopy = void 0;
18914
+ }
18467
18915
  //#endregion
18468
18916
  //#region src/plugins/renderer/kept/state.ts
18469
18917
  /**
@@ -18524,6 +18972,8 @@ function createKeptState(config) {
18524
18972
  byTop: emptyMap$8(),
18525
18973
  ranges: emptyMap$8(),
18526
18974
  spare: void 0,
18975
+ quadGeometry: void 0,
18976
+ quadCopy: void 0,
18527
18977
  pool: emptyTextures(),
18528
18978
  poolBytes: 0,
18529
18979
  madeGroups: emptyWeakSet$2(),
@@ -18559,12 +19009,14 @@ function createKeptState(config) {
18559
19009
  }
18560
19010
  /**
18561
19011
  * Destroys the engine objects of one record: the quad leaves the tree, the stand-ins drop the filters first (they
18562
- * belong to `effects`), the keeper and every texture go.
19012
+ * belong to `effects`), the keeper and every texture go. The shader goes before the textures: Pixi warns at a source
19013
+ * destroyed while a shader binds it.
18563
19014
  *
18564
19015
  * @param record - The record.
18565
19016
  * @param drop - Destroys one texture: unregisters it from `host.keep` first while the host lives.
18566
19017
  */
18567
19018
  function destroyRecord(record, drop) {
19019
+ if (record.shade !== void 0) destroyShade(record.shade);
18568
19020
  if (record.standIn !== void 0) {
18569
19021
  record.standIn.filters = null;
18570
19022
  record.standIn.destroy();
@@ -18578,6 +19030,8 @@ function destroyRecord(record, drop) {
18578
19030
  if (record.s1 !== void 0) drop(record.s1);
18579
19031
  if (record.s3 !== void 0) drop(record.s3);
18580
19032
  for (const texture of record.s2) drop(texture);
19033
+ record.shade = void 0;
19034
+ record.shaded = false;
18581
19035
  record.standIn = void 0;
18582
19036
  record.keeperStandIn = void 0;
18583
19037
  record.keeper = void 0;
@@ -18625,6 +19079,7 @@ function stopKept(state) {
18625
19079
  for (const range of state.ranges.values()) destroyRange(range, destroyTexture$1);
18626
19080
  if (state.spare !== void 0) destroyWhole(state.spare);
18627
19081
  state.spare = void 0;
19082
+ dropQuadParts(state);
18628
19083
  for (const texture of state.pool) destroyTexture$1(texture);
18629
19084
  state.pool.length = 0;
18630
19085
  state.poolBytes = 0;
@@ -18810,6 +19265,26 @@ function drawsDirect(stack) {
18810
19265
  return !Number.isNaN(stack.alpha) && stack.P === 0 && stack.rs === NOW.r;
18811
19266
  }
18812
19267
  /**
19268
+ * Tells whether the record being stepped may draw through its filter's own body (F126 stage 2): on WebGPU, one enabled
19269
+ * filter with a quad, no inputs, on `"inherit"`, at the canvas resolution, and not drawn direct. An `Alpha` beside it does
19270
+ * not fit: stage 3 draws `F(A·x)` in stack order, the mesh would draw `A·F(x)`, and for a body that is not alpha-linear
19271
+ * the picture would pop at every entry. A top that blends otherwise never gets here: `pictureWhy` refuses it. A mesh
19272
+ * destroyed with a parent around it has nothing left to draw on. Read on `NOW`, once a step; allocates nothing.
19273
+ *
19274
+ * @param kctx - The kept context.
19275
+ * @param record - The record.
19276
+ * @returns True when it fits.
19277
+ */
19278
+ function shadeFits(kctx, record) {
19279
+ if (kctx.host.kind() !== "webgpu" || NOW.enabled !== 1) return false;
19280
+ if (NOW.rs !== NOW.r || drawsDirect(NOW)) return false;
19281
+ const slot = enabledSlot(record.slots);
19282
+ const bodyOnQuad = slot?.quad !== void 0 && slot.inputs === void 0;
19283
+ const followsCanvas = slot?.filter.resolution === "inherit";
19284
+ const meshStands = !record.shaded || record.shade?.mesh.destroyed !== true;
19285
+ return bodyOnQuad && followsCanvas && meshStands;
19286
+ }
19287
+ /**
18813
19288
  * Tells whether a take the budget refused still does not fit (P6.3); the pool's bytes are the take's to have (F119).
18814
19289
  *
18815
19290
  * @param state - The kept state.
@@ -19086,6 +19561,11 @@ function createRecord$1(kctx, pixi, entity, view, slots, category) {
19086
19561
  standIn: void 0,
19087
19562
  keeperStandIn: void 0,
19088
19563
  quad: void 0,
19564
+ shade: void 0,
19565
+ shaded: false,
19566
+ outputRuns: 0,
19567
+ outputAt: 0,
19568
+ shadedAt: 0,
19089
19569
  keeper: void 0,
19090
19570
  s1: void 0,
19091
19571
  s2: [],
@@ -19109,6 +19589,7 @@ function createRecord$1(kctx, pixi, entity, view, slots, category) {
19109
19589
  settle: false,
19110
19590
  coarse: false,
19111
19591
  refined: false,
19592
+ redrawn: false,
19112
19593
  refused: 0,
19113
19594
  cut: false,
19114
19595
  direct: false,
@@ -19144,6 +19625,7 @@ function createRecord$1(kctx, pixi, entity, view, slots, category) {
19144
19625
  * @param putBack - False when the view is leaving: the release strips its filters anyway.
19145
19626
  */
19146
19627
  function goLive(kctx, record, view, putBack) {
19628
+ leaveShade(record);
19147
19629
  endLoan(record.s2Of);
19148
19630
  setOrigins(record.slots, 0, 0);
19149
19631
  if (record.standIn !== void 0 && !record.standIn.destroyed) record.standIn.filters = null;
@@ -19468,13 +19950,15 @@ function renderStages(kctx, pixi, matrices, record, view, now) {
19468
19950
  return ok;
19469
19951
  }
19470
19952
  record.direct = false;
19953
+ if (record.shaded && !shadeFits(kctx, record)) leaveShade(record);
19471
19954
  if (ok && first !== void 0) renderStage2(kctx, pixi, matrices, record, {
19472
19955
  inputs: first.inputs,
19473
19956
  resolution: now.r,
19474
19957
  padding: now.P
19475
19958
  });
19476
19959
  else if (record.s2Of !== void 0) releaseInputs(kctx, record);
19477
- ok = ok && renderStage3(kctx, pixi, matrices, record, now);
19960
+ if (record.shaded) record.shadedAt = kctx.state.frame;
19961
+ ok = ok && (record.shaded ? renderShade : renderStage3)(kctx, pixi, matrices, record, now);
19478
19962
  account(kctx, record);
19479
19963
  if (!ok && live) putFiltersBack(kctx, record, view);
19480
19964
  return ok;
@@ -19498,6 +19982,7 @@ function putFiltersBack(kctx, record, view) {
19498
19982
  * @param record - The record.
19499
19983
  */
19500
19984
  function goDirect(kctx, record) {
19985
+ leaveShade(record);
19501
19986
  if (record.s2Of !== void 0) releaseInputs(kctx, record);
19502
19987
  if (record.s3 !== void 0) {
19503
19988
  dropTexture(kctx, record.s3);
@@ -19578,6 +20063,35 @@ function scalable(record, stepped) {
19578
20063
  return taken > 0 && now > 0 && withinLimit;
19579
20064
  }
19580
20065
  /**
20066
+ * The quad of a kept record, drawing `output`: made once, the mesh of a shaded record reading its texture through its
20067
+ * shader (`Mesh.texture` does not reach it).
20068
+ *
20069
+ * @param pixi - The module that draws.
20070
+ * @param record - The record, kept.
20071
+ * @param output - What it draws.
20072
+ * @returns The quad.
20073
+ */
20074
+ function quadDrawing(pixi, record, output) {
20075
+ if (record.quad === void 0 || record.quad.destroyed) {
20076
+ record.quad = new pixi.Sprite(output);
20077
+ record.quad.label = `kept:${labelOf$4(record.top)}`;
20078
+ }
20079
+ if (!record.shaded && record.quad.texture !== output) record.quad.texture = output;
20080
+ return record.quad;
20081
+ }
20082
+ /**
20083
+ * Hangs a quad right above its top in the same parent.
20084
+ *
20085
+ * @param quad - The quad.
20086
+ * @param top - The top.
20087
+ * @param parent - The top's parent.
20088
+ */
20089
+ function hangQuad(quad, top, parent) {
20090
+ if (quad.parent === parent && parent.children[parent.getChildIndex(top) + 1] === quad) return;
20091
+ quad.removeFromParent();
20092
+ parent.addChildAt(quad, parent.getChildIndex(top) + 1);
20093
+ }
20094
+ /**
19581
20095
  * Places the quad of a kept record (P3.5, P2.4): beside its top in the same parent, at the top's depth, drawing the
19582
20096
  * filter output at its canvas place `O + Δ` with an identity world scale, or scaled to this frame's linear part when
19583
20097
  * it differs from the take's (F67); shown while the top is visible and no cover or alpha hides it. Every value is compared before it is written.
@@ -19593,17 +20107,9 @@ function placeQuad(sync, pixi, matrices, record, view) {
19593
20107
  const parent = top.parent;
19594
20108
  const output = (record.direct ? record.s1 : record.s3) ?? pixi.Texture.EMPTY;
19595
20109
  const alpha = (record.direct ? NOW.alpha : 1) * top.alpha;
19596
- if (record.quad === void 0 || record.quad.destroyed) {
19597
- record.quad = new pixi.Sprite(output);
19598
- record.quad.label = `kept:${labelOf$4(top)}`;
19599
- }
19600
- const quad = record.quad;
19601
- if (quad.texture !== output) quad.texture = output;
20110
+ const quad = quadDrawing(pixi, record, output);
19602
20111
  if (parent === null) return;
19603
- if (quad.parent !== parent || parent.children[parent.getChildIndex(top) + 1] !== quad) {
19604
- quad.removeFromParent();
19605
- parent.addChildAt(quad, parent.getChildIndex(top) + 1);
19606
- }
20112
+ hangQuad(quad, top, parent);
19607
20113
  if (quad.zIndex !== top.zIndex) quad.zIndex = top.zIndex;
19608
20114
  if (quad.blendMode !== top.blendMode) quad.blendMode = top.blendMode;
19609
20115
  if (quad.alpha !== alpha) quad.alpha = alpha;
@@ -19621,6 +20127,12 @@ function placeQuad(sync, pixi, matrices, record, view) {
19621
20127
  local.tx = inverse.a * x + inverse.c * y + inverse.tx;
19622
20128
  local.ty = inverse.b * x + inverse.d * y + inverse.ty;
19623
20129
  }
20130
+ if (record.shaded) {
20131
+ local.a *= output.width;
20132
+ local.b *= output.width;
20133
+ local.c *= output.height;
20134
+ local.d *= output.height;
20135
+ }
19624
20136
  if (storeMatrix(key, KEY.qa, local)) quad.setFromMatrix(local);
19625
20137
  const visible = top.visible && !sync.hiddenBy(view, "alpha") && !sync.hiddenBy(view, "cover");
19626
20138
  if (quad.visible !== visible) quad.visible = visible;
@@ -20101,13 +20613,29 @@ function stagesOwed(record, hold) {
20101
20613
  */
20102
20614
  function refresh$1(kctx, pixi, matrices, record, view, hold) {
20103
20615
  if (drawsDirect(NOW)) {
20104
- if (record.direct) return false;
20105
- goDirect(kctx, record);
20106
- account(kctx, record);
20616
+ turnDirect(kctx, record);
20107
20617
  return false;
20108
20618
  }
20109
- const owed = stagesOwed(record, hold);
20110
- if (owed === OWED.none) return false;
20619
+ return refreshOutput(kctx, pixi, matrices, record, view, hold);
20620
+ }
20621
+ /**
20622
+ * Redoes what a record that does not draw direct owes, on its mesh when it is shaded or goes on it now: a stack that
20623
+ * stopped fitting leaves and owes stage 3, one at rest may leave, and what is left is today's tail of stage 2 and 3.
20624
+ *
20625
+ * @param kctx - The kept context.
20626
+ * @param pixi - The module that draws.
20627
+ * @param matrices - The scratch matrices.
20628
+ * @param record - The record, kept.
20629
+ * @param view - Its view.
20630
+ * @param hold - A step of the resolution owes no stage.
20631
+ * @returns True when the record was taken whole.
20632
+ */
20633
+ function refreshOutput(kctx, pixi, matrices, record, view, hold) {
20634
+ const fits = shadeFits(kctx, record);
20635
+ const unfit = record.shaded && !fits;
20636
+ if (unfit) leaveShade(record);
20637
+ const owed = Math.max(stagesOwed(record, hold), unfit ? OWED.output : OWED.none);
20638
+ if (owed === OWED.none) return leaveAtRest(kctx, pixi, matrices, record, view, hold);
20111
20639
  const chain = owed === OWED.chain;
20112
20640
  const why = refreshWhy(record, chain, hold);
20113
20641
  if (hold && record.key[KEY.rs] !== NOW.rs) {
@@ -20116,6 +20644,10 @@ function refresh$1(kctx, pixi, matrices, record, view, hold) {
20116
20644
  }
20117
20645
  const inputs = firstInputs(record.slots)?.inputs;
20118
20646
  if (inputs === void 0 && record.s2Of !== void 0) releaseInputs(kctx, record);
20647
+ if (!unfit && enterShadeWhenDue(kctx, pixi, record, owed, fits)) {
20648
+ redrawShade(kctx, pixi, matrices, record);
20649
+ return false;
20650
+ }
20119
20651
  if (chain && inputs !== void 0) renderStage2(kctx, pixi, matrices, record, {
20120
20652
  inputs,
20121
20653
  resolution: NOW.r,
@@ -20129,6 +20661,96 @@ function refresh$1(kctx, pixi, matrices, record, view, hold) {
20129
20661
  return false;
20130
20662
  }
20131
20663
  /**
20664
+ * Lets a record that stayed kept draw its subtree picture itself, when it does not yet: a stack became all alphas.
20665
+ *
20666
+ * @param kctx - The kept context.
20667
+ * @param record - The record, kept.
20668
+ */
20669
+ function turnDirect(kctx, record) {
20670
+ if (record.direct) return;
20671
+ goDirect(kctx, record);
20672
+ account(kctx, record);
20673
+ }
20674
+ /**
20675
+ * A change of a shaded record: no take and no pass, unless the padded picture must be copied, and the mesh draws what
20676
+ * changed, so the pictures above it hold something else now.
20677
+ *
20678
+ * @param kctx - The kept context.
20679
+ * @param pixi - The module that draws.
20680
+ * @param matrices - The scratch matrices.
20681
+ * @param record - The record, shaded.
20682
+ */
20683
+ function redrawShade(kctx, pixi, matrices, record) {
20684
+ const { state } = kctx;
20685
+ const passes = state.flushPasses;
20686
+ renderShade(kctx, pixi, matrices, record, NOW);
20687
+ record.shadedAt = state.frame;
20688
+ record.redrawn = true;
20689
+ if (state.flushPasses !== passes) account(kctx, record);
20690
+ }
20691
+ /**
20692
+ * Counts an output owed by a record on its sprite, and puts the record on its mesh when it is due: stage 3 alone was owed
20693
+ * more than `QUAD_AFTER` times without a gap of `CALM_AFTER` frames, and it fits. The gap rule, not a reset on a quiet
20694
+ * frame: a tween that writes every second frame reaches the mode. A shaded record counts nothing.
20695
+ *
20696
+ * @param kctx - The kept context.
20697
+ * @param pixi - The module that draws.
20698
+ * @param record - The record, kept.
20699
+ * @param owed - What it owes, not none.
20700
+ * @param fits - It fits the mode.
20701
+ * @returns True when the mesh draws the change.
20702
+ */
20703
+ function enterShadeWhenDue(kctx, pixi, record, owed, fits) {
20704
+ if (record.shaded) return true;
20705
+ const { frame } = kctx.state;
20706
+ record.outputRuns = frame - record.outputAt > 8 ? 1 : record.outputRuns + 1;
20707
+ record.outputAt = frame;
20708
+ const quad = enabledSlot(record.slots)?.quad;
20709
+ const outputAlone = owed === OWED.output;
20710
+ const ranLong = record.outputRuns > 2;
20711
+ if (!outputAlone || !fits || !ranLong || quad === void 0) return false;
20712
+ return enterShade(kctx, pixi, record, quad, NOW);
20713
+ }
20714
+ /**
20715
+ * Tells whether a shaded record went `QUAD_CALM` drawn frames without a change: it is due to leave.
20716
+ *
20717
+ * @param state - The kept state.
20718
+ * @param record - The record.
20719
+ * @returns True when it is.
20720
+ */
20721
+ function shadedCalm(state, record) {
20722
+ return record.shaded && state.frame - record.shadedAt >= 30;
20723
+ }
20724
+ /**
20725
+ * A shaded record that owes nothing and stood `QUAD_CALM` frames goes back to its sprite (F126 stage 2): a resting mesh
20726
+ * runs the whole body every frame. Under `limitLeft`, shared with the refining and the settle, it stays shaded in a frame
20727
+ * the limit is spent. It counts as a refresh. The pixels do not change, so the pass marks nothing above; a stack whose
20728
+ * resolution moved under a held step is taken whole, as `refresh` takes it, and that does change them.
20729
+ *
20730
+ * @param kctx - The kept context.
20731
+ * @param pixi - The module that draws.
20732
+ * @param matrices - The scratch matrices.
20733
+ * @param record - The record, kept.
20734
+ * @param view - Its view.
20735
+ * @param hold - A step of the resolution owes no stage.
20736
+ * @returns True when the record was taken whole.
20737
+ */
20738
+ function leaveAtRest(kctx, pixi, matrices, record, view, hold) {
20739
+ const { state } = kctx;
20740
+ if (!shadedCalm(state, record) || !limitLeft(kctx)) return false;
20741
+ leaveShade(record);
20742
+ if (hold && record.key[KEY.rs] !== NOW.rs) {
20743
+ retakeOrGoLive(kctx, pixi, matrices, record, view, RETAKE.filter);
20744
+ return true;
20745
+ }
20746
+ noteTake(kctx, record, RETAKE.filter);
20747
+ renderStage3(kctx, pixi, matrices, record, NOW);
20748
+ account(kctx, record);
20749
+ state.refreshesOpen += 1;
20750
+ BEFORE.passes = state.flushPasses;
20751
+ return false;
20752
+ }
20753
+ /**
20132
20754
  * Tells whether a record's quad shows: visible and hanging in the tree.
20133
20755
  *
20134
20756
  * @param record - The record.
@@ -20161,7 +20783,7 @@ function noteDrawing(kctx, record, into) {
20161
20783
  * @returns True when the pictures above it hold something else now.
20162
20784
  */
20163
20785
  function drawingChanged(kctx, record, before) {
20164
- return before.mode !== record.mode || before.passes !== kctx.state.flushPasses || !Object.is(before.qtx, record.key[KEY.qtx]) || !Object.is(before.qty, record.key[KEY.qty]) || before.shown !== quadShown(record);
20786
+ return record.redrawn || before.mode !== record.mode || before.passes !== kctx.state.flushPasses || !Object.is(before.qtx, record.key[KEY.qtx]) || !Object.is(before.qty, record.key[KEY.qty]) || before.shown !== quadShown(record);
20165
20787
  }
20166
20788
  /**
20167
20789
  * Tells whether a kept record has anything to do in this frame: the frame is not calm, or a flag or a debt is on it.
@@ -20171,7 +20793,7 @@ function drawingChanged(kctx, record, before) {
20171
20793
  * @returns True when it is to be stepped.
20172
20794
  */
20173
20795
  function owesStep(state, record) {
20174
- return !state.calm || state.bypassed || record.mode !== "kept" || record.dirtyS1 || record.dirtyS2 || record.dirtyS3 || record.settle || record.coarse || record.churn !== 0;
20796
+ return !state.calm || state.bypassed || record.mode !== "kept" || record.dirtyS1 || record.dirtyS2 || record.dirtyS3 || record.settle || record.coarse || record.churn !== 0 || shadedCalm(state, record);
20175
20797
  }
20176
20798
  /**
20177
20799
  * The frame of a kept record in a calm frame (no mark, no whole-frame reason) that owes nothing: no dirty flag, no
@@ -20257,6 +20879,7 @@ function stepRecord(kctx, pixi, matrices, record, view) {
20257
20879
  record.dirtyS2 = false;
20258
20880
  record.dirtyS3 = false;
20259
20881
  record.refined = false;
20882
+ record.redrawn = false;
20260
20883
  record.markBy = 0;
20261
20884
  record.spared = false;
20262
20885
  if (record.alphaDue && record.mode !== "kept") record.alphaMissed = true;
@@ -20347,6 +20970,7 @@ function dirtyAbove(kctx, pixi, record) {
20347
20970
  above.markBy = record.entity;
20348
20971
  }
20349
20972
  }
20973
+ if (kctx.state.ranges.size === 0) return;
20350
20974
  for (const range of kctx.state.ranges.values()) if (rangeHolds$1(range.entries, record.top)) range.due = true;
20351
20975
  }
20352
20976
  /**
@@ -20584,13 +21208,19 @@ function lastTake(kctx, record) {
20584
21208
  */
20585
21209
  function recordEntry(kctx, record, view) {
20586
21210
  const retake = lastTake(kctx, record);
20587
- if (record.mode === "kept") return {
20588
- view,
20589
- mode: record.direct ? "direct" : "kept",
20590
- reason: null,
20591
- calmIn: 0,
20592
- retake
20593
- };
21211
+ if (record.mode === "kept") {
21212
+ const entry = {
21213
+ view,
21214
+ mode: record.direct ? "direct" : "kept",
21215
+ reason: null,
21216
+ calmIn: 0,
21217
+ retake
21218
+ };
21219
+ return record.shaded ? {
21220
+ ...entry,
21221
+ quad: true
21222
+ } : entry;
21223
+ }
20594
21224
  const why = record.why === 0 ? WHY.waiting : record.why;
20595
21225
  return {
20596
21226
  view,
@@ -20952,6 +21582,7 @@ function createKeptApi(ctx, deps) {
20952
21582
  state.spare = void 0;
20953
21583
  }
20954
21584
  emptyPool$1(kctx);
21585
+ dropQuadParts(state);
20955
21586
  state.bytes = 0;
20956
21587
  state.poolBytes = 0;
20957
21588
  state.drawnPictures = 0;
@@ -27134,8 +27765,10 @@ function renderPassesOf(state, kept) {
27134
27765
  * filter of its render, so the warm-up never opens a second level of Pixi's filter stack (Pixi 8.21 reads the stale
27135
27766
  * input texture of that level at its next push, and a pool trim destroys it in between). A probe whose render throws
27136
27767
  * ends the warm-up of the application: a throw inside Pixi's render leaves its filter stack unbalanced, which no public
27137
- * API rebalances, so another probe would only throw again. The end of a run reaches the monitor through `onWarm`; this
27138
- * file never imports the monitor (LEAD-FIXES-3 O24).
27768
+ * API rebalances, so another probe would only throw again. A filter handed over with its quad draws a mesh of that
27769
+ * program after it, on WebGPU, inside an error scope: a quad program that does not fit its pipeline fails asynchronously,
27770
+ * as a blank view with nothing in the logs, and this is the one place such a fault can be seen. The end of a run
27771
+ * reaches the monitor through `onWarm`; this file never imports the monitor (LEAD-FIXES-3 O24).
27139
27772
  */
27140
27773
  /** The side of every probe, in CSS pixels: the smallest thing that still draws a triangle. */
27141
27774
  const PROBE_SIZE = 4;
@@ -27265,10 +27898,41 @@ function buildObjects(pixi) {
27265
27898
  graphics,
27266
27899
  particlesNormal: particlesOf(pixi, "normal"),
27267
27900
  particlesAdd: particlesOf(pixi, "add"),
27268
- text: void 0
27901
+ text: void 0,
27902
+ quad: void 0
27269
27903
  };
27270
27904
  }
27271
27905
  /**
27906
+ * The mesh of the quad subjects, made at their first draw: a trimmed Pixi that draws no quad has no need of its classes.
27907
+ *
27908
+ * @param pixi - The module that draws.
27909
+ * @returns The mesh, its geometry and the uniforms its probes bind.
27910
+ */
27911
+ function quadMesh(pixi) {
27912
+ const geometry = unitQuad(pixi);
27913
+ const mesh = new pixi.Mesh({ geometry });
27914
+ mesh.label = "renderer.warm.quad";
27915
+ mesh.scale.set(PROBE_SIZE);
27916
+ return {
27917
+ mesh,
27918
+ geometry,
27919
+ gfu: filterGlobals(pixi).group,
27920
+ shader: void 0
27921
+ };
27922
+ }
27923
+ /**
27924
+ * Frees the mesh of the quad subjects: the probes' uniform buffer by hand, as the kept cache frees a view's.
27925
+ *
27926
+ * @param probe - The mesh, when a quad was drawn on this device.
27927
+ */
27928
+ function dropQuadMesh(probe) {
27929
+ if (probe === void 0) return;
27930
+ probe.shader?.destroy();
27931
+ probe.gfu.buffer?.destroy();
27932
+ probe.mesh.destroy();
27933
+ probe.geometry.destroy(true);
27934
+ }
27935
+ /**
27272
27936
  * Destroys the probe tree of a device that went or of a renderer that stops: the module's own texture and mask
27273
27937
  * included, never a filter it was handed.
27274
27938
  *
@@ -27280,6 +27944,7 @@ function dropObjects(warm) {
27280
27944
  warm.objects = void 0;
27281
27945
  clearFilters(objects.holder);
27282
27946
  objects.list.length = 0;
27947
+ dropQuadMesh(objects.quad);
27283
27948
  const nodes = [
27284
27949
  objects.root,
27285
27950
  objects.clipFrame,
@@ -27337,6 +28002,27 @@ function enqueue$1(warm, subject, variants) {
27337
28002
  });
27338
28003
  }
27339
28004
  /**
28005
+ * Queues the draws of a filter, then the one draw of its quad. A quad program is a WebGPU program: WebGL draws the
28006
+ * filter alone.
28007
+ *
28008
+ * @param sctx - Domain context of the sync module.
28009
+ * @param filter - The filter.
28010
+ * @param variants - The variants of this device.
28011
+ * @returns The draws queued.
28012
+ */
28013
+ function enqueueFilter(sctx, filter, variants) {
28014
+ const { warm } = sctx.ctx.state.sync;
28015
+ const quad = warm.quads.get(filter);
28016
+ enqueue$1(warm, filter, variants);
28017
+ if (quad === void 0 || sctx.deps.host.kind() !== "webgpu") return variants.length;
28018
+ const once = variants.slice(0, 1);
28019
+ enqueue$1(warm, {
28020
+ filter,
28021
+ quad
28022
+ }, once);
28023
+ return variants.length + once.length;
28024
+ }
28025
+ /**
27340
28026
  * Tells whether the renderer can warm anything now: the config asks for draws, a device draws, and no probe threw on
27341
28027
  * this application.
27342
28028
  *
@@ -27357,6 +28043,7 @@ function canWarm(sctx) {
27357
28043
  function abandon(warm) {
27358
28044
  for (const [filter, entry] of warm.waiting) {
27359
28045
  warm.filters.delete(filter);
28046
+ warm.quads.delete(filter);
27360
28047
  for (const resolve of entry.resolve) resolve(false);
27361
28048
  }
27362
28049
  warm.waiting.clear();
@@ -27391,13 +28078,13 @@ function startWarm$2(sctx) {
27391
28078
  enqueue$1(warm, "text", variants);
27392
28079
  }
27393
28080
  for (const filter of warm.filters) {
28081
+ const left = enqueueFilter(sctx, filter, variants);
27394
28082
  const entry = warm.waiting.get(filter);
27395
28083
  if (entry === void 0) warm.waiting.set(filter, {
27396
- left: variants.length,
28084
+ left,
27397
28085
  resolve: []
27398
28086
  });
27399
- else entry.left = variants.length;
27400
- enqueue$1(warm, filter, variants);
28087
+ else entry.left = left;
27401
28088
  }
27402
28089
  sctx.deps.demand.request();
27403
28090
  }
@@ -27429,9 +28116,10 @@ function queueText(sctx, key) {
27429
28116
  *
27430
28117
  * @param sctx - Domain context of the sync module.
27431
28118
  * @param filter - A filter the caller keeps alive while it waits.
28119
+ * @param quad - Its body on a quad, drawn after it.
27432
28120
  * @returns Whether the filter's pipelines were created.
27433
28121
  */
27434
- function warmFilter(sctx, filter) {
28122
+ function warmFilter(sctx, filter, quad) {
27435
28123
  const { warm } = sctx.ctx.state.sync;
27436
28124
  if (!canWarm(sctx)) return Promise.resolve(false);
27437
28125
  const waiting = warm.waiting.get(filter);
@@ -27441,11 +28129,10 @@ function warmFilter(sctx, filter) {
27441
28129
  resolve: []
27442
28130
  };
27443
28131
  if (waiting === void 0) {
27444
- const variants = variantsOf(sctx);
27445
- entry.left = variants.length;
27446
28132
  warm.filters.add(filter);
28133
+ if (quad !== void 0) warm.quads.set(filter, quad);
28134
+ entry.left = enqueueFilter(sctx, filter, variantsOf(sctx));
27447
28135
  warm.waiting.set(filter, entry);
27448
- enqueue$1(warm, filter, variants);
27449
28136
  sctx.deps.demand.request();
27450
28137
  }
27451
28138
  return new Promise((resolve) => {
@@ -27453,8 +28140,56 @@ function warmFilter(sctx, filter) {
27453
28140
  });
27454
28141
  }
27455
28142
  /**
27456
- * The node one subject hangs from: a content object, or the holder with the draw's filter on it. The text is made at
27457
- * its first draw, in the font of the warm-up.
28143
+ * Tells a filter's quad from every other subject.
28144
+ *
28145
+ * @param subject - The subject.
28146
+ * @returns True for a quad.
28147
+ */
28148
+ function isQuadSubject(subject) {
28149
+ return typeof subject !== "string" && "quad" in subject;
28150
+ }
28151
+ /**
28152
+ * The filter a subject that is no name belongs to.
28153
+ *
28154
+ * @param subject - A filter, or its quad.
28155
+ * @returns The filter.
28156
+ */
28157
+ function filterOf(subject) {
28158
+ return isQuadSubject(subject) ? subject.filter : subject;
28159
+ }
28160
+ /**
28161
+ * The mesh of a quad subject, with a shader of this program over Pixi's white texture: the pipeline is what the probe
28162
+ * is for, and a pipeline is keyed by the layout.
28163
+ *
28164
+ * @param pixi - The module that draws.
28165
+ * @param objects - The probe tree.
28166
+ * @param subject - The quad.
28167
+ * @returns The mesh.
28168
+ */
28169
+ function quadNode(pixi, objects, subject) {
28170
+ const probe = objects.quad ?? quadMesh(pixi);
28171
+ objects.quad = probe;
28172
+ probe.shader = quadShader(pixi, subject.quad, probe.gfu, pixi.Texture.WHITE.source);
28173
+ probe.mesh.shader = probe.shader;
28174
+ return probe.mesh;
28175
+ }
28176
+ /**
28177
+ * The node of a filter or a quad: the holder with the draw's filter on it, or the mesh of the quad.
28178
+ *
28179
+ * @param pixi - The module that draws.
28180
+ * @param objects - The probe tree.
28181
+ * @param subject - The filter or the quad.
28182
+ * @returns The node.
28183
+ */
28184
+ function filterNode(pixi, objects, subject) {
28185
+ if (isQuadSubject(subject)) return quadNode(pixi, objects, subject);
28186
+ objects.list[0] = subject;
28187
+ objects.holder.filters = objects.list;
28188
+ return objects.holder;
28189
+ }
28190
+ /**
28191
+ * The node one subject hangs from: a content object, the holder with the draw's filter on it, or the mesh of a quad. The
28192
+ * text is made at its first draw, in the font of the warm-up.
27458
28193
  *
27459
28194
  * @param pixi - The module that draws.
27460
28195
  * @param warm - The warm branch of the sync state.
@@ -27463,11 +28198,7 @@ function warmFilter(sctx, filter) {
27463
28198
  * @returns The node, or `undefined` for the text without a font.
27464
28199
  */
27465
28200
  function nodeOf$1(pixi, warm, objects, subject) {
27466
- if (typeof subject !== "string") {
27467
- objects.list[0] = subject;
27468
- objects.holder.filters = objects.list;
27469
- return objects.holder;
27470
- }
28201
+ if (typeof subject !== "string") return filterNode(pixi, objects, subject);
27471
28202
  if (subject !== "text") return objects[FIXED_NODES[subject]];
27472
28203
  if (warm.textFont === void 0) return void 0;
27473
28204
  objects.text ??= new pixi.BitmapText({
@@ -27512,12 +28243,65 @@ function failWarm(sctx, draw, error) {
27512
28243
  error
27513
28244
  } : {
27514
28245
  subject: "filter",
27515
- filter: filterName(subject),
28246
+ filter: filterName(filterOf(subject)),
27516
28247
  variant,
27517
28248
  error
27518
28249
  });
27519
28250
  }
27520
28251
  /**
28252
+ * What a scope of a device lost meanwhile answers: nothing to report, its restore warms everything again.
28253
+ */
28254
+ function scopeLost() {}
28255
+ /**
28256
+ * Opens the error scope of a quad's draw.
28257
+ *
28258
+ * @param sctx - Domain context of the sync module.
28259
+ * @param subject - The subject of the draw.
28260
+ * @returns The device whose scope is open, `undefined` for any other subject or with no device.
28261
+ */
28262
+ function openScope(sctx, subject) {
28263
+ if (!isQuadSubject(subject)) return void 0;
28264
+ const device = sctx.deps.host.device();
28265
+ device?.pushErrorScope("validation");
28266
+ return device;
28267
+ }
28268
+ /**
28269
+ * Closes the error scope of a quad's draw, and logs what it caught with the program's name. The warm-up goes on: the
28270
+ * draw failed, not Pixi's filter stack, and the views of that kind fall back on a blank mesh only in that kind.
28271
+ *
28272
+ * @param sctx - Domain context of the sync module.
28273
+ * @param device - The device of the scope.
28274
+ * @param subject - The subject of the draw.
28275
+ */
28276
+ function closeScope(sctx, device, subject) {
28277
+ const program = isQuadSubject(subject) ? subject.quad.program.name : "";
28278
+ device.popErrorScope().then((error) => {
28279
+ if (error !== null) sctx.ctx.log.error("renderer:warm-invalid", {
28280
+ program,
28281
+ message: error.message
28282
+ });
28283
+ }).catch(scopeLost);
28284
+ }
28285
+ /**
28286
+ * Takes a subject out of the probe tree after its render, thrown or not: the tree holds it only during its own render.
28287
+ * A filter comes off the holder, and a quad's shader goes: it was made for this draw.
28288
+ *
28289
+ * @param objects - The probe tree.
28290
+ * @param node - The node the subject hung from.
28291
+ */
28292
+ function takeDown$1(objects, node) {
28293
+ node.removeFromParent();
28294
+ objects.clipFrame.removeFromParent();
28295
+ if (node === objects.holder) {
28296
+ clearFilters(objects.holder);
28297
+ objects.list.length = 0;
28298
+ }
28299
+ if (node === objects.quad?.mesh) {
28300
+ objects.quad.shader?.destroy();
28301
+ objects.quad.shader = void 0;
28302
+ }
28303
+ }
28304
+ /**
27521
28305
  * Draws one probe: hangs the subject in its variant under the root, renders the root onto the canvas or, for a texture
27522
28306
  * variant, into the module's texture, and takes it all down again, so the tree holds the subject only during its own
27523
28307
  * render. A render that throws ends the warm-up of the application (`failWarm`).
@@ -27538,6 +28322,7 @@ function drawProbe(sctx, pixi, objects, draw) {
27538
28322
  objects.clip.addChild(node);
27539
28323
  objects.root.addChild(objects.clipFrame);
27540
28324
  } else objects.root.addChild(node);
28325
+ const scope = openScope(sctx, draw.subject);
27541
28326
  try {
27542
28327
  sctx.deps.host.renderProbe(objects.root, textured ? objects.target : void 0);
27543
28328
  return true;
@@ -27545,12 +28330,8 @@ function drawProbe(sctx, pixi, objects, draw) {
27545
28330
  failWarm(sctx, draw, error);
27546
28331
  return false;
27547
28332
  } finally {
27548
- node.removeFromParent();
27549
- objects.clipFrame.removeFromParent();
27550
- if (node === objects.holder) {
27551
- clearFilters(objects.holder);
27552
- objects.list.length = 0;
27553
- }
28333
+ if (scope !== void 0) closeScope(sctx, scope, draw.subject);
28334
+ takeDown$1(objects, node);
27554
28335
  }
27555
28336
  }
27556
28337
  /**
@@ -27626,7 +28407,7 @@ function warmStep(sctx) {
27626
28407
  if (draw === void 0) continue;
27627
28408
  drawn += 1;
27628
28409
  if (!drawProbe(sctx, pixi, objects, draw)) return true;
27629
- if (typeof draw.subject !== "string") drawnOnce(warm, draw.subject);
28410
+ if (typeof draw.subject !== "string") drawnOnce(warm, filterOf(draw.subject));
27630
28411
  }
27631
28412
  warm.draws += drawn;
27632
28413
  if (warm.head < warm.queue.length) sctx.deps.demand.request();
@@ -27644,6 +28425,7 @@ function stopWarm(state) {
27644
28425
  for (const entry of warm.waiting.values()) for (const resolve of entry.resolve) resolve(false);
27645
28426
  warm.waiting.clear();
27646
28427
  warm.filters.clear();
28428
+ warm.quads.clear();
27647
28429
  dropObjects(warm);
27648
28430
  warm.queue.length = 0;
27649
28431
  warm.head = 0;
@@ -34981,7 +35763,7 @@ function createSyncApi(ctx, deps) {
34981
35763
  filters: {
34982
35764
  set: (entity, slots) => setFilters(state, entity, slots, deps.demand.mark, deps.kept),
34983
35765
  area: (entity, area) => setArea(sctx, entity, area),
34984
- warm: (filter) => warmFilter(sctx, filter)
35766
+ warm: (filter, quad) => warmFilter(sctx, filter, quad)
34985
35767
  },
34986
35768
  leave: {
34987
35769
  show: (look) => showLeave(sctx, look),
@@ -35784,6 +36566,7 @@ function createWarmState() {
35784
36566
  queue: [],
35785
36567
  head: 0,
35786
36568
  filters: emptySet$4(),
36569
+ quads: emptyMap$6(),
35787
36570
  waiting: emptyMap$6(),
35788
36571
  textQueued: false,
35789
36572
  textFont: void 0,
@@ -45921,16 +46704,16 @@ fn mainVertex(@location(0) aPosition: vec2<f32>) -> VSOutput {
45921
46704
  * resource key of the instance is `fu` too. Nothing without uniforms.
45922
46705
  *
45923
46706
  * @param uniforms - The uniforms in declaration order.
46707
+ * @param group - The bind group of `fu`: 1 in a filter's source, 3 in a quad program's.
45924
46708
  * @returns The WGSL lines, or `""`.
45925
46709
  * @example
45926
46710
  * ```ts
45927
46711
  * uniformStruct([{ name: "amount", type: "f32", form: "number", size: 1 }]); // "struct FilterUniforms {\n amount: f32,\n};\n\n@group(1) @binding(0) var<uniform> fu: FilterUniforms;\n"
45928
46712
  * ```
45929
46713
  */
45930
- function uniformStruct(uniforms) {
46714
+ function uniformStruct(uniforms, group = 1) {
45931
46715
  if (uniforms.length === 0) return "";
45932
- return `struct FilterUniforms {\n${uniforms.map((uniform) => ` ${uniform.name}: ${uniform.type},\n`).join("")}};\n\n@group(1) @binding(0) var<uniform> fu: FilterUniforms;
45933
- `;
46716
+ return `struct FilterUniforms {\n${uniforms.map((uniform) => ` ${uniform.name}: ${uniform.type},\n`).join("")}};\n\n@group(${group}) @binding(0) var<uniform> fu: FilterUniforms;\n`;
45934
46717
  }
45935
46718
  /**
45936
46719
  * The engine's half of each input: the texture and the sampler in `@group(1)` after `fu`, and the function that
@@ -45940,7 +46723,9 @@ function uniformStruct(uniforms) {
45940
46723
  * @returns The WGSL lines, or `""`.
45941
46724
  * @example
45942
46725
  * ```ts
45943
- * inputBindings([blurInput]).includes("fn sampleBlur(uv: vec2<f32>) -> vec4<f32>"); // true
46726
+ * const soft = { name: "soft", from: "input", texture: "uSoft", sampler: "uSoftSampler", sample: "sampleSoft", scale: { name: "softScale", type: "f32", form: "number", size: 1 }, clamp: { name: "softClamp", type: "vec4<f32>", form: "vector", size: 4 }, stages: [], chain: () => [] } as const;
46727
+ *
46728
+ * inputBindings([soft]).includes("fn sampleSoft(uv: vec2<f32>) -> vec4<f32>"); // true
45944
46729
  * ```
45945
46730
  */
45946
46731
  function inputBindings(inputs) {
@@ -46001,7 +46786,7 @@ fn sampleBack(uv: vec2<f32>) -> vec4<f32> {
46001
46786
  * @returns The WGSL source both stages are built from.
46002
46787
  * @example
46003
46788
  * ```ts
46004
- * assemble([], [], body, undefined, true).includes("fn sampleBack(uv: vec2<f32>) -> vec4<f32>"); // true
46789
+ * assemble([], [], "", undefined, true).includes("fn sampleBack(uv: vec2<f32>) -> vec4<f32>"); // true
46005
46790
  * ```
46006
46791
  */
46007
46792
  function assemble(uniforms, inputs, body, origin, backdrop = false) {
@@ -46015,6 +46800,113 @@ function assemble(uniforms, inputs, body, origin, backdrop = false) {
46015
46800
  const helper = origin === void 0 ? "" : CANVAS_PIXEL;
46016
46801
  return `${HEADER}${struct}${inputBindings(inputs)}${back}${helper}${body}`;
46017
46802
  }
46803
+ /**
46804
+ * The head of a quad program. Pixi fills groups 0 and 1 by the names `globalUniforms` and `localUniforms`
46805
+ * (`GpuProgram.mjs:34-35`, `GpuMeshAdapter.mjs:44-50`), so the filter's bindings of `HEADER` move to group 2 and the
46806
+ * vertex stage becomes the mesh's. A literal, like `HEADER`: a game without `effectsPlugin` carries neither.
46807
+ */
46808
+ const QUAD_HEADER = `struct GlobalFilterUniforms {
46809
+ uInputSize: vec4<f32>,
46810
+ uInputPixel: vec4<f32>,
46811
+ uInputClamp: vec4<f32>,
46812
+ uOutputFrame: vec4<f32>,
46813
+ uGlobalFrame: vec4<f32>,
46814
+ uOutputTexture: vec4<f32>,
46815
+ };
46816
+
46817
+ @group(2) @binding(0) var<uniform> gfu: GlobalFilterUniforms;
46818
+ @group(2) @binding(1) var uTexture: texture_2d<f32>;
46819
+ @group(2) @binding(2) var uSampler: sampler;
46820
+
46821
+ struct VSOutput {
46822
+ @builtin(position) position: vec4<f32>,
46823
+ @location(0) uv: vec2<f32>,
46824
+ };
46825
+
46826
+ struct GlobalUniforms {
46827
+ uProjectionMatrix: mat3x3<f32>,
46828
+ uWorldTransformMatrix: mat3x3<f32>,
46829
+ uWorldColorAlpha: vec4<f32>,
46830
+ uResolution: vec2<f32>,
46831
+ };
46832
+ struct LocalUniforms { uTransformMatrix: mat3x3<f32>, uColor: vec4<f32>, uRound: f32 };
46833
+ @group(0) @binding(0) var<uniform> globalUniforms: GlobalUniforms;
46834
+ @group(1) @binding(0) var<uniform> localUniforms: LocalUniforms;
46835
+
46836
+ @vertex
46837
+ fn mainVertex(@location(0) aPosition: vec2<f32>, @location(1) aUV: vec2<f32>) -> VSOutput {
46838
+ let mvp = globalUniforms.uProjectionMatrix * globalUniforms.uWorldTransformMatrix * localUniforms.uTransformMatrix;
46839
+ let clip = mvp * vec3<f32>(aPosition, 1.0);
46840
+
46841
+ return VSOutput(vec4<f32>(clip.xy, 0.0, 1.0), aUV);
46842
+ }
46843
+
46844
+ `;
46845
+ /**
46846
+ * The entry point of a quad program: the body times what Pixi's own mesh shader multiplies by
46847
+ * (`defaultProgramTemplate.mjs:42`), `uColor` premultiplied, so the view's alpha and tint reach the mesh.
46848
+ */
46849
+ const QUAD_TAIL = `
46850
+
46851
+ @fragment
46852
+ fn mainFragment(@location(0) uv: vec2<f32>) -> @location(0) vec4<f32> {
46853
+ return filterBody(uv) * localUniforms.uColor * globalUniforms.uWorldColorAlpha;
46854
+ }
46855
+ `;
46856
+ /** A line comment or a block comment of WGSL. */
46857
+ const COMMENT$1 = /\/\/[^\n]*|\/\*[\s\S]*?\*\//g;
46858
+ /** What the rewrite looks at: a comment, which it leaves alone, or the head of an entry point up to its opening brace. */
46859
+ const QUAD_WALK = /\/\/[^\n]*|\/\*[\s\S]*?\*\/|@fragment\s[^{]*[^{\s]/g;
46860
+ /** The one head the rewrite fits, without its whitespace: its group names the `uv`. */
46861
+ const PLAIN_HEAD = /^@fragmentfnmainFragment\(@location\(0\)(\w+):vec2<f32>\)->@location\(0\)vec4<f32>$/;
46862
+ /** Whitespace, which a head may hold anywhere the plain one has a space, a newline or nothing. */
46863
+ const SPACE = /\s/g;
46864
+ /** What a body cannot carry onto the mesh: a builtin the wrapper does not pass, a name the quad program declares. */
46865
+ const QUAD_REFUSED = /@builtin\s*\(|\b(?:filterBody|[Gg]lobalUniforms|[Ll]ocalUniforms)\b/;
46866
+ /**
46867
+ * A fragment body as a function the wrapper calls: the plain signature found once outside a comment, rewritten to
46868
+ * `filterBody`, the rest of the text as it is. Whitespace and newlines of the signature may vary. A body read outside
46869
+ * its comments that takes a `@builtin` or declares a name of the quad program stays out.
46870
+ *
46871
+ * @param wgsl - The fragment body the game wrote.
46872
+ * @returns The rewritten body, or `undefined` when the rewrite does not fit.
46873
+ * @example
46874
+ * ```ts
46875
+ * quadBody("@fragment fn mainFragment(@location(0) uv: vec2<f32>) -> @location(0) vec4<f32> { return vec4<f32>(uv, 0.0, 1.0); }"); // "fn filterBody(uv: vec2<f32>) -> vec4<f32> { return vec4<f32>(uv, 0.0, 1.0); }"
46876
+ * ```
46877
+ */
46878
+ function quadBody(wgsl) {
46879
+ let found = 0;
46880
+ const rewritten = wgsl.replaceAll(QUAD_WALK, (head) => {
46881
+ const name = PLAIN_HEAD.exec(head.replaceAll(SPACE, ""))?.[1];
46882
+ if (name === void 0) return head;
46883
+ found += 1;
46884
+ return `fn filterBody(${name}: vec2<f32>) -> vec4<f32>`;
46885
+ });
46886
+ return found === 1 && !QUAD_REFUSED.test(wgsl.replaceAll(COMMENT$1, "")) ? rewritten : void 0;
46887
+ }
46888
+ /**
46889
+ * The quad program of a filter: the head of the mesh, the uniform struct at group 3 (the uniforms, then the engine's
46890
+ * `keptOrigin` of a body that calls `canvasPixel`, as `assemble` lists them, so the struct matches the instance's group
46891
+ * member for member: a shader that asks for more than the group holds fails only as an asynchronous GPU validation
46892
+ * error, a blank view with nothing in the logs), the `canvasPixel` helper, the body as `filterBody`, the entry point.
46893
+ *
46894
+ * @param uniforms - The uniforms in declaration order.
46895
+ * @param body - The fragment body the game wrote.
46896
+ * @param origin - The `keptOrigin` uniform, for a body that calls `canvasPixel`.
46897
+ * @returns The WGSL source of both stages, or `undefined` for a body the rewrite does not fit.
46898
+ * @example
46899
+ * ```ts
46900
+ * assembleQuad([], "@fragment fn mainFragment(@location(0) uv: vec2<f32>) -> @location(0) vec4<f32> { return vec4<f32>(uv, 0.0, 1.0); }")?.includes("fn filterBody(uv: vec2<f32>) -> vec4<f32>"); // true
46901
+ * assembleQuad([], "@fragment fn mainFragment(@builtin(position) at: vec4<f32>) -> @location(0) vec4<f32> { return at; }"); // undefined
46902
+ * ```
46903
+ */
46904
+ function assembleQuad(uniforms, body, origin) {
46905
+ const rewritten = quadBody(body);
46906
+ if (rewritten === void 0) return void 0;
46907
+ const struct = uniformStruct(origin === void 0 ? uniforms : [...uniforms, origin], 3);
46908
+ return `${QUAD_HEADER}${struct}${origin === void 0 ? "" : CANVAS_PIXEL}${rewritten}${QUAD_TAIL}`;
46909
+ }
46018
46910
  //#endregion
46019
46911
  //#region src/plugins/effects/filters/glsl.ts
46020
46912
  /**
@@ -46693,6 +47585,7 @@ function defineFilter(id, spec) {
46693
47585
  id,
46694
47586
  source: assemble(uniforms, inputs, spec.wgsl, origin, backdrop),
46695
47587
  glsl: assembleGlsl(uniforms, inputs, spec.glsl, origin, backdrop),
47588
+ quadSource: inputs.length === 0 && !backdrop ? assembleQuad(uniforms, spec.wgsl, origin) : void 0,
46696
47589
  uniforms,
46697
47590
  passes,
46698
47591
  padding,
@@ -47382,10 +48275,41 @@ function createOurs(pixi, definition, value) {
47382
48275
  height: 0,
47383
48276
  some: false
47384
48277
  },
47385
- areaStale: false
48278
+ areaStale: false,
48279
+ quad: void 0
47386
48280
  };
47387
48281
  }
47388
48282
  /**
48283
+ * The program a definition's body runs on a kept view's quad, once its quad text compiled clean on this run's device.
48284
+ * Built at the first ask and looked up after that: `GpuProgram.from` builds a key of the whole source on every call,
48285
+ * and this is asked for every instance and at every sync of a changed view.
48286
+ *
48287
+ * @param ectx - Domain context of the effects plugin.
48288
+ * @param pixi - The module the renderer loaded.
48289
+ * @param definition - The filter definition.
48290
+ * @returns The shared program, or `undefined` for a definition with no usable quad.
48291
+ */
48292
+ function quadProgramOf(ectx, pixi, definition) {
48293
+ const { quadSource: source } = definition;
48294
+ const { quads, programs } = ectx.state.checks;
48295
+ if (source === void 0 || !quads.has(definition)) return void 0;
48296
+ const held = programs.get(definition);
48297
+ if (held !== void 0) return held;
48298
+ const program = pixi.GpuProgram.from({
48299
+ name: `${definition.id}.quad`,
48300
+ vertex: {
48301
+ source,
48302
+ entryPoint: "mainVertex"
48303
+ },
48304
+ fragment: {
48305
+ source,
48306
+ entryPoint: "mainFragment"
48307
+ }
48308
+ });
48309
+ programs.set(definition, program);
48310
+ return program;
48311
+ }
48312
+ /**
47389
48313
  * The quality a `Blur` draws at: its own, or `config.blur.quality` for 0.
47390
48314
  *
47391
48315
  * @param ectx - Domain context of the effects plugin.
@@ -48289,12 +49213,17 @@ function createStandIn(ectx, pixi, kind, value) {
48289
49213
  *
48290
49214
  * @param pixi - The module the renderer loaded.
48291
49215
  * @param definition - A definition whose check answered ok.
48292
- * @returns The probe's filter and its teardown.
49216
+ * @param program - The quad program of a kind that hands one over, drawn with the probe's own uniform group.
49217
+ * @returns The probe's filter, its quad and its teardown.
48293
49218
  */
48294
- function createWarmFilter(pixi, definition) {
49219
+ function createWarmFilter(pixi, definition, program) {
48295
49220
  const body = createOurs(pixi, definition, PROBE_VALUE);
48296
49221
  return {
48297
49222
  filter: body.filter,
49223
+ quad: program === void 0 ? void 0 : {
49224
+ program,
49225
+ fu: body.group
49226
+ },
48298
49227
  destroy: () => destroyBody(body)
48299
49228
  };
48300
49229
  }
@@ -48788,6 +49717,18 @@ function checkList(ectx) {
48788
49717
  return list;
48789
49718
  }
48790
49719
  /**
49720
+ * The definitions the registered kinds draw as themselves: a stage or a fallback never runs on a quad, unless it is a
49721
+ * kind too.
49722
+ *
49723
+ * @param ectx - Domain context of the effects plugin.
49724
+ * @returns The main body of every kind of ours.
49725
+ */
49726
+ function kindBodies(ectx) {
49727
+ const bodies = /* @__PURE__ */ new Set();
49728
+ for (const kind of ectx.state.kinds.values()) if (kind.source === "wgsl") bodies.add(kind.definition);
49729
+ return bodies;
49730
+ }
49731
+ /**
48791
49732
  * Logs the line of a fallback that fails its own check, once: no kind can draw it in place of its own.
48792
49733
  *
48793
49734
  * @param ectx - Domain context of the effects plugin.
@@ -48834,15 +49775,57 @@ function finish(ectx, run, definition, passed) {
48834
49775
  if (checks.started && checks.waiting === 0) complete(ectx);
48835
49776
  }
48836
49777
  /**
48837
- * Takes the WGSL compilation messages of one definition: every error is one log line, and one error breaks it. An
48838
- * answer of an earlier run is ignored.
49778
+ * Takes the compilation messages of a quad program: clean, the definition's quad is usable; an error is one log line,
49779
+ * however many the compiler found, and costs the quad only. Either way the definition answers ok: its body compiled.
49780
+ * An answer of an earlier run is ignored.
49781
+ *
49782
+ * @param ectx - Domain context of the effects plugin.
49783
+ * @param run - The run the check was started in.
49784
+ * @param definition - The definition.
49785
+ * @param messages - What the compiler said.
49786
+ */
49787
+ function settleQuad(ectx, run, definition, messages) {
49788
+ const { checks } = ectx.state;
49789
+ if (checks.run !== run || checks.status.get(definition) !== "pending") return;
49790
+ const error = messages.find((message) => message.type === "error");
49791
+ if (error === void 0) checks.quads.add(definition);
49792
+ else ectx.log.error("effects:wgsl", {
49793
+ filter: definition.id,
49794
+ quad: true,
49795
+ line: error.lineNum,
49796
+ column: error.linePos,
49797
+ message: error.message
49798
+ });
49799
+ finish(ectx, run, definition, true);
49800
+ }
49801
+ /**
49802
+ * Starts the compile of a definition's quad program, after its body compiled clean. With no device (lost since), or
49803
+ * info it cannot read, the definition is ok without a quad: an unchecked text never reaches the GPU.
49804
+ *
49805
+ * @param ectx - Domain context of the effects plugin.
49806
+ * @param run - The current run.
49807
+ * @param definition - The definition.
49808
+ * @param source - Its quad program.
49809
+ */
49810
+ function checkQuad(ectx, run, definition, source) {
49811
+ const device = ectx.deps.renderer.host.device();
49812
+ if (device === void 0) {
49813
+ finish(ectx, run, definition, true);
49814
+ return;
49815
+ }
49816
+ device.createShaderModule({ code: source }).getCompilationInfo().then((info) => settleQuad(ectx, run, definition, info.messages), () => finish(ectx, run, definition, true));
49817
+ }
49818
+ /**
49819
+ * Takes the WGSL compilation messages of one definition: every error is one log line, and one error breaks it. A body
49820
+ * that compiled goes on to its quad program, if it has one to check. An answer of an earlier run is ignored.
48839
49821
  *
48840
49822
  * @param ectx - Domain context of the effects plugin.
48841
49823
  * @param run - The run the check was started in.
48842
49824
  * @param definition - The definition.
48843
49825
  * @param messages - What the compiler said.
49826
+ * @param quad - The quad program to check after the body; `undefined` for none.
48844
49827
  */
48845
- function settle$1(ectx, run, definition, messages) {
49828
+ function settle$1(ectx, run, definition, messages, quad) {
48846
49829
  const { checks } = ectx.state;
48847
49830
  if (checks.run !== run || checks.status.get(definition) !== "pending") return;
48848
49831
  const errors = messages.filter((message) => message.type === "error");
@@ -48852,23 +49835,26 @@ function settle$1(ectx, run, definition, messages) {
48852
49835
  column: error.linePos,
48853
49836
  message: error.message
48854
49837
  });
48855
- finish(ectx, run, definition, errors.length === 0);
49838
+ if (errors.length === 0 && quad !== void 0) checkQuad(ectx, run, definition, quad);
49839
+ else finish(ectx, run, definition, errors.length === 0);
48856
49840
  }
48857
49841
  /**
48858
- * Starts the WGSL check of a definition through the renderer's device. With no device (lost) it is ok at once;
48859
- * otherwise it answers when `getCompilationInfo()` resolves. A check that cannot read its info counts as ok.
49842
+ * Starts the WGSL check of a definition through the renderer's device. With no device (lost) it is ok at once, with no
49843
+ * quad; otherwise it answers when `getCompilationInfo()` resolves, and a quad's after that. A check that cannot read
49844
+ * its info counts as ok.
48860
49845
  *
48861
49846
  * @param ectx - Domain context of the effects plugin.
48862
49847
  * @param run - The current run.
48863
49848
  * @param definition - The definition.
49849
+ * @param quad - Its quad program, for a kind that can run on one.
48864
49850
  */
48865
- function checkWgsl(ectx, run, definition) {
49851
+ function checkWgsl(ectx, run, definition, quad) {
48866
49852
  const device = ectx.deps.renderer.host.device();
48867
49853
  if (device === void 0) {
48868
49854
  finish(ectx, run, definition, true);
48869
49855
  return;
48870
49856
  }
48871
- device.createShaderModule({ code: definition.source }).getCompilationInfo().then((info) => settle$1(ectx, run, definition, info.messages), () => settle$1(ectx, run, definition, []));
49857
+ device.createShaderModule({ code: definition.source }).getCompilationInfo().then((info) => settle$1(ectx, run, definition, info.messages, quad), () => settle$1(ectx, run, definition, [], quad));
48872
49858
  }
48873
49859
  /**
48874
49860
  * Reads the errors of a WebGL info log, one per `ERROR: 0:<line>: <message>` line; a summary line
@@ -48953,12 +49939,13 @@ function startChecks(ectx) {
48953
49939
  const { checks } = ectx.state;
48954
49940
  const backend = ectx.deps.renderer.host.kind();
48955
49941
  checks.startedAt = pageNow$1();
49942
+ const bodies = kindBodies(ectx);
48956
49943
  for (const definition of checkList(ectx)) {
48957
49944
  if (checks.status.has(definition)) continue;
48958
49945
  checks.status.set(definition, "pending");
48959
49946
  checks.waiting += 1;
48960
49947
  checks.checked += 1;
48961
- if (backend === "webgpu") checkWgsl(ectx, checks.run, definition);
49948
+ if (backend === "webgpu") checkWgsl(ectx, checks.run, definition, bodies.has(definition) ? definition.quadSource : void 0);
48962
49949
  else if (backend === "webgl") checkGlsl(ectx, checks.run, definition);
48963
49950
  else finish(ectx, checks.run, definition, true);
48964
49951
  }
@@ -49150,7 +50137,8 @@ function warmDefinitions(ectx) {
49150
50137
  * starts the shader checks; a kind whose check is pending gets no instance, a broken kind its
49151
50138
  * stand-in. A view whose filters declare an `area` gets the union of their areas handed to
49152
50139
  * `renderer.sync.filters.area` when it changes (B4). Once the checks settled, every checked
49153
- * definition and every Pixi-core kind is handed to `renderer.sync.filters.warm` as a probe (F4).
50140
+ * definition and every Pixi-core kind is handed to `renderer.sync.filters.warm` as a probe (F4). A filter of ours whose
50141
+ * body can run on a mesh hands its quad over the slot and with its probe; a stand-in never does.
49154
50142
  *
49155
50143
  * Per frame it brings up to date only the views marked dirty: a filter component changed (the change sets of every
49156
50144
  * kind), came or left, a map was retired, a kind still waits for its instance, a chain left places to destroy; a debug
@@ -49421,14 +50409,48 @@ function byOrder(a, b) {
49421
50409
  return a.order - b.order || a.index - b.index;
49422
50410
  }
49423
50411
  /**
50412
+ * The quad program an instance hands over now: one of ours with a usable quad. Never a stand-in: the mesh path does not
50413
+ * run `apply`, so the dev mark of a broken kind, which only a stand-in carries, would be lost.
50414
+ *
50415
+ * @param ectx - Domain context of the effects plugin.
50416
+ * @param pixi - The module the renderer loaded.
50417
+ * @param instance - The instance.
50418
+ * @returns The program, or `undefined`.
50419
+ */
50420
+ function quadProgramFor(ectx, pixi, instance) {
50421
+ if (instance.kind !== "wgsl" || instance.standIn) return void 0;
50422
+ return quadProgramOf(ectx, pixi, instance.definition);
50423
+ }
50424
+ /**
50425
+ * What an instance's slot carries for the quad, one object for the instance's life: the renderer builds its shader
50426
+ * again for another one.
50427
+ *
50428
+ * @param ectx - Domain context of the effects plugin.
50429
+ * @param pixi - The module the renderer loaded.
50430
+ * @param instance - The instance.
50431
+ * @returns The quad, or `undefined` for an instance that hands none.
50432
+ */
50433
+ function quadOf(ectx, pixi, instance) {
50434
+ if (instance.kind !== "wgsl") return void 0;
50435
+ const program = quadProgramFor(ectx, pixi, instance);
50436
+ if (program === void 0) return void 0;
50437
+ instance.quad ??= {
50438
+ program,
50439
+ fu: instance.group
50440
+ };
50441
+ return instance.quad;
50442
+ }
50443
+ /**
49424
50444
  * Tells whether the sorted instances of this frame differ from the last list handed over: other
49425
- * instances, another order, other passes, or other stage filters of their inputs.
50445
+ * instances, another order, other passes, other stage filters of their inputs, or another quad.
49426
50446
  *
50447
+ * @param ectx - Domain context of the effects plugin.
50448
+ * @param pixi - The module the renderer loaded.
49427
50449
  * @param assigned - The last list handed over.
49428
50450
  * @param placed - The sorted instances of this frame.
49429
50451
  * @returns True when the renderer must get a new list.
49430
50452
  */
49431
- function differs(assigned, placed) {
50453
+ function differs(ectx, pixi, assigned, placed) {
49432
50454
  if (assigned.length !== placed.length) return true;
49433
50455
  let index = 0;
49434
50456
  for (const instance of placed) {
@@ -49437,6 +50459,7 @@ function differs(assigned, placed) {
49437
50459
  if (slot?.filter !== instance.filter || slot.passes !== instance.passes) return true;
49438
50460
  if (instance.kind === "wgsl" && slot.inputs !== instance.inputs?.slot) return true;
49439
50461
  if (slot.cache !== cacheOfInstance(instance) || slot.blurs !== blursOf(instance)) return true;
50462
+ if (slot.quad?.program !== quadProgramFor(ectx, pixi, instance)) return true;
49440
50463
  }
49441
50464
  return false;
49442
50465
  }
@@ -49562,13 +50585,16 @@ function syncKind(ectx, pixi, entity, view, kind, changed, off) {
49562
50585
  /**
49563
50586
  * The slot of one instance: its filter, its passes, its kind id for the performance log, the
49564
50587
  * seam of its inputs when it has some, and what the kept-picture cache may do with it (its
49565
- * category, a placed filter's origin, whether it shows a blurred copy).
50588
+ * category, a placed filter's origin, whether it shows a blurred copy, the quad its body runs on).
49566
50589
  *
50590
+ * @param ectx - Domain context of the effects plugin.
50591
+ * @param pixi - The module the renderer loaded.
49567
50592
  * @param instance - The instance.
49568
50593
  * @returns The slot.
49569
50594
  */
49570
- function slotOf$2(instance) {
50595
+ function slotOf$2(ectx, pixi, instance) {
49571
50596
  const cache = cacheOfInstance(instance);
50597
+ const quad = quadOf(ectx, pixi, instance);
49572
50598
  const slot = {
49573
50599
  filter: instance.filter,
49574
50600
  passes: instance.passes,
@@ -49577,6 +50603,7 @@ function slotOf$2(instance) {
49577
50603
  };
49578
50604
  if (instance.kind === "wgsl" && instance.inputs !== void 0) slot.inputs = instance.inputs.slot;
49579
50605
  if (blursOf(instance)) slot.blurs = true;
50606
+ if (quad !== void 0) slot.quad = quad;
49580
50607
  if (cache === "placed" && instance.kind === "wgsl") {
49581
50608
  const origin = instance.group?.uniforms.keptOrigin;
49582
50609
  if (origin instanceof Float32Array) slot.origin = origin;
@@ -49584,6 +50611,18 @@ function slotOf$2(instance) {
49584
50611
  return slot;
49585
50612
  }
49586
50613
  /**
50614
+ * The slot list of a view's instances. Its own function: a closure over `ectx` and `pixi` inside `syncView` would put
50615
+ * them in a context made at every call of it (48 B), also in a sync that hands nothing over.
50616
+ *
50617
+ * @param ectx - Domain context of the effects plugin.
50618
+ * @param pixi - The module the renderer loaded.
50619
+ * @param placed - The sorted instances.
50620
+ * @returns The slots.
50621
+ */
50622
+ function slotsOf(ectx, pixi, placed) {
50623
+ return placed.map((instance) => slotOf$2(ectx, pixi, instance));
50624
+ }
50625
+ /**
49587
50626
  * Brings every kind of a view up to date and collects the instances it has, in kind order, into the view's own list.
49588
50627
  * A kind with no instance yet (its check pending, its map not loaded) keeps the view dirty, so the next run asks
49589
50628
  * again; a kind a debug switch turned off is written and left out of the list.
@@ -49620,9 +50659,9 @@ function syncView(ectx, pixi, view) {
49620
50659
  const { placed, entity } = view;
49621
50660
  placeKinds(ectx, pixi, view);
49622
50661
  if (!inOrder(placed)) placed.sort(byOrder);
49623
- const relisted = differs(view.assigned, placed);
50662
+ const relisted = differs(ectx, pixi, view.assigned, placed);
49624
50663
  if (relisted) {
49625
- const slots = placed.map((instance) => slotOf$2(instance));
50664
+ const slots = slotsOf(ectx, pixi, placed);
49626
50665
  if (slots.length > 0 || ectx.deps.world.ecs.ownerOf(entity) !== void 0) ectx.deps.renderer.sync.filters.set(entity, Object.freeze(slots));
49627
50666
  view.assigned = slots;
49628
50667
  }
@@ -49844,14 +50883,16 @@ function coreProbe(ectx, pixi, id) {
49844
50883
  instance.filter.enabled = true;
49845
50884
  return {
49846
50885
  filter: instance.filter,
50886
+ quad: void 0,
49847
50887
  destroy: () => destroyFilter(instance)
49848
50888
  };
49849
50889
  }
49850
50890
  /**
49851
50891
  * The probes of the warm-up, built one at a time in hand-over order: every Pixi-core kind, then every definition
49852
50892
  * `warmDefinitions` lists (the body of every ready kind, every stage of its inputs, every checked fallback), each in
49853
- * its own order. A core kind goes first: when the renderer has nothing to warm, the one probe built to learn it is one
49854
- * of Pixi's own filters, and no program of a game's shader is compiled for nothing.
50893
+ * its own order. Only the body of a kind brings its quad: stages and fallbacks never shade, so the check compiles none
50894
+ * for them. A core kind goes first: when the renderer has nothing to warm, the one probe built to learn it is one of
50895
+ * Pixi's own filters, and no program of a game's shader is compiled for nothing.
49855
50896
  *
49856
50897
  * @param ectx - Domain context of the effects plugin.
49857
50898
  * @param pixi - The module the renderer loaded.
@@ -49862,7 +50903,7 @@ function* probesOf(ectx, pixi) {
49862
50903
  const probe = coreProbe(ectx, pixi, id);
49863
50904
  if (probe !== void 0) yield probe;
49864
50905
  }
49865
- for (const entry of warmDefinitions(ectx)) yield createWarmFilter(pixi, entry.definition);
50906
+ for (const { definition } of warmDefinitions(ectx)) yield createWarmFilter(pixi, definition, quadProgramOf(ectx, pixi, definition));
49866
50907
  }
49867
50908
  /**
49868
50909
  * Hands one probe to `renderer.sync.filters.warm` and keeps it; a probe the renderer answers false for is destroyed.
@@ -49872,7 +50913,7 @@ function* probesOf(ectx, pixi) {
49872
50913
  * @returns The renderer's answer: true once the probe was warmed, false when there is nothing to warm.
49873
50914
  */
49874
50915
  function handProbe(ectx, probe) {
49875
- const answer = ectx.deps.renderer.sync.filters.warm(probe.filter);
50916
+ const answer = ectx.deps.renderer.sync.filters.warm(probe.filter, probe.quad);
49876
50917
  ectx.state.warm.probes.push(probe);
49877
50918
  answer.then((warmed) => {
49878
50919
  if (!warmed) dropProbe(ectx, probe);
@@ -51062,6 +52103,8 @@ function createCheckState(run) {
51062
52103
  run,
51063
52104
  started: false,
51064
52105
  status: /* @__PURE__ */ new WeakMap(),
52106
+ quads: /* @__PURE__ */ new WeakSet(),
52107
+ programs: /* @__PURE__ */ new WeakMap(),
51065
52108
  waiting: 0,
51066
52109
  checked: 0,
51067
52110
  failed: 0,