@null3d/engine 0.1.1 → 0.1.2

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.
@@ -3754,13 +3754,13 @@ export function writeParticleRecords(id, count, first) {
3754
3754
  function __wbg_get_imports() {
3755
3755
  const import0 = {
3756
3756
  __proto__: null,
3757
- __wbg___null3dWantJobWorkers_10d524ad0ed0e256: function() {
3757
+ __wbg___null3dWantJobWorkers_a7e579abfe5104c1: function() {
3758
3758
  globalThis.__null3dWantJobWorkers();
3759
3759
  },
3760
- __wbg_error_d1f27407881ca75b: function(arg0, arg1) {
3760
+ __wbg_error_1b4739328f95458f: function(arg0, arg1) {
3761
3761
  console.error(getStringFromWasm0(arg0, arg1));
3762
3762
  },
3763
- __wbg_now_5de1fa58eeb98466: function() {
3763
+ __wbg_now_2d6cdf5b44f2ba86: function() {
3764
3764
  const ret = performance.now();
3765
3765
  return ret;
3766
3766
  },
@@ -3971,4 +3971,4 @@ async function __wbg_init(module_or_path) {
3971
3971
 
3972
3972
  export { initSync, __wbg_init as default };
3973
3973
 
3974
- export const coreSources = "51abe3b07231ee49";
3974
+ export const coreSources = "971a5051f735f1c8";
Binary file
@@ -3754,13 +3754,13 @@ export function writeParticleRecords(id, count, first) {
3754
3754
  function __wbg_get_imports(memory) {
3755
3755
  const import0 = {
3756
3756
  __proto__: null,
3757
- __wbg___null3dWantJobWorkers_10d524ad0ed0e256: function() {
3757
+ __wbg___null3dWantJobWorkers_a7e579abfe5104c1: function() {
3758
3758
  globalThis.__null3dWantJobWorkers();
3759
3759
  },
3760
- __wbg_error_d1f27407881ca75b: function(arg0, arg1) {
3760
+ __wbg_error_1b4739328f95458f: function(arg0, arg1) {
3761
3761
  console.error(getStringFromWasm0(arg0, arg1));
3762
3762
  },
3763
- __wbg_now_5de1fa58eeb98466: function() {
3763
+ __wbg_now_2d6cdf5b44f2ba86: function() {
3764
3764
  const ret = performance.now();
3765
3765
  return ret;
3766
3766
  },
@@ -3987,4 +3987,4 @@ export function releaseInstance() {
3987
3987
  dropMemoryViews();
3988
3988
  }
3989
3989
 
3990
- export const coreSources = "51abe3b07231ee49";
3990
+ export const coreSources = "971a5051f735f1c8";
Binary file
@@ -280,6 +280,7 @@ type ErrorCode =
280
280
  | 'E1305'
281
281
  | 'E1306'
282
282
  | 'E1307'
283
+ | 'E1308'
283
284
  | 'E1401'
284
285
  | 'E1402'
285
286
  | 'E1403'
@@ -590,7 +591,7 @@ The GPU path the engine draws with: core WebGPU, WebGPU in compatibility mode on
590
591
  ## `VERSION`
591
592
 
592
593
  ```ts
593
- const VERSION: '0.1.1'
594
+ const VERSION: '0.1.2'
594
595
  ```
595
596
 
596
597
  The engine version, which the WebAssembly core and this package always share.
@@ -187,6 +187,10 @@ Some laptops have a separate graphics chip next to the one built into the proces
187
187
 
188
188
  Other switches make one device test the paths of other devices. They cover copied uploads, shader compiles without the parallel compile extension, the 8-bit color path, each WebGL2 depth mode and each compressed texture family. The engine reads them in development builds, or in a production build with the Vite plugin's `urlSwitches` option on.
189
189
 
190
+ A production build can ship the shaders of one path alone. It suits a deployment whose browser always offers that path. The engine then refuses a tier that the build lacks, with [E1308](../errors/E1308.md), even where the browser offers it.
191
+
192
+ `engine.report` still describes the browser, and `engine.capabilities.tier` still names the path that the page draws with. The Vite plugin's `shaders.gpuPaths` option makes such a build, and the build is smaller than one of both paths ([Ship a subset of the GPU paths](../guides/assets-pipeline.md#ship-a-subset-of-the-gpu-paths)).
193
+
190
194
  On WebGL2, uploads read straight from the engine's shared memory. A browser that refuses to read shared memory gets a copy of each upload instead.
191
195
 
192
196
  The switch `?depth=` forces a WebGL2 depth mode: `reversed`, `reversed-gl` or `standard`, where the near plane stores 0 and the far plane 1. A browser without `EXT_clip_control` cannot draw `reversed`, so it draws its own mode instead. Shadow maps hold the same depth values as on WebGPU in `reversed` and `reversed-gl`. In `standard` they would hold them the other way around, so WebGL2 draws no shadows in that mode.
@@ -0,0 +1,31 @@
1
+ ---
2
+ id: errors/E1308
3
+ title: "E1308: GPU path not in this build"
4
+ generated: true
5
+ summary: "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."
6
+ ---
7
+
8
+ # E1308: GPU path not in this build
9
+
10
+ ## What happened
11
+
12
+ 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.
13
+
14
+ ## How to fix it
15
+
16
+ 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.
17
+
18
+ [Where problems appear](../guides/debugging.md#where-problems-appear) says where each kind of error reaches your code.
19
+
20
+ ## Example message
21
+
22
+ The engine prints the part below, then the fix above and a link to this page.
23
+
24
+ ```text
25
+ 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.
26
+ ```
27
+
28
+ ## See also
29
+
30
+ - [Error codes](index.md)
31
+ - [Debugging](../guides/debugging.md)
@@ -64,6 +64,7 @@ Codes from E2000 to E9999 belong to add-ons. An add-on's message starts with its
64
64
  | [E1305](E1305.md) | GPU rejected work | The GPU path refused a command that the engine gave it after the start, such as a buffer larger than the device allows. The objects that the command made or drew are missing, and the canvas can stay black. The engine reports the first time this happens on each GPU device, and draws on. |
65
65
  | [E1306](E1306.md) | Safari before 18 | The browser runs the WebKit engine of a Safari before 18, which null3D does not support. Every browser on iPhone and iPad runs WebKit, so Chrome, Edge and Firefox there count too. |
66
66
  | [E1307](E1307.md) | Pipeline not built | After the start, the GPU's driver could not build one pipeline that draws objects of the scene. The objects that draw with it are missing from the pass that the message names, and the engine draws on. |
67
+ | [E1308](E1308.md) | GPU path not in this build | 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. |
67
68
 
68
69
  ## Setup, loading and runtime
69
70
 
@@ -194,6 +194,8 @@ The `startsWith` check refuses an address that points outside `dist/`. The game'
194
194
 
195
195
  To check the app, open its developer tools and read `crossOriginIsolated` in the console, or read `engine.capabilities.threaded` in the page's code. Both are `true` when the engine runs threaded.
196
196
 
197
+ An app that controls its browser frame can ship a subset of the GPU paths, which saves most of the shader set's size in its package and installer. Electron's Chromium draws with WebGPU where the device and its driver allow it, and that differs by operating system and Chromium version. Check each system that the app ships on, and test the built app there, before you rely on WebGPU alone ([Ship a subset of the GPU paths](../guides/assets-pipeline.md#ship-a-subset-of-the-gpu-paths)).
198
+
197
199
  ## Send the files with Brotli
198
200
 
199
201
  The engine's shader text compresses well with Brotli, which finds text that repeats far apart. gzip finds only repeats that are close together. So the host's compression changes what a page downloads at its start. On a threaded page, in the default latency mode ([Architecture](../concepts/architecture.md#latency-modes)), the engine's part of the start downloads about:
@@ -52,7 +52,7 @@ Every Vite build of a null3D project needs the plugin, for the dev server and fo
52
52
  - Starts each worker's on-demand imports together with the file that imports them, so a worker does not wait one round trip for each file.
53
53
  - Writes the notices of the third-party code that the engine and the add-ons ship beside the page in each production build. [Hosting](hosting.md#publish-the-third-party-notices) says what to do with them.
54
54
  - Writes the list of the build's files, `null3d-files.json`, beside the page in each production build. A game's service worker caches the files of that list for offline play, as [Hosting](hosting.md#offline-play) shows.
55
- - Copies the engine's compiled shader files into a production build, each as a file of its own. Its `shaders.list` option names a list of the permutation words that your pages draw with. The build then copies only their builds ([Build only the shader permutations you draw with](../guides/assets-pipeline.md#build-only-the-shader-permutations-you-draw-with)).
55
+ - Copies the engine's compiled shader files into a production build, each as a file of its own. Its `shaders.list` option names a list of the permutation words that your pages draw with. The build then copies only their builds ([Build only the shader permutations you draw with](../guides/assets-pipeline.md#build-only-the-shader-permutations-you-draw-with)). Its `shaders.gpuPaths` option ships a subset of the GPU paths, such as WebGPU alone, for an app whose browser always offers them ([Ship a subset of the GPU paths](../guides/assets-pipeline.md#ship-a-subset-of-the-gpu-paths)).
56
56
  - Keeps each of the engine's files a file of its own, so a strict Content-Security-Policy does not block them. Vite still turns your own small files into `data:` addresses, which such a policy blocks.
57
57
 
58
58
  <details>
@@ -13,12 +13,12 @@ null3D comes with two agent skills. A skill is a folder of instructions that a c
13
13
  | `null3d-develop` | Builds, debugs and speeds up null3D projects, including product and marketing pages |
14
14
  | `null3d-port-threejs` | Ports three.js and React Three Fiber projects to null3D |
15
15
 
16
- Install the skills that match the engine version your project uses. Each release of the engine has its own skills.
16
+ Each release of the engine has its own skills. The links in this page give the latest release's skills. [Other agent tools](#other-agent-tools) shows how to pin an older release.
17
17
 
18
18
  ## Claude Code
19
19
 
20
20
  ```sh
21
- claude plugin marketplace add https://raw.githubusercontent.com/null3d-engine/null3d/main/.claude-plugin/marketplace.json
21
+ claude plugin marketplace add null3d-engine/null3d
22
22
  claude plugin install null3d@null3d
23
23
  ```
24
24
 
@@ -26,20 +26,23 @@ The plugin holds the skills of the latest release, and Claude Code downloads onl
26
26
 
27
27
  ## claude.ai and the Claude desktop app
28
28
 
29
- Each release's page on GitHub has `null3d-develop.zip` and `null3d-port-threejs.zip` attached. Upload each zip where the app lets you add skills.
29
+ Download each skill as a zip and upload it where the app lets you add skills:
30
+
31
+ - [null3d-develop](https://null3d.dev/skills/null3d-develop)
32
+ - [null3d-port-threejs](https://null3d.dev/skills/null3d-port-threejs)
30
33
 
31
34
  ## Other agent tools
32
35
 
33
- The [`skills` command](https://github.com/vercel-labs/skills) installs a skill into many agent tools, including Claude Code, Cursor and OpenCode. Give it the folder of each skill in the release that your project uses:
36
+ The [`skills` command](https://github.com/vercel-labs/skills) installs a skill into many agent tools, including Claude Code, Cursor and OpenCode:
34
37
 
35
38
  ```sh
36
- bunx skills add https://github.com/null3d-engine/null3d/tree/0.1.0/.claude/skills/null3d-develop
37
- bunx skills add https://github.com/null3d-engine/null3d/tree/0.1.0/.claude/skills/null3d-port-threejs
39
+ bunx skills add https://null3d.dev/skills/null3d-develop
40
+ bunx skills add https://null3d.dev/skills/null3d-port-threejs
38
41
  ```
39
42
 
40
- Replace `0.1.0` with your engine version. The command asks which agents to install into, and `-a` names them.
43
+ The command asks which agents to install into, and `-a` names them. These links give the latest release. For an older engine, add its release tag as a last path segment, such as `/skills/null3d-develop/<tag>`.
41
44
 
42
- To install by hand, copy each skill's folder from `.claude/skills/` in the release into your agent's skills folder, and keep the folder's name. Use those copies: the repository's `skills/` folder also holds test material for the skills.
45
+ To install by hand, unzip a skill into your agent's skills folder and keep the folder's name.
43
46
 
44
47
  ## Docs by ID
45
48
 
@@ -679,3 +679,49 @@ NULL3D_SHADER_PERMUTATIONS=examples/shader-permutations.txt bun run build
679
679
  Without the variable, or with it empty, `bun run build` compiles every permutation. `bun run examples:build` reads the examples' list this way. With it, the build's cache keys and its input hash include the list, so a changed list builds again.
680
680
 
681
681
  The file that the asset command writes into a model, `asset.extras.NULL3D_shaders`, names the bits that the model turns on. The list here is different: it holds the whole words that your scenes draw with. [Loading screens](loading-screens.md#loading-everything-up-front) describes the model's list.
682
+
683
+ ## Ship a subset of the GPU paths
684
+
685
+ The engine draws with WebGPU where the browser offers it, and with WebGL2 everywhere else ([GPU tiers and backends](../concepts/backends.md)). A production build copies the shaders of both paths, so a host or a desktop app stores both. Most of that is the WebGL2 half: GLSL text is about nine tenths of the shader set's bytes.
686
+
687
+ A deployment that knows which paths its devices offer can ship a subset of them. An Electron app ships Chromium, and Chromium draws with WebGPU where the device lets it. A kiosk, a game inside a WebView, and a game that requires Chrome all know the same. Such a build drops the other path's shader files, and its app package holds no WebGL2 shader files.
688
+
689
+ The build, the app package and the installer get smaller. The download shrinks too, wherever a visitor downloads the whole app. That covers an Electron installer, an archive of the site, and the files that a service worker caches for offline play. A page's own start download does not change, because a page already downloads one path's files.
690
+
691
+ Ship a subset only when every device that runs the app offers the paths it keeps. A page on a device without WebGPU stops with [E1308](../errors/E1308.md), and the engine cannot fall back. Check the devices and the operating systems that the app ships on, with a run of `navigator.gpu` or `engine.capabilities.tier` on each.
692
+
693
+ ```ts
694
+ // vite.config.ts
695
+ import null3d from '@null3d/vite-plugin';
696
+ import { defineConfig } from 'vite';
697
+
698
+ export default defineConfig({
699
+ plugins: [null3d({ shaders: { gpuPaths: ['webgpu'] } })],
700
+ });
701
+ ```
702
+
703
+ The option takes `'webgpu'` and `'webgl2'`, and it must include `'webgpu'`. The shader compiler builds every shader for WebGPU, so a project's own shaders and its add-ons' shaders have no other form. That leaves `['webgpu']` as the one path a build can ship, and leaving the option out ships both.
704
+
705
+ A build with the option does these things:
706
+
707
+ - It copies only the WebGPU files of the engine's shader set. The set keeps its module of loader tables, which name the WebGL2 files, so those tables resolve to one empty module instead.
708
+ - It compiles your own custom shaders and their materials for WebGPU alone, and drops the WebGL2 sets of a custom material, effect or sky layer.
709
+ - It drops the WebGL2 builds of an add-on package's compiled shaders.
710
+ - It writes the shipped paths into the engine's marker module, which is how the engine knows its build's choice.
711
+
712
+ The examples' production build, with the whole set and no list, shows the difference:
713
+
714
+ | GPU paths that the build ships | Shader files | Size |
715
+ | --- | --- | --- |
716
+ | Both, the default | 8,689 | 4,118 MB |
717
+ | WebGPU alone | 1,967 | 330 MB |
718
+
719
+ The files that remain of the dropped path are eight stub modules of about 60 bytes. Each stands in for a module that a page would load by name, and a page never reads one on the WebGPU path.
720
+
721
+ The option combines with `shaders.list`: a build with both copies only the listed words' builds of the shipped path.
722
+
723
+ The dev server keeps both paths, so you can test the other one with `?gpu=webgl2`. When a page draws with a path that a production build does not ship, the dev server warns. It warns in its terminal and in the browser's console, once for each page.
724
+
725
+ Test the production build on the shipped path before you ship it. Run your browser tests against it, and check that each page draws. A test that forces the other path with `?gpu=webgl2` fails with E1308, which is the message that a device without WebGPU shows.
726
+
727
+ The build still holds the JavaScript of both GPU paths, which is a small part of the engine's code. It also holds the engine's own passes' GLSL text, which is in the shared shader module. An add-on that a page loads from a CDN at run time keeps both paths, because the plugin narrows only what the build bundles.
@@ -83,6 +83,39 @@ For a game, the late state has no page content to show. There it changes the mes
83
83
 
84
84
  Later page blocks run after a successful start, inside that `try`.
85
85
 
86
+ ### A scene that builds in stages
87
+
88
+ A scene whose later stages build after the first frame still reveals its canvas at the first frame. A canvas held back for a later stage makes the visitor wait for that stage's whole build.
89
+
90
+ On a Galaxy S24 on the WebGL2 path, a page whose canvas waits for its city stage shows it 6.4 seconds into a repeat visit. Revealed at the first frame, the same canvas shows after 1.8 seconds, and after 3.2 seconds on a first visit.
91
+
92
+ Hide the place of a stage that has not built yet. Fog that lies thick on the ground and thins with height hides empty ground, and leaves a subject high above it in clear air. Once the stage shows, clear the fog over a second or two. Clear it by the clock, because the next warm-up can hold the frames back.
93
+
94
+ ```ts
95
+ // sketch.ts: fog over the place of the city, which builds after the first frame.
96
+ const mist = { color: '#5a6472', density: 0.2, height: 0, heightFalloff: 0.03, background: 1 };
97
+ scene.setFog(mist);
98
+ let clearFrom = 0;
99
+ void engine.firstFrame.then(async () => {
100
+ await buildCity(); // creates the city hidden, warms it up, then shows it
101
+ clearFrom = performance.now();
102
+ });
103
+ return {
104
+ onUpdate() {
105
+ if (clearFrom === 0 || mist.density === 0) return;
106
+ mist.density = 0.2 * Math.max(0, 1 - (performance.now() - clearFrom) / 2000);
107
+ scene.setFog(mist);
108
+ },
109
+ };
110
+ ```
111
+
112
+ - Give the fog the tone of what it hides. Light words over a pale fog do not read, and a darker fog keeps the page's contrast.
113
+ - Start every value that the sketch eases at the page's own state, such as the hour of a day cycle. The first frame shows the ease. Pass the page's state in `sketchData`.
114
+ - After the deadline, the poster shows the finished scene. When the first frame comes later, keep the poster until the canvas shows as much as the poster does.
115
+ - Words styled to stand over the scene need the page's own ink while a loader stands on a plain background. Fade them to their color as the canvas comes in.
116
+ - A fill light that only a plain first view needs fades with that view. A directional light lights every view, and a device that skips the richer stage keeps it.
117
+ - Build each part that an interaction needs in an early stage that every device gets. A part that a lighter device skips takes the interaction with it. For example, a cube that opens round a glowing heart never opens where the heart is missing.
118
+
86
119
  ## Mark a decorative canvas
87
120
 
88
121
  A scene that only decorates gets `aria-hidden="true"`, so screen readers skip it. It takes no keyboard focus. Give it `pointer-events: none` when it does not react to the pointer, so clicks reach the page. [Accessibility](accessibility.md) covers a canvas the visitor operates.
@@ -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)).
@@ -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.
@@ -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.
@@ -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.',
@@ -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,6 +43,7 @@ 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.',
@@ -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;
@@ -7,6 +7,7 @@ import { type QualityPreset } from '../quality/presets.js';
7
7
  import type { GpuErrorKind } from '../render/loss.js';
8
8
  import type { Tier } from '../render/renderer.js';
9
9
  import type { ReplayResult } from '../shared/recording.js';
10
+ import { type GpuPath } from '../shared/tier.js';
10
11
  import type { QualityUpdate } from '../sketch/quality.js';
11
12
  import type { LabelSlotSender } from '../sketch/ui.js';
12
13
  import type { RendererRequest, WorkerReply } from '../workers/protocol.js';
@@ -761,8 +762,20 @@ interface TierChoice {
761
762
  tier: Tier;
762
763
  forceCompat: boolean;
763
764
  }
764
- /** Picks the GPU tier from feature tests, never from browser or GPU names. */
765
- export declare function chooseTier(report: CapabilityReport, wanted: GpuSwitch, inWorker: boolean): TierChoice | null;
765
+ /** True when this build holds the shaders of `path`. */
766
+ export declare function shipsPath(path: GpuPath): boolean;
767
+ /**
768
+ * Picks the GPU tier from feature tests, never from browser or GPU names. A path whose shaders this
769
+ * build does not ship counts as unavailable, whether or not the browser offers it.
770
+ */
771
+ export declare function chooseTier(report: CapabilityReport, wanted: GpuSwitch, inWorker: boolean, ships?: (path: GpuPath) => boolean): TierChoice | null;
772
+ /**
773
+ * The error for a start that found no usable GPU tier. When the build holds the shaders of one path
774
+ * and this start would draw with the other, it names the build's choice (E1308), because no browser
775
+ * or setting can fix that page. Otherwise the browser offers no path the engine can draw with, or
776
+ * none that the page asked for (E1301).
777
+ */
778
+ export declare function noTierError(report: CapabilityReport, requested: GpuSwitch, inWorker: boolean, ships?: (path: GpuPath) => boolean): EngineError;
766
779
  /**
767
780
  * The error of a worker that failed to start. An engine error keeps its code and message; any
768
781
  * other failure becomes E1405.
@@ -15,6 +15,7 @@ import { EngineError, errorFixesReady, errorOfMessage } from '../errors/engine-e
15
15
  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
+ import { SHIPPED_GPU_PATHS } from '../generated/shader-permutations.js';
18
19
  import { recordPermutations, reportPermutations, stopRecordingPermutations } from '../gpu/variants.js';
19
20
  import { maxTargetFps, } from '../quality/check.js';
20
21
  import { choosePreset, crashLowest, crashTier, deviceKind, gpuOcclusionChoice, memoryPreset, textureMemoryCap, withinTier, } from '../quality/chooser.js';
@@ -32,9 +33,10 @@ import { KEY_CODES } from '../shared/key-codes.js';
32
33
  import { memoryBytes } from '../shared/memory-views.js';
33
34
  import { createMetricsBuffer, MetricsReader, threadRoles } from '../shared/metrics.js';
34
35
  import { addMeasurementRelease } from '../shared/page-measurement.js';
35
- import { PERMUTATION_WORD_EVENT } from '../shared/permutation-words.js';
36
+ import { GPU_PATH_EVENT, PERMUTATION_WORD_EVENT } from '../shared/permutation-words.js';
36
37
  import { sketchDataText } from '../shared/sketch-data.js';
37
38
  import { clearJobTasks, jobAsker, setJobTasks } from '../shared/task-host.js';
39
+ import { pathOfTier } from '../shared/tier.js';
38
40
  import { hearAddonsEarly, onAddonChecked } from '../shared/version.js';
39
41
  import { VIDEO_FOLLOW } from '../shared/videos.js';
40
42
  import { notifySlot, setWakeByMessage } from '../shared/wake.js';
@@ -116,11 +118,26 @@ const INSPECT_REPLY_LIMIT_MS = 30_000;
116
118
  * than waiting for a worker that may never speak.
117
119
  */
118
120
  export const RETRY_REPLY_MS = 10_000;
119
- /** Picks the GPU tier from feature tests, never from browser or GPU names. */
120
- export function chooseTier(report, wanted, inWorker) {
121
+ /** The GPU paths whose shaders this build ships, or null for both, as the plugin's build wrote it. */
122
+ const SHIPPED_PATHS = SHIPPED_GPU_PATHS === null ? null : new Set(SHIPPED_GPU_PATHS);
123
+ /** True when this build holds the shaders of `path`. */
124
+ export function shipsPath(path) {
125
+ return SHIPPED_PATHS === null || SHIPPED_PATHS.has(path);
126
+ }
127
+ /** The path that a page's GPU switch draws with, or undefined for the engine's own choice. */
128
+ function pathOfSwitch(wanted) {
129
+ return wanted === 'auto' ? undefined : pathOfTier(wanted === 'webgl2' ? 'webgl2' : 'webgpu');
130
+ }
131
+ /**
132
+ * Picks the GPU tier from feature tests, never from browser or GPU names. A path whose shaders this
133
+ * build does not ship counts as unavailable, whether or not the browser offers it.
134
+ */
135
+ export function chooseTier(report, wanted, inWorker, ships = shipsPath) {
121
136
  const worker = 'failure' in report.worker ? undefined : report.worker;
122
- const webgpu = report.webgpu.compatibilityAdapter && (!inWorker || worker?.offscreenWebGPU === true);
123
- const webgl2 = inWorker ? worker?.offscreenWebGL2 === true : report.webgl2.available;
137
+ const webgpu = ships('webgpu') &&
138
+ report.webgpu.compatibilityAdapter &&
139
+ (!inWorker || worker?.offscreenWebGPU === true);
140
+ const webgl2 = ships('webgl2') && (inWorker ? worker?.offscreenWebGL2 === true : report.webgl2.available);
124
141
  if (wanted === 'webgl2')
125
142
  return webgl2 ? { tier: 'webgl2', forceCompat: false } : null;
126
143
  if (wanted === 'compat')
@@ -136,6 +153,38 @@ export function chooseTier(report, wanted, inWorker) {
136
153
  };
137
154
  return webgl2 ? { tier: 'webgl2', forceCompat: false } : null;
138
155
  }
156
+ /** The name of a GPU path, as the error messages carry it. */
157
+ function pathName(path) {
158
+ return path === 'webgl2' ? 'WebGL2' : 'WebGPU';
159
+ }
160
+ /** The GPU paths that this build ships, as the error messages carry them. */
161
+ function shippedNames(ships) {
162
+ if (ships('webgpu') && ships('webgl2'))
163
+ return 'WebGPU and WebGL2';
164
+ return ships('webgpu') ? 'WebGPU' : 'WebGL2';
165
+ }
166
+ /**
167
+ * The error for a start that found no usable GPU tier. When the build holds the shaders of one path
168
+ * and this start would draw with the other, it names the build's choice (E1308), because no browser
169
+ * or setting can fix that page. Otherwise the browser offers no path the engine can draw with, or
170
+ * none that the page asked for (E1301).
171
+ */
172
+ export function noTierError(report, requested, inWorker, ships = shipsPath) {
173
+ const named = pathOfSwitch(requested);
174
+ if (named !== undefined && !ships(named))
175
+ return new EngineError('E1308', `this build ships only the ${shippedNames(ships)} shaders, and ?gpu=${requested} asks for ${pathName(named)}. Build the project with both GPU paths, or remove the switch.`);
176
+ if (named !== undefined)
177
+ return new EngineError('E1301', `no usable GPU path for ?gpu=${requested} in this browser.`);
178
+ const worker = 'failure' in report.worker ? undefined : report.worker;
179
+ const offered = report.webgpu.compatibilityAdapter
180
+ ? 'webgpu'
181
+ : (inWorker ? worker?.offscreenWebGL2 === true : report.webgl2.available)
182
+ ? 'webgl2'
183
+ : undefined;
184
+ if (offered !== undefined && !ships(offered))
185
+ return new EngineError('E1308', `this build ships only the ${shippedNames(ships)} shaders, and this device would draw with ${pathName(offered)}. The Vite plugin's shaders.gpuPaths option left ${pathName(offered)} out. Build the project with both GPU paths, or run the page in a browser that offers ${pathName(ships('webgpu') ? 'webgpu' : 'webgl2')}.`);
186
+ return new EngineError('E1301', `no usable GPU path for ?gpu=${requested} in this browser.`);
187
+ }
139
188
  /**
140
189
  * True while this page is hidden. A hidden page draws no frames, so a capture's answer comes once
141
190
  * the page shows again, however long that takes, and the answer's limit counts only the time the
@@ -925,6 +974,12 @@ function placement(options, switches) {
925
974
  function announcePermutationWord(word) {
926
975
  globalThis.dispatchEvent?.(new CustomEvent(PERMUTATION_WORD_EVENT, { detail: word }));
927
976
  }
977
+ /** In a development build, tells the dev server the GPU path that this engine draws with. */
978
+ function announceGpuPath(tier) {
979
+ if (!DEV)
980
+ return;
981
+ globalThis.dispatchEvent?.(new CustomEvent(GPU_PATH_EVENT, { detail: pathOfTier(tier) }));
982
+ }
928
983
  /**
929
984
  * Starts the engine with the page's switches. With a hold time or a replay, it resolves once the
930
985
  * last frame is read back, and publishes it.
@@ -1614,8 +1669,9 @@ async function startEngine(options, switches, modes, { threaded, sketchThread },
1614
1669
  drawModule ??= loadDrawModule();
1615
1670
  }
1616
1671
  if (!choice)
1617
- throw new EngineError('E1301', `no usable GPU path for ?gpu=${requested} in this browser.`);
1672
+ throw noTierError(report, requested, renderThread !== 'main');
1618
1673
  tier = choice.tier;
1674
+ announceGpuPath(tier);
1619
1675
  const { forceCompat } = choice;
1620
1676
  // Where the page draws, it moves the label elements right after each frame it draws.
1621
1677
  const labels = new PageLabels(views, renderThread === 'main');
@@ -1 +1 @@
1
- {"tag":"0.1.1","file":"0.1.1-shaders.tar.br","url":"https://github.com/null3d-engine/null3d/releases/download/0.1.1/0.1.1-shaders.tar.br","sha256":"be65517c3b8351b5756a8d38967fa37d102daab39fa4152db245ad658c6f39de"}
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,2 +1,8 @@
1
1
  /** The event on the page's global object that carries a word that the page draws with. */
2
2
  export declare const PERMUTATION_WORD_EVENT = "null3d:permutation";
3
+ /**
4
+ * The event on the page's global object that carries the GPU path that the engine started on. The
5
+ * dev server compares it with the paths that a production build ships, and warns when a page draws
6
+ * with a path that the build leaves out.
7
+ */
8
+ export declare const GPU_PATH_EVENT = "null3d:gpu-path";
@@ -6,3 +6,9 @@
6
6
  // too.
7
7
  /** The event on the page's global object that carries a word that the page draws with. */
8
8
  export const PERMUTATION_WORD_EVENT = 'null3d:permutation';
9
+ /**
10
+ * The event on the page's global object that carries the GPU path that the engine started on. The
11
+ * dev server compares it with the paths that a production build ships, and warns when a page draws
12
+ * with a path that the build leaves out.
13
+ */
14
+ export const GPU_PATH_EVENT = 'null3d:gpu-path';
@@ -5,3 +5,12 @@
5
5
  * @category api/engine
6
6
  */
7
7
  export type Tier = 'webgpu' | 'webgpu-compat' | 'webgl2';
8
+ /**
9
+ * A GPU path that a build can ship: WebGPU, whose shaders are WGSL, or WebGL2, whose shaders are
10
+ * GLSL ES 3.00. WebGPU's compatibility mode draws with the WebGPU shaders.
11
+ *
12
+ * @category api/engine
13
+ */
14
+ export type GpuPath = 'webgpu' | 'webgl2';
15
+ /** The path whose shaders a tier draws with. */
16
+ export declare function pathOfTier(tier: Tier): GpuPath;
@@ -1,3 +1,6 @@
1
1
  // The GPU paths, in a file of their own, so code without browser types can name them: the quality
2
2
  // presets and the docs generator.
3
- export {};
3
+ /** The path whose shaders a tier draws with. */
4
+ export function pathOfTier(tier) {
5
+ return tier === 'webgl2' ? 'webgl2' : 'webgpu';
6
+ }
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @category api/engine
5
5
  */
6
- export declare const VERSION = "0.1.1";
6
+ export declare const VERSION = "0.1.2";
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.1';
14
+ export const VERSION = '0.1.2';
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@null3d/engine",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "The null3D engine, a high-performance browser 3D engine for agents, faster than three.js, with wide device compatibility: the TypeScript API, the page shim, the worker entry points, both WebAssembly builds and the docs.",
5
5
  "license": "MIT OR Apache-2.0",
6
6
  "author": "Ramesh Nair (https://hiddentao.com)",