@motion-core/motion-gpu 0.4.1 → 0.4.2

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.
Files changed (205) hide show
  1. package/dist/advanced.d.ts +1 -0
  2. package/dist/advanced.d.ts.map +1 -0
  3. package/dist/advanced.js +12 -6
  4. package/dist/core/advanced.d.ts +1 -0
  5. package/dist/core/advanced.d.ts.map +1 -0
  6. package/dist/core/advanced.js +12 -5
  7. package/dist/core/current-value.d.ts +1 -0
  8. package/dist/core/current-value.d.ts.map +1 -0
  9. package/dist/core/current-value.js +35 -34
  10. package/dist/core/current-value.js.map +1 -0
  11. package/dist/core/error-diagnostics.d.ts +1 -0
  12. package/dist/core/error-diagnostics.d.ts.map +1 -0
  13. package/dist/core/error-diagnostics.js +70 -137
  14. package/dist/core/error-diagnostics.js.map +1 -0
  15. package/dist/core/error-report.d.ts +1 -0
  16. package/dist/core/error-report.d.ts.map +1 -0
  17. package/dist/core/error-report.js +184 -233
  18. package/dist/core/error-report.js.map +1 -0
  19. package/dist/core/frame-registry.d.ts +1 -0
  20. package/dist/core/frame-registry.d.ts.map +1 -0
  21. package/dist/core/frame-registry.js +546 -662
  22. package/dist/core/frame-registry.js.map +1 -0
  23. package/dist/core/index.d.ts +1 -0
  24. package/dist/core/index.d.ts.map +1 -0
  25. package/dist/core/index.js +11 -12
  26. package/dist/core/material-preprocess.d.ts +1 -0
  27. package/dist/core/material-preprocess.d.ts.map +1 -0
  28. package/dist/core/material-preprocess.js +128 -151
  29. package/dist/core/material-preprocess.js.map +1 -0
  30. package/dist/core/material.d.ts +1 -0
  31. package/dist/core/material.d.ts.map +1 -0
  32. package/dist/core/material.js +263 -317
  33. package/dist/core/material.js.map +1 -0
  34. package/dist/core/recompile-policy.d.ts +1 -0
  35. package/dist/core/recompile-policy.d.ts.map +1 -0
  36. package/dist/core/recompile-policy.js +18 -13
  37. package/dist/core/recompile-policy.js.map +1 -0
  38. package/dist/core/render-graph.d.ts +1 -0
  39. package/dist/core/render-graph.d.ts.map +1 -0
  40. package/dist/core/render-graph.js +61 -68
  41. package/dist/core/render-graph.js.map +1 -0
  42. package/dist/core/render-targets.d.ts +1 -0
  43. package/dist/core/render-targets.d.ts.map +1 -0
  44. package/dist/core/render-targets.js +52 -53
  45. package/dist/core/render-targets.js.map +1 -0
  46. package/dist/core/renderer.d.ts +1 -0
  47. package/dist/core/renderer.d.ts.map +1 -0
  48. package/dist/core/renderer.js +942 -1081
  49. package/dist/core/renderer.js.map +1 -0
  50. package/dist/core/runtime-loop.d.ts +1 -0
  51. package/dist/core/runtime-loop.d.ts.map +1 -0
  52. package/dist/core/runtime-loop.js +305 -362
  53. package/dist/core/runtime-loop.js.map +1 -0
  54. package/dist/core/scheduler-helpers.d.ts +1 -0
  55. package/dist/core/scheduler-helpers.d.ts.map +1 -0
  56. package/dist/core/scheduler-helpers.js +52 -51
  57. package/dist/core/scheduler-helpers.js.map +1 -0
  58. package/dist/core/shader.d.ts +1 -0
  59. package/dist/core/shader.d.ts.map +1 -0
  60. package/dist/core/shader.js +92 -117
  61. package/dist/core/shader.js.map +1 -0
  62. package/dist/core/texture-loader.d.ts +1 -0
  63. package/dist/core/texture-loader.d.ts.map +1 -0
  64. package/dist/core/texture-loader.js +205 -273
  65. package/dist/core/texture-loader.js.map +1 -0
  66. package/dist/core/textures.d.ts +1 -0
  67. package/dist/core/textures.d.ts.map +1 -0
  68. package/dist/core/textures.js +106 -116
  69. package/dist/core/textures.js.map +1 -0
  70. package/dist/core/types.d.ts +1 -0
  71. package/dist/core/types.d.ts.map +1 -0
  72. package/dist/core/types.js +0 -4
  73. package/dist/core/uniforms.d.ts +1 -0
  74. package/dist/core/uniforms.d.ts.map +1 -0
  75. package/dist/core/uniforms.js +170 -191
  76. package/dist/core/uniforms.js.map +1 -0
  77. package/dist/index.d.ts +1 -0
  78. package/dist/index.d.ts.map +1 -0
  79. package/dist/index.js +11 -6
  80. package/dist/passes/BlitPass.d.ts +1 -0
  81. package/dist/passes/BlitPass.d.ts.map +1 -0
  82. package/dist/passes/BlitPass.js +23 -18
  83. package/dist/passes/BlitPass.js.map +1 -0
  84. package/dist/passes/CopyPass.d.ts +1 -0
  85. package/dist/passes/CopyPass.d.ts.map +1 -0
  86. package/dist/passes/CopyPass.js +58 -52
  87. package/dist/passes/CopyPass.js.map +1 -0
  88. package/dist/passes/FullscreenPass.d.ts +1 -0
  89. package/dist/passes/FullscreenPass.d.ts.map +1 -0
  90. package/dist/passes/FullscreenPass.js +127 -130
  91. package/dist/passes/FullscreenPass.js.map +1 -0
  92. package/dist/passes/ShaderPass.d.ts +1 -0
  93. package/dist/passes/ShaderPass.d.ts.map +1 -0
  94. package/dist/passes/ShaderPass.js +40 -37
  95. package/dist/passes/ShaderPass.js.map +1 -0
  96. package/dist/passes/index.d.ts +1 -0
  97. package/dist/passes/index.d.ts.map +1 -0
  98. package/dist/passes/index.js +4 -3
  99. package/dist/react/FragCanvas.d.ts +1 -0
  100. package/dist/react/FragCanvas.d.ts.map +1 -0
  101. package/dist/react/FragCanvas.js +234 -211
  102. package/dist/react/FragCanvas.js.map +1 -0
  103. package/dist/react/MotionGPUErrorOverlay.d.ts +1 -0
  104. package/dist/react/MotionGPUErrorOverlay.d.ts.map +1 -0
  105. package/dist/react/MotionGPUErrorOverlay.js +96 -13
  106. package/dist/react/MotionGPUErrorOverlay.js.map +1 -0
  107. package/dist/react/Portal.d.ts +1 -0
  108. package/dist/react/Portal.d.ts.map +1 -0
  109. package/dist/react/Portal.js +18 -21
  110. package/dist/react/Portal.js.map +1 -0
  111. package/dist/react/advanced.d.ts +1 -0
  112. package/dist/react/advanced.d.ts.map +1 -0
  113. package/dist/react/advanced.js +12 -6
  114. package/dist/react/frame-context.d.ts +1 -0
  115. package/dist/react/frame-context.d.ts.map +1 -0
  116. package/dist/react/frame-context.js +88 -94
  117. package/dist/react/frame-context.js.map +1 -0
  118. package/dist/react/index.d.ts +1 -0
  119. package/dist/react/index.d.ts.map +1 -0
  120. package/dist/react/index.js +10 -9
  121. package/dist/react/motiongpu-context.d.ts +1 -0
  122. package/dist/react/motiongpu-context.d.ts.map +1 -0
  123. package/dist/react/motiongpu-context.js +18 -15
  124. package/dist/react/motiongpu-context.js.map +1 -0
  125. package/dist/react/use-motiongpu-user-context.d.ts +1 -0
  126. package/dist/react/use-motiongpu-user-context.d.ts.map +1 -0
  127. package/dist/react/use-motiongpu-user-context.js +83 -82
  128. package/dist/react/use-motiongpu-user-context.js.map +1 -0
  129. package/dist/react/use-texture.d.ts +1 -0
  130. package/dist/react/use-texture.d.ts.map +1 -0
  131. package/dist/react/use-texture.js +132 -152
  132. package/dist/react/use-texture.js.map +1 -0
  133. package/dist/svelte/FragCanvas.svelte.d.ts +1 -0
  134. package/dist/svelte/FragCanvas.svelte.d.ts.map +1 -0
  135. package/dist/svelte/MotionGPUErrorOverlay.svelte.d.ts +1 -0
  136. package/dist/svelte/MotionGPUErrorOverlay.svelte.d.ts.map +1 -0
  137. package/dist/svelte/Portal.svelte.d.ts +1 -0
  138. package/dist/svelte/Portal.svelte.d.ts.map +1 -0
  139. package/dist/svelte/advanced.d.ts +1 -0
  140. package/dist/svelte/advanced.d.ts.map +1 -0
  141. package/dist/svelte/advanced.js +11 -6
  142. package/dist/svelte/frame-context.d.ts +1 -0
  143. package/dist/svelte/frame-context.d.ts.map +1 -0
  144. package/dist/svelte/frame-context.js +27 -27
  145. package/dist/svelte/frame-context.js.map +1 -0
  146. package/dist/svelte/index.d.ts +1 -0
  147. package/dist/svelte/index.d.ts.map +1 -0
  148. package/dist/svelte/index.js +10 -9
  149. package/dist/svelte/motiongpu-context.d.ts +1 -0
  150. package/dist/svelte/motiongpu-context.d.ts.map +1 -0
  151. package/dist/svelte/motiongpu-context.js +24 -21
  152. package/dist/svelte/motiongpu-context.js.map +1 -0
  153. package/dist/svelte/use-motiongpu-user-context.d.ts +1 -0
  154. package/dist/svelte/use-motiongpu-user-context.d.ts.map +1 -0
  155. package/dist/svelte/use-motiongpu-user-context.js +69 -70
  156. package/dist/svelte/use-motiongpu-user-context.js.map +1 -0
  157. package/dist/svelte/use-texture.d.ts +1 -0
  158. package/dist/svelte/use-texture.d.ts.map +1 -0
  159. package/dist/svelte/use-texture.js +125 -147
  160. package/dist/svelte/use-texture.js.map +1 -0
  161. package/package.json +12 -7
  162. package/src/lib/advanced.ts +6 -0
  163. package/src/lib/core/advanced.ts +12 -0
  164. package/src/lib/core/current-value.ts +64 -0
  165. package/src/lib/core/error-diagnostics.ts +236 -0
  166. package/src/lib/core/error-report.ts +406 -0
  167. package/src/lib/core/frame-registry.ts +1189 -0
  168. package/src/lib/core/index.ts +77 -0
  169. package/src/lib/core/material-preprocess.ts +284 -0
  170. package/src/lib/core/material.ts +667 -0
  171. package/src/lib/core/recompile-policy.ts +31 -0
  172. package/src/lib/core/render-graph.ts +143 -0
  173. package/src/lib/core/render-targets.ts +107 -0
  174. package/src/lib/core/renderer.ts +1547 -0
  175. package/src/lib/core/runtime-loop.ts +458 -0
  176. package/src/lib/core/scheduler-helpers.ts +136 -0
  177. package/src/lib/core/shader.ts +258 -0
  178. package/src/lib/core/texture-loader.ts +476 -0
  179. package/src/lib/core/textures.ts +235 -0
  180. package/src/lib/core/types.ts +582 -0
  181. package/src/lib/core/uniforms.ts +282 -0
  182. package/src/lib/index.ts +6 -0
  183. package/src/lib/passes/BlitPass.ts +54 -0
  184. package/src/lib/passes/CopyPass.ts +80 -0
  185. package/src/lib/passes/FullscreenPass.ts +173 -0
  186. package/src/lib/passes/ShaderPass.ts +88 -0
  187. package/src/lib/passes/index.ts +3 -0
  188. package/src/lib/react/FragCanvas.tsx +345 -0
  189. package/src/lib/react/MotionGPUErrorOverlay.tsx +392 -0
  190. package/src/lib/react/Portal.tsx +34 -0
  191. package/src/lib/react/advanced.ts +36 -0
  192. package/src/lib/react/frame-context.ts +169 -0
  193. package/src/lib/react/index.ts +51 -0
  194. package/src/lib/react/motiongpu-context.ts +88 -0
  195. package/src/lib/react/use-motiongpu-user-context.ts +186 -0
  196. package/src/lib/react/use-texture.ts +233 -0
  197. package/src/lib/svelte/FragCanvas.svelte +249 -0
  198. package/src/lib/svelte/MotionGPUErrorOverlay.svelte +382 -0
  199. package/src/lib/svelte/Portal.svelte +31 -0
  200. package/src/lib/svelte/advanced.ts +32 -0
  201. package/src/lib/svelte/frame-context.ts +87 -0
  202. package/src/lib/svelte/index.ts +51 -0
  203. package/src/lib/svelte/motiongpu-context.ts +97 -0
  204. package/src/lib/svelte/use-motiongpu-user-context.ts +145 -0
  205. package/src/lib/svelte/use-texture.ts +232 -0
