@null3d/vite-plugin 0.1.0 → 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.
@@ -14,6 +14,8 @@ export declare const DRAW_INDEX = 1;
14
14
  export declare const TONE_MAP = 2;
15
15
  /** The permutation bit of builds that skin in the vertex shader. */
16
16
  export declare const SKIN = 64;
17
+ /** The permutation bit of builds that do their color math at half precision. */
18
+ export declare const HALF = 8192;
17
19
  /** A GPU path, as a build's field of its output names it. */
18
20
  type Target = 'wgsl' | 'glsl';
19
21
  /** The builds of one custom material, by name. */
@@ -38,9 +40,15 @@ export interface BuildSource {
38
40
  }
39
41
  /** The shaders of one module whose builds go to sets, in the order that the module holds them. */
40
42
  export declare class ModuleBuilds {
43
+ private readonly glsl;
41
44
  readonly sources: BuildSource[];
42
45
  /** How many shaders of each kind the module gave, which numbers their records in a set. */
43
46
  private readonly counts;
47
+ /**
48
+ * `glsl` false keeps the WebGPU path alone: each shader loses its WebGL2 builds and pieces
49
+ * before it is packed, so their text reaches neither the module nor a set of builds.
50
+ */
51
+ constructor(glsl?: boolean);
44
52
  /**
45
53
  * The JavaScript expression of `shader` in a module that `pack` packs, as `ShaderPack.value`
46
54
  * gives it. The value of a shader whose builds load on first use keeps none: it gets a
@@ -58,12 +66,20 @@ export interface BuildSet {
58
66
  /** The builds of each shader of the module that the set serves, by name. */
59
67
  readonly records: readonly Builds[];
60
68
  }
69
+ /**
70
+ * The compiled WGSL of `shader` with every build and piece of the WebGL2 path removed, for a build
71
+ * that ships WebGPU alone: a whole shader keeps no WebGL2 variant, a material keeps no GLSL
72
+ * variants, and an effect or a tone curve keeps no GLSL pieces. The text of the other path then
73
+ * never reaches the module or a set that the build writes.
74
+ */
75
+ export declare function withoutGlsl(shader: CompiledWgsl): CompiledWgsl;
61
76
  /**
62
77
  * The sets that hold `sources`' builds: for a material one for each GPU path and value of its fixed
63
78
  * bits, and for an effect or a tone curve one for each GPU path. Each set holds the builds of every
64
- * shader of its kind that the set serves.
79
+ * shader of its kind that the set serves. With `glsl` false, the sets of the WebGL2 path are left
80
+ * out, for a build that ships WebGPU alone.
65
81
  */
66
- export declare function buildSets(sources: readonly BuildSource[]): BuildSet[];
82
+ export declare function buildSets(sources: readonly BuildSource[], glsl?: boolean): BuildSet[];
67
83
  /** The code of the module that holds one set of builds. */
68
84
  export declare function setModule(records: readonly Builds[]): string;
69
85
  /**
@@ -74,9 +90,12 @@ export declare function setModule(records: readonly Builds[]): string;
74
90
  export declare function loadBuilds(sets: readonly BuildSet[], address: (name: string) => string): string;
75
91
  /** The sets of builds that the plugin wrote, by the name of each set's virtual module. */
