wesl-plugin 0.6.0-pre3
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 +92 -0
- package/dist/PluginExtension-BPBKs2pN.d.ts +41 -0
- package/dist/chunk-JSBRDJBE.js +30 -0
- package/dist/chunk-USWZ2CIV.js +11 -0
- package/dist/chunk-WRYP67OK.js +6761 -0
- package/dist/chunk-ZJBZ62NB.js +11 -0
- package/dist/pluginIndex.d.ts +7 -0
- package/dist/pluginIndex.js +42 -0
- package/dist/plugins/astro.d.ts +7 -0
- package/dist/plugins/astro.js +18 -0
- package/dist/plugins/esbuild.d.ts +8 -0
- package/dist/plugins/esbuild.js +11 -0
- package/dist/plugins/farm.d.ts +8 -0
- package/dist/plugins/farm.js +11 -0
- package/dist/plugins/nuxt.d.ts +10 -0
- package/dist/plugins/nuxt.js +28 -0
- package/dist/plugins/rollup.d.ts +8 -0
- package/dist/plugins/rollup.js +11 -0
- package/dist/plugins/rspack.d.ts +7 -0
- package/dist/plugins/rspack.js +11 -0
- package/dist/plugins/vite.d.ts +8 -0
- package/dist/plugins/vite.js +8 -0
- package/dist/plugins/webpack.d.ts +8 -0
- package/dist/plugins/webpack.js +8 -0
- package/dist/weslPluginOptions-BBX99ilB.d.ts +8 -0
- package/package.json +101 -0
- package/src/BindingLayoutExtension.ts +35 -0
- package/src/LinkExtension.ts +51 -0
- package/src/PluginExtension.ts +26 -0
- package/src/defaultSuffixTypes.d.ts +14 -0
- package/src/pluginIndex.ts +2 -0
- package/src/plugins/astro.ts +13 -0
- package/src/plugins/esbuild.ts +4 -0
- package/src/plugins/farm.ts +4 -0
- package/src/plugins/nuxt.ts +25 -0
- package/src/plugins/rollup.ts +4 -0
- package/src/plugins/rspack.ts +4 -0
- package/src/plugins/vite.ts +4 -0
- package/src/plugins/webpack.ts +4 -0
- package/src/weslPlugin.ts +327 -0
- package/src/weslPluginOptions.ts +6 -0
package/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# wesl plugin
|
|
2
|
+
|
|
3
|
+
The wesl-plugin handles `.wesl` and `.wgsl` files
|
|
4
|
+
in JavaScript bundlers to make using webgpu shaders more convenient.
|
|
5
|
+
Plugin features are accessed from JavaScript and TypeScript with `import` statements:
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import linkConfig from "./shaders/app.wesl?link";
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Each plugin features is enabled by its own wesl-plugin [extension](#extensions).
|
|
12
|
+
|
|
13
|
+
## Getting started
|
|
14
|
+
|
|
15
|
+
### Vite
|
|
16
|
+
|
|
17
|
+
Add the wesl-plugin along with any selected extensions to `vite.config.ts`:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { UserConfig } from "vite";
|
|
21
|
+
import weslPlugin from "wesl-plugin/vite";
|
|
22
|
+
import { linkBuildPlugin } from "wesl-plugin";
|
|
23
|
+
|
|
24
|
+
const config: UserConfig = {
|
|
25
|
+
plugins: [ weslPlugin({ extensions: [linkBuildPlugin] }) ],
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default config;
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
In your JavaScript or TypeScript program you can then import
|
|
32
|
+
wesl or wgsl shaders with a `?link` suffix and link them into WGSL at runtime.
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import linkConfig from "./shaders/app.wesl?link";
|
|
36
|
+
|
|
37
|
+
function makeShaders() {
|
|
38
|
+
const vertShader = await link({
|
|
39
|
+
...linkConfig,
|
|
40
|
+
rootModuleName: "myVerts.wesl",
|
|
41
|
+
conditions: {mobileGPU: true}
|
|
42
|
+
});
|
|
43
|
+
const computeShader = await link({
|
|
44
|
+
...linkConfig,
|
|
45
|
+
rootModuleName: "myCompute.wesl",
|
|
46
|
+
constants: {num_lights: 1}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Other Bundlers
|
|
53
|
+
|
|
54
|
+
The wesl-plugin is available for many popular bundlers:
|
|
55
|
+
|
|
56
|
+
``` ts
|
|
57
|
+
import weslPlugin from "wesl-plugin/esbuild";
|
|
58
|
+
import weslPlugin from "wesl-plugin/rollup";
|
|
59
|
+
import weslPlugin from "wesl-plugin/webpack";
|
|
60
|
+
import weslPlugin from "wesl-plugin/nuxt";
|
|
61
|
+
import weslPlugin from "wesl-plugin/farm";
|
|
62
|
+
import weslPlugin from "wesl-plugin/rpack";
|
|
63
|
+
// etc.
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Extensions
|
|
67
|
+
|
|
68
|
+
- **LinkExtension** - import `?link` in JavaScript/TypeScript programs to conveniently assemble shader files and libraries for linking at runtime.
|
|
69
|
+
Reads the `wesl.toml` file to find local shader files, partially parses the local
|
|
70
|
+
shader files to find shader libraries, and returns a `LinkParams` object
|
|
71
|
+
ready to use for runtime linking.
|
|
72
|
+
|
|
73
|
+
### Prototype Extensions
|
|
74
|
+
|
|
75
|
+
- **SimpleReReflectExtension** - (_demo for extension writers_) import `?simple_reflect` to
|
|
76
|
+
translate some wgsl `struct` elements into JavaScript and TypeScript.
|
|
77
|
+
Demonstrates to wesl-plugin extension authors how to connect
|
|
78
|
+
to the wesl-plugin, how to produce JavaScript, and how to produce TypeScript.
|
|
79
|
+
- **BindingLayoutExtension** - (_prototype_) import `?bindingLayout` to collect JavaScript
|
|
80
|
+
`BindingGroupLayout` objects.
|
|
81
|
+
Works in concert with the `bindingStructsPlugin` to translate a proposed new WGSL
|
|
82
|
+
feature for defining binding group layouts in shaders [#4957](https://github.com/gpuweb/gpuweb/issues/4957).
|
|
83
|
+
|
|
84
|
+
## Developing a wesl-plugin extension
|
|
85
|
+
|
|
86
|
+
To add a new extension to the wesl-plugin:
|
|
87
|
+
|
|
88
|
+
- Pick an import suffix (e.g. `?myExtension`).
|
|
89
|
+
- Implement a function that returns a JavaScript string.
|
|
90
|
+
- Extensions have access to wgsl/wesl sources, a parsed abstract syntax tree for the sources, etc.
|
|
91
|
+
|
|
92
|
+
See [PluginExtension.ts](https://github.com/wgsl-tooling-wg/wesl-js/blob/master/tools/packages/wesl-plugin/src/PluginExtension.ts) for details.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { WeslJsPlugin, ParsedRegistry } from 'wesl';
|
|
2
|
+
|
|
3
|
+
/** loaded (or synthesized) info from .toml */
|
|
4
|
+
interface WeslToml {
|
|
5
|
+
/** glob search strings to find .wesl/.wgsl files. Relative to the toml directory! */
|
|
6
|
+
weslFiles: string[];
|
|
7
|
+
/** base directory for wesl files. Relative to the toml directory! */
|
|
8
|
+
weslRoot: string;
|
|
9
|
+
}
|
|
10
|
+
interface WeslTomlInfo {
|
|
11
|
+
/** The path to the toml file, relative to the cwd */
|
|
12
|
+
tomlFile: string;
|
|
13
|
+
/** The path to the directory that contains the toml. Relative to the cwd. Paths inside the toml are relative to this. */
|
|
14
|
+
tomlDir: string;
|
|
15
|
+
/**
|
|
16
|
+
* The wesl root, relative to the cwd. This lets us correctly do `path.resolve(resolvedWeslRoot, someShaderFile)`
|
|
17
|
+
*/
|
|
18
|
+
resolvedWeslRoot: string;
|
|
19
|
+
/** The underlying toml file */
|
|
20
|
+
toml: WeslToml;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** function type required for for emit extensions */
|
|
24
|
+
type ExtensionEmitFn = (id: string, pluginApi: PluginExtensionApi) => Promise<string>;
|
|
25
|
+
/** an extension that runs inside the wesl-js build plugin */
|
|
26
|
+
interface PluginExtension extends WeslJsPlugin {
|
|
27
|
+
/** javascript imports with this suffix will trigger the plugin */
|
|
28
|
+
extensionName: string;
|
|
29
|
+
/** generate javascript text for js/ts importers to use.
|
|
30
|
+
* e.g. import myPluginJs from "./foo.wesl?myPlugin"; */
|
|
31
|
+
emitFn: ExtensionEmitFn;
|
|
32
|
+
}
|
|
33
|
+
/** api supplied to plugin extensions */
|
|
34
|
+
interface PluginExtensionApi {
|
|
35
|
+
weslToml: () => Promise<WeslTomlInfo>;
|
|
36
|
+
weslSrc: () => Promise<Record<string, string>>;
|
|
37
|
+
weslRegistry: () => Promise<ParsedRegistry>;
|
|
38
|
+
weslMain: (baseId: string) => Promise<string>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type { ExtensionEmitFn as E, PluginExtension as P, PluginExtensionApi as a };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
__commonJS,
|
|
29
|
+
__toESM
|
|
30
|
+
};
|