wesl-gpu 0.1.9 → 0.1.12

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.
@@ -0,0 +1,185 @@
1
+ import { LinkParams, VirtualLibraryFn } from "wesl";
2
+
3
+ //#region src/DeviceCache.d.ts
4
+
5
+ /**
6
+ * WeakMap cache for GPUDevice-based caching
7
+ *
8
+ * GPUDevices are weakly held to avoid memory leaks.
9
+ */
10
+ declare class DeviceCache<T> {
11
+ private cache;
12
+ get(device: GPUDevice, key: string): T | undefined;
13
+ set(device: GPUDevice, key: string, value: T): void;
14
+ }
15
+ //#endregion
16
+ //#region src/ErrorScopes.d.ts
17
+ /**
18
+ * Runs a function with WebGPU error scopes, automatically handling push/pop/check.
19
+ * Throws if any validation, out-of-memory, or internal errors occur.
20
+ */
21
+ declare function withErrorScopes<T>(device: GPUDevice, fn: () => T | Promise<T>): Promise<T>;
22
+ //#endregion
23
+ //#region src/ExampleTextures.d.ts
24
+ interface SamplerOptions {
25
+ addressMode?: "clamp-to-edge" | "repeat" | "mirror-repeat";
26
+ filterMode?: "nearest" | "linear";
27
+ }
28
+ /** Create texture filled with solid color. Internally cached. */
29
+ declare function solidTexture(device: GPUDevice, color: [r: number, g: number, b: number, a: number], width: number, height: number): GPUTexture;
30
+ /** Create gradient texture. Direction: 'horizontal' (default) or 'vertical'. */
31
+ declare function gradientTexture(device: GPUDevice, width: number, height: number, direction?: "horizontal" | "vertical"): GPUTexture;
32
+ /** Create checkerboard pattern. cellSize: pixels per cell (default: width/4). */
33
+ declare function checkerboardTexture(device: GPUDevice, width: number, height: number, cellSize?: number): GPUTexture;
34
+ /** Create sampler. Default: linear filtering with clamp-to-edge. Internally cached. */
35
+ declare function createSampler(device: GPUDevice, options?: SamplerOptions): GPUSampler;
36
+ /** Create radial gradient texture (white center to black edge). */
37
+ declare function radialGradientTexture(device: GPUDevice, size: number): GPUTexture;
38
+ /** Create edge pattern texture with sharp vertical, horizontal, and diagonal lines. */
39
+ declare function edgePatternTexture(device: GPUDevice, size: number): GPUTexture;
40
+ /** Create color bars texture (RGB primaries and secondaries). */
41
+ declare function colorBarsTexture(device: GPUDevice, size: number): GPUTexture;
42
+ /** Create seeded noise pattern (deterministic). */
43
+ declare function noiseTexture(device: GPUDevice, size: number, seed?: number): GPUTexture;
44
+ //#endregion
45
+ //#region src/RenderUniforms.d.ts
46
+ /** User provided uniform values */
47
+ interface RenderUniforms {
48
+ /** Elapsed time in seconds (default: 0.0) */
49
+ time?: number;
50
+ /** Mouse position in [0,1] normalized coords (default: [0.0, 0.0]) */
51
+ mouse?: [number, number];
52
+ }
53
+ /**
54
+ * Creates a standard uniform buffer for running test fragment shaders.
55
+ *
56
+ * @param outputSize - Output texture dimensions (becomes uniforms.resolution)
57
+ * @param uniforms - User-provided uniform values (time, mouse)
58
+ * @returns GPUBuffer containing uniform data
59
+ */
60
+ declare function renderUniformBuffer(device: GPUDevice, outputSize: [number, number], uniforms?: RenderUniforms): GPUBuffer;
61
+ /**
62
+ * Updates an existing uniform buffer with new values.
63
+ * Use this for per-frame updates in render loops (avoids buffer recreation).
64
+ *
65
+ * @param buffer - Existing uniform buffer to update
66
+ * @param device - GPU device
67
+ * @param resolution - Output texture dimensions
68
+ * @param time - Elapsed time in seconds
69
+ * @param mouse - Mouse position [0,1] normalized coords
70
+ */
71
+ declare function updateRenderUniforms(buffer: GPUBuffer, device: GPUDevice, resolution: [number, number], time: number, mouse?: [number, number]): void;
72
+ /**
73
+ * return the WGSL struct for use in shaders as test::Uniforms.
74
+ *
75
+ * @returns virtual library object for passing to compileShader()
76
+ */
77
+ declare function createUniformsVirtualLib(): Record<string, VirtualLibraryFn>;
78
+ //#endregion
79
+ //#region src/FragmentParams.d.ts
80
+ /** WESL linker options - aligned with wesl's LinkParams */
81
+ type WeslOptions = Pick<LinkParams, "resolver" | "weslSrc" | "rootModuleName" | "conditions" | "libs" | "virtualLibs" | "packageName" | "constants" | "config">;
82
+ /** GPU rendering params for fragment shaders */
83
+ interface FragmentRenderParams {
84
+ device: GPUDevice;
85
+ /** Output texture format. Default: "rgba32float" */
86
+ textureFormat?: GPUTextureFormat;
87
+ /** Output texture size. Default: [1, 1] */
88
+ size?: [width: number, height: number];
89
+ /** Uniform values (time, mouse). Resolution auto-populated from size. */
90
+ uniforms?: RenderUniforms;
91
+ /** Input textures. Bindings: [1..n], samplers at [n+1..n+m]. */
92
+ textures?: GPUTexture[];
93
+ /** Samplers. Length 1 (reused) or match textures.length. */
94
+ samplers?: GPUSampler[];
95
+ }
96
+ /** Combined params for fragment shader execution */
97
+ interface FragmentParams extends WeslOptions, FragmentRenderParams {
98
+ /** Fragment shader source (vertex shader auto-provided) */
99
+ src: string;
100
+ }
101
+ //#endregion
102
+ //#region src/FragmentPipeline.d.ts
103
+ type LinkFragmentParams = WeslOptions & {
104
+ device: GPUDevice;
105
+ /** Fragment shader source (vertex shader is auto-provided) */
106
+ fragmentSource: string;
107
+ };
108
+ interface LinkAndCreateParams extends LinkFragmentParams {
109
+ format: GPUTextureFormat;
110
+ layout?: GPUPipelineLayout | "auto";
111
+ }
112
+ /** Combined: link WESL source and create pipeline in one step. */
113
+ declare function linkAndCreatePipeline(params: LinkAndCreateParams): Promise<GPURenderPipeline>;
114
+ /**
115
+ * Link a WESL/WGSL fragment shader to a shader module.
116
+ * Adds:
117
+ * - vertex shader that covers the viewport with a fullscreen triangle
118
+ * - a virtual module containing a std uniform buffer (for size, etc.)
119
+ */
120
+ declare function linkFragmentShader(params: LinkFragmentParams): Promise<GPUShaderModule>;
121
+ //#endregion
122
+ //#region src/FragmentRender.d.ts
123
+ interface RenderFrameParams {
124
+ device: GPUDevice;
125
+ pipeline: GPURenderPipeline;
126
+ bindGroup?: GPUBindGroup;
127
+ targetView: GPUTextureView;
128
+ }
129
+ /** Execute one fullscreen fragment render pass to target view. */
130
+ declare function renderFrame(params: RenderFrameParams): void;
131
+ //#endregion
132
+ //#region src/FullscreenVertex.d.ts
133
+ /** Number of vertices drawn for fullscreen quad using triangle-strip topology */
134
+ declare const fullscreenVertexCount = 4;
135
+ /** Fullscreen triangle vertex shader that covers viewport with 3 vertices, no vertex buffer needed */
136
+ declare const fullscreenTriangleVertex = "\n @vertex\n fn vs_main(@builtin(vertex_index) idx: u32) -> @builtin(position) vec4f {\n // Covers viewport with 3 vertices, no vertex buffer needed\n var pos: vec2f;\n if (idx == 0u) {\n pos = vec2f(-1.0, -1.0);\n } else if (idx == 1u) {\n pos = vec2f(3.0, -1.0);\n } else {\n pos = vec2f(-1.0, 3.0);\n }\n return vec4f(pos, 0.0, 1.0);\n }";
137
+ //#endregion
138
+ //#region src/RunFragment.d.ts
139
+ /**
140
+ * Run a fragment shader and return pixel data.
141
+ *
142
+ * Combines linking, uniform setup, and rendering into a single call.
143
+ * Useful for shader testing or single-frame renders.
144
+ *
145
+ * @returns Pixel data as a flattened number array
146
+ */
147
+ declare function runFragment(params: FragmentParams): Promise<number[]>;
148
+ //#endregion
149
+ //#region src/SimpleRender.d.ts
150
+ interface SimpleRenderParams {
151
+ device: GPUDevice;
152
+ /** shader module to run, presumed to have one vertex and one fragment entry */
153
+ module: GPUShaderModule;
154
+ /** format of the output texture. default "rgba32float" */
155
+ outputFormat?: GPUTextureFormat;
156
+ /** size of the output texture. default [1, 1]
157
+ * Use [2, 2] for derivative tests
158
+ * Use [512, 512] for visual image tests */
159
+ size?: [number, number];
160
+ /** Input textures to bind in group 0.
161
+ * Bindings: textures at [1..n], samplers at [n+1..n+m]. */
162
+ textures?: GPUTexture[];
163
+ /** Samplers for the input textures.
164
+ * Must be length 1 (reused for all textures) or match textures.length exactly. */
165
+ samplers?: GPUSampler[];
166
+ /** pass these uniforms to the shader in group 0 binding 0 */
167
+ uniformBuffer?: GPUBuffer;
168
+ }
169
+ /**
170
+ * Executes a render pipeline with the given shader module.
171
+ * Creates a texture with the specified format, renders to it, and returns all pixel data.
172
+ * @returns output texture contents in a flattened array (rows flattened, color channels interleaved).
173
+ */
174
+ declare function simpleRender(params: SimpleRenderParams): Promise<number[]>;
175
+ /**
176
+ * Create bind group with optional uniforms, textures, and samplers.
177
+ * Binding layout: 0=uniform buffer (if provided), 1..n=textures, n+1..n+m=samplers.
178
+ * Samplers must be length 1 (reused for all textures) or match textures.length exactly.
179
+ */
180
+ declare function createBindGroup(device: GPUDevice, uniformBuffer: GPUBuffer | undefined, textures?: GPUTexture[], samplers?: GPUSampler[]): {
181
+ layout: GPUBindGroupLayout;
182
+ bindGroup: GPUBindGroup;
183
+ };
184
+ //#endregion
185
+ export { DeviceCache, FragmentParams, FragmentRenderParams, LinkAndCreateParams, LinkFragmentParams, RenderFrameParams, RenderUniforms, SamplerOptions, SimpleRenderParams, WeslOptions, checkerboardTexture, colorBarsTexture, createBindGroup, createSampler, createUniformsVirtualLib, edgePatternTexture, fullscreenTriangleVertex, fullscreenVertexCount, gradientTexture, linkAndCreatePipeline, linkFragmentShader, noiseTexture, radialGradientTexture, renderFrame, renderUniformBuffer, runFragment, simpleRender, solidTexture, updateRenderUniforms, withErrorScopes };
package/package.json CHANGED
@@ -1,18 +1,22 @@
1
1
  {
2
2
  "name": "wesl-gpu",
3
3
  "description": "Browser-compatible WebGPU utilities for shader testing and rendering",
4
- "version": "0.1.9",
4
+ "version": "0.1.12",
5
5
  "type": "module",
6
+ "files": [
7
+ "dist",
8
+ "src"
9
+ ],
6
10
  "repository": "github:wgsl-tooling-wg/wesl-js",
7
11
  "exports": {
8
12
  ".": {
9
- "types": "./dist/index.d.mts",
10
- "import": "./dist/index.mjs"
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js"
11
15
  }
12
16
  },
13
17
  "dependencies": {
14
18
  "thimbleberry": "^0.2.10",
15
- "wesl": "0.7.6"
19
+ "wesl": "0.7.9"
16
20
  },
17
21
  "devDependencies": {
18
22
  "@webgpu/types": "^0.1.68"
@@ -32,5 +36,5 @@
32
36
  "test:once": "vitest run",
33
37
  "typecheck": "tsgo"
34
38
  },
35
- "main": "./dist/index.mjs"
39
+ "main": "./dist/index.js"
36
40
  }
package/tsconfig.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.browser.json"
3
- }
File without changes