@swf2es/render 0.1.28 → 0.1.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/webgl/backend.d.ts +53 -5
- package/dist/webgl/backend.d.ts.map +1 -1
- package/dist/webgl/backend.js +158 -33
- package/dist/webgl/backend.js.map +1 -1
- package/dist/webgl/draws.d.ts.map +1 -1
- package/dist/webgl/draws.js +2 -1
- package/dist/webgl/draws.js.map +1 -1
- package/dist/webgl/kernels.d.ts +6 -1
- package/dist/webgl/kernels.d.ts.map +1 -1
- package/dist/webgl/kernels.js +11 -1
- package/dist/webgl/kernels.js.map +1 -1
- package/dist/webgl/losses.d.ts +44 -0
- package/dist/webgl/losses.d.ts.map +1 -0
- package/dist/webgl/losses.js +80 -0
- package/dist/webgl/losses.js.map +1 -0
- package/dist/webgl/precompile.d.ts.map +1 -1
- package/dist/webgl/precompile.js +4 -2
- package/dist/webgl/precompile.js.map +1 -1
- package/package.json +2 -2
- package/src/webgl/backend.ts +228 -59
- package/src/webgl/draws.ts +2 -1
- package/src/webgl/kernels.ts +10 -0
- package/src/webgl/losses.ts +92 -0
- package/src/webgl/precompile.ts +4 -2
package/src/webgl/backend.ts
CHANGED
|
@@ -38,6 +38,7 @@ import { FilterRunner } from "./filters.js";
|
|
|
38
38
|
import { GpuTextures } from "./gpu-textures.js";
|
|
39
39
|
import { HeldLayers } from "./holds.js";
|
|
40
40
|
import { KernelPrograms } from "./kernels.js";
|
|
41
|
+
import { LinkLosses } from "./losses.js";
|
|
41
42
|
import { ProgramQueue } from "./precompile.js";
|
|
42
43
|
import { LAYER_UNIT, TEXTURE_UNIT } from "./programs.js";
|
|
43
44
|
import { Stage } from "./stage.js";
|
|
@@ -147,11 +148,20 @@ export class WebGLBackend {
|
|
|
147
148
|
/** Framebuffers onto registry textures, drawn into or read, by texture id, with the texture they were made for. */
|
|
148
149
|
private textureFramebuffers: ({ texture: WebGLTexture; framebuffer: WebGLFramebuffer } | null)[] =
|
|
149
150
|
[];
|
|
151
|
+
/** Which failed links are a lost context's (gaveUp, and the kernels'). */
|
|
152
|
+
private readonly losses: LinkLosses;
|
|
153
|
+
/** Whether what the context holds is made (setUp): not after it was lost, till it is back. */
|
|
154
|
+
private made = false;
|
|
155
|
+
/** Whether frames draw: made, and no work given up on since (gaveUp). */
|
|
156
|
+
private ready = false;
|
|
157
|
+
/** The failure work was last given up on for, the context not flagged lost (resume). */
|
|
158
|
+
private fault: unknown = null;
|
|
150
159
|
|
|
151
160
|
constructor(gl: WebGL2RenderingContext) {
|
|
152
161
|
this.gl = gl;
|
|
153
162
|
this.state = new GlState(gl);
|
|
154
|
-
this.
|
|
163
|
+
this.losses = new LinkLosses(gl);
|
|
164
|
+
this.kernels = new KernelPrograms(gl, this.state, this.losses);
|
|
155
165
|
this.pool = new TargetPool(gl, this.state);
|
|
156
166
|
this.stage = new Stage(gl, this.state, this.pool);
|
|
157
167
|
this.gpu = new GpuTextures(gl, this.state);
|
|
@@ -180,21 +190,105 @@ export class WebGLBackend {
|
|
|
180
190
|
this.kernels,
|
|
181
191
|
);
|
|
182
192
|
this.holds = new HeldLayers(gl, this.state, this.pool, this.draws, this.compositor, this.gpu);
|
|
183
|
-
|
|
193
|
+
// A context lost already gives up here, and is made again once it is restored.
|
|
194
|
+
try {
|
|
195
|
+
this.setUp();
|
|
196
|
+
this.made = this.ready = true;
|
|
197
|
+
} catch (e) {
|
|
198
|
+
this.gaveUp(e);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Whether frames wait (resume): the context was lost and is not back
|
|
204
|
+
* yet, or work was given up on as lost before the browser said so.
|
|
205
|
+
*/
|
|
206
|
+
get stale(): boolean {
|
|
207
|
+
return !this.ready;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Whether a stale backend draws again, the context not flagged lost: not
|
|
212
|
+
* while a failure that said nothing may yet be a loss Chrome has not
|
|
213
|
+
* flagged (LinkLosses); after that, it was the shaders' fault, and frames
|
|
214
|
+
* draw on as before the failure, linking again what failed, which then
|
|
215
|
+
* throws. Nothing is made again on a live context, whose objects are
|
|
216
|
+
* all there, a BitmapData's newest pixels among them. Throws that
|
|
217
|
+
* failure where the setUp it came from never finished.
|
|
218
|
+
*/
|
|
219
|
+
resume(): boolean {
|
|
220
|
+
if (this.ready) {
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (this.gl.isContextLost() || !this.losses.expired) {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (!this.made) {
|
|
229
|
+
throw this.fault;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
this.losses.concede();
|
|
233
|
+
this.ready = true;
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** Whether frames draw: the context there, and what it holds made. */
|
|
238
|
+
private get usable(): boolean {
|
|
239
|
+
return this.ready && !this.gl.isContextLost();
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Whether what the context holds may be drawn into and read: made, and
|
|
244
|
+
* not lost. Not stopped by a frame given up on as lost (stale): a
|
|
245
|
+
* BitmapData's texture, whose pixels may be newer than its store's, is
|
|
246
|
+
* read, filled and drawn into meanwhile as ever, unless that needs a
|
|
247
|
+
* program that fails.
|
|
248
|
+
*/
|
|
249
|
+
private get live(): boolean {
|
|
250
|
+
return this.made && !this.gl.isContextLost();
|
|
184
251
|
}
|
|
185
252
|
|
|
186
253
|
/**
|
|
187
254
|
* The context came back after it was lost: everything made again, every
|
|
188
255
|
* geometry copied in again from the registry's arrays. The textures were
|
|
189
|
-
* lost with it, which their owners add again (Textures.lost).
|
|
256
|
+
* lost with it, which their owners add again (Textures.lost). Lost again
|
|
257
|
+
* meanwhile, it stays stale, for the next restore.
|
|
190
258
|
*/
|
|
191
259
|
restore(geometries: Geometries): void {
|
|
192
|
-
this.
|
|
260
|
+
this.losses.clear();
|
|
261
|
+
this.made = this.ready = false;
|
|
193
262
|
geometries.added.length = 0;
|
|
194
263
|
geometries.removed.length = 0;
|
|
195
264
|
geometries.updated.length = 0;
|
|
196
|
-
this.
|
|
197
|
-
|
|
265
|
+
if (this.gl.isContextLost()) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
try {
|
|
270
|
+
this.setUp();
|
|
271
|
+
this.atlas.repack(geometries);
|
|
272
|
+
this.atlas.repackGlyphs(geometries);
|
|
273
|
+
this.made = this.ready = true;
|
|
274
|
+
} catch (e) {
|
|
275
|
+
this.gaveUp(e);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Work that threw `e` given up on, where a program would not be made as
|
|
281
|
+
* the context was lost (LinkLosses): frames wait (stale) till it is
|
|
282
|
+
* restored, or till the failure turns out the shaders' (resume), with
|
|
283
|
+
* nothing thrown. Anything else is thrown on.
|
|
284
|
+
*/
|
|
285
|
+
private gaveUp(e: unknown): void {
|
|
286
|
+
if (!this.losses.lost(e)) {
|
|
287
|
+
throw e;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
this.ready = false;
|
|
291
|
+
this.fault = e;
|
|
198
292
|
}
|
|
199
293
|
|
|
200
294
|
/** Programs, buffers and textures made, as the context comes or comes back. */
|
|
@@ -215,8 +309,6 @@ export class WebGLBackend {
|
|
|
215
309
|
// Kernels' programs made again as first used, the context's own gone with it.
|
|
216
310
|
this.kernels.clear();
|
|
217
311
|
const textureMost = gl.getParameter(gl.MAX_TEXTURE_SIZE) as number;
|
|
218
|
-
this.draws.setUp(textureMost);
|
|
219
|
-
this.compositor.setUp();
|
|
220
312
|
// A lost context's programs went with it: all queued again.
|
|
221
313
|
this.programs = new ProgramQueue(gl, this.state);
|
|
222
314
|
this.overProgram = null;
|
|
@@ -243,12 +335,15 @@ export class WebGLBackend {
|
|
|
243
335
|
this.gpu.setUp();
|
|
244
336
|
// The context's own, gone with it.
|
|
245
337
|
this.textureFramebuffers = [];
|
|
338
|
+
// Linked last: a context lost meanwhile throws here (gaveUp), the rest made, for destroy.
|
|
339
|
+
this.draws.setUp(textureMost);
|
|
340
|
+
this.compositor.setUp();
|
|
246
341
|
}
|
|
247
342
|
|
|
248
343
|
/**
|
|
249
344
|
* Draw a frame: what the geometries added and removed first, then the
|
|
250
|
-
* rows, then the commands
|
|
251
|
-
*
|
|
345
|
+
* rows, then the commands, onto the canvas. Nothing while the context is
|
|
346
|
+
* lost; a frame the context is lost in midway is given up on (gaveUp).
|
|
252
347
|
*/
|
|
253
348
|
execute(
|
|
254
349
|
commands: Commands,
|
|
@@ -259,16 +354,38 @@ export class WebGLBackend {
|
|
|
259
354
|
filters: Filters,
|
|
260
355
|
keeps: Keeps,
|
|
261
356
|
target: Target,
|
|
262
|
-
|
|
357
|
+
): void {
|
|
358
|
+
if (!this.usable) {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
try {
|
|
363
|
+
this.run(commands, scene, rows, geometries, textures, filters, keeps, target, null);
|
|
364
|
+
this.losses.endFrame();
|
|
365
|
+
} catch (e) {
|
|
366
|
+
this.gaveUp(e);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* A frame drawn as `execute` draws it, onto the canvas or into `root`, a
|
|
372
|
+
* layer the target's size, as BitmapData.draw's frames go.
|
|
373
|
+
*/
|
|
374
|
+
private run(
|
|
375
|
+
commands: Commands,
|
|
376
|
+
scene: SceneList,
|
|
377
|
+
rows: Rows,
|
|
378
|
+
geometries: Geometries,
|
|
379
|
+
textures: Textures,
|
|
380
|
+
filters: Filters,
|
|
381
|
+
keeps: Keeps,
|
|
382
|
+
target: Target,
|
|
383
|
+
root: Layer | null,
|
|
263
384
|
): void {
|
|
264
385
|
// A frame drawn into a layer, for BitmapData, is no frame of the canvas': idle layers are
|
|
265
386
|
// counted in the canvas' frames.
|
|
266
387
|
const counted = root === null;
|
|
267
388
|
const gl = this.gl;
|
|
268
|
-
if (gl.isContextLost()) {
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
389
|
this.frameFilters = filters;
|
|
273
390
|
this.atlas.place(geometries);
|
|
274
391
|
this.gpu.uploadTextures(textures, this.clearTexture);
|
|
@@ -519,26 +636,31 @@ export class WebGLBackend {
|
|
|
519
636
|
): Uint8Array {
|
|
520
637
|
const gl = this.gl;
|
|
521
638
|
const bytes = new Uint8Array(width * height * 4);
|
|
522
|
-
if (
|
|
639
|
+
if (!this.live) {
|
|
523
640
|
return bytes;
|
|
524
641
|
}
|
|
525
642
|
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
643
|
+
try {
|
|
644
|
+
const layer = this.drawSampled(
|
|
645
|
+
commands,
|
|
646
|
+
scene,
|
|
647
|
+
rows,
|
|
648
|
+
geometries,
|
|
649
|
+
textures,
|
|
650
|
+
filters,
|
|
651
|
+
keeps,
|
|
652
|
+
target,
|
|
653
|
+
width,
|
|
654
|
+
height,
|
|
655
|
+
samples,
|
|
656
|
+
);
|
|
657
|
+
this.state.bindFramebuffer(layer.framebuffer);
|
|
658
|
+
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, bytes);
|
|
659
|
+
this.pool.giveLayer(layer);
|
|
660
|
+
} catch (e) {
|
|
661
|
+
this.gaveUp(e);
|
|
662
|
+
}
|
|
663
|
+
|
|
542
664
|
return bytes;
|
|
543
665
|
}
|
|
544
666
|
|
|
@@ -568,31 +690,35 @@ export class WebGLBackend {
|
|
|
568
690
|
y: number,
|
|
569
691
|
opaque: boolean,
|
|
570
692
|
): boolean {
|
|
571
|
-
|
|
572
|
-
if (gl.isContextLost()) {
|
|
693
|
+
if (!this.live) {
|
|
573
694
|
return false;
|
|
574
695
|
}
|
|
575
696
|
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
697
|
+
try {
|
|
698
|
+
const layer = this.drawSampled(
|
|
699
|
+
commands,
|
|
700
|
+
scene,
|
|
701
|
+
rows,
|
|
702
|
+
geometries,
|
|
703
|
+
textures,
|
|
704
|
+
filters,
|
|
705
|
+
keeps,
|
|
706
|
+
target,
|
|
707
|
+
width,
|
|
708
|
+
height,
|
|
709
|
+
samples,
|
|
710
|
+
);
|
|
711
|
+
const into = this.textureFramebuffer(id);
|
|
712
|
+
if (into) {
|
|
713
|
+
this.compositeOver(layer, into, x, y, width, height, opaque);
|
|
714
|
+
}
|
|
593
715
|
|
|
594
|
-
|
|
595
|
-
|
|
716
|
+
this.pool.giveLayer(layer);
|
|
717
|
+
return into !== null;
|
|
718
|
+
} catch (e) {
|
|
719
|
+
this.gaveUp(e);
|
|
720
|
+
return false;
|
|
721
|
+
}
|
|
596
722
|
}
|
|
597
723
|
|
|
598
724
|
/**
|
|
@@ -665,7 +791,7 @@ export class WebGLBackend {
|
|
|
665
791
|
* row by row; null on a lost context or without the texture.
|
|
666
792
|
*/
|
|
667
793
|
readTexture(id: number, width: number, height: number): Uint8Array | null {
|
|
668
|
-
const framebuffer = this.
|
|
794
|
+
const framebuffer = this.live ? this.textureFramebuffer(id) : null;
|
|
669
795
|
if (!framebuffer) {
|
|
670
796
|
return null;
|
|
671
797
|
}
|
|
@@ -690,8 +816,12 @@ export class WebGLBackend {
|
|
|
690
816
|
height: number,
|
|
691
817
|
pixel: number,
|
|
692
818
|
): boolean {
|
|
819
|
+
if (!this.live) {
|
|
820
|
+
return false;
|
|
821
|
+
}
|
|
822
|
+
|
|
693
823
|
this.gpu.uploadTextures(textures, this.clearTexture);
|
|
694
|
-
const framebuffer = this.
|
|
824
|
+
const framebuffer = this.textureFramebuffer(id);
|
|
695
825
|
if (!framebuffer) {
|
|
696
826
|
return false;
|
|
697
827
|
}
|
|
@@ -750,8 +880,12 @@ export class WebGLBackend {
|
|
|
750
880
|
dy: number,
|
|
751
881
|
): boolean {
|
|
752
882
|
const gl = this.gl;
|
|
883
|
+
if (!this.live) {
|
|
884
|
+
return false;
|
|
885
|
+
}
|
|
886
|
+
|
|
753
887
|
this.gpu.uploadTextures(textures, this.clearTexture);
|
|
754
|
-
const source =
|
|
888
|
+
const source = this.textureFramebuffer(from);
|
|
755
889
|
const target = source ? this.textureFramebuffer(to) : null;
|
|
756
890
|
if (!source || !target) {
|
|
757
891
|
return false;
|
|
@@ -849,11 +983,46 @@ export class WebGLBackend {
|
|
|
849
983
|
height: number,
|
|
850
984
|
samples: number,
|
|
851
985
|
): void {
|
|
852
|
-
|
|
853
|
-
if (gl.isContextLost()) {
|
|
986
|
+
if (!this.usable) {
|
|
854
987
|
return;
|
|
855
988
|
}
|
|
856
989
|
|
|
990
|
+
try {
|
|
991
|
+
this.planeInto(
|
|
992
|
+
keep,
|
|
993
|
+
commands,
|
|
994
|
+
scene,
|
|
995
|
+
rows,
|
|
996
|
+
geometries,
|
|
997
|
+
textures,
|
|
998
|
+
filters,
|
|
999
|
+
keeps,
|
|
1000
|
+
target,
|
|
1001
|
+
width,
|
|
1002
|
+
height,
|
|
1003
|
+
samples,
|
|
1004
|
+
);
|
|
1005
|
+
} catch (e) {
|
|
1006
|
+
this.gaveUp(e);
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
/** drawPlane's drawing, what throws thrown on. */
|
|
1011
|
+
private planeInto(
|
|
1012
|
+
keep: number,
|
|
1013
|
+
commands: Commands,
|
|
1014
|
+
scene: SceneList,
|
|
1015
|
+
rows: Rows,
|
|
1016
|
+
geometries: Geometries,
|
|
1017
|
+
textures: Textures,
|
|
1018
|
+
filters: Filters,
|
|
1019
|
+
keeps: Keeps,
|
|
1020
|
+
target: Target,
|
|
1021
|
+
width: number,
|
|
1022
|
+
height: number,
|
|
1023
|
+
samples: number,
|
|
1024
|
+
): void {
|
|
1025
|
+
const gl = this.gl;
|
|
857
1026
|
const layer = this.drawSampled(
|
|
858
1027
|
commands,
|
|
859
1028
|
scene,
|
|
@@ -906,7 +1075,7 @@ export class WebGLBackend {
|
|
|
906
1075
|
samples: number,
|
|
907
1076
|
): Layer {
|
|
908
1077
|
let layer = this.pool.takeLayer(width * samples, height * samples);
|
|
909
|
-
this.
|
|
1078
|
+
this.run(commands, scene, rows, geometries, textures, filters, keeps, target, layer);
|
|
910
1079
|
for (let k = samples; k > 1; k /= 2) {
|
|
911
1080
|
const half = this.filters.halve(layer, (width * k) / 2, (height * k) / 2);
|
|
912
1081
|
this.pool.giveLayer(layer);
|
package/src/webgl/draws.ts
CHANGED
|
@@ -227,7 +227,8 @@ export class Draws {
|
|
|
227
227
|
try {
|
|
228
228
|
this.program = endProgram(gl, fill);
|
|
229
229
|
} catch (e) {
|
|
230
|
-
|
|
230
|
+
// Not where the context is flagged lost, whose every link fails.
|
|
231
|
+
if (!this.multi || gl.isContextLost()) {
|
|
231
232
|
throw e;
|
|
232
233
|
}
|
|
233
234
|
|
package/src/webgl/kernels.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { type GlState, linkProgram, ShaderError } from "@swf2es/context3d/device
|
|
|
2
2
|
import type { Filters } from "../filters.js";
|
|
3
3
|
import type { KernelImage } from "../kernel-shaders.js";
|
|
4
4
|
import { CLAMP } from "../scene.js";
|
|
5
|
+
import type { LinkLosses } from "./losses.js";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* A Pixel Bender kernel's program: where it takes its uniforms, asked
|
|
@@ -47,6 +48,8 @@ export class KernelPrograms {
|
|
|
47
48
|
constructor(
|
|
48
49
|
private readonly gl: WebGL2RenderingContext,
|
|
49
50
|
private readonly state: GlState,
|
|
51
|
+
/** Which failed links are a lost context's, which are not kept as failed. */
|
|
52
|
+
private readonly losses: LinkLosses,
|
|
50
53
|
) {}
|
|
51
54
|
|
|
52
55
|
/**
|
|
@@ -102,6 +105,13 @@ export class KernelPrograms {
|
|
|
102
105
|
if (!(e instanceof ShaderError)) {
|
|
103
106
|
throw e;
|
|
104
107
|
}
|
|
108
|
+
|
|
109
|
+
// A kernel that would not link is drawn without. One lost with the context is drawn
|
|
110
|
+
// without too, into nothing or for a frame or so, but not kept as failed: it is linked
|
|
111
|
+
// again as it is next used, or once the context is back.
|
|
112
|
+
if (this.losses.lost(e)) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
105
115
|
}
|
|
106
116
|
}
|
|
107
117
|
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { lostShader, type ShaderError } from "@swf2es/context3d/device";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* How long link failures that say nothing are taken for a lost context
|
|
5
|
+
* that is not flagged yet: Chrome flags a GPU process that died a task or
|
|
6
|
+
* so later, which a host drawing more than once a task, or a busy page,
|
|
7
|
+
* may stretch over a few frames.
|
|
8
|
+
*/
|
|
9
|
+
export const LOSS_GRACE_MS = 500;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Which program links that failed are a lost context's (ShaderError.lost):
|
|
13
|
+
* all, while the context is flagged lost; a failure that says nothing,
|
|
14
|
+
* with the context not flagged, only for LOSS_GRACE_MS after the first of
|
|
15
|
+
* a run of them, which a frame drawn without one ends, as does a grace's
|
|
16
|
+
* time passing with none. One that outlives that is a fault of the
|
|
17
|
+
* shaders after all: thrown, or drawn without, as before, till a frame is
|
|
18
|
+
* drawn without a failure.
|
|
19
|
+
*/
|
|
20
|
+
export class LinkLosses {
|
|
21
|
+
private readonly gl: WebGL2RenderingContext;
|
|
22
|
+
/** When the first failure that said nothing came, the context not flagged lost; -1 for none. */
|
|
23
|
+
private since = -1;
|
|
24
|
+
/** When the last came. */
|
|
25
|
+
private last = -1;
|
|
26
|
+
/** Whether the run's failures are taken for the shaders' (concede). */
|
|
27
|
+
private conceded = false;
|
|
28
|
+
/** Whether a failure came in the frame being drawn (endFrame). */
|
|
29
|
+
private failed = false;
|
|
30
|
+
|
|
31
|
+
constructor(gl: WebGL2RenderingContext) {
|
|
32
|
+
this.gl = gl;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Whether `e` is taken for a lost context's (see the class). */
|
|
36
|
+
lost(e: unknown): e is ShaderError {
|
|
37
|
+
if (!lostShader(e)) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (this.gl.isContextLost()) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const now = performance.now();
|
|
46
|
+
this.failed = true;
|
|
47
|
+
if (this.conceded) {
|
|
48
|
+
this.last = now;
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// A failure a grace after the last, as after work given up on and nothing drawn since, starts
|
|
53
|
+
// a run of its own: a loss long after a fault is a loss.
|
|
54
|
+
if (this.since < 0 || now - this.last >= LOSS_GRACE_MS) {
|
|
55
|
+
this.since = now;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
this.last = now;
|
|
59
|
+
return now - this.since < LOSS_GRACE_MS;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Whether a failure taken for a loss has outlived the grace, the context still not flagged lost. */
|
|
63
|
+
get expired(): boolean {
|
|
64
|
+
return this.since < 0 || performance.now() - this.since >= LOSS_GRACE_MS;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The run's failures taken for the shaders', its grace over with the
|
|
69
|
+
* context not flagged lost: those that follow too, till a frame is drawn
|
|
70
|
+
* without one, which ends the run (WebGLBackend.resume).
|
|
71
|
+
*/
|
|
72
|
+
concede(): void {
|
|
73
|
+
this.conceded = true;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** A frame drawn whole: one without a failure ends the run. */
|
|
77
|
+
endFrame(): void {
|
|
78
|
+
if (!this.failed) {
|
|
79
|
+
this.since = -1;
|
|
80
|
+
this.conceded = false;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
this.failed = false;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The context restored: what failed before was its loss. */
|
|
87
|
+
clear(): void {
|
|
88
|
+
this.since = -1;
|
|
89
|
+
this.conceded = false;
|
|
90
|
+
this.failed = false;
|
|
91
|
+
}
|
|
92
|
+
}
|
package/src/webgl/precompile.ts
CHANGED
|
@@ -163,8 +163,10 @@ export class ProgramQueue {
|
|
|
163
163
|
try {
|
|
164
164
|
program = endProgram(this.gl, job.pending as PendingProgram);
|
|
165
165
|
} catch (e) {
|
|
166
|
-
// A program that does not link is linked again as it is needed, which says why
|
|
167
|
-
|
|
166
|
+
// A program that does not link is linked again as it is needed, which says why, or gives
|
|
167
|
+
// up on the frame where the context is lost unflagged (WebGLBackend.gaveUp); one on a
|
|
168
|
+
// context flagged lost gives up on it now.
|
|
169
|
+
if (e instanceof ShaderError && !this.gl.isContextLost()) {
|
|
168
170
|
return false;
|
|
169
171
|
}
|
|
170
172
|
|