76
92
  export declare class MaterialBuilds {
93
+ private readonly glsl;
77
94
  private readonly sets;
78
95
  /** The names of the sets of each module, so a module's new compile drops its old sets. */
79
96
  private readonly owners;
97
+ /** `glsl` says whether the WebGL2 sets are made; a build that ships WebGPU alone says false. */
98
+ constructor(glsl?: () => boolean);
80
99
  /**
81
100
  * The code that ends module `file`, whose shaders `builds` holds: the function that imports
82
101
  * each set, or nothing for a module without such shaders. The sets of the module's previous
@@ -30,6 +30,10 @@ export const DRAW_INDEX = 1;
30
30
  export const TONE_MAP = 2;
31
31
  /** The permutation bit of builds that skin in the vertex shader. */
32
32
  export const SKIN = 64;
33
+ /** The permutation bit of builds that do their color math at half precision. */
34
+ export const HALF = 8192;
35
+ /** The GPU paths, in the order that a build takes them. */
36
+ const TARGETS = ['wgsl', 'glsl'];
33
37
  /** The permutation bits that a device of each GPU path fixes, which split its builds into sets. */
34
38
  const FIXED = { wgsl: TONE_MAP, glsl: TONE_MAP | DRAW_INDEX };
35
39
  /** Each value of the bits of `mask`, from 0 up. */
@@ -97,28 +101,37 @@ function isBuildKind(kind) {
97
101
  }
98
102
  /** The shaders of one module whose builds go to sets, in the order that the module holds them. */
99
103
  export class ModuleBuilds {
104
+ glsl;
100
105
  sources = [];
101
106
  /** How many shaders of each kind the module gave, which numbers their records in a set. */
102
107
  counts = new Map();
108
+ /**
109
+ * `glsl` false keeps the WebGPU path alone: each shader loses its WebGL2 builds and pieces
110
+ * before it is packed, so their text reaches neither the module nor a set of builds.
111
+ */
112
+ constructor(glsl = true) {
113
+ this.glsl = glsl;
114
+ }
103
115
  /**
104
116
  * The JavaScript expression of `shader` in a module that `pack` packs, as `ShaderPack.value`
105
117
  * gives it. The value of a shader whose builds load on first use keeps none: it gets a
106
118
  * function that imports a set.
107
119
  */
108
120
  value(pack, shader, hot) {
109
- const kind = shader.kind;
121
+ const kept = this.glsl ? shader : withoutGlsl(shader);
122
+ const kind = kept.kind;
110
123
  const variants = isBuildKind(kind)
111
- ? shader.variants
124
+ ? kept.variants
112
125
  : undefined;
113
126
  if (variants === undefined || Object.keys(variants).length === 0)
114
- return pack.value(shader, hot);
127
+ return pack.value(kept, hot);
115
128
  const index = this.counts.get(kind) ?? 0;
116
129
  this.counts.set(kind, index + 1);
117
130
  this.sources.push({ kind: kind, variants });
118
131
  // An effect's pieces reach the thread that draws. An effect that reads the pixels beside its
119
132
  // own joins a host as the first member of a group or of the fold. The shader build gives no
120
133
  // pieces to an effect that declares textures or reads bloom's chain, which draws its own pass.
121
- return pack.value({ ...shader, variants: {}, permutations: permutationsOf(variants) }, hot, index, kind);
134
+ return pack.value({ ...kept, variants: {}, permutations: permutationsOf(variants) }, hot, index, kind);
122
135
  }
123
136
  }
124
137
  /** The builds of `variants` that the GPU path `target` draws, and no output for the other path. */
@@ -135,6 +148,42 @@ function onlyTarget(variants, target) {
135
148
  }
136
149
  return kept;
137
150
  }
151
+ /** The builds of `variants` for the WebGPU path alone: those with no WebGPU output go. */
152
+ function webgpuOnly(variants) {
153
+ return onlyTarget(variants, 'wgsl');
154
+ }
155
+ /** The pieces of `pieces` without their WebGL2 additions. */
156
+ function withoutGlslPieces(pieces) {
157
+ const strip = (group) => Object.fromEntries(Object.entries(group).map(([name, piece]) => [name, { ...piece, glsl: null }]));
158
+ return { group: strip(pieces.group), fold: strip(pieces.fold) };
159
+ }
160
+ /**
161
+ * The compiled WGSL of `shader` with every build and piece of the WebGL2 path removed, for a build
162
+ * that ships WebGPU alone: a whole shader keeps no WebGL2 variant, a material keeps no GLSL
163
+ * variants, and an effect or a tone curve keeps no GLSL pieces. The text of the other path then
164
+ * never reaches the module or a set that the build writes.
165
+ */
166
+ export function withoutGlsl(shader) {
167
+ switch (shader.kind) {
168
+ case 'shader':
169
+ return { ...shader, webgl2: null };
170
+ case 'material':
171
+ return { ...shader, variants: webgpuOnly(shader.variants) };
172
+ case 'effect':
173
+ case 'toneCurve':
174
+ return {
175
+ ...shader,
176
+ variants: webgpuOnly(shader.variants),
177
+ pieces: withoutGlslPieces(shader.pieces),
178
+ };
179
+ case 'skyLayer':
180
+ return {
181
+ ...shader,
182
+ variants: webgpuOnly(shader.variants),
183
+ map: webgpuOnly(shader.map),
184
+ };
185
+ }
186
+ }
138
187
  /** The builds of the shaders of `kind` in `sources`, in the module's order. */
