@null3d/engine 0.1.1 → 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 (63) 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 +2 -1
  6. package/docs/cli/null3d.md +60 -4
  7. package/docs/concepts/backends.md +4 -0
  8. package/docs/concepts/quality-presets.md +2 -0
  9. package/docs/errors/E1308.md +31 -0
  10. package/docs/errors/E1404.md +5 -1
  11. package/docs/errors/index.md +1 -0
  12. package/docs/getting-started/cdn.md +1 -1
  13. package/docs/getting-started/first-scene.md +3 -1
  14. package/docs/getting-started/hosting.md +13 -3
  15. package/docs/getting-started/install.md +21 -1
  16. package/docs/getting-started/project-structure.md +1 -1
  17. package/docs/guides/agents.md +12 -9
  18. package/docs/guides/assets-pipeline.md +77 -6
  19. package/docs/guides/content-pages.md +33 -0
  20. package/docs/guides/debugging.md +2 -0
  21. package/docs/guides/deploying.md +5 -1
  22. package/docs/guides/deterministic-simulation.md +5 -2
  23. package/docs/guides/loading-screens.md +4 -0
  24. package/docs/guides/performance.md +2 -0
  25. package/docs/guides/start-time.md +8 -0
  26. package/docs/guides/testing.md +20 -0
  27. package/docs/pages.md +1 -1
  28. package/docs/porting/verification.md +1 -1
  29. package/lib/errors/codes.js +11 -0
  30. package/lib/errors/engine-error.js +1 -1
  31. package/lib/errors/fixes.d.ts +1 -0
  32. package/lib/errors/fixes.js +2 -1
  33. package/lib/generated/shader-permutations.d.ts +6 -0
  34. package/lib/generated/shader-permutations.js +6 -0
  35. package/lib/gpu/device-shaders.d.ts +5 -0
  36. package/lib/gpu/device-shaders.js +10 -1
  37. package/lib/gpu/variants.d.ts +25 -0
  38. package/lib/gpu/variants.js +75 -5
  39. package/lib/gpu/webgl2/backend.d.ts +22 -3
  40. package/lib/gpu/webgl2/backend.js +108 -22
  41. package/lib/gpu/webgl2/programs.d.ts +5 -0
  42. package/lib/gpu/webgl2/programs.js +25 -2
  43. package/lib/gpu/webgpu/backend.d.ts +34 -1
  44. package/lib/gpu/webgpu/backend.js +173 -27
  45. package/lib/gpu/webgpu/pipelines.d.ts +2 -2
  46. package/lib/gpu/webgpu/pipelines.js +15 -15
  47. package/lib/page/engine.d.ts +15 -2
  48. package/lib/page/engine.js +124 -9
  49. package/lib/page/permutation-recording.d.ts +5 -3
  50. package/lib/page/permutation-recording.js +13 -7
  51. package/lib/quality/chooser.d.ts +2 -0
  52. package/lib/quality/chooser.js +4 -0
  53. package/lib/shader-artifact.json +1 -1
  54. package/lib/shared/permutation-words.d.ts +6 -0
  55. package/lib/shared/permutation-words.js +6 -0
  56. package/lib/shared/tier.d.ts +9 -0
  57. package/lib/shared/tier.js +4 -1
  58. package/lib/shared/version.d.ts +1 -1
  59. package/lib/shared/version.js +1 -1
  60. package/lib/workers/protocol.d.ts +29 -0
  61. package/lib/workers/render-worker.js +6 -3
  62. package/lib/workers/sketch-worker.js +6 -3
  63. package/package.json +1 -1
@@ -139,6 +139,8 @@ A bug that shows at one moment is easier to fix when every run reaches it. Hold
139
139
  Drew no frame of /: E1408: hold mode stopped at 1 seconds, in frame 61: E1203: setPosition() got NaN for x on an object (slot 2). ...
