@swf2es/render 0.1.35 → 0.1.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swf2es/render",
3
- "version": "0.1.35",
3
+ "version": "0.1.37",
4
4
  "description": "swf2es's own renderer: a scene list, a planner and a WebGL 2 backend (docs/renderer.md)",
5
5
  "keywords": [
6
6
  "swf",
@@ -33,6 +33,6 @@
33
33
  "src"
34
34
  ],
35
35
  "dependencies": {
36
- "@swf2es/context3d": "0.1.35"
36
+ "@swf2es/context3d": "0.1.37"
37
37
  }
38
38
  }
package/src/registry.ts CHANGED
@@ -73,6 +73,11 @@ export class Registry {
73
73
  }
74
74
  }
75
75
 
76
+ /** How many unused frames `id` is let go of after. */
77
+ idleOf(id: number): number {
78
+ return this.idleFrames[id] ?? 0;
79
+ }
80
+
76
81
  /** The frame `id` was last used in. */
77
82
  usedIn(id: number): number {
78
83
  return this.usedAt[id] ?? -1;
@@ -3,6 +3,7 @@ import {
3
3
  type Geometries,
4
4
  type GeometryData,
5
5
  GLYPH_FLOATS,
6
+ IDLE_FRAMES,
6
7
  RELEASE_FRAMES,
7
8
  samplesStage,
8
9
  } from "../geometry.js";
@@ -100,6 +101,50 @@ function localIndices(source: Uint16Array | Uint32Array, count: number): Uint16A
100
101
  return local;
101
102
  }
102
103
 
104
+ /**
105
+ * What merges a small geometry: its arrays while it is its place's (dropBatch), the atlas frame
106
+ * it was placed on, and how many distinct draws the runs have gathered of it, up to 2, which
107
+ * decide whether a short-lived one keeps its arrays (settle), with the frame and scene entry of
108
+ * the last (gathered).
109
+ */
110
+ export interface Batch {
111
+ data: GeometryData | null;
112
+ frame: number;
113
+ draws: number;
114
+ drawnAt: number;
115
+ drawnEntry: number;
116
+ }
117
+
118
+ /**
119
+ * A draw of `place`, entry `entry` of atlas frame `frame`'s scene, gathered into a run (Draws):
120
+ * counted once, however often the entry is gathered, as a mask's is for its push and its pop,
121
+ * and a frame's whose run table overflowed is again as it draws, up to the 2 that keep a
122
+ * geometry's arrays past RELEASE_FRAMES (settle).
123
+ */
124
+ export function gathered(place: Place, frame: number, entry: number): void {
125
+ const batch = place.batch;
126
+ if (batch && batch.draws < 2 && (batch.drawnAt !== frame || batch.drawnEntry !== entry)) {
127
+ batch.draws++;
128
+ batch.drawnAt = frame;
129
+ batch.drawnEntry = entry;
130
+ }
131
+ }
132
+
133
+ /**
134
+ * `place`'s batch let go of, its arrays first: a batch let go of in the old generation, where V8
135
+ * can come to allocate them once a still scene's have lived long (it pretenures what mostly
136
+ * survives), still holds what it points to through every young collection till the next full
137
+ * one. A text redrawn each frame then kept every frame's arrays alive long enough to fill the
138
+ * old generation, whose sweeps of their buffers stalled frames by up to 100 ms (the players'
139
+ * drawing benchmark, text-800, after its still scenes).
140
+ */
141
+ function dropBatch(place: Place): void {
142
+ if (place.batch) {
143
+ place.batch.data = null;
144
+ place.batch = null;
145
+ }
146
+ }
147
+
103
148
  /**
104
149
  * Where a geometry lies in the atlas, its page and its ranges there, or in
105
150
  * the glyph atlas with its text's mode and table, and their slot in the
@@ -117,15 +162,16 @@ export interface Place {
117
162
  /** Whether it samples the stage's pixel (samplesStage), which the stage fill program draws. */
118
163
  stage: boolean;
119
164
  /**
120
- * Small, unchanged geometries may be copied into a run's streaming buffer: their vertices from
121
- * the page, on the GPU, and their indices from `local`. The frame it was placed on.
165
+ * Small, unchanged geometries may be copied into a run's streaming buffer from their arrays,
166
+ * which their registry keeps (settle). Null for one too large to merge, and for a short-lived
167
+ * one let go of after a single draw, which then draws from the atlas.
122
168
  */
