wgsl-test 0.2.1 → 0.2.5
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 +2 -27
- package/dist/index.js +145 -84
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/TestFragmentShader.ts +13 -62
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wgsl-test",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -18,18 +18,18 @@
|
|
|
18
18
|
"pngjs": "^7.0.0",
|
|
19
19
|
"thimbleberry": "^0.2.10",
|
|
20
20
|
"webgpu": "^0.3.8",
|
|
21
|
-
"wesl": "0.
|
|
22
|
-
"wesl-gpu": "0.1.
|
|
21
|
+
"wesl": "0.7.1",
|
|
22
|
+
"wesl-gpu": "0.1.4"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/pngjs": "^6.0.0",
|
|
26
|
-
"@webgpu/types": "^0.1.
|
|
26
|
+
"@webgpu/types": "^0.1.68",
|
|
27
27
|
"dependent_package": "x",
|
|
28
28
|
"wesl-tooling": "x"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"vitest": "^
|
|
32
|
-
"vitest-image-snapshot": "^0.6.
|
|
31
|
+
"vitest": "^4.0.16",
|
|
32
|
+
"vitest-image-snapshot": "^0.6.39"
|
|
33
33
|
},
|
|
34
34
|
"peerDependenciesMeta": {
|
|
35
35
|
"vitest": {
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { componentByteSize, numComponents, texelLoadType } from "thimbleberry";
|
|
2
2
|
import type { ImageData } from "vitest-image-snapshot";
|
|
3
|
-
import type { LinkParams } from "wesl";
|
|
4
3
|
import { normalizeModuleName } from "wesl";
|
|
5
4
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
simpleRender,
|
|
5
|
+
type FragmentRenderParams,
|
|
6
|
+
runFragment as runFragmentCore,
|
|
7
|
+
type WeslOptions,
|
|
10
8
|
} from "wesl-gpu";
|
|
11
9
|
import { resolveShaderContext } from "./CompileShader.ts";
|
|
12
10
|
import { resolveShaderSource } from "./ShaderModuleLoader.ts";
|
|
13
11
|
|
|
14
|
-
export interface FragmentTestParams {
|
|
12
|
+
export interface FragmentTestParams extends WeslOptions, FragmentRenderParams {
|
|
15
13
|
/** WESL/WGSL source code for the fragment shader to test.
|
|
16
14
|
* Either src or moduleName must be provided, but not both. */
|
|
17
15
|
src?: string;
|
|
@@ -27,39 +25,6 @@ export interface FragmentTestParams {
|
|
|
27
25
|
* Typically use `import.meta.url`. */
|
|
28
26
|
projectDir?: string;
|
|
29
27
|
|
|
30
|
-
/** GPU device for running the tests.
|
|
31
|
-
* Typically use `getGPUDevice()` from wgsl-test. */
|
|
32
|
-
device: GPUDevice;
|
|
33
|
-
|
|
34
|
-
/** Texture format for the output texture. Default: "rgba32float" */
|
|
35
|
-
textureFormat?: GPUTextureFormat;
|
|
36
|
-
|
|
37
|
-
/** Size of the output texture. Default: [1, 1] for simple color tests.
|
|
38
|
-
* Use [2, 2] for derivative tests (forms a complete 2x2 quad for dpdx/dpdy). */
|
|
39
|
-
size?: [width: number, height: number];
|
|
40
|
-
|
|
41
|
-
/** Flags for conditional compilation to test shader specialization.
|
|
42
|
-
* Useful for testing `@if` statements in the shader. */
|
|
43
|
-
conditions?: LinkParams["conditions"];
|
|
44
|
-
|
|
45
|
-
/** Constants for shader compilation.
|
|
46
|
-
* Injects host-provided values via the `constants::` namespace. */
|
|
47
|
-
constants?: LinkParams["constants"];
|
|
48
|
-
|
|
49
|
-
/** Uniform values for the shader (time, mouse).
|
|
50
|
-
* Resolution is auto-populated from the size parameter.
|
|
51
|
-
* Creates test::Uniforms struct available in the shader. */
|
|
52
|
-
uniforms?: RenderUniforms;
|
|
53
|
-
|
|
54
|
-
/** Input textures for the shader.
|
|
55
|
-
* Bindings: textures at [1..n], samplers at [n+1..n+m].
|
|
56
|
-
* Binding 0 is reserved for uniforms. */
|
|
57
|
-
textures?: GPUTexture[];
|
|
58
|
-
|
|
59
|
-
/** Samplers for the input textures.
|
|
60
|
-
* Must be length 1 (reused for all textures) or match textures.length exactly. */
|
|
61
|
-
samplers?: GPUSampler[];
|
|
62
|
-
|
|
63
28
|
/** Use source shaders from current package instead of built bundles.
|
|
64
29
|
* Default: true for faster iteration during development. */
|
|
65
30
|
useSourceShaders?: boolean;
|
|
@@ -142,39 +107,25 @@ export async function testFragmentImage(
|
|
|
142
107
|
}
|
|
143
108
|
|
|
144
109
|
async function runFragment(params: FragmentTestParams): Promise<number[]> {
|
|
145
|
-
const { projectDir,
|
|
146
|
-
const { conditions = {}, constants } = params;
|
|
147
|
-
const { textureFormat = "rgba32float", size = [1, 1] } = params;
|
|
148
|
-
const { textures, samplers, uniforms = {} } = params;
|
|
110
|
+
const { projectDir, src, moduleName, useSourceShaders } = params;
|
|
149
111
|
|
|
150
112
|
// Resolve shader source from either src or moduleName
|
|
151
113
|
const fragmentSrc = await resolveShaderSource(src, moduleName, projectDir);
|
|
152
114
|
|
|
115
|
+
// Resolve context (libs, resolver, packageName) from project
|
|
153
116
|
const ctx = await resolveShaderContext({
|
|
154
117
|
src: fragmentSrc,
|
|
155
118
|
projectDir,
|
|
156
119
|
useSourceShaders,
|
|
157
120
|
});
|
|
158
121
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
constants,
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
const uniformBuffer = renderUniformBuffer(device, size, uniforms);
|
|
170
|
-
return await simpleRender({
|
|
171
|
-
device,
|
|
172
|
-
module,
|
|
173
|
-
outputFormat: textureFormat,
|
|
174
|
-
size,
|
|
175
|
-
textures,
|
|
176
|
-
samplers,
|
|
177
|
-
uniformBuffer,
|
|
122
|
+
// Use shared runFragment with resolved source and context
|
|
123
|
+
return runFragmentCore({
|
|
124
|
+
...params,
|
|
125
|
+
src: fragmentSrc,
|
|
126
|
+
libs: params.libs ?? ctx.libs,
|
|
127
|
+
resolver: params.resolver ?? ctx.resolver,
|
|
128
|
+
packageName: params.packageName ?? ctx.packageName,
|
|
178
129
|
});
|
|
179
130
|
}
|
|
180
131
|
|