140
140
  ```
141
141
 
142
+ The command's browser draws the WebGPU path where the device offers it. [Testing your sketch](testing.md#the-browser-must-take-the-webgpu-path) gives the setup for a browser of your own.
143
+
142
144
  It also saves the errors and warnings that the page logged, with their stacks, in a JSON file. [Testing your sketch](testing.md) explains hold mode.
143
145
 
144
146
  ## Measure
@@ -50,7 +50,7 @@ Cross-Origin-Embedder-Policy: require-corp
50
50
 
51
51
  [Headers on common hosts](../getting-started/hosting.md#headers-on-common-hosts) gives each file. Without the headers, the engine loads its single-threaded build. The page still runs, with the same API and features, on one thread. Files from other sites need CORS or `Cross-Origin-Resource-Policy` headers under isolation ([Files from other sites](../getting-started/hosting.md#files-from-other-sites)).
52
52
 
53
- Serve the page over HTTPS. WebGPU and shared memory need a secure page. Over plain HTTP, the engine draws with WebGL2.
53
+ Serve the page over HTTPS. WebGPU and shared memory need a secure page. Over plain HTTP, the engine draws with WebGL2. A browser that drives a test must also start with `--enable-unsafe-webgpu`: [Testing your sketch](testing.md#the-browser-must-take-the-webgpu-path) gives the setup.
54
54
 
55
55
  ## Let browsers keep the files
56
56
 
@@ -73,6 +73,10 @@ A page's start downloads the engine, then the files of the first view. Keep each
73
73
 
74
74
  So the engine's start takes about 844 KB after Brotli, before the page's own code and the scene's files. The JavaScript counts the engine's code for the page and its workers and the GPU path's renderer. It also counts the largest shader file that a start can load. [Send the files with Brotli](../getting-started/hosting.md#send-the-files-with-brotli) gives the figures for gzip and for files as they are.
75
75
 
76
+ The host stores the shader files of both GPU paths, and a page downloads one path's. A build that ships a subset copies no files of the paths it leaves out. That saves most of the shader set's size in the app package, the installer and the host. The start stays the same.
77
+
78
+ A visitor who downloads the whole app also downloads less: an Electron installer, a zip of the site, or the files that a service worker caches. [Ship a subset of the GPU paths](assets-pipeline.md#ship-a-subset-of-the-gpu-paths) gives the measured sizes.
79
+
76
80
  `assets optimize` makes models and their textures smaller, and its report warns for each quality preset whose texture memory a model passes ([The budget report](assets-pipeline.md#the-budget-report)). Phones and tablets start at the Low and Medium presets, which give textures less memory.
77
81
 
78
82
  To shorten the start, begin the first view's downloads at the top of the setup. Draw the first frame before the large models arrive ([A fast start](start-time.md)).
@@ -221,12 +221,15 @@ The game's module then imports `createEngine` and `SKETCH` from the folder's `en
221
221
  The shader modules decide most of the folder's size. Copy only the builds of the shader permutation words that the game draws with:
222
222
 
223
223
  1. Build a development copy of the folder (`bunx vite build --mode development`). A production build ignores `?permutations`, `?gpu` and `?preset`, so a recording of it holds nothing.
224
- 2. Record the words from a run of the game's page, as [Build only the shader permutations you draw with](assets-pipeline.md#build-only-the-shader-permutations-you-draw-with) shows. The game's engine starts on a click, so name its page with `--live` and give the recorder the start control. Serve the game with its development folder, and give the recorder its address: `bunx @null3d/cli shaders record --base http://localhost:8080 --live /game.html --click "#play"`.
224
+ 2. Record the words from a run of the game's page, as [Build only the shader permutations you draw with](assets-pipeline.md#build-only-the-shader-permutations-you-draw-with) shows. The game's engine starts on a click, so name its page with `--live` and give the recorder the start control. Serve the game with its development folder, and give the recorder its address: `bunx @null3d/cli shaders record --base http://localhost:8080 --live /game.html --click "#play"`. The recorder's browser takes the WebGPU path where the device offers it.
225
225
  3. Name the list in the engine folder's config, as `null3d({ shaders: { list: 'shader-permutations.txt' } })`, and build the folder in production again. The build copies only the listed builds, from the release asset, and compiles nothing.