@@ -0,0 +1,406 @@
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
+ | 'WEBGPU_DEVICE_LOST'
21
+ | 'WEBGPU_UNCAPTURED_ERROR'
22
+ | 'BIND_GROUP_MISMATCH'
23
+ | 'TEXTURE_USAGE_INVALID'
24
+ | 'TEXTURE_REQUEST_FAILED'
25
+ | 'TEXTURE_DECODE_UNAVAILABLE'
26
+ | 'TEXTURE_REQUEST_ABORTED'
27
+ | 'MOTIONGPU_RUNTIME_ERROR';
28
+
29
+ /**
30
+ * Severity level for user-facing diagnostics.
31
+ */
32
+ export type MotionGPUErrorSeverity = 'error' | 'fatal';
33
+
34
+ /**
35
+ * One source-code line displayed in diagnostics snippet.
36
+ */
37
+ export interface MotionGPUErrorSourceLine {
38
+ number: number;
39
+ code: string;
40
+ highlight: boolean;
41
+ }
42
+
43
+ /**
44
+ * Structured source context displayed for shader compilation errors.
45
+ */
46
+ export interface MotionGPUErrorSource {
47
+ component: string;
48
+ location: string;
49
+ line: number;
50
+ column?: number;
51
+ snippet: MotionGPUErrorSourceLine[];
52
+ }
53
+
54
+ /**
55
+ * Optional runtime context captured with diagnostics payload.
56
+ */
57
+ export interface MotionGPUErrorContext {
58
+ materialSignature?: string;
59
+ passGraph?: {
60
+ passCount: number;
61
+ enabledPassCount: number;
62
+ inputs: string[];
63
+ outputs: string[];
64
+ };
65
+ activeRenderTargets: string[];
66
+ }
67
+
68
+ /**
69
+ * Structured error payload used by UI diagnostics.
70
+ */
71
+ export interface MotionGPUErrorReport {
72
+ /**
73
+ * Stable machine-readable category code.
74
+ */
75
+ code: MotionGPUErrorCode;
76
+ /**
77
+ * Severity level used by diagnostics UIs and telemetry.
78
+ */
79
+ severity: MotionGPUErrorSeverity;
80
+ /**
81
+ * Whether runtime may recover without full renderer re-creation.
82
+ */
83
+ recoverable: boolean;
84
+ /**
85
+ * Short category title.
86
+ */
87
+ title: string;
88
+ /**
89
+ * Primary human-readable message.
90
+ */
91
+ message: string;
92
+ /**
93
+ * Suggested remediation hint.
94
+ */
95
+ hint: string;
96
+ /**
97
+ * Additional parsed details (for example WGSL line errors).
98
+ */
99
+ details: string[];
100
+ /**
101
+ * Stack trace lines when available.
102
+ */
103
+ stack: string[];
104
+ /**
105
+ * Original unmodified message.
106
+ */
107
+ rawMessage: string;
108
+ /**
109
+ * Runtime phase where the error occurred.
110
+ */
111
+ phase: MotionGPUErrorPhase;
112
+ /**
113
+ * Optional source context for shader-related diagnostics.
114
+ */
115
+ source: MotionGPUErrorSource | null;
116
+ /**
117
+ * Optional runtime context snapshot (material/pass graph/render targets).
118
+ */
119
+ context: MotionGPUErrorContext | null;
120
+ }
121
+
122
+ /**
123
+ * Splits multi-line values into trimmed non-empty lines.
124
+ */
125
+ function splitLines(value: string): string[] {
126
+ return value
127
+ .split('\n')
128
+ .map((line) => line.trim())
129
+ .filter((line) => line.length > 0);
130
+ }
131
+
132
+ function toDisplayName(path: string): string {
133
+ const normalized = path.split(/[?#]/)[0] ?? path;
134
+ const chunks = normalized.split(/[\\/]/);
135
+ const last = chunks[chunks.length - 1];
136
+ return last && last.length > 0 ? last : path;
137
+ }
138
+
139
+ function toSnippet(source: string, line: number, radius = 3): MotionGPUErrorSourceLine[] {
140
+ const lines = source.replace(/\r\n?/g, '\n').split('\n');
141
+ if (lines.length === 0) {
142
+ return [];
143
+ }
144
+
145
+ const targetLine = Math.min(Math.max(1, line), lines.length);
146
+ const start = Math.max(1, targetLine - radius);
147
+ const end = Math.min(lines.length, targetLine + radius);
148
+ const snippet: MotionGPUErrorSourceLine[] = [];
149
+
150
+ for (let index = start; index <= end; index += 1) {
151
+ snippet.push({
152
+ number: index,
153
+ code: lines[index - 1] ?? '',
154
+ highlight: index === targetLine
155
+ });
156
+ }
157
+
158
+ return snippet;
159
+ }
160
+
161
+ function buildSourceFromDiagnostics(error: unknown): MotionGPUErrorSource | null {
162
+ const diagnostics = getShaderCompilationDiagnostics(error);
163
+ if (!diagnostics || diagnostics.diagnostics.length === 0) {
164
+ return null;
165
+ }
166
+
167
+ const primary = diagnostics.diagnostics.find((entry) => entry.sourceLocation !== null);
168
+ if (!primary?.sourceLocation) {
169
+ return null;
170
+ }
171
+
172
+ const location = primary.sourceLocation;
173
+ const column = primary.linePos && primary.linePos > 0 ? primary.linePos : undefined;
174
+
175
+ if (location.kind === 'fragment') {
176
+ const component =
177
+ diagnostics.materialSource?.component ??
178
+ (diagnostics.materialSource?.file
179
+ ? toDisplayName(diagnostics.materialSource.file)
180
+ : 'User shader fragment');
181
+ const locationLabel = formatShaderSourceLocation(location) ?? `fragment line ${location.line}`;
182
+ return {
183
+ component,
184
+ location: `${component} (${locationLabel})`,
185
+ line: location.line,
186
+ ...(column !== undefined ? { column } : {}),
187
+ snippet: toSnippet(diagnostics.fragmentSource, location.line)
188
+ };
189
+ }
190
+
191
+ if (location.kind === 'include') {
192
+ const includeName = location.include ?? 'unknown';
193
+ const includeSource = diagnostics.includeSources[includeName] ?? '';
194
+ const component = `#include <${includeName}>`;
195
+ const locationLabel = formatShaderSourceLocation(location) ?? `include <${includeName}>`;
196
+ return {
197
+ component,
198
+ location: `${component} (${locationLabel})`,
199
+ line: location.line,
200
+ ...(column !== undefined ? { column } : {}),
201
+ snippet: toSnippet(includeSource, location.line)
202
+ };
203
+ }
204
+
205
+ const defineName = location.define ?? 'unknown';
206
+ const defineLine = Math.max(1, location.line);
207
+ const component = `#define ${defineName}`;
208
+ const locationLabel =
209
+ formatShaderSourceLocation(location) ?? `define "${defineName}" line ${defineLine}`;
210
+ return {
211
+ component,
212
+ location: `${component} (${locationLabel})`,
213
+ line: defineLine,
214
+ ...(column !== undefined ? { column } : {}),
215
+ snippet: toSnippet(diagnostics.defineBlockSource ?? '', defineLine, 2)
216
+ };
217
+ }
218
+
219
+ function formatDiagnosticMessage(entry: ShaderCompilationDiagnostic): string {
220
+ const sourceLabel = formatShaderSourceLocation(entry.sourceLocation);
221
+ const generatedLineLabel =
222
+ entry.generatedLine > 0 ? `generated WGSL line ${entry.generatedLine}` : null;
223
+ const labels = [sourceLabel, generatedLineLabel].filter((value) => Boolean(value));
224
+ if (labels.length === 0) {
225
+ return entry.message;
226
+ }
227
+
228
+ return `[${labels.join(' | ')}] ${entry.message}`;
229
+ }
230
+
231
+ /**
232
+ * Maps known WebGPU/WGSL error patterns to a user-facing title and hint.
233
+ */
234
+ function classifyErrorMessage(
235
+ message: string
236
+ ): Pick<MotionGPUErrorReport, 'code' | 'severity' | 'recoverable' | 'title' | 'hint'> {
237
+ if (message.includes('WebGPU is not available in this browser')) {
238
+ return {
239
+ code: 'WEBGPU_UNAVAILABLE',
240
+ severity: 'fatal',
241
+ recoverable: false,
242
+ title: 'WebGPU unavailable',
243
+ hint: 'Use a browser with WebGPU enabled (latest Chrome/Edge/Safari TP) and secure context.'
244
+ };
245
+ }
246
+
247
+ if (message.includes('Unable to acquire WebGPU adapter')) {
248
+ return {
249
+ code: 'WEBGPU_ADAPTER_UNAVAILABLE',
250
+ severity: 'fatal',
251
+ recoverable: false,
252
+ title: 'WebGPU adapter unavailable',
253
+ hint: 'GPU adapter request failed. Check browser permissions, flags and device support.'
254
+ };
255
+ }
256
+
257
+ if (message.includes('Canvas does not support webgpu context')) {
258
+ return {
259
+ code: 'WEBGPU_CONTEXT_UNAVAILABLE',
260
+ severity: 'error',
261
+ recoverable: true,
262
+ title: 'Canvas cannot create WebGPU context',
263
+ hint: 'Make sure this canvas is attached to DOM and not using an unsupported context option.'
264
+ };
265
+ }
266
+
267
+ if (message.includes('WGSL compilation failed')) {
268
+ return {
269
+ code: 'WGSL_COMPILATION_FAILED',
270
+ severity: 'error',
271
+ recoverable: true,
272
+ title: 'WGSL compilation failed',
273
+ hint: 'Check WGSL line numbers below and verify struct/binding/function signatures.'
274
+ };
275
+ }
276
+
277
+ if (message.includes('WebGPU device lost') || message.includes('Device Lost')) {
278
+ return {
279
+ code: 'WEBGPU_DEVICE_LOST',
280
+ severity: 'fatal',
281
+ recoverable: false,
282
+ title: 'WebGPU device lost',
283
+ hint: 'GPU device/context was lost. Recreate the renderer and check OS/GPU stability.'
284
+ };
285
+ }
286
+
287
+ if (message.includes('WebGPU uncaptured error')) {
288
+ return {
289
+ code: 'WEBGPU_UNCAPTURED_ERROR',
290
+ severity: 'error',
291
+ recoverable: true,
292
+ title: 'WebGPU uncaptured error',
293
+ hint: 'A GPU command failed asynchronously. Review details and validate resource/state usage.'
294
+ };
295
+ }
296
+
297
+ if (message.includes('CreateBindGroup') || message.includes('bind group layout')) {
298
+ return {
299
+ code: 'BIND_GROUP_MISMATCH',
300
+ severity: 'error',
301
+ recoverable: true,
302
+ title: 'Bind group mismatch',
303
+ hint: 'Bindings in shader and runtime resources are out of sync. Verify uniforms/textures layout.'
304
+ };
305
+ }
306
+
307
+ if (message.includes('Destination texture needs to have CopyDst')) {
308
+ return {
309
+ code: 'TEXTURE_USAGE_INVALID',
310
+ severity: 'error',
311
+ recoverable: true,
312
+ title: 'Invalid texture usage flags',
313
+ hint: 'Texture used as upload destination must include CopyDst (and often RenderAttachment).'
314
+ };
315
+ }
316
+
317
+ if (message.includes('Texture request failed')) {
318
+ return {
319
+ code: 'TEXTURE_REQUEST_FAILED',
320
+ severity: 'error',
321
+ recoverable: true,
322
+ title: 'Texture request failed',
323
+ hint: 'Verify texture URL, CORS policy and response status before retrying.'
324
+ };
325
+ }
326
+
327
+ if (message.includes('createImageBitmap is not available in this runtime')) {
328
+ return {
329
+ code: 'TEXTURE_DECODE_UNAVAILABLE',
330
+ severity: 'fatal',
331
+ recoverable: false,
332
+ title: 'Texture decode unavailable',
333
+ hint: 'Runtime lacks createImageBitmap support. Use a browser/runtime with image bitmap decoding.'
334
+ };
335
+ }
336
+
337
+ if (message.toLowerCase().includes('texture request was aborted')) {
338
+ return {
339
+ code: 'TEXTURE_REQUEST_ABORTED',
340
+ severity: 'error',
341
+ recoverable: true,
342
+ title: 'Texture request aborted',
343
+ hint: 'Texture load was cancelled. Retry the request when source inputs stabilize.'
344
+ };
345
+ }
346
+
347
+ return {
348
+ code: 'MOTIONGPU_RUNTIME_ERROR',
349
+ severity: 'error',
350
+ recoverable: true,
351
+ title: 'MotionGPU render error',
352
+ hint: 'Review technical details below. If issue persists, isolate shader/uniform/texture changes.'
353
+ };
354
+ }
355
+
356
+ /**
357
+ * Converts unknown errors to a consistent, display-ready error report.
358
+ *
359
+ * @param error - Unknown thrown value.
360
+ * @param phase - Phase during which error occurred.
361
+ * @returns Normalized error report.
362
+ */
363
+ export function toMotionGPUErrorReport(
364
+ error: unknown,
365
+ phase: MotionGPUErrorPhase
366
+ ): MotionGPUErrorReport {
367
+ const shaderDiagnostics = getShaderCompilationDiagnostics(error);
368
+ const rawMessage =
369
+ error instanceof Error
370
+ ? error.message
371
+ : typeof error === 'string'
372
+ ? error
373
+ : 'Unknown FragCanvas error';
374
+ const rawLines = splitLines(rawMessage);
375
+ const defaultMessage = rawLines[0] ?? rawMessage;
376
+ const defaultDetails = rawLines.slice(1);
377
+ const source = buildSourceFromDiagnostics(error);
378
+ const context = shaderDiagnostics?.runtimeContext ?? null;
379
+ const message =
380
+ shaderDiagnostics && shaderDiagnostics.diagnostics[0]
381
+ ? formatDiagnosticMessage(shaderDiagnostics.diagnostics[0])
382
+ : defaultMessage;
383
+ const details = shaderDiagnostics
384
+ ? shaderDiagnostics.diagnostics.slice(1).map((entry) => formatDiagnosticMessage(entry))
385
+ : defaultDetails;
386
+ const stack =
387
+ error instanceof Error && error.stack
388
+ ? splitLines(error.stack).filter((line) => line !== message)
389
+ : [];
390
+ const classification = classifyErrorMessage(rawMessage);
391
+
392
+ return {
393
+ code: classification.code,
394
+ severity: classification.severity,
395
+ recoverable: classification.recoverable,
396
+ title: classification.title,
397
+ message,
398
+ hint: classification.hint,
399
+ details,
400
+ stack,
401
+ rawMessage,
402
+ phase,
403
+ source,
404
+ context
405
+ };
406
+ }