@null3d/vite-plugin 0.0.0-stage → 0.0.0

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 (50) hide show
  1. package/LICENSE-APACHE +176 -0
  2. package/LICENSE-MIT +21 -0
  3. package/THIRD-PARTY-NOTICES.txt +398 -0
  4. package/dist/shader-compiler.stamp.json +4 -0
  5. package/dist/shader-compiler.wasm +0 -0
  6. package/lib/assets.d.ts +94 -0
  7. package/lib/assets.js +189 -0
  8. package/lib/client.d.ts +21 -0
  9. package/lib/compile-pool.d.ts +25 -0
  10. package/lib/compile-pool.js +90 -0
  11. package/lib/compile-worker.js +11 -0
  12. package/lib/compiler-calls.d.ts +26 -0
  13. package/lib/compiler-calls.js +97 -0
  14. package/lib/compiler-stamp.d.ts +8 -0
  15. package/lib/compiler-stamp.js +34 -0
  16. package/lib/declarations.d.ts +10 -0
  17. package/lib/declarations.js +80 -0
  18. package/lib/engine-shaders-local.d.ts +6 -0
  19. package/lib/engine-shaders-local.js +75 -0
  20. package/lib/engine-shaders.d.ts +61 -0
  21. package/lib/engine-shaders.js +170 -0
  22. package/lib/hash-pool.d.ts +24 -0
  23. package/lib/hash-pool.js +84 -0
  24. package/lib/hash-worker.js +53 -0
  25. package/lib/hot.d.ts +53 -0
  26. package/lib/hot.js +101 -0
  27. package/lib/index.d.ts +95 -0
  28. package/lib/index.js +895 -0
  29. package/lib/material-builds.d.ts +91 -0
  30. package/lib/material-builds.js +236 -0
  31. package/lib/offline.d.ts +92 -0
  32. package/lib/offline.js +304 -0
  33. package/lib/pack.d.ts +30 -0
  34. package/lib/pack.js +112 -0
  35. package/lib/package-files.d.ts +12 -0
  36. package/lib/package-files.js +39 -0
  37. package/lib/paragraphs.d.ts +19 -0
  38. package/lib/paragraphs.js +131 -0
  39. package/lib/shader-cache.d.ts +59 -0
  40. package/lib/shader-cache.js +213 -0
  41. package/lib/shader-compiler.d.ts +258 -0
  42. package/lib/shader-compiler.js +169 -0
  43. package/lib/shader-types.d.ts +261 -0
  44. package/lib/shader-types.js +4 -0
  45. package/lib/wgsl.d.ts +118 -0
  46. package/lib/wgsl.js +446 -0
  47. package/lib/worker-preload.d.ts +17 -0
  48. package/lib/worker-preload.js +65 -0
  49. package/package.json +69 -5
  50. package/README.md +0 -3