226
+ 4. Record the states that a player opens, such as each level and menu. Use `--steps` with the game's own steps, `--manual`, or a browser test, as the assets guide shows. A single load of the game reaches only its first state.
226
227
 
227
228
  With null3D 0.1.0's shader set, a small scene drew with 6 words. Its build copied 218 shader files and 17 MB, against 7,597 files and 4,115 MB without a list. Build the set again after each engine upgrade.
228
229
 
229
- The shader modules in a release asset are the full set. A game that builds against that asset without a list copies every module into its files folder. The build then warns with the size that it copied. That can exceed the folder's file and byte limits. Record again after the game gains a feature that turns on a new word. The engine names a word that the list lacks the first time a pipeline needs it.
230
+ The shader modules in a release asset are the full set. A game that builds against that asset without a list copies every module into its files folder. The build then warns with the size that it copied. That can exceed the folder's file and byte limits.
231
+
232
+ Record again after the game gains a feature that turns on a new word. Check the production build with `bunx @null3d/cli shaders verify`, which drives the pages on both GPU paths and fails on a word that the list lacks. The engine skips the pipeline or pass whose word is missing, and reports the word.
230
233
 
231
234
  ## API reference
232
235
 
@@ -223,6 +223,10 @@ An object of a new kind can need more than one pipeline. Where the scene draws t
223
223
 
224
224
  In hold mode, the engine draws one frame, which waits for its pipelines, so `scene.warmUp()` resolves at once.
225
225
 
226
+ A warm-up shares the GPU with the frames that the scene draws while it waits. So warm up the stages of cheap objects before a heavy stage shows. On a slow GPU, each frame of a heavy stage can take seconds, and every warm-up after it waits that long too.
227
+
228
+ In SwiftShader, a software GPU, a hero object's richer materials warmed up in 1.3 seconds before a city showed. After the city showed, the same warm-up took more than 20 seconds.
229
+
226
230
  ## Loading everything up front
227
231
 
228
232
  Most shaders come with the engine's start. The shaders of a feature that many games leave out download the first time the sketch uses it. So a page that never uses the feature never downloads them. [Shaders that load on first use](first-use-shaders.md) lists every such feature and the moment its shaders download. For example, `'skinning'` downloads with the first skinned mesh, and `'bloom'` when `post.set` turns bloom on.
@@ -14,6 +14,8 @@ This guide covers the frames. [A fast start](start-time.md) covers the wait befo
14
14
 
15
15
  Measure before you change anything, so you know which cost matters. Add `?stats` to the page's address for a live overlay, or call `debug.stats(true)` in the sketch. Call `engine.measure(5)` for figures over a window. Run `bunx @null3d/cli bench` to measure a production build with no test code. Measure in every rendering mode and preset, over the whole camera path, with repeats: [Testing your sketch](testing.md#check-every-rendering-mode) says how. [Measure](#measure) below gives each figure.
16
16
 
