@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
@@ -7,12 +7,13 @@ import * as G from '../../generated/gpu.js';
7
7
  import { DEV } from '../../shared/dev.js';
8
8
  import { ImageTable } from '../../shared/images.js';
9
9
  import { DROP_COUNTED_LABEL } from '../../shared/metrics.js';
10
+ import { ShaderLoadError } from '../device-shaders.js';
10
11
  import { EarlyBuilds, keyOf, PipelineListing } from '../early-builds.js';
11
12
  import { JoinedBuilds, joinedReady } from '../effect-join.js';
12
13
  import { CLOUD_FIELD_WORD, CLOUD_STEPS_WORD, LAYER_WORD, LIGHT_BUFFER_WORD, } from '../environment-words.js';
13
14
  import { floatOfBits } from '../float-bits.js';
14
15
  import { GpuMemory, textureBytes } from '../memory.js';
15
- import { variantFor } from '../variants.js';
16
+ import { MissingShaderError, MissingVariantError, reportMissingVariant, reportUnavailableShader, variantFor, } from '../variants.js';
16
17
  import { BufferReads } from './buffer-reads.js';
17
18
  import { IndirectArguments } from './indirect-arguments.js';
18
19
  import { Pipelines, SKIN_BUILDS } from './pipelines.js';
@@ -151,6 +152,10 @@ export class WebGPUBackend {
151
152
  ownsImages;
152
153
  /** The sampler that mip levels read the level before them with. */
153
154
  mipSampler;
155
+ /** True once the loaded set showed that it lacks the shader that makes mip levels. */
156
+ mipMissing = false;
157
+ /** True once the loaded set showed that it lacks the shader that scales a texture into another. */
158
+ scaleMissing = false;
154
159
  /** What making each texture's mip levels draws with, by texture id, once it made them. */
155
160
  mipChains = [];
156
161
  /**
@@ -585,6 +590,40 @@ export class WebGPUBackend {
585
590
  blockBytes(id) {
586
591
  return G.FORMAT_BLOCK_BYTES[this.formats[id]] ?? 0;
587
592
  }
593
+ /**
594
+ * The pipeline that makes mip levels of textures of `format`, or undefined when its shader is
595
+ * absent, which leaves the levels as they are. The engine reports the cause once.
596
+ */
597
+ mipPipeline(format) {
598
+ if (this.mipMissing)
599
+ return undefined;
600
+ try {
601
+ return this.pipelines.mipmaps(format);
602
+ }
603
+ catch (error) {
604
+ if (!this.reportUnavailable(error, 'the mip level shader'))
605
+ throw error;
606
+ this.mipMissing = true;
607
+ return undefined;
608
+ }
609
+ }
610
+ /**
611
+ * The pipeline that draws a texture into the corner of another, or undefined when its shader is
612
+ * absent, which leaves the image as it is. The engine reports the cause once.
613
+ */
614
+ scalePipeline(format) {
615
+ if (this.scaleMissing)
616
+ return undefined;
617
+ try {
618
+ return this.pipelines.mipScale(format);
619
+ }
620
+ catch (error) {
621
+ if (!this.reportUnavailable(error, 'the mip scale shader'))
622
+ throw error;
623
+ this.scaleMissing = true;
624
+ return undefined;
625
+ }
626
+ }
588
627
  /**
589
628
  * Makes mip levels 1 and up of one layer of a texture array, a render pass per level. Each pass
590
629
  * draws into its level of the layer, and reads the level before it through a view of every
@@ -595,7 +634,9 @@ export class WebGPUBackend {
595
634
  */
596
635
  generateMipmaps(id, layer, levels = 0) {
597
636
  const texture = this.need(this.textures, id, 'texture');
598
- const pipeline = this.pipelines.mipmaps(texture.format);
637
+ const pipeline = this.mipPipeline(texture.format);
638
+ if (!pipeline)
639
+ return;
599
640
  let chain = this.mipChains[id];
600
641
  if (!chain || chain.layer !== layer || chain.pipeline !== pipeline)
601
642
  chain = this.mipChains[id] = this.mipChain(texture, pipeline, layer);
@@ -625,7 +666,9 @@ export class WebGPUBackend {
625
666
  const levels = words[a + 5];
626
667
  const source = this.need(this.textures, sourceId, 'texture');
627
668
  const dest = this.need(this.textures, destId, 'texture');
628
- const pipeline = this.pipelines.mipScale(dest.format);
669
+ const pipeline = this.scalePipeline(dest.format);
670
+ if (!pipeline)
671
+ return;
629
672
  this.mipSampler ??= this.device.createSampler({ magFilter: 'linear', minFilter: 'linear' });
630
673
  const sourceView = source.createView({
631
674
  dimension: '2d-array',
@@ -1054,10 +1097,17 @@ export class WebGPUBackend {
1054
1097
  for (const build of Object.values(builds))
1055
1098
  if (build.wgsl)
1056
1099
  this.pipelines.prepareModule(name, build.wgsl);
1057
- for (const [template, bits] of compute ?? [])
1058
- this.device
1059
- .createComputePipelineAsync(this.pipelines.compute(template, bits))
1060
- .catch(() => undefined);
1100
+ for (const [template, bits] of compute ?? []) {
1101
+ try {
1102
+ this.device
1103
+ .createComputePipelineAsync(this.pipelines.compute(template, bits))
1104
+ .catch(() => undefined);
1105
+ }
1106
+ catch (error) {
1107
+ if (!this.reportUnavailable(error, `compute pass ${template}`))
1108
+ throw error;
1109
+ }
1110
+ }
1061
1111
  }
1062
1112
  /**
1063
1113
  * Starts to build the pipelines of `list`, a pipeline list of the pipelines that the first frame
@@ -1140,7 +1190,19 @@ export class WebGPUBackend {
1140
1190
  unparkEach(parked, op, ready) {
1141
1191
  for (let k = parked.length - 1; k >= 0; k--) {
1142
1192
  const operands = parked[k];
1143
- if (!ready(operands))
1193
+ let isReady;
1194
+ try {
1195
+ isReady = ready(operands);
1196
+ }
1197
+ catch (error) {
1198
+ if (!this.unavailable(error, op, operands))
1199
+ throw error;
1200
+ parked.splice(k, 1);
1201
+ this.builds--;
1202
+ this.counts.pipelines--;
1203
+ continue;
1204
+ }
1205
+ if (!isReady)
1144
1206
  continue;
1145
1207
  parked.splice(k, 1);
1146
1208
  this.builds--;
@@ -1156,12 +1218,23 @@ export class WebGPUBackend {
1156
1218
  this.counts.pipelines++;
1157
1219
  const id = words[a];
1158
1220
  const device = this.device;
1221
+ const template = words[a + 1];
1222
+ const permutation = words[a + 2];
1159
1223
  if (op === G.OP_CREATE_COMPUTE_PIPELINE) {
1160
- if (!this.computeReady(words[a + 1], words[a + 2])) {
1161
- // Its dispatches do nothing until its shader file arrives and the pipeline builds.
1162
- this.computePipelines[id] = null;
1163
- this.builds++;
1164
- this.parkedCompute.push(words.slice(a, a - 1 + (words[a - 1] >>> 8)));
1224
+ let descriptor;
1225
+ try {
1226
+ if (!this.computeReady(template, permutation)) {
1227
+ // Its dispatches do nothing until its shader file arrives and the pipeline builds.
1228
+ this.computePipelines[id] = null;
1229
+ this.builds++;
1230
+ this.parkedCompute.push(words.slice(a, a - 1 + (words[a - 1] >>> 8)));
1231
+ return;
1232
+ }
1233
+ descriptor = this.pipelines.compute(template, permutation);
1234
+ }
1235
+ catch (error) {
1236
+ if (!this.unavailable(error, op, words.subarray(a)))
1237
+ throw error;
1165
1238
  return;
1166
1239
  }
1167
1240
  const early = background ? this.early?.take(op, words, a) : undefined;
@@ -1172,10 +1245,9 @@ export class WebGPUBackend {
1172
1245
  if (!background) {
1173
1246
  this.computePipelines[id] =
1174
1247
  this.takeAhead(op, words, a) ??
1175
- device.createComputePipeline(this.pipelines.compute(words[a + 1], words[a + 2]));
1248
+ device.createComputePipeline(descriptor);
1176
1249
  return;
1177
1250
  }
1178
- const descriptor = this.pipelines.compute(words[a + 1], words[a + 2]);
1179
1251
  this.computePipelines[id] = null;
1180
1252
  this.builds++;
1181
1253
  this.running++;
@@ -1189,17 +1261,23 @@ export class WebGPUBackend {
1189
1261
  return;
1190
1262
  }
1191
1263
  this.lineLists[id] = (words[a + 6] & G.STATE_LINE_LIST) !== 0;
1192
- if (!this.templateReady(words[a + 1], words[a + 2])) {
1193
- // Its draws draw nothing until the shader arrives and the pipeline builds.
1194
- this.renderPipelines[id] = null;
1195
- this.builds++;
1196
- // The command's header, before its operands, gives its length in words.
1197
- this.parked.push(words.slice(a, a - 1 + (words[a - 1] >>> 8)));
1264
+ try {
1265
+ if (!this.templateReady(template, permutation)) {
1266
+ // Its draws draw nothing until the shader arrives and the pipeline builds.
1267
+ this.renderPipelines[id] = null;
1268
+ this.builds++;
1269
+ // The command's header, before its operands, gives its length in words.
1270
+ this.parked.push(words.slice(a, a - 1 + (words[a - 1] >>> 8)));
1271
+ return;
1272
+ }
1273
+ }
1274
+ catch (error) {
1275
+ if (!this.unavailable(error, op, words.subarray(a)))
1276
+ throw error;
1198
1277
  return;
1199
1278
  }
1200
1279
  // A joined shader always builds in the background, so a frame never waits for it and its
1201
1280
  // failure only sends its effects back to a pass each.
1202
- const template = words[a + 1];
1203
1281
  const joined = this.joins.joined(template);
1204
1282
  if (DEV && !joined && this.images.shaders.has(template))
1205
1283
  this.customOperands.set(id, words.slice(a, a + RENDER_PIPELINE_OPERANDS));
@@ -1209,17 +1287,24 @@ export class WebGPUBackend {
1209
1287
  return;
1210
1288
  }
1211
1289
  if (!background && !joined) {
1212
- this.renderPipelines[id] =
1213
- this.takeAhead(op, words, a) ??
1214
- device.createRenderPipeline(this.renderDescriptor(words, a));
1290
+ const ahead = this.takeAhead(op, words, a);
1291
+ if (ahead) {
1292
+ this.renderPipelines[id] = ahead;
1293
+ return;
1294
+ }
1295
+ const descriptor = this.describedRender(words, a);
1296
+ if (descriptor === null)
1297
+ return;
1298
+ this.renderPipelines[id] = device.createRenderPipeline(descriptor);
1215
1299
  return;
1216
1300
  }
1217
- const descriptor = this.renderDescriptor(words, a);
1301
+ const descriptor = this.describedRender(words, a);
1302
+ if (descriptor === null)
1303
+ return;
1218
1304
  this.renderPipelines[id] = null;
1219
1305
  this.builds++;
1220
1306
  this.running++;
1221
1307
  const start = performance.now();
1222
- const permutation = words[a + 2];
1223
1308
  device.createRenderPipelineAsync(descriptor).then((pipeline) => {
1224
1309
  this.running--;
1225
1310
  if (joined)
@@ -1233,6 +1318,67 @@ export class WebGPUBackend {
1233
1318
  this.joins.failed(template, error);
1234
1319
  });
1235
1320
  }
1321
+ /**
1322
+ * The render pipeline's descriptor, or null when the loaded shader set lacks its variant, for a
1323
+ * template that draws the scene's meshes or a full-screen pass. Its draws then draw nothing, as
1324
+ * a pipeline that the driver refused twice does. A joined shader's effects fall back to a pass
1325
+ * each.
1326
+ */
1327
+ describedRender(words, a) {
1328
+ const template = words[a + 1];
1329
+ try {
1330
+ return this.renderDescriptor(words, a);
1331
+ }
1332
+ catch (error) {
1333
+ if (!(error instanceof MissingVariantError))
1334
+ throw error;
1335
+ this.renderPipelines[words[a]] = null;
1336
+ reportMissingVariant(this.pipelines.describe(template, words[a + 2]), error.word);
1337
+ if (this.joins.joined(template))
1338
+ this.joins.failed(template, error);
1339
+ return null;
1340
+ }
1341
+ }
1342
+ /**
1343
+ * Reports a shader that is absent or that failed to load, and returns true for either. A word
1344
+ * that the loaded set lacks goes to the page's report, and a file that did not load goes to its
1345
+ * warning. Any other error returns false, and the caller rethrows it as the engine fault it is.
1346
+ */
1347
+ reportUnavailable(error, name) {
1348
+ if (error instanceof MissingShaderError) {
1349
+ reportMissingVariant(`the ${error.shader} shader`, error.word);
1350
+ return true;
1351
+ }
1352
+ if (error instanceof ShaderLoadError) {
1353
+ reportUnavailableShader(name, error.message);
1354
+ return true;
1355
+ }
1356
+ return false;
1357
+ }
1358
+ /**
1359
+ * Marks the pipeline of a create command as unavailable when its shader is absent or did not
1360
+ * load: its draws or dispatches do nothing, and the engine reports the cause once. A joined
1361
+ * shader's effects fall back to a pass each. Returns false for any other error.
1362
+ */
1363
+ unavailable(error, op, operands) {
1364
+ const compute = op === G.OP_CREATE_COMPUTE_PIPELINE;
1365
+ const id = operands[0];
1366
+ const template = operands[1];
1367
+ const permutation = operands[2];
1368
+ const name = compute
1369
+ ? `compute pass ${template}`
1370
+ : this.pipelines.describe(template, permutation);
1371
+ if (!this.reportUnavailable(error, name))
1372
+ return false;
1373
+ if (compute)
1374
+ this.computePipelines[id] = null;
1375
+ else {
1376
+ this.renderPipelines[id] = null;
1377
+ if (this.joins.joined(template))
1378
+ this.joins.failed(template, error);
1379
+ }
1380
+ return true;
1381
+ }
1236
1382
  /**
1237
1383
  * Hears that a render pipeline did not build. A pipeline of the scene's objects that the GPU's
1238
1384
  * driver refused waits for its retry, and still counts as building. Any other failure, such as
@@ -198,8 +198,8 @@ export declare class Pipelines {
198
198
  has(id: number): boolean;
199
199
  /**
200
200
  * True when the pipelines of a template draw objects of the scene: meshes, or a custom material's
201
- * draw shader. A frame can go without such a pipeline's draws, while a pass of the frame's own
202
- * cannot.
201
+ * draw shader. A driver's refusal of such a pipeline is retried, and then its draws skip. A
202
+ * missing shader or a failed load skips any pipeline or pass (D-405).
203
203
  */
204
204
  drawsObjects(id: number): boolean;
205
205
  /** The name of a render pipeline of a template, for a message (`pipelineName`). */
@@ -8,7 +8,7 @@ import { DEBUG_LINES_SHADER, DEBUG_VIEW_SHADER, MOTION_VIEW_SHADER, } from '../.
8
8
  import { LINE_VERTICES } from '../line-vertices.js';
9
9
  import { PARTICLE_RECORDS } from '../particle-records.js';
10
10
  import { pipelineName } from '../pipeline-name.js';
11
- import { missingShader, missingVariant, variantFor } from '../variants.js';
11
+ import { listedWord, MissingVariantError, missingShaderError, missingVariant, variantFor, } from '../variants.js';
12
12
  import { plainScale, variantLocations, vertexAttribute, vertexStride, } from '../vertex-format.js';
13
13
  /**
14
14
  * True in development builds, which add the debug views' templates. This file reads the constant
@@ -1603,8 +1603,8 @@ export class Pipelines {
1603
1603
  }
1604
1604
  /**
1605
1605
  * True when the pipelines of a template draw objects of the scene: meshes, or a custom material's
1606
- * draw shader. A frame can go without such a pipeline's draws, while a pass of the frame's own
1607
- * cannot.
1606
+ * draw shader. A driver's refusal of such a pipeline is retried, and then its draws skip. A
1607
+ * missing shader or a failed load skips any pipeline or pass (D-405).
1608
1608
  */
1609
1609
  drawsObjects(id) {
1610
1610
  const template = this.templates[id];
@@ -1693,7 +1693,7 @@ export class Pipelines {
1693
1693
  const build = ownPrepass && !cutoutPrepass ? (permutation & ~PERMUTATION_PREPASS) >>> 0 : permutation;
1694
1694
  const shader = variantFor(t.shader, build, 'wgsl')?.wgsl;
1695
1695
  if (!shader)
1696
- throw new Error(`render template ${template}: ${missingVariant(build)}`);
1696
+ throw new MissingVariantError(listedWord(build), `render template ${template}: ${missingVariant(build)}`);
1697
1697
  const module = this.module(t.label, shader);
1698
1698
  const entryPoints = shader.pipelines[t.pipeline];
1699
1699
  const skins = (permutation & PERMUTATION_SKIN) !== 0;
@@ -1837,7 +1837,7 @@ export class Pipelines {
1837
1837
  mipDescriptor(format, entry) {
1838
1838
  const shader = this.mipmap;
1839
1839
  if (!shader)
1840
- throw new Error(missingShader('mip level', 0));
1840
+ throw missingShaderError('mip level', 0);
1841
1841
  const module = this.module('mipmaps', shader);
1842
1842
  const entryPoints = shader.pipelines[entry];
1843
1843
  return {
@@ -1895,7 +1895,7 @@ export class Pipelines {
1895
1895
  const color = (permutation & PERMUTATION_VERTEX_COLOR) !== 0 ? ' color' : '';
1896
1896
  const shader = variantFor(this.skin, permutation, 'wgsl')?.wgsl;
1897
1897
  if (!shader)
1898
- throw new Error(missingShader('skinning', permutation));
1898
+ throw missingShaderError('skinning', permutation);
1899
1899
  const constants = this.floatSkinnedDirections ? { [NARROW_DIRECTIONS_ID]: 0 } : undefined;
1900
1900
  return {
1901
1901
  label: `skin${tangent}${color}`,
@@ -1906,7 +1906,7 @@ export class Pipelines {
1906
1906
  if (template === TEMPLATE_CULL && permutation & PERMUTATION_MOTION) {
1907
1907
  const shader = variantFor(this.cullMotion, permutation, 'wgsl')?.wgsl;
1908
1908
  if (!shader)
1909
- throw new Error(missingShader('motion culling', permutation));
1909
+ throw missingShaderError('motion culling', permutation);
1910
1910
  return {
1911
1911
  label: 'cull motion',
1912
1912
  layout: this.cullLayout,
@@ -1915,7 +1915,7 @@ export class Pipelines {
1915
1915
  }
1916
1916
  if (template === TEMPLATE_CULL) {
1917
1917
  if (!this.cull)
1918
- throw new Error(missingShader('culling', 0));
1918
+ throw missingShaderError('culling', 0);
1919
1919
  return {
1920
1920
  label: 'cull',
1921
1921
  layout: this.cullLayout,
@@ -1926,7 +1926,7 @@ export class Pipelines {
1926
1926
  if (phase) {
1927
1927
  const shader = variantFor(this.occlusion, 0, 'wgsl')?.wgsl;
1928
1928
  if (!shader)
1929
- throw new Error(missingShader('occlusion culling', 0));
1929
+ throw missingShaderError('occlusion culling', 0);
1930
1930
  return {
1931
1931
  label: `occlusion ${phase}`,
1932
1932
  layout: this.cullLayout,
@@ -1936,7 +1936,7 @@ export class Pipelines {
1936
1936
  if (template === TEMPLATE_CLUSTER) {
1937
1937
  const shader = this.cluster ? variantFor(this.cluster, 0, 'wgsl')?.wgsl : undefined;
1938
1938
  if (!shader)
1939
- throw new Error(missingShader('cluster', 0));
1939
+ throw missingShaderError('cluster', 0);
1940
1940
  return {
1941
1941
  label: 'cluster cull',
1942
1942
  layout: this.clusterLayout,
@@ -1946,7 +1946,7 @@ export class Pipelines {
1946
1946
  if (template === TEMPLATE_DEPTH_PYRAMID) {
1947
1947
  const shader = variantFor(this.pyramid, 0, 'wgsl')?.wgsl;
1948
1948
  if (!shader)
1949
- throw new Error(missingShader('depth pyramid', 0));
1949
+ throw missingShaderError('depth pyramid', 0);
1950
1950
  return {
1951
1951
  label: 'depth pyramid',
1952
1952
  layout: this.pyramidLayout,
@@ -1956,7 +1956,7 @@ export class Pipelines {
1956
1956
  if (template === TEMPLATE_FEATURE_ROWS) {
1957
1957
  const shader = variantFor(this.featureRows, 0, 'wgsl')?.wgsl;
1958
1958
  if (!shader)
1959
- throw new Error(missingShader('feature rows', 0));
1959
+ throw missingShaderError('feature rows', 0);
1960
1960
  this.featureRowsLayout ??= this.device.createPipelineLayout({
1961
1961
  bindGroupLayouts: [this.layout(LAYOUT_FEATURE_ROWS)],
1962
1962
  });
@@ -1970,7 +1970,7 @@ export class Pipelines {
1970
1970
  if (exposureEntry) {
1971
1971
  const shader = variantFor(this.exposureHistogram, 0, 'wgsl')?.wgsl;
1972
1972
  if (!shader)
1973
- throw new Error(missingShader('exposure histogram', 0));
1973
+ throw missingShaderError('exposure histogram', 0);
1974
1974
  this.exposureLayout ??= this.device.createPipelineLayout({
1975
1975
  bindGroupLayouts: [this.layout(LAYOUT_EXPOSURE)],
1976
1976
  });
@@ -1988,7 +1988,7 @@ export class Pipelines {
1988
1988
  const clear = template === TEMPLATE_LIGHT_DEPTH_CLEAR || template === TEMPLATE_LIGHT_DEPTH_CLEAR_MS;
1989
1989
  const shader = multisampled ? this.lightDepthMs : this.lightDepth;
1990
1990
  if (!shader)
1991
- throw new Error(missingShader('light depth', 0));
1991
+ throw missingShaderError('light depth', 0);
1992
1992
  return {
1993
1993
  label: clear ? 'light depth clear' : 'light depth',
1994
1994
  layout: multisampled ? this.lightDepthMsLayout : this.lightDepthLayout,
@@ -2003,7 +2003,7 @@ export class Pipelines {
2003
2003
  throw new Error(`unknown compute template ${template}`);
2004
2004
  const shader = this.lightClusters;
2005
2005
  if (!shader)
2006
- throw new Error(missingShader('light clustering', 0));
2006
+ throw missingShaderError('light clustering', 0);
2007
2007
  return {
2008
2008
  label: entryPoint,
2009
2009
  layout: this.lightLayout,
@@ -16,9 +16,9 @@ import { messageOf } from '../errors/message.js';
16
16
  import { FORMAT_CANVAS, PERMUTATION_HALF } from '../generated/gpu.js';
17
17
  import { SHADER_FEATURES } from '../generated/shader-features.js';
18
18
  import { SHIPPED_GPU_PATHS } from '../generated/shader-permutations.js';
19
- import { recordPermutations, reportPermutations, stopRecordingPermutations } from '../gpu/variants.js';
19
+ import { receiveMissingVariants, receiveUnavailableShaders, recordPermutations, reportPermutations, stopRecordingPermutations, } from '../gpu/variants.js';
20
20
  import { maxTargetFps, } from '../quality/check.js';
21
- import { choosePreset, crashLowest, crashTier, deviceKind, gpuOcclusionChoice, memoryPreset, textureMemoryCap, withinTier, } from '../quality/chooser.js';
21
+ import { choosePreset, crashLowest, crashTier, deviceKind, gpuOcclusionChoice, memoryPreset, presetCapped, textureMemoryCap, withinTier, } from '../quality/chooser.js';
22
22
  import { readDeviceHints } from '../quality/device-hints.js';
23
23
  import { capTextureMemory, checkedSettings, checkSettings, lowestTierSettings, presetCheckOption, presetOption, presetValue, targetFpsOption, } from '../quality/presets.js';
24
24
  import { loadDrawModule, preloadDrawing } from '../render/load-draw.js';
@@ -77,6 +77,40 @@ function fallbackText(report) {
77
77
  let warnedFallback = false;
78
78
  /** True once an engine on the page has warned that a service worker's page lost its isolation. */
79
79
  let warnedIsolation = false;
80
+ /** The words that the loaded shader set lacks on this page, for a production build's check. */
81
+ const missingWords = new Set();
82
+ /**
83
+ * Publishes a word that the loaded shader set lacks, once per word, and warns. A production
84
+ * build's check reads `window.__null3dMissingWords`, which also holds the words in a release.
85
+ */
86
+ function publishMissingWord(pipeline, word) {
87
+ if (missingWords.has(word))
88
+ return;
89
+ missingWords.add(word);
90
+ globalThis.__null3dMissingWords = [...missingWords].sort((a, b) => a - b);
91
+ console.warn(`null3D: ${pipeline} asks for the permutation word 0x${word.toString(16).padStart(8, '0')}, which the shader list lacks. The engine draws without it. Record the pages again with bunx @null3d/cli shaders record.`);
92
+ }
93
+ /** The shader files that did not load on this page, by the pipeline that needed one. */
94
+ const unavailableShaders = new Set();
95
+ /**
96
+ * Warns about a pipeline or pass whose shader file did not load, once for each cause. The engine
97
+ * draws without it, so the rest of the scene stays.
98
+ */
99
+ function publishUnavailableShader(pipeline, reason) {
100
+ const key = `${pipeline}\n${reason}`;
101
+ if (unavailableShaders.has(key))
102
+ return;
103
+ unavailableShaders.add(key);
104
+ console.warn(`null3D: ${pipeline} needs a shader file that did not load, so the engine draws without it: ${reason}`);
105
+ }
106
+ /** Starts a new engine's record of missing words, and publishes an empty list for its check. */
107
+ function resetMissingWords() {
108
+ missingWords.clear();
109
+ unavailableShaders.clear();
110
+ globalThis.__null3dMissingWords = [];
111
+ }
112
+ /** True once an engine on the page has warned that a named preset ran on WebGL2 without WebGPU. */
113
+ let warnedCappedPreset = false;
80
114
  /** The global where the `?bench` switch publishes the running engine. */
81
115
  const BENCH_GLOBAL = '__null3dEngine';
82
116
  /** The global where a development build publishes its inspection bridge, for the MCP server. */
@@ -332,6 +366,15 @@ export class EngineWorker {
332
366
  if (DEV)
333
367
  announcePermutationWord(reply.word);
334
368
  return;
369
+ case 'recorded-word':
370
+ this.recording?.heard(reply.word);
371
+ return;
372
+ case 'missing-word':
373
+ publishMissingWord(reply.pipeline, reply.word);
374
+ return;
375
+ case 'unavailable-shader':
376
+ publishUnavailableShader(reply.pipeline, reply.reason);
377
+ return;
335
378
  case 'sketch-message':
336
379
  events.sketchMessage(reply.name, reply.data);
337
380
  return;
@@ -899,6 +942,7 @@ function prefetch(url) {
899
942
  */
900
943
  export async function createEngine(options) {
901
944
  const switches = parseSwitches(URL_SWITCHES ? (globalThis.location?.search ?? '') : '');
945
+ resetMissingWords();
902
946
  const holding = options.hold !== undefined || switches.hold !== undefined || switches.replay !== undefined;
903
947
  const place = placement(options, switches);
904
948
  if (DEV && !warnedIsolation) {
@@ -1695,6 +1739,17 @@ async function startEngine(options, switches, modes, { threaded, sketchThread },
1695
1739
  const stored = switches.freshCheck ? undefined : checkStore?.read();
1696
1740
  const storedCheck = stored && checkEnded(stored) ? stored : undefined;
1697
1741
  const preset = stored ? checkedPreset(stored) : chosen;
1742
+ // A page that names a heavier preset than WebGL2 can run gets Medium with no other sign. When
1743
+ // the browser reports WebGPU but offers no adapter, the browser's start switch is the cause.
1744
+ if (DEV &&
1745
+ !warnedCappedPreset &&
1746
+ tier === 'webgl2' &&
1747
+ presetCapped(presetRequest.wanted, tier) &&
1748
+ report.webgpu.available &&
1749
+ !report.webgpu.compatibilityAdapter) {
1750
+ warnedCappedPreset = true;
1751
+ console.warn(`null3D: this page asked for the ${presetRequest.wanted} preset, and runs ${preset} on WebGL2. The browser reports WebGPU but offers no adapter: Chromium offers one only when it starts with --enable-unsafe-webgpu. Start the browser with that switch to draw the WebGPU presets.`);
1752
+ }
1698
1753
  // Occlusion culling on the GPU needs WebGPU's compute passes. Phones and tablets run it only
1699
1754
  // when the page asks.
1700
1755
  const gpuOcclusion = tier === 'webgl2'
@@ -1783,7 +1838,11 @@ async function startEngine(options, switches, modes, { threaded, sketchThread },
1783
1838
  if (recording && hold === undefined)
1784
1839
  globalThis.__null3dStopRecording = stopRecording;
1785
1840
  if (recording && renderThread === 'main')
1786
- recordPermutations();
1841
+ recordPermutations((word) => recording.heard(word));
1842
+ if (renderThread === 'main')
1843
+ receiveMissingVariants(publishMissingWord);
1844
+ if (renderThread === 'main')
1845
+ receiveUnavailableShaders(publishUnavailableShader);
1787
1846
  // The dev server compares each word that the page draws with against the project's list.
1788
1847
  if (DEV && renderThread === 'main')
1789
1848
  reportPermutations(announcePermutationWord);
@@ -13,14 +13,16 @@ declare global {
13
13
  export declare class PermutationRecording {
14
14
  private readonly drawing;
15
15
  private readonly words;
16
- /** True once the words are published, so a later answer changes nothing. */
17
- private published;
18
16
  constructor(drawing: DrawingThread);
19
17
  /**
20
18
  * Takes the drawing thread's words, which publishes them. Another thread that does not draw asks
21
19
  * no pipelines for a variant, so its words wait for the drawing thread.
22
20
  */
23
21
  answered(role: 'sketch' | 'render' | 'page', words: readonly number[]): void;
24
- /** Publishes the words gathered so far, once. */
22
+ /** Takes a word as the drawing thread finds it, and publishes the growing set at once. */
23
+ heard(word: number): void;
24
+ /** Adds a word, and says whether it was new. */
25
+ private add;
26
+ /** Publishes the words gathered so far. A live page's set grows until its tool stops it. */
25
27
  private publish;
26
28
  }
@@ -7,8 +7,6 @@
7
7
  export class PermutationRecording {
8
8
  drawing;
9
9
  words = new Set();
10
- /** True once the words are published, so a later answer changes nothing. */
11
- published = false;
12
10
  constructor(drawing) {
13
11
  this.drawing = drawing;
14
12
  }
@@ -18,15 +16,23 @@ export class PermutationRecording {
18
16
  */
19
17
  answered(role, words) {
20
18
  for (const word of words)
21
- this.words.add(word >>> 0);
19
+ this.add(word);
22
20
  if (role === this.drawing)
23
21
  this.publish();
24
22
  }
25
- /** Publishes the words gathered so far, once. */
23
+ /** Takes a word as the drawing thread finds it, and publishes the growing set at once. */
24
+ heard(word) {
25
+ if (this.add(word))
26
+ this.publish();
27
+ }
28
+ /** Adds a word, and says whether it was new. */
29
+ add(word) {
30
+ const held = this.words.has(word >>> 0);
31
+ this.words.add(word >>> 0);
32
+ return !held;
33
+ }
34
+ /** Publishes the words gathered so far. A live page's set grows until its tool stops it. */
26
35
  publish() {
27
- if (this.published)
28
- return;
29
- this.published = true;
30
36
  window.__null3dPermutations = [...this.words].sort((a, b) => a - b);
31
37
  }
32
38
  }
@@ -70,6 +70,8 @@ export interface PresetRequest {
70
70
  export declare function deviceKind(hints: DeviceHints): DeviceKind;
71
71
  /** `preset`, or the GPU path's highest preset when `preset` is heavier. */
72
72
  export declare function withinTier(preset: QualityPreset, tier: Tier): QualityPreset;
73
+ /** True when the page asked for a heavier preset than the GPU path can run. */
74
+ export declare function presetCapped(wanted: QualityPreset | 'auto', tier: Tier): boolean;
73
75
  /** The preset that the hints give: the device's own, one lower when its memory reads under 4 GB. */
74
76
  export declare function hintedPreset(hints: DeviceHints): QualityPreset;
75
77
  /** `preset` after crashed starts: the same with none, one lower after one, and Low after two. */
@@ -62,6 +62,10 @@ export function withinTier(preset, tier) {
62
62
  const ceiling = TIER_CEILINGS[tier];
63
63
  return presetIndex(preset) <= presetIndex(ceiling) ? preset : ceiling;
64
64
  }
65
+ /** True when the page asked for a heavier preset than the GPU path can run. */
66
+ export function presetCapped(wanted, tier) {
67
+ return wanted !== 'auto' && withinTier(wanted, tier) !== wanted;
68
+ }
65
69
  /** The preset that the hints give: the device's own, one lower when its memory reads under 4 GB. */
66
70
  export function hintedPreset(hints) {
67
71
  const preset = DEVICE_PRESETS[deviceKind(hints)];
@@ -1 +1 @@
1
- {"tag":"0.1.2","file":"0.1.2-shaders.tar.br","url":"https://github.com/null3d-engine/null3d/releases/download/0.1.2/0.1.2-shaders.tar.br","sha256":"6ab4019ca61ff2b66f5cff07f62692330afc34ddbbad623c555fbc45c7a01be5"}
1
+ {"tag":"0.1.3","file":"0.1.3-shaders.tar.br","url":"https://github.com/null3d-engine/null3d/releases/download/0.1.3/0.1.3-shaders.tar.br","sha256":"6ab4019ca61ff2b66f5cff07f62692330afc34ddbbad623c555fbc45c7a01be5"}
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @category api/engine
5
5
  */
6
- export declare const VERSION = "0.1.2";
6
+ export declare const VERSION = "0.1.3";
7
7
  /**
8
8
  * The version of the plugin interface that an add-on from another developer builds against. It is
9
9
  * a whole number, and it changes only when a stable add-on hook changes, never with every engine
@@ -11,7 +11,7 @@ import { DEV } from './dev.js';
11
11
  *
12
12
  * @category api/engine
13
13
  */
14
- export const VERSION = '0.1.2';
14
+ export const VERSION = '0.1.3';
15
15
  /**
16
16
  * The version of the plugin interface that an add-on from another developer builds against. It is
17
17
  * a whole number, and it changes only when a stable add-on hook changes, never with every engine