@motion-core/motion-gpu 0.4.2 → 0.6.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.js +3 -1
- package/dist/core/advanced.js +3 -1
- 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 +135 -0
- package/dist/core/compute-shader.d.ts.map +1 -0
- package/dist/core/compute-shader.js +238 -0
- package/dist/core/compute-shader.js.map +1 -0
- 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 +1 -1
- package/dist/core/error-report.d.ts.map +1 -1
- package/dist/core/error-report.js +82 -1
- package/dist/core/error-report.js.map +1 -1
- package/dist/core/frame-registry.d.ts.map +1 -1
- package/dist/core/frame-registry.js +1 -1
- package/dist/core/frame-registry.js.map +1 -1
- package/dist/core/index.d.ts +5 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +3 -1
- package/dist/core/material-preprocess.d.ts.map +1 -1
- package/dist/core/material-preprocess.js +5 -3
- package/dist/core/material-preprocess.js.map +1 -1
- package/dist/core/material.d.ts +22 -6
- package/dist/core/material.d.ts.map +1 -1
- package/dist/core/material.js +32 -4
- package/dist/core/material.js.map +1 -1
- package/dist/core/render-graph.d.ts +7 -3
- package/dist/core/render-graph.d.ts.map +1 -1
- package/dist/core/render-graph.js +22 -6
- package/dist/core/render-graph.js.map +1 -1
- package/dist/core/renderer.d.ts.map +1 -1
- package/dist/core/renderer.js +489 -29
- package/dist/core/renderer.js.map +1 -1
- package/dist/core/runtime-loop.d.ts +2 -2
- package/dist/core/runtime-loop.d.ts.map +1 -1
- package/dist/core/runtime-loop.js +74 -14
- package/dist/core/runtime-loop.js.map +1 -1
- package/dist/core/shader.d.ts +16 -3
- package/dist/core/shader.d.ts.map +1 -1
- package/dist/core/shader.js +22 -2
- package/dist/core/shader.js.map +1 -1
- 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.map +1 -1
- package/dist/core/texture-loader.js +4 -0
- package/dist/core/texture-loader.js.map +1 -1
- package/dist/core/textures.d.ts +16 -0
- package/dist/core/textures.d.ts.map +1 -1
- package/dist/core/textures.js +8 -2
- package/dist/core/textures.js.map +1 -1
- package/dist/core/types.d.ts +146 -4
- package/dist/core/types.d.ts.map +1 -1
- package/dist/index.js +3 -1
- 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/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.map +1 -1
- package/dist/passes/ShaderPass.js +2 -1
- package/dist/passes/ShaderPass.js.map +1 -1
- package/dist/passes/index.d.ts +2 -0
- package/dist/passes/index.d.ts.map +1 -1
- package/dist/passes/index.js +3 -1
- package/dist/react/FragCanvas.d.ts +2 -2
- package/dist/react/FragCanvas.d.ts.map +1 -1
- package/dist/react/FragCanvas.js.map +1 -1
- package/dist/react/MotionGPUErrorOverlay.d.ts.map +1 -1
- package/dist/react/MotionGPUErrorOverlay.js +123 -20
- package/dist/react/MotionGPUErrorOverlay.js.map +1 -1
- package/dist/react/advanced.js +3 -1
- package/dist/react/index.d.ts +5 -2
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +3 -1
- package/dist/svelte/FragCanvas.svelte +2 -2
- package/dist/svelte/FragCanvas.svelte.d.ts +2 -2
- package/dist/svelte/FragCanvas.svelte.d.ts.map +1 -1
- package/dist/svelte/MotionGPUErrorOverlay.svelte +137 -7
- package/dist/svelte/MotionGPUErrorOverlay.svelte.d.ts.map +1 -1
- package/dist/svelte/advanced.js +3 -1
- package/dist/svelte/index.d.ts +5 -2
- package/dist/svelte/index.d.ts.map +1 -1
- package/dist/svelte/index.js +3 -1
- package/package.json +1 -1
- package/src/lib/core/compute-bindgroup-cache.ts +73 -0
- package/src/lib/core/compute-shader.ts +412 -0
- package/src/lib/core/error-diagnostics.ts +29 -4
- package/src/lib/core/error-report.ts +155 -1
- package/src/lib/core/frame-registry.ts +2 -1
- package/src/lib/core/index.ts +18 -1
- package/src/lib/core/material-preprocess.ts +17 -6
- package/src/lib/core/material.ts +103 -21
- package/src/lib/core/render-graph.ts +39 -9
- package/src/lib/core/renderer.ts +768 -48
- package/src/lib/core/runtime-loop.ts +116 -16
- package/src/lib/core/shader.ts +58 -4
- package/src/lib/core/storage-buffers.ts +142 -0
- package/src/lib/core/texture-loader.ts +6 -0
- package/src/lib/core/textures.ts +29 -2
- package/src/lib/core/types.ts +165 -4
- package/src/lib/passes/ComputePass.ts +136 -0
- package/src/lib/passes/PingPongComputePass.ts +180 -0
- package/src/lib/passes/ShaderPass.ts +2 -1
- package/src/lib/passes/index.ts +6 -0
- package/src/lib/react/FragCanvas.tsx +3 -3
- package/src/lib/react/MotionGPUErrorOverlay.tsx +137 -5
- package/src/lib/react/index.ts +18 -1
- package/src/lib/svelte/FragCanvas.svelte +2 -2
- package/src/lib/svelte/MotionGPUErrorOverlay.svelte +137 -7
- package/src/lib/svelte/index.ts +18 -1
|
@@ -7,6 +7,7 @@ import { buildRendererPipelineSignature } from "./recompile-policy.js";
|
|
|
7
7
|
function getRendererRetryDelayMs(attempt) {
|
|
8
8
|
return Math.min(8e3, 250 * 2 ** Math.max(0, attempt - 1));
|
|
9
9
|
}
|
|
10
|
+
var ERROR_CLEAR_GRACE_MS = 750;
|
|
10
11
|
function createMotionGPURuntimeLoop(options) {
|
|
11
12
|
const { canvas: canvasElement, registry, size } = options;
|
|
12
13
|
let frameId = null;
|
|
@@ -36,9 +37,19 @@ function createMotionGPURuntimeLoop(options) {
|
|
|
36
37
|
width: 0,
|
|
37
38
|
height: 0
|
|
38
39
|
};
|
|
40
|
+
let storageBufferKeys = [];
|
|
41
|
+
let storageBufferKeySet = /* @__PURE__ */ new Set();
|
|
42
|
+
let storageBufferDefinitions = {};
|
|
43
|
+
const pendingStorageWrites = [];
|
|
39
44
|
let shouldContinueAfterFrame = false;
|
|
40
45
|
let activeErrorKey = null;
|
|
41
46
|
let errorHistory = [];
|
|
47
|
+
let errorClearReadyAtMs = 0;
|
|
48
|
+
let lastFrameTimestampMs = performance.now();
|
|
49
|
+
const resolveNowMs = (nowMs) => {
|
|
50
|
+
if (typeof nowMs === "number" && Number.isFinite(nowMs)) return nowMs;
|
|
51
|
+
return lastFrameTimestampMs;
|
|
52
|
+
};
|
|
42
53
|
const getHistoryLimit = () => {
|
|
43
54
|
const value = options.getErrorHistoryLimit?.() ?? 0;
|
|
44
55
|
if (!Number.isFinite(value) || value <= 0) return 0;
|
|
@@ -61,11 +72,12 @@ function createMotionGPURuntimeLoop(options) {
|
|
|
61
72
|
return;
|
|
62
73
|
}
|
|
63
74
|
if (errorHistory.length <= limit) return;
|
|
64
|
-
errorHistory
|
|
75
|
+
errorHistory.splice(0, errorHistory.length - limit);
|
|
65
76
|
publishErrorHistory();
|
|
66
77
|
};
|
|
67
|
-
const setError = (error, phase) => {
|
|
78
|
+
const setError = (error, phase, nowMs) => {
|
|
68
79
|
const report = toMotionGPUErrorReport(error, phase);
|
|
80
|
+
errorClearReadyAtMs = resolveNowMs(nowMs) + ERROR_CLEAR_GRACE_MS;
|
|
69
81
|
const reportKey = JSON.stringify({
|
|
70
82
|
phase: report.phase,
|
|
71
83
|
title: report.title,
|
|
@@ -76,8 +88,8 @@ function createMotionGPURuntimeLoop(options) {
|
|
|
76
88
|
activeErrorKey = reportKey;
|
|
77
89
|
const historyLimit = getHistoryLimit();
|
|
78
90
|
if (historyLimit > 0) {
|
|
79
|
-
errorHistory
|
|
80
|
-
if (errorHistory.length > historyLimit) errorHistory
|
|
91
|
+
errorHistory.push(report);
|
|
92
|
+
if (errorHistory.length > historyLimit) errorHistory.splice(0, errorHistory.length - historyLimit);
|
|
81
93
|
publishErrorHistory();
|
|
82
94
|
}
|
|
83
95
|
options.reportError(report);
|
|
@@ -87,9 +99,11 @@ function createMotionGPURuntimeLoop(options) {
|
|
|
87
99
|
onError(report);
|
|
88
100
|
} catch {}
|
|
89
101
|
};
|
|
90
|
-
const
|
|
102
|
+
const maybeClearError = (nowMs) => {
|
|
91
103
|
if (activeErrorKey === null) return;
|
|
104
|
+
if (resolveNowMs(nowMs) < errorClearReadyAtMs) return;
|
|
92
105
|
activeErrorKey = null;
|
|
106
|
+
errorClearReadyAtMs = 0;
|
|
93
107
|
options.reportError(null);
|
|
94
108
|
};
|
|
95
109
|
const scheduleFrame = () => {
|
|
@@ -108,12 +122,12 @@ function createMotionGPURuntimeLoop(options) {
|
|
|
108
122
|
requestFrame();
|
|
109
123
|
};
|
|
110
124
|
const resetRuntimeMaps = () => {
|
|
111
|
-
for (const key of Object.keys(runtimeUniforms)) if (!uniformKeySet.has(key))
|
|
112
|
-
for (const key of Object.keys(runtimeTextures)) if (!textureKeySet.has(key))
|
|
125
|
+
for (const key of Object.keys(runtimeUniforms)) if (!uniformKeySet.has(key)) delete runtimeUniforms[key];
|
|
126
|
+
for (const key of Object.keys(runtimeTextures)) if (!textureKeySet.has(key)) delete runtimeTextures[key];
|
|
113
127
|
};
|
|
114
128
|
const resetRenderPayloadMaps = () => {
|
|
115
|
-
for (const key of Object.keys(renderUniforms)) if (!uniformKeySet.has(key))
|
|
116
|
-
for (const key of Object.keys(renderTextures)) if (!textureKeySet.has(key))
|
|
129
|
+
for (const key of Object.keys(renderUniforms)) if (!uniformKeySet.has(key)) delete renderUniforms[key];
|
|
130
|
+
for (const key of Object.keys(renderTextures)) if (!textureKeySet.has(key)) delete renderTextures[key];
|
|
117
131
|
};
|
|
118
132
|
const syncMaterialRuntimeState = (materialState) => {
|
|
119
133
|
const signatureChanged = activeMaterialSignature !== materialState.signature;
|
|
@@ -127,6 +141,9 @@ function createMotionGPURuntimeLoop(options) {
|
|
|
127
141
|
textureKeys = materialState.textureKeys;
|
|
128
142
|
uniformKeySet = new Set(uniformKeys);
|
|
129
143
|
textureKeySet = new Set(textureKeys);
|
|
144
|
+
storageBufferKeys = materialState.storageBufferKeys;
|
|
145
|
+
storageBufferKeySet = new Set(storageBufferKeys);
|
|
146
|
+
storageBufferDefinitions = options.getMaterial().storageBuffers ?? {};
|
|
130
147
|
resetRuntimeMaps();
|
|
131
148
|
resetRenderPayloadMaps();
|
|
132
149
|
activeMaterialSignature = materialState.signature;
|
|
@@ -145,15 +162,51 @@ function createMotionGPURuntimeLoop(options) {
|
|
|
145
162
|
if (!textureKeySet.has(name)) throw new Error(`Unknown texture "${name}". Declare it in material.textures first.`);
|
|
146
163
|
runtimeTextures[name] = value;
|
|
147
164
|
};
|
|
165
|
+
const writeStorageBuffer = (name, data, writeOptions) => {
|
|
166
|
+
if (!storageBufferKeySet.has(name)) throw new Error(`Unknown storage buffer "${name}". Declare it in material.storageBuffers first.`);
|
|
167
|
+
const definition = storageBufferDefinitions[name];
|
|
168
|
+
if (!definition) throw new Error(`Missing definition for storage buffer "${name}".`);
|
|
169
|
+
const offset = writeOptions?.offset ?? 0;
|
|
170
|
+
if (offset < 0 || offset + data.byteLength > definition.size) throw new Error(`Storage buffer "${name}" write out of bounds: offset=${offset}, dataSize=${data.byteLength}, bufferSize=${definition.size}.`);
|
|
171
|
+
pendingStorageWrites.push({
|
|
172
|
+
name,
|
|
173
|
+
data,
|
|
174
|
+
offset
|
|
175
|
+
});
|
|
176
|
+
};
|
|
177
|
+
const readStorageBuffer = (name) => {
|
|
178
|
+
if (!storageBufferKeySet.has(name)) throw new Error(`Unknown storage buffer "${name}". Declare it in material.storageBuffers first.`);
|
|
179
|
+
if (!renderer) return Promise.reject(/* @__PURE__ */ new Error(`Cannot read storage buffer "${name}": renderer not initialized.`));
|
|
180
|
+
const gpuBuffer = renderer.getStorageBuffer?.(name);
|
|
181
|
+
if (!gpuBuffer) return Promise.reject(/* @__PURE__ */ new Error(`Storage buffer "${name}" not allocated on GPU.`));
|
|
182
|
+
const device = renderer.getDevice?.();
|
|
183
|
+
if (!device) return Promise.reject(/* @__PURE__ */ new Error("Cannot read storage buffer: GPU device unavailable."));
|
|
184
|
+
const definition = storageBufferDefinitions[name];
|
|
185
|
+
if (!definition) return Promise.reject(/* @__PURE__ */ new Error(`Missing definition for storage buffer "${name}".`));
|
|
186
|
+
const stagingBuffer = device.createBuffer({
|
|
187
|
+
size: definition.size,
|
|
188
|
+
usage: GPUBufferUsage.MAP_READ | GPUBufferUsage.COPY_DST
|
|
189
|
+
});
|
|
190
|
+
const commandEncoder = device.createCommandEncoder();
|
|
191
|
+
commandEncoder.copyBufferToBuffer(gpuBuffer, 0, stagingBuffer, 0, definition.size);
|
|
192
|
+
device.queue.submit([commandEncoder.finish()]);
|
|
193
|
+
return stagingBuffer.mapAsync(GPUMapMode.READ).then(() => {
|
|
194
|
+
const result = stagingBuffer.getMappedRange().slice(0);
|
|
195
|
+
stagingBuffer.unmap();
|
|
196
|
+
stagingBuffer.destroy();
|
|
197
|
+
return result;
|
|
198
|
+
});
|
|
199
|
+
};
|
|
148
200
|
const renderFrame = (timestamp) => {
|
|
149
201
|
frameId = null;
|
|
150
202
|
if (isDisposed) return;
|
|
203
|
+
lastFrameTimestampMs = timestamp;
|
|
151
204
|
syncErrorHistory();
|
|
152
205
|
let materialState;
|
|
153
206
|
try {
|
|
154
207
|
materialState = resolveActiveMaterial();
|
|
155
208
|
} catch (error) {
|
|
156
|
-
setError(error, "initialization");
|
|
209
|
+
setError(error, "initialization", timestamp);
|
|
157
210
|
scheduleFrame();
|
|
158
211
|
return;
|
|
159
212
|
}
|
|
@@ -188,6 +241,9 @@ function createMotionGPURuntimeLoop(options) {
|
|
|
188
241
|
uniformLayout: materialState.uniformLayout,
|
|
189
242
|
textureKeys: materialState.textureKeys,
|
|
190
243
|
textureDefinitions: materialState.textures,
|
|
244
|
+
storageBufferKeys: materialState.storageBufferKeys,
|
|
245
|
+
storageBufferDefinitions,
|
|
246
|
+
storageTextureKeys: materialState.storageTextureKeys,
|
|
191
247
|
getRenderTargets: options.getRenderTargets,
|
|
192
248
|
getPasses: options.getPasses,
|
|
193
249
|
outputColorSpace,
|
|
@@ -206,7 +262,7 @@ function createMotionGPURuntimeLoop(options) {
|
|
|
206
262
|
failedRendererSignature = null;
|
|
207
263
|
failedRendererAttempts = 0;
|
|
208
264
|
nextRendererRetryAt = 0;
|
|
209
|
-
|
|
265
|
+
maybeClearError(performance.now());
|
|
210
266
|
} catch (error) {
|
|
211
267
|
failedRendererSignature = rendererSignature;
|
|
212
268
|
failedRendererAttempts += 1;
|
|
@@ -241,6 +297,8 @@ function createMotionGPURuntimeLoop(options) {
|
|
|
241
297
|
delta,
|
|
242
298
|
setUniform,
|
|
243
299
|
setTexture,
|
|
300
|
+
writeStorageBuffer,
|
|
301
|
+
readStorageBuffer,
|
|
244
302
|
invalidate,
|
|
245
303
|
advance,
|
|
246
304
|
renderMode: registry.getRenderMode(),
|
|
@@ -266,12 +324,14 @@ function createMotionGPURuntimeLoop(options) {
|
|
|
266
324
|
renderMode: registry.getRenderMode(),
|
|
267
325
|
uniforms: renderUniforms,
|
|
268
326
|
textures: renderTextures,
|
|
269
|
-
canvasSize
|
|
327
|
+
canvasSize,
|
|
328
|
+
pendingStorageWrites: pendingStorageWrites.length > 0 ? pendingStorageWrites : void 0
|
|
270
329
|
});
|
|
330
|
+
if (pendingStorageWrites.length > 0) pendingStorageWrites.length = 0;
|
|
271
331
|
}
|
|
272
|
-
|
|
332
|
+
maybeClearError(timestamp);
|
|
273
333
|
} catch (error) {
|
|
274
|
-
setError(error, "render");
|
|
334
|
+
setError(error, "render", timestamp);
|
|
275
335
|
} finally {
|
|
276
336
|
registry.endFrame();
|
|
277
337
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-loop.js","names":[],"sources":["../../src/lib/core/runtime-loop.ts"],"sourcesContent":["import type { CurrentReadable, CurrentWritable } from './current-value.js';\nimport { resolveMaterial, type FragMaterial, type ResolvedMaterial } from './material.js';\nimport {\n\ttoMotionGPUErrorReport,\n\ttype MotionGPUErrorPhase,\n\ttype MotionGPUErrorReport\n} from './error-report.js';\nimport { createRenderer } from './renderer.js';\nimport { buildRendererPipelineSignature } from './recompile-policy.js';\nimport { assertUniformValueForType } from './uniforms.js';\nimport type { FrameRegistry } from './frame-registry.js';\nimport type {\n\tFrameInvalidationToken,\n\tOutputColorSpace,\n\tRenderPass,\n\tRenderer,\n\tRenderTargetDefinitionMap,\n\tTextureMap,\n\tTextureValue,\n\tUniformType,\n\tUniformValue\n} from './types.js';\n\nexport interface MotionGPURuntimeLoopOptions {\n\tcanvas: HTMLCanvasElement;\n\tregistry: FrameRegistry;\n\tsize: CurrentWritable<{ width: number; height: number }>;\n\tdpr: CurrentReadable<number>;\n\tmaxDelta: CurrentReadable<number>;\n\tgetMaterial: () => FragMaterial;\n\tgetRenderTargets: () => RenderTargetDefinitionMap;\n\tgetPasses: () => RenderPass[];\n\tgetClearColor: () => [number, number, number, number];\n\tgetOutputColorSpace: () => OutputColorSpace;\n\tgetAdapterOptions: () => GPURequestAdapterOptions | undefined;\n\tgetDeviceDescriptor: () => GPUDeviceDescriptor | undefined;\n\tgetOnError: () => ((report: MotionGPUErrorReport) => void) | undefined;\n\treportError: (report: MotionGPUErrorReport | null) => void;\n\tgetErrorHistoryLimit?: () => number | undefined;\n\tgetOnErrorHistory?: () => ((history: MotionGPUErrorReport[]) => void) | undefined;\n\treportErrorHistory?: (history: MotionGPUErrorReport[]) => void;\n}\n\nexport interface MotionGPURuntimeLoop {\n\trequestFrame: () => void;\n\tinvalidate: (token?: FrameInvalidationToken) => void;\n\tadvance: () => void;\n\tdestroy: () => void;\n}\n\nfunction getRendererRetryDelayMs(attempt: number): number {\n\treturn Math.min(8000, 250 * 2 ** Math.max(0, attempt - 1));\n}\n\nexport function createMotionGPURuntimeLoop(\n\toptions: MotionGPURuntimeLoopOptions\n): MotionGPURuntimeLoop {\n\tconst { canvas: canvasElement, registry, size } = options;\n\tlet frameId: number | null = null;\n\tlet renderer: Renderer | null = null;\n\tlet isDisposed = false;\n\tlet previousTime = performance.now() / 1000;\n\tlet activeRendererSignature = '';\n\tlet failedRendererSignature: string | null = null;\n\tlet failedRendererAttempts = 0;\n\tlet nextRendererRetryAt = 0;\n\tlet rendererRebuildPromise: Promise<void> | null = null;\n\n\tconst runtimeUniforms: Record<string, UniformValue> = {};\n\tconst runtimeTextures: TextureMap = {};\n\tlet activeUniforms: Record<string, UniformValue> = {};\n\tlet activeTextures: Record<string, { source?: TextureValue }> = {};\n\tlet uniformKeys: string[] = [];\n\tlet uniformKeySet = new Set<string>();\n\tlet uniformTypes = new Map<string, UniformType>();\n\tlet textureKeys: string[] = [];\n\tlet textureKeySet = new Set<string>();\n\tlet activeMaterialSignature = '';\n\tlet currentCssWidth = -1;\n\tlet currentCssHeight = -1;\n\tconst renderUniforms: Record<string, UniformValue> = {};\n\tconst renderTextures: TextureMap = {};\n\tconst canvasSize = { width: 0, height: 0 };\n\tlet shouldContinueAfterFrame = false;\n\tlet activeErrorKey: string | null = null;\n\tlet errorHistory: MotionGPUErrorReport[] = [];\n\n\tconst getHistoryLimit = (): number => {\n\t\tconst value = options.getErrorHistoryLimit?.() ?? 0;\n\t\tif (!Number.isFinite(value) || value <= 0) {\n\t\t\treturn 0;\n\t\t}\n\n\t\treturn Math.floor(value);\n\t};\n\n\tconst publishErrorHistory = (): void => {\n\t\toptions.reportErrorHistory?.(errorHistory);\n\t\tconst onErrorHistory = options.getOnErrorHistory?.();\n\t\tif (!onErrorHistory) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tonErrorHistory(errorHistory);\n\t\t} catch {\n\t\t\t// User-provided error history handlers must not break runtime error recovery.\n\t\t}\n\t};\n\n\tconst syncErrorHistory = (): void => {\n\t\tconst limit = getHistoryLimit();\n\t\tif (limit <= 0) {\n\t\t\tif (errorHistory.length === 0) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\terrorHistory = [];\n\t\t\tpublishErrorHistory();\n\t\t\treturn;\n\t\t}\n\n\t\tif (errorHistory.length <= limit) {\n\t\t\treturn;\n\t\t}\n\n\t\terrorHistory = errorHistory.slice(errorHistory.length - limit);\n\t\tpublishErrorHistory();\n\t};\n\n\tconst setError = (error: unknown, phase: MotionGPUErrorPhase): void => {\n\t\tconst report = toMotionGPUErrorReport(error, phase);\n\t\tconst reportKey = JSON.stringify({\n\t\t\tphase: report.phase,\n\t\t\ttitle: report.title,\n\t\t\tmessage: report.message,\n\t\t\trawMessage: report.rawMessage\n\t\t});\n\t\tif (activeErrorKey === reportKey) {\n\t\t\treturn;\n\t\t}\n\t\tactiveErrorKey = reportKey;\n\t\tconst historyLimit = getHistoryLimit();\n\t\tif (historyLimit > 0) {\n\t\t\terrorHistory = [...errorHistory, report];\n\t\t\tif (errorHistory.length > historyLimit) {\n\t\t\t\terrorHistory = errorHistory.slice(errorHistory.length - historyLimit);\n\t\t\t}\n\t\t\tpublishErrorHistory();\n\t\t}\n\t\toptions.reportError(report);\n\t\tconst onError = options.getOnError();\n\t\tif (!onError) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tonError(report);\n\t\t} catch {\n\t\t\t// User-provided error handlers must not break runtime error recovery.\n\t\t}\n\t};\n\n\tconst clearError = (): void => {\n\t\tif (activeErrorKey === null) {\n\t\t\treturn;\n\t\t}\n\n\t\tactiveErrorKey = null;\n\t\toptions.reportError(null);\n\t};\n\n\tconst scheduleFrame = (): void => {\n\t\tif (isDisposed || frameId !== null) {\n\t\t\treturn;\n\t\t}\n\n\t\tframeId = requestAnimationFrame(renderFrame);\n\t};\n\n\tconst requestFrame = (): void => {\n\t\tscheduleFrame();\n\t};\n\n\tconst invalidate = (token?: FrameInvalidationToken): void => {\n\t\tregistry.invalidate(token);\n\t\trequestFrame();\n\t};\n\n\tconst advance = (): void => {\n\t\tregistry.advance();\n\t\trequestFrame();\n\t};\n\n\tconst resetRuntimeMaps = (): void => {\n\t\tfor (const key of Object.keys(runtimeUniforms)) {\n\t\t\tif (!uniformKeySet.has(key)) {\n\t\t\t\tReflect.deleteProperty(runtimeUniforms, key);\n\t\t\t}\n\t\t}\n\n\t\tfor (const key of Object.keys(runtimeTextures)) {\n\t\t\tif (!textureKeySet.has(key)) {\n\t\t\t\tReflect.deleteProperty(runtimeTextures, key);\n\t\t\t}\n\t\t}\n\t};\n\n\tconst resetRenderPayloadMaps = (): void => {\n\t\tfor (const key of Object.keys(renderUniforms)) {\n\t\t\tif (!uniformKeySet.has(key)) {\n\t\t\t\tReflect.deleteProperty(renderUniforms, key);\n\t\t\t}\n\t\t}\n\n\t\tfor (const key of Object.keys(renderTextures)) {\n\t\t\tif (!textureKeySet.has(key)) {\n\t\t\t\tReflect.deleteProperty(renderTextures, key);\n\t\t\t}\n\t\t}\n\t};\n\n\tconst syncMaterialRuntimeState = (materialState: ResolvedMaterial): void => {\n\t\tconst signatureChanged = activeMaterialSignature !== materialState.signature;\n\t\tconst defaultsChanged =\n\t\t\tactiveUniforms !== materialState.uniforms || activeTextures !== materialState.textures;\n\n\t\tif (!signatureChanged && !defaultsChanged) {\n\t\t\treturn;\n\t\t}\n\n\t\tactiveUniforms = materialState.uniforms;\n\t\tactiveTextures = materialState.textures;\n\t\tif (!signatureChanged) {\n\t\t\treturn;\n\t\t}\n\n\t\tuniformKeys = materialState.uniformLayout.entries.map((entry) => entry.name);\n\t\tuniformTypes = new Map(\n\t\t\tmaterialState.uniformLayout.entries.map((entry) => [entry.name, entry.type])\n\t\t);\n\t\ttextureKeys = materialState.textureKeys;\n\t\tuniformKeySet = new Set(uniformKeys);\n\t\ttextureKeySet = new Set(textureKeys);\n\t\tresetRuntimeMaps();\n\t\tresetRenderPayloadMaps();\n\t\tactiveMaterialSignature = materialState.signature;\n\t};\n\n\tconst resolveActiveMaterial = (): ResolvedMaterial => {\n\t\treturn resolveMaterial(options.getMaterial());\n\t};\n\n\tconst setUniform = (name: string, value: UniformValue): void => {\n\t\tif (!uniformKeySet.has(name)) {\n\t\t\tthrow new Error(`Unknown uniform \"${name}\". Declare it in material.uniforms first.`);\n\t\t}\n\t\tconst expectedType = uniformTypes.get(name);\n\t\tif (!expectedType) {\n\t\t\tthrow new Error(`Unknown uniform type for \"${name}\"`);\n\t\t}\n\t\tassertUniformValueForType(expectedType, value);\n\t\truntimeUniforms[name] = value;\n\t};\n\n\tconst setTexture = (name: string, value: TextureValue): void => {\n\t\tif (!textureKeySet.has(name)) {\n\t\t\tthrow new Error(`Unknown texture \"${name}\". Declare it in material.textures first.`);\n\t\t}\n\t\truntimeTextures[name] = value;\n\t};\n\n\tconst renderFrame = (timestamp: number): void => {\n\t\tframeId = null;\n\t\tif (isDisposed) {\n\t\t\treturn;\n\t\t}\n\t\tsyncErrorHistory();\n\n\t\tlet materialState: ResolvedMaterial;\n\t\ttry {\n\t\t\tmaterialState = resolveActiveMaterial();\n\t\t} catch (error) {\n\t\t\tsetError(error, 'initialization');\n\t\t\tscheduleFrame();\n\t\t\treturn;\n\t\t}\n\n\t\tshouldContinueAfterFrame = false;\n\n\t\tconst outputColorSpace = options.getOutputColorSpace();\n\t\tconst rendererSignature = buildRendererPipelineSignature({\n\t\t\tmaterialSignature: materialState.signature,\n\t\t\toutputColorSpace\n\t\t});\n\t\tsyncMaterialRuntimeState(materialState);\n\n\t\tif (failedRendererSignature && failedRendererSignature !== rendererSignature) {\n\t\t\tfailedRendererSignature = null;\n\t\t\tfailedRendererAttempts = 0;\n\t\t\tnextRendererRetryAt = 0;\n\t\t}\n\n\t\tif (!renderer || activeRendererSignature !== rendererSignature) {\n\t\t\tif (\n\t\t\t\tfailedRendererSignature === rendererSignature &&\n\t\t\t\tperformance.now() < nextRendererRetryAt\n\t\t\t) {\n\t\t\t\tscheduleFrame();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (!rendererRebuildPromise) {\n\t\t\t\trendererRebuildPromise = (async () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst nextRenderer = await createRenderer({\n\t\t\t\t\t\t\tcanvas: canvasElement,\n\t\t\t\t\t\t\tfragmentWgsl: materialState.fragmentWgsl,\n\t\t\t\t\t\t\tfragmentLineMap: materialState.fragmentLineMap,\n\t\t\t\t\t\t\tfragmentSource: materialState.fragmentSource,\n\t\t\t\t\t\t\tincludeSources: materialState.includeSources,\n\t\t\t\t\t\t\tdefineBlockSource: materialState.defineBlockSource,\n\t\t\t\t\t\t\tmaterialSource: materialState.source,\n\t\t\t\t\t\t\tmaterialSignature: materialState.signature,\n\t\t\t\t\t\t\tuniformLayout: materialState.uniformLayout,\n\t\t\t\t\t\t\ttextureKeys: materialState.textureKeys,\n\t\t\t\t\t\t\ttextureDefinitions: materialState.textures,\n\t\t\t\t\t\t\tgetRenderTargets: options.getRenderTargets,\n\t\t\t\t\t\t\tgetPasses: options.getPasses,\n\t\t\t\t\t\t\toutputColorSpace,\n\t\t\t\t\t\t\tgetClearColor: options.getClearColor,\n\t\t\t\t\t\t\tgetDpr: () => options.dpr.current,\n\t\t\t\t\t\t\tadapterOptions: options.getAdapterOptions(),\n\t\t\t\t\t\t\tdeviceDescriptor: options.getDeviceDescriptor()\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (isDisposed) {\n\t\t\t\t\t\t\tnextRenderer.destroy();\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\trenderer?.destroy();\n\t\t\t\t\t\trenderer = nextRenderer;\n\t\t\t\t\t\tactiveRendererSignature = rendererSignature;\n\t\t\t\t\t\tfailedRendererSignature = null;\n\t\t\t\t\t\tfailedRendererAttempts = 0;\n\t\t\t\t\t\tnextRendererRetryAt = 0;\n\t\t\t\t\t\tclearError();\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tfailedRendererSignature = rendererSignature;\n\t\t\t\t\t\tfailedRendererAttempts += 1;\n\t\t\t\t\t\tconst retryDelayMs = getRendererRetryDelayMs(failedRendererAttempts);\n\t\t\t\t\t\tnextRendererRetryAt = performance.now() + retryDelayMs;\n\t\t\t\t\t\tsetError(error, 'initialization');\n\t\t\t\t\t} finally {\n\t\t\t\t\t\trendererRebuildPromise = null;\n\t\t\t\t\t\tscheduleFrame();\n\t\t\t\t\t}\n\t\t\t\t})();\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\tconst time = timestamp / 1000;\n\t\tconst rawDelta = Math.max(0, time - previousTime);\n\t\tconst delta = Math.min(rawDelta, options.maxDelta.current);\n\t\tpreviousTime = time;\n\t\tconst rect = canvasElement.getBoundingClientRect();\n\t\tconst width = Math.max(0, Math.floor(rect.width));\n\t\tconst height = Math.max(0, Math.floor(rect.height));\n\t\tif (width !== currentCssWidth || height !== currentCssHeight) {\n\t\t\tcurrentCssWidth = width;\n\t\t\tcurrentCssHeight = height;\n\t\t\tsize.set({ width, height });\n\t\t}\n\n\t\ttry {\n\t\t\tregistry.run({\n\t\t\t\ttime,\n\t\t\t\tdelta,\n\t\t\t\tsetUniform,\n\t\t\t\tsetTexture,\n\t\t\t\tinvalidate,\n\t\t\t\tadvance,\n\t\t\t\trenderMode: registry.getRenderMode(),\n\t\t\t\tautoRender: registry.getAutoRender(),\n\t\t\t\tcanvas: canvasElement\n\t\t\t});\n\n\t\t\tconst shouldRenderFrame = registry.shouldRender();\n\t\t\tshouldContinueAfterFrame =\n\t\t\t\tregistry.getRenderMode() === 'always' ||\n\t\t\t\t(registry.getRenderMode() === 'on-demand' && shouldRenderFrame);\n\n\t\t\tif (shouldRenderFrame) {\n\t\t\t\tfor (const key of uniformKeys) {\n\t\t\t\t\tconst runtimeValue = runtimeUniforms[key];\n\t\t\t\t\trenderUniforms[key] =\n\t\t\t\t\t\truntimeValue === undefined ? (activeUniforms[key] as UniformValue) : runtimeValue;\n\t\t\t\t}\n\n\t\t\t\tfor (const key of textureKeys) {\n\t\t\t\t\tconst runtimeValue = runtimeTextures[key];\n\t\t\t\t\trenderTextures[key] =\n\t\t\t\t\t\truntimeValue === undefined ? (activeTextures[key]?.source ?? null) : runtimeValue;\n\t\t\t\t}\n\n\t\t\t\tcanvasSize.width = width;\n\t\t\t\tcanvasSize.height = height;\n\t\t\t\trenderer.render({\n\t\t\t\t\ttime,\n\t\t\t\t\tdelta,\n\t\t\t\t\trenderMode: registry.getRenderMode(),\n\t\t\t\t\tuniforms: renderUniforms,\n\t\t\t\t\ttextures: renderTextures,\n\t\t\t\t\tcanvasSize\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tclearError();\n\t\t} catch (error) {\n\t\t\tsetError(error, 'render');\n\t\t} finally {\n\t\t\tregistry.endFrame();\n\t\t}\n\n\t\tif (shouldContinueAfterFrame) {\n\t\t\tscheduleFrame();\n\t\t}\n\t};\n\n\t(async () => {\n\t\ttry {\n\t\t\tconst initialMaterial = resolveActiveMaterial();\n\t\t\tsyncMaterialRuntimeState(initialMaterial);\n\t\t\tactiveRendererSignature = '';\n\t\t\tscheduleFrame();\n\t\t} catch (error) {\n\t\t\tsetError(error, 'initialization');\n\t\t\tscheduleFrame();\n\t\t}\n\t})();\n\n\treturn {\n\t\trequestFrame,\n\t\tinvalidate,\n\t\tadvance,\n\t\tdestroy: () => {\n\t\t\tisDisposed = true;\n\t\t\tif (frameId !== null) {\n\t\t\t\tcancelAnimationFrame(frameId);\n\t\t\t\tframeId = null;\n\t\t\t}\n\t\t\trenderer?.destroy();\n\t\t\tregistry.clear();\n\t\t}\n\t};\n}\n"],"mappings":";;;;;;AAkDA,SAAS,wBAAwB,SAAyB;AACzD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Y;AACZ,MAAI;AAEH,4BADwB,uBAAuB,CACN;AACzC,6BAA0B;AAC1B,kBAAe;WACP,OAAO;AACf,YAAS,OAAO,iBAAiB;AACjC,kBAAe;;KAEb;AAEJ,QAAO;EACN;EACA;EACA;EACA,eAAe;AACd,gBAAa;AACb,OAAI,YAAY,MAAM;AACrB,yBAAqB,QAAQ;AAC7B,cAAU;;AAEX,aAAU,SAAS;AACnB,YAAS,OAAO;;EAEjB"}
|
|
1
|
+
{"version":3,"file":"runtime-loop.js","names":[],"sources":["../../src/lib/core/runtime-loop.ts"],"sourcesContent":["import type { CurrentReadable, CurrentWritable } from './current-value.js';\nimport { resolveMaterial, type FragMaterial, type ResolvedMaterial } from './material.js';\nimport {\n\ttoMotionGPUErrorReport,\n\ttype MotionGPUErrorPhase,\n\ttype MotionGPUErrorReport\n} from './error-report.js';\nimport { createRenderer } from './renderer.js';\nimport { buildRendererPipelineSignature } from './recompile-policy.js';\nimport { assertUniformValueForType } from './uniforms.js';\nimport type { FrameRegistry } from './frame-registry.js';\nimport type {\n\tAnyPass,\n\tFrameInvalidationToken,\n\tOutputColorSpace,\n\tPendingStorageWrite,\n\tRenderer,\n\tRenderTargetDefinitionMap,\n\tStorageBufferDefinitionMap,\n\tTextureMap,\n\tTextureValue,\n\tUniformType,\n\tUniformValue\n} from './types.js';\n\nexport interface MotionGPURuntimeLoopOptions {\n\tcanvas: HTMLCanvasElement;\n\tregistry: FrameRegistry;\n\tsize: CurrentWritable<{ width: number; height: number }>;\n\tdpr: CurrentReadable<number>;\n\tmaxDelta: CurrentReadable<number>;\n\tgetMaterial: () => FragMaterial;\n\tgetRenderTargets: () => RenderTargetDefinitionMap;\n\tgetPasses: () => AnyPass[];\n\tgetClearColor: () => [number, number, number, number];\n\tgetOutputColorSpace: () => OutputColorSpace;\n\tgetAdapterOptions: () => GPURequestAdapterOptions | undefined;\n\tgetDeviceDescriptor: () => GPUDeviceDescriptor | undefined;\n\tgetOnError: () => ((report: MotionGPUErrorReport) => void) | undefined;\n\treportError: (report: MotionGPUErrorReport | null) => void;\n\tgetErrorHistoryLimit?: () => number | undefined;\n\tgetOnErrorHistory?: () => ((history: MotionGPUErrorReport[]) => void) | undefined;\n\treportErrorHistory?: (history: MotionGPUErrorReport[]) => void;\n}\n\nexport interface MotionGPURuntimeLoop {\n\trequestFrame: () => void;\n\tinvalidate: (token?: FrameInvalidationToken) => void;\n\tadvance: () => void;\n\tdestroy: () => void;\n}\n\nfunction getRendererRetryDelayMs(attempt: number): number {\n\treturn Math.min(8000, 250 * 2 ** Math.max(0, attempt - 1));\n}\n\nconst ERROR_CLEAR_GRACE_MS = 750;\n\nexport function createMotionGPURuntimeLoop(\n\toptions: MotionGPURuntimeLoopOptions\n): MotionGPURuntimeLoop {\n\tconst { canvas: canvasElement, registry, size } = options;\n\tlet frameId: number | null = null;\n\tlet renderer: Renderer | null = null;\n\tlet isDisposed = false;\n\tlet previousTime = performance.now() / 1000;\n\tlet activeRendererSignature = '';\n\tlet failedRendererSignature: string | null = null;\n\tlet failedRendererAttempts = 0;\n\tlet nextRendererRetryAt = 0;\n\tlet rendererRebuildPromise: Promise<void> | null = null;\n\n\tconst runtimeUniforms: Record<string, UniformValue> = {};\n\tconst runtimeTextures: TextureMap = {};\n\tlet activeUniforms: Record<string, UniformValue> = {};\n\tlet activeTextures: Record<string, { source?: TextureValue }> = {};\n\tlet uniformKeys: string[] = [];\n\tlet uniformKeySet = new Set<string>();\n\tlet uniformTypes = new Map<string, UniformType>();\n\tlet textureKeys: string[] = [];\n\tlet textureKeySet = new Set<string>();\n\tlet activeMaterialSignature = '';\n\tlet currentCssWidth = -1;\n\tlet currentCssHeight = -1;\n\tconst renderUniforms: Record<string, UniformValue> = {};\n\tconst renderTextures: TextureMap = {};\n\tconst canvasSize = { width: 0, height: 0 };\n\tlet storageBufferKeys: string[] = [];\n\tlet storageBufferKeySet = new Set<string>();\n\tlet storageBufferDefinitions: StorageBufferDefinitionMap = {};\n\tconst pendingStorageWrites: PendingStorageWrite[] = [];\n\tlet shouldContinueAfterFrame = false;\n\tlet activeErrorKey: string | null = null;\n\tlet errorHistory: MotionGPUErrorReport[] = [];\n\tlet errorClearReadyAtMs = 0;\n\tlet lastFrameTimestampMs = performance.now();\n\n\tconst resolveNowMs = (nowMs?: number): number => {\n\t\tif (typeof nowMs === 'number' && Number.isFinite(nowMs)) {\n\t\t\treturn nowMs;\n\t\t}\n\n\t\treturn lastFrameTimestampMs;\n\t};\n\n\tconst getHistoryLimit = (): number => {\n\t\tconst value = options.getErrorHistoryLimit?.() ?? 0;\n\t\tif (!Number.isFinite(value) || value <= 0) {\n\t\t\treturn 0;\n\t\t}\n\n\t\treturn Math.floor(value);\n\t};\n\n\tconst publishErrorHistory = (): void => {\n\t\toptions.reportErrorHistory?.(errorHistory);\n\t\tconst onErrorHistory = options.getOnErrorHistory?.();\n\t\tif (!onErrorHistory) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tonErrorHistory(errorHistory);\n\t\t} catch {\n\t\t\t// User-provided error history handlers must not break runtime error recovery.\n\t\t}\n\t};\n\n\tconst syncErrorHistory = (): void => {\n\t\tconst limit = getHistoryLimit();\n\t\tif (limit <= 0) {\n\t\t\tif (errorHistory.length === 0) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\terrorHistory = [];\n\t\t\tpublishErrorHistory();\n\t\t\treturn;\n\t\t}\n\n\t\tif (errorHistory.length <= limit) {\n\t\t\treturn;\n\t\t}\n\n\t\terrorHistory.splice(0, errorHistory.length - limit);\n\t\tpublishErrorHistory();\n\t};\n\n\tconst setError = (error: unknown, phase: MotionGPUErrorPhase, nowMs?: number): void => {\n\t\tconst report = toMotionGPUErrorReport(error, phase);\n\t\terrorClearReadyAtMs = resolveNowMs(nowMs) + ERROR_CLEAR_GRACE_MS;\n\t\tconst reportKey = JSON.stringify({\n\t\t\tphase: report.phase,\n\t\t\ttitle: report.title,\n\t\t\tmessage: report.message,\n\t\t\trawMessage: report.rawMessage\n\t\t});\n\t\tif (activeErrorKey === reportKey) {\n\t\t\treturn;\n\t\t}\n\t\tactiveErrorKey = reportKey;\n\t\tconst historyLimit = getHistoryLimit();\n\t\tif (historyLimit > 0) {\n\t\t\terrorHistory.push(report);\n\t\t\tif (errorHistory.length > historyLimit) {\n\t\t\t\terrorHistory.splice(0, errorHistory.length - historyLimit);\n\t\t\t}\n\t\t\tpublishErrorHistory();\n\t\t}\n\t\toptions.reportError(report);\n\t\tconst onError = options.getOnError();\n\t\tif (!onError) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tonError(report);\n\t\t} catch {\n\t\t\t// User-provided error handlers must not break runtime error recovery.\n\t\t}\n\t};\n\n\tconst maybeClearError = (nowMs?: number): void => {\n\t\tif (activeErrorKey === null) {\n\t\t\treturn;\n\t\t}\n\t\tif (resolveNowMs(nowMs) < errorClearReadyAtMs) {\n\t\t\treturn;\n\t\t}\n\n\t\tactiveErrorKey = null;\n\t\terrorClearReadyAtMs = 0;\n\t\toptions.reportError(null);\n\t};\n\n\tconst scheduleFrame = (): void => {\n\t\tif (isDisposed || frameId !== null) {\n\t\t\treturn;\n\t\t}\n\n\t\tframeId = requestAnimationFrame(renderFrame);\n\t};\n\n\tconst requestFrame = (): void => {\n\t\tscheduleFrame();\n\t};\n\n\tconst invalidate = (token?: FrameInvalidationToken): void => {\n\t\tregistry.invalidate(token);\n\t\trequestFrame();\n\t};\n\n\tconst advance = (): void => {\n\t\tregistry.advance();\n\t\trequestFrame();\n\t};\n\n\tconst resetRuntimeMaps = (): void => {\n\t\tfor (const key of Object.keys(runtimeUniforms)) {\n\t\t\tif (!uniformKeySet.has(key)) {\n\t\t\t\tdelete runtimeUniforms[key];\n\t\t\t}\n\t\t}\n\n\t\tfor (const key of Object.keys(runtimeTextures)) {\n\t\t\tif (!textureKeySet.has(key)) {\n\t\t\t\tdelete runtimeTextures[key];\n\t\t\t}\n\t\t}\n\t};\n\n\tconst resetRenderPayloadMaps = (): void => {\n\t\tfor (const key of Object.keys(renderUniforms)) {\n\t\t\tif (!uniformKeySet.has(key)) {\n\t\t\t\tdelete renderUniforms[key];\n\t\t\t}\n\t\t}\n\n\t\tfor (const key of Object.keys(renderTextures)) {\n\t\t\tif (!textureKeySet.has(key)) {\n\t\t\t\tdelete renderTextures[key];\n\t\t\t}\n\t\t}\n\t};\n\n\tconst syncMaterialRuntimeState = (materialState: ResolvedMaterial): void => {\n\t\tconst signatureChanged = activeMaterialSignature !== materialState.signature;\n\t\tconst defaultsChanged =\n\t\t\tactiveUniforms !== materialState.uniforms || activeTextures !== materialState.textures;\n\n\t\tif (!signatureChanged && !defaultsChanged) {\n\t\t\treturn;\n\t\t}\n\n\t\tactiveUniforms = materialState.uniforms;\n\t\tactiveTextures = materialState.textures;\n\t\tif (!signatureChanged) {\n\t\t\treturn;\n\t\t}\n\n\t\tuniformKeys = materialState.uniformLayout.entries.map((entry) => entry.name);\n\t\tuniformTypes = new Map(\n\t\t\tmaterialState.uniformLayout.entries.map((entry) => [entry.name, entry.type])\n\t\t);\n\t\ttextureKeys = materialState.textureKeys;\n\t\tuniformKeySet = new Set(uniformKeys);\n\t\ttextureKeySet = new Set(textureKeys);\n\t\tstorageBufferKeys = materialState.storageBufferKeys;\n\t\tstorageBufferKeySet = new Set(storageBufferKeys);\n\t\tstorageBufferDefinitions = (options.getMaterial().storageBuffers ??\n\t\t\t{}) as StorageBufferDefinitionMap;\n\t\tresetRuntimeMaps();\n\t\tresetRenderPayloadMaps();\n\t\tactiveMaterialSignature = materialState.signature;\n\t};\n\n\tconst resolveActiveMaterial = (): ResolvedMaterial => {\n\t\treturn resolveMaterial(options.getMaterial());\n\t};\n\n\tconst setUniform = (name: string, value: UniformValue): void => {\n\t\tif (!uniformKeySet.has(name)) {\n\t\t\tthrow new Error(`Unknown uniform \"${name}\". Declare it in material.uniforms first.`);\n\t\t}\n\t\tconst expectedType = uniformTypes.get(name);\n\t\tif (!expectedType) {\n\t\t\tthrow new Error(`Unknown uniform type for \"${name}\"`);\n\t\t}\n\t\tassertUniformValueForType(expectedType, value);\n\t\truntimeUniforms[name] = value;\n\t};\n\n\tconst setTexture = (name: string, value: TextureValue): void => {\n\t\tif (!textureKeySet.has(name)) {\n\t\t\tthrow new Error(`Unknown texture \"${name}\". Declare it in material.textures first.`);\n\t\t}\n\t\truntimeTextures[name] = value;\n\t};\n\n\tconst writeStorageBuffer = (\n\t\tname: string,\n\t\tdata: ArrayBufferView,\n\t\twriteOptions?: { offset?: number }\n\t): void => {\n\t\tif (!storageBufferKeySet.has(name)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Unknown storage buffer \"${name}\". Declare it in material.storageBuffers first.`\n\t\t\t);\n\t\t}\n\t\tconst definition = storageBufferDefinitions[name];\n\t\tif (!definition) {\n\t\t\tthrow new Error(`Missing definition for storage buffer \"${name}\".`);\n\t\t}\n\t\tconst offset = writeOptions?.offset ?? 0;\n\t\tif (offset < 0 || offset + data.byteLength > definition.size) {\n\t\t\tthrow new Error(\n\t\t\t\t`Storage buffer \"${name}\" write out of bounds: offset=${offset}, dataSize=${data.byteLength}, bufferSize=${definition.size}.`\n\t\t\t);\n\t\t}\n\t\tpendingStorageWrites.push({ name, data, offset });\n\t};\n\n\tconst readStorageBuffer = (name: string): Promise<ArrayBuffer> => {\n\t\tif (!storageBufferKeySet.has(name)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Unknown storage buffer \"${name}\". Declare it in material.storageBuffers first.`\n\t\t\t);\n\t\t}\n\t\tif (!renderer) {\n\t\t\treturn Promise.reject(\n\t\t\t\tnew Error(`Cannot read storage buffer \"${name}\": renderer not initialized.`)\n\t\t\t);\n\t\t}\n\t\tconst gpuBuffer = renderer.getStorageBuffer?.(name);\n\t\tif (!gpuBuffer) {\n\t\t\treturn Promise.reject(new Error(`Storage buffer \"${name}\" not allocated on GPU.`));\n\t\t}\n\t\tconst device = renderer.getDevice?.();\n\t\tif (!device) {\n\t\t\treturn Promise.reject(new Error('Cannot read storage buffer: GPU device unavailable.'));\n\t\t}\n\t\tconst definition = storageBufferDefinitions[name];\n\t\tif (!definition) {\n\t\t\treturn Promise.reject(new Error(`Missing definition for storage buffer \"${name}\".`));\n\t\t}\n\t\tconst stagingBuffer = device.createBuffer({\n\t\t\tsize: definition.size,\n\t\t\tusage: GPUBufferUsage.MAP_READ | GPUBufferUsage.COPY_DST\n\t\t});\n\t\tconst commandEncoder = device.createCommandEncoder();\n\t\tcommandEncoder.copyBufferToBuffer(gpuBuffer, 0, stagingBuffer, 0, definition.size);\n\t\tdevice.queue.submit([commandEncoder.finish()]);\n\t\treturn stagingBuffer.mapAsync(GPUMapMode.READ).then(() => {\n\t\t\tconst result = stagingBuffer.getMappedRange().slice(0);\n\t\t\tstagingBuffer.unmap();\n\t\t\tstagingBuffer.destroy();\n\t\t\treturn result;\n\t\t});\n\t};\n\n\tconst renderFrame = (timestamp: number): void => {\n\t\tframeId = null;\n\t\tif (isDisposed) {\n\t\t\treturn;\n\t\t}\n\t\tlastFrameTimestampMs = timestamp;\n\t\tsyncErrorHistory();\n\n\t\tlet materialState: ResolvedMaterial;\n\t\ttry {\n\t\t\tmaterialState = resolveActiveMaterial();\n\t\t} catch (error) {\n\t\t\tsetError(error, 'initialization', timestamp);\n\t\t\tscheduleFrame();\n\t\t\treturn;\n\t\t}\n\n\t\tshouldContinueAfterFrame = false;\n\n\t\tconst outputColorSpace = options.getOutputColorSpace();\n\t\tconst rendererSignature = buildRendererPipelineSignature({\n\t\t\tmaterialSignature: materialState.signature,\n\t\t\toutputColorSpace\n\t\t});\n\t\tsyncMaterialRuntimeState(materialState);\n\n\t\tif (failedRendererSignature && failedRendererSignature !== rendererSignature) {\n\t\t\tfailedRendererSignature = null;\n\t\t\tfailedRendererAttempts = 0;\n\t\t\tnextRendererRetryAt = 0;\n\t\t}\n\n\t\tif (!renderer || activeRendererSignature !== rendererSignature) {\n\t\t\tif (\n\t\t\t\tfailedRendererSignature === rendererSignature &&\n\t\t\t\tperformance.now() < nextRendererRetryAt\n\t\t\t) {\n\t\t\t\tscheduleFrame();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (!rendererRebuildPromise) {\n\t\t\t\trendererRebuildPromise = (async () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst nextRenderer = await createRenderer({\n\t\t\t\t\t\t\tcanvas: canvasElement,\n\t\t\t\t\t\t\tfragmentWgsl: materialState.fragmentWgsl,\n\t\t\t\t\t\t\tfragmentLineMap: materialState.fragmentLineMap,\n\t\t\t\t\t\t\tfragmentSource: materialState.fragmentSource,\n\t\t\t\t\t\t\tincludeSources: materialState.includeSources,\n\t\t\t\t\t\t\tdefineBlockSource: materialState.defineBlockSource,\n\t\t\t\t\t\t\tmaterialSource: materialState.source,\n\t\t\t\t\t\t\tmaterialSignature: materialState.signature,\n\t\t\t\t\t\t\tuniformLayout: materialState.uniformLayout,\n\t\t\t\t\t\t\ttextureKeys: materialState.textureKeys,\n\t\t\t\t\t\t\ttextureDefinitions: materialState.textures,\n\t\t\t\t\t\t\tstorageBufferKeys: materialState.storageBufferKeys,\n\t\t\t\t\t\t\tstorageBufferDefinitions,\n\t\t\t\t\t\t\tstorageTextureKeys: materialState.storageTextureKeys,\n\t\t\t\t\t\t\tgetRenderTargets: options.getRenderTargets,\n\t\t\t\t\t\t\tgetPasses: options.getPasses,\n\t\t\t\t\t\t\toutputColorSpace,\n\t\t\t\t\t\t\tgetClearColor: options.getClearColor,\n\t\t\t\t\t\t\tgetDpr: () => options.dpr.current,\n\t\t\t\t\t\t\tadapterOptions: options.getAdapterOptions(),\n\t\t\t\t\t\t\tdeviceDescriptor: options.getDeviceDescriptor()\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (isDisposed) {\n\t\t\t\t\t\t\tnextRenderer.destroy();\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\trenderer?.destroy();\n\t\t\t\t\t\trenderer = nextRenderer;\n\t\t\t\t\t\tactiveRendererSignature = rendererSignature;\n\t\t\t\t\t\tfailedRendererSignature = null;\n\t\t\t\t\t\tfailedRendererAttempts = 0;\n\t\t\t\t\t\tnextRendererRetryAt = 0;\n\t\t\t\t\t\tmaybeClearError(performance.now());\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tfailedRendererSignature = rendererSignature;\n\t\t\t\t\t\tfailedRendererAttempts += 1;\n\t\t\t\t\t\tconst retryDelayMs = getRendererRetryDelayMs(failedRendererAttempts);\n\t\t\t\t\t\tnextRendererRetryAt = performance.now() + retryDelayMs;\n\t\t\t\t\t\tsetError(error, 'initialization');\n\t\t\t\t\t} finally {\n\t\t\t\t\t\trendererRebuildPromise = null;\n\t\t\t\t\t\tscheduleFrame();\n\t\t\t\t\t}\n\t\t\t\t})();\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\tconst time = timestamp / 1000;\n\t\tconst rawDelta = Math.max(0, time - previousTime);\n\t\tconst delta = Math.min(rawDelta, options.maxDelta.current);\n\t\tpreviousTime = time;\n\t\tconst rect = canvasElement.getBoundingClientRect();\n\t\tconst width = Math.max(0, Math.floor(rect.width));\n\t\tconst height = Math.max(0, Math.floor(rect.height));\n\t\tif (width !== currentCssWidth || height !== currentCssHeight) {\n\t\t\tcurrentCssWidth = width;\n\t\t\tcurrentCssHeight = height;\n\t\t\tsize.set({ width, height });\n\t\t}\n\n\t\ttry {\n\t\t\tregistry.run({\n\t\t\t\ttime,\n\t\t\t\tdelta,\n\t\t\t\tsetUniform,\n\t\t\t\tsetTexture,\n\t\t\t\twriteStorageBuffer,\n\t\t\t\treadStorageBuffer,\n\t\t\t\tinvalidate,\n\t\t\t\tadvance,\n\t\t\t\trenderMode: registry.getRenderMode(),\n\t\t\t\tautoRender: registry.getAutoRender(),\n\t\t\t\tcanvas: canvasElement\n\t\t\t});\n\n\t\t\tconst shouldRenderFrame = registry.shouldRender();\n\t\t\tshouldContinueAfterFrame =\n\t\t\t\tregistry.getRenderMode() === 'always' ||\n\t\t\t\t(registry.getRenderMode() === 'on-demand' && shouldRenderFrame);\n\n\t\t\tif (shouldRenderFrame) {\n\t\t\t\tfor (const key of uniformKeys) {\n\t\t\t\t\tconst runtimeValue = runtimeUniforms[key];\n\t\t\t\t\trenderUniforms[key] =\n\t\t\t\t\t\truntimeValue === undefined ? (activeUniforms[key] as UniformValue) : runtimeValue;\n\t\t\t\t}\n\n\t\t\t\tfor (const key of textureKeys) {\n\t\t\t\t\tconst runtimeValue = runtimeTextures[key];\n\t\t\t\t\trenderTextures[key] =\n\t\t\t\t\t\truntimeValue === undefined ? (activeTextures[key]?.source ?? null) : runtimeValue;\n\t\t\t\t}\n\n\t\t\t\tcanvasSize.width = width;\n\t\t\t\tcanvasSize.height = height;\n\t\t\t\trenderer.render({\n\t\t\t\t\ttime,\n\t\t\t\t\tdelta,\n\t\t\t\t\trenderMode: registry.getRenderMode(),\n\t\t\t\t\tuniforms: renderUniforms,\n\t\t\t\t\ttextures: renderTextures,\n\t\t\t\t\tcanvasSize,\n\t\t\t\t\tpendingStorageWrites: pendingStorageWrites.length > 0 ? pendingStorageWrites : undefined\n\t\t\t\t});\n\t\t\t\t// Clear in-place after synchronous render() completes — avoids\n\t\t\t\t// the splice(0) copy and eliminates the conditional spread object.\n\t\t\t\tif (pendingStorageWrites.length > 0) {\n\t\t\t\t\tpendingStorageWrites.length = 0;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tmaybeClearError(timestamp);\n\t\t} catch (error) {\n\t\t\tsetError(error, 'render', timestamp);\n\t\t} finally {\n\t\t\tregistry.endFrame();\n\t\t}\n\n\t\tif (shouldContinueAfterFrame) {\n\t\t\tscheduleFrame();\n\t\t}\n\t};\n\n\t(async () => {\n\t\ttry {\n\t\t\tconst initialMaterial = resolveActiveMaterial();\n\t\t\tsyncMaterialRuntimeState(initialMaterial);\n\t\t\tactiveRendererSignature = '';\n\t\t\tscheduleFrame();\n\t\t} catch (error) {\n\t\t\tsetError(error, 'initialization');\n\t\t\tscheduleFrame();\n\t\t}\n\t})();\n\n\treturn {\n\t\trequestFrame,\n\t\tinvalidate,\n\t\tadvance,\n\t\tdestroy: () => {\n\t\t\tisDisposed = true;\n\t\t\tif (frameId !== null) {\n\t\t\t\tcancelAnimationFrame(frameId);\n\t\t\t\tframeId = null;\n\t\t\t}\n\t\t\trenderer?.destroy();\n\t\t\tregistry.clear();\n\t\t}\n\t};\n}\n"],"mappings":";;;;;;AAoDA,SAAS,wBAAwB,SAAyB;AACzD,QAAO,KAAK,IAAI,KAAM,MAAM,KAAK,KAAK,IAAI,GAAG,UAAU,EAAE,CAAC;;AAG3D,IAAM,uBAAuB;AAE7B,SAAgB,2BACf,SACuB;CACvB,MAAM,EAAE,QAAQ,eAAe,UAAU,SAAS;CAClD,IAAI,UAAyB;CAC7B,IAAI,WAA4B;CAChC,IAAI,aAAa;CACjB,IAAI,eAAe,YAAY,KAAK,GAAG;CACvC,IAAI,0BAA0B;CAC9B,IAAI,0BAAyC;CAC7C,IAAI,yBAAyB;CAC7B,IAAI,sBAAsB;CAC1B,IAAI,yBAA+C;CAEnD,MAAM,kBAAgD,EAAE;CACxD,MAAM,kBAA8B,EAAE;CACtC,IAAI,iBAA+C,EAAE;CACrD,IAAI,iBAA4D,EAAE;CAClE,IAAI,cAAwB,EAAE;CAC9B,IAAI,gCAAgB,IAAI,KAAa;CACrC,IAAI,+BAAe,IAAI,KAA0B;CACjD,IAAI,cAAwB,EAAE;CAC9B,IAAI,gCAAgB,IAAI,KAAa;CACrC,IAAI,0BAA0B;CAC9B,IAAI,kBAAkB;CACtB,IAAI,mBAAmB;CACvB,MAAM,iBAA+C,EAAE;CACvD,MAAM,iBAA6B,EAAE;CACrC,MAAM,aAAa;EAAE,OAAO;EAAG,QAAQ;EAAG;CAC1C,IAAI,oBAA8B,EAAE;CACpC,IAAI,sCAAsB,IAAI,KAAa;CAC3C,IAAI,2BAAuD,EAAE;CAC7D,MAAM,uBAA8C,EAAE;CACtD,IAAI,2BAA2B;CAC/B,IAAI,iBAAgC;CACpC,IAA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rB,yBAAqB,QAAQ;AAC7B,cAAU;;AAEX,aAAU,SAAS;AACnB,YAAS,OAAO;;EAEjB"}
|
package/dist/core/shader.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import type { MaterialLineMap, MaterialSourceLocation } from './material-preprocess.js';
|
|
2
|
-
import type { UniformLayout } from './types.js';
|
|
2
|
+
import type { StorageBufferType, UniformLayout } from './types.js';
|
|
3
|
+
type ComputeShaderSourceLocation = {
|
|
4
|
+
kind: 'compute';
|
|
5
|
+
line: number;
|
|
6
|
+
};
|
|
3
7
|
/**
|
|
4
8
|
* 1-based map from generated WGSL lines to original material source lines.
|
|
5
9
|
*/
|
|
6
|
-
export type ShaderLineMap = Array<MaterialSourceLocation | null>;
|
|
10
|
+
export type ShaderLineMap = Array<(MaterialSourceLocation | ComputeShaderSourceLocation) | null>;
|
|
7
11
|
/**
|
|
8
12
|
* Result of shader source generation with line mapping metadata.
|
|
9
13
|
*/
|
|
@@ -28,6 +32,10 @@ export interface BuiltShaderSource {
|
|
|
28
32
|
*/
|
|
29
33
|
export declare function buildShaderSource(fragmentWgsl: string, uniformLayout: UniformLayout, textureKeys?: string[], options?: {
|
|
30
34
|
convertLinearToSrgb?: boolean;
|
|
35
|
+
storageBufferKeys?: string[];
|
|
36
|
+
storageBufferDefinitions?: Record<string, {
|
|
37
|
+
type: StorageBufferType;
|
|
38
|
+
}>;
|
|
31
39
|
}): string;
|
|
32
40
|
/**
|
|
33
41
|
* Assembles complete WGSL shader source with material-source line mapping metadata.
|
|
@@ -35,9 +43,14 @@ export declare function buildShaderSource(fragmentWgsl: string, uniformLayout: U
|
|
|
35
43
|
export declare function buildShaderSourceWithMap(fragmentWgsl: string, uniformLayout: UniformLayout, textureKeys?: string[], options?: {
|
|
36
44
|
convertLinearToSrgb?: boolean;
|
|
37
45
|
fragmentLineMap?: MaterialLineMap;
|
|
46
|
+
storageBufferKeys?: string[];
|
|
47
|
+
storageBufferDefinitions?: Record<string, {
|
|
48
|
+
type: StorageBufferType;
|
|
49
|
+
}>;
|
|
38
50
|
}): BuiltShaderSource;
|
|
39
51
|
/**
|
|
40
52
|
* Converts source location metadata to user-facing diagnostics label.
|
|
41
53
|
*/
|
|
42
|
-
export declare function formatShaderSourceLocation(location: MaterialSourceLocation | null): string | null;
|
|
54
|
+
export declare function formatShaderSourceLocation(location: (MaterialSourceLocation | ComputeShaderSourceLocation) | null): string | null;
|
|
55
|
+
export {};
|
|
43
56
|
//# sourceMappingURL=shader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shader.d.ts","sourceRoot":"","sources":["../../src/lib/core/shader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AACxF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AA+
|
|
1
|
+
{"version":3,"file":"shader.d.ts","sourceRoot":"","sources":["../../src/lib/core/shader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AACxF,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEnE,KAAK,2BAA2B,GAAG;IAClC,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACb,CAAC;AA+IF;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,KAAK,CAAC,CAAC,sBAAsB,GAAG,2BAA2B,CAAC,GAAG,IAAI,CAAC,CAAC;AAEjG;;GAEG;AACH,MAAM,WAAW,iBAAiB;IACjC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,OAAO,EAAE,aAAa,CAAC;CACvB;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAChC,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,aAAa,EAC5B,WAAW,GAAE,MAAM,EAAO,EAC1B,OAAO,CAAC,EAAE;IACT,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,wBAAwB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,iBAAiB,CAAA;KAAE,CAAC,CAAC;CACvE,GACC,MAAM,CAwDR;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CACvC,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,aAAa,EAC5B,WAAW,GAAE,MAAM,EAAO,EAC1B,OAAO,CAAC,EAAE;IACT,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,wBAAwB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,iBAAiB,CAAA;KAAE,CAAC,CAAC;CACvE,GACC,iBAAiB,CA4BnB;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CACzC,QAAQ,EAAE,CAAC,sBAAsB,GAAG,2BAA2B,CAAC,GAAG,IAAI,GACrE,MAAM,GAAG,IAAI,CAkBf"}
|
package/dist/core/shader.js
CHANGED
|
@@ -42,6 +42,21 @@ function buildTextureBindings(textureKeys) {
|
|
|
42
42
|
return declarations.join("\n");
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
|
+
* Builds read-only storage buffer bindings for fragment shader.
|
|
46
|
+
*/
|
|
47
|
+
function buildFragmentStorageBufferBindings(storageBufferKeys, definitions) {
|
|
48
|
+
if (storageBufferKeys.length === 0) return "";
|
|
49
|
+
const declarations = [];
|
|
50
|
+
for (let index = 0; index < storageBufferKeys.length; index += 1) {
|
|
51
|
+
const key = storageBufferKeys[index];
|
|
52
|
+
if (key === void 0) continue;
|
|
53
|
+
const definition = definitions[key];
|
|
54
|
+
if (!definition) continue;
|
|
55
|
+
declarations.push(`@group(1) @binding(${index}) var<storage, read> ${key}: ${definition.type};`);
|
|
56
|
+
}
|
|
57
|
+
return declarations.join("\n");
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
45
60
|
* Optionally returns helper WGSL for linear-to-sRGB conversion.
|
|
46
61
|
*/
|
|
47
62
|
function buildColorTransformHelpers(enableSrgbTransform) {
|
|
@@ -86,6 +101,9 @@ function buildShaderSource(fragmentWgsl, uniformLayout, textureKeys = [], option
|
|
|
86
101
|
const keepAliveExpression = getKeepAliveExpression(uniformLayout);
|
|
87
102
|
const textureBindings = buildTextureBindings(textureKeys);
|
|
88
103
|
const enableSrgbTransform = options?.convertLinearToSrgb ?? false;
|
|
104
|
+
const colorTransformHelpers = buildColorTransformHelpers(enableSrgbTransform);
|
|
105
|
+
const fragmentOutput = buildFragmentOutput(keepAliveExpression, enableSrgbTransform);
|
|
106
|
+
const storageBufferBindings = buildFragmentStorageBufferBindings(options?.storageBufferKeys ?? [], options?.storageBufferDefinitions ?? {});
|
|
89
107
|
return `
|
|
90
108
|
struct MotionGPUFrame {
|
|
91
109
|
time: f32,
|
|
@@ -100,7 +118,8 @@ struct MotionGPUUniforms {
|
|
|
100
118
|
@group(0) @binding(0) var<uniform> motiongpuFrame: MotionGPUFrame;
|
|
101
119
|
@group(0) @binding(1) var<uniform> motiongpuUniforms: MotionGPUUniforms;
|
|
102
120
|
${textureBindings}
|
|
103
|
-
${
|
|
121
|
+
${storageBufferBindings ? "\n" + storageBufferBindings : ""}
|
|
122
|
+
${colorTransformHelpers}
|
|
104
123
|
|
|
105
124
|
struct MotionGPUVertexOut {
|
|
106
125
|
@builtin(position) position: vec4f,
|
|
@@ -126,7 +145,7 @@ ${fragmentWgsl}
|
|
|
126
145
|
|
|
127
146
|
@fragment
|
|
128
147
|
fn motiongpuFragment(in: MotionGPUVertexOut) -> @location(0) vec4f {
|
|
129
|
-
${
|
|
148
|
+
${fragmentOutput}
|
|
130
149
|
}
|
|
131
150
|
`;
|
|
132
151
|
}
|
|
@@ -163,6 +182,7 @@ function formatShaderSourceLocation(location) {
|
|
|
163
182
|
if (!location) return null;
|
|
164
183
|
if (location.kind === "fragment") return `fragment line ${location.line}`;
|
|
165
184
|
if (location.kind === "include") return `include <${location.include}> line ${location.line}`;
|
|
185
|
+
if (location.kind === "compute") return `compute line ${location.line}`;
|
|
166
186
|
return `define "${location.define}" line ${location.line}`;
|
|
167
187
|
}
|
|
168
188
|
//#endregion
|
package/dist/core/shader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shader.js","names":[],"sources":["../../src/lib/core/shader.ts"],"sourcesContent":["import { assertUniformName } from './uniforms.js';\nimport type { MaterialLineMap, MaterialSourceLocation } from './material-preprocess.js';\nimport type { UniformLayout } from './types.js';\n\n/**\n * Fallback uniform field used when no custom uniforms are provided.\n */\nconst DEFAULT_UNIFORM_FIELD = 'motiongpu_unused: vec4f,';\n\n/**\n * Builds WGSL struct fields for user uniforms.\n */\nfunction buildUniformStruct(layout: UniformLayout): string {\n\tif (layout.entries.length === 0) {\n\t\treturn DEFAULT_UNIFORM_FIELD;\n\t}\n\n\treturn layout.entries\n\t\t.map((entry) => {\n\t\t\tassertUniformName(entry.name);\n\t\t\treturn `${entry.name}: ${entry.type},`;\n\t\t})\n\t\t.join('\\n\\t');\n}\n\n/**\n * Builds a numeric expression that references one uniform value to keep bindings alive.\n */\nfunction getKeepAliveExpression(layout: UniformLayout): string {\n\tif (layout.entries.length === 0) {\n\t\treturn 'motiongpuUniforms.motiongpu_unused.x';\n\t}\n\n\tconst [firstEntry] = layout.entries;\n\tif (!firstEntry) {\n\t\treturn 'motiongpuUniforms.motiongpu_unused.x';\n\t}\n\n\tif (firstEntry.type === 'f32') {\n\t\treturn `motiongpuUniforms.${firstEntry.name}`;\n\t}\n\n\tif (firstEntry.type === 'mat4x4f') {\n\t\treturn `motiongpuUniforms.${firstEntry.name}[0].x`;\n\t}\n\n\treturn `motiongpuUniforms.${firstEntry.name}.x`;\n}\n\n/**\n * Builds texture sampler/texture binding declarations.\n */\nfunction buildTextureBindings(textureKeys: string[]): string {\n\tif (textureKeys.length === 0) {\n\t\treturn '';\n\t}\n\n\tconst declarations: string[] = [];\n\n\tfor (let index = 0; index < textureKeys.length; index += 1) {\n\t\tconst key = textureKeys[index];\n\t\tif (key === undefined) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tassertUniformName(key);\n\t\tconst binding = 2 + index * 2;\n\t\tdeclarations.push(`@group(0) @binding(${binding}) var ${key}Sampler: sampler;`);\n\t\tdeclarations.push(`@group(0) @binding(${binding + 1}) var ${key}: texture_2d<f32>;`);\n\t}\n\n\treturn declarations.join('\\n');\n}\n\n/**\n * Optionally returns helper WGSL for linear-to-sRGB conversion.\n */\nfunction buildColorTransformHelpers(enableSrgbTransform: boolean): string {\n\tif (!enableSrgbTransform) {\n\t\treturn '';\n\t}\n\n\treturn `\nfn motiongpuLinearToSrgb(linearColor: vec3f) -> vec3f {\n\tlet cutoff = vec3f(0.0031308);\n\tlet lower = linearColor * 12.92;\n\tlet higher = vec3f(1.055) * pow(linearColor, vec3f(1.0 / 2.4)) - vec3f(0.055);\n\treturn select(lower, higher, linearColor > cutoff);\n}\n`;\n}\n\n/**\n * Builds fragment output code with optional color-space conversion.\n */\nfunction buildFragmentOutput(keepAliveExpression: string, enableSrgbTransform: boolean): string {\n\tif (enableSrgbTransform) {\n\t\treturn `\n\tlet fragColor = frag(in.uv);\n\tlet motiongpuKeepAlive = ${keepAliveExpression};\n\tlet motiongpuLinear = vec4f(fragColor.rgb + motiongpuKeepAlive * 0.0, fragColor.a);\n\tlet motiongpuSrgb = motiongpuLinearToSrgb(max(motiongpuLinear.rgb, vec3f(0.0)));\n\treturn vec4f(motiongpuSrgb, motiongpuLinear.a);\n`;\n\t}\n\n\treturn `\n\tlet fragColor = frag(in.uv);\n\tlet motiongpuKeepAlive = ${keepAliveExpression};\n\treturn vec4f(fragColor.rgb + motiongpuKeepAlive * 0.0, fragColor.a);\n`;\n}\n\n/**\n * 1-based map from generated WGSL lines to original material source lines.\n */\nexport type ShaderLineMap = Array<MaterialSourceLocation | null>;\n\n/**\n * Result of shader source generation with line mapping metadata.\n */\nexport interface BuiltShaderSource {\n\t/**\n\t * Full WGSL source code.\n\t */\n\tcode: string;\n\t/**\n\t * 1-based generated-line map to material source locations.\n\t */\n\tlineMap: ShaderLineMap;\n}\n\n/**\n * Assembles complete WGSL shader source used by the fullscreen renderer pipeline.\n *\n * @param fragmentWgsl - User fragment shader code containing `frag(uv: vec2f) -> vec4f`.\n * @param uniformLayout - Resolved uniform layout.\n * @param textureKeys - Sorted texture keys.\n * @param options - Shader build options.\n * @returns Complete WGSL source for vertex + fragment stages.\n */\nexport function buildShaderSource(\n\tfragmentWgsl: string,\n\tuniformLayout: UniformLayout,\n\ttextureKeys: string[] = [],\n\toptions?: { convertLinearToSrgb?: boolean }\n): string {\n\tconst uniformFields = buildUniformStruct(uniformLayout);\n\tconst keepAliveExpression = getKeepAliveExpression(uniformLayout);\n\tconst textureBindings = buildTextureBindings(textureKeys);\n\tconst enableSrgbTransform = options?.convertLinearToSrgb ?? false;\n\tconst colorTransformHelpers = buildColorTransformHelpers(enableSrgbTransform);\n\tconst fragmentOutput = buildFragmentOutput(keepAliveExpression, enableSrgbTransform);\n\n\treturn `\nstruct 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${textureBindings}\n${colorTransformHelpers}\n\nstruct MotionGPUVertexOut {\n\t@builtin(position) position: vec4f,\n\t@location(0) uv: vec2f,\n};\n\n@vertex\nfn motiongpuVertex(@builtin(vertex_index) index: u32) -> MotionGPUVertexOut {\n\tvar positions = array<vec2f, 3>(\n\t\tvec2f(-1.0, -3.0),\n\t\tvec2f(-1.0, 1.0),\n\t\tvec2f(3.0, 1.0)\n\t);\n\n\tlet position = positions[index];\n\tvar out: MotionGPUVertexOut;\n\tout.position = vec4f(position, 0.0, 1.0);\n\tout.uv = (position + vec2f(1.0, 1.0)) * 0.5;\n\treturn out;\n}\n\n${fragmentWgsl}\n\n@fragment\nfn motiongpuFragment(in: MotionGPUVertexOut) -> @location(0) vec4f {\n\t${fragmentOutput}\n}\n`;\n}\n\n/**\n * Assembles complete WGSL shader source with material-source line mapping metadata.\n */\nexport function buildShaderSourceWithMap(\n\tfragmentWgsl: string,\n\tuniformLayout: UniformLayout,\n\ttextureKeys: string[] = [],\n\toptions?: {\n\t\tconvertLinearToSrgb?: boolean;\n\t\tfragmentLineMap?: MaterialLineMap;\n\t}\n): BuiltShaderSource {\n\tconst code = buildShaderSource(fragmentWgsl, uniformLayout, textureKeys, options);\n\tconst fragmentStartIndex = code.indexOf(fragmentWgsl);\n\tconst lineCount = code.split('\\n').length;\n\tconst lineMap: ShaderLineMap = new Array(lineCount + 1).fill(null);\n\n\tif (fragmentStartIndex === -1) {\n\t\treturn {\n\t\t\tcode,\n\t\t\tlineMap\n\t\t};\n\t}\n\n\tconst fragmentStartLine = code.slice(0, fragmentStartIndex).split('\\n').length;\n\tconst fragmentLineCount = fragmentWgsl.split('\\n').length;\n\n\tfor (let line = 0; line < fragmentLineCount; line += 1) {\n\t\tconst generatedLine = fragmentStartLine + line;\n\t\tlineMap[generatedLine] = options?.fragmentLineMap?.[line + 1] ?? {\n\t\t\tkind: 'fragment',\n\t\t\tline: line + 1\n\t\t};\n\t}\n\n\treturn {\n\t\tcode,\n\t\tlineMap\n\t};\n}\n\n/**\n * Converts source location metadata to user-facing diagnostics label.\n */\nexport function formatShaderSourceLocation(location: MaterialSourceLocation | null): string | null {\n\tif (!location) {\n\t\treturn null;\n\t}\n\n\tif (location.kind === 'fragment') {\n\t\treturn `fragment line ${location.line}`;\n\t}\n\n\tif (location.kind === 'include') {\n\t\treturn `include <${location.include}> line ${location.line}`;\n\t}\n\n\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shader.ts"],"sourcesContent":["import { assertUniformName } from './uniforms.js';\nimport type { MaterialLineMap, MaterialSourceLocation } from './material-preprocess.js';\nimport type { StorageBufferType, UniformLayout } from './types.js';\n\ntype ComputeShaderSourceLocation = {\n\tkind: 'compute';\n\tline: number;\n};\n\n/**\n * Fallback uniform field used when no custom uniforms are provided.\n */\nconst DEFAULT_UNIFORM_FIELD = 'motiongpu_unused: vec4f,';\n\n/**\n * Builds WGSL struct fields for user uniforms.\n */\nfunction buildUniformStruct(layout: UniformLayout): string {\n\tif (layout.entries.length === 0) {\n\t\treturn DEFAULT_UNIFORM_FIELD;\n\t}\n\n\treturn layout.entries\n\t\t.map((entry) => {\n\t\t\tassertUniformName(entry.name);\n\t\t\treturn `${entry.name}: ${entry.type},`;\n\t\t})\n\t\t.join('\\n\\t');\n}\n\n/**\n * Builds a numeric expression that references one uniform value to keep bindings alive.\n */\nfunction getKeepAliveExpression(layout: UniformLayout): string {\n\tif (layout.entries.length === 0) {\n\t\treturn 'motiongpuUniforms.motiongpu_unused.x';\n\t}\n\n\tconst [firstEntry] = layout.entries;\n\tif (!firstEntry) {\n\t\treturn 'motiongpuUniforms.motiongpu_unused.x';\n\t}\n\n\tif (firstEntry.type === 'f32') {\n\t\treturn `motiongpuUniforms.${firstEntry.name}`;\n\t}\n\n\tif (firstEntry.type === 'mat4x4f') {\n\t\treturn `motiongpuUniforms.${firstEntry.name}[0].x`;\n\t}\n\n\treturn `motiongpuUniforms.${firstEntry.name}.x`;\n}\n\n/**\n * Builds texture sampler/texture binding declarations.\n */\nfunction buildTextureBindings(textureKeys: string[]): string {\n\tif (textureKeys.length === 0) {\n\t\treturn '';\n\t}\n\n\tconst declarations: string[] = [];\n\n\tfor (let index = 0; index < textureKeys.length; index += 1) {\n\t\tconst key = textureKeys[index];\n\t\tif (key === undefined) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tassertUniformName(key);\n\t\tconst binding = 2 + index * 2;\n\t\tdeclarations.push(`@group(0) @binding(${binding}) var ${key}Sampler: sampler;`);\n\t\tdeclarations.push(`@group(0) @binding(${binding + 1}) var ${key}: texture_2d<f32>;`);\n\t}\n\n\treturn declarations.join('\\n');\n}\n\n/**\n * Builds read-only storage buffer bindings for fragment shader.\n */\nfunction buildFragmentStorageBufferBindings(\n\tstorageBufferKeys: string[],\n\tdefinitions: Record<string, { type: StorageBufferType }>\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\tdeclarations.push(\n\t\t\t`@group(1) @binding(${index}) var<storage, read> ${key}: ${definition.type};`\n\t\t);\n\t}\n\n\treturn declarations.join('\\n');\n}\n\n/**\n * Optionally returns helper WGSL for linear-to-sRGB conversion.\n */\nfunction buildColorTransformHelpers(enableSrgbTransform: boolean): string {\n\tif (!enableSrgbTransform) {\n\t\treturn '';\n\t}\n\n\treturn `\nfn motiongpuLinearToSrgb(linearColor: vec3f) -> vec3f {\n\tlet cutoff = vec3f(0.0031308);\n\tlet lower = linearColor * 12.92;\n\tlet higher = vec3f(1.055) * pow(linearColor, vec3f(1.0 / 2.4)) - vec3f(0.055);\n\treturn select(lower, higher, linearColor > cutoff);\n}\n`;\n}\n\n/**\n * Builds fragment output code with optional color-space conversion.\n */\nfunction buildFragmentOutput(keepAliveExpression: string, enableSrgbTransform: boolean): string {\n\tif (enableSrgbTransform) {\n\t\treturn `\n\tlet fragColor = frag(in.uv);\n\tlet motiongpuKeepAlive = ${keepAliveExpression};\n\tlet motiongpuLinear = vec4f(fragColor.rgb + motiongpuKeepAlive * 0.0, fragColor.a);\n\tlet motiongpuSrgb = motiongpuLinearToSrgb(max(motiongpuLinear.rgb, vec3f(0.0)));\n\treturn vec4f(motiongpuSrgb, motiongpuLinear.a);\n`;\n\t}\n\n\treturn `\n\tlet fragColor = frag(in.uv);\n\tlet motiongpuKeepAlive = ${keepAliveExpression};\n\treturn vec4f(fragColor.rgb + motiongpuKeepAlive * 0.0, fragColor.a);\n`;\n}\n\n/**\n * 1-based map from generated WGSL lines to original material source lines.\n */\nexport type ShaderLineMap = Array<(MaterialSourceLocation | ComputeShaderSourceLocation) | null>;\n\n/**\n * Result of shader source generation with line mapping metadata.\n */\nexport interface BuiltShaderSource {\n\t/**\n\t * Full WGSL source code.\n\t */\n\tcode: string;\n\t/**\n\t * 1-based generated-line map to material source locations.\n\t */\n\tlineMap: ShaderLineMap;\n}\n\n/**\n * Assembles complete WGSL shader source used by the fullscreen renderer pipeline.\n *\n * @param fragmentWgsl - User fragment shader code containing `frag(uv: vec2f) -> vec4f`.\n * @param uniformLayout - Resolved uniform layout.\n * @param textureKeys - Sorted texture keys.\n * @param options - Shader build options.\n * @returns Complete WGSL source for vertex + fragment stages.\n */\nexport function buildShaderSource(\n\tfragmentWgsl: string,\n\tuniformLayout: UniformLayout,\n\ttextureKeys: string[] = [],\n\toptions?: {\n\t\tconvertLinearToSrgb?: boolean;\n\t\tstorageBufferKeys?: string[];\n\t\tstorageBufferDefinitions?: Record<string, { type: StorageBufferType }>;\n\t}\n): string {\n\tconst uniformFields = buildUniformStruct(uniformLayout);\n\tconst keepAliveExpression = getKeepAliveExpression(uniformLayout);\n\tconst textureBindings = buildTextureBindings(textureKeys);\n\tconst enableSrgbTransform = options?.convertLinearToSrgb ?? false;\n\tconst colorTransformHelpers = buildColorTransformHelpers(enableSrgbTransform);\n\tconst fragmentOutput = buildFragmentOutput(keepAliveExpression, enableSrgbTransform);\n\tconst storageBufferBindings = buildFragmentStorageBufferBindings(\n\t\toptions?.storageBufferKeys ?? [],\n\t\toptions?.storageBufferDefinitions ?? {}\n\t);\n\n\treturn `\nstruct 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${textureBindings}\n${storageBufferBindings ? '\\n' + storageBufferBindings : ''}\n${colorTransformHelpers}\n\nstruct MotionGPUVertexOut {\n\t@builtin(position) position: vec4f,\n\t@location(0) uv: vec2f,\n};\n\n@vertex\nfn motiongpuVertex(@builtin(vertex_index) index: u32) -> MotionGPUVertexOut {\n\tvar positions = array<vec2f, 3>(\n\t\tvec2f(-1.0, -3.0),\n\t\tvec2f(-1.0, 1.0),\n\t\tvec2f(3.0, 1.0)\n\t);\n\n\tlet position = positions[index];\n\tvar out: MotionGPUVertexOut;\n\tout.position = vec4f(position, 0.0, 1.0);\n\tout.uv = (position + vec2f(1.0, 1.0)) * 0.5;\n\treturn out;\n}\n\n${fragmentWgsl}\n\n@fragment\nfn motiongpuFragment(in: MotionGPUVertexOut) -> @location(0) vec4f {\n\t${fragmentOutput}\n}\n`;\n}\n\n/**\n * Assembles complete WGSL shader source with material-source line mapping metadata.\n */\nexport function buildShaderSourceWithMap(\n\tfragmentWgsl: string,\n\tuniformLayout: UniformLayout,\n\ttextureKeys: string[] = [],\n\toptions?: {\n\t\tconvertLinearToSrgb?: boolean;\n\t\tfragmentLineMap?: MaterialLineMap;\n\t\tstorageBufferKeys?: string[];\n\t\tstorageBufferDefinitions?: Record<string, { type: StorageBufferType }>;\n\t}\n): BuiltShaderSource {\n\tconst code = buildShaderSource(fragmentWgsl, uniformLayout, textureKeys, options);\n\tconst fragmentStartIndex = code.indexOf(fragmentWgsl);\n\tconst lineCount = code.split('\\n').length;\n\tconst lineMap: ShaderLineMap = new Array(lineCount + 1).fill(null);\n\n\tif (fragmentStartIndex === -1) {\n\t\treturn {\n\t\t\tcode,\n\t\t\tlineMap\n\t\t};\n\t}\n\n\tconst fragmentStartLine = code.slice(0, fragmentStartIndex).split('\\n').length;\n\tconst fragmentLineCount = fragmentWgsl.split('\\n').length;\n\n\tfor (let line = 0; line < fragmentLineCount; line += 1) {\n\t\tconst generatedLine = fragmentStartLine + line;\n\t\tlineMap[generatedLine] = options?.fragmentLineMap?.[line + 1] ?? {\n\t\t\tkind: 'fragment',\n\t\t\tline: line + 1\n\t\t};\n\t}\n\n\treturn {\n\t\tcode,\n\t\tlineMap\n\t};\n}\n\n/**\n * Converts source location metadata to user-facing diagnostics label.\n */\nexport function formatShaderSourceLocation(\n\tlocation: (MaterialSourceLocation | ComputeShaderSourceLocation) | null\n): string | null {\n\tif (!location) {\n\t\treturn null;\n\t}\n\n\tif (location.kind === 'fragment') {\n\t\treturn `fragment line ${location.line}`;\n\t}\n\n\tif (location.kind === 'include') {\n\t\treturn `include <${location.include}> line ${location.line}`;\n\t}\n\n\tif (location.kind === 'compute') {\n\t\treturn `compute line ${location.line}`;\n\t}\n\n\treturn `define \"${location.define}\" line ${location.line}`;\n}\n"],"mappings":";;;;;AAYA,IAAM,wBAAwB;;;;AAK9B,SAAS,mBAAmB,QAA+B;AAC1D,KAAI,OAAO,QAAQ,WAAW,EAC7B,QAAO;AAGR,QAAO,OAAO,QACZ,KAAK,UAAU;AACf,oBAAkB,MAAM,KAAK;AAC7B,SAAO,GAAG,MAAM,KAAK,IAAI,MAAM,KAAK;GACnC,CACD,KAAK,MAAO;;;;;AAMf,SAAS,uBAAuB,QAA+B;AAC9D,KAAI,OAAO,QAAQ,WAAW,EAC7B,QAAO;CAGR,MAAM,CAAC,cAAc,OAAO;AAC5B,KAAI,CAAC,WACJ,QAAO;AAGR,KAAI,WAAW,SAAS,MACvB,QAAO,qBAAqB,WAAW;AAGxC,KAAI,WAAW,SAAS,UACvB,QAAO,qBAAqB,WAAW,KAAK;AAG7C,QAAO,qBAAqB,WAAW,KAAK;;;;;AAM7C,SAAS,qBAAqB,aAA+B;AAC5D,KAAI,YAAY,WAAW,EAC1B,QAAO;CAGR,MAAM,eAAyB,EAAE;AAEjC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storage-compatible texture formats for `texture_storage_2d`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const STORAGE_TEXTURE_FORMATS: ReadonlySet<GPUTextureFormat>;
|
|
7
|
+
/**
|
|
8
|
+
* Validates a single storage buffer definition.
|
|
9
|
+
*
|
|
10
|
+
* @param name - Buffer identifier.
|
|
11
|
+
* @param definition - Storage buffer definition to validate.
|
|
12
|
+
* @throws {Error} When any field is invalid.
|
|
13
|
+
*/
|
|
14
|
+
export declare function assertStorageBufferDefinition(name: string, definition: StorageBufferDefinition): void;
|
|
15
|
+
/**
|
|
16
|
+
* Validates and returns sorted storage buffer keys.
|
|
17
|
+
*
|
|
18
|
+
* @param definitions - Storage buffer definition map.
|
|
19
|
+
* @returns Lexicographically sorted buffer keys.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveStorageBufferKeys(definitions: StorageBufferDefinitionMap): string[];
|
|
22
|
+
/**
|
|
23
|
+
* Normalizes a storage buffer definition with defaults applied.
|
|
24
|
+
*
|
|
25
|
+
* @param definition - Raw definition.
|
|
26
|
+
* @returns Normalized definition with access default.
|
|
27
|
+
*/
|
|
28
|
+
export declare function normalizeStorageBufferDefinition(definition: StorageBufferDefinition): Required<Pick<StorageBufferDefinition, 'size' | 'type' | 'access'>>;
|
|
29
|
+
/**
|
|
30
|
+
* Validates that a texture format is storage-compatible.
|
|
31
|
+
*
|
|
32
|
+
* @param name - Texture identifier.
|
|
33
|
+
* @param format - GPU texture format.
|
|
34
|
+
* @throws {Error} When format is not storage-compatible.
|
|
35
|
+
*/
|
|
36
|
+
export declare function assertStorageTextureFormat(name: string, format: GPUTextureFormat): void;
|
|
37
|
+
//# sourceMappingURL=storage-buffers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-buffers.d.ts","sourceRoot":"","sources":["../../src/lib/core/storage-buffers.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EACX,uBAAuB,EACvB,0BAA0B,EAE1B,MAAM,YAAY,CAAC;AAgBpB;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,WAAW,CAAC,gBAAgB,CAkB1C,CAAC;AAEzB;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAC5C,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,uBAAuB,GACjC,IAAI,CAsCN;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,0BAA0B,GAAG,MAAM,EAAE,CAS1F;AAED;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAC/C,UAAU,EAAE,uBAAuB,GACjC,QAAQ,CAAC,IAAI,CAAC,uBAAuB,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC,CAAC,CAMrE;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAOvF"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { assertUniformName } from "./uniforms.js";
|
|
2
|
+
//#region src/lib/core/storage-buffers.ts
|
|
3
|
+
/**
|
|
4
|
+
* Valid WGSL storage buffer element types.
|
|
5
|
+
*/
|
|
6
|
+
var VALID_STORAGE_BUFFER_TYPES = new Set([
|
|
7
|
+
"array<f32>",
|
|
8
|
+
"array<vec2f>",
|
|
9
|
+
"array<vec3f>",
|
|
10
|
+
"array<vec4f>",
|
|
11
|
+
"array<u32>",
|
|
12
|
+
"array<i32>",
|
|
13
|
+
"array<vec4u>",
|
|
14
|
+
"array<vec4i>"
|
|
15
|
+
]);
|
|
16
|
+
/**
|
|
17
|
+
* Storage-compatible texture formats for `texture_storage_2d`.
|
|
18
|
+
*/
|
|
19
|
+
var STORAGE_TEXTURE_FORMATS = new Set([
|
|
20
|
+
"r32float",
|
|
21
|
+
"r32sint",
|
|
22
|
+
"r32uint",
|
|
23
|
+
"rg32float",
|
|
24
|
+
"rg32sint",
|
|
25
|
+
"rg32uint",
|
|
26
|
+
"rgba8unorm",
|
|
27
|
+
"rgba8snorm",
|
|
28
|
+
"rgba8uint",
|
|
29
|
+
"rgba8sint",
|
|
30
|
+
"rgba16float",
|
|
31
|
+
"rgba16uint",
|
|
32
|
+
"rgba16sint",
|
|
33
|
+
"rgba32float",
|
|
34
|
+
"rgba32uint",
|
|
35
|
+
"rgba32sint",
|
|
36
|
+
"bgra8unorm"
|
|
37
|
+
]);
|
|
38
|
+
/**
|
|
39
|
+
* Validates a single storage buffer definition.
|
|
40
|
+
*
|
|
41
|
+
* @param name - Buffer identifier.
|
|
42
|
+
* @param definition - Storage buffer definition to validate.
|
|
43
|
+
* @throws {Error} When any field is invalid.
|
|
44
|
+
*/
|
|
45
|
+
function assertStorageBufferDefinition(name, definition) {
|
|
46
|
+
assertUniformName(name);
|
|
47
|
+
if (!Number.isFinite(definition.size) || definition.size <= 0) throw new Error(`Storage buffer "${name}" size must be a finite number greater than 0, got ${definition.size}`);
|
|
48
|
+
if (definition.size % 4 !== 0) throw new Error(`Storage buffer "${name}" size must be a multiple of 4, got ${definition.size}`);
|
|
49
|
+
if (!VALID_STORAGE_BUFFER_TYPES.has(definition.type)) throw new Error(`Storage buffer "${name}" has unknown type "${definition.type}". Supported types: ${[...VALID_STORAGE_BUFFER_TYPES].join(", ")}`);
|
|
50
|
+
if (definition.access !== void 0 && definition.access !== "read" && definition.access !== "read-write") throw new Error(`Storage buffer "${name}" has invalid access mode "${definition.access}". Use 'read' or 'read-write'.`);
|
|
51
|
+
if (definition.initialData !== void 0) {
|
|
52
|
+
if (definition.initialData.byteLength > definition.size) throw new Error(`Storage buffer "${name}" initialData byte length (${definition.initialData.byteLength}) exceeds buffer size (${definition.size})`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Validates and returns sorted storage buffer keys.
|
|
57
|
+
*
|
|
58
|
+
* @param definitions - Storage buffer definition map.
|
|
59
|
+
* @returns Lexicographically sorted buffer keys.
|
|
60
|
+
*/
|
|
61
|
+
function resolveStorageBufferKeys(definitions) {
|
|
62
|
+
const keys = Object.keys(definitions).sort();
|
|
63
|
+
for (const key of keys) {
|
|
64
|
+
const definition = definitions[key];
|
|
65
|
+
if (definition) assertStorageBufferDefinition(key, definition);
|
|
66
|
+
}
|
|
67
|
+
return keys;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Normalizes a storage buffer definition with defaults applied.
|
|
71
|
+
*
|
|
72
|
+
* @param definition - Raw definition.
|
|
73
|
+
* @returns Normalized definition with access default.
|
|
74
|
+
*/
|
|
75
|
+
function normalizeStorageBufferDefinition(definition) {
|
|
76
|
+
return {
|
|
77
|
+
size: definition.size,
|
|
78
|
+
type: definition.type,
|
|
79
|
+
access: definition.access ?? "read-write"
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Validates that a texture format is storage-compatible.
|
|
84
|
+
*
|
|
85
|
+
* @param name - Texture identifier.
|
|
86
|
+
* @param format - GPU texture format.
|
|
87
|
+
* @throws {Error} When format is not storage-compatible.
|
|
88
|
+
*/
|
|
89
|
+
function assertStorageTextureFormat(name, format) {
|
|
90
|
+
if (!STORAGE_TEXTURE_FORMATS.has(format)) throw new Error(`Texture "${name}" with storage:true requires a storage-compatible format, but got "${format}". Supported formats: ${[...STORAGE_TEXTURE_FORMATS].join(", ")}`);
|
|
91
|
+
}
|
|
92
|
+
//#endregion
|
|
93
|
+
export { STORAGE_TEXTURE_FORMATS, assertStorageBufferDefinition, assertStorageTextureFormat, normalizeStorageBufferDefinition, resolveStorageBufferKeys };
|
|
94
|
+
|
|
95
|
+
//# sourceMappingURL=storage-buffers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-buffers.js","names":[],"sources":["../../src/lib/core/storage-buffers.ts"],"sourcesContent":["import { assertUniformName } from './uniforms.js';\nimport type {\n\tStorageBufferDefinition,\n\tStorageBufferDefinitionMap,\n\tStorageBufferType\n} from './types.js';\n\n/**\n * Valid WGSL storage buffer element types.\n */\nconst VALID_STORAGE_BUFFER_TYPES: ReadonlySet<string> = new Set<StorageBufferType>([\n\t'array<f32>',\n\t'array<vec2f>',\n\t'array<vec3f>',\n\t'array<vec4f>',\n\t'array<u32>',\n\t'array<i32>',\n\t'array<vec4u>',\n\t'array<vec4i>'\n]);\n\n/**\n * Storage-compatible texture formats for `texture_storage_2d`.\n */\nexport const STORAGE_TEXTURE_FORMATS: ReadonlySet<GPUTextureFormat> = new Set([\n\t'r32float',\n\t'r32sint',\n\t'r32uint',\n\t'rg32float',\n\t'rg32sint',\n\t'rg32uint',\n\t'rgba8unorm',\n\t'rgba8snorm',\n\t'rgba8uint',\n\t'rgba8sint',\n\t'rgba16float',\n\t'rgba16uint',\n\t'rgba16sint',\n\t'rgba32float',\n\t'rgba32uint',\n\t'rgba32sint',\n\t'bgra8unorm'\n] as GPUTextureFormat[]);\n\n/**\n * Validates a single storage buffer definition.\n *\n * @param name - Buffer identifier.\n * @param definition - Storage buffer definition to validate.\n * @throws {Error} When any field is invalid.\n */\nexport function assertStorageBufferDefinition(\n\tname: string,\n\tdefinition: StorageBufferDefinition\n): void {\n\tassertUniformName(name);\n\n\tif (!Number.isFinite(definition.size) || definition.size <= 0) {\n\t\tthrow new Error(\n\t\t\t`Storage buffer \"${name}\" size must be a finite number greater than 0, got ${definition.size}`\n\t\t);\n\t}\n\n\tif (definition.size % 4 !== 0) {\n\t\tthrow new Error(\n\t\t\t`Storage buffer \"${name}\" size must be a multiple of 4, got ${definition.size}`\n\t\t);\n\t}\n\n\tif (!VALID_STORAGE_BUFFER_TYPES.has(definition.type)) {\n\t\tthrow new Error(\n\t\t\t`Storage buffer \"${name}\" has unknown type \"${definition.type}\". Supported types: ${[...VALID_STORAGE_BUFFER_TYPES].join(', ')}`\n\t\t);\n\t}\n\n\tif (\n\t\tdefinition.access !== undefined &&\n\t\tdefinition.access !== 'read' &&\n\t\tdefinition.access !== 'read-write'\n\t) {\n\t\tthrow new Error(\n\t\t\t`Storage buffer \"${name}\" has invalid access mode \"${definition.access}\". Use 'read' or 'read-write'.`\n\t\t);\n\t}\n\n\tif (definition.initialData !== undefined) {\n\t\tif (definition.initialData.byteLength > definition.size) {\n\t\t\tthrow new Error(\n\t\t\t\t`Storage buffer \"${name}\" initialData byte length (${definition.initialData.byteLength}) exceeds buffer size (${definition.size})`\n\t\t\t);\n\t\t}\n\t}\n}\n\n/**\n * Validates and returns sorted storage buffer keys.\n *\n * @param definitions - Storage buffer definition map.\n * @returns Lexicographically sorted buffer keys.\n */\nexport function resolveStorageBufferKeys(definitions: StorageBufferDefinitionMap): string[] {\n\tconst keys = Object.keys(definitions).sort();\n\tfor (const key of keys) {\n\t\tconst definition = definitions[key];\n\t\tif (definition) {\n\t\t\tassertStorageBufferDefinition(key, definition);\n\t\t}\n\t}\n\treturn keys;\n}\n\n/**\n * Normalizes a storage buffer definition with defaults applied.\n *\n * @param definition - Raw definition.\n * @returns Normalized definition with access default.\n */\nexport function normalizeStorageBufferDefinition(\n\tdefinition: StorageBufferDefinition\n): Required<Pick<StorageBufferDefinition, 'size' | 'type' | 'access'>> {\n\treturn {\n\t\tsize: definition.size,\n\t\ttype: definition.type,\n\t\taccess: definition.access ?? 'read-write'\n\t};\n}\n\n/**\n * Validates that a texture format is storage-compatible.\n *\n * @param name - Texture identifier.\n * @param format - GPU texture format.\n * @throws {Error} When format is not storage-compatible.\n */\nexport function assertStorageTextureFormat(name: string, format: GPUTextureFormat): void {\n\tif (!STORAGE_TEXTURE_FORMATS.has(format)) {\n\t\tthrow new Error(\n\t\t\t`Texture \"${name}\" with storage:true requires a storage-compatible format, but got \"${format}\". ` +\n\t\t\t\t`Supported formats: ${[...STORAGE_TEXTURE_FORMATS].join(', ')}`\n\t\t);\n\t}\n}\n"],"mappings":";;;;;AAUA,IAAM,6BAAkD,IAAI,IAAuB;CAClF;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,CAAC;;;;AAKF,IAAa,0BAAyD,IAAI,IAAI;CAC7E;CACA;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