17
+ The figures here name the path and preset that each one measured. On a page that fell back to WebGL2 they mean nothing: that path runs different code at Medium at most. [Testing your sketch](testing.md#the-browser-must-take-the-webgpu-path) keeps a test browser on the WebGPU path.
18
+
17
19
  ## Where frame time goes
18
20
 
19
21
  ```mermaid
@@ -281,6 +281,12 @@ Chrome on Android keeps about 2 MB of a site's compiled WebGPU pipelines between
281
281
  - Warm up behind the loading screen, so play builds no pipeline ([Loading screens and warm-up](loading-screens.md#pipelines-and-warm-up)).
282
282
  - Time the start on the phones and tablets of your audience. A desktop browser that emulates a phone builds pipelines at the computer's speed.
283
283
 
284
+ A phone on the WebGL2 path pays more for each later stage. On a Galaxy S24 with Samsung's Xclipse GPU, Chrome has no WebGPU, so a page draws with WebGL2. There, a city stage of a content page took 5.3 seconds to warm up, on a repeat visit too.
285
+
286
+ Chrome drew nothing on the page during that warm-up, so the screen froze for 2 to 4 seconds at a time. No loading animation can move through such a freeze.
287
+
288
+ So on that path, leave the optional effects out at the lightest preset, such as bloom, depth of field and lit fog. Each one adds programs to every warm-up. Show the canvas at the first frame, and let the later stages arrive behind it ([3D scenes on content pages](content-pages.md#a-scene-that-builds-in-stages)).
289
+
284
290
  The engine's own passes add pipelines too, and the first frame builds only those that it draws with:
285
291
 
286
292
  - On WebGPU, the pass that lists each cluster's point, spot and area lights takes 4 compute pipelines. Where the GPU fits the clusters to the measured depth (`lightFit`), it takes 4 more. A first frame whose scene holds none of these lights leaves them out.
@@ -323,6 +329,8 @@ Judge a start only on a production build that a host serves as above. The Vite d
323
329
 
324
330
  A phone or tablet that tests the page must trust its certificate. Chrome keeps no file in its cache from a site whose certificate it accepted after a warning. Every load then downloads every file again: a reload of the dev server took 30 seconds instead of 15. Install the certificate's root on the device, as [During development](../getting-started/hosting.md#during-development) shows.
325
331
 
332
+ A browser that drives the test must also start with `--enable-unsafe-webgpu`, or it measures WebGL2. [Testing your sketch](testing.md#the-browser-must-take-the-webgpu-path) gives the browser setup.
333
+
326
334
  ## Measure a start
327
335
 
328
336
  `engine.measure()` gives the start's times in its `load` figures ([Performance guide](performance.md#measure)):
@@ -235,6 +235,26 @@ The engine reads these switches from the page's address in development builds: t
235
235
 
236
236
  To use them in a production build of test pages, turn on the Vite plugin's `urlSwitches` option: `null3d({ urlSwitches: true })`. For a benchmark page that loads the CDN build, `bun run build:cdn --url-switches` does the same ([Try null3D from a CDN](../getting-started/cdn.md#production-and-development-entries)).
237
237
 
238
+ ### The browser must take the WebGPU path
239
+
240
+ A browser that drives a test must start with `--enable-unsafe-webgpu`. Playwright's Chromium reports `navigator.gpu`, but its adapter request resolves to null without that switch. The engine then draws WebGL2 at Medium.
241
+
242
+ ```ts
243
+ // playwright.config.ts
244
+ import { defineConfig } from '@playwright/test';
245
+
246
+ export default defineConfig({
247
+ use: {
248
+ ignoreHTTPSErrors: true,
249
+ launchOptions: { args: ['--enable-unsafe-webgpu'] },
250
+ },
251
+ });
252
+ ```
253
+
254
+ `ignoreHTTPSErrors` lets the test browser open a page on a local certificate. It does not turn on WebGPU: the switch does that, and a plain `http://localhost` page is a secure context already.
255
+
256
+ A suite on WebGL2 at Medium passes while the shipped WebGPU path stays untested. High and Ultra exist only on WebGPU, with their larger shadow settings and higher render scale. Read `engine.capabilities.tier` in the page, or the `tier` field of `window.__null3dHold`, to prove which path drew the frame.
257
+
238
258
  ### Common switches
239
259
 
240
260
  | Switch | Effect |
package/docs/pages.md CHANGED
@@ -251,7 +251,7 @@ summary: The docs pages of each area and group.
251
251
 
252
252
  | Page | What it covers |
253
253
  | --- | --- |
254
- | [The `null3d` command](cli/null3d.md) | create, test, bench, check-addon, shot, upgrade, assets, mcp, shaders record. |
254
+ | [The `null3d` command](cli/null3d.md) | create, test, bench, check-addon, shot, upgrade, assets, mcp, shaders record, shaders verify. |
255
255
 
256
256
  ## Errors
257
257
 
@@ -118,7 +118,7 @@ Write each accepted difference down, with its reason.
118
118
 
119
119
  ## Compare performance
120
120
 
121
- Measure both apps on the same device, browser, window size and pixel ratio, with the display at 60 Hz. Time a production build of each app: `bunx vite build`, then `bunx vite preview`. Never time null3D on the dev server. The dev server runs the engine's development checks in every frame, so the port looks slower than it ships.
121
+ Measure both apps on the same device, browser, window size and pixel ratio, with the display at 60 Hz. Time a production build of each app: `bunx vite build`, then `bunx vite preview`. Never time null3D on the dev server. The dev server runs the engine's development checks in every frame, so the port looks slower than it ships. Give the browser WebGPU, as [Testing your sketch](../guides/testing.md#the-browser-must-take-the-webgpu-path) shows, or both apps run their WebGL2 path.
122
122
 
123
123
  `bunx @null3d/cli bench` makes a production build of the null3D app, and measures it ([The `null3d` command](../cli/null3d.md#bench)):
124
124
 
@@ -253,6 +253,11 @@ const DOCS = {
253
253
  details: 'The driver refused the pipeline among the other builds, and again when the engine built it alone. A driver does this when it runs short of memory as it compiles the shader, or when its compiler fails on the shader.\n\nOn WebGL2, a program that the driver refuses to link twice counts the same. The engine reports the first failure of each kind on each GPU device.',
254
254
  detailsSummary: 'how the engine builds the pipeline',
255
255
  },
256
+ E1308: {
257
+ title: 'GPU path not in this build',
258
+ cause: "This page's build holds the shaders of one GPU path, and this device would draw with the other. The Vite plugin's shaders.gpuPaths option left the other path out, for a deployment whose browser always offers the shipped one, such as an Electron app whose Chromium draws with WebGPU.",
259
+ example: "E1308: this build ships only the WebGPU shaders, and this device would draw with WebGL2. The Vite plugin's shaders.gpuPaths option left WebGL2 out.",
260
+ },
256
261
  E1401: {
257
262
  title: 'Not a sketch module',
258
263
  cause: 'The module passed to createEngine as the sketch does not export a sketch as its default export.',
@@ -272,6 +277,12 @@ const DOCS = {
272
277
  title: 'Engine thread failed',
273
278
  cause: 'An engine thread, or the drawing on the page, hit an error it could not handle, such as a trap in the engine core. After the start, the thread stops its loop: the engine draws no new frames, and engine.onFailure receives this error. During the start, createEngine() stops the engine and rejects with this error.',
274
279
  example: 'E1404: the render worker failed: out of memory.',
280
+ cases: [
281
+ "The message may quote a failed import of a table of shared shader paragraphs. An older build's module names a fixed table file, so a deploy that mixes builds can pair it with a table from another build. The browser reports that the module does not provide an export that it imports, such as AREA_LIGHTS_SHARED_126.",
282
+ ],
283
+ fixCases: [
284
+ "If an older build's page shows this, rebuild it with this version of the plugin. That version names each table after its content, so the page cannot ask for an old table. A cache purge also removes the old files.",
285
+ ],
275
286
  },
276
287
  E1405: {
277
288
  title: 'Engine thread did not start',
@@ -26,7 +26,7 @@ const thread = globalThis;
26
26
  * Every code, joined, so an error keeps its code before the file of fixes arrives. A test keeps it
27
27
  * equal to the keys of the table.
28
28
  */
29
- const CODES = 'E1101E1102E1103E1104E1105E1106E1107E1108E1109E1110E1111E1112E1203E1204E1205E1206E1207E1208E1209E1213E1214E1215E1216E1217E1218E1219E1220E1221E1222E1223E1224E1225E1301E1302E1303E1304E1305E1306E1307E1401E1402E1403E1404E1405E1406E1407E1408E1409E1410E1411E1412E1413E1414E1415E1416E1417E1418E1419E1420E1421E1422E1423E1424E1425E1426E1430E1431E1432E1433E1434E1435E1436E1437E1501E1502E1503E1504E1505E1506';
29
+ const CODES = 'E1101E1102E1103E1104E1105E1106E1107E1108E1109E1110E1111E1112E1203E1204E1205E1206E1207E1208E1209E1213E1214E1215E1216E1217E1218E1219E1220E1221E1222E1223E1224E1225E1301E1302E1303E1304E1305E1306E1307E1308E1401E1402E1403E1404E1405E1406E1407E1408E1409E1410E1411E1412E1413E1414E1415E1416E1417E1418E1419E1420E1421E1422E1423E1424E1425E1426E1430E1431E1432E1433E1434E1435E1436E1437E1501E1502E1503E1504E1505E1506';
30
30
  const waiting = [];
31
31
  /** This copy's wait for the thread's load of the fixes, which settles its own waiting errors. */
32
32
  let loading;
@@ -38,6 +38,7 @@ export declare const ERROR_FIXES: {
38
38
  E1305: string;
39
39
  E1306: string;
40
40
  E1307: string;
41
+ E1308: string;
41
42
  E1401: string;
42
43
  E1402: string;
43
44
  E1403: string;
@@ -43,10 +43,11 @@ export const ERROR_FIXES = {
43
43
  E1305: "Read the message: it quotes the GPU path. A buffer or texture past the device's limits names the limit: make the scene smaller there. Otherwise this is an engine bug: report it with the message and the browser.",
44
44
  E1306: 'Update Safari to version 18 or later. On iPhone and iPad, update iOS or iPadOS to 18 or later, which updates the engine of every browser there.',
45
45
  E1307: "Read the message: it names the pipeline and quotes the driver. If it names a custom material, shorten that material's WGSL, with fewer texture reads, loops and calls. On a device with little memory, use a lower quality preset, smaller textures and fewer objects. Update the browser and the device's system software, and report an engine template with the device.",
46
+ E1308: "Add 'webgl2' to the Vite plugin's shaders.gpuPaths option and build the page again, for a deployment whose devices may lack WebGPU. A build that ships one GPU path must always offer it.",
46
47
  E1401: 'End the sketch module with export default defineSketch(...), and pass that module to createEngine.',
47
48
  E1402: 'Reinstall the engine package so all of its parts come from one version. If you build the engine from source, run bun run build again.',
48
49
  E1403: 'Create objects in the setup function you pass to defineSketch, or later, never when the sketch module loads.',
49
- E1404: 'This is an engine bug. Report it with the message and the browser, then destroy the engine and start it again.',
50
+ E1404: "When the message quotes a failed import of a shader table, rebuild the page with this version of the plugin. Or purge the host's cache. Otherwise this is an engine bug: report it with the message and the browser, then destroy the engine and start it again.",
50
51
  E1405: "Read the message: it names the worker that did not start, and why. The sketch worker also reports an error that your sketch's setup function threw: fix the setup function. Otherwise, check that the page is served with the isolation headers and that the engine files load. Allow the workers in the `worker-src` of a Content-Security-Policy, and report the error if it repeats.",
51
52
  E1406: "Check that the host serves every file that the build wrote, at the paths that the build gave them. The engine's .wasm files, the KTX2 transcoder's files, the glTF loader's files, the meshopt decoder and the level planner's simplifier are among them. If the page loads at other times, the network dropped: reload the page.",
52
53
  E1407: 'Give the sketch time to hold at in seconds, such as ?hold=1.5 or hold: 1.5. A bare ?hold holds at the time of the hold option, or at 0 without one.',
@@ -4,3 +4,9 @@
4
4
  * engine names the word and the list that must carry it.
5
5
  */
6
6
  export declare const LISTED_PERMUTATIONS: readonly number[] | null;
7
+ /**
8
+ * The GPU paths whose shaders this build ships, or null when it ships both. A build
9
+ * that ships one path drops the other path's shader files, and the engine names this
10
+ * build's choice when a device would need a path that it lacks.
11
+ */
12
+ export declare const SHIPPED_GPU_PATHS: readonly ('webgpu' | 'webgl2')[] | null;
@@ -7,3 +7,9 @@
7
7
  * engine names the word and the list that must carry it.
8
8
  */
9
9
  export const LISTED_PERMUTATIONS = null;
10
+ /**
11
+ * The GPU paths whose shaders this build ships, or null when it ships both. A build
12
+ * that ships one path drops the other path's shader files, and the engine names this
13
+ * build's choice when a device would need a path that it lacks.
14
+ */
15
+ export const SHIPPED_GPU_PATHS = null;
@@ -5,6 +5,11 @@ import { type DeviceShaders, type FirstUseShaders, type ShaderVariants } from '.
5
5
  * gives it, for a device with those bits.
6
6
  */
7
7
  export type DeviceModuleLoader = (bits: number, file: string | undefined) => Promise<FirstUseShaders>;
8
+ /** The error for a shader file that did not load, which a pipeline needs. Its cause is the load's. */
9
+ export declare class ShaderLoadError extends Error {
10
+ readonly reason: unknown;
11
+ constructor(reason: unknown, message: string);
12
+ }
8
13
  /** The device shaders that a backend reads, which grow by another module when a pipeline needs it. */
9
14
  export declare class DeviceShaderSet {
10
15
  readonly shaders: DeviceShaders;
@@ -32,6 +32,15 @@ const HDR_FEATURES = new Set([
32
32
  'fog_volume',
33
33
  'taa',
34
34
  ]);
35
+ /** The error for a shader file that did not load, which a pipeline needs. Its cause is the load's. */
36
+ export class ShaderLoadError extends Error {
37
+ reason;
38
+ constructor(reason, message) {
39
+ super(message, { cause: reason });
40
+ this.reason = reason;
41
+ this.name = 'ShaderLoadError';
42
+ }
43
+ }
35
44
  /** The device shaders that a backend reads, which grow by another module when a pipeline needs it. */
36
45
  export class DeviceShaderSet {
37
46
  shaders;
@@ -88,7 +97,7 @@ export class DeviceShaderSet {
88
97
  const key = this.loadModule(file, bits);
89
98
  if (this.failures.has(key)) {
90
99
  const reason = this.failures.get(key);
91
- throw new Error(`the engine could not download the shaders that a pipeline needs: ${reason instanceof Error ? reason.message : String(reason)}. Check the network, and that the page's build is deployed whole`, { cause: reason });
100
+ throw new ShaderLoadError(reason, `the engine could not download the shaders that a pipeline needs: ${reason instanceof Error ? reason.message : String(reason)}. Check the network, and that the page's build is deployed whole`);
92
101
  }
93
102
  return this.settled.has(key);
94
103
  }
@@ -1,4 +1,18 @@
1
1
  import type { ShaderVariant, ShaderVariants } from '../generated/shaders.js';
2
+ /** The word as a list writes it: without the bits that a device fixes. */
3
+ export declare function listedWord(permutation: number): number;
4
+ /**
5
+ * The error for a pipeline whose loaded shader set has no variant that it asks for. Its `word` is
6
+ * the word as a list writes it, which names the entry to add.
7
+ */
8
+ export declare class MissingVariantError extends Error {
9
+ readonly word: number;
10
+ constructor(word: number, message: string);
11
+ }
12
+ /** Reports a pipeline or pass whose shader variant the loaded set lacks, for it to skip. */
13
+ export declare function reportMissingVariant(pipeline: string, word: number): void;
14
+ /** Reports a pipeline or pass whose shader file failed to load, for it to skip. */
15
+ export declare function reportUnavailableShader(pipeline: string, reason: string): void;
2
16
  /**
3
17
  * The variant of a shader for a pipeline's permutation word, with output for `target`, or
4
18
  * undefined when the shader has none. The word never holds the half precision bit, which the
@@ -20,3 +34,14 @@ export declare function missingVariant(permutation: number, listed?: boolean): s
20
34
  * that the list lacks, as `missingVariant` does.
21
35
  */
22
36
  export declare function missingShader(name: string, permutation: number, listed?: boolean): string;
37
+ /**
38
+ * The error for an engine pass whose shader the loaded set lacks. Its `word` is the word as a list
39
+ * writes it, and `shader` names the pass's shader for a report.
40
+ */
41
+ export declare class MissingShaderError extends Error {
42
+ readonly shader: string;
43
+ readonly word: number;
44
+ constructor(shader: string, word: number, message: string);
45
+ }
46
+ /** The error for the engine pass of `name` whose shader the loaded set lacks. */
47
+ export declare function missingShaderError(name: string, permutation: number, listed?: boolean): MissingShaderError;
@@ -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