139
188
  function variantsOf(sources, kind) {
140
189
  return sources.filter((source) => source.kind === kind).map((source) => source.variants);
@@ -148,11 +197,12 @@ function setOf(bits, key, records) {
148
197
  /**
149
198
  * The sets that hold `sources`' builds: for a material one for each GPU path and value of its fixed
150
199
  * bits, and for an effect or a tone curve one for each GPU path. Each set holds the builds of every
151
- * shader of its kind that the set serves.
200
+ * shader of its kind that the set serves. With `glsl` false, the sets of the WebGL2 path are left
201
+ * out, for a build that ships WebGPU alone.
152
202
  */
153
- export function buildSets(sources) {
203
+ export function buildSets(sources, glsl = true) {
154
204
  const sets = [];
155
- for (const target of ['wgsl', 'glsl']) {
205
+ for (const target of glsl ? TARGETS : ['wgsl']) {
156
206
  const materials = variantsOf(sources, 'material');
157
207
  if (materials.length > 0)
158
208
  for (const set of setsOf(target)) {
@@ -198,16 +248,21 @@ function ${LOAD_BUILDS}(kind, target, set) {
198
248
  }
199
249
  /** The sets of builds that the plugin wrote, by the name of each set's virtual module. */
200
250
  export class MaterialBuilds {
251
+ glsl;
201
252
  sets = new Map();
202
253
  /** The names of the sets of each module, so a module's new compile drops its old sets. */
203
254
  owners = new Map();
255
+ /** `glsl` says whether the WebGL2 sets are made; a build that ships WebGPU alone says false. */
256
+ constructor(glsl = () => true) {
257
+ this.glsl = glsl;
258
+ }
204
259
  /**
205
260
  * The code that ends module `file`, whose shaders `builds` holds: the function that imports
206
261
  * each set, or nothing for a module without such shaders. The sets of the module's previous
207
262
  * compile go, unless another module has the same.
208
263
  */
209
264
  finish(file, builds) {
210
- const sets = buildSets(builds.sources);
265
+ const sets = buildSets(builds.sources, this.glsl());
211
266
  const names = new Set(sets.map((set) => set.name));
212
267
  for (const set of sets)
213
268
  this.sets.set(set.name, [...set.records]);
package/lib/pack.d.ts CHANGED
@@ -1,5 +1,15 @@
1
- /** The function that the plugin adds to a module, which rebuilds the module's compiled shaders. */
1
+ /**
2
+ * The function that the plugin adds to a module, which rebuilds the module's compiled shaders.
3
+ */
2
4
  export declare const UNPACK = "__null3dShader";
5
+ /**
6
+ * The text of a packed shader module with its WebGL2 builds removed, for a build that ships WebGPU
7
+ * alone: each record keeps no WebGL2 output, the module keeps no table of GLSL text, and the loader
8
+ * of build sets loses the entries of the GLSL sets, so their modules are never imported or emitted.
9
+ * Throws when the text is not in the form that `ShaderPack` writes, so a build never ships a module
10
+ * that it misread.
11
+ */
12
+ export declare function narrowShaderPack(text: string, file: string): string;
3
13
  /**
4
14
  * The function of a module whose custom materials' builds load on first use, which imports the
5
15
  * builds of a GPU path and a set by its permutation bits, as `material-builds.ts` writes it.
package/lib/pack.js CHANGED
@@ -13,8 +13,77 @@
13
13
  // reads faster than an object literal of the same size, and which the transforms after the plugin
14
14
  // leave on one line. The function makes no code from strings, so a strict Content Security Policy
15
15
  // allows it.
16
- /** The function that the plugin adds to a module, which rebuilds the module's compiled shaders. */
16
+ /**
17
+ * The function that the plugin adds to a module, which rebuilds the module's compiled shaders.
18
+ */
17
19
  export const UNPACK = '__null3dShader';
20
+ /**
21
+ * The two tables of an unpacked module in its text: the WGSL table and the GLSL table, each the
22
+ * JavaScript string literal that `JSON.stringify(JSON.stringify(...))` writes.
23
+ */
24
+ const PATHS_TABLES = /__null3dShader\.paths = \[\s*("(?:[^"\\]|\\.)*")\s*,\s*("(?:[^"\\]|\\.)*")\s*\]/;
25
+ /** The call that a module makes to unpack each compiled shader, and its first argument. */
26
+ const PACK_CALL = /__null3dShader\(\s*("(?:[^"\\]|\\.)*")/g;
27
+ /** The entries of a build-set loader that hold the sets of one GPU path, one on each line. */
28
+ const SET_ENTRY = /[ \t]*"(?:material|effect|toneCurve) glsl \d+": \(\) => import\("[^"]*"\),\r?\n/g;
29
+ /** The JSON text of a table that holds no text, in the form that the module's tables take. */
30
+ const EMPTY_TABLE = JSON.stringify(JSON.stringify({ blocks: [], lists: [] }));
31
+ /** Why a packed shader module cannot be narrowed: its text is not the form that the pack writes. */
32
+ function unreadablePack(file) {
33
+ return new Error(`null3D cannot drop the WebGL2 builds of ${file}: the module is not in the form that the null3D plugin packs a compiled shader in. Install the same version of @null3d/vite-plugin as the package that wrote it.`);
34
+ }
35
+ /**
36
+ * Sets every `glsl` and `webgl2` field of a packed record to null, at any depth, so that no getter
37
+ * ever asks for a source of a table that no longer holds any. A material's variants, an effect's
38
+ * pieces and a whole shader's records all name their WebGL2 output that way.
39
+ */
40
+ function dropWebgl2(value) {
41
+ if (Array.isArray(value)) {
42
+ for (const item of value)
43
+ dropWebgl2(item);
44
+ return;
45
+ }
46
+ if (value === null || typeof value !== 'object')
47
+ return;
48
+ const record = value;
49
+ for (const key of Object.keys(record)) {
50
+ if (key === 'glsl' || key === 'webgl2')
51
+ record[key] = null;
52
+ else
53
+ dropWebgl2(record[key]);
54
+ }
55
+ }
56
+ /**
57
+ * The text of a packed shader module with its WebGL2 builds removed, for a build that ships WebGPU
58
+ * alone: each record keeps no WebGL2 output, the module keeps no table of GLSL text, and the loader
59
+ * of build sets loses the entries of the GLSL sets, so their modules are never imported or emitted.
60
+ * Throws when the text is not in the form that `ShaderPack` writes, so a build never ships a module
61
+ * that it misread.
62
+ */
63
+ export function narrowShaderPack(text, file) {
64
+ const tables = PATHS_TABLES.exec(text);
65
+ if (tables === null)
66
+ throw unreadablePack(file);
67
+ let narrowed = text.replace(PATHS_TABLES, (_match, wgsl, _glsl) => `__null3dShader.paths = [${wgsl}, ${EMPTY_TABLE}]`);
68
+ let calls = 0;
69
+ narrowed = narrowed.replace(PACK_CALL, (match, literal) => {
70
+ let packed;
71
+ let records;
72
+ try {
73
+ packed = JSON.parse(literal);
74
+ records = JSON.parse(packed);
75
+ }
76
+ catch {
77
+ throw unreadablePack(file);
78
+ }
79
+ dropWebgl2(records);
80
+ calls++;
81
+ return match.replace(literal, () => JSON.stringify(JSON.stringify(records)));
82
+ });
83
+ if (calls === 0)
84
+ throw unreadablePack(file);
85
+ return narrowed.replace(SET_ENTRY, '');
86
+ }
18
87
  /**
19
88
  * The function of a module whose custom materials' builds load on first use, which imports the
20
89
  * builds of a GPU path and a set by its permutation bits, as `material-builds.ts` writes it.
@@ -1,9 +1,15 @@
1
1
  import type { Plugin, Rollup } from 'vite';
2
+ /** One import of a table of shared paragraphs: the table's file name without `.js`, and its names. */
3
+ export interface TableImport {
4
+ readonly stem: string;
5
+ readonly names: readonly string[];
6
+ }
2
7
  /**
3
- * The tables that a device module on disk imports. The file is read from its start only, so a
4
- * build covers the whole generated set without holding any of it in memory.
8
+ * The tables that a device module on disk imports, with the names it takes from each. The file is
9
+ * read from its start only, so a build covers the whole generated set without holding any of it
10
+ * in memory.
5
11
  */
6
- export declare function tableStemsOfFile(file: string): string[];
12
+ export declare function tableImportsOfFile(file: string): TableImport[];
7
13
  /**
8
14
  * Emits each shared table of shader paragraphs beside the copied device modules that import it,
9
15
  * and gives the files of the tables of each of those modules. A build's bundle is the same after a
package/lib/paragraphs.js CHANGED
@@ -10,8 +10,11 @@
10
10
  // whatever the project's assets folder and asset naming pattern are.
11
11
  import { closeSync, existsSync, openSync, readFileSync, readSync, statSync } from 'node:fs';
12
12
  import { dirname, isAbsolute, join, posix, resolve } from 'node:path';
13
- /** An import of a table of shared paragraphs, at the top of a device module of its kind. */
14
- const PARAGRAPH_IMPORT = /from '\.\/(shader-paragraphs-[a-z0-9-]+)\.js';/g;
13
+ /**
14
+ * An import of a table of shared paragraphs, at the top of a device module of its kind, with the
15
+ * names it takes from the table.
16
+ */
17
+ const PARAGRAPH_IMPORT = /import\s*\{([^}]*)\}\s*from '\.\/(shader-paragraphs-[a-z0-9-]+)\.js';/g;
15
18
  /**
16
19
  * How much of a copied file this reads at first. The shader build writes the imports among the
17
20
  * first lines, and a device module is hundreds of kilobytes, so the rest is never read. A device
@@ -26,11 +29,11 @@ function headOf(source, bytes) {
26
29
  return new TextDecoder().decode(source.subarray(0, bytes));
27
30
  }
28
31
  /**
29
- * The names of the paragraph tables that a device module imports. A module imports its
30
- * kind's table and one for each feature family whose paragraphs it holds, so the module of a
31
- * relief feature imports several. The imports end at the first blank line after them.
32
+ * The paragraph tables that a device module imports, with the names it takes from each. A module
33
+ * imports its kind's table and one for each feature family whose paragraphs it holds, so the module
34
+ * of a relief feature imports several. The imports end at the first blank line after them.
32
35
  */
33
- function tableStems(read, length) {
36
+ function tableImports(read, length) {
34
37
  let window = Math.min(IMPORT_WINDOW, length);
35
38
  for (;;) {
36
39
  const head = read(window);
@@ -41,15 +44,26 @@ function tableStems(read, length) {
41
44
  return [];
42
45
  const complete = window >= length || head.indexOf('\n\n', first) >= 0;
43
46
  if (complete)
44
- return [...head.matchAll(PARAGRAPH_IMPORT)].map((match) => match[1]);
47
+ return [...head.matchAll(PARAGRAPH_IMPORT)].map((match) => ({
48
+ stem: match[2],
49
+ names: match[1]
50
+ .split(',')
51
+ .map((name) => name.trim())
52
+ .filter((name) => name !== ''),
53
+ }));
45
54
  window = Math.min(window * 2, length);
46
55
  }
47
56
  }
57
+ /** The names of the paragraph tables that a device module imports. */
58
+ function tableStems(read, length) {
59
+ return tableImports(read, length).map((entry) => entry.stem);
60
+ }
48
61
  /**
49
- * The tables that a device module on disk imports. The file is read from its start only, so a
50
- * build covers the whole generated set without holding any of it in memory.
62
+ * The tables that a device module on disk imports, with the names it takes from each. The file is
63
+ * read from its start only, so a build covers the whole generated set without holding any of it
64
+ * in memory.
51
65
  */
52
- export function tableStemsOfFile(file) {
66
+ export function tableImportsOfFile(file) {
53
67
  const fd = openSync(file, 'r');
54
68
  try {
55
69
  const length = statSync(file).size;
@@ -58,7 +72,7 @@ export function tableStemsOfFile(file) {
58
72
  const count = readSync(fd, buffer, 0, buffer.length, 0);
59
73
  return buffer.subarray(0, count).toString('utf8');
60
74
  };
61
- return tableStems(read, length);
75
+ return tableImports(read, length);
62
76
  }
63
77
  finally {
64
78
  closeSync(fd);
@@ -0,0 +1,166 @@
1
+ /**
2
+ * The permutation bits that a device fixes when it starts. A listed word leaves them out, so one
3
+ * list serves every device module, and a build matches a word with those bits cleared.
4
+ */
5
+ export declare const DEVICE_BITS: number;
6
+ /**
7
+ * A GPU path that a build can ship: WGSL builds for WebGPU, or GLSL ES 3.00 builds for WebGL2.
8
+ * WebGPU's compatibility mode draws with the WebGPU builds, so it counts as `webgpu`.
9
+ */
10
+ export type GpuPath = 'webgpu' | 'webgl2';
11
+ /** The shader language of a GPU path: WGSL for WebGPU, GLSL for WebGL2. */
12
+ export type ShaderTarget = 'wgsl' | 'glsl';
13
+ /** The shader target of a GPU path. */
14
+ export declare function targetOfPath(path: GpuPath): ShaderTarget;
15
+ /**
16
+ * The shader target of a generated shader module, from its name, or null for the modules that both
17
+ * paths share, such as the main module and the marker module. A name that no longer names a target
18
+ * cannot slip through: the build only drops a module whose target it read here.
19
+ */
20
+ export declare function targetOfModule(name: string): ShaderTarget | null;
21
+ /** The shader targets that a project's build keeps. */
22
+ export interface ShippedTargets {
23
+ readonly wgsl: boolean;
24
+ readonly glsl: boolean;
25
+ }
26
+ /**
27
+ * The shader targets that the plugin's options ship. Both unless `gpuPaths` names one. Throws for
28
+ * a list that names no GPU path, an unknown path, or one without WebGPU: the shader compiler builds
29
+ * every shader for WebGPU, and a build that leaves it out would have no form for the shaders that a
30
+ * project's own modules and its add-ons declare.
31
+ */
32
+ export declare function shippedTargets(options: ShaderOptions | undefined): ShippedTargets;
33
+ /** The shader options of the plugin. */
34
+ export interface ShaderOptions {
35
+ /**
36
+ * The file that lists the permutation words that the project's pages draw with, one
37
+ * hexadecimal word on each line, as `bunx @null3d/cli shaders record` writes it. The path is
38
+ * relative to Vite's root. A production build then copies only the shader builds of those words,
39
+ * for every value of the bits a device fixes, and fails when the engine's shader set lacks a
40
+ * listed word. Without it, a build copies the whole set. The dev server draws with the whole
41
+ * set, and warns in the terminal and the browser's console about each word that a page draws
42
+ * with and the list lacks.
43
+ */
44
+ list?: string;
45
+ /**
46
+ * The GPU paths whose shaders the build ships, such as `['webgpu']` for an app whose browser
47
+ * frame always offers WebGPU, as an Electron desktop app's does. A build then drops the other
48
+ * path's shader files and fails with E1308 on a device that would need them. The default is
49
+ * both paths. `webgpu` is required, because the shader compiler builds every shader for it. The
50
+ * dev server keeps both paths. Docs: guides/assets-pipeline.md#ship-a-subset-of-the-gpu-paths.
51
+ */
52
+ gpuPaths?: readonly GpuPath[];
53
+ }
54
+ /**
55
+ * The words of a list file's text: one word on each line, as hexadecimal with `0x` or as a decimal
56
+ * number, with `#` starting a comment, the rule that the engine's shader build reads. Throws with
57
+ * the line of a word it cannot read, and for a list without a word.
58
+ */
59
+ export declare function parseShaderList(text: string, file: string): number[];
60
+ /** A project's list of permutation words. */
61
+ export declare class ShaderList {
62
+ /** The list's file, as the build names it in its messages. */
63
+ readonly file: string;
64
+ /** The listed words, without the bits that a device fixes. */
65
+ readonly words: ReadonlySet<number>;
66
+ constructor(
67
+ /** The list's file, as the build names it in its messages. */
68
+ file: string, words: Iterable<number>);
69
+ /**
70
+ * Reads the list at `path`, which messages name as `name`. Throws for a list without the word
71
+ * that has no bit set, which every page's start draws its own passes with.
72
+ */
73
+ static read(path: string, name?: string): ShaderList;
74
+ /**
75
+ * True when the list names the build whose permutation word is `permutation`: the word itself,
76
+ * or the word with the bits that a device fixes cleared.
77
+ */
78
+ holds(permutation: number): boolean;
79
+ /** The listed words that none of `held`, the words that a set's builds answer, holds. */
80
+ missing(held: ReadonlySet<number>): number[];
81
+ }
82
+ /** The dev server's warning about a word that a page draws with and the project's list lacks. */
83
+ export interface UnlistedWord {
84
+ readonly message: string;
85
+ /** True for the first warning about the word since the list last changed. */
86
+ readonly first: boolean;
87
+ }
88
+ /**
89
+ * The dev server's check of the words that its pages draw with against the project's list. The
90
+ * dev server draws with the whole shader set, so a page there draws a word that the list lacks,
91
+ * while a production build with the list stops that page. The check names such a word when a page
92
+ * first draws with it. It reads the list again whenever the file changes, so a recording made
93
+ * while the server runs counts at once.
94
+ */
95
+ export declare class UnlistedWords {
96
+ private readonly path;
97
+ /** The list's file, as the warnings name it. */
98
+ private readonly name;
99
+ /** The list file's change time when it was last read, or undefined before the first read. */
100
+ private stamp;
101
+ private list;
102
+ /** Why the list cannot be read, when it cannot. */
103
+ private problem;
104
+ /** The words that the check has warned about since the list last changed. */
105
+ private readonly warned;
106
+ /** True once the check has reported the list's problem since the list last changed. */
107
+ private problemShown;
108
+ constructor(path: string,
109
+ /** The list's file, as the warnings name it. */
110
+ name: string);
111
+ /**
112
+ * The warning about `word`, which the page at `page` draws with, without the bits that a device
113
+ * fixes. Undefined when the list holds the word.
114
+ */
115
+ check(word: number, page: string): UnlistedWord | undefined;
116
+ /** Reads the list again when its file changed since the last read. */
117
+ private refresh;
118
+ }
119
+ /** Adds to `held` each word that a build with the permutation word `permutation` answers. */
120
+ export declare function holdWord(held: Set<number>, permutation: number): void;
121
+ /** A word as the list writes it: eight hexadecimal digits after `0x`. */
122
+ export declare function wordText(word: number): string;
123
+ /**
124
+ * A line of a generated shader module that holds a build's permutation word. The hash workers
125
+ * read the same lines in `hash-worker.js`, which cannot import this module.
126
+ */
127
+ export declare const PERMUTATION_LINE: RegExp;
128
+ /** The permutation word of each build that a generated module's text holds. */
129
+ export declare function moduleWords(text: string): number[];
130
+ /**
131
+ * The permutation words that a built file's text names: those of the builds that it bundles, such
132
+ * as the main shader module's own, a custom material's and an add-on's. A key of that name in other
133
+ * code adds a word too, so the words that a check reads from here can only be more, never fewer.
134
+ */
135
+ export declare function builtWords(text: string): number[];
136
+ /**
137
+ * The module that stands for a device file whose builds the list leaves out. It holds no build,
138
+ * so a page that asks for one of those words loads it, finds no build, and the engine names the
139
+ * word.
140
+ */
141
+ export declare const UNLISTED_MODULE = "// The builds of a device module that the project's shader list leaves out.\nexport const SHADERS = {};\n";
142
+ /**
143
+ * The generated marker module's text for a build: the listed words, or null for a build that copies
144
+ * the whole set, and the shipped GPU paths, or null for a build that ships both. The module that
145
+ * the shader build writes declares both names, so the engine reads one shape either way.
146
+ */
147
+ export declare function shaderMarkersModule(words: ReadonlySet<number> | null, paths: readonly GpuPath[] | null): string;
148
+ /**
149
+ * The text of the generated device module `text` with only the builds whose permutation word
150
+ * `keep` takes, and the counts of the builds it kept and held. A shader keeps its entry with no
151
+ * build. Each shared paragraph and imported name that no kept build reads goes too, and so does an
152
+ * import of a table of paragraphs that no kept build reads. Throws when the module is not in the
153
+ * form that the shader build writes, so a build never ships a module it misread.
154
+ */
155
+ export declare function narrowShaderModule(text: string, keep: (permutation: number) => boolean, file?: string): {
156
+ text: string;
157
+ kept: number;
158
+ builds: number;
159
+ };
160
+ /**
161
+ * The text of a table of shared paragraphs with only the paragraphs that `names` lists, the names
162
+ * that the build's copies import from it. A paragraph of a table reads no other value, so each
163
+ * one stays or goes on its own. Throws when the table is not in the form that the shader build
164
+ * writes.
165
+ */
166
+ export declare function narrowParagraphTable(text: string, names: ReadonlySet<string>, file?: string): string;