@null3d/vite-plugin 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/shader-compiler.stamp.json +1 -1
- package/dist/shader-compiler.wasm +0 -0
- package/lib/hot.d.ts +13 -2
- package/lib/hot.js +28 -3
- package/lib/index.d.ts +1 -1
- package/lib/index.js +263 -74
- package/lib/material-builds.d.ts +19 -2
- package/lib/material-builds.js +61 -8
- package/lib/pack.d.ts +11 -1
- package/lib/pack.js +70 -1
- package/lib/paragraphs.d.ts +81 -10
- package/lib/paragraphs.js +289 -46
- package/lib/shader-list.d.ts +41 -2
- package/lib/shader-list.js +56 -10
- package/lib/wgsl.d.ts +10 -9
- package/lib/wgsl.js +31 -28
- package/package.json +3 -3
package/lib/wgsl.js
CHANGED
|
@@ -214,10 +214,12 @@ function pipelinesOf(path, source, hint) {
|
|
|
214
214
|
return { pipelines };
|
|
215
215
|
}
|
|
216
216
|
/** The builds of a shader from a project: one for WebGPU, and one for WebGL2. */
|
|
217
|
-
const
|
|
217
|
+
const ALL_BUILDS = {
|
|
218
218
|
webgpu: { targets: ['wgsl'] },
|
|
219
219
|
webgl2: { defs: ['WEBGL2'], targets: ['glsl'] },
|
|
220
220
|
};
|
|
221
|
+
/** The build that a compile of whole shaders makes when it ships the WebGPU path alone. */
|
|
222
|
+
const WEBGPU_BUILD = { webgpu: ALL_BUILDS.webgpu };
|
|
221
223
|
/**
|
|
222
224
|
* What a compile of a project's WGSL of `source` does. WGSL without entry points that declares a
|
|
223
225
|
* post function is an effect or a tone curve, one that declares `skyLayer` is a sky layer, and one
|
|
@@ -225,7 +227,7 @@ const BUILDS = {
|
|
|
225
227
|
* shader, one that the engine's mesh calls or a draw shader. `hint` ends the message about WGSL
|
|
226
228
|
* that is none of these.
|
|
227
229
|
*/
|
|
228
|
-
function planOf(path, source, hint) {
|
|
230
|
+
function planOf(path, source, hint, glsl) {
|
|
229
231
|
const noEntryPoints = entryPoints(source).length === 0;
|
|
230
232
|
if (noEntryPoints && declaresFunction(source, SKY_LAYER_FUNCTIONS))
|
|
231
233
|
return { kind: 'skyLayer' };
|
|
@@ -240,13 +242,13 @@ function planOf(path, source, hint) {
|
|
|
240
242
|
if ('problem' in shape)
|
|
241
243
|
return { kind: 'problem', problem: shape.problem };
|
|
242
244
|
const render = Object.keys(shape.pipelines).length > 0;
|
|
243
|
-
const variants = render
|
|
245
|
+
const variants = render && glsl ? ALL_BUILDS : WEBGPU_BUILD;
|
|
244
246
|
return { kind: 'shader', pipelines: shape.pipelines, variants, builds: Object.keys(variants) };
|
|
245
247
|
}
|
|
246
248
|
/** An effect's or a tone curve's compile as the result of compiling WGSL from a project. */
|
|
247
|
-
function effectOutcome(result) {
|
|
248
|
-
// Effects and tone curves build for
|
|
249
|
-
const builds = ['webgpu', 'webgl2'];
|
|
249
|
+
function effectOutcome(result, glsl) {
|
|
250
|
+
// Effects and tone curves build for the paths that the compile ships.
|
|
251
|
+
const builds = glsl ? ['webgpu', 'webgl2'] : ['webgpu'];
|
|
250
252
|
if (!result.ok)
|
|
251
253
|
return { ok: false, problems: result.problems, builds };
|
|
252
254
|
const { warnings } = result;
|
|
@@ -261,9 +263,9 @@ function effectOutcome(result) {
|
|
|
261
263
|
};
|
|
262
264
|
}
|
|
263
265
|
/** A sky layer's compile as the result of compiling WGSL from a project. */
|
|
264
|
-
function skyLayerOutcome(result) {
|
|
265
|
-
// A sky layer builds for
|
|
266
|
-
const builds = ['webgpu', 'webgl2'];
|
|
266
|
+
function skyLayerOutcome(result, glsl) {
|
|
267
|
+
// A sky layer builds for the paths that the compile ships.
|
|
268
|
+
const builds = glsl ? ['webgpu', 'webgl2'] : ['webgpu'];
|
|
267
269
|
if (!result.ok)
|
|
268
270
|
return { ok: false, problems: result.problems, builds };
|
|
269
271
|
return {
|
|
@@ -274,9 +276,9 @@ function skyLayerOutcome(result) {
|
|
|
274
276
|
};
|
|
275
277
|
}
|
|
276
278
|
/** A custom material's compile as the result of compiling WGSL from a project. */
|
|
277
|
-
function materialOutcome(result, draw) {
|
|
278
|
-
// Custom materials build for
|
|
279
|
-
const builds = ['webgpu', 'webgl2'];
|
|
279
|
+
function materialOutcome(result, draw, glsl) {
|
|
280
|
+
// Custom materials build for the paths that the compile ships.
|
|
281
|
+
const builds = glsl ? ['webgpu', 'webgl2'] : ['webgpu'];
|
|
280
282
|
if (!result.ok)
|
|
281
283
|
return { ok: false, problems: result.problems, builds };
|
|
282
284
|
const shader = {
|
|
@@ -298,22 +300,23 @@ function shaderOutcome(result, builds) {
|
|
|
298
300
|
}
|
|
299
301
|
/**
|
|
300
302
|
* Compiles WGSL from a project with the engine's shader library. A whole shader builds for WebGPU,
|
|
301
|
-
* and for WebGL2 when it has a render pipeline. A custom material's
|
|
302
|
-
* variant of the engine's standard material, and a custom effect's or
|
|
303
|
-
* template. `path` names the file in messages, and `hint` ends the message
|
|
304
|
-
* none of these. `compiler` runs the compile, on this thread by default.
|
|
303
|
+
* and for WebGL2 when it has a render pipeline and the compile ships that path. A custom material's
|
|
304
|
+
* functions build into every variant of the engine's standard material, and a custom effect's or
|
|
305
|
+
* tone curve's into its template. `path` names the file in messages, and `hint` ends the message
|
|
306
|
+
* about WGSL that is none of these. `compiler` runs the compile, on this thread by default. `glsl`
|
|
307
|
+
* false builds the WebGPU path alone, for a project whose build ships no WebGL2 shaders.
|
|
305
308
|
*/
|
|
306
|
-
export async function compileWgsl(path, source, hint, compiler = compileHere) {
|
|
307
|
-
const plan = planOf(path, source, hint);
|
|
309
|
+
export async function compileWgsl(path, source, hint, compiler = compileHere, glsl = true) {
|
|
310
|
+
const plan = planOf(path, source, hint, glsl);
|
|
308
311
|
switch (plan.kind) {
|
|
309
312
|
case 'problem':
|
|
310
313
|
return { ok: false, problems: [plan.problem], builds: [] };
|
|
311
314
|
case 'effect':
|
|
312
|
-
return effectOutcome(await compiler.effect({ path, source }));
|
|
315
|
+
return effectOutcome(await compiler.effect({ path, source }), glsl);
|
|
313
316
|
case 'skyLayer':
|
|
314
|
-
return skyLayerOutcome(await compiler.skyLayer({ path, source }));
|
|
317
|
+
return skyLayerOutcome(await compiler.skyLayer({ path, source }), glsl);
|
|
315
318
|
case 'material':
|
|
316
|
-
return materialOutcome(await compiler.material({ path, source }), plan.draw);
|
|
319
|
+
return materialOutcome(await compiler.material({ path, source }), plan.draw, glsl);
|
|
317
320
|
case 'shader':
|
|
318
321
|
return shaderOutcome(await compiler.shader({ path, source, pipelines: plan.pipelines, variants: plan.variants }), plan.builds);
|
|
319
322
|
}
|
|
@@ -387,25 +390,25 @@ function fileOutcome(compiled, source, origin, id) {
|
|
|
387
390
|
}
|
|
388
391
|
/**
|
|
389
392
|
* Compiles a `.wgsl` file. `path` names the file in messages, `id` is its module id, and `text` its
|
|
390
|
-
* content as read from disk.
|
|
393
|
+
* content as read from disk. `glsl` false builds the WebGPU path alone.
|
|
391
394
|
*/
|
|
392
|
-
export async function compileWgslFile(path, id, text, compiler = compileHere) {
|
|
395
|
+
export async function compileWgslFile(path, id, text, compiler = compileHere, glsl = true) {
|
|
393
396
|
const source = text.replaceAll('\r\n', '\n');
|
|
394
|
-
const compiled = await compileWgsl(path, source, FILE_HINT, compiler);
|
|
397
|
+
const compiled = await compileWgsl(path, source, FILE_HINT, compiler, glsl);
|
|
395
398
|
return fileOutcome(compiled, source, { path, line: 1, column: 1 }, id);
|
|
396
399
|
}
|
|
397
400
|
/**
|
|
398
401
|
* Compiles one tagged template literal of a script module, whose code is `code`: the compiled
|
|
399
402
|
* WGSL that takes its place, or the error that stops the module.
|
|
400
403
|
*/
|
|
401
|
-
export async function compileLiteral(literal, code, id, path, compiler = compileHere) {
|
|
404
|
+
export async function compileLiteral(literal, code, id, path, compiler = compileHere, glsl = true) {
|
|
402
405
|
if (literal.substitution !== null) {
|
|
403
406
|
const problem = problemAt(path, code, literal.substitution, SUBSTITUTION);
|
|
404
407
|
const failed = { ok: false, problems: [problem], builds: [] };
|
|
405
408
|
return { error: wgslError(failed, code, { path, line: 1, column: 1 }, id, code) };
|
|
406
409
|
}
|
|
407
410
|
const origin = { path, ...placeOf(code, literal.start + 1) };
|
|
408
|
-
const compiled = await compileWgsl(path, literal.source, TAG_HINT, compiler);
|
|
411
|
+
const compiled = await compileWgsl(path, literal.source, TAG_HINT, compiler, glsl);
|
|
409
412
|
if (compiled.ok)
|
|
410
413
|
return { shader: compiled.shader, warnings: warningLines(compiled, literal.source, origin) };
|
|
411
414
|
return { error: wgslError(compiled, literal.source, origin, id, code) };
|
|
@@ -414,9 +417,9 @@ export async function compileLiteral(literal, code, id, path, compiler = compile
|
|
|
414
417
|
* Compiles each tagged template literal in a script module, all at once, with every literal's
|
|
415
418
|
* warnings, or gives the error that stops the module at its first literal that does not compile.
|
|
416
419
|
*/
|
|
417
|
-
export async function compileTaggedWgsl(code, id, path, compiler = compileHere) {
|
|
420
|
+
export async function compileTaggedWgsl(code, id, path, compiler = compileHere, glsl = true) {
|
|
418
421
|
const literals = findTaggedWgsl(code, id);
|
|
419
|
-
const results = await Promise.all(literals.map((literal) => compileLiteral(literal, code, id, path, compiler)));
|
|
422
|
+
const results = await Promise.all(literals.map((literal) => compileLiteral(literal, code, id, path, compiler, glsl)));
|
|
420
423
|
const shaders = [];
|
|
421
424
|
const warnings = [];
|
|
422
425
|
for (const [k, result] of results.entries()) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@null3d/vite-plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Vite plugin for null3D projects: cross-origin isolation headers, HTTPS for testing on phones and tablets, WGSL compiled for WebGPU and WebGL2, glTF models optimized on import, and production builds that compile the sketch module and ship the engine core.",
|
|
5
5
|
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"author": "Ramesh Nair (https://hiddentao.com)",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"prepack": "bun ../../tools/build-package.ts vite-plugin"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@null3d/cli": "0.1.
|
|
55
|
+
"@null3d/cli": "0.1.3",
|
|
56
56
|
"vite": ">=8"
|
|
57
57
|
},
|
|
58
58
|
"peerDependenciesMeta": {
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
}
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@null3d/cli": "0.1.
|
|
64
|
+
"@null3d/cli": "0.1.3",
|
|
65
65
|
"vite": "8.3.1"
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|