wesl-tooling 0.6.2 → 0.6.4
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/dist/index.d.ts +17 -5
- package/dist/index.js +14 -5
- package/package.json +4 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VirtualLibraryFn, WeslBundle
|
|
1
|
+
import { VirtualLibraryFn, WeslBundle } from "wesl";
|
|
2
2
|
import { GPUElementFormat } from "thimbleberry";
|
|
3
3
|
|
|
4
4
|
//#region src/ParseDependencies.d.ts
|
|
@@ -42,6 +42,18 @@ declare function dependencyBundles(weslSrc: Record<string, string>, projectDir:
|
|
|
42
42
|
|
|
43
43
|
//#endregion
|
|
44
44
|
//#region src/SimpleComputeShader.d.ts
|
|
45
|
+
interface CompileShaderParams {
|
|
46
|
+
/** The project directory, used for resolving dependencies. */
|
|
47
|
+
projectDir: string;
|
|
48
|
+
/** The GPUDevice to use for shader compilation. */
|
|
49
|
+
device: GPUDevice;
|
|
50
|
+
/** The WGSL/WESL shader source code. */
|
|
51
|
+
src: string;
|
|
52
|
+
/** Optional conditions for shader compilation. */
|
|
53
|
+
conditions?: Record<string, boolean>;
|
|
54
|
+
/** Optional virtual libraries to include in the shader. */
|
|
55
|
+
virtualLibs?: Record<string, VirtualLibraryFn>;
|
|
56
|
+
}
|
|
45
57
|
/**
|
|
46
58
|
* Compiles a single WESL shader source string into a GPUShaderModule for testing
|
|
47
59
|
* with automatic package detection.
|
|
@@ -51,11 +63,11 @@ declare function dependencyBundles(weslSrc: Record<string, string>, projectDir:
|
|
|
51
63
|
* bundle to include in the link.
|
|
52
64
|
*
|
|
53
65
|
* @param projectDir - The project directory, used for resolving dependencies.
|
|
54
|
-
* @param device - The
|
|
66
|
+
* @param device - The GPUDevice to use for shader compilation.
|
|
55
67
|
* @param src - The WESL shader source code.
|
|
56
68
|
* @returns A Promise that resolves to the compiled GPUShaderModule.
|
|
57
69
|
*/
|
|
58
|
-
declare function compileShader(
|
|
70
|
+
declare function compileShader(params: CompileShaderParams): Promise<GPUShaderModule>;
|
|
59
71
|
/**
|
|
60
72
|
* Transpiles and runs a simple compute shader on the GPU for testing.
|
|
61
73
|
*
|
|
@@ -72,7 +84,7 @@ declare function compileShader(projectDir: string, device: WeslDevice, src: stri
|
|
|
72
84
|
* @param resultFormat - format for interpreting the result buffer data. (default u32)
|
|
73
85
|
* @returns storage result array (typically four numbers if the buffer format is u32 or f32)
|
|
74
86
|
*/
|
|
75
|
-
declare function testComputeShader(projectDir: string, gpu: GPU, src: string, resultFormat?: GPUElementFormat): Promise<number[]>;
|
|
87
|
+
declare function testComputeShader(projectDir: string, gpu: GPU, src: string, resultFormat?: GPUElementFormat, conditions?: Record<string, boolean>): Promise<number[]>;
|
|
76
88
|
/**
|
|
77
89
|
* Transpiles and runs a simple compute shader on the GPU for testing.
|
|
78
90
|
*
|
|
@@ -92,4 +104,4 @@ declare function testComputeShader(projectDir: string, gpu: GPU, src: string, re
|
|
|
92
104
|
declare function runSimpleComputePipeline(device: GPUDevice, module: GPUShaderModule, resultFormat?: GPUElementFormat): Promise<number[]>;
|
|
93
105
|
|
|
94
106
|
//#endregion
|
|
95
|
-
export { compileShader, dependencyBundles, parseDependencies, runSimpleComputePipeline, testComputeShader };
|
|
107
|
+
export { CompileShaderParams, compileShader, dependencyBundles, parseDependencies, runSimpleComputePipeline, testComputeShader };
|
package/dist/index.js
CHANGED
|
@@ -95,17 +95,19 @@ const resultBufferSize = 16;
|
|
|
95
95
|
* bundle to include in the link.
|
|
96
96
|
*
|
|
97
97
|
* @param projectDir - The project directory, used for resolving dependencies.
|
|
98
|
-
* @param device - The
|
|
98
|
+
* @param device - The GPUDevice to use for shader compilation.
|
|
99
99
|
* @param src - The WESL shader source code.
|
|
100
100
|
* @returns A Promise that resolves to the compiled GPUShaderModule.
|
|
101
101
|
*/
|
|
102
|
-
async function compileShader(
|
|
102
|
+
async function compileShader(params) {
|
|
103
|
+
const { projectDir, device, src, conditions, virtualLibs } = params;
|
|
103
104
|
const weslSrc = { main: src };
|
|
104
105
|
const libs = await dependencyBundles(weslSrc, projectDir);
|
|
105
106
|
const linked = await link({
|
|
106
107
|
weslSrc,
|
|
107
108
|
libs,
|
|
108
|
-
virtualLibs
|
|
109
|
+
virtualLibs,
|
|
110
|
+
conditions
|
|
109
111
|
});
|
|
110
112
|
return device.createShaderModule({ code: linked.dest });
|
|
111
113
|
}
|
|
@@ -125,14 +127,21 @@ async function compileShader(projectDir, device, src, virtualLibs) {
|
|
|
125
127
|
* @param resultFormat - format for interpreting the result buffer data. (default u32)
|
|
126
128
|
* @returns storage result array (typically four numbers if the buffer format is u32 or f32)
|
|
127
129
|
*/
|
|
128
|
-
async function testComputeShader(projectDir, gpu, src, resultFormat = "f32") {
|
|
130
|
+
async function testComputeShader(projectDir, gpu, src, resultFormat = "f32", conditions = {}) {
|
|
129
131
|
const adapter = await gpu.requestAdapter();
|
|
130
132
|
const device = await requestWeslDevice(adapter);
|
|
131
133
|
try {
|
|
132
134
|
const arraySize = resultBufferSize / elementByteSize(resultFormat);
|
|
133
135
|
const arrayType = `array<${resultFormat}, ${arraySize}>`;
|
|
134
136
|
const virtualLibs = { test: () => `@group(0) @binding(0) var <storage, read_write> results: ${arrayType};` };
|
|
135
|
-
const
|
|
137
|
+
const params = {
|
|
138
|
+
projectDir,
|
|
139
|
+
device,
|
|
140
|
+
src,
|
|
141
|
+
conditions,
|
|
142
|
+
virtualLibs
|
|
143
|
+
};
|
|
144
|
+
const module = await compileShader(params);
|
|
136
145
|
const result = await runSimpleComputePipeline(device, module, resultFormat);
|
|
137
146
|
return result;
|
|
138
147
|
} finally {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wesl-tooling",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -17,6 +17,9 @@
|
|
|
17
17
|
"tsdown": "^0.11.3",
|
|
18
18
|
"wesl": "0.6.2"
|
|
19
19
|
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"wesl": "^0.6.2"
|
|
22
|
+
},
|
|
20
23
|
"scripts": {
|
|
21
24
|
"echo": "echo",
|
|
22
25
|
"build": "tsdown",
|