123
- batch: { frame: number } | null;
169
+ batch: Batch | null;
124
170
  /**
125
- * Its indices counted from its first vertex: what moving it in the atlas (repack) or copying it
126
- * into a run's stream needs, as WebGL copies an index buffer only as it is. Its geometry's own
127
- * till it has stood RELEASE_FRAMES, then a copy of its own, in 16 bits where its vertices fit,
128
- * as its arrays are let go of (Geometries.release).
171
+ * Its indices counted from its first vertex: what moving it in the atlas (repack) needs, as
172
+ * WebGL copies an index buffer only as it is. Its geometry's own till it has stood
173
+ * RELEASE_FRAMES, then, where its arrays are let go of (Geometries.release), a copy of its own,
174
+ * in 16 bits where its vertices fit.
129
175
  */
130
176
  local: Uint16Array | Uint32Array;
131
177
  }
@@ -133,9 +179,12 @@ export interface Place {
133
179
  /**
134
180
  * The geometry atlas: every geometry copied once into a page's vertex and
135
181
  * index buffers, and advanced text's glyph quads into an atlas of their
136
- * own, where the draws find them by their places. Only a geometry's indices
137
- * stay on the CPU once copied (Place.local), counted from its first vertex,
138
- * and its registry lets go of its arrays (Geometries.release). A geometry
182
+ * own, where the draws find them by their places. Once copied, a geometry
183
+ * keeps only its indices on the CPU (Place.local), counted from its first
184
+ * vertex, and its registry lets go of its arrays (Geometries.release),
185
+ * unless it is small enough to merge (settle): that one keeps its arrays,
186
+ * which a run's stream stages again whenever moving content makes its runs
187
+ * anew. A geometry
139
188
  * let go of leaves holes in its page, which later geometries are placed in
140
189
  * once the top is full; a page is packed again only when what is added
141
190
  * finds no room, its vertices moved on the GPU and its indices written
@@ -270,6 +319,7 @@ export class GeometryAtlas {
270
319
  this.places[id] = null;
271
320
  // Its geometry's own, where it has not settled: a settling entry would keep them alive.
272
321
  place.local = NO_INDICES;
322
+ dropBatch(place);
273
323
  if (place.glyphs) {
274
324
  this.glyphs.live -= place.vertices;
275
325
  this.glyphs.holes += place.vertices;
@@ -312,7 +362,10 @@ export class GeometryAtlas {
312
362
  if (place && data && !data.glyphs && place.vertices === data.positions.length / 2) {
313
363
  this.copyVertices(this.pages[place.page], data, place.vertexStart);
314
364
  place.stage = samplesStage(data);
315
- place.batch = this.batch(data);
365
+ // Its draws carried over: it is the same geometry, changed in place.
366
+ const draws = place.batch?.draws ?? 0;
367
+ dropBatch(place);
368
+ place.batch = this.batch(data, draws);
316
369
  } else if (place && data) {
317
370
  this.letGo(id);
318
371
  geometries.added.push(id);
@@ -424,8 +477,22 @@ export class GeometryAtlas {
424
477
 
425
478
  /**
426
479
  * The geometries placed RELEASE_FRAMES of their registry's ago or more, by its frames, not the
427
- * atlas', which a BitmapData's draws advance too, and placed still: their indices copied into
428
- * arrays of their own and their arrays let go of (Geometries.release), only while the context
480
+ * atlas', which a BitmapData's draws advance too, and placed still: their arrays let go of
481
+ * (Geometries.release) and their indices copied into arrays of their own, unless they are
482
+ * small enough to merge. Those keep their arrays, which a run's stream stages again whenever
483
+ * moving content makes its runs anew: copying such geometries from the page on the GPU
484
+ * instead, a copy for each, made a frame of moving timelines thousands of copies and ANGLE's
485
+ * GL wait twice as long (0.1.35), and getting them back by tessellating them again stalls a
486
+ * frame wherever a still run changes or the stream is made anew. Only one whose owner lets it
487
+ * go within fewer idle frames than IDLE_FRAMES, as text's glyph quads, and that was drawn once
488
+ * goes too, and no longer merges: a text changed every frame makes a new one each frame, and
489
+ * keeping their arrays till they went idle (0.1.36) let them outlive two of V8's young
490
+ * collections, the old generation's sweeps of their many buffers then stalling frames by up to
491
+ * 100 ms (the players' drawing benchmark, text-800). No rule of what a geometry did in its
492
+ * first frames told those from the strokes a timeline played by a few instances makes at a
493
+ * scale, drawn for a frame and again a loop later: letting go of every geometry drawn once
494
+ * unmerged such timelines' runs for good (bench.ts --timelines 20 --apart: GL wait 0.9 to
495
+ * 4.0 ms on SwiftShader). Only while the context
429
496
  * is not known to be lost: copies made into a lost one are no copies, and the arrays stay for
430
497
  * the restore. In Chrome's window before it flags a loss (webgl/losses.ts), arrays may go
431
498
  * after copies that never reached the GPU; the restore's Geometries.lost rebuilds them.
@@ -445,15 +512,26 @@ export class GeometryAtlas {
445
512
 
446
513
  for (let i = 0; i < k; i++) {
447
514
  const place = places[i];
448
- if (this.places[ids[i]] === place && geometries.get(ids[i])) {
449
- place.local = localIndices(place.local, place.vertices);
515
+ // Small enough to merge (Place.batch): its arrays kept for a run's stream to stage, unless
516
+ // it is one of the short-lived kind and was drawn once.
517
+ const kept =
518
+ place.batch !== null && (place.batch.draws > 1 || geometries.idleOf(ids[i]) >= IDLE_FRAMES);
519
+ if (this.places[ids[i]] === place && !kept && geometries.get(ids[i])) {
450
520
  geometries.release(ids[i]);
521
+ if (geometries.released(ids[i])) {
522
+ place.local = localIndices(place.local, place.vertices);
523
+ dropBatch(place);
524
+ }
451
525
  }
452
526
  }
453
527
 
454
- places.splice(0, k);
455
- ids.splice(0, k);
456
- frames.splice(0, k);
528
+ // Moved down in place: a frame's settling allocates nothing.
529
+ places.copyWithin(0, k);
530
+ ids.copyWithin(0, k);
531
+ frames.copyWithin(0, k);
532
+ places.length -= k;
533
+ ids.length -= k;
534
+ frames.length -= k;
457
535
  }
458
536
 
459
537
  /**
@@ -782,9 +860,9 @@ export class GeometryAtlas {
782
860
  }
783
861
  }
784
862
 
785
- private batch(data: GeometryData): Place["batch"] {
863
+ private batch(data: GeometryData, draws = 0): Place["batch"] {
786
864
  return data.positions.length <= 512 && data.indices.length <= 1024 && !data.depths
787
- ? { frame: this.frame }
865
+ ? { data, frame: this.frame, draws, drawnAt: -1, drawnEntry: -1 }
788
866
  : null;
789
867
  }
790
868
 
@@ -1,7 +1,14 @@
1
1
  import type { GlState } from "@swf2es/context3d/device";
2
- import { type GeometryAtlas, type Place, VERTEX_BYTES } from "./atlas.js";
2
+ import type { GeometryData } from "../geometry.js";
3
+ import type { Batch, Place } from "./atlas.js";
3
4
  import { COLOR_AT, DRAW_AT, MERGED_LINE, MERGED_UNIT, POSITION_AT, TEXEL_AT } from "./programs.js";
4
5
 
6
+ /**
7
+ * Atlas attributes followed by where the draw's packed row is in the rows'
8
+ * texture: transforms and snapping stay in the shader, and a row that
9
+ * changes changes no vertex.
10
+ */
11
+ const WORDS = 6;
5
12
  /** Bound the extra CPU and GPU storage, falling back to the atlas after it fills. */
6
13
  const VERTICES_MOST = 2 << 20;
7
14
  const INDICES_MOST = 6 << 20;
@@ -11,8 +18,6 @@ const INDICES_LEAST = 3 << 14;
11
18
  /** Frames over which the most used is watched; room four times that is let go of after them. */
12
19
  const SHRINK_FRAMES = 240;
13
20
 
14
- type Batch = NonNullable<Place["batch"]>;
15
-
16
21
  /** A run's geometries copied in a row into the stream, where every run of the same geometries finds them. */
17
22
  interface Segment {
18
23
  batches: Batch[];
@@ -30,35 +35,20 @@ interface Segment {
30
35
  * Small geometries merged run by run in painter's order, each run's copy a
31
36
  * segment of one stream that any later run of the same geometries draws
32
37
  * again, wherever it comes in the frame: its rows are in a texture of its
33
- * own, written each frame, not in its vertices. A segment's vertices are
34
- * copied from the atlas on the GPU, as the atlas has them, and beside them
35
- * in a buffer of their own each one's slot of its draw's row in the rows'
36
- * texture: transforms and snapping stay in the shader, and a row that
37
- * changes changes no vertex. Only the slots and indices of the segments a
38
- * frame adds are staged on the CPU, after the stream's top, and uploaded
39
- * there at once, the indices from the atlas' copies (Place.local), as the
40
- * geometries' arrays are let go of once in the atlas; what is below stays
41
- * on the GPU alone, and a buffer grown keeps it by a copy there. Segments
42
- * no run used in a frame are let go of, and their room once the stream is
43
- * twice what the last frame used, the stream then made anew.
38
+ * own, written each frame, not in its vertices. Only the segments a frame adds are staged on the
39
+ * CPU, after the stream's top, and uploaded there at once; what is below
40
+ * stays on the GPU alone, and a buffer grown keeps it by a copy there.
41
+ * Segments no run used in a frame are let go of, and their room once the
42
+ * stream is twice what the last frame used, the stream then made anew.
44
43
  */
45
44
  export class FillBatches {
46
45
  vertexArray!: WebGLVertexArrayObject;
47
46
  private vertexBuffer!: WebGLBuffer;
48
- private slotBuffer!: WebGLBuffer;
49
47
  private indexBuffer!: WebGLBuffer;
50
- /** The staged slots and indices: the stream from fromVertex and fromIndex. */
51
- private slots = new Int32Array(0);
48
+ /** The staged words, the same bytes as floats, and indices: the stream from fromVertex and fromIndex. */
49
+ private words = new Uint32Array(0);
50
+ private floats = new Float32Array(0);
52
51
  private indices = new Uint32Array(0);
53
- /**
54
- * The copies from the atlas a frame's segments stage, made as it uploads: each from its page's
55
- * vertex buffer, from vertex `copyFrom`, to the stream's vertex `copyTo`, `copyCount` vertices.
56
- */
57
- private readonly copyPage: WebGLBuffer[] = [];
58
- private readonly copyFrom: number[] = [];
59
- private readonly copyTo: number[] = [];
60
- private readonly copyCount: number[] = [];
61
- private copies = 0;
62
52
  private vertexCapacity = 0;
63
53
  private indexCapacity = 0;
64
54
  private vertexTop = 0;
@@ -103,7 +93,6 @@ export class FillBatches {
103
93
  constructor(
104
94
  private readonly gl: WebGL2RenderingContext,
105
95
  private readonly state: GlState,
106
- private readonly atlas: GeometryAtlas,
107
96
  ) {}
108
97
 
109
98
  /** The buffers and the rows' texture made, `textureMost` lines at most, as the context comes. */
@@ -115,20 +104,18 @@ export class FillBatches {
115
104
  this.slotsMost = MERGED_LINE * textureMost;
116
105
  this.vertexArray = gl.createVertexArray() as WebGLVertexArrayObject;
117
106
  this.vertexBuffer = gl.createBuffer() as WebGLBuffer;
118
- this.slotBuffer = gl.createBuffer() as WebGLBuffer;
119
107
  this.indexBuffer = gl.createBuffer() as WebGLBuffer;
120
108
  this.state.bindVertexArray(this.vertexArray);
121
109
  gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
122
110
  gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
123
111
  gl.enableVertexAttribArray(POSITION_AT);
124
- gl.vertexAttribPointer(POSITION_AT, 2, gl.FLOAT, false, VERTEX_BYTES, 0);
112
+ gl.vertexAttribPointer(POSITION_AT, 2, gl.FLOAT, false, WORDS * 4, 0);
125
113
  gl.enableVertexAttribArray(TEXEL_AT);
126
- gl.vertexAttribPointer(TEXEL_AT, 2, gl.FLOAT, false, VERTEX_BYTES, 8);
114
+ gl.vertexAttribPointer(TEXEL_AT, 2, gl.FLOAT, false, WORDS * 4, 8);
127
115
  gl.enableVertexAttribArray(COLOR_AT);
128
- gl.vertexAttribPointer(COLOR_AT, 4, gl.UNSIGNED_BYTE, true, VERTEX_BYTES, 16);
129
- gl.bindBuffer(gl.ARRAY_BUFFER, this.slotBuffer);
116
+ gl.vertexAttribPointer(COLOR_AT, 4, gl.UNSIGNED_BYTE, true, WORDS * 4, 16);
130
117
  gl.enableVertexAttribArray(DRAW_AT);
131
- gl.vertexAttribIPointer(DRAW_AT, 1, gl.INT, 4, 0);
118
+ gl.vertexAttribIPointer(DRAW_AT, 1, gl.INT, WORDS * 4, 20);
132
119
  // Disabled in the atlas VAO: a negative attribute selects the existing run-table path.
133
120
  gl.vertexAttribI4i(DRAW_AT, -1, 0, 0, 0);
134
121
  this.vertexCapacity = 0;
@@ -164,7 +151,6 @@ export class FillBatches {
164
151
  }
165
152
 
166
153
  this.full = false;
167
- this.copies = 0;
168
154
  const seen = this.seenBefore;
169
155
  this.seenBefore = this.seen;
170
156
  this.seen = seen;
@@ -264,20 +250,29 @@ export class FillBatches {
264
250
  this.vertexTop + vertices - this.fromVertex,
265
251
  this.indexTop + indices - this.fromIndex,
266
252
  );
267
- const slots = this.slots;
253
+ const floats = this.floats;
254
+ const words = this.words;
268
255
  const staged = this.indices;
269
- const pages = this.atlas.pages;
270
256
  for (let i = 0; i < count; i++) {
271
257
  const place = places[i];
272
- segment.batches[i] = place.batch as Batch;
258
+ const batch = place.batch as Batch;
259
+ segment.batches[i] = batch;
260
+ // A place's batch, which holds its arrays while it is the place's (atlas.ts, dropBatch).
261
+ const data = batch.data as GeometryData;
273
262
  const base = this.vertexTop;
274
- const page = pages[place.page];
275
- this.stageCopy(page.vertexBuffer, place.vertexStart, base, place.vertices);
276
- slots.fill(segment.slot + i, base - this.fromVertex, base - this.fromVertex + place.vertices);
277
- const local = place.local;
263
+ for (let j = 0; j < place.vertices; j++) {
264
+ const at = (base - this.fromVertex + j) * WORDS;
265
+ floats[at] = data.positions[j * 2];
266
+ floats[at + 1] = data.positions[j * 2 + 1];
267
+ floats[at + 2] = data.texels ? data.texels[j * 2] : 0;
268
+ floats[at + 3] = data.texels ? data.texels[j * 2 + 1] : 0;
269
+ words[at + 4] = data.colors[j];
270
+ words[at + 5] = segment.slot + i;
271
+ }
272
+
278
273
  let at = this.indexTop - this.fromIndex;
279
- for (let j = 0; j < local.length; j++) {
280
- staged[at++] = base + local[j];
274
+ for (let j = 0; j < place.indices; j++) {
275
+ staged[at++] = base + data.indices[j];
281
276
  }
282
277
 
283
278
  this.vertexTop += place.vertices;
@@ -295,30 +290,6 @@ export class FillBatches {
295
290
  return segment;
296
291
  }
297
292
 
298
- /**
299
- * `count` vertices from vertex `from` of an atlas page's `buffer` to be copied to the stream's
300
- * vertex `to` as the frame uploads: joined to the copy before where both run on from it, as
301
- * geometries placed together lie together.
302
- */
303
- private stageCopy(buffer: WebGLBuffer, from: number, to: number, count: number): void {
304
- const k = this.copies - 1;
305
- if (
306
- k >= 0 &&
307
- this.copyPage[k] === buffer &&
308
- this.copyFrom[k] + this.copyCount[k] === from &&
309
- this.copyTo[k] + this.copyCount[k] === to
310
- ) {
311
- this.copyCount[k] += count;
312
- return;
313
- }
314
-
315
- this.copyPage[k + 1] = buffer;
316
- this.copyFrom[k + 1] = from;
317
- this.copyTo[k + 1] = to;
318
- this.copyCount[k + 1] = count;
319
- this.copies = k + 2;
320
- }
321
-
322
293
  /** Whether the `count` rows from `slot` are `rows`. */
323
294
  private rowsAre(slot: number, rows: Int32Array, count: number): boolean {
324
295
  for (let i = 0; i < count; i++) {
@@ -450,27 +421,22 @@ export class FillBatches {
450
421
  this.watch(staging);
451
422
  }
452
423
 
453
- /**
454
- * What add staged uploaded where it lies, and the vertices it staged copied from the atlas, the
455
- * buffers grown first to fit the stream.
456
- */
424
+ /** What add staged uploaded where it lies, the buffers grown first to fit the stream. */
457
425
  private uploadStaged(): void {
458
426
  const gl = this.gl;
459
427
  this.state.bindVertexArray(this.vertexArray);
428
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
460
429
  if (this.vertexTop > this.vertexCapacity) {
461
430
  this.vertexCapacity = Math.min(
462
431
  VERTICES_MOST,
463
432
  Math.max(this.vertexTop, this.vertexCapacity * 2),
464
433
  );
465
- gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
466
434
  this.resize(
467
435
  gl.ARRAY_BUFFER,
468
436
  this.vertexBuffer,
469
- this.vertexCapacity * VERTEX_BYTES,
470
- this.fromVertex * VERTEX_BYTES,
437
+ this.vertexCapacity * WORDS * 4,
438
+ this.fromVertex * WORDS * 4,
471
439
  );
472
- gl.bindBuffer(gl.ARRAY_BUFFER, this.slotBuffer);
473
- this.resize(gl.ARRAY_BUFFER, this.slotBuffer, this.vertexCapacity * 4, this.fromVertex * 4);
474
440
  }
475
441
 
476
442
  if (this.indexTop > this.indexCapacity) {
@@ -483,28 +449,13 @@ export class FillBatches {
483
449
  );
484
450
  }
485
451
 
486
- gl.bindBuffer(gl.ARRAY_BUFFER, this.slotBuffer);
487
452
  gl.bufferSubData(
488
453
  gl.ARRAY_BUFFER,
489
- this.fromVertex * 4,
490
- this.slots,
454
+ this.fromVertex * WORDS * 4,
455
+ this.words,
491
456
  0,
492
- this.vertexTop - this.fromVertex,
457
+ (this.vertexTop - this.fromVertex) * WORDS,
493
458
  );
494
- gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
495
- for (let k = 0; k < this.copies; k++) {
496
- gl.bindBuffer(gl.COPY_READ_BUFFER, this.copyPage[k]);
497
- gl.copyBufferSubData(
498
- gl.COPY_READ_BUFFER,
499
- gl.ARRAY_BUFFER,
500
- this.copyFrom[k] * VERTEX_BYTES,
501
- this.copyTo[k] * VERTEX_BYTES,
502
- this.copyCount[k] * VERTEX_BYTES,
503
- );
504
- }
505
-
506
- gl.bindBuffer(gl.COPY_READ_BUFFER, null);
507
- this.copies = 0;
508
459
  gl.bufferSubData(
509
460
  gl.ELEMENT_ARRAY_BUFFER,
510
461
  this.fromIndex * 4,
@@ -523,22 +474,21 @@ export class FillBatches {
523
474
 
524
475
  this.gl.deleteVertexArray(this.vertexArray);
525
476
  this.gl.deleteBuffer(this.vertexBuffer);
526
- this.gl.deleteBuffer(this.slotBuffer);
527
477
  this.gl.deleteBuffer(this.indexBuffer);
528
- this.slots = new Int32Array(0);
478
+ this.words = new Uint32Array(0);
479
+ this.floats = new Float32Array(0);
529
480
  this.indices = new Uint32Array(0);
530
- this.copyPage.length = 0;
531
- this.copies = 0;
532
481
  }
533
482
 
534
483
  /** Staging for at least `vertices` and `indices` from its start, what is staged kept. */
535
484
  private stageRoom(vertices: number, indices: number): void {
536
- if (vertices > this.slots.length) {
537
- const grown = new Int32Array(
538
- Math.min(VERTICES_MOST, Math.max(vertices, this.slots.length * 2)),
485
+ if (vertices * WORDS > this.words.length) {
486
+ const grown = new Uint32Array(
487
+ Math.min(VERTICES_MOST * WORDS, Math.max(vertices * WORDS, this.words.length * 2)),
539
488
  );
540
- grown.set(this.slots);
541
- this.slots = grown;
489
+ grown.set(this.words);
490
+ this.words = grown;
491
+ this.floats = new Float32Array(grown.buffer);
542
492
  }
543
493
 
544
494
  if (indices > this.indices.length) {
@@ -579,11 +529,9 @@ export class FillBatches {
579
529
  this.resize(
580
530
  gl.ARRAY_BUFFER,
581
531
  this.vertexBuffer,
582
- vertices * VERTEX_BYTES,
583
- keepVertices * VERTEX_BYTES,
532
+ vertices * WORDS * 4,
533
+ keepVertices * WORDS * 4,
584
534
  );
585
- gl.bindBuffer(gl.ARRAY_BUFFER, this.slotBuffer);
586
- this.resize(gl.ARRAY_BUFFER, this.slotBuffer, vertices * 4, keepVertices * 4);
587
535
  }
588
536
 
589
537
  const indices = Math.max(INDICES_LEAST, this.mostIndices * 2);
@@ -593,9 +541,10 @@ export class FillBatches {
593
541
  this.resize(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer, indices * 4, keepIndices * 4);
594
542
  }
595
543
 
596
- const staged = Math.max(VERTICES_LEAST, this.mostStaged * 2);
597
- if (this.mostStaged * 4 <= this.slots.length && staged < this.slots.length) {
598
- this.slots = new Int32Array(staged);
544
+ const staged = Math.max(VERTICES_LEAST, this.mostStaged * 2) * WORDS;
545
+ if (this.mostStaged * 4 * WORDS <= this.words.length && staged < this.words.length) {
546
+ this.words = new Uint32Array(staged);
547
+ this.floats = new Float32Array(this.words.buffer);
599
548
  }
600
549
 
601
550
  const stagedIndices = Math.max(INDICES_LEAST, this.mostStagedIndices * 2);
@@ -15,7 +15,7 @@ import {
15
15
  SMOOTH,
16
16
  SNAP,
17
17
  } from "../scene.js";
18
- import type { GeometryAtlas, Place } from "./atlas.js";
18
+ import { type GeometryAtlas, gathered, type Place } from "./atlas.js";
19
19
  import { FillBatches } from "./batches.js";
20
20
  import { setModeBlend } from "./composite.js";
21
21
  import type { GpuTextures } from "./gpu-textures.js";
@@ -225,7 +225,7 @@ export class Draws {
225
225
  this.gl = gl;
226
226
  this.state = state;
227
227
  this.atlas = atlas;
228
- this.batches = new FillBatches(gl, state, atlas);
228
+ this.batches = new FillBatches(gl, state);
229
229
  this.gpu = gpu;
230
230
  this.pool = pool;
231
231
  }
@@ -785,7 +785,8 @@ export class Draws {
785
785
  * textures (FILL_TEXTURES, each with its sampling), RUN_MOST at most:
786
786
  * their runCounts, runOffsets and runRows (FILL_SLOT), and the units their
787
787
  * textures take in runUnits. Without WEBGL_multi_draw, a run is of
788
- * geometries too large to merge (Place.batch), of geometries added this
788
+ * geometries that do not merge (Place.batch: too large, or short-lived
789
+ * and let go of after a single draw), of geometries added this
789
790
  * frame, or of stable ones alone, so that a stable run's merged copy is
790
791
  * drawn again while a part of it changes from frame to frame; and without
791
792
  * merging each fill is a run. A fill that samples the stage's pixel
@@ -798,7 +799,7 @@ export class Draws {
798
799
  const single = !this.multi;
799
800
  const most = this.multi || this.merging ? RUN_MOST : 1;
800
801
  const frame = this.atlas.frame;
801
- // Without a multi-draw, what the run is of: geometries too large to merge, geometries added
802
+ // Without a multi-draw, what the run is of: geometries that do not merge, geometries added
802
803
  // this frame, or stable ones, whose merged copy later frames draw again.
803
804
  let kind = -1;
804
805
  let draws = 0;
@@ -848,6 +849,9 @@ export class Draws {
848
849
 
849
850
  this.runCounts[draws] = place.indices;
850
851
  this.runPlaces[draws] = place;
852
+ // A short-lived geometry drawn more than once keeps its arrays (atlas.ts, settle).
853
+ gathered(place, frame, j);
854
+
851
855
  this.runOffsets[draws] = place.indexStart * 4;
852
856
  this.runRows[draws] =
853
857
  scene.row[j] | (slot << FILL_SLOT) | (scene.sampler[j] & SNAP ? SNAP_BIT : 0);