@motion-core/motion-gpu 0.5.0 → 0.7.0
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 +35 -2
- package/dist/core/compute-bindgroup-cache.d.ts +13 -0
- package/dist/core/compute-bindgroup-cache.d.ts.map +1 -0
- package/dist/core/compute-bindgroup-cache.js +45 -0
- package/dist/core/compute-bindgroup-cache.js.map +1 -0
- package/dist/core/compute-shader.d.ts +48 -0
- package/dist/core/compute-shader.d.ts.map +1 -1
- package/dist/core/compute-shader.js +34 -1
- package/dist/core/compute-shader.js.map +1 -1
- package/dist/core/error-diagnostics.d.ts +8 -1
- package/dist/core/error-diagnostics.d.ts.map +1 -1
- package/dist/core/error-diagnostics.js +7 -3
- package/dist/core/error-diagnostics.js.map +1 -1
- package/dist/core/error-report.d.ts.map +1 -1
- package/dist/core/error-report.js +19 -1
- package/dist/core/error-report.js.map +1 -1
- package/dist/core/material.d.ts.map +1 -1
- package/dist/core/material.js +2 -1
- package/dist/core/material.js.map +1 -1
- package/dist/core/pointer.d.ts +96 -0
- package/dist/core/pointer.d.ts.map +1 -0
- package/dist/core/pointer.js +71 -0
- package/dist/core/pointer.js.map +1 -0
- package/dist/core/renderer.d.ts.map +1 -1
- package/dist/core/renderer.js +150 -85
- package/dist/core/renderer.js.map +1 -1
- package/dist/core/runtime-loop.d.ts.map +1 -1
- package/dist/core/runtime-loop.js +26 -14
- package/dist/core/runtime-loop.js.map +1 -1
- package/dist/core/shader.d.ts +7 -2
- package/dist/core/shader.d.ts.map +1 -1
- package/dist/core/shader.js +1 -0
- package/dist/core/shader.js.map +1 -1
- package/dist/core/textures.d.ts +4 -0
- package/dist/core/textures.d.ts.map +1 -1
- package/dist/core/textures.js +2 -1
- package/dist/core/textures.js.map +1 -1
- package/dist/core/types.d.ts +1 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/react/advanced.js +2 -1
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +2 -1
- package/dist/react/use-pointer.d.ts +94 -0
- package/dist/react/use-pointer.d.ts.map +1 -0
- package/dist/react/use-pointer.js +285 -0
- package/dist/react/use-pointer.js.map +1 -0
- package/dist/svelte/advanced.js +2 -1
- package/dist/svelte/index.d.ts +2 -0
- package/dist/svelte/index.d.ts.map +1 -1
- package/dist/svelte/index.js +2 -1
- package/dist/svelte/use-pointer.d.ts +94 -0
- package/dist/svelte/use-pointer.d.ts.map +1 -0
- package/dist/svelte/use-pointer.js +292 -0
- package/dist/svelte/use-pointer.js.map +1 -0
- package/package.json +1 -1
- package/src/lib/core/compute-bindgroup-cache.ts +73 -0
- package/src/lib/core/compute-shader.ts +86 -0
- package/src/lib/core/error-diagnostics.ts +29 -4
- package/src/lib/core/error-report.ts +26 -1
- package/src/lib/core/material.ts +2 -1
- package/src/lib/core/pointer.ts +177 -0
- package/src/lib/core/renderer.ts +198 -92
- package/src/lib/core/runtime-loop.ts +37 -16
- package/src/lib/core/shader.ts +13 -2
- package/src/lib/core/textures.ts +6 -1
- package/src/lib/core/types.ts +1 -1
- package/src/lib/react/index.ts +10 -0
- package/src/lib/react/use-pointer.ts +515 -0
- package/src/lib/svelte/index.ts +10 -0
- package/src/lib/svelte/use-pointer.ts +507 -0
package/README.md
CHANGED
|
@@ -65,7 +65,7 @@ Motion GPU follows a simple three-step flow:
|
|
|
65
65
|
|
|
66
66
|
1. Define an immutable material with `defineMaterial(...)`.
|
|
67
67
|
2. Render it with `<FragCanvas />`.
|
|
68
|
-
3. Drive runtime updates with `useFrame(...)`, `useMotionGPU()`, and `useTexture(...)`.
|
|
68
|
+
3. Drive runtime updates with `useFrame(...)`, `useMotionGPU()`, `usePointer()`, and `useTexture(...)`.
|
|
69
69
|
|
|
70
70
|
---
|
|
71
71
|
|
|
@@ -100,6 +100,7 @@ Motion GPU follows a simple three-step flow:
|
|
|
100
100
|
- `defineMaterial`
|
|
101
101
|
- `useMotionGPU`
|
|
102
102
|
- `useFrame`
|
|
103
|
+
- `usePointer`
|
|
103
104
|
- `useTexture`
|
|
104
105
|
- `ShaderPass`
|
|
105
106
|
- `BlitPass`
|
|
@@ -134,6 +135,7 @@ Also exports runtime/core types:
|
|
|
134
135
|
- `defineMaterial`
|
|
135
136
|
- `useMotionGPU`
|
|
136
137
|
- `useFrame`
|
|
138
|
+
- `usePointer`
|
|
137
139
|
- `useTexture`
|
|
138
140
|
- `ShaderPass`
|
|
139
141
|
- `BlitPass`
|
|
@@ -308,6 +310,37 @@ export function Runtime() {
|
|
|
308
310
|
|
|
309
311
|
---
|
|
310
312
|
|
|
313
|
+
## 2b. Add pointer-driven uniforms via `usePointer`
|
|
314
|
+
|
|
315
|
+
```svelte
|
|
316
|
+
<!-- Runtime.svelte -->
|
|
317
|
+
<script lang="ts">
|
|
318
|
+
import { useFrame, usePointer } from '@motion-core/motion-gpu/svelte';
|
|
319
|
+
|
|
320
|
+
const pointer = usePointer();
|
|
321
|
+
|
|
322
|
+
useFrame((state) => {
|
|
323
|
+
state.setUniform('uMouse', pointer.state.current.uv);
|
|
324
|
+
});
|
|
325
|
+
</script>
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
```tsx
|
|
329
|
+
import { useFrame, usePointer } from '@motion-core/motion-gpu/react';
|
|
330
|
+
|
|
331
|
+
export function Runtime() {
|
|
332
|
+
const pointer = usePointer();
|
|
333
|
+
|
|
334
|
+
useFrame((state) => {
|
|
335
|
+
state.setUniform('uMouse', pointer.state.current.uv);
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
return null;
|
|
339
|
+
}
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
---
|
|
343
|
+
|
|
311
344
|
## 3. Add a GPU compute pass
|
|
312
345
|
|
|
313
346
|
```svelte
|
|
@@ -442,7 +475,7 @@ fn frag(uv: vec2f) -> vec4f
|
|
|
442
475
|
fn shade(inputColor: vec4f, uv: vec2f) -> vec4f
|
|
443
476
|
```
|
|
444
477
|
|
|
445
|
-
3. `useFrame()` and `
|
|
478
|
+
3. `useFrame()`, `useMotionGPU()`, and `usePointer()` must be called inside `<FragCanvas>` subtree.
|
|
446
479
|
|
|
447
480
|
4. You can only set uniforms/textures that were declared in `defineMaterial(...)`.
|
|
448
481
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="@webgpu/types" />
|
|
2
|
+
export interface ComputeStorageBindGroupCacheRequest {
|
|
3
|
+
topologyKey: string;
|
|
4
|
+
layoutEntries: GPUBindGroupLayoutEntry[];
|
|
5
|
+
bindGroupEntries: GPUBindGroupEntry[];
|
|
6
|
+
resourceRefs: readonly unknown[];
|
|
7
|
+
}
|
|
8
|
+
export interface ComputeStorageBindGroupCache {
|
|
9
|
+
getOrCreate: (request: ComputeStorageBindGroupCacheRequest) => GPUBindGroup | null;
|
|
10
|
+
reset: () => void;
|
|
11
|
+
}
|
|
12
|
+
export declare function createComputeStorageBindGroupCache(device: GPUDevice): ComputeStorageBindGroupCache;
|
|
13
|
+
//# sourceMappingURL=compute-bindgroup-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compute-bindgroup-cache.d.ts","sourceRoot":"","sources":["../../src/lib/core/compute-bindgroup-cache.ts"],"names":[],"mappings":";AAAA,MAAM,WAAW,mCAAmC;IACnD,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,uBAAuB,EAAE,CAAC;IACzC,gBAAgB,EAAE,iBAAiB,EAAE,CAAC;IACtC,YAAY,EAAE,SAAS,OAAO,EAAE,CAAC;CACjC;AAED,MAAM,WAAW,4BAA4B;IAC5C,WAAW,EAAE,CAAC,OAAO,EAAE,mCAAmC,KAAK,YAAY,GAAG,IAAI,CAAC;IACnF,KAAK,EAAE,MAAM,IAAI,CAAC;CAClB;AAgBD,wBAAgB,kCAAkC,CACjD,MAAM,EAAE,SAAS,GACf,4BAA4B,CA4C9B"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//#region src/lib/core/compute-bindgroup-cache.ts
|
|
2
|
+
function equalResourceRefs(previous, next) {
|
|
3
|
+
if (previous.length !== next.length) return false;
|
|
4
|
+
for (let index = 0; index < previous.length; index += 1) if (!Object.is(previous[index], next[index])) return false;
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
function createComputeStorageBindGroupCache(device) {
|
|
8
|
+
let cachedTopologyKey = null;
|
|
9
|
+
let cachedLayout = null;
|
|
10
|
+
let cachedBindGroup = null;
|
|
11
|
+
let cachedResourceRefs = [];
|
|
12
|
+
const reset = () => {
|
|
13
|
+
cachedTopologyKey = null;
|
|
14
|
+
cachedLayout = null;
|
|
15
|
+
cachedBindGroup = null;
|
|
16
|
+
cachedResourceRefs = [];
|
|
17
|
+
};
|
|
18
|
+
return {
|
|
19
|
+
getOrCreate(request) {
|
|
20
|
+
if (request.layoutEntries.length === 0) {
|
|
21
|
+
reset();
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
if (cachedTopologyKey !== request.topologyKey) {
|
|
25
|
+
cachedTopologyKey = request.topologyKey;
|
|
26
|
+
cachedLayout = device.createBindGroupLayout({ entries: request.layoutEntries });
|
|
27
|
+
cachedBindGroup = null;
|
|
28
|
+
cachedResourceRefs = [];
|
|
29
|
+
}
|
|
30
|
+
if (!cachedLayout) throw new Error("Compute storage bind group cache is missing a layout.");
|
|
31
|
+
if (cachedBindGroup && equalResourceRefs(cachedResourceRefs, request.resourceRefs)) return cachedBindGroup;
|
|
32
|
+
cachedBindGroup = device.createBindGroup({
|
|
33
|
+
layout: cachedLayout,
|
|
34
|
+
entries: request.bindGroupEntries
|
|
35
|
+
});
|
|
36
|
+
cachedResourceRefs = [...request.resourceRefs];
|
|
37
|
+
return cachedBindGroup;
|
|
38
|
+
},
|
|
39
|
+
reset
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { createComputeStorageBindGroupCache };
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=compute-bindgroup-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compute-bindgroup-cache.js","names":[],"sources":["../../src/lib/core/compute-bindgroup-cache.ts"],"sourcesContent":["export interface ComputeStorageBindGroupCacheRequest {\n\ttopologyKey: string;\n\tlayoutEntries: GPUBindGroupLayoutEntry[];\n\tbindGroupEntries: GPUBindGroupEntry[];\n\tresourceRefs: readonly unknown[];\n}\n\nexport interface ComputeStorageBindGroupCache {\n\tgetOrCreate: (request: ComputeStorageBindGroupCacheRequest) => GPUBindGroup | null;\n\treset: () => void;\n}\n\nfunction equalResourceRefs(previous: readonly unknown[], next: readonly unknown[]): boolean {\n\tif (previous.length !== next.length) {\n\t\treturn false;\n\t}\n\n\tfor (let index = 0; index < previous.length; index += 1) {\n\t\tif (!Object.is(previous[index], next[index])) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn true;\n}\n\nexport function createComputeStorageBindGroupCache(\n\tdevice: GPUDevice\n): ComputeStorageBindGroupCache {\n\tlet cachedTopologyKey: string | null = null;\n\tlet cachedLayout: GPUBindGroupLayout | null = null;\n\tlet cachedBindGroup: GPUBindGroup | null = null;\n\tlet cachedResourceRefs: readonly unknown[] = [];\n\n\tconst reset = (): void => {\n\t\tcachedTopologyKey = null;\n\t\tcachedLayout = null;\n\t\tcachedBindGroup = null;\n\t\tcachedResourceRefs = [];\n\t};\n\n\treturn {\n\t\tgetOrCreate(request) {\n\t\t\tif (request.layoutEntries.length === 0) {\n\t\t\t\treset();\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tif (cachedTopologyKey !== request.topologyKey) {\n\t\t\t\tcachedTopologyKey = request.topologyKey;\n\t\t\t\tcachedLayout = device.createBindGroupLayout({ entries: request.layoutEntries });\n\t\t\t\tcachedBindGroup = null;\n\t\t\t\tcachedResourceRefs = [];\n\t\t\t}\n\n\t\t\tif (!cachedLayout) {\n\t\t\t\tthrow new Error('Compute storage bind group cache is missing a layout.');\n\t\t\t}\n\n\t\t\tif (cachedBindGroup && equalResourceRefs(cachedResourceRefs, request.resourceRefs)) {\n\t\t\t\treturn cachedBindGroup;\n\t\t\t}\n\n\t\t\tcachedBindGroup = device.createBindGroup({\n\t\t\t\tlayout: cachedLayout,\n\t\t\t\tentries: request.bindGroupEntries\n\t\t\t});\n\t\t\tcachedResourceRefs = [...request.resourceRefs];\n\t\t\treturn cachedBindGroup;\n\t\t},\n\t\treset\n\t};\n}\n"],"mappings":";AAYA,SAAS,kBAAkB,UAA8B,MAAmC;AAC3F,KAAI,SAAS,WAAW,KAAK,OAC5B,QAAO;AAGR,MAAK,IAAI,QAAQ,GAAG,QAAQ,SAAS,QAAQ,SAAS,EACrD,KAAI,CAAC,OAAO,GAAG,SAAS,QAAQ,KAAK,OAAO,CAC3C,QAAO;AAIT,QAAO;;AAGR,SAAgB,mCACf,QAC+B;CAC/B,IAAI,oBAAmC;CACvC,IAAI,eAA0C;CAC9C,IAAI,kBAAuC;CAC3C,IAAI,qBAAyC,EAAE;CAE/C,MAAM,cAAoB;AACzB,sBAAoB;AACpB,iBAAe;AACf,oBAAkB;AAClB,uBAAqB,EAAE;;AAGxB,QAAO;EACN,YAAY,SAAS;AACpB,OAAI,QAAQ,cAAc,WAAW,GAAG;AACvC,WAAO;AACP,WAAO;;AAGR,OAAI,sBAAsB,QAAQ,aAAa;AAC9C,wBAAoB,QAAQ;AAC5B,mBAAe,OAAO,sBAAsB,EAAE,SAAS,QAAQ,eAAe,CAAC;AAC/E,sBAAkB;AAClB,yBAAqB,EAAE;;AAGxB,OAAI,CAAC,aACJ,OAAM,IAAI,MAAM,wDAAwD;AAGzE,OAAI,mBAAmB,kBAAkB,oBAAoB,QAAQ,aAAa,CACjF,QAAO;AAGR,qBAAkB,OAAO,gBAAgB;IACxC,QAAQ;IACR,SAAS,QAAQ;IACjB,CAAC;AACF,wBAAqB,CAAC,GAAG,QAAQ,aAAa;AAC9C,UAAO;;EAER;EACA"}
|
|
@@ -65,6 +65,24 @@ export declare function buildPingPongComputeShaderSource(options: {
|
|
|
65
65
|
target: string;
|
|
66
66
|
targetFormat: GPUTextureFormat;
|
|
67
67
|
}): string;
|
|
68
|
+
/**
|
|
69
|
+
* Source location for generated compute shader lines.
|
|
70
|
+
*/
|
|
71
|
+
export interface ComputeShaderSourceLocation {
|
|
72
|
+
kind: 'compute';
|
|
73
|
+
line: number;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 1-based line map from generated compute WGSL to user compute source.
|
|
77
|
+
*/
|
|
78
|
+
export type ComputeShaderLineMap = Array<ComputeShaderSourceLocation | null>;
|
|
79
|
+
/**
|
|
80
|
+
* Result of compute shader source generation with line mapping metadata.
|
|
81
|
+
*/
|
|
82
|
+
export interface BuiltComputeShaderSource {
|
|
83
|
+
code: string;
|
|
84
|
+
lineMap: ComputeShaderLineMap;
|
|
85
|
+
}
|
|
68
86
|
/**
|
|
69
87
|
* Assembles full compute shader WGSL with preamble.
|
|
70
88
|
*
|
|
@@ -84,4 +102,34 @@ export declare function buildComputeShaderSource(options: {
|
|
|
84
102
|
format: GPUTextureFormat;
|
|
85
103
|
}>;
|
|
86
104
|
}): string;
|
|
105
|
+
/**
|
|
106
|
+
* Assembles full compute shader WGSL with source line mapping metadata.
|
|
107
|
+
*/
|
|
108
|
+
export declare function buildComputeShaderSourceWithMap(options: {
|
|
109
|
+
compute: string;
|
|
110
|
+
uniformLayout: UniformLayout;
|
|
111
|
+
storageBufferKeys: string[];
|
|
112
|
+
storageBufferDefinitions: Record<string, {
|
|
113
|
+
type: StorageBufferType;
|
|
114
|
+
access: StorageBufferAccess;
|
|
115
|
+
}>;
|
|
116
|
+
storageTextureKeys: string[];
|
|
117
|
+
storageTextureDefinitions: Record<string, {
|
|
118
|
+
format: GPUTextureFormat;
|
|
119
|
+
}>;
|
|
120
|
+
}): BuiltComputeShaderSource;
|
|
121
|
+
/**
|
|
122
|
+
* Assembles ping-pong compute shader WGSL with source line mapping metadata.
|
|
123
|
+
*/
|
|
124
|
+
export declare function buildPingPongComputeShaderSourceWithMap(options: {
|
|
125
|
+
compute: string;
|
|
126
|
+
uniformLayout: UniformLayout;
|
|
127
|
+
storageBufferKeys: string[];
|
|
128
|
+
storageBufferDefinitions: Record<string, {
|
|
129
|
+
type: StorageBufferType;
|
|
130
|
+
access: StorageBufferAccess;
|
|
131
|
+
}>;
|
|
132
|
+
target: string;
|
|
133
|
+
targetFormat: GPUTextureFormat;
|
|
134
|
+
}): BuiltComputeShaderSource;
|
|
87
135
|
//# sourceMappingURL=compute-shader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compute-shader.d.ts","sourceRoot":"","sources":["../../src/lib/core/compute-shader.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAExF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,QAA+D,CAAC;AA+DnG;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAc3D;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAc9E;AA2BD;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAChD,iBAAiB,EAAE,MAAM,EAAE,EAC3B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,MAAM,EAAE,mBAAmB,CAAA;CAAE,CAAC,EACrF,UAAU,EAAE,MAAM,GAChB,MAAM,CAyBR;AAED;;;;;;;GAOG;AACH,wBAAgB,kCAAkC,CACjD,kBAAkB,EAAE,MAAM,EAAE,EAC5B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,gBAAgB,CAAA;CAAE,CAAC,EACzD,UAAU,EAAE,MAAM,GAChB,MAAM,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AM,EAAE,mBAAmB,CAAA;KAAE,CACxD,CAAC;IACF,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,gBAAgB,CAAC;CAC/B,GAAG,wBAAwB,CAM3B"}
|
|
@@ -199,7 +199,40 @@ ${storageTextureBindings ? "\n" + storageTextureBindings : ""}
|
|
|
199
199
|
${options.compute}
|
|
200
200
|
`;
|
|
201
201
|
}
|
|
202
|
+
function buildComputeLineMap(generatedCode, userComputeSource) {
|
|
203
|
+
const lineCount = generatedCode.split("\n").length;
|
|
204
|
+
const lineMap = new Array(lineCount + 1).fill(null);
|
|
205
|
+
const computeStartIndex = generatedCode.indexOf(userComputeSource);
|
|
206
|
+
if (computeStartIndex === -1) return lineMap;
|
|
207
|
+
const computeStartLine = generatedCode.slice(0, computeStartIndex).split("\n").length;
|
|
208
|
+
const computeLineCount = userComputeSource.split("\n").length;
|
|
209
|
+
for (let line = 0; line < computeLineCount; line += 1) lineMap[computeStartLine + line] = {
|
|
210
|
+
kind: "compute",
|
|
211
|
+
line: line + 1
|
|
212
|
+
};
|
|
213
|
+
return lineMap;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Assembles full compute shader WGSL with source line mapping metadata.
|
|
217
|
+
*/
|
|
218
|
+
function buildComputeShaderSourceWithMap(options) {
|
|
219
|
+
const code = buildComputeShaderSource(options);
|
|
220
|
+
return {
|
|
221
|
+
code,
|
|
222
|
+
lineMap: buildComputeLineMap(code, options.compute)
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Assembles ping-pong compute shader WGSL with source line mapping metadata.
|
|
227
|
+
*/
|
|
228
|
+
function buildPingPongComputeShaderSourceWithMap(options) {
|
|
229
|
+
const code = buildPingPongComputeShaderSource(options);
|
|
230
|
+
return {
|
|
231
|
+
code,
|
|
232
|
+
lineMap: buildComputeLineMap(code, options.compute)
|
|
233
|
+
};
|
|
234
|
+
}
|
|
202
235
|
//#endregion
|
|
203
|
-
export { COMPUTE_ENTRY_CONTRACT, assertComputeContract, buildComputeShaderSource, buildComputeStorageBufferBindings, buildComputeStorageTextureBindings, buildPingPongComputeShaderSource, extractWorkgroupSize, storageTextureSampleScalarType };
|
|
236
|
+
export { COMPUTE_ENTRY_CONTRACT, assertComputeContract, buildComputeShaderSource, buildComputeShaderSourceWithMap, buildComputeStorageBufferBindings, buildComputeStorageTextureBindings, buildPingPongComputeShaderSource, buildPingPongComputeShaderSourceWithMap, extractWorkgroupSize, storageTextureSampleScalarType };
|
|
204
237
|
|
|
205
238
|
//# sourceMappingURL=compute-shader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compute-shader.js","names":[],"sources":["../../src/lib/core/compute-shader.ts"],"sourcesContent":["import type { StorageBufferAccess, StorageBufferType, UniformLayout } from './types.js';\n\n/**\n * Regex contract for compute entrypoint.\n * Matches: @compute @workgroup_size(...) fn compute(\n * with @builtin(global_invocation_id) parameter.\n */\nexport const COMPUTE_ENTRY_CONTRACT = /@compute\\s+@workgroup_size\\s*\\([^)]+\\)\\s*fn\\s+compute\\s*\\(/;\n\n/**\n * Regex to extract @workgroup_size values.\n */\nconst WORKGROUP_SIZE_PATTERN =\n\t/@workgroup_size\\s*\\(\\s*(\\d+)(?:\\s*,\\s*(\\d+))?(?:\\s*,\\s*(\\d+))?\\s*\\)/;\n\n/**\n * Regex to verify @builtin(global_invocation_id) parameter.\n */\nconst GLOBAL_INVOCATION_ID_PATTERN = /@builtin\\s*\\(\\s*global_invocation_id\\s*\\)/;\nconst WORKGROUP_DIMENSION_MIN = 1;\nconst WORKGROUP_DIMENSION_MAX = 65535;\n\nfunction extractComputeParamList(compute: string): string | null {\n\tconst computeFnIndex = compute.indexOf('fn compute');\n\tif (computeFnIndex === -1) {\n\t\treturn null;\n\t}\n\n\tconst openParenIndex = compute.indexOf('(', computeFnIndex);\n\tif (openParenIndex === -1) {\n\t\treturn null;\n\t}\n\n\tlet depth = 0;\n\tfor (let index = openParenIndex; index < compute.length; index += 1) {\n\t\tconst char = compute[index];\n\t\tif (char === '(') {\n\t\t\tdepth += 1;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === ')') {\n\t\t\tdepth -= 1;\n\t\t\tif (depth === 0) {\n\t\t\t\treturn compute.slice(openParenIndex + 1, index);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn null;\n}\n\nfunction assertWorkgroupDimension(value: number): void {\n\tif (\n\t\t!Number.isFinite(value) ||\n\t\t!Number.isInteger(value) ||\n\t\tvalue < WORKGROUP_DIMENSION_MIN ||\n\t\tvalue > WORKGROUP_DIMENSION_MAX\n\t) {\n\t\tthrow new Error(\n\t\t\t`@workgroup_size dimensions must be integers in range ${WORKGROUP_DIMENSION_MIN}-${WORKGROUP_DIMENSION_MAX}, got ${value}.`\n\t\t);\n\t}\n}\n\n/**\n * Default uniform field used when no custom uniforms are provided in compute.\n */\nconst DEFAULT_UNIFORM_FIELD = 'motiongpu_unused: vec4f,';\n\n/**\n * Validates compute shader user code matches the compute contract.\n *\n * @param compute - User compute shader WGSL source.\n * @throws {Error} When shader does not match the compute contract.\n */\nexport function assertComputeContract(compute: string): void {\n\tif (!COMPUTE_ENTRY_CONTRACT.test(compute)) {\n\t\tthrow new Error(\n\t\t\t'Compute shader must declare `@compute @workgroup_size(...) fn compute(...)`. ' +\n\t\t\t\t'Ensure the function is named `compute` and includes @compute and @workgroup_size annotations.'\n\t\t);\n\t}\n\n\tconst params = extractComputeParamList(compute);\n\tif (!params || !GLOBAL_INVOCATION_ID_PATTERN.test(params)) {\n\t\tthrow new Error('Compute shader must include a `@builtin(global_invocation_id)` parameter.');\n\t}\n\n\textractWorkgroupSize(compute);\n}\n\n/**\n * Extracts @workgroup_size values from WGSL compute shader.\n *\n * @param compute - Validated compute shader source.\n * @returns Tuple [x, y, z] with defaults of 1 for omitted dimensions.\n */\nexport function extractWorkgroupSize(compute: string): [number, number, number] {\n\tconst match = compute.match(WORKGROUP_SIZE_PATTERN);\n\tif (!match) {\n\t\tthrow new Error('Could not extract @workgroup_size from compute shader source.');\n\t}\n\n\tconst x = Number.parseInt(match[1] ?? '1', 10);\n\tconst y = Number.parseInt(match[2] ?? '1', 10);\n\tconst z = Number.parseInt(match[3] ?? '1', 10);\n\tassertWorkgroupDimension(x);\n\tassertWorkgroupDimension(y);\n\tassertWorkgroupDimension(z);\n\n\treturn [x, y, z];\n}\n\n/**\n * Maps StorageBufferAccess to WGSL var qualifier.\n */\nfunction toWgslAccessMode(access: StorageBufferAccess): string {\n\tswitch (access) {\n\t\tcase 'read':\n\t\t\treturn 'read';\n\t\tcase 'read-write':\n\t\t\treturn 'read_write';\n\t\tdefault:\n\t\t\tthrow new Error(`Unsupported storage buffer access mode \"${String(access)}\".`);\n\t}\n}\n\n/**\n * Builds WGSL struct fields for uniforms used in compute shader preamble.\n */\nfunction buildUniformStructForCompute(layout: UniformLayout): string {\n\tif (layout.entries.length === 0) {\n\t\treturn DEFAULT_UNIFORM_FIELD;\n\t}\n\n\treturn layout.entries.map((entry) => `${entry.name}: ${entry.type},`).join('\\n\\t');\n}\n\n/**\n * Builds storage buffer binding declarations for compute shader.\n *\n * @param storageBufferKeys - Sorted buffer keys.\n * @param definitions - Type/access definitions per key.\n * @param groupIndex - Bind group index for storage buffers.\n * @returns WGSL binding declaration string.\n */\nexport function buildComputeStorageBufferBindings(\n\tstorageBufferKeys: string[],\n\tdefinitions: Record<string, { type: StorageBufferType; access: StorageBufferAccess }>,\n\tgroupIndex: number\n): string {\n\tif (storageBufferKeys.length === 0) {\n\t\treturn '';\n\t}\n\n\tconst declarations: string[] = [];\n\n\tfor (let index = 0; index < storageBufferKeys.length; index += 1) {\n\t\tconst key = storageBufferKeys[index];\n\t\tif (key === undefined) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst definition = definitions[key];\n\t\tif (!definition) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst accessMode = toWgslAccessMode(definition.access);\n\t\tdeclarations.push(\n\t\t\t`@group(${groupIndex}) @binding(${index}) var<storage, ${accessMode}> ${key}: ${definition.type};`\n\t\t);\n\t}\n\n\treturn declarations.join('\\n');\n}\n\n/**\n * Builds storage texture binding declarations for compute shader.\n *\n * @param storageTextureKeys - Sorted storage texture keys.\n * @param definitions - Format definitions per key.\n * @param groupIndex - Bind group index for storage textures.\n * @returns WGSL binding declaration string.\n */\nexport function buildComputeStorageTextureBindings(\n\tstorageTextureKeys: string[],\n\tdefinitions: Record<string, { format: GPUTextureFormat }>,\n\tgroupIndex: number\n): string {\n\tif (storageTextureKeys.length === 0) {\n\t\treturn '';\n\t}\n\n\tconst declarations: string[] = [];\n\n\tfor (let index = 0; index < storageTextureKeys.length; index += 1) {\n\t\tconst key = storageTextureKeys[index];\n\t\tif (key === undefined) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst definition = definitions[key];\n\t\tif (!definition) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tdeclarations.push(\n\t\t\t`@group(${groupIndex}) @binding(${index}) var ${key}: texture_storage_2d<${definition.format}, write>;`\n\t\t);\n\t}\n\n\treturn declarations.join('\\n');\n}\n\n/**\n * Maps storage texture format to sampled texture scalar type for `texture_2d<T>`.\n */\nexport function storageTextureSampleScalarType(format: GPUTextureFormat): 'f32' | 'u32' | 'i32' {\n\tconst normalized = String(format).toLowerCase();\n\tif (normalized.endsWith('uint')) {\n\t\treturn 'u32';\n\t}\n\tif (normalized.endsWith('sint')) {\n\t\treturn 'i32';\n\t}\n\treturn 'f32';\n}\n\n/**\n * Assembles compute shader WGSL for ping-pong workflows.\n *\n * Exposes two generated bindings under group(2):\n * - `${target}A`: sampled read texture (`texture_2d<T>`)\n * - `${target}B`: storage write texture (`texture_storage_2d<format, write>`)\n */\nexport function buildPingPongComputeShaderSource(options: {\n\tcompute: string;\n\tuniformLayout: UniformLayout;\n\tstorageBufferKeys: string[];\n\tstorageBufferDefinitions: Record<\n\t\tstring,\n\t\t{ type: StorageBufferType; access: StorageBufferAccess }\n\t>;\n\ttarget: string;\n\ttargetFormat: GPUTextureFormat;\n}): string {\n\tconst uniformFields = buildUniformStructForCompute(options.uniformLayout);\n\tconst storageBufferBindings = buildComputeStorageBufferBindings(\n\t\toptions.storageBufferKeys,\n\t\toptions.storageBufferDefinitions,\n\t\t1\n\t);\n\tconst sampledType = storageTextureSampleScalarType(options.targetFormat);\n\tconst pingPongTextureBindings = [\n\t\t`@group(2) @binding(0) var ${options.target}A: texture_2d<${sampledType}>;`,\n\t\t`@group(2) @binding(1) var ${options.target}B: texture_storage_2d<${options.targetFormat}, write>;`\n\t].join('\\n');\n\n\treturn `struct MotionGPUFrame {\n\ttime: f32,\n\tdelta: f32,\n\tresolution: vec2f,\n};\n\nstruct MotionGPUUniforms {\n\t${uniformFields}\n};\n\n@group(0) @binding(0) var<uniform> motiongpuFrame: MotionGPUFrame;\n@group(0) @binding(1) var<uniform> motiongpuUniforms: MotionGPUUniforms;\n${storageBufferBindings ? '\\n' + storageBufferBindings : ''}\n${pingPongTextureBindings ? '\\n' + pingPongTextureBindings : ''}\n\n${options.compute}\n`;\n}\n\n/**\n * Assembles full compute shader WGSL with preamble.\n *\n * @param options - Compute shader build options.\n * @returns Complete WGSL source for compute stage.\n */\nexport function buildComputeShaderSource(options: {\n\tcompute: string;\n\tuniformLayout: UniformLayout;\n\tstorageBufferKeys: string[];\n\tstorageBufferDefinitions: Record<\n\t\tstring,\n\t\t{ type: StorageBufferType; access: StorageBufferAccess }\n\t>;\n\tstorageTextureKeys: string[];\n\tstorageTextureDefinitions: Record<string, { format: GPUTextureFormat }>;\n}): string {\n\tconst uniformFields = buildUniformStructForCompute(options.uniformLayout);\n\tconst storageBufferBindings = buildComputeStorageBufferBindings(\n\t\toptions.storageBufferKeys,\n\t\toptions.storageBufferDefinitions,\n\t\t1\n\t);\n\tconst storageTextureBindings = buildComputeStorageTextureBindings(\n\t\toptions.storageTextureKeys,\n\t\toptions.storageTextureDefinitions,\n\t\t2\n\t);\n\n\treturn `struct MotionGPUFrame {\n\ttime: f32,\n\tdelta: f32,\n\tresolution: vec2f,\n};\n\nstruct MotionGPUUniforms {\n\t${uniformFields}\n};\n\n@group(0) @binding(0) var<uniform> motiongpuFrame: MotionGPUFrame;\n@group(0) @binding(1) var<uniform> motiongpuUniforms: MotionGPUUniforms;\n${storageBufferBindings ? '\\n' + storageBufferBindings : ''}\n${storageTextureBindings ? '\\n' + storageTextureBindings : ''}\n\n${options.compute}\n`;\n}\n"],"mappings":";;;;;;AAOA,IAAa,yBAAyB;;;;AAKtC,IAAM,yBACL;;;;AAKD,IAAM,+BAA+B;AACrC,IAAM,0BAA0B;AAChC,IAAM,0BAA0B;AAEhC,SAAS,wBAAwB,SAAgC;CAChE,MAAM,iBAAiB,QAAQ,QAAQ,aAAa;AACpD,KAAI,mBAAmB,GACtB,QAAO;CAGR,MAAM,iBAAiB,QAAQ,QAAQ,KAAK,eAAe;AAC3D,KAAI,mBAAmB,GACtB,QAAO;CAGR,IAAI,QAAQ;AACZ,MAAK,IAAI,QAAQ,gBAAgB,QAAQ,QAAQ,QAAQ,SAAS,GAAG;EACpE,MAAM,OAAO,QAAQ;AACrB,MAAI,SAAS,KAAK;AACjB,YAAS;AACT;;AAGD,MAAI,SAAS,KAAK;AACjB,YAAS;AACT,OAAI,UAAU,EACb,QAAO,QAAQ,MAAM,iBAAiB,GAAG,MAAM;;;AAKlD,QAAO;;AAGR,SAAS,yBAAyB,OAAqB;AACtD,KACC,CAAC,OAAO,SAAS,MAAM,IACvB,CAAC,OAAO,UAAU,MAAM,IACxB,QAAQ,2BACR,QAAQ,wBAER,OAAM,IAAI,MACT,wDAAwD,wBAAwB,GAAG,wBAAwB,QAAQ,MAAM,GACzH;;;;;AAOH,IAAM,wBAAwB;;;;;;;AAQ9B,SAAgB,sBAAsB,SAAuB;AAC5D,KAAI,CAAC,uBAAuB,KAAK,QAAQ,CACxC,OAAM,IAAI,MACT,6KAEA;CAGF,MAAM,SAAS,wBAAwB,QAAQ;AAC/C,KAAI,CAAC,UAAU,CA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,EACA;AAED,QAAO;;;;;;;GAOL,cAAc;;;;;EAKf,wBAAwB,OAAO,wBAAwB,GAAG;EAC1D,yBAAyB,OAAO,yBAAyB,GAAG;;EAE5D,QAAQ,QAAQ"}
|
|
1
|
+
{"version":3,"file":"compute-shader.js","names":[],"sources":["../../src/lib/core/compute-shader.ts"],"sourcesContent":["import type { StorageBufferAccess, StorageBufferType, UniformLayout } from './types.js';\n\n/**\n * Regex contract for compute entrypoint.\n * Matches: @compute @workgroup_size(...) fn compute(\n * with @builtin(global_invocation_id) parameter.\n */\nexport const COMPUTE_ENTRY_CONTRACT = /@compute\\s+@workgroup_size\\s*\\([^)]+\\)\\s*fn\\s+compute\\s*\\(/;\n\n/**\n * Regex to extract @workgroup_size values.\n */\nconst WORKGROUP_SIZE_PATTERN =\n\t/@workgroup_size\\s*\\(\\s*(\\d+)(?:\\s*,\\s*(\\d+))?(?:\\s*,\\s*(\\d+))?\\s*\\)/;\n\n/**\n * Regex to verify @builtin(global_invocation_id) parameter.\n */\nconst GLOBAL_INVOCATION_ID_PATTERN = /@builtin\\s*\\(\\s*global_invocation_id\\s*\\)/;\nconst WORKGROUP_DIMENSION_MIN = 1;\nconst WORKGROUP_DIMENSION_MAX = 65535;\n\nfunction extractComputeParamList(compute: string): string | null {\n\tconst computeFnIndex = compute.indexOf('fn compute');\n\tif (computeFnIndex === -1) {\n\t\treturn null;\n\t}\n\n\tconst openParenIndex = compute.indexOf('(', computeFnIndex);\n\tif (openParenIndex === -1) {\n\t\treturn null;\n\t}\n\n\tlet depth = 0;\n\tfor (let index = openParenIndex; index < compute.length; index += 1) {\n\t\tconst char = compute[index];\n\t\tif (char === '(') {\n\t\t\tdepth += 1;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === ')') {\n\t\t\tdepth -= 1;\n\t\t\tif (depth === 0) {\n\t\t\t\treturn compute.slice(openParenIndex + 1, index);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn null;\n}\n\nfunction assertWorkgroupDimension(value: number): void {\n\tif (\n\t\t!Number.isFinite(value) ||\n\t\t!Number.isInteger(value) ||\n\t\tvalue < WORKGROUP_DIMENSION_MIN ||\n\t\tvalue > WORKGROUP_DIMENSION_MAX\n\t) {\n\t\tthrow new Error(\n\t\t\t`@workgroup_size dimensions must be integers in range ${WORKGROUP_DIMENSION_MIN}-${WORKGROUP_DIMENSION_MAX}, got ${value}.`\n\t\t);\n\t}\n}\n\n/**\n * Default uniform field used when no custom uniforms are provided in compute.\n */\nconst DEFAULT_UNIFORM_FIELD = 'motiongpu_unused: vec4f,';\n\n/**\n * Validates compute shader user code matches the compute contract.\n *\n * @param compute - User compute shader WGSL source.\n * @throws {Error} When shader does not match the compute contract.\n */\nexport function assertComputeContract(compute: string): void {\n\tif (!COMPUTE_ENTRY_CONTRACT.test(compute)) {\n\t\tthrow new Error(\n\t\t\t'Compute shader must declare `@compute @workgroup_size(...) fn compute(...)`. ' +\n\t\t\t\t'Ensure the function is named `compute` and includes @compute and @workgroup_size annotations.'\n\t\t);\n\t}\n\n\tconst params = extractComputeParamList(compute);\n\tif (!params || !GLOBAL_INVOCATION_ID_PATTERN.test(params)) {\n\t\tthrow new Error('Compute shader must include a `@builtin(global_invocation_id)` parameter.');\n\t}\n\n\textractWorkgroupSize(compute);\n}\n\n/**\n * Extracts @workgroup_size values from WGSL compute shader.\n *\n * @param compute - Validated compute shader source.\n * @returns Tuple [x, y, z] with defaults of 1 for omitted dimensions.\n */\nexport function extractWorkgroupSize(compute: string): [number, number, number] {\n\tconst match = compute.match(WORKGROUP_SIZE_PATTERN);\n\tif (!match) {\n\t\tthrow new Error('Could not extract @workgroup_size from compute shader source.');\n\t}\n\n\tconst x = Number.parseInt(match[1] ?? '1', 10);\n\tconst y = Number.parseInt(match[2] ?? '1', 10);\n\tconst z = Number.parseInt(match[3] ?? '1', 10);\n\tassertWorkgroupDimension(x);\n\tassertWorkgroupDimension(y);\n\tassertWorkgroupDimension(z);\n\n\treturn [x, y, z];\n}\n\n/**\n * Maps StorageBufferAccess to WGSL var qualifier.\n */\nfunction toWgslAccessMode(access: StorageBufferAccess): string {\n\tswitch (access) {\n\t\tcase 'read':\n\t\t\treturn 'read';\n\t\tcase 'read-write':\n\t\t\treturn 'read_write';\n\t\tdefault:\n\t\t\tthrow new Error(`Unsupported storage buffer access mode \"${String(access)}\".`);\n\t}\n}\n\n/**\n * Builds WGSL struct fields for uniforms used in compute shader preamble.\n */\nfunction buildUniformStructForCompute(layout: UniformLayout): string {\n\tif (layout.entries.length === 0) {\n\t\treturn DEFAULT_UNIFORM_FIELD;\n\t}\n\n\treturn layout.entries.map((entry) => `${entry.name}: ${entry.type},`).join('\\n\\t');\n}\n\n/**\n * Builds storage buffer binding declarations for compute shader.\n *\n * @param storageBufferKeys - Sorted buffer keys.\n * @param definitions - Type/access definitions per key.\n * @param groupIndex - Bind group index for storage buffers.\n * @returns WGSL binding declaration string.\n */\nexport function buildComputeStorageBufferBindings(\n\tstorageBufferKeys: string[],\n\tdefinitions: Record<string, { type: StorageBufferType; access: StorageBufferAccess }>,\n\tgroupIndex: number\n): string {\n\tif (storageBufferKeys.length === 0) {\n\t\treturn '';\n\t}\n\n\tconst declarations: string[] = [];\n\n\tfor (let index = 0; index < storageBufferKeys.length; index += 1) {\n\t\tconst key = storageBufferKeys[index];\n\t\tif (key === undefined) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst definition = definitions[key];\n\t\tif (!definition) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst accessMode = toWgslAccessMode(definition.access);\n\t\tdeclarations.push(\n\t\t\t`@group(${groupIndex}) @binding(${index}) var<storage, ${accessMode}> ${key}: ${definition.type};`\n\t\t);\n\t}\n\n\treturn declarations.join('\\n');\n}\n\n/**\n * Builds storage texture binding declarations for compute shader.\n *\n * @param storageTextureKeys - Sorted storage texture keys.\n * @param definitions - Format definitions per key.\n * @param groupIndex - Bind group index for storage textures.\n * @returns WGSL binding declaration string.\n */\nexport function buildComputeStorageTextureBindings(\n\tstorageTextureKeys: string[],\n\tdefinitions: Record<string, { format: GPUTextureFormat }>,\n\tgroupIndex: number\n): string {\n\tif (storageTextureKeys.length === 0) {\n\t\treturn '';\n\t}\n\n\tconst declarations: string[] = [];\n\n\tfor (let index = 0; index < storageTextureKeys.length; index += 1) {\n\t\tconst key = storageTextureKeys[index];\n\t\tif (key === undefined) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst definition = definitions[key];\n\t\tif (!definition) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tdeclarations.push(\n\t\t\t`@group(${groupIndex}) @binding(${index}) var ${key}: texture_storage_2d<${definition.format}, write>;`\n\t\t);\n\t}\n\n\treturn declarations.join('\\n');\n}\n\n/**\n * Maps storage texture format to sampled texture scalar type for `texture_2d<T>`.\n */\nexport function storageTextureSampleScalarType(format: GPUTextureFormat): 'f32' | 'u32' | 'i32' {\n\tconst normalized = String(format).toLowerCase();\n\tif (normalized.endsWith('uint')) {\n\t\treturn 'u32';\n\t}\n\tif (normalized.endsWith('sint')) {\n\t\treturn 'i32';\n\t}\n\treturn 'f32';\n}\n\n/**\n * Assembles compute shader WGSL for ping-pong workflows.\n *\n * Exposes two generated bindings under group(2):\n * - `${target}A`: sampled read texture (`texture_2d<T>`)\n * - `${target}B`: storage write texture (`texture_storage_2d<format, write>`)\n */\nexport function buildPingPongComputeShaderSource(options: {\n\tcompute: string;\n\tuniformLayout: UniformLayout;\n\tstorageBufferKeys: string[];\n\tstorageBufferDefinitions: Record<\n\t\tstring,\n\t\t{ type: StorageBufferType; access: StorageBufferAccess }\n\t>;\n\ttarget: string;\n\ttargetFormat: GPUTextureFormat;\n}): string {\n\tconst uniformFields = buildUniformStructForCompute(options.uniformLayout);\n\tconst storageBufferBindings = buildComputeStorageBufferBindings(\n\t\toptions.storageBufferKeys,\n\t\toptions.storageBufferDefinitions,\n\t\t1\n\t);\n\tconst sampledType = storageTextureSampleScalarType(options.targetFormat);\n\tconst pingPongTextureBindings = [\n\t\t`@group(2) @binding(0) var ${options.target}A: texture_2d<${sampledType}>;`,\n\t\t`@group(2) @binding(1) var ${options.target}B: texture_storage_2d<${options.targetFormat}, write>;`\n\t].join('\\n');\n\n\treturn `struct MotionGPUFrame {\n\ttime: f32,\n\tdelta: f32,\n\tresolution: vec2f,\n};\n\nstruct MotionGPUUniforms {\n\t${uniformFields}\n};\n\n@group(0) @binding(0) var<uniform> motiongpuFrame: MotionGPUFrame;\n@group(0) @binding(1) var<uniform> motiongpuUniforms: MotionGPUUniforms;\n${storageBufferBindings ? '\\n' + storageBufferBindings : ''}\n${pingPongTextureBindings ? '\\n' + pingPongTextureBindings : ''}\n\n${options.compute}\n`;\n}\n\n/**\n * Source location for generated compute shader lines.\n */\nexport interface ComputeShaderSourceLocation {\n\tkind: 'compute';\n\tline: number;\n}\n\n/**\n * 1-based line map from generated compute WGSL to user compute source.\n */\nexport type ComputeShaderLineMap = Array<ComputeShaderSourceLocation | null>;\n\n/**\n * Result of compute shader source generation with line mapping metadata.\n */\nexport interface BuiltComputeShaderSource {\n\tcode: string;\n\tlineMap: ComputeShaderLineMap;\n}\n\n/**\n * Assembles full compute shader WGSL with preamble.\n *\n * @param options - Compute shader build options.\n * @returns Complete WGSL source for compute stage.\n */\nexport function buildComputeShaderSource(options: {\n\tcompute: string;\n\tuniformLayout: UniformLayout;\n\tstorageBufferKeys: string[];\n\tstorageBufferDefinitions: Record<\n\t\tstring,\n\t\t{ type: StorageBufferType; access: StorageBufferAccess }\n\t>;\n\tstorageTextureKeys: string[];\n\tstorageTextureDefinitions: Record<string, { format: GPUTextureFormat }>;\n}): string {\n\tconst uniformFields = buildUniformStructForCompute(options.uniformLayout);\n\tconst storageBufferBindings = buildComputeStorageBufferBindings(\n\t\toptions.storageBufferKeys,\n\t\toptions.storageBufferDefinitions,\n\t\t1\n\t);\n\tconst storageTextureBindings = buildComputeStorageTextureBindings(\n\t\toptions.storageTextureKeys,\n\t\toptions.storageTextureDefinitions,\n\t\t2\n\t);\n\n\treturn `struct MotionGPUFrame {\n\ttime: f32,\n\tdelta: f32,\n\tresolution: vec2f,\n};\n\nstruct MotionGPUUniforms {\n\t${uniformFields}\n};\n\n@group(0) @binding(0) var<uniform> motiongpuFrame: MotionGPUFrame;\n@group(0) @binding(1) var<uniform> motiongpuUniforms: MotionGPUUniforms;\n${storageBufferBindings ? '\\n' + storageBufferBindings : ''}\n${storageTextureBindings ? '\\n' + storageTextureBindings : ''}\n\n${options.compute}\n`;\n}\n\nfunction buildComputeLineMap(\n\tgeneratedCode: string,\n\tuserComputeSource: string\n): ComputeShaderLineMap {\n\tconst lineCount = generatedCode.split('\\n').length;\n\tconst lineMap: ComputeShaderLineMap = new Array(lineCount + 1).fill(null);\n\tconst computeStartIndex = generatedCode.indexOf(userComputeSource);\n\tif (computeStartIndex === -1) {\n\t\treturn lineMap;\n\t}\n\n\tconst computeStartLine = generatedCode.slice(0, computeStartIndex).split('\\n').length;\n\tconst computeLineCount = userComputeSource.split('\\n').length;\n\tfor (let line = 0; line < computeLineCount; line += 1) {\n\t\tlineMap[computeStartLine + line] = {\n\t\t\tkind: 'compute',\n\t\t\tline: line + 1\n\t\t};\n\t}\n\n\treturn lineMap;\n}\n\n/**\n * Assembles full compute shader WGSL with source line mapping metadata.\n */\nexport function buildComputeShaderSourceWithMap(options: {\n\tcompute: string;\n\tuniformLayout: UniformLayout;\n\tstorageBufferKeys: string[];\n\tstorageBufferDefinitions: Record<\n\t\tstring,\n\t\t{ type: StorageBufferType; access: StorageBufferAccess }\n\t>;\n\tstorageTextureKeys: string[];\n\tstorageTextureDefinitions: Record<string, { format: GPUTextureFormat }>;\n}): BuiltComputeShaderSource {\n\tconst code = buildComputeShaderSource(options);\n\treturn {\n\t\tcode,\n\t\tlineMap: buildComputeLineMap(code, options.compute)\n\t};\n}\n\n/**\n * Assembles ping-pong compute shader WGSL with source line mapping metadata.\n */\nexport function buildPingPongComputeShaderSourceWithMap(options: {\n\tcompute: string;\n\tuniformLayout: UniformLayout;\n\tstorageBufferKeys: string[];\n\tstorageBufferDefinitions: Record<\n\t\tstring,\n\t\t{ type: StorageBufferType; access: StorageBufferAccess }\n\t>;\n\ttarget: string;\n\ttargetFormat: GPUTextureFormat;\n}): BuiltComputeShaderSource {\n\tconst code = buildPingPongComputeShaderSource(options);\n\treturn {\n\t\tcode,\n\t\tlineMap: buildComputeLineMap(code, options.compute)\n\t};\n}\n"],"mappings":";;;;;;AAOA,IAAa,yBAAyB;;;;AAKtC,IAAM,yBACL;;;;AAKD,IAAM,+BAA+B;AACrC,IAAM,0BAA0B;AAChC,IAAM,0BAA0B;AAEhC,SAAS,wBAAwB,SAAgC;CAChE,MAAM,iBAAiB,QAAQ,QAAQ,aAAa;AACpD,KAAI,mBAAmB,GACtB,QAAO;CAGR,MAAM,iBAAiB,QAAQ,QAAQ,KAAK,eAAe;AAC3D,KAAI,mBAAmB,GACtB,QAAO;CAGR,IAAI,QAAQ;AACZ,MAAK,IAAI,QAAQ,gBAAgB,QAAQ,QAAQ,QAAQ,SAAS,GAAG;EACpE,MAAM,OAAO,QAAQ;AACrB,MAAI,SAAS,KAAK;AACjB,YAAS;AACT;;AAGD,MAAI,SAAS,KAAK;AACjB,YAAS;AACT,OAAI,UAAU,EACb,QAAO,QAAQ,MAAM,iBAAiB,GAAG,MAAM;;;AAKlD,QAAO;;AAGR,SAAS,yBAAyB,OAAqB;AACtD,KACC,CAAC,OAAO,SAAS,MAAM,IACvB,CAAC,OAAO,UAAU,MAAM,IACxB,QAAQ,2BACR,QAAQ,wBAER,OAAM,IAAI,MACT,wDAAwD,wBAAwB,GAAG,wBAAwB,QAAQ,MAAM,GACzH;;;;;AAOH,IAAM,wBAAwB;;;;;;;AAQ9B,SAAgB,sBAAsB,SAAuB;AAC5D,KAAI,CAAC,uBAAuB,KAAK,QAAQ,CACxC,OAAM,IAAI,MACT,6KAEA;CAGF,MAAM,SAAS,wBAAwB,QAAQ;AAC/C,KAAI,CAAC,UAAU,CAAC,6BAA6B,KAAK,OAAO,CACxD,OAA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Ac;;;;;EAKf,wBAAwB,OAAO,wBAAwB,GAAG;EAC1D,yBAAyB,OAAO,yBAAyB,GAAG;;EAE5D,QAAQ,QAAQ;;;AAIlB,SAAS,oBACR,eACA,mBACuB;CACvB,MAAM,YAAY,cAAc,MAAM,KAAK,CAAC;CAC5C,MAAM,UAAgC,IAAI,MAAM,YAAY,EAAE,CAAC,KAAK,KAAK;CACzE,MAAM,oBAAoB,cAAc,QAAQ,kBAAkB;AAClE,KAAI,sBAAsB,GACzB,QAAO;CAGR,MAAM,mBAAmB,cAAc,MAAM,GAAG,kBAAkB,CAAC,MAAM,KAAK,CAAC;CAC/E,MAAM,mBAAmB,kBAAkB,MAAM,KAAK,CAAC;AACvD,MAAK,IAAI,OAAO,GAAG,OAAO,kBAAkB,QAAQ,EACnD,SAAQ,mBAAmB,QAAQ;EAClC,MAAM;EACN,MAAM,OAAO;EACb;AAGF,QAAO;;;;;AAMR,SAAgB,gCAAgC,SAUnB;CAC5B,MAAM,OAAO,yBAAyB,QAAQ;AAC9C,QAAO;EACN;EACA,SAAS,oBAAoB,MAAM,QAAQ,QAAQ;EACnD;;;;;AAMF,SAAgB,wCAAwC,SAU3B;CAC5B,MAAM,OAAO,iCAAiC,QAAQ;AACtD,QAAO;EACN;EACA,SAAS,oBAAoB,MAAM,QAAQ,QAAQ;EACnD"}
|
|
@@ -9,6 +9,11 @@ export interface MaterialSourceMetadata {
|
|
|
9
9
|
column?: number;
|
|
10
10
|
functionName?: string;
|
|
11
11
|
}
|
|
12
|
+
export interface ComputeSourceLocation {
|
|
13
|
+
kind: 'compute';
|
|
14
|
+
line: number;
|
|
15
|
+
}
|
|
16
|
+
export type ShaderSourceLocation = MaterialSourceLocation | ComputeSourceLocation;
|
|
12
17
|
/**
|
|
13
18
|
* One WGSL compiler diagnostic enriched with source-location metadata.
|
|
14
19
|
*/
|
|
@@ -17,7 +22,7 @@ export interface ShaderCompilationDiagnostic {
|
|
|
17
22
|
message: string;
|
|
18
23
|
linePos?: number;
|
|
19
24
|
lineLength?: number;
|
|
20
|
-
sourceLocation:
|
|
25
|
+
sourceLocation: ShaderSourceLocation | null;
|
|
21
26
|
}
|
|
22
27
|
/**
|
|
23
28
|
* Runtime context snapshot captured for shader compilation diagnostics.
|
|
@@ -37,8 +42,10 @@ export interface ShaderCompilationRuntimeContext {
|
|
|
37
42
|
*/
|
|
38
43
|
export interface ShaderCompilationDiagnosticsPayload {
|
|
39
44
|
kind: 'shader-compilation';
|
|
45
|
+
shaderStage?: 'fragment' | 'compute';
|
|
40
46
|
diagnostics: ShaderCompilationDiagnostic[];
|
|
41
47
|
fragmentSource: string;
|
|
48
|
+
computeSource?: string;
|
|
42
49
|
includeSources: Record<string, string>;
|
|
43
50
|
defineBlockSource?: string;
|
|
44
51
|
materialSource: MaterialSourceMetadata | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-diagnostics.d.ts","sourceRoot":"","sources":["../../src/lib/core/error-diagnostics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAEvE;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACtC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC3C,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"error-diagnostics.d.ts","sourceRoot":"","sources":["../../src/lib/core/error-diagnostics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,0BA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cAAc,EAAE,sBAAsB,GAAG,IAAI,CAAC;IAC9C,cAAc,CAAC,EAAE,+BAA+B,CAAC;CACjD;AAkHD;;GAEG;AACH,wBAAgB,kCAAkC,CACjD,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,mCAAmC,GAC1C,KAAK,CAGP;AAED;;GAEG;AACH,wBAAgB,+BAA+B,CAC9C,KAAK,EAAE,OAAO,GACZ,mCAAmC,GAAG,IAAI,CAwE5C"}
|
|
@@ -9,12 +9,12 @@ function isMaterialSourceMetadata(value) {
|
|
|
9
9
|
if (record.column !== void 0 && typeof record.column !== "number") return false;
|
|
10
10
|
return true;
|
|
11
11
|
}
|
|
12
|
-
function
|
|
12
|
+
function isShaderSourceLocation(value) {
|
|
13
13
|
if (value === null) return true;
|
|
14
14
|
if (typeof value !== "object") return false;
|
|
15
15
|
const record = value;
|
|
16
16
|
const kind = record.kind;
|
|
17
|
-
if (kind !== "fragment" && kind !== "include" && kind !== "define") return false;
|
|
17
|
+
if (kind !== "fragment" && kind !== "include" && kind !== "define" && kind !== "compute") return false;
|
|
18
18
|
return typeof record.line === "number";
|
|
19
19
|
}
|
|
20
20
|
function isShaderCompilationDiagnostic(value) {
|
|
@@ -24,7 +24,7 @@ function isShaderCompilationDiagnostic(value) {
|
|
|
24
24
|
if (typeof record.message !== "string") return false;
|
|
25
25
|
if (record.linePos !== void 0 && typeof record.linePos !== "number") return false;
|
|
26
26
|
if (record.lineLength !== void 0 && typeof record.lineLength !== "number") return false;
|
|
27
|
-
if (!
|
|
27
|
+
if (!isShaderSourceLocation(record.sourceLocation)) return false;
|
|
28
28
|
return true;
|
|
29
29
|
}
|
|
30
30
|
function isStringArray(value) {
|
|
@@ -60,8 +60,10 @@ function getShaderCompilationDiagnostics(error) {
|
|
|
60
60
|
if (payload === null || typeof payload !== "object") return null;
|
|
61
61
|
const record = payload;
|
|
62
62
|
if (record.kind !== "shader-compilation") return null;
|
|
63
|
+
if (record.shaderStage !== void 0 && record.shaderStage !== "fragment" && record.shaderStage !== "compute") return null;
|
|
63
64
|
if (!Array.isArray(record.diagnostics) || !record.diagnostics.every(isShaderCompilationDiagnostic)) return null;
|
|
64
65
|
if (typeof record.fragmentSource !== "string") return null;
|
|
66
|
+
if (record.computeSource !== void 0 && typeof record.computeSource !== "string") return null;
|
|
65
67
|
if (record.defineBlockSource !== void 0 && typeof record.defineBlockSource !== "string") return null;
|
|
66
68
|
if (record.includeSources === null || typeof record.includeSources !== "object") return null;
|
|
67
69
|
const includeSources = record.includeSources;
|
|
@@ -70,8 +72,10 @@ function getShaderCompilationDiagnostics(error) {
|
|
|
70
72
|
if (record.runtimeContext !== void 0 && !isShaderCompilationRuntimeContext(record.runtimeContext)) return null;
|
|
71
73
|
return {
|
|
72
74
|
kind: "shader-compilation",
|
|
75
|
+
...record.shaderStage !== void 0 ? { shaderStage: record.shaderStage } : {},
|
|
73
76
|
diagnostics: record.diagnostics,
|
|
74
77
|
fragmentSource: record.fragmentSource,
|
|
78
|
+
...record.computeSource !== void 0 ? { computeSource: record.computeSource } : {},
|
|
75
79
|
includeSources,
|
|
76
80
|
...record.defineBlockSource !== void 0 ? { defineBlockSource: record.defineBlockSource } : {},
|
|
77
81
|
materialSource: record.materialSource ?? null,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-diagnostics.js","names":[],"sources":["../../src/lib/core/error-diagnostics.ts"],"sourcesContent":["import type { MaterialSourceLocation } from './material-preprocess.js';\n\n/**\n * Source metadata for material declaration callsite.\n */\nexport interface MaterialSourceMetadata {\n\tcomponent?: string;\n\tfile?: string;\n\tline?: number;\n\tcolumn?: number;\n\tfunctionName?: string;\n}\n\n/**\n * One WGSL compiler diagnostic enriched with source-location metadata.\n */\nexport interface ShaderCompilationDiagnostic {\n\tgeneratedLine: number;\n\tmessage: string;\n\tlinePos?: number;\n\tlineLength?: number;\n\tsourceLocation: MaterialSourceLocation | null;\n}\n\n/**\n * Runtime context snapshot captured for shader compilation diagnostics.\n */\nexport interface ShaderCompilationRuntimeContext {\n\tmaterialSignature?: string;\n\tpassGraph?: {\n\t\tpassCount: number;\n\t\tenabledPassCount: number;\n\t\tinputs: string[];\n\t\toutputs: string[];\n\t};\n\tactiveRenderTargets: string[];\n}\n\n/**\n * Structured payload attached to WGSL compilation errors.\n */\nexport interface ShaderCompilationDiagnosticsPayload {\n\tkind: 'shader-compilation';\n\tdiagnostics: ShaderCompilationDiagnostic[];\n\tfragmentSource: string;\n\tincludeSources: Record<string, string>;\n\tdefineBlockSource?: string;\n\tmaterialSource: MaterialSourceMetadata | null;\n\truntimeContext?: ShaderCompilationRuntimeContext;\n}\n\ntype MotionGPUErrorWithDiagnostics = Error & {\n\tmotiongpuDiagnostics?: unknown;\n};\n\nfunction isMaterialSourceMetadata(value: unknown): value is MaterialSourceMetadata {\n\tif (value === null || typeof value !== 'object') {\n\t\treturn false;\n\t}\n\n\tconst record = value as Record<string, unknown>;\n\tif (record.component !== undefined && typeof record.component !== 'string') {\n\t\treturn false;\n\t}\n\tif (record.file !== undefined && typeof record.file !== 'string') {\n\t\treturn false;\n\t}\n\tif (record.functionName !== undefined && typeof record.functionName !== 'string') {\n\t\treturn false;\n\t}\n\tif (record.line !== undefined && typeof record.line !== 'number') {\n\t\treturn false;\n\t}\n\tif (record.column !== undefined && typeof record.column !== 'number') {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n\nfunction isMaterialSourceLocation(value: unknown): value is MaterialSourceLocation | null {\n\tif (value === null) {\n\t\treturn true;\n\t}\n\n\tif (typeof value !== 'object') {\n\t\treturn false;\n\t}\n\n\tconst record = value as Record<string, unknown>;\n\tconst kind = record.kind;\n\tif (kind !== 'fragment' && kind !== 'include' && kind !== 'define') {\n\t\treturn false;\n\t}\n\n\treturn typeof record.line === 'number';\n}\n\nfunction isShaderCompilationDiagnostic(value: unknown): value is ShaderCompilationDiagnostic {\n\tif (value === null || typeof value !== 'object') {\n\t\treturn false;\n\t}\n\n\tconst record = value as Record<string, unknown>;\n\tif (typeof record.generatedLine !== 'number') {\n\t\treturn false;\n\t}\n\tif (typeof record.message !== 'string') {\n\t\treturn false;\n\t}\n\tif (record.linePos !== undefined && typeof record.linePos !== 'number') {\n\t\treturn false;\n\t}\n\tif (record.lineLength !== undefined && typeof record.lineLength !== 'number') {\n\t\treturn false;\n\t}\n\tif (!isMaterialSourceLocation(record.sourceLocation)) {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n\nfunction isStringArray(value: unknown): value is string[] {\n\treturn Array.isArray(value) && value.every((entry) => typeof entry === 'string');\n}\n\nfunction isShaderCompilationRuntimeContext(\n\tvalue: unknown\n): value is ShaderCompilationRuntimeContext {\n\tif (value === null || typeof value !== 'object') {\n\t\treturn false;\n\t}\n\n\tconst record = value as Record<string, unknown>;\n\tif (record.materialSignature !== undefined && typeof record.materialSignature !== 'string') {\n\t\treturn false;\n\t}\n\tif (!isStringArray(record.activeRenderTargets)) {\n\t\treturn false;\n\t}\n\tconst passGraph = record.passGraph;\n\tif (passGraph === undefined) {\n\t\treturn true;\n\t}\n\tif (passGraph === null || typeof passGraph !== 'object') {\n\t\treturn false;\n\t}\n\n\tconst passGraphRecord = passGraph as Record<string, unknown>;\n\tif (typeof passGraphRecord.passCount !== 'number') {\n\t\treturn false;\n\t}\n\tif (typeof passGraphRecord.enabledPassCount !== 'number') {\n\t\treturn false;\n\t}\n\tif (!isStringArray(passGraphRecord.inputs) || !isStringArray(passGraphRecord.outputs)) {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n\n/**\n * Attaches structured diagnostics payload to an Error.\n */\nexport function attachShaderCompilationDiagnostics(\n\terror: Error,\n\tpayload: ShaderCompilationDiagnosticsPayload\n): Error {\n\t(error as MotionGPUErrorWithDiagnostics).motiongpuDiagnostics = payload;\n\treturn error;\n}\n\n/**\n * Extracts structured diagnostics payload from unknown error value.\n */\nexport function getShaderCompilationDiagnostics(\n\terror: unknown\n): ShaderCompilationDiagnosticsPayload | null {\n\tif (!(error instanceof Error)) {\n\t\treturn null;\n\t}\n\n\tconst payload = (error as MotionGPUErrorWithDiagnostics).motiongpuDiagnostics;\n\tif (payload === null || typeof payload !== 'object') {\n\t\treturn null;\n\t}\n\n\tconst record = payload as Record<string, unknown>;\n\tif (record.kind !== 'shader-compilation') {\n\t\treturn null;\n\t}\n\tif (\n\t\t!Array.isArray(record.diagnostics) ||\n\t\t!record.diagnostics.every(isShaderCompilationDiagnostic)\n\t) {\n\t\treturn null;\n\t}\n\tif (typeof record.fragmentSource !== 'string') {\n\t\treturn null;\n\t}\n\tif (record.defineBlockSource !== undefined && typeof record.defineBlockSource !== 'string') {\n\t\treturn null;\n\t}\n\tif (record.includeSources === null || typeof record.includeSources !== 'object') {\n\t\treturn null;\n\t}\n\tconst includeSources = record.includeSources as Record<string, unknown>;\n\tif (Object.values(includeSources).some((value) => typeof value !== 'string')) {\n\t\treturn null;\n\t}\n\tif (record.materialSource !== null && !isMaterialSourceMetadata(record.materialSource)) {\n\t\treturn null;\n\t}\n\tif (\n\t\trecord.runtimeContext !== undefined &&\n\t\t!isShaderCompilationRuntimeContext(record.runtimeContext)\n\t) {\n\t\treturn null;\n\t}\n\n\treturn {\n\t\tkind: 'shader-compilation',\n\t\tdiagnostics: record.diagnostics as ShaderCompilationDiagnostic[],\n\t\tfragmentSource: record.fragmentSource,\n\t\tincludeSources: includeSources as Record<string, string>,\n\t\t...(record.defineBlockSource !== undefined\n\t\t\t? { defineBlockSource: record.defineBlockSource as string }\n\t\t\t: {}),\n\t\tmaterialSource: (record.materialSource ?? null) as MaterialSourceMetadata | null,\n\t\t...(record.runtimeContext !== undefined\n\t\t\t? { runtimeContext: record.runtimeContext as ShaderCompilationRuntimeContext }\n\t\t\t: {})\n\t};\n}\n"],"mappings":";AAuDA,SAAS,yBAAyB,OAAiD;AAClF,KAAI,UAAU,QAAQ,OAAO,UAAU,SACtC,QAAO;CAGR,MAAM,SAAS;AACf,KAAI,OAAO,cAAc,UAAa,OAAO,OAAO,cAAc,SACjE,QAAO;AAER,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AC5E,EAAE;EACL"}
|
|
1
|
+
{"version":3,"file":"error-diagnostics.js","names":[],"sources":["../../src/lib/core/error-diagnostics.ts"],"sourcesContent":["import type { MaterialSourceLocation } from './material-preprocess.js';\n\n/**\n * Source metadata for material declaration callsite.\n */\nexport interface MaterialSourceMetadata {\n\tcomponent?: string;\n\tfile?: string;\n\tline?: number;\n\tcolumn?: number;\n\tfunctionName?: string;\n}\n\nexport interface ComputeSourceLocation {\n\tkind: 'compute';\n\tline: number;\n}\n\nexport type ShaderSourceLocation = MaterialSourceLocation | ComputeSourceLocation;\n\n/**\n * One WGSL compiler diagnostic enriched with source-location metadata.\n */\nexport interface ShaderCompilationDiagnostic {\n\tgeneratedLine: number;\n\tmessage: string;\n\tlinePos?: number;\n\tlineLength?: number;\n\tsourceLocation: ShaderSourceLocation | null;\n}\n\n/**\n * Runtime context snapshot captured for shader compilation diagnostics.\n */\nexport interface ShaderCompilationRuntimeContext {\n\tmaterialSignature?: string;\n\tpassGraph?: {\n\t\tpassCount: number;\n\t\tenabledPassCount: number;\n\t\tinputs: string[];\n\t\toutputs: string[];\n\t};\n\tactiveRenderTargets: string[];\n}\n\n/**\n * Structured payload attached to WGSL compilation errors.\n */\nexport interface ShaderCompilationDiagnosticsPayload {\n\tkind: 'shader-compilation';\n\tshaderStage?: 'fragment' | 'compute';\n\tdiagnostics: ShaderCompilationDiagnostic[];\n\tfragmentSource: string;\n\tcomputeSource?: string;\n\tincludeSources: Record<string, string>;\n\tdefineBlockSource?: string;\n\tmaterialSource: MaterialSourceMetadata | null;\n\truntimeContext?: ShaderCompilationRuntimeContext;\n}\n\ntype MotionGPUErrorWithDiagnostics = Error & {\n\tmotiongpuDiagnostics?: unknown;\n};\n\nfunction isMaterialSourceMetadata(value: unknown): value is MaterialSourceMetadata {\n\tif (value === null || typeof value !== 'object') {\n\t\treturn false;\n\t}\n\n\tconst record = value as Record<string, unknown>;\n\tif (record.component !== undefined && typeof record.component !== 'string') {\n\t\treturn false;\n\t}\n\tif (record.file !== undefined && typeof record.file !== 'string') {\n\t\treturn false;\n\t}\n\tif (record.functionName !== undefined && typeof record.functionName !== 'string') {\n\t\treturn false;\n\t}\n\tif (record.line !== undefined && typeof record.line !== 'number') {\n\t\treturn false;\n\t}\n\tif (record.column !== undefined && typeof record.column !== 'number') {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n\nfunction isShaderSourceLocation(value: unknown): value is ShaderSourceLocation | null {\n\tif (value === null) {\n\t\treturn true;\n\t}\n\n\tif (typeof value !== 'object') {\n\t\treturn false;\n\t}\n\n\tconst record = value as Record<string, unknown>;\n\tconst kind = record.kind;\n\tif (kind !== 'fragment' && kind !== 'include' && kind !== 'define' && kind !== 'compute') {\n\t\treturn false;\n\t}\n\n\treturn typeof record.line === 'number';\n}\n\nfunction isShaderCompilationDiagnostic(value: unknown): value is ShaderCompilationDiagnostic {\n\tif (value === null || typeof value !== 'object') {\n\t\treturn false;\n\t}\n\n\tconst record = value as Record<string, unknown>;\n\tif (typeof record.generatedLine !== 'number') {\n\t\treturn false;\n\t}\n\tif (typeof record.message !== 'string') {\n\t\treturn false;\n\t}\n\tif (record.linePos !== undefined && typeof record.linePos !== 'number') {\n\t\treturn false;\n\t}\n\tif (record.lineLength !== undefined && typeof record.lineLength !== 'number') {\n\t\treturn false;\n\t}\n\tif (!isShaderSourceLocation(record.sourceLocation)) {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n\nfunction isStringArray(value: unknown): value is string[] {\n\treturn Array.isArray(value) && value.every((entry) => typeof entry === 'string');\n}\n\nfunction isShaderCompilationRuntimeContext(\n\tvalue: unknown\n): value is ShaderCompilationRuntimeContext {\n\tif (value === null || typeof value !== 'object') {\n\t\treturn false;\n\t}\n\n\tconst record = value as Record<string, unknown>;\n\tif (record.materialSignature !== undefined && typeof record.materialSignature !== 'string') {\n\t\treturn false;\n\t}\n\tif (!isStringArray(record.activeRenderTargets)) {\n\t\treturn false;\n\t}\n\tconst passGraph = record.passGraph;\n\tif (passGraph === undefined) {\n\t\treturn true;\n\t}\n\tif (passGraph === null || typeof passGraph !== 'object') {\n\t\treturn false;\n\t}\n\n\tconst passGraphRecord = passGraph as Record<string, unknown>;\n\tif (typeof passGraphRecord.passCount !== 'number') {\n\t\treturn false;\n\t}\n\tif (typeof passGraphRecord.enabledPassCount !== 'number') {\n\t\treturn false;\n\t}\n\tif (!isStringArray(passGraphRecord.inputs) || !isStringArray(passGraphRecord.outputs)) {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n\n/**\n * Attaches structured diagnostics payload to an Error.\n */\nexport function attachShaderCompilationDiagnostics(\n\terror: Error,\n\tpayload: ShaderCompilationDiagnosticsPayload\n): Error {\n\t(error as MotionGPUErrorWithDiagnostics).motiongpuDiagnostics = payload;\n\treturn error;\n}\n\n/**\n * Extracts structured diagnostics payload from unknown error value.\n */\nexport function getShaderCompilationDiagnostics(\n\terror: unknown\n): ShaderCompilationDiagnosticsPayload | null {\n\tif (!(error instanceof Error)) {\n\t\treturn null;\n\t}\n\n\tconst payload = (error as MotionGPUErrorWithDiagnostics).motiongpuDiagnostics;\n\tif (payload === null || typeof payload !== 'object') {\n\t\treturn null;\n\t}\n\n\tconst record = payload as Record<string, unknown>;\n\tif (record.kind !== 'shader-compilation') {\n\t\treturn null;\n\t}\n\tif (\n\t\trecord.shaderStage !== undefined &&\n\t\trecord.shaderStage !== 'fragment' &&\n\t\trecord.shaderStage !== 'compute'\n\t) {\n\t\treturn null;\n\t}\n\tif (\n\t\t!Array.isArray(record.diagnostics) ||\n\t\t!record.diagnostics.every(isShaderCompilationDiagnostic)\n\t) {\n\t\treturn null;\n\t}\n\tif (typeof record.fragmentSource !== 'string') {\n\t\treturn null;\n\t}\n\tif (record.computeSource !== undefined && typeof record.computeSource !== 'string') {\n\t\treturn null;\n\t}\n\tif (record.defineBlockSource !== undefined && typeof record.defineBlockSource !== 'string') {\n\t\treturn null;\n\t}\n\tif (record.includeSources === null || typeof record.includeSources !== 'object') {\n\t\treturn null;\n\t}\n\tconst includeSources = record.includeSources as Record<string, unknown>;\n\tif (Object.values(includeSources).some((value) => typeof value !== 'string')) {\n\t\treturn null;\n\t}\n\tif (record.materialSource !== null && !isMaterialSourceMetadata(record.materialSource)) {\n\t\treturn null;\n\t}\n\tif (\n\t\trecord.runtimeContext !== undefined &&\n\t\t!isShaderCompilationRuntimeContext(record.runtimeContext)\n\t) {\n\t\treturn null;\n\t}\n\n\treturn {\n\t\tkind: 'shader-compilation',\n\t\t...(record.shaderStage !== undefined\n\t\t\t? { shaderStage: record.shaderStage as 'fragment' | 'compute' }\n\t\t\t: {}),\n\t\tdiagnostics: record.diagnostics as ShaderCompilationDiagnostic[],\n\t\tfragmentSource: record.fragmentSource,\n\t\t...(record.computeSource !== undefined\n\t\t\t? { computeSource: record.computeSource as string }\n\t\t\t: {}),\n\t\tincludeSources: includeSources as Record<string, string>,\n\t\t...(record.defineBlockSource !== undefined\n\t\t\t? { defineBlockSource: record.defineBlockSource as string }\n\t\t\t: {}),\n\t\tmaterialSource: (record.materialSource ?? null) as MaterialSourceMetadata | null,\n\t\t...(record.runtimeContext !== undefined\n\t\t\t? { runtimeContext: record.runtimeContext as ShaderCompilationRuntimeContext }\n\t\t\t: {})\n\t};\n}\n"],"mappings":";AAgEA,SAAS,yBAAyB,OAAiD;AAClF,KAAI,UAAU,QAAQ,OAAO,UAAU,SACtC,QAAO;CAGR,MAAM,SAAS;AACf,KAAI,OAAO,cAAc,UAAa,OAAO,OAAO,cAAc,SACjE,QAAO;AAER,KAAI,OAAO,SAAS,UAAa,OAAO,OAAO,SAAS,SACvD,QAAO;AAER,KAAI,OAAO,iBAAiB,UAAa,OAAO,OAAO,iBAAiB,SACvE,QAAO;AAER,KAAI,OAAO,SAAS,UAAa,OAAO,OAAO,SAAS,SACvD,QAAO;AAER,KAAI,OAAO,WAAW,UAAa,OAAO,OAAO,WAAW,SAC3D,QAAO;AAGR,QAAO;;AAGR,SAAS,uBAAuB,OAAsD;AACrF,KAAI,UAAU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GAC5E,EAAE;EACL"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-report.d.ts","sourceRoot":"","sources":["../../src/lib/core/error-report.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,gBAAgB,GAAG,QAAQ,CAAC;AAE9D;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAC3B,oBAAoB,GACpB,4BAA4B,GAC5B,4BAA4B,GAC5B,yBAAyB,GACzB,4BAA4B,GAC5B,oBAAoB,GACpB,yBAAyB,GACzB,qBAAqB,GACrB,0BAA0B,GAC1B,uBAAuB,GACvB,8BAA8B,GAC9B,4BAA4B,GAC5B,sBAAsB,GACtB,gCAAgC,GAChC,uBAAuB,GACvB,wBAAwB,GACxB,4BAA4B,GAC5B,yBAAyB,GACzB,4BAA4B,GAC5B,0BAA0B,GAC1B,yBAAyB,CAAC;AAE7B;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,OAAO,GAAG,OAAO,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,wBAAwB,EAAE,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACrC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,SAAS,CAAC,EAAE;QACX,SAAS,EAAE,MAAM,CAAC;QAClB,gBAAgB,EAAE,MAAM,CAAC;QACzB,MAAM,EAAE,MAAM,EAAE,CAAC;QACjB,OAAO,EAAE,MAAM,EAAE,CAAC;KAClB,CAAC;IACF,mBAAmB,EAAE,MAAM,EAAE,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACpC;;OAEG;IACH,IAAI,EAAE,kBAAkB,CAAC;IACzB;;OAEG;IACH,QAAQ,EAAE,sBAAsB,CAAC;IACjC;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC;IACrB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB;;OAEG;IACH,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,KAAK,EAAE,mBAAmB,CAAC;IAC3B;;OAEG;IACH,MAAM,EAAE,oBAAoB,GAAG,IAAI,CAAC;IACpC;;OAEG;IACH,OAAO,EAAE,qBAAqB,GAAG,IAAI,CAAC;CACtC;
|
|
1
|
+
{"version":3,"file":"error-report.d.ts","sourceRoot":"","sources":["../../src/lib/core/error-report.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,gBAAgB,GAAG,QAAQ,CAAC;AAE9D;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAC3B,oBAAoB,GACpB,4BAA4B,GAC5B,4BAA4B,GAC5B,yBAAyB,GACzB,4BAA4B,GAC5B,oBAAoB,GACpB,yBAAyB,GACzB,qBAAqB,GACrB,0BAA0B,GAC1B,uBAAuB,GACvB,8BAA8B,GAC9B,4BAA4B,GAC5B,sBAAsB,GACtB,gCAAgC,GAChC,uBAAuB,GACvB,wBAAwB,GACxB,4BAA4B,GAC5B,yBAAyB,GACzB,4BAA4B,GAC5B,0BAA0B,GAC1B,yBAAyB,CAAC;AAE7B;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,OAAO,GAAG,OAAO,CAAC;AAEvD;;GAEG;AAC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AACH,wBAAgB,sBAAsB,CACrC,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,mBAAmB,GACxB,oBAAoB,CAoDtB"}
|
|
@@ -55,6 +55,17 @@ function buildSourceFromDiagnostics(error) {
|
|
|
55
55
|
snippet: toSnippet(includeSource, location.line)
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
|
+
if (location.kind === "compute") {
|
|
59
|
+
const computeSource = diagnostics.computeSource ?? diagnostics.fragmentSource;
|
|
60
|
+
const component = "Compute shader";
|
|
61
|
+
return {
|
|
62
|
+
component,
|
|
63
|
+
location: `${component} (${formatShaderSourceLocation(location) ?? `compute line ${location.line}`})`,
|
|
64
|
+
line: location.line,
|
|
65
|
+
...column !== void 0 ? { column } : {},
|
|
66
|
+
snippet: toSnippet(computeSource, location.line)
|
|
67
|
+
};
|
|
68
|
+
}
|
|
58
69
|
const defineName = location.define ?? "unknown";
|
|
59
70
|
const defineLine = Math.max(1, location.line);
|
|
60
71
|
const component = `#define ${defineName}`;
|
|
@@ -241,7 +252,14 @@ function toMotionGPUErrorReport(error, phase) {
|
|
|
241
252
|
const message = shaderDiagnostics && shaderDiagnostics.diagnostics[0] ? formatDiagnosticMessage(shaderDiagnostics.diagnostics[0]) : defaultMessage;
|
|
242
253
|
const details = shaderDiagnostics ? shaderDiagnostics.diagnostics.slice(1).map((entry) => formatDiagnosticMessage(entry)) : defaultDetails;
|
|
243
254
|
const stack = error instanceof Error && error.stack ? splitLines(error.stack).filter((line) => line !== message) : [];
|
|
244
|
-
|
|
255
|
+
let classification = classifyErrorMessage(rawMessage);
|
|
256
|
+
if (shaderDiagnostics?.shaderStage === "compute" && classification.code === "WGSL_COMPILATION_FAILED") classification = {
|
|
257
|
+
code: "COMPUTE_COMPILATION_FAILED",
|
|
258
|
+
severity: "error",
|
|
259
|
+
recoverable: true,
|
|
260
|
+
title: "Compute shader compilation failed",
|
|
261
|
+
hint: "Check WGSL compute shader sources below and verify storage bindings."
|
|
262
|
+
};
|
|
245
263
|
return {
|
|
246
264
|
code: classification.code,
|
|
247
265
|
severity: classification.severity,
|