@null3d/engine 0.1.2 → 0.1.3

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.
Files changed (49) hide show
  1. package/dist/wasm/single/null3d.js +4 -4
  2. package/dist/wasm/single/null3d_bg.wasm +0 -0
  3. package/dist/wasm/threaded/null3d.js +4 -4
  4. package/dist/wasm/threaded/null3d_bg.wasm +0 -0
  5. package/docs/api/reference/engine.md +1 -1
  6. package/docs/cli/null3d.md +60 -4
  7. package/docs/concepts/quality-presets.md +2 -0
  8. package/docs/errors/E1404.md +5 -1
  9. package/docs/getting-started/cdn.md +1 -1
  10. package/docs/getting-started/first-scene.md +3 -1
  11. package/docs/getting-started/hosting.md +11 -3
  12. package/docs/getting-started/install.md +20 -0
  13. package/docs/getting-started/project-structure.md +1 -1
  14. package/docs/guides/agents.md +1 -1
  15. package/docs/guides/assets-pipeline.md +31 -6
  16. package/docs/guides/debugging.md +2 -0
  17. package/docs/guides/deploying.md +1 -1
  18. package/docs/guides/deterministic-simulation.md +5 -2
  19. package/docs/guides/performance.md +2 -0
  20. package/docs/guides/start-time.md +2 -0
  21. package/docs/guides/testing.md +20 -0
  22. package/docs/pages.md +1 -1
  23. package/docs/porting/verification.md +1 -1
  24. package/lib/errors/codes.js +6 -0
  25. package/lib/errors/fixes.js +1 -1
  26. package/lib/gpu/device-shaders.d.ts +5 -0
  27. package/lib/gpu/device-shaders.js +10 -1
  28. package/lib/gpu/variants.d.ts +25 -0
  29. package/lib/gpu/variants.js +75 -5
  30. package/lib/gpu/webgl2/backend.d.ts +22 -3
  31. package/lib/gpu/webgl2/backend.js +108 -22
  32. package/lib/gpu/webgl2/programs.d.ts +5 -0
  33. package/lib/gpu/webgl2/programs.js +25 -2
  34. package/lib/gpu/webgpu/backend.d.ts +34 -1
  35. package/lib/gpu/webgpu/backend.js +173 -27
  36. package/lib/gpu/webgpu/pipelines.d.ts +2 -2
  37. package/lib/gpu/webgpu/pipelines.js +15 -15
  38. package/lib/page/engine.js +62 -3
  39. package/lib/page/permutation-recording.d.ts +5 -3
  40. package/lib/page/permutation-recording.js +13 -7
  41. package/lib/quality/chooser.d.ts +2 -0
  42. package/lib/quality/chooser.js +4 -0
  43. package/lib/shader-artifact.json +1 -1
  44. package/lib/shared/version.d.ts +1 -1
  45. package/lib/shared/version.js +1 -1
  46. package/lib/workers/protocol.d.ts +29 -0
  47. package/lib/workers/render-worker.js +6 -3
  48. package/lib/workers/sketch-worker.js +6 -3
  49. package/package.json +1 -1
