@motion-core/motion-gpu 0.4.1 → 0.5.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 +99 -0
- package/dist/advanced.d.ts +1 -0
- package/dist/advanced.d.ts.map +1 -0
- package/dist/advanced.js +14 -6
- package/dist/core/advanced.d.ts +1 -0
- package/dist/core/advanced.d.ts.map +1 -0
- package/dist/core/advanced.js +14 -5
- package/dist/core/compute-shader.d.ts +87 -0
- package/dist/core/compute-shader.d.ts.map +1 -0
- package/dist/core/compute-shader.js +205 -0
- package/dist/core/compute-shader.js.map +1 -0
- package/dist/core/current-value.d.ts +1 -0
- package/dist/core/current-value.d.ts.map +1 -0
- package/dist/core/current-value.js +35 -34
- package/dist/core/current-value.js.map +1 -0
- package/dist/core/error-diagnostics.d.ts +1 -0
- package/dist/core/error-diagnostics.d.ts.map +1 -0
- package/dist/core/error-diagnostics.js +70 -137
- package/dist/core/error-diagnostics.js.map +1 -0
- package/dist/core/error-report.d.ts +2 -1
- package/dist/core/error-report.d.ts.map +1 -0
- package/dist/core/error-report.js +247 -233
- package/dist/core/error-report.js.map +1 -0
- package/dist/core/frame-registry.d.ts +1 -0
- package/dist/core/frame-registry.d.ts.map +1 -0
- package/dist/core/frame-registry.js +546 -662
- package/dist/core/frame-registry.js.map +1 -0
- package/dist/core/index.d.ts +6 -2
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +13 -12
- package/dist/core/material-preprocess.d.ts +1 -0
- package/dist/core/material-preprocess.d.ts.map +1 -0
- package/dist/core/material-preprocess.js +131 -152
- package/dist/core/material-preprocess.js.map +1 -0
- package/dist/core/material.d.ts +23 -6
- package/dist/core/material.d.ts.map +1 -0
- package/dist/core/material.js +290 -317
- package/dist/core/material.js.map +1 -0
- package/dist/core/recompile-policy.d.ts +1 -0
- package/dist/core/recompile-policy.d.ts.map +1 -0
- package/dist/core/recompile-policy.js +18 -13
- package/dist/core/recompile-policy.js.map +1 -0
- package/dist/core/render-graph.d.ts +8 -3
- package/dist/core/render-graph.d.ts.map +1 -0
- package/dist/core/render-graph.js +77 -68
- package/dist/core/render-graph.js.map +1 -0
- package/dist/core/render-targets.d.ts +1 -0
- package/dist/core/render-targets.d.ts.map +1 -0
- package/dist/core/render-targets.js +52 -53
- package/dist/core/render-targets.js.map +1 -0
- package/dist/core/renderer.d.ts +1 -0
- package/dist/core/renderer.d.ts.map +1 -0
- package/dist/core/renderer.js +1337 -1081
- package/dist/core/renderer.js.map +1 -0
- package/dist/core/runtime-loop.d.ts +3 -2
- package/dist/core/runtime-loop.d.ts.map +1 -0
- package/dist/core/runtime-loop.js +353 -362
- package/dist/core/runtime-loop.js.map +1 -0
- package/dist/core/scheduler-helpers.d.ts +1 -0
- package/dist/core/scheduler-helpers.d.ts.map +1 -0
- package/dist/core/scheduler-helpers.js +52 -51
- package/dist/core/scheduler-helpers.js.map +1 -0
- package/dist/core/shader.d.ts +10 -1
- package/dist/core/shader.d.ts.map +1 -0
- package/dist/core/shader.js +109 -115
- package/dist/core/shader.js.map +1 -0
- package/dist/core/storage-buffers.d.ts +37 -0
- package/dist/core/storage-buffers.d.ts.map +1 -0
- package/dist/core/storage-buffers.js +95 -0
- package/dist/core/storage-buffers.js.map +1 -0
- package/dist/core/texture-loader.d.ts +1 -0
- package/dist/core/texture-loader.d.ts.map +1 -0
- package/dist/core/texture-loader.js +209 -273
- package/dist/core/texture-loader.js.map +1 -0
- package/dist/core/textures.d.ts +13 -0
- package/dist/core/textures.d.ts.map +1 -0
- package/dist/core/textures.js +111 -116
- package/dist/core/textures.js.map +1 -0
- package/dist/core/types.d.ts +147 -4
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +0 -4
- package/dist/core/uniforms.d.ts +1 -0
- package/dist/core/uniforms.d.ts.map +1 -0
- package/dist/core/uniforms.js +170 -191
- package/dist/core/uniforms.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -6
- package/dist/passes/BlitPass.d.ts +1 -0
- package/dist/passes/BlitPass.d.ts.map +1 -0
- package/dist/passes/BlitPass.js +23 -18
- package/dist/passes/BlitPass.js.map +1 -0
- package/dist/passes/ComputePass.d.ts +83 -0
- package/dist/passes/ComputePass.d.ts.map +1 -0
- package/dist/passes/ComputePass.js +92 -0
- package/dist/passes/ComputePass.js.map +1 -0
- package/dist/passes/CopyPass.d.ts +1 -0
- package/dist/passes/CopyPass.d.ts.map +1 -0
- package/dist/passes/CopyPass.js +58 -52
- package/dist/passes/CopyPass.js.map +1 -0
- package/dist/passes/FullscreenPass.d.ts +1 -0
- package/dist/passes/FullscreenPass.d.ts.map +1 -0
- package/dist/passes/FullscreenPass.js +127 -130
- package/dist/passes/FullscreenPass.js.map +1 -0
- package/dist/passes/PingPongComputePass.d.ts +104 -0
- package/dist/passes/PingPongComputePass.d.ts.map +1 -0
- package/dist/passes/PingPongComputePass.js +132 -0
- package/dist/passes/PingPongComputePass.js.map +1 -0
- package/dist/passes/ShaderPass.d.ts +1 -0
- package/dist/passes/ShaderPass.d.ts.map +1 -0
- package/dist/passes/ShaderPass.js +41 -37
- package/dist/passes/ShaderPass.js.map +1 -0
- package/dist/passes/index.d.ts +3 -0
- package/dist/passes/index.d.ts.map +1 -0
- package/dist/passes/index.js +6 -3
- package/dist/react/FragCanvas.d.ts +3 -2
- package/dist/react/FragCanvas.d.ts.map +1 -0
- package/dist/react/FragCanvas.js +234 -211
- package/dist/react/FragCanvas.js.map +1 -0
- package/dist/react/MotionGPUErrorOverlay.d.ts +1 -0
- package/dist/react/MotionGPUErrorOverlay.d.ts.map +1 -0
- package/dist/react/MotionGPUErrorOverlay.js +200 -14
- package/dist/react/MotionGPUErrorOverlay.js.map +1 -0
- package/dist/react/Portal.d.ts +1 -0
- package/dist/react/Portal.d.ts.map +1 -0
- package/dist/react/Portal.js +18 -21
- package/dist/react/Portal.js.map +1 -0
- package/dist/react/advanced.d.ts +1 -0
- package/dist/react/advanced.d.ts.map +1 -0
- package/dist/react/advanced.js +14 -6
- package/dist/react/frame-context.d.ts +1 -0
- package/dist/react/frame-context.d.ts.map +1 -0
- package/dist/react/frame-context.js +88 -94
- package/dist/react/frame-context.js.map +1 -0
- package/dist/react/index.d.ts +6 -2
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +12 -9
- package/dist/react/motiongpu-context.d.ts +1 -0
- package/dist/react/motiongpu-context.d.ts.map +1 -0
- package/dist/react/motiongpu-context.js +18 -15
- package/dist/react/motiongpu-context.js.map +1 -0
- package/dist/react/use-motiongpu-user-context.d.ts +1 -0
- package/dist/react/use-motiongpu-user-context.d.ts.map +1 -0
- package/dist/react/use-motiongpu-user-context.js +83 -82
- package/dist/react/use-motiongpu-user-context.js.map +1 -0
- package/dist/react/use-texture.d.ts +1 -0
- package/dist/react/use-texture.d.ts.map +1 -0
- package/dist/react/use-texture.js +132 -152
- package/dist/react/use-texture.js.map +1 -0
- package/dist/svelte/FragCanvas.svelte +2 -2
- package/dist/svelte/FragCanvas.svelte.d.ts +3 -2
- package/dist/svelte/FragCanvas.svelte.d.ts.map +1 -0
- package/dist/svelte/MotionGPUErrorOverlay.svelte +137 -7
- package/dist/svelte/MotionGPUErrorOverlay.svelte.d.ts +1 -0
- package/dist/svelte/MotionGPUErrorOverlay.svelte.d.ts.map +1 -0
- package/dist/svelte/Portal.svelte.d.ts +1 -0
- package/dist/svelte/Portal.svelte.d.ts.map +1 -0
- package/dist/svelte/advanced.d.ts +1 -0
- package/dist/svelte/advanced.d.ts.map +1 -0
- package/dist/svelte/advanced.js +13 -6
- package/dist/svelte/frame-context.d.ts +1 -0
- package/dist/svelte/frame-context.d.ts.map +1 -0
- package/dist/svelte/frame-context.js +27 -27
- package/dist/svelte/frame-context.js.map +1 -0
- package/dist/svelte/index.d.ts +6 -2
- package/dist/svelte/index.d.ts.map +1 -0
- package/dist/svelte/index.js +12 -9
- package/dist/svelte/motiongpu-context.d.ts +1 -0
- package/dist/svelte/motiongpu-context.d.ts.map +1 -0
- package/dist/svelte/motiongpu-context.js +24 -21
- package/dist/svelte/motiongpu-context.js.map +1 -0
- package/dist/svelte/use-motiongpu-user-context.d.ts +1 -0
- package/dist/svelte/use-motiongpu-user-context.d.ts.map +1 -0
- package/dist/svelte/use-motiongpu-user-context.js +69 -70
- package/dist/svelte/use-motiongpu-user-context.js.map +1 -0
- package/dist/svelte/use-texture.d.ts +1 -0
- package/dist/svelte/use-texture.d.ts.map +1 -0
- package/dist/svelte/use-texture.js +125 -147
- package/dist/svelte/use-texture.js.map +1 -0
- package/package.json +12 -7
- package/src/lib/advanced.ts +6 -0
- package/src/lib/core/advanced.ts +12 -0
- package/src/lib/core/compute-shader.ts +326 -0
- package/src/lib/core/current-value.ts +64 -0
- package/src/lib/core/error-diagnostics.ts +236 -0
- package/src/lib/core/error-report.ts +535 -0
- package/src/lib/core/frame-registry.ts +1190 -0
- package/src/lib/core/index.ts +94 -0
- package/src/lib/core/material-preprocess.ts +295 -0
- package/src/lib/core/material.ts +748 -0
- package/src/lib/core/recompile-policy.ts +31 -0
- package/src/lib/core/render-graph.ts +173 -0
- package/src/lib/core/render-targets.ts +107 -0
- package/src/lib/core/renderer.ts +2161 -0
- package/src/lib/core/runtime-loop.ts +537 -0
- package/src/lib/core/scheduler-helpers.ts +136 -0
- package/src/lib/core/shader.ts +301 -0
- package/src/lib/core/storage-buffers.ts +142 -0
- package/src/lib/core/texture-loader.ts +482 -0
- package/src/lib/core/textures.ts +257 -0
- package/src/lib/core/types.ts +743 -0
- package/src/lib/core/uniforms.ts +282 -0
- package/src/lib/index.ts +6 -0
- package/src/lib/passes/BlitPass.ts +54 -0
- package/src/lib/passes/ComputePass.ts +136 -0
- package/src/lib/passes/CopyPass.ts +80 -0
- package/src/lib/passes/FullscreenPass.ts +173 -0
- package/src/lib/passes/PingPongComputePass.ts +180 -0
- package/src/lib/passes/ShaderPass.ts +89 -0
- package/src/lib/passes/index.ts +9 -0
- package/src/lib/react/FragCanvas.tsx +345 -0
- package/src/lib/react/MotionGPUErrorOverlay.tsx +524 -0
- package/src/lib/react/Portal.tsx +34 -0
- package/src/lib/react/advanced.ts +36 -0
- package/src/lib/react/frame-context.ts +169 -0
- package/src/lib/react/index.ts +68 -0
- package/src/lib/react/motiongpu-context.ts +88 -0
- package/src/lib/react/use-motiongpu-user-context.ts +186 -0
- package/src/lib/react/use-texture.ts +233 -0
- package/src/lib/svelte/FragCanvas.svelte +249 -0
- package/src/lib/svelte/MotionGPUErrorOverlay.svelte +512 -0
- package/src/lib/svelte/Portal.svelte +31 -0
- package/src/lib/svelte/advanced.ts +32 -0
- package/src/lib/svelte/frame-context.ts +87 -0
- package/src/lib/svelte/index.ts +68 -0
- package/src/lib/svelte/motiongpu-context.ts +97 -0
- package/src/lib/svelte/use-motiongpu-user-context.ts +145 -0
- package/src/lib/svelte/use-texture.ts +232 -0
|
@@ -0,0 +1,535 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getShaderCompilationDiagnostics,
|
|
3
|
+
type ShaderCompilationDiagnostic
|
|
4
|
+
} from './error-diagnostics.js';
|
|
5
|
+
import { formatShaderSourceLocation } from './shader.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Runtime phase in which an error occurred.
|
|
9
|
+
*/
|
|
10
|
+
export type MotionGPUErrorPhase = 'initialization' | 'render';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Stable machine-readable error category code.
|
|
14
|
+
*/
|
|
15
|
+
export type MotionGPUErrorCode =
|
|
16
|
+
| 'WEBGPU_UNAVAILABLE'
|
|
17
|
+
| 'WEBGPU_ADAPTER_UNAVAILABLE'
|
|
18
|
+
| 'WEBGPU_CONTEXT_UNAVAILABLE'
|
|
19
|
+
| 'WGSL_COMPILATION_FAILED'
|
|
20
|
+
| 'MATERIAL_PREPROCESS_FAILED'
|
|
21
|
+
| 'WEBGPU_DEVICE_LOST'
|
|
22
|
+
| 'WEBGPU_UNCAPTURED_ERROR'
|
|
23
|
+
| 'BIND_GROUP_MISMATCH'
|
|
24
|
+
| 'RUNTIME_RESOURCE_MISSING'
|
|
25
|
+
| 'UNIFORM_VALUE_INVALID'
|
|
26
|
+
| 'STORAGE_BUFFER_OUT_OF_BOUNDS'
|
|
27
|
+
| 'STORAGE_BUFFER_READ_FAILED'
|
|
28
|
+
| 'RENDER_GRAPH_INVALID'
|
|
29
|
+
| 'PINGPONG_CONFIGURATION_INVALID'
|
|
30
|
+
| 'TEXTURE_USAGE_INVALID'
|
|
31
|
+
| 'TEXTURE_REQUEST_FAILED'
|
|
32
|
+
| 'TEXTURE_DECODE_UNAVAILABLE'
|
|
33
|
+
| 'TEXTURE_REQUEST_ABORTED'
|
|
34
|
+
| 'COMPUTE_COMPILATION_FAILED'
|
|
35
|
+
| 'COMPUTE_CONTRACT_INVALID'
|
|
36
|
+
| 'MOTIONGPU_RUNTIME_ERROR';
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Severity level for user-facing diagnostics.
|
|
40
|
+
*/
|
|
41
|
+
export type MotionGPUErrorSeverity = 'error' | 'fatal';
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* One source-code line displayed in diagnostics snippet.
|
|
45
|
+
*/
|
|
46
|
+
export interface MotionGPUErrorSourceLine {
|
|
47
|
+
number: number;
|
|
48
|
+
code: string;
|
|
49
|
+
highlight: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Structured source context displayed for shader compilation errors.
|
|
54
|
+
*/
|
|
55
|
+
export interface MotionGPUErrorSource {
|
|
56
|
+
component: string;
|
|
57
|
+
location: string;
|
|
58
|
+
line: number;
|
|
59
|
+
column?: number;
|
|
60
|
+
snippet: MotionGPUErrorSourceLine[];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Optional runtime context captured with diagnostics payload.
|
|
65
|
+
*/
|
|
66
|
+
export interface MotionGPUErrorContext {
|
|
67
|
+
materialSignature?: string;
|
|
68
|
+
passGraph?: {
|
|
69
|
+
passCount: number;
|
|
70
|
+
enabledPassCount: number;
|
|
71
|
+
inputs: string[];
|
|
72
|
+
outputs: string[];
|
|
73
|
+
};
|
|
74
|
+
activeRenderTargets: string[];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Structured error payload used by UI diagnostics.
|
|
79
|
+
*/
|
|
80
|
+
export interface MotionGPUErrorReport {
|
|
81
|
+
/**
|
|
82
|
+
* Stable machine-readable category code.
|
|
83
|
+
*/
|
|
84
|
+
code: MotionGPUErrorCode;
|
|
85
|
+
/**
|
|
86
|
+
* Severity level used by diagnostics UIs and telemetry.
|
|
87
|
+
*/
|
|
88
|
+
severity: MotionGPUErrorSeverity;
|
|
89
|
+
/**
|
|
90
|
+
* Whether runtime may recover without full renderer re-creation.
|
|
91
|
+
*/
|
|
92
|
+
recoverable: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Short category title.
|
|
95
|
+
*/
|
|
96
|
+
title: string;
|
|
97
|
+
/**
|
|
98
|
+
* Primary human-readable message.
|
|
99
|
+
*/
|
|
100
|
+
message: string;
|
|
101
|
+
/**
|
|
102
|
+
* Suggested remediation hint.
|
|
103
|
+
*/
|
|
104
|
+
hint: string;
|
|
105
|
+
/**
|
|
106
|
+
* Additional parsed details (for example WGSL line errors).
|
|
107
|
+
*/
|
|
108
|
+
details: string[];
|
|
109
|
+
/**
|
|
110
|
+
* Stack trace lines when available.
|
|
111
|
+
*/
|
|
112
|
+
stack: string[];
|
|
113
|
+
/**
|
|
114
|
+
* Original unmodified message.
|
|
115
|
+
*/
|
|
116
|
+
rawMessage: string;
|
|
117
|
+
/**
|
|
118
|
+
* Runtime phase where the error occurred.
|
|
119
|
+
*/
|
|
120
|
+
phase: MotionGPUErrorPhase;
|
|
121
|
+
/**
|
|
122
|
+
* Optional source context for shader-related diagnostics.
|
|
123
|
+
*/
|
|
124
|
+
source: MotionGPUErrorSource | null;
|
|
125
|
+
/**
|
|
126
|
+
* Optional runtime context snapshot (material/pass graph/render targets).
|
|
127
|
+
*/
|
|
128
|
+
context: MotionGPUErrorContext | null;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Splits multi-line values into trimmed non-empty lines.
|
|
133
|
+
*/
|
|
134
|
+
function splitLines(value: string): string[] {
|
|
135
|
+
return value
|
|
136
|
+
.split('\n')
|
|
137
|
+
.map((line) => line.trim())
|
|
138
|
+
.filter((line) => line.length > 0);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function toDisplayName(path: string): string {
|
|
142
|
+
const normalized = path.split(/[?#]/)[0] ?? path;
|
|
143
|
+
const chunks = normalized.split(/[\\/]/);
|
|
144
|
+
const last = chunks[chunks.length - 1];
|
|
145
|
+
return last && last.length > 0 ? last : path;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function toSnippet(source: string, line: number, radius = 3): MotionGPUErrorSourceLine[] {
|
|
149
|
+
const lines = source.replace(/\r\n?/g, '\n').split('\n');
|
|
150
|
+
if (lines.length === 0) {
|
|
151
|
+
return [];
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const targetLine = Math.min(Math.max(1, line), lines.length);
|
|
155
|
+
const start = Math.max(1, targetLine - radius);
|
|
156
|
+
const end = Math.min(lines.length, targetLine + radius);
|
|
157
|
+
const snippet: MotionGPUErrorSourceLine[] = [];
|
|
158
|
+
|
|
159
|
+
for (let index = start; index <= end; index += 1) {
|
|
160
|
+
snippet.push({
|
|
161
|
+
number: index,
|
|
162
|
+
code: lines[index - 1] ?? '',
|
|
163
|
+
highlight: index === targetLine
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return snippet;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function buildSourceFromDiagnostics(error: unknown): MotionGPUErrorSource | null {
|
|
171
|
+
const diagnostics = getShaderCompilationDiagnostics(error);
|
|
172
|
+
if (!diagnostics || diagnostics.diagnostics.length === 0) {
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const primary = diagnostics.diagnostics.find((entry) => entry.sourceLocation !== null);
|
|
177
|
+
if (!primary?.sourceLocation) {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const location = primary.sourceLocation;
|
|
182
|
+
const column = primary.linePos && primary.linePos > 0 ? primary.linePos : undefined;
|
|
183
|
+
|
|
184
|
+
if (location.kind === 'fragment') {
|
|
185
|
+
const component =
|
|
186
|
+
diagnostics.materialSource?.component ??
|
|
187
|
+
(diagnostics.materialSource?.file
|
|
188
|
+
? toDisplayName(diagnostics.materialSource.file)
|
|
189
|
+
: 'User shader fragment');
|
|
190
|
+
const locationLabel = formatShaderSourceLocation(location) ?? `fragment line ${location.line}`;
|
|
191
|
+
return {
|
|
192
|
+
component,
|
|
193
|
+
location: `${component} (${locationLabel})`,
|
|
194
|
+
line: location.line,
|
|
195
|
+
...(column !== undefined ? { column } : {}),
|
|
196
|
+
snippet: toSnippet(diagnostics.fragmentSource, location.line)
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (location.kind === 'include') {
|
|
201
|
+
const includeName = location.include ?? 'unknown';
|
|
202
|
+
const includeSource = diagnostics.includeSources[includeName] ?? '';
|
|
203
|
+
const component = `#include <${includeName}>`;
|
|
204
|
+
const locationLabel = formatShaderSourceLocation(location) ?? `include <${includeName}>`;
|
|
205
|
+
return {
|
|
206
|
+
component,
|
|
207
|
+
location: `${component} (${locationLabel})`,
|
|
208
|
+
line: location.line,
|
|
209
|
+
...(column !== undefined ? { column } : {}),
|
|
210
|
+
snippet: toSnippet(includeSource, location.line)
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const defineName = location.define ?? 'unknown';
|
|
215
|
+
const defineLine = Math.max(1, location.line);
|
|
216
|
+
const component = `#define ${defineName}`;
|
|
217
|
+
const locationLabel =
|
|
218
|
+
formatShaderSourceLocation(location) ?? `define "${defineName}" line ${defineLine}`;
|
|
219
|
+
return {
|
|
220
|
+
component,
|
|
221
|
+
location: `${component} (${locationLabel})`,
|
|
222
|
+
line: defineLine,
|
|
223
|
+
...(column !== undefined ? { column } : {}),
|
|
224
|
+
snippet: toSnippet(diagnostics.defineBlockSource ?? '', defineLine, 2)
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function formatDiagnosticMessage(entry: ShaderCompilationDiagnostic): string {
|
|
229
|
+
const sourceLabel = formatShaderSourceLocation(entry.sourceLocation);
|
|
230
|
+
const generatedLineLabel =
|
|
231
|
+
entry.generatedLine > 0 ? `generated WGSL line ${entry.generatedLine}` : null;
|
|
232
|
+
const labels = [sourceLabel, generatedLineLabel].filter((value) => Boolean(value));
|
|
233
|
+
if (labels.length === 0) {
|
|
234
|
+
return entry.message;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return `[${labels.join(' | ')}] ${entry.message}`;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Maps known WebGPU/WGSL error patterns to a user-facing title and hint.
|
|
242
|
+
*/
|
|
243
|
+
function classifyErrorMessage(
|
|
244
|
+
message: string
|
|
245
|
+
): Pick<MotionGPUErrorReport, 'code' | 'severity' | 'recoverable' | 'title' | 'hint'> {
|
|
246
|
+
if (message.includes('WebGPU is not available in this browser')) {
|
|
247
|
+
return {
|
|
248
|
+
code: 'WEBGPU_UNAVAILABLE',
|
|
249
|
+
severity: 'fatal',
|
|
250
|
+
recoverable: false,
|
|
251
|
+
title: 'WebGPU unavailable',
|
|
252
|
+
hint: 'Use a browser with WebGPU enabled (latest Chrome/Edge/Safari TP) and secure context.'
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (message.includes('Unable to acquire WebGPU adapter')) {
|
|
257
|
+
return {
|
|
258
|
+
code: 'WEBGPU_ADAPTER_UNAVAILABLE',
|
|
259
|
+
severity: 'fatal',
|
|
260
|
+
recoverable: false,
|
|
261
|
+
title: 'WebGPU adapter unavailable',
|
|
262
|
+
hint: 'GPU adapter request failed. Check browser permissions, flags and device support.'
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (message.includes('Canvas does not support webgpu context')) {
|
|
267
|
+
return {
|
|
268
|
+
code: 'WEBGPU_CONTEXT_UNAVAILABLE',
|
|
269
|
+
severity: 'error',
|
|
270
|
+
recoverable: true,
|
|
271
|
+
title: 'Canvas cannot create WebGPU context',
|
|
272
|
+
hint: 'Make sure this canvas is attached to DOM and not using an unsupported context option.'
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if (message.includes('WGSL compilation failed')) {
|
|
277
|
+
return {
|
|
278
|
+
code: 'WGSL_COMPILATION_FAILED',
|
|
279
|
+
severity: 'error',
|
|
280
|
+
recoverable: true,
|
|
281
|
+
title: 'WGSL compilation failed',
|
|
282
|
+
hint: 'Check WGSL line numbers below and verify struct/binding/function signatures.'
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (
|
|
287
|
+
message.includes('Invalid include directive in fragment shader.') ||
|
|
288
|
+
message.includes('Unknown include "') ||
|
|
289
|
+
message.includes('Circular include detected for "') ||
|
|
290
|
+
message.includes('Invalid define value for "') ||
|
|
291
|
+
message.includes('Invalid include "')
|
|
292
|
+
) {
|
|
293
|
+
return {
|
|
294
|
+
code: 'MATERIAL_PREPROCESS_FAILED',
|
|
295
|
+
severity: 'error',
|
|
296
|
+
recoverable: true,
|
|
297
|
+
title: 'Material preprocess failed',
|
|
298
|
+
hint: 'Validate #include keys, define values and include expansion order before retrying.'
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (message.includes('Compute shader compilation failed')) {
|
|
303
|
+
return {
|
|
304
|
+
code: 'COMPUTE_COMPILATION_FAILED',
|
|
305
|
+
severity: 'error',
|
|
306
|
+
recoverable: true,
|
|
307
|
+
title: 'Compute shader compilation failed',
|
|
308
|
+
hint: 'Check WGSL compute shader sources below and verify storage bindings.'
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (
|
|
313
|
+
message.includes(
|
|
314
|
+
'Compute shader must declare `@compute @workgroup_size(...) fn compute(...)`.'
|
|
315
|
+
) ||
|
|
316
|
+
message.includes('Compute shader must include a `@builtin(global_invocation_id)` parameter.') ||
|
|
317
|
+
message.includes('Could not extract @workgroup_size from compute shader source.') ||
|
|
318
|
+
message.includes('@workgroup_size dimensions must be integers in range') ||
|
|
319
|
+
message.includes('Unsupported storage buffer access mode "')
|
|
320
|
+
) {
|
|
321
|
+
return {
|
|
322
|
+
code: 'COMPUTE_CONTRACT_INVALID',
|
|
323
|
+
severity: 'error',
|
|
324
|
+
recoverable: true,
|
|
325
|
+
title: 'Compute contract is invalid',
|
|
326
|
+
hint: 'Ensure compute shader contract (@compute, @workgroup_size, global_invocation_id, storage access) is valid.'
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (message.includes('WebGPU device lost') || message.includes('Device Lost')) {
|
|
331
|
+
return {
|
|
332
|
+
code: 'WEBGPU_DEVICE_LOST',
|
|
333
|
+
severity: 'fatal',
|
|
334
|
+
recoverable: false,
|
|
335
|
+
title: 'WebGPU device lost',
|
|
336
|
+
hint: 'GPU device/context was lost. Recreate the renderer and check OS/GPU stability.'
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
if (message.includes('WebGPU uncaptured error')) {
|
|
341
|
+
return {
|
|
342
|
+
code: 'WEBGPU_UNCAPTURED_ERROR',
|
|
343
|
+
severity: 'error',
|
|
344
|
+
recoverable: true,
|
|
345
|
+
title: 'WebGPU uncaptured error',
|
|
346
|
+
hint: 'A GPU command failed asynchronously. Review details and validate resource/state usage.'
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
if (message.includes('CreateBindGroup') || message.includes('bind group layout')) {
|
|
351
|
+
return {
|
|
352
|
+
code: 'BIND_GROUP_MISMATCH',
|
|
353
|
+
severity: 'error',
|
|
354
|
+
recoverable: true,
|
|
355
|
+
title: 'Bind group mismatch',
|
|
356
|
+
hint: 'Bindings in shader and runtime resources are out of sync. Verify uniforms/textures layout.'
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
if (message.includes('Storage buffer "') && message.includes('write out of bounds:')) {
|
|
361
|
+
return {
|
|
362
|
+
code: 'STORAGE_BUFFER_OUT_OF_BOUNDS',
|
|
363
|
+
severity: 'error',
|
|
364
|
+
recoverable: true,
|
|
365
|
+
title: 'Storage buffer write out of bounds',
|
|
366
|
+
hint: 'Ensure offset + write byte length does not exceed declared storage buffer size.'
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if (
|
|
371
|
+
message.includes('Cannot read storage buffer "') ||
|
|
372
|
+
message.includes('Cannot read storage buffer: GPU device unavailable.') ||
|
|
373
|
+
message.includes('not allocated on GPU.')
|
|
374
|
+
) {
|
|
375
|
+
return {
|
|
376
|
+
code: 'STORAGE_BUFFER_READ_FAILED',
|
|
377
|
+
severity: 'error',
|
|
378
|
+
recoverable: true,
|
|
379
|
+
title: 'Storage buffer read failed',
|
|
380
|
+
hint: 'Readbacks require an initialized renderer, allocated GPU buffer and active device.'
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if (
|
|
385
|
+
message.includes('Unknown uniform "') ||
|
|
386
|
+
message.includes('Unknown uniform type for "') ||
|
|
387
|
+
message.includes('Unknown texture "') ||
|
|
388
|
+
message.includes('Unknown storage buffer "') ||
|
|
389
|
+
message.includes('Missing definition for storage buffer "') ||
|
|
390
|
+
message.includes('Missing texture definition for "') ||
|
|
391
|
+
(message.includes('Storage buffer "') && message.includes('" not allocated.')) ||
|
|
392
|
+
(message.includes('Storage texture "') && message.includes('" not allocated.'))
|
|
393
|
+
) {
|
|
394
|
+
return {
|
|
395
|
+
code: 'RUNTIME_RESOURCE_MISSING',
|
|
396
|
+
severity: 'error',
|
|
397
|
+
recoverable: true,
|
|
398
|
+
title: 'Runtime resource binding failed',
|
|
399
|
+
hint: 'Check material declarations and runtime keys for uniforms, textures and storage resources.'
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
if (message.includes('Uniform ') && message.includes(' value must')) {
|
|
404
|
+
return {
|
|
405
|
+
code: 'UNIFORM_VALUE_INVALID',
|
|
406
|
+
severity: 'error',
|
|
407
|
+
recoverable: true,
|
|
408
|
+
title: 'Uniform value is invalid',
|
|
409
|
+
hint: 'Provide finite values with tuple/matrix sizes matching the uniform type.'
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
if (
|
|
414
|
+
message.includes('Render pass #') ||
|
|
415
|
+
message.includes('Render graph references unknown runtime target')
|
|
416
|
+
) {
|
|
417
|
+
return {
|
|
418
|
+
code: 'RENDER_GRAPH_INVALID',
|
|
419
|
+
severity: 'error',
|
|
420
|
+
recoverable: true,
|
|
421
|
+
title: 'Render graph configuration is invalid',
|
|
422
|
+
hint: 'Verify pass inputs/outputs, declared render targets and execution order.'
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
if (message.includes('PingPongComputePass must provide a target texture key.')) {
|
|
427
|
+
return {
|
|
428
|
+
code: 'PINGPONG_CONFIGURATION_INVALID',
|
|
429
|
+
severity: 'error',
|
|
430
|
+
recoverable: true,
|
|
431
|
+
title: 'Ping-pong compute pass is misconfigured',
|
|
432
|
+
hint: 'Configure a valid target texture key for PingPongComputePass.'
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
if (message.includes('Destination texture needs to have CopyDst')) {
|
|
437
|
+
return {
|
|
438
|
+
code: 'TEXTURE_USAGE_INVALID',
|
|
439
|
+
severity: 'error',
|
|
440
|
+
recoverable: true,
|
|
441
|
+
title: 'Invalid texture usage flags',
|
|
442
|
+
hint: 'Texture used as upload destination must include CopyDst (and often RenderAttachment).'
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
if (message.includes('Texture request failed')) {
|
|
447
|
+
return {
|
|
448
|
+
code: 'TEXTURE_REQUEST_FAILED',
|
|
449
|
+
severity: 'error',
|
|
450
|
+
recoverable: true,
|
|
451
|
+
title: 'Texture request failed',
|
|
452
|
+
hint: 'Verify texture URL, CORS policy and response status before retrying.'
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
if (message.includes('createImageBitmap is not available in this runtime')) {
|
|
457
|
+
return {
|
|
458
|
+
code: 'TEXTURE_DECODE_UNAVAILABLE',
|
|
459
|
+
severity: 'fatal',
|
|
460
|
+
recoverable: false,
|
|
461
|
+
title: 'Texture decode unavailable',
|
|
462
|
+
hint: 'Runtime lacks createImageBitmap support. Use a browser/runtime with image bitmap decoding.'
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
if (message.toLowerCase().includes('texture request was aborted')) {
|
|
467
|
+
return {
|
|
468
|
+
code: 'TEXTURE_REQUEST_ABORTED',
|
|
469
|
+
severity: 'error',
|
|
470
|
+
recoverable: true,
|
|
471
|
+
title: 'Texture request aborted',
|
|
472
|
+
hint: 'Texture load was cancelled. Retry the request when source inputs stabilize.'
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
return {
|
|
477
|
+
code: 'MOTIONGPU_RUNTIME_ERROR',
|
|
478
|
+
severity: 'error',
|
|
479
|
+
recoverable: true,
|
|
480
|
+
title: 'MotionGPU render error',
|
|
481
|
+
hint: 'Review technical details below. If issue persists, isolate shader/uniform/texture changes.'
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Converts unknown errors to a consistent, display-ready error report.
|
|
487
|
+
*
|
|
488
|
+
* @param error - Unknown thrown value.
|
|
489
|
+
* @param phase - Phase during which error occurred.
|
|
490
|
+
* @returns Normalized error report.
|
|
491
|
+
*/
|
|
492
|
+
export function toMotionGPUErrorReport(
|
|
493
|
+
error: unknown,
|
|
494
|
+
phase: MotionGPUErrorPhase
|
|
495
|
+
): MotionGPUErrorReport {
|
|
496
|
+
const shaderDiagnostics = getShaderCompilationDiagnostics(error);
|
|
497
|
+
const rawMessage =
|
|
498
|
+
error instanceof Error
|
|
499
|
+
? error.message
|
|
500
|
+
: typeof error === 'string'
|
|
501
|
+
? error
|
|
502
|
+
: 'Unknown FragCanvas error';
|
|
503
|
+
const rawLines = splitLines(rawMessage);
|
|
504
|
+
const defaultMessage = rawLines[0] ?? rawMessage;
|
|
505
|
+
const defaultDetails = rawLines.slice(1);
|
|
506
|
+
const source = buildSourceFromDiagnostics(error);
|
|
507
|
+
const context = shaderDiagnostics?.runtimeContext ?? null;
|
|
508
|
+
const message =
|
|
509
|
+
shaderDiagnostics && shaderDiagnostics.diagnostics[0]
|
|
510
|
+
? formatDiagnosticMessage(shaderDiagnostics.diagnostics[0])
|
|
511
|
+
: defaultMessage;
|
|
512
|
+
const details = shaderDiagnostics
|
|
513
|
+
? shaderDiagnostics.diagnostics.slice(1).map((entry) => formatDiagnosticMessage(entry))
|
|
514
|
+
: defaultDetails;
|
|
515
|
+
const stack =
|
|
516
|
+
error instanceof Error && error.stack
|
|
517
|
+
? splitLines(error.stack).filter((line) => line !== message)
|
|
518
|
+
: [];
|
|
519
|
+
const classification = classifyErrorMessage(rawMessage);
|
|
520
|
+
|
|
521
|
+
return {
|
|
522
|
+
code: classification.code,
|
|
523
|
+
severity: classification.severity,
|
|
524
|
+
recoverable: classification.recoverable,
|
|
525
|
+
title: classification.title,
|
|
526
|
+
message,
|
|
527
|
+
hint: classification.hint,
|
|
528
|
+
details,
|
|
529
|
+
stack,
|
|
530
|
+
rawMessage,
|
|
531
|
+
phase,
|
|
532
|
+
source,
|
|
533
|
+
context
|
|
534
|
+
};
|
|
535
|
+
}
|