@@ -0,0 +1,59 @@
1
+ import { type CompileResult, type EffectResult, type MaterialResult, type MaterialSource, type ShaderCompiler, type ShaderSource, type SkyLayerResult } from './shader-compiler.js';
2
+ /** The cache's folder in a project, beside the asset tool's cache. */
3
+ export declare const SHADER_CACHE_FOLDER = "null3d-shaders";
4
+ /** The canonical opt-out, the same name that turns off the repository's own build caches. */
5
+ export declare const NO_CACHE = "NULL3D_NO_CACHE";
6
+ /** A second name that turns the cache off, as `NO_CACHE` does. */
7
+ export declare const NO_SHADER_CACHE = "NULL3D_NO_SHADER_CACHE";
8
+ /** The folder of the compiled shaders' cache in a project. */
9
+ export declare function shaderCacheFolder(root: string): string;
10
+ /** True when the environment asks the build to ignore the cache. */
11
+ export declare function shaderCacheOff(): boolean;
12
+ /**
13
+ * The version that keys the cache: the engine's, with the shader build's own stamp. Both change
14
+ * when the engine or the inputs of a project's compile change, so neither serves an old shader
15
+ * after an upgrade or a change that could affect it.
16
+ */
17
+ export declare function shaderCompilerVersion(root: string): string;
18
+ /** The options of a cache. */
19
+ export interface ShaderCacheOptions {
20
+ /** The version stamp; the default is `shaderCompilerVersion(root)`. */
21
+ version?: string;
22
+ /** True to compile every request, ignoring the cache. */
23
+ disabled?: () => boolean;
24
+ }
25
+ /**
26
+ * Compiles through another compiler, and keeps each result in a project's cache. A request whose
27
+ * key the cache holds gives the stored result and never touches the inner compiler, so no compiler
28
+ * worker starts. Two requests with one key compile once, however they arrive. Its fields are
29
+ * declared here rather than in the constructor's parameters: the command-line tool imports this
30
+ * package's source while Node runs it, and Node strips types from that source without transforming
31
+ * a parameter property.
32
+ */
33
+ export declare class ShaderCache implements ShaderCompiler {
34
+ /** Requests that are compiling now, by key, so a second one waits for the first. */
35
+ private readonly running;
36
+ /** The project's folder, as a getter, so a build that moves it reads the new one. */
37
+ private readonly root;
38
+ private readonly inner;
39
+ private readonly options;
40
+ private stamp;
41
+ /** True once this build has said that it compiles shaders, so it says it once. */
42
+ private announced;
43
+ constructor(root: () => string, inner: ShaderCompiler, options?: ShaderCacheOptions);
44
+ shader(shader: ShaderSource): Promise<CompileResult>;
45
+ material(material: MaterialSource): Promise<MaterialResult>;
46
+ effect(effect: MaterialSource): Promise<EffectResult>;
47
+ skyLayer(layer: MaterialSource): Promise<SkyLayerResult>;
48
+ /**
49
+ * The key of a request: the cache format, the compiler's version, the kind of compile and the
50
+ * request itself, hashed as the repository's build caches hash their inputs.
51
+ */
52
+ private key;
53
+ /**
54
+ * Says once per build that the shaders are compiled, so the pause before the first result does
55
+ * not look like a hang, and names the cache that later builds read instead.
56
+ */
57
+ private announceCompile;
58
+ private run;
59
+ }
@@ -0,0 +1,213 @@
1
+ // A persistent cache of compiled shaders, so a project builds its shaders once. A shader compile
2
+ // takes the CPU for most of a second, and without the cache every `vite build` and `vite dev`
3
+ // compiles the same WGSL again from nothing. The plugin keeps each result in
4
+ // `node_modules/.cache/null3d-shaders`, as the asset tool keeps its own results in
5
+ // `node_modules/.cache/null3d-assets`. A cache entry is keyed by everything that decides the
6
+ // output: the WGSL, the path it came from, the variant spec that the compiler is given, and the
7
+ // compiler's version. The version is the engine's version with the shader build's own stamp, so
8
+ // an engine or compiler upgrade misses every entry. A changed source, spec or compiler therefore
9
+ // misses, and the plugin never serves a wrong shader. Set `NULL3D_NO_CACHE=1`, or run Vite with
10
+ // `--force`, to ignore the cache.
11
+ //
12
+ // A game project's cache is not one of the repository's own build caches: it lives in the project,
13
+ // not under `~/.cache/null3d`, and a project that installs this package cannot load repository
14
+ // tooling. So this module repeats the three rules that one module keeps for the repository's caches
15
+ // in `tools/lib/build-cache.ts` (D-177): a write is atomic, any change to an input misses, and there
16
+ // is one documented opt-out. The `hashOf` and `writeFileAtomic` helpers below mirror that module's,
17
+ // and the opt-out names match its list. It takes no build lock: each entry is one atomic file, and
18
+ // the compiler pool runs several compiles at once, so a lock would only serialize them. Its rules
19
+ // for game developers are in docs/getting-started/install.md.
20
+ import { createHash } from 'node:crypto';
21
+ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
22
+ import { createRequire } from 'node:module';
23
+ import { dirname, join } from 'node:path';
24
+ import { COMPILER_STAMP_FILE, readCompilerStamp } from "./compiler-stamp.js";
25
+ import { SHADER_COMPILER_URL, } from "./shader-compiler.js";
26
+ /** The cache's folder in a project, beside the asset tool's cache. */
27
+ export const SHADER_CACHE_FOLDER = 'null3d-shaders';
28
+ /** The canonical opt-out, the same name that turns off the repository's own build caches. */
29
+ export const NO_CACHE = 'NULL3D_NO_CACHE';
30
+ /** A second name that turns the cache off, as `NO_CACHE` does. */
31
+ export const NO_SHADER_CACHE = 'NULL3D_NO_SHADER_CACHE';
32
+ /** Every name that turns the cache off, as `tools/lib/build-cache.ts` lists them. */
33
+ const NO_CACHE_NAMES = [NO_CACHE, 'NULL3D_NO_BUILD_CACHE', NO_SHADER_CACHE];
34
+ /**
35
+ * The shape of a cache entry. Bump it when the records of a compiled shader change, so an older
36
+ * entry is never read with new meaning.
37
+ */
38
+ const FORMAT = 1;
39
+ /** The folder of the compiled shaders' cache in a project. */
40
+ export function shaderCacheFolder(root) {
41
+ return join(root, 'node_modules/.cache', SHADER_CACHE_FOLDER);
42
+ }
43
+ /** True when the environment asks the build to ignore the cache. */
44
+ export function shaderCacheOff() {
45
+ return NO_CACHE_NAMES.some((name) => process.env[name] === '1');
46
+ }
47
+ /** A SHA-256 of the given values, in order, as `tools/lib/build-cache.ts`'s `hashOf` does. */
48
+ function hashOf(...inputs) {
49
+ const hash = createHash('sha256');
50
+ for (const input of inputs) {
51
+ hash.update(input);
52
+ hash.update('\0');
53
+ }
54
+ return hash.digest('hex');
55
+ }
56
+ /** The version of the installed engine, or `unknown` when the project does not install it. */
57
+ function engineVersion(root) {
58
+ try {
59
+ const manifest = createRequire(join(root, 'package.json')).resolve('@null3d/engine/package.json');
60
+ const { version } = JSON.parse(readFileSync(manifest, 'utf8'));
61
+ return version ?? 'unknown';
62
+ }
63
+ catch {
64
+ return 'unknown';
65
+ }
66
+ }
67
+ /** The record that the build writes beside the compiler, naming the inputs of a project's compile. */
68
+ const COMPILER_STAMP_URL = new URL(`../dist/${COMPILER_STAMP_FILE}`, import.meta.url);
69
+ /**
70
+ * The shader build's own stamp: the inputs that a project's compile may read, which the build
71
+ * records beside the compiler. A build that wrote no record is named by the compiler's own bytes,
72
+ * which change with every shader source and so compile every entry again.
73
+ */
74
+ let stamp;
75
+ function shaderBuildStamp() {
76
+ if (stamp === undefined) {
77
+ stamp = readCompilerStamp(COMPILER_STAMP_URL);
78
+ if (stamp === undefined) {
79
+ try {
80
+ stamp = hashOf(readFileSync(SHADER_COMPILER_URL));
81
+ }
82
+ catch {
83
+ stamp = 'missing';
84
+ }
85
+ }
86
+ }
87
+ return stamp;
88
+ }
89
+ /**
90
+ * The version that keys the cache: the engine's, with the shader build's own stamp. Both change
91
+ * when the engine or the inputs of a project's compile change, so neither serves an old shader
92
+ * after an upgrade or a change that could affect it.
93
+ */
94
+ export function shaderCompilerVersion(root) {
95
+ return `${engineVersion(root)}:${shaderBuildStamp()}`;
96
+ }
97
+ /** What a cache reads and writes: a compile's result, and its own record of whether it compiled. */
98
+ function isResult(value) {
99
+ return (typeof value === 'object' &&
100
+ value !== null &&
101
+ typeof value.ok === 'boolean');
102
+ }
103
+ /** The cached result of a key, or undefined when the cache holds none the plugin can trust. */
104
+ function readCached(file) {
105
+ if (!existsSync(file))
106
+ return undefined;
107
+ try {
108
+ const value = JSON.parse(readFileSync(file, 'utf8'));
109
+ return isResult(value) ? value : undefined;
110
+ }
111
+ catch {
112
+ // An entry that does not parse is one this build wrote while it stopped, or one from
113
+ // another cache format. Compile again; never fail the build over a cache.
114
+ return undefined;
115
+ }
116
+ }
117
+ /**
118
+ * Writes an entry in one step, as `tools/lib/build-cache.ts`'s `writeFileAtomic` does, so a reader
119
+ * sees the whole old entry or the whole new one. A cache that cannot be written is not a failure:
120
+ * the compile's result still stands.
121
+ */
122
+ function writeCached(file, result) {
123
+ try {
124
+ mkdirSync(dirname(file), { recursive: true });
125
+ const partial = `${file}.${process.pid}.partial`;
126
+ writeFileSync(partial, JSON.stringify(result));
127
+ renameSync(partial, file);
128
+ }
129
+ catch {
130
+ // A read-only folder, a full disk: the build carries on without the cache.
131
+ }
132
+ }
133
+ /**
134
+ * Compiles through another compiler, and keeps each result in a project's cache. A request whose
135
+ * key the cache holds gives the stored result and never touches the inner compiler, so no compiler
136
+ * worker starts. Two requests with one key compile once, however they arrive. Its fields are
137
+ * declared here rather than in the constructor's parameters: the command-line tool imports this
138
+ * package's source while Node runs it, and Node strips types from that source without transforming
139
+ * a parameter property.
140
+ */
141
+ export class ShaderCache {
142
+ /** Requests that are compiling now, by key, so a second one waits for the first. */
143
+ running = new Map();
144
+ /** The project's folder, as a getter, so a build that moves it reads the new one. */
145
+ root;
146
+ inner;
147
+ options;
148
+ stamp;
149
+ /** True once this build has said that it compiles shaders, so it says it once. */
150
+ announced = false;
151
+ constructor(root, inner, options = {}) {
152
+ this.root = root;
153
+ this.inner = inner;
154
+ this.options = options;
155
+ }
156
+ shader(shader) {
157
+ return this.run('shader', shader, () => this.inner.shader(shader));
158
+ }
159
+ material(material) {
160
+ return this.run('material', material, () => this.inner.material(material));
161
+ }
162
+ effect(effect) {
163
+ return this.run('effect', effect, () => this.inner.effect(effect));
164
+ }
165
+ skyLayer(layer) {
166
+ return this.run('skyLayer', layer, () => this.inner.skyLayer(layer));
167
+ }
168
+ /**
169
+ * The key of a request: the cache format, the compiler's version, the kind of compile and the
170
+ * request itself, hashed as the repository's build caches hash their inputs.
171
+ */
172
+ key(kind, request) {
173
+ this.stamp ??= this.options.version ?? shaderCompilerVersion(this.root());
174
+ return hashOf(String(FORMAT), this.stamp, kind, JSON.stringify(request));
175
+ }
176
+ /**
177
+ * Says once per build that the shaders are compiled, so the pause before the first result does
178
+ * not look like a hang, and names the cache that later builds read instead.
179
+ */
180
+ announceCompile(request) {
181
+ if (this.announced)
182
+ return;
183
+ this.announced = true;
184
+ const path = request.path;
185
+ const what = typeof path === 'string' ? path : 'this project';
186
+ console.log(`null3D: compiling the shaders of ${what}. A compile takes up to a second, and the results are kept in ${shaderCacheFolder(this.root())}, so later builds do not compile again.`);
187
+ }
188
+ async run(kind, request, compile) {
189
+ if (this.options.disabled?.())
190
+ return compile();
191
+ const key = this.key(kind, request);
192
+ const file = join(shaderCacheFolder(this.root()), `${key}.json`);
193
+ const cached = readCached(file);
194
+ if (cached !== undefined)
195
+ return cached;
196
+ this.announceCompile(request);
197
+ const pending = this.running.get(key);
198
+ if (pending)
199
+ return pending;
200
+ const work = (async () => {
201
+ const result = await compile();
202
+ writeCached(file, result);
203
+ return result;
204
+ })();
205
+ this.running.set(key, work);
206
+ try {
207
+ return await work;
208
+ }
209
+ finally {
210
+ this.running.delete(key);
211
+ }
212
+ }
213
+ }
@@ -0,0 +1,258 @@
1
+ import type { CompiledTexture, CompiledUniform, EffectPieces, ShaderVariant, WgslPipeline } from './shader-types.js';
2
+ /** Where `bun run build` writes the module. */
3
+ export declare const SHADER_COMPILER_URL: URL;
4
+ /** A language that a shader variant builds for: WGSL for WebGPU, or GLSL ES 3.00 for WebGL2. */
5
+ export type ShaderTarget = 'wgsl' | 'glsl';
6
+ /** One variant of a shader: a build for each combination of its permutation bits. */
7
+ export interface ShaderVariantSpec {
8
+ /** Shader defs that are true in every build of the variant, for `#ifdef NAME` lines. */
9
+ readonly defs?: readonly string[];
10
+ /**
11
+ * Permutation bits by name, such as `TONE_MAP`. The variant builds once for each combination
12
+ * of them, with the names of the bits it has as more shader defs. The build without any bit
13
+ * takes the variant's name, and each other build adds the names of its bits in lowercase.
14
+ */
15
+ readonly permutations?: readonly string[];
16
+ /**
17
+ * The languages to write. A variant whose only target is `glsl` may read
18
+ * `@builtin(draw_index)`: its vertex shader then reads `gl_DrawID` from `WEBGL_multi_draw`.
19
+ */
20
+ readonly targets: readonly ShaderTarget[];
21
+ }
22
+ /** A shader to compile. */
23
+ export interface ShaderSource {
24
+ /** The file that the WGSL comes from, as problems name it. */
25
+ readonly path: string;
26
+ /** The WGSL. It may import the engine's library modules, such as `#import null3d::math`. */
27
+ readonly source: string;
28
+ /**
29
+ * Render pipelines by name. WebGL2 gets one GLSL program for each pipeline, so a variant that
30
+ * targets `glsl` needs at least one.
31
+ */
32
+ readonly pipelines?: Readonly<Record<string, WgslPipeline>>;
33
+ /** Builds of the shader by name. */
34
+ readonly variants: Readonly<Record<string, ShaderVariantSpec>>;
35
+ }
36
+ /** A problem that stopped a compile. */
37
+ export interface ShaderProblem {
38
+ /** The file that the problem is in, or null when it belongs to none. */
39
+ readonly file: string | null;
40
+ /** The 1-based line, or null when the problem has no place in the file. */
41
+ readonly line: number | null;
42
+ /** The 1-based column in that line, counted in characters, or null. */
43
+ readonly column: number | null;
44
+ /** The WGSL language feature that the problem is about, or null. */
45
+ readonly feature: string | null;
46
+ /** What is wrong and how to fix it. */
47
+ readonly message: string;
48
+ /** The variants that have the problem. */
49
+ readonly variants: readonly string[];
50
+ }
51
+ /**
52
+ * The result of a compile: each variant by name, or the problems that stopped it. A compile that
53
+ * succeeds also gives its warnings: calls that a target browser cannot compile.
54
+ */
55
+ export type CompileResult = {
56
+ readonly ok: true;
57
+ readonly variants: Readonly<Record<string, ShaderVariant>>;
58
+ readonly warnings: readonly ShaderProblem[];
59
+ } | {
60
+ readonly ok: false;
61
+ readonly problems: readonly ShaderProblem[];
62
+ };
63
+ /**
64
+ * Compiles every variant of a shader with the engine's shader library. The same problem in
65
+ * several variants comes once, with each variant's name.
66
+ */
67
+ export declare function compileShader(shader: ShaderSource): CompileResult;
68
+ /** A shader compile's result from the module's response. */
69
+ export declare function shaderResult(response: Response<Record<string, ShaderVariant>>): CompileResult;
70
+ /** The WGSL of a custom material: functions that the engine's standard material calls. */
71
+ export interface MaterialSource {
72
+ /** The file that the WGSL comes from, as problems name it. */
73
+ readonly path: string;
74
+ /** The WGSL, which declares `fn surface`, `struct Uniforms`, and anything they use. */
75
+ readonly source: string;
76
+ /**
77
+ * The share of the material's builds to make, for one of `count` threads that build the
78
+ * material together, or every build without it. `joinShares` joins the shares' results.
79
+ */
80
+ readonly share?: {
81
+ readonly index: number;
82
+ readonly count: number;
83
+ };
84
+ }
85
+ /** A custom material, built into every variant of the engine's standard material. */
86
+ export interface MaterialBuild {
87
+ /** The functions that the WGSL declares for the engine to call, such as `surface`. */
88
+ readonly functions: readonly string[];
89
+ /** The fields of the WGSL's `struct Uniforms`, where the engine writes each. */
90
+ readonly uniforms: readonly CompiledUniform[];
91
+ /** The textures that the WGSL declares, where the engine writes the layer of each. */
92
+ readonly textures: readonly CompiledTexture[];
93
+ /** The standard material's variants with the WGSL's functions, or a full shader's, by name. */
94
+ readonly variants: Readonly<Record<string, ShaderVariant>>;
95
+ /** The vertex shader locations that the vertex stage reads from a mesh's vertices. */
96
+ readonly locations: readonly number[];
97
+ /** The optional vertex attributes that those locations read, as the engine's format bits. */
98
+ readonly attributes: number;
99
+ /** True when the shader reads the material's base color and opacity, as the template does. */
100
+ readonly baseColor: boolean;
101
+ /** True when the WGSL reads an instance's index or an object's id. */
102
+ readonly objectIds: boolean;
103
+ /** True when the WGSL reads the copy of the scene's depth through `sceneDepth`. */
104
+ readonly sceneDepth: boolean;
105
+ /** True when the WGSL sets or reads the surface's alpha. */
106
+ readonly alpha: boolean;
107
+ }
108
+ /** The result of a custom material's compile, with its warnings when it succeeds. */
109
+ export type MaterialResult = {
110
+ readonly ok: true;
111
+ readonly material: MaterialBuild;
112
+ readonly warnings: readonly ShaderProblem[];
113
+ } | {
114
+ readonly ok: false;
115
+ readonly problems: readonly ShaderProblem[];
116
+ };
117
+ /**
118
+ * Builds a custom material's WGSL into every variant of the engine's standard material, which
119
+ * then calls its functions. Problems in the WGSL name its own lines.
120
+ */
121
+ export declare function compileMaterial(material: MaterialSource): MaterialResult;
122
+ /** A custom material's result from the module's response. */
123
+ export declare function materialResult(response: Response<MaterialBuild>): MaterialResult;
124
+ /** A custom effect or tone curve, built into the engine's effect template or its final pass. */
125
+ export interface EffectBuild {
126
+ /** The function that the WGSL declares: `effect` or `toneCurve`. */
127
+ readonly function: 'effect' | 'toneCurve';
128
+ /** The fields of the WGSL's `struct Uniforms`, where the engine writes each. */
129
+ readonly uniforms: readonly CompiledUniform[];
130
+ /** True when the effect reads the scene's depth. */
131
+ readonly depth: boolean;
132
+ /** True when the effect reads a level of bloom's chain. */
133
+ readonly bloom: boolean;
134
+ /** True when the effect joins the effect before it. */
135
+ readonly joins: boolean;
136
+ /** The textures that an effect declares, where the engine writes each one's layer. */
137
+ readonly textures: readonly CompiledTexture[];
138
+ /** The template's variants with the WGSL, by name. */
139
+ readonly variants: Readonly<Record<string, ShaderVariant>>;
140
+ /** The pieces that the engine joins into its hosts. */
141
+ readonly pieces: EffectPieces;
142
+ }
143
+ /** The result of a custom effect's or tone curve's compile, with its warnings when it succeeds. */
144
+ export type EffectResult = {
145
+ readonly ok: true;
146
+ readonly effect: EffectBuild;
147
+ readonly warnings: readonly ShaderProblem[];
148
+ } | {
149
+ readonly ok: false;
150
+ readonly problems: readonly ShaderProblem[];
151
+ };
152
+ /** A sky layer, built into every variant of the engine's two sky-layer templates. */
153
+ export interface SkyLayerBuild {
154
+ /** The sky-layer template's variants with the WGSL, by name. */
155
+ readonly variants: Readonly<Record<string, ShaderVariant>>;
156
+ /** The sky-map shader's variants with the WGSL, by name. */
157
+ readonly map: Readonly<Record<string, ShaderVariant>>;
158
+ }
159
+ /** The result of a sky layer's compile, with its warnings when it succeeds. */
160
+ export type SkyLayerResult = {
161
+ readonly ok: true;
162
+ readonly layer: SkyLayerBuild;
163
+ readonly warnings: readonly ShaderProblem[];
164
+ } | {
165
+ readonly ok: false;
166
+ readonly problems: readonly ShaderProblem[];
167
+ };
168
+ /**
169
+ * Builds a custom effect's WGSL into every variant of the engine's effect template, or a custom
170
+ * tone curve's into every variant of its final pass. Problems in the WGSL name its own lines.
171
+ */
172
+ export declare function compileEffect(effect: MaterialSource): EffectResult;
173
+ /** A custom effect's or tone curve's result from the module's response. */
174
+ export declare function effectResult(response: Response<EffectBuild>): EffectResult;
175
+ /**
176
+ * Builds a sky layer's WGSL into every variant of the engine's sky-layer template. Problems in the
177
+ * WGSL name its own lines.
178
+ */
179
+ export declare function compileSkyLayer(layer: MaterialSource): SkyLayerResult;
180
+ /** A sky layer's result from the module's response. */
181
+ export declare function skyLayerResult(response: Response<SkyLayerBuild>): SkyLayerResult;
182
+ /**
183
+ * The result of a custom material from the results of its shares: every build, by name in the
184
+ * order that the compiler gives them, with every warning, or every problem of every share. Each
185
+ * problem and warning comes once, with every build that has it.
186
+ */
187
+ export declare function joinShares(shares: readonly MaterialResult[]): MaterialResult;
188
+ /**
189
+ * Compiles shaders and custom materials: on this thread, which waits for each compile, or on worker
190
+ * threads, while this thread goes on.
191
+ */
192
+ export interface ShaderCompiler {
193
+ shader(shader: ShaderSource): Promise<CompileResult>;
194
+ material(material: MaterialSource): Promise<MaterialResult>;
195
+ effect(effect: MaterialSource): Promise<EffectResult>;
196
+ skyLayer(layer: MaterialSource): Promise<SkyLayerResult>;
197
+ }
198
+ /** Compiles on this thread. */
199
+ export declare const compileHere: ShaderCompiler;
200
+ /** A shader manifest and every WGSL file beside it, as `bun run shaders` reads them. */
201
+ export interface ShaderBuildInputs {
202
+ /** The manifest's text. */
203
+ readonly manifest: string;
204
+ /** Each WGSL file by path in the shader folder. The library modules are the files in `lib/`. */
205
+ readonly files: Readonly<Record<string, string>>;
206
+ }
207
+ /** Every variant of every shader in a manifest. */
208
+ export interface ShaderBuildOutput {
209
+ /** Variants by shader name, then by variant name. */
210
+ readonly shaders: Readonly<Record<string, Readonly<Record<string, ShaderVariant>>>>;
211
+ /** Pipeline names by shader name, sorted. */
212
+ readonly pipelines: Readonly<Record<string, readonly string[]>>;
213
+ }
214
+ /** The result of a manifest build. */
215
+ export type ShaderBuildResult = {
216
+ readonly ok: true;
217
+ readonly output: ShaderBuildOutput;
218
+ } | {
219
+ readonly ok: false;
220
+ readonly problems: readonly ShaderProblem[];
221
+ };
222
+ /**
223
+ * Builds every variant in a shader manifest, as the native `bun run shaders` does. The answer may
224
+ * be large — the engine's own manifest answers with hundreds of megabytes — and the module hands
225
+ * it over in pieces, which `CompilerCalls` joins before this reads it.
226
+ */
227
+ export declare function buildShaders(inputs: ShaderBuildInputs): ShaderBuildResult;
228
+ /**
229
+ * Prepares the engine's own manifest, whose sources the compiler carries, and lists the file names
230
+ * of every module it makes. No text is rendered yet: the modules come one at a time, so a build
231
+ * never holds the whole set beside its sources.
232
+ */
233
+ export declare function prepareEngineModules(): readonly string[];
234
+ /** One module of the prepared engine build: its file name and its text. */
235
+ export declare function engineModule(name: string): {
236
+ readonly path: string;
237
+ readonly text: string;
238
+ };
239
+ /**
240
+ * The module's response to a call: its output, or the problems that stopped the call. The calls
241
+ * that compile users' shaders add their warnings when they have any.
242
+ */
243
+ export type Response<T> = {
244
+ readonly ok: true;
245
+ readonly output: T;
246
+ readonly warnings?: readonly ShaderProblem[];
247
+ } | {
248
+ readonly ok: false;
249
+ readonly problems: readonly ShaderProblem[];
250
+ readonly warnings?: readonly ShaderProblem[];
251
+ };
252
+ /** The name of one of the module's exports that takes a request. */
253
+ export type CallName = 'compile' | 'compile_material' | 'compile_effect' | 'compile_sky_layer' | 'build' | 'prepare_modules' | 'module';
254
+ /**
255
+ * The compiled module, from the file that `bun run build` writes. The first call compiles it, and
256
+ * throws when the file is missing.
257
+ */
258
+ export declare function compilerModule(): WebAssembly.Module;