@@ -19,22 +19,70 @@ function exactly(shader, permutation, target) {
19
19
  * build then builds.
20
20
  */
21
21
  let recorded;
22
+ /** Hears each word that a recording adds, so a live page streams its growing set to its tool. */
23
+ let recordedSink;
22
24
  /**
23
25
  * The bits that a device fixes when it starts, which a recorded word leaves out. One list then
24
26
  * serves every device module, and a build makes the word's builds for each value of those bits.
25
27
  */
26
28
  const DEVICE_BITS = PERMUTATION_DRAW_INDEX | PERMUTATION_TONE_MAP | PERMUTATION_HALF;
29
+ /** The word as a list writes it: without the bits that a device fixes. */
30
+ export function listedWord(permutation) {
31
+ return (permutation & ~DEVICE_BITS) >>> 0;
32
+ }
33
+ /**
34
+ * The error for a pipeline whose loaded shader set has no variant that it asks for. Its `word` is
35
+ * the word as a list writes it, which names the entry to add.
36
+ */
37
+ export class MissingVariantError extends Error {
38
+ word;
39
+ constructor(word, message) {
40
+ super(message);
41
+ this.word = word;
42
+ this.name = 'MissingVariantError';
43
+ }
44
+ }
45
+ /** Hears each pipeline or pass whose variant the loaded shader set lacks, so it can skip. */
46
+ let missingSink;
47
+ /**
48
+ * @internal Hears each pipeline or pass whose shader variant the loaded set lacks. The drawing
49
+ * thread sets this to publish the word, and the page logs one warning for it. A production build
50
+ * keeps the report, because a narrowed production build is where it matters.
51
+ */
52
+ export function receiveMissingVariants(sink) {
53
+ missingSink = sink;
54
+ }
55
+ /** Reports a pipeline or pass whose shader variant the loaded set lacks, for it to skip. */
56
+ export function reportMissingVariant(pipeline, word) {
57
+ missingSink?.(pipeline, word);
58
+ }
59
+ /** Hears each pipeline or pass whose shader file failed to load, so it can skip. */
60
+ let unavailableSink;
61
+ /**
62
+ * @internal Hears each pipeline or pass whose shader file failed to load. The drawing thread sets
63
+ * this to report the failure, and the page logs one warning for it.
64
+ */
65
+ export function receiveUnavailableShaders(sink) {
66
+ unavailableSink = sink;
67
+ }
68
+ /** Reports a pipeline or pass whose shader file failed to load, for it to skip. */
69
+ export function reportUnavailableShader(pipeline, reason) {
70
+ unavailableSink?.(pipeline, reason);
71
+ }
27
72
  /**
28
73
  * @internal Starts collecting the permutation words that the pipelines ask for, until
29
- * [`stopRecordingPermutations`]. A word that a pipeline found is added once.
74
+ * [`stopRecordingPermutations`]. A word that a pipeline found is added once, and `onWord` hears
75
+ * each one as it arrives so a live page streams its growing set to its tool.
30
76
  */
31
- export function recordPermutations() {
77
+ export function recordPermutations(onWord) {
32
78
  recorded = new Set();
79
+ recordedSink = onWord;
33
80
  }
34
81
  /** @internal Stops collecting, and gives the words collected since, in order. */
35
82
  export function stopRecordingPermutations() {
36
83
  const words = [...(recorded ?? [])].sort((a, b) => a - b);
37
84
  recorded = undefined;
85
+ recordedSink = undefined;
38
86
  return words;
39
87
  }
40
88
  /**
@@ -66,8 +114,11 @@ export function variantFor(shader, permutation, target) {
66
114
  // bits a device fixes are left out, so one list holds the words of every device module.
67
115
  // A development build reports the same words to the dev server.
68
116
  if (found !== undefined) {
69
- const word = (permutation & ~DEVICE_BITS) >>> 0;
70
- recorded?.add(word);
117
+ const word = listedWord(permutation);
118
+ if (recorded !== undefined && !recorded.has(word)) {
119
+ recorded.add(word);
120
+ recordedSink?.(word);
121
+ }
71
122
  if (DEV && reporting !== undefined && !reporting.words.has(word)) {
72
123
  reporting.words.add(word);
73
124
  reporting.report(word);
@@ -84,7 +135,7 @@ export function variantFor(shader, permutation, target) {
84
135
  export function missingVariant(permutation, listed = LISTED_PERMUTATIONS !== null) {
85
136
  if (!listed)
86
137
  return `the shader set has no variant for the permutation word 0x${(permutation >>> 0).toString(16)}.`;
87
- const word = `0x${((permutation & ~DEVICE_BITS) >>> 0).toString(16).padStart(8, '0')}`;
138
+ const word = `0x${listedWord(permutation).toString(16).padStart(8, '0')}`;
88
139
  return `the shader set holds only the permutation words of the project's shader list, and this pipeline asks for ${word}, which the list lacks. Record the pages again with bunx @null3d/cli shaders record so that the word reaches the list, or add ${word} to the list by hand, and build again.`;
89
140
  }
90
141
  /**
@@ -97,3 +148,22 @@ export function missingShader(name, permutation, listed = LISTED_PERMUTATIONS !=
97
148
  ? `the ${name} shader is missing: ${missingVariant(permutation, true)}`
98
149
  : `the device's shader modules have no ${name} shader`;
99
150
  }
151
+ /**
152
+ * The error for an engine pass whose shader the loaded set lacks. Its `word` is the word as a list
153
+ * writes it, and `shader` names the pass's shader for a report.
154
+ */
155
+ export class MissingShaderError extends Error {
156
+ shader;
157
+ word;
158
+ constructor(shader, word, message) {
159
+ super(message);
160
+ this.shader = shader;
161
+ this.word = word;
162
+ this.name = 'MissingShaderError';
163
+ }
164
+ }
165
+ /** The error for the engine pass of `name` whose shader the loaded set lacks. */
166
+ export function missingShaderError(name, permutation, listed = LISTED_PERMUTATIONS !== null) {
167
+ const word = listed ? listedWord(permutation) : permutation >>> 0;
168
+ return new MissingShaderError(name, word, missingShader(name, permutation, listed));
169
+ }
@@ -1,7 +1,7 @@
1
1
  import type { DeviceShaders, FirstUseShaders } from '../../generated/shaders.js';
2
2
  import type { DepthMode } from '../../page/switches.js';
3
3
  import { ImageTable } from '../../shared/images.js';
4
- import type { DeviceShaderSet } from '../device-shaders.js';
4
+ import { type DeviceShaderSet } from '../device-shaders.js';
5
5
  import { JoinedBuilds } from '../effect-join.js';
6
6
  import { GpuMemory } from '../memory.js';
7
7
  import type { ReadSink } from '../readback.js';
@@ -52,6 +52,8 @@ export declare class WebGL2Backend {
52
52
  private readonly pipelines;
53
53
  /** The programs of the templates and permutations in use, which their pipelines share. */
54
54
  private readonly programs;
55
+ /** The spare programs whose shader variant the loaded set lacks, by key. */
56
+ private readonly spareMissing;
55
57
  private readonly templates;
56
58
  /** The template of the program that draws mip levels. */
57
59
  private readonly mipTemplate;
@@ -330,7 +332,11 @@ export declare class WebGL2Backend {
330
332
  * stop.
331
333
  */
332
334
  takeListing(): Uint32Array | undefined;
333
- /** Creates each parked pipeline whose custom material's shader has arrived. */
335
+ /**
336
+ * Creates each parked pipeline whose custom material's shader has arrived. A pipeline whose
337
+ * shader file failed to load is dropped, with a drawer that draws nothing, so no frame waits
338
+ * for it.
339
+ */
334
340
  private unpark;
335
341
  /**
336
342
  * True once a program may be used without waiting: it has compiled and linked, or failed to, or
@@ -343,6 +349,13 @@ export declare class WebGL2Backend {
343
349
  * for it.
344
350
  */
345
351
  private createPipeline;
352
+ /** Stores the pipeline of a create command that draws with `program`. */
353
+ private installPipeline;
354
+ /**
355
+ * A stand-in for a pipeline whose shader file did not load. Its draws draw nothing, as a
356
+ * pipeline that the driver refused twice does, and the engine warns once.
357
+ */
358
+ private unavailableProgram;
346
359
  resetCounts(): void;
347
360
  /** Counts a draw of `count` vertices or indices, `instances` times, with the current pipeline. */
348
361
  private countDraw;
@@ -369,9 +382,15 @@ export declare class WebGL2Backend {
369
382
  private prebuildSparePrograms;
370
383
  /**
371
384
  * The program that draws mip levels, or the one that copies a layer, in use. Its first use
372
- * waits for its link when the driver has not finished it.
385
+ * waits for its link when the driver has not finished it. Undefined when the loaded set lacks
386
+ * its shader, which skips the pass.
373
387
  */
374
388
  private spareProgram;
389
+ /**
390
+ * The program that draws mip levels, copies a layer or scales a texture, or undefined when the
391
+ * loaded set lacks its variant, which the engine reports once.
392
+ */
393
+ private spareProgramFor;
375
394
  /**
376
395
  * Puts a program of the scene's objects in use, as `useProgram` does, and returns true. A link
377
396
  * that the driver refused links once more, from new shaders: a driver can run short of memory
@@ -21,16 +21,17 @@
21
21
  import * as G from '../../generated/gpu.js';
22
22
  import { DEV } from '../../shared/dev.js';
23
23
  import { ImageTable } from '../../shared/images.js';
24
+ import { ShaderLoadError } from '../device-shaders.js';
24
25
  import { EarlyBuilds, PipelineListing } from '../early-builds.js';
25
26
  import { JoinedBuilds, joinedReady } from '../effect-join.js';
26
27
  import { CLOUD_FIELD_WORD, CLOUD_STEPS_WORD, LAYER_WORD, LIGHT_BUFFER_WORD, } from '../environment-words.js';
27
28
  import { floatOfBits } from '../float-bits.js';
28
29
  import { GpuMemory, textureBytes } from '../memory.js';
29
30
  import { pipelineName } from '../pipeline-name.js';
30
- import { variantFor } from '../variants.js';
31
+ import { MissingVariantError, reportMissingVariant, reportUnavailableShader, variantFor, } from '../variants.js';
31
32
  import { forEachFallbackAttribute, forEachVertexAttribute, isNormalized, vertexStride, } from '../vertex-format.js';
32
33
  import { setDepthMode } from './depth.js';
33
- import { buildPermutation, createProgram, customTemplate, engineTemplates, LinkFailure, linkLogs, metalFault, mipmapTemplate, prepareProgram, programHost, relink, slotOf, UPLOAD_UNIT, } from './programs.js';
34
+ import { buildPermutation, createProgram, customTemplate, engineTemplates, LinkFailure, linkLogs, metalFault, mipmapTemplate, prepareProgram, programHost, refusedProgram, relink, slotOf, UPLOAD_UNIT, } from './programs.js';
34
35
  /** The unit that the mip level shader samples: its source texture's group 0, binding 0. */
35
36
  const MIP_UNIT = 0;
36
37
  /** The key of the mip level program among the programs of pipelines. */
@@ -303,6 +304,8 @@ export class WebGL2Backend {
303
304
  pipelines = [];
304
305
  /** The programs of the templates and permutations in use, which their pipelines share. */
305
306
  programs = new Map();
307
+ /** The spare programs whose shader variant the loaded set lacks, by key. */
308
+ spareMissing = new Set();
306
309
  templates;
307
310
  /** The template of the program that draws mip levels. */
308
311
  mipTemplate;
@@ -804,10 +807,28 @@ export class WebGL2Backend {
804
807
  this.early = undefined;
805
808
  return this.listing.take();
806
809
  }
807
- /** Creates each parked pipeline whose custom material's shader has arrived. */
810
+ /**
811
+ * Creates each parked pipeline whose custom material's shader has arrived. A pipeline whose
812
+ * shader file failed to load is dropped, with a drawer that draws nothing, so no frame waits
813
+ * for it.
814
+ */
808
815
  unpark() {
809
816
  for (const [id, operands] of this.parked) {
810
- if (!this.templateReady(operands[1], operands[2]))
817
+ const template = operands[1];
818
+ const permutation = operands[2];
819
+ let ready;
820
+ try {
821
+ ready = this.templateReady(template, permutation);
822
+ }
823
+ catch (error) {
824
+ if (!(error instanceof ShaderLoadError))
825
+ throw error;
826
+ this.parked.delete(id);
827
+ this.counts.pipelines--;
828
+ this.installPipeline(operands, 0, this.unavailableProgram(template, permutation, error));
829
+ continue;
830
+ }
831
+ if (!ready)
811
832
  continue;
812
833
  this.parked.delete(id);
813
834
  this.counts.pipelines--;
@@ -832,19 +853,32 @@ export class WebGL2Backend {
832
853
  */
833
854
  createPipeline(words, a, background) {
834
855
  const template = words[a + 1];
835
- const flags = words[a + 6];
836
- if (!this.templateReady(template, words[a + 2])) {
837
- // The command's header, before its operands, gives its length in words.
838
- this.parked.set(words[a], words.slice(a, a - 1 + (words[a - 1] >>> 8)));
839
- this.counts.pipelines++;
840
- return;
856
+ const permutation = words[a + 2];
857
+ try {
858
+ if (!this.templateReady(template, permutation)) {
859
+ // The command's header, before its operands, gives its length in words.
860
+ this.parked.set(words[a], words.slice(a, a - 1 + (words[a - 1] >>> 8)));
861
+ this.counts.pipelines++;
862
+ return;
863
+ }
864
+ this.installPipeline(words, a, this.programOf(template, permutation, background));
841
865
  }
866
+ catch (error) {
867
+ if (!(error instanceof ShaderLoadError))
868
+ throw error;
869
+ this.installPipeline(words, a, this.unavailableProgram(template, permutation, error));
870
+ }
871
+ }
872
+ /** Stores the pipeline of a create command that draws with `program`. */
873
+ installPipeline(words, a, program) {
874
+ const template = words[a + 1];
875
+ const flags = words[a + 6];
842
876
  const depth = words[a + 4] !== G.FORMAT_NONE;
843
877
  // The list's bias is in reversed depth. Standard depth stores the near plane as 0, so a bias
844
878
  // toward the camera turns negative there.
845
879
  const sign = this.depth.standard ? -1 : 1;
846
880
  this.pipelines[words[a]] = {
847
- program: this.programOf(template, words[a + 2], background),
881
+ program,
848
882
  cull: this.cullOf(flags),
849
883
  depth,
850
884
  depthWrite: depth && (flags & (G.STATE_NO_DEPTH_WRITE | G.STATE_NO_DEPTH_TEST)) === 0,
@@ -856,10 +890,20 @@ export class WebGL2Backend {
856
890
  offsetFactor: sign * floatOfBits(words[a + 9]),
857
891
  vertexFormat: words[a + 7],
858
892
  mode: flags & G.STATE_LINE_LIST ? this.gl.LINES : this.gl.TRIANGLES,
859
- vertices: this.need(this.templates, template, 'render pipeline template').vertices,
893
+ vertices: this.templates[template]?.vertices,
860
894
  };
861
895
  this.counts.pipelines++;
862
896
  }
897
+ /**
898
+ * A stand-in for a pipeline whose shader file did not load. Its draws draw nothing, as a
899
+ * pipeline that the driver refused twice does, and the engine warns once.
900
+ */
901
+ unavailableProgram(template, permutation, error) {
902
+ reportUnavailableShader(pipelineName(template, permutation), error.message);
903
+ if (this.joins.joined(template))
904
+ this.joins.failed(template, error);
905
+ return refusedProgram(this.gl, template, permutation);
906
+ }
863
907
  resetCounts() {
864
908
  this.counts.uploadBytes = 0;
865
909
  this.counts.drawCalls = 0;
@@ -1157,13 +1201,33 @@ export class WebGL2Backend {
1157
1201
  }
1158
1202
  /**
1159
1203
  * The program that draws mip levels, or the one that copies a layer, in use. Its first use
1160
- * waits for its link when the driver has not finished it.
1204
+ * waits for its link when the driver has not finished it. Undefined when the loaded set lacks
1205
+ * its shader, which skips the pass.
1161
1206
  */
1162
1207
  spareProgram(key) {
1163
- const program = this.spareProgramOf(key);
1164
- this.useProgram(program);
1208
+ const program = this.spareProgramFor(key);
1209
+ if (program)
1210
+ this.useProgram(program);
1165
1211
  return program;
1166
1212
  }
1213
+ /**
1214
+ * The program that draws mip levels, copies a layer or scales a texture, or undefined when the
1215
+ * loaded set lacks its variant, which the engine reports once.
1216
+ */
1217
+ spareProgramFor(key) {
1218
+ if (this.spareMissing.has(key))
1219
+ return undefined;
1220
+ try {
1221
+ return this.spareProgramOf(key);
1222
+ }
1223
+ catch (error) {
1224
+ if (!(error instanceof MissingVariantError))
1225
+ throw error;
1226
+ this.spareMissing.add(key);
1227
+ reportMissingVariant(`the ${key} shader`, error.word);
1228
+ return undefined;
1229
+ }
1230
+ }
1167
1231
  /**
1168
1232
  * Puts a program of the scene's objects in use, as `useProgram` does, and returns true. A link
1169
1233
  * that the driver refused links once more, from new shaders: a driver can run short of memory
@@ -1239,7 +1303,21 @@ export class WebGL2Backend {
1239
1303
  let program = this.programs.get(key);
1240
1304
  if (!program) {
1241
1305
  const glsl = this.need(this.templates, template, 'render pipeline template');
1242
- program = createProgram(this.gl, glsl, permutation);
1306
+ try {
1307
+ program = createProgram(this.gl, glsl, permutation);
1308
+ }
1309
+ catch (error) {
1310
+ // A pipeline whose word the loaded set lacks skips its draws, as one the driver
1311
+ // refused twice does. A joined shader's effects fall back to a pass each.
1312
+ if (!(error instanceof MissingVariantError))
1313
+ throw error;
1314
+ program = refusedProgram(this.gl, template, permutation);
1315
+ reportMissingVariant(pipelineName(template, permutation), error.word);
1316
+ if (this.joins.joined(template))
1317
+ this.joins.failed(template, error);
1318
+ this.programs.set(key, program);
1319
+ return program;
1320
+ }
1243
1321
  this.programs.set(key, program);
1244
1322
  const joined = this.joins.joined(template)
1245
1323
  ? { template, start: performance.now(), failed: false }
@@ -1763,6 +1841,8 @@ export class WebGL2Backend {
1763
1841
  return;
1764
1842
  }
1765
1843
  const program = this.beginSpareDraws(MIP_PROGRAM, texture, texture.format, texture.width, texture.height);
1844
+ if (!program)
1845
+ return;
1766
1846
  const count = levels === 0 ? texture.mips : Math.min(levels, texture.mips);
1767
1847
  for (let level = 1; level < count; level++) {
1768
1848
  const width = Math.max(1, texture.width >> level);
@@ -1788,6 +1868,8 @@ export class WebGL2Backend {
1788
1868
  const source = this.textureOf(sourceId);
1789
1869
  const dest = this.textureOf(destId);
1790
1870
  const program = this.beginSpareDraws(SCALE_PROGRAM, source, dest.format, size, size);
1871
+ if (!program)
1872
+ return;
1791
1873
  this.drawScaleIntoSpare(program, source, size | (sourceLayer << SCALE_SIZE_BITS), size, size);
1792
1874
  this.copyFromSpare(dest, 0, 0, 0, destLayer, 0, 0, size, size);
1793
1875
  this.endSpareDraws(source, dest.format);
@@ -1888,9 +1970,11 @@ export class WebGL2Backend {
1888
1970
  * takes the format of what the draws go into, which a scale draw writes into another texture.
1889
1971
  */
1890
1972
  beginSpareDraws(key, source, format, width, height) {
1973
+ const program = this.spareProgram(key);
1974
+ if (!program)
1975
+ return undefined;
1891
1976
  const gl = this.gl;
1892
1977
  const spare = this.spareOf(format, width, height);
1893
- const program = this.spareProgram(key);
1894
1978
  if (!this.mipFramebuffer)
1895
1979
  this.mipFramebuffer = gl.createFramebuffer();
1896
1980
  if (!this.mipSampler) {
@@ -2028,12 +2112,14 @@ export class WebGL2Backend {
2028
2112
  const right = sourceX + width;
2029
2113
  const top = sourceY + height;
2030
2114
  const program = this.beginSpareDraws(COPY_PROGRAM, source, source.format, right, top);
2031
- for (let k = 0; k < layers; k++) {
2032
- this.drawIntoSpare(program, source, sourceLevel, sourceLayer + k, right, top);
2033
- this.copyFromSpare(destination, level, x, y, layer + k, sourceX, sourceY, width, height);
2115
+ if (program) {
2116
+ for (let k = 0; k < layers; k++) {
2117
+ this.drawIntoSpare(program, source, sourceLevel, sourceLayer + k, right, top);
2118
+ this.copyFromSpare(destination, level, x, y, layer + k, sourceX, sourceY, width, height);
2119
+ }
2120
+ this.endSpareDraws(source, source.format);
2121
+ return;
2034
2122
  }
2035
- this.endSpareDraws(source, source.format);
2036
- return;
2037
2123
  }
2038
2124
  if (!this.copyFramebuffer)
2039
2125
  this.copyFramebuffer = gl.createFramebuffer();
@@ -157,6 +157,11 @@ export declare function mipmapTemplate(shaders: DeviceShaders, pipeline: 'main'
157
157
  * shader of its build with the prepass's fragment shader.
158
158
  */
159
159
  export declare function createProgram(gl: WebGL2RenderingContext, template: GlslTemplate, permutation: number): Program;
160
+ /**
161
+ * A stand-in for a program of a mesh template whose shader variant the loaded set lacks. Its draws
162
+ * draw nothing, as a program that the driver refused twice does, so the rest of the scene draws.
163
+ */
164
+ export declare function refusedProgram(gl: WebGL2RenderingContext, template: number, permutation: number): Program;
160
165
  /**
161
166
  * The names that a GLSL source declares as uniforms or uniform blocks. One walk of the source
162
167
  * answers every name, so a check over a program's whole reflection costs a scan beside a scan
@@ -16,7 +16,7 @@ import { PERMUTATION_PREPASS, TEMPLATE_ACCUMULATE, TEMPLATE_AO, TEMPLATE_AO_DENO
16
16
  import { DEBUG_LINES_SHADER, DEBUG_VIEW_SHADER, DEPTH_MAPPING_UNIFORM, MOTION_VIEW_SHADER, } from '../../generated/shaders.js';
17
17
  import { LINE_VERTICES } from '../line-vertices.js';
18
18
  import { PARTICLE_RECORDS } from '../particle-records.js';
19
- import { missingVariant, variantFor } from '../variants.js';
19
+ import { listedWord, MissingVariantError, missingVariant, variantFor } from '../variants.js';
20
20
  /**
21
21
  * True in development builds, which add the debug views' templates. This file reads the constant
22
22
  * itself, as the files that load on first use do. It loads with its GPU path's renderers, apart from
@@ -289,7 +289,7 @@ export function createProgram(gl, template, permutation) {
289
289
  const shading = variantFor(template.shader, build, 'glsl')?.glsl?.[template.pipeline];
290
290
  const source = shading && build !== permutation ? { ...shading, fragment: PREPASS_FRAGMENT } : shading;
291
291
  if (!source)
292
- throw new Error(`a render pipeline template: ${missingVariant(build)}`);
292
+ throw new MissingVariantError(listedWord(build), `a render pipeline template: ${missingVariant(build)}`);
293
293
  const { program, shaders } = link(gl, source, '');
294
294
  return {
295
295
  program,
@@ -302,6 +302,29 @@ export function createProgram(gl, template, permutation) {
302
302
  background: false,
303
303
  };
304
304
  }
305
+ /**
306
+ * A stand-in for a program of a mesh template whose shader variant the loaded set lacks. Its draws
307
+ * draw nothing, as a program that the driver refused twice does, so the rest of the scene draws.
308
+ */
309
+ export function refusedProgram(gl, template, permutation) {
310
+ const program = gl.createProgram();
311
+ if (!program)
312
+ throw new Error('WebGL2 could not create a program');
313
+ return {
314
+ program,
315
+ source: {
316
+ vertex: { source: '', uniformBlocks: [], textures: [] },
317
+ fragment: { source: '', uniformBlocks: [], textures: [] },
318
+ },
319
+ shaders: [],
320
+ firstInstance: null,
321
+ firstInstanceValue: 0,
322
+ textureUnits: [],
323
+ ready: true,
324
+ background: false,
325
+ objects: { template, permutation, refused: true },
326
+ };
327
+ }
305
328
  /** The head of a uniform declaration, with the text between it and the declaration's end. */
306
329
  const DECLARATION = /^\s*(?:layout\([^)]*\)\s*)?uniform\b([^;{]*)/gm;
307
330
  /** A word of a declaration, which is a name that the source declares. */
@@ -1,6 +1,6 @@
1
1
  import type { DeviceShaders, FirstUseShaders } from '../../generated/shaders.js';
2
2
  import { ImageTable } from '../../shared/images.js';
3
- import type { DeviceShaderSet } from '../device-shaders.js';
3
+ import { type DeviceShaderSet } from '../device-shaders.js';
4
4
  import { JoinedBuilds } from '../effect-join.js';
5
5
  import { GpuMemory } from '../memory.js';
6
6
  import type { ReadSink } from '../readback.js';
@@ -40,6 +40,10 @@ export declare class WebGPUBackend {
40
40
  private readonly ownsImages;
41
41
  /** The sampler that mip levels read the level before them with. */
42
42
  private mipSampler;
43
+ /** True once the loaded set showed that it lacks the shader that makes mip levels. */
44
+ private mipMissing;
45
+ /** True once the loaded set showed that it lacks the shader that scales a texture into another. */
46
+ private scaleMissing;
43
47
  /** What making each texture's mip levels draws with, by texture id, once it made them. */
44
48
  private readonly mipChains;
45
49
  /**
@@ -254,6 +258,16 @@ export declare class WebGPUBackend {
254
258
  private copyTexture;
255
259
  /** Bytes of one block of texels of a texture: one texel unless its format is compressed. */
256
260
  private blockBytes;
261
+ /**
262
+ * The pipeline that makes mip levels of textures of `format`, or undefined when its shader is
263
+ * absent, which leaves the levels as they are. The engine reports the cause once.
264
+ */
265
+ private mipPipeline;
266
+ /**
267
+ * The pipeline that draws a texture into the corner of another, or undefined when its shader is
268
+ * absent, which leaves the image as it is. The engine reports the cause once.
269
+ */
270
+ private scalePipeline;
257
271
  /**
258
272
  * Makes mip levels 1 and up of one layer of a texture array, a render pass per level. Each pass
259
273
  * draws into its level of the layer, and reads the level before it through a view of every
@@ -402,6 +416,25 @@ export declare class WebGPUBackend {
402
416
  * operands at `a`: in the background when `background` is set, else at once.
403
417
  */
404
418
  private createPipeline;
419
+ /**
420
+ * The render pipeline's descriptor, or null when the loaded shader set lacks its variant, for a
421
+ * template that draws the scene's meshes or a full-screen pass. Its draws then draw nothing, as
422
+ * a pipeline that the driver refused twice does. A joined shader's effects fall back to a pass
423
+ * each.
424
+ */
425
+ private describedRender;
426
+ /**
427
+ * Reports a shader that is absent or that failed to load, and returns true for either. A word
428
+ * that the loaded set lacks goes to the page's report, and a file that did not load goes to its
429
+ * warning. Any other error returns false, and the caller rethrows it as the engine fault it is.
430
+ */
431
+ private reportUnavailable;
432
+ /**
433
+ * Marks the pipeline of a create command as unavailable when its shader is absent or did not
434
+ * load: its draws or dispatches do nothing, and the engine reports the cause once. A joined
435
+ * shader's effects fall back to a pass each. Returns false for any other error.
436
+ */
437
+ private unavailable;
405
438
  /**
406
439
  * Hears that a render pipeline did not build. A pipeline of the scene's objects that the GPU's
407
440
  * driver refused waits for its retry, and still counts as building. Any other failure, such as