@motion-core/motion-gpu 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +99 -0
- package/dist/advanced.js +3 -1
- package/dist/core/advanced.js +3 -1
- package/dist/core/compute-shader.d.ts +87 -0
- package/dist/core/compute-shader.d.ts.map +1 -0
- package/dist/core/compute-shader.js +205 -0
- package/dist/core/compute-shader.js.map +1 -0
- package/dist/core/error-report.d.ts +1 -1
- package/dist/core/error-report.d.ts.map +1 -1
- package/dist/core/error-report.js +63 -0
- 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 +30 -3
- 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 +418 -23
- 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 +49 -1
- package/dist/core/runtime-loop.js.map +1 -1
- package/dist/core/shader.d.ts +9 -1
- package/dist/core/shader.d.ts.map +1 -1
- package/dist/core/shader.js +21 -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 +12 -0
- package/dist/core/textures.d.ts.map +1 -1
- package/dist/core/textures.js +7 -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-shader.ts +326 -0
- package/src/lib/core/error-report.ts +129 -0
- 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 +101 -20
- package/src/lib/core/render-graph.ts +39 -9
- package/src/lib/core/renderer.ts +655 -41
- package/src/lib/core/runtime-loop.ts +82 -3
- package/src/lib/core/shader.ts +45 -2
- package/src/lib/core/storage-buffers.ts +142 -0
- package/src/lib/core/texture-loader.ts +6 -0
- package/src/lib/core/textures.ts +24 -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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textures.js","names":[],"sources":["../../src/lib/core/textures.ts"],"sourcesContent":["import { assertUniformName } from './uniforms.js';\nimport type {\n\tTextureData,\n\tTextureDefinition,\n\tTextureDefinitionMap,\n\tTextureUpdateMode,\n\tTextureValue\n} from './types.js';\n\n/**\n * Texture definition with defaults and normalized numeric limits applied.\n */\nexport interface NormalizedTextureDefinition {\n\t/**\n\t * Normalized source value.\n\t */\n\tsource: TextureValue;\n\t/**\n\t * Effective color space.\n\t */\n\tcolorSpace: 'srgb' | 'linear';\n\t/**\n\t * Effective texture format.\n\t */\n\tformat: GPUTextureFormat;\n\t/**\n\t * Effective flip-y flag.\n\t */\n\tflipY: boolean;\n\t/**\n\t * Effective mipmap toggle.\n\t */\n\tgenerateMipmaps: boolean;\n\t/**\n\t * Effective premultiplied-alpha flag.\n\t */\n\tpremultipliedAlpha: boolean;\n\t/**\n\t * Effective dynamic update strategy.\n\t */\n\tupdate?: TextureUpdateMode;\n\t/**\n\t * Effective anisotropy level.\n\t */\n\tanisotropy: number;\n\t/**\n\t * Effective filter mode.\n\t */\n\tfilter: GPUFilterMode;\n\t/**\n\t * Effective U address mode.\n\t */\n\taddressModeU: GPUAddressMode;\n\t/**\n\t * Effective V address mode.\n\t */\n\taddressModeV: GPUAddressMode;\n}\n\n/**\n * Default sampling filter for textures when no explicit value is provided.\n */\nconst DEFAULT_TEXTURE_FILTER: GPUFilterMode = 'linear';\n\n/**\n * Default addressing mode for textures when no explicit value is provided.\n */\nconst DEFAULT_TEXTURE_ADDRESS_MODE: GPUAddressMode = 'clamp-to-edge';\n\n/**\n * Validates and returns sorted texture keys.\n *\n * @param textures - Texture definition map.\n * @returns Lexicographically sorted texture keys.\n */\nexport function resolveTextureKeys(textures: TextureDefinitionMap): string[] {\n\tconst keys = Object.keys(textures).sort();\n\tfor (const key of keys) {\n\t\tassertUniformName(key);\n\t}\n\treturn keys;\n}\n\n/**\n * Applies defaults and clamps to a single texture definition.\n *\n * @param definition - Optional texture definition.\n * @returns Normalized definition with deterministic defaults.\n */\nexport function normalizeTextureDefinition(\n\tdefinition: TextureDefinition | undefined\n): NormalizedTextureDefinition {\n\tconst normalized: NormalizedTextureDefinition = {\n\t\tsource: definition?.source ?? null,\n\t\tcolorSpace: definition?.colorSpace ?? 'srgb',\n\t\tformat: definition?.
|
|
1
|
+
{"version":3,"file":"textures.js","names":[],"sources":["../../src/lib/core/textures.ts"],"sourcesContent":["import { assertUniformName } from './uniforms.js';\nimport type {\n\tTextureData,\n\tTextureDefinition,\n\tTextureDefinitionMap,\n\tTextureUpdateMode,\n\tTextureValue\n} from './types.js';\n\n/**\n * Texture definition with defaults and normalized numeric limits applied.\n */\nexport interface NormalizedTextureDefinition {\n\t/**\n\t * Normalized source value.\n\t */\n\tsource: TextureValue;\n\t/**\n\t * Effective color space.\n\t */\n\tcolorSpace: 'srgb' | 'linear';\n\t/**\n\t * Effective texture format.\n\t */\n\tformat: GPUTextureFormat;\n\t/**\n\t * Effective flip-y flag.\n\t */\n\tflipY: boolean;\n\t/**\n\t * Effective mipmap toggle.\n\t */\n\tgenerateMipmaps: boolean;\n\t/**\n\t * Effective premultiplied-alpha flag.\n\t */\n\tpremultipliedAlpha: boolean;\n\t/**\n\t * Effective dynamic update strategy.\n\t */\n\tupdate?: TextureUpdateMode;\n\t/**\n\t * Effective anisotropy level.\n\t */\n\tanisotropy: number;\n\t/**\n\t * Effective filter mode.\n\t */\n\tfilter: GPUFilterMode;\n\t/**\n\t * Effective U address mode.\n\t */\n\taddressModeU: GPUAddressMode;\n\t/**\n\t * Effective V address mode.\n\t */\n\taddressModeV: GPUAddressMode;\n\t/**\n\t * Whether this texture is a storage texture (writable by compute).\n\t */\n\tstorage: boolean;\n\t/**\n\t * Explicit width for storage textures. Undefined when derived from source.\n\t */\n\twidth?: number;\n\t/**\n\t * Explicit height for storage textures. Undefined when derived from source.\n\t */\n\theight?: number;\n}\n\n/**\n * Default sampling filter for textures when no explicit value is provided.\n */\nconst DEFAULT_TEXTURE_FILTER: GPUFilterMode = 'linear';\n\n/**\n * Default addressing mode for textures when no explicit value is provided.\n */\nconst DEFAULT_TEXTURE_ADDRESS_MODE: GPUAddressMode = 'clamp-to-edge';\n\n/**\n * Validates and returns sorted texture keys.\n *\n * @param textures - Texture definition map.\n * @returns Lexicographically sorted texture keys.\n */\nexport function resolveTextureKeys(textures: TextureDefinitionMap): string[] {\n\tconst keys = Object.keys(textures).sort();\n\tfor (const key of keys) {\n\t\tassertUniformName(key);\n\t}\n\treturn keys;\n}\n\n/**\n * Applies defaults and clamps to a single texture definition.\n *\n * @param definition - Optional texture definition.\n * @returns Normalized definition with deterministic defaults.\n */\nexport function normalizeTextureDefinition(\n\tdefinition: TextureDefinition | undefined\n): NormalizedTextureDefinition {\n\tconst isStorage = definition?.storage === true;\n\tconst defaultFormat = definition?.colorSpace === 'linear' ? 'rgba8unorm' : 'rgba8unorm-srgb';\n\tconst normalized: NormalizedTextureDefinition = {\n\t\tsource: definition?.source ?? null,\n\t\tcolorSpace: definition?.colorSpace ?? 'srgb',\n\t\tformat: definition?.format ?? defaultFormat,\n\t\tflipY: definition?.flipY ?? true,\n\t\tgenerateMipmaps: definition?.generateMipmaps ?? false,\n\t\tpremultipliedAlpha: definition?.premultipliedAlpha ?? false,\n\t\tanisotropy: Math.max(1, Math.min(16, Math.floor(definition?.anisotropy ?? 1))),\n\t\tfilter: definition?.filter ?? DEFAULT_TEXTURE_FILTER,\n\t\taddressModeU: definition?.addressModeU ?? DEFAULT_TEXTURE_ADDRESS_MODE,\n\t\taddressModeV: definition?.addressModeV ?? DEFAULT_TEXTURE_ADDRESS_MODE,\n\t\tstorage: isStorage\n\t};\n\n\tif (definition?.width !== undefined) {\n\t\tnormalized.width = definition.width;\n\t}\n\tif (definition?.height !== undefined) {\n\t\tnormalized.height = definition.height;\n\t}\n\n\tif (definition?.update !== undefined) {\n\t\tnormalized.update = definition.update;\n\t}\n\n\treturn normalized;\n}\n\n/**\n * Normalizes all texture definitions for already-resolved texture keys.\n *\n * @param textures - Source texture definitions.\n * @param textureKeys - Texture keys to normalize.\n * @returns Normalized map keyed by `textureKeys`.\n */\nexport function normalizeTextureDefinitions(\n\ttextures: TextureDefinitionMap,\n\ttextureKeys: string[]\n): Record<string, NormalizedTextureDefinition> {\n\tconst out: Record<string, NormalizedTextureDefinition> = {};\n\tfor (const key of textureKeys) {\n\t\tout[key] = normalizeTextureDefinition(textures[key]);\n\t}\n\treturn out;\n}\n\n/**\n * Checks whether a texture value is a structured `{ source, width?, height? }` object.\n */\nexport function isTextureData(value: TextureValue): value is TextureData {\n\treturn typeof value === 'object' && value !== null && 'source' in value;\n}\n\n/**\n * Converts supported texture input variants to normalized `TextureData`.\n *\n * @param value - Texture value input.\n * @returns Structured texture data or `null`.\n */\nexport function toTextureData(value: TextureValue): TextureData | null {\n\tif (value === null) {\n\t\treturn null;\n\t}\n\n\tif (isTextureData(value)) {\n\t\treturn value;\n\t}\n\n\treturn { source: value };\n}\n\n/**\n * Resolves effective runtime texture update strategy.\n */\nexport function resolveTextureUpdateMode(input: {\n\tsource: TextureData['source'];\n\toverride?: TextureUpdateMode;\n\tdefaultMode?: TextureUpdateMode;\n}): TextureUpdateMode {\n\tif (input.override) {\n\t\treturn input.override;\n\t}\n\n\tif (input.defaultMode) {\n\t\treturn input.defaultMode;\n\t}\n\n\tif (isVideoTextureSource(input.source)) {\n\t\treturn 'perFrame';\n\t}\n\n\treturn 'once';\n}\n\n/**\n * Resolves texture dimensions from explicit values or source metadata.\n *\n * @param data - Texture payload.\n * @returns Positive integer width/height.\n * @throws {Error} When dimensions cannot be resolved to positive values.\n */\nexport function resolveTextureSize(data: TextureData): {\n\twidth: number;\n\theight: number;\n} {\n\tconst source = data.source as {\n\t\twidth?: number;\n\t\theight?: number;\n\t\tnaturalWidth?: number;\n\t\tnaturalHeight?: number;\n\t\tvideoWidth?: number;\n\t\tvideoHeight?: number;\n\t};\n\n\tconst width = data.width ?? source.naturalWidth ?? source.videoWidth ?? source.width ?? 0;\n\tconst height = data.height ?? source.naturalHeight ?? source.videoHeight ?? source.height ?? 0;\n\n\tif (width <= 0 || height <= 0) {\n\t\tthrow new Error('Texture source must have positive width and height');\n\t}\n\n\treturn { width, height };\n}\n\n/**\n * Computes the number of mipmap levels for a base texture size.\n *\n * @param width - Base width.\n * @param height - Base height.\n * @returns Total mip level count (minimum `1`).\n */\nexport function getTextureMipLevelCount(width: number, height: number): number {\n\tlet levels = 1;\n\tlet currentWidth = Math.max(1, width);\n\tlet currentHeight = Math.max(1, height);\n\n\twhile (currentWidth > 1 || currentHeight > 1) {\n\t\tcurrentWidth = Math.max(1, Math.floor(currentWidth / 2));\n\t\tcurrentHeight = Math.max(1, Math.floor(currentHeight / 2));\n\t\tlevels += 1;\n\t}\n\n\treturn levels;\n}\n\n/**\n * Checks whether the source is an `HTMLVideoElement`.\n */\nexport function isVideoTextureSource(source: TextureData['source']): source is HTMLVideoElement {\n\treturn typeof HTMLVideoElement !== 'undefined' && source instanceof HTMLVideoElement;\n}\n"],"mappings":";;;;;AA0EA,IAAM,yBAAwC;;;;AAK9C,IAAM,+BAA+C;;;;;;;AAQrD,SAAgB,mBAAmB,UAA0C;CAC5E,MAAM,OAAO,OAAO,KAAK,SAAS,CAAC,MAAM;AACzC,MAAK,MAAM,OAAO,KACjB,mBAAkB,IAAI;AAEvB,QAAO;;;;;;;;AASR,SAAgB,2BACf,YAC8B;CAC9B,MAAM,YAAY,YAAY,YAAY;CAC1C,MAAM,gBAAgB,YAAY,eAAe,WAAW,eAAe;CAC3E,MAAM,aAA0C;EAC/C,QAAQ,YAAY,UAAU;EAC9B,YAAY,YAAY,cAAc;EACtC,QAAQ,YAAY,UAAU;EAC9B,OAAO,YAAY,SAAS;EAC5B,iBAAiB,YAAY,mBAAmB;EAChD,oBAAoB,YAAY,sBAAsB;EACtD,YAAY,KAAK,IAAI,GAAG,KAAK,IAAI,IAAI,KAAK,MAAM,YAAY,cAAc,EAAE,CAAC,CAAC;EAC9E,QAAQ,YAAY,UAAU;EAC9B,cAAc,YAAY,gBAAgB;EAC1C,cAAc,YAAY,gBAAgB;EAC1C,SAAS;EACT;AAED,KAAI,YAAY,UAAU,OACzB,YAAW,QAAQ,WAAW;AAE/B,KAAI,YAAY,WAAW,OAC1B,YAAW,SAAS,WAAW;AAGhC,KAAI,YAAY,WAAW,OAC1B,YAAW,SAAS,WAAW;AAGhC,QAAO;;;;;;;;;AAUR,SAAgB,4BACf,UACA,aAC8C;CAC9C,MAAM,MAAmD,EAAE;AAC3D,MAAK,MAAM,OAAO,YACjB,KAAI,OAAO,2BAA2B,SAAS,KAAK;AAErD,QAAO;;;;;AAMR,SAAgB,cAAc,OAA2C;AACxE,QAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,YAAY;;;;;;;;AASnE,SAAgB,cAAc,OAAyC;AACtE,KAAI,UAAU,KACb,QAAO;AAGR,KAAI,cAAc,MAAM,CACvB,QAAO;AAGR,QAAO,EAAE,QAAQ,OAAO;;;;;AAMzB,SAAgB,yBAAyB,OAInB;AACrB,KAAI,MAAM,SACT,QAAO,MAAM;AAGd,KAAI,MAAM,YACT,QAAO,MAAM;AAGd,KAAI,qBAAqB,MAAM,OAAO,CACrC,QAAO;AAGR,QAAO;;;;;;;;;AAUR,SAAgB,mBAAmB,MAGjC;CACD,MAAM,SAAS,KAAK;CASpB,MAAM,QAAQ,KAAK,SAAS,OAAO,gBAAgB,OAAO,cAAc,OAAO,SAAS;CACxF,MAAM,SAAS,KAAK,UAAU,OAAO,iBAAiB,OAAO,eAAe,OAAO,UAAU;AAE7F,KAAI,SAAS,KAAK,UAAU,EAC3B,OAAM,IAAI,MAAM,qDAAqD;AAGtE,QAAO;EAAE;EAAO;EAAQ;;;;;;;;;AAUzB,SAAgB,wBAAwB,OAAe,QAAwB;CAC9E,IAAI,SAAS;CACb,IAAI,eAAe,KAAK,IAAI,GAAG,MAAM;CACrC,IAAI,gBAAgB,KAAK,IAAI,GAAG,OAAO;AAEvC,QAAO,eAAe,KAAK,gBAAgB,GAAG;AAC7C,iBAAe,KAAK,IAAI,GAAG,KAAK,MAAM,eAAe,EAAE,CAAC;AACxD,kBAAgB,KAAK,IAAI,GAAG,KAAK,MAAM,gBAAgB,EAAE,CAAC;AAC1D,YAAU;;AAGX,QAAO;;;;;AAMR,SAAgB,qBAAqB,QAA2D;AAC/F,QAAO,OAAO,qBAAqB,eAAe,kBAAkB"}
|
package/dist/core/types.d.ts
CHANGED
|
@@ -175,6 +175,26 @@ export interface TextureDefinition {
|
|
|
175
175
|
* V axis address mode.
|
|
176
176
|
*/
|
|
177
177
|
addressModeV?: GPUAddressMode;
|
|
178
|
+
/**
|
|
179
|
+
* When true, this texture is also writable by compute passes.
|
|
180
|
+
*/
|
|
181
|
+
storage?: boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Required when storage is true. Must be a storage-compatible format.
|
|
184
|
+
*/
|
|
185
|
+
format?: GPUTextureFormat;
|
|
186
|
+
/**
|
|
187
|
+
* Explicit texture width. Required for storage textures without a source.
|
|
188
|
+
*/
|
|
189
|
+
width?: number;
|
|
190
|
+
/**
|
|
191
|
+
* Explicit texture height. Required for storage textures without a source.
|
|
192
|
+
*/
|
|
193
|
+
height?: number;
|
|
194
|
+
/**
|
|
195
|
+
* When true, texture is visible (sampled) in fragment shader. Default: true.
|
|
196
|
+
*/
|
|
197
|
+
fragmentVisible?: boolean;
|
|
178
198
|
}
|
|
179
199
|
/**
|
|
180
200
|
* Texture definition map keyed by uniform-compatible texture names.
|
|
@@ -184,6 +204,39 @@ export type TextureDefinitionMap<TKey extends string = string> = Record<TKey, Te
|
|
|
184
204
|
* Runtime texture value map keyed by texture uniform names.
|
|
185
205
|
*/
|
|
186
206
|
export type TextureMap<TKey extends string = string> = Record<TKey, TextureValue>;
|
|
207
|
+
/**
|
|
208
|
+
* Access mode for storage buffers in compute shaders.
|
|
209
|
+
*/
|
|
210
|
+
export type StorageBufferAccess = 'read' | 'read-write';
|
|
211
|
+
/**
|
|
212
|
+
* WGSL storage buffer element type.
|
|
213
|
+
*/
|
|
214
|
+
export type StorageBufferType = 'array<f32>' | 'array<vec2f>' | 'array<vec3f>' | 'array<vec4f>' | 'array<u32>' | 'array<i32>' | 'array<vec4u>' | 'array<vec4i>';
|
|
215
|
+
/**
|
|
216
|
+
* Definition of a single storage buffer resource.
|
|
217
|
+
*/
|
|
218
|
+
export interface StorageBufferDefinition {
|
|
219
|
+
/**
|
|
220
|
+
* Buffer size in bytes. Must be > 0 and multiple of 4.
|
|
221
|
+
*/
|
|
222
|
+
size: number;
|
|
223
|
+
/**
|
|
224
|
+
* WGSL type annotation for codegen.
|
|
225
|
+
*/
|
|
226
|
+
type: StorageBufferType;
|
|
227
|
+
/**
|
|
228
|
+
* Access mode in compute shader. Default: 'read-write'.
|
|
229
|
+
*/
|
|
230
|
+
access?: StorageBufferAccess;
|
|
231
|
+
/**
|
|
232
|
+
* Initial data uploaded on creation.
|
|
233
|
+
*/
|
|
234
|
+
initialData?: Float32Array | Uint32Array | Int32Array;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Map of named storage buffer definitions.
|
|
238
|
+
*/
|
|
239
|
+
export type StorageBufferDefinitionMap<TKey extends string = string> = Record<TKey, StorageBufferDefinition>;
|
|
187
240
|
/**
|
|
188
241
|
* Output color space requested for final canvas presentation.
|
|
189
242
|
*/
|
|
@@ -329,6 +382,39 @@ export interface RenderPassContext extends Required<RenderPassFlags> {
|
|
|
329
382
|
preserve?: boolean;
|
|
330
383
|
}) => GPURenderPassEncoder;
|
|
331
384
|
}
|
|
385
|
+
/**
|
|
386
|
+
* Context provided to compute pass render calls.
|
|
387
|
+
*/
|
|
388
|
+
export interface ComputePassContext {
|
|
389
|
+
/**
|
|
390
|
+
* Active GPU device.
|
|
391
|
+
*/
|
|
392
|
+
device: GPUDevice;
|
|
393
|
+
/**
|
|
394
|
+
* Shared command encoder for this frame.
|
|
395
|
+
*/
|
|
396
|
+
commandEncoder: GPUCommandEncoder;
|
|
397
|
+
/**
|
|
398
|
+
* Frame width in pixels.
|
|
399
|
+
*/
|
|
400
|
+
width: number;
|
|
401
|
+
/**
|
|
402
|
+
* Frame height in pixels.
|
|
403
|
+
*/
|
|
404
|
+
height: number;
|
|
405
|
+
/**
|
|
406
|
+
* Frame timestamp in seconds.
|
|
407
|
+
*/
|
|
408
|
+
time: number;
|
|
409
|
+
/**
|
|
410
|
+
* Frame delta in seconds.
|
|
411
|
+
*/
|
|
412
|
+
delta: number;
|
|
413
|
+
/**
|
|
414
|
+
* Begins a compute pass on the shared command encoder.
|
|
415
|
+
*/
|
|
416
|
+
beginComputePass: () => GPUComputePassEncoder;
|
|
417
|
+
}
|
|
332
418
|
/**
|
|
333
419
|
* Formal render pass contract used by MotionGPU render graph.
|
|
334
420
|
*/
|
|
@@ -362,6 +448,20 @@ export interface RenderPass extends RenderPassFlags {
|
|
|
362
448
|
*/
|
|
363
449
|
dispose?: () => void;
|
|
364
450
|
}
|
|
451
|
+
/**
|
|
452
|
+
* Minimal interface for compute passes in the render graph.
|
|
453
|
+
* Compute passes do not participate in slot routing.
|
|
454
|
+
*/
|
|
455
|
+
export interface ComputePassLike {
|
|
456
|
+
readonly isCompute: true;
|
|
457
|
+
enabled?: boolean;
|
|
458
|
+
setSize?: (width: number, height: number) => void;
|
|
459
|
+
dispose?: () => void;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Union type for all pass types accepted by the render graph.
|
|
463
|
+
*/
|
|
464
|
+
export type AnyPass = RenderPass | ComputePassLike;
|
|
365
465
|
/**
|
|
366
466
|
* Frame submission strategy for the scheduler.
|
|
367
467
|
*/
|
|
@@ -390,6 +490,16 @@ export interface FrameState {
|
|
|
390
490
|
* Sets a texture value for current/next frame.
|
|
391
491
|
*/
|
|
392
492
|
setTexture: (name: string, value: TextureValue) => void;
|
|
493
|
+
/**
|
|
494
|
+
* Writes data to a named storage buffer.
|
|
495
|
+
*/
|
|
496
|
+
writeStorageBuffer: (name: string, data: ArrayBufferView, options?: {
|
|
497
|
+
offset?: number;
|
|
498
|
+
}) => void;
|
|
499
|
+
/**
|
|
500
|
+
* Async readback of storage buffer data.
|
|
501
|
+
*/
|
|
502
|
+
readStorageBuffer: (name: string) => Promise<ArrayBuffer>;
|
|
393
503
|
/**
|
|
394
504
|
* Invalidates frame for on-demand rendering.
|
|
395
505
|
*/
|
|
@@ -414,6 +524,17 @@ export interface FrameState {
|
|
|
414
524
|
/**
|
|
415
525
|
* Internal renderer construction options resolved from material/context state.
|
|
416
526
|
*/
|
|
527
|
+
/**
|
|
528
|
+
* Pending storage buffer write queued from FrameState.
|
|
529
|
+
*/
|
|
530
|
+
export interface PendingStorageWrite {
|
|
531
|
+
/** Storage buffer name. */
|
|
532
|
+
name: string;
|
|
533
|
+
/** Data to write. */
|
|
534
|
+
data: ArrayBufferView;
|
|
535
|
+
/** Byte offset into the storage buffer. */
|
|
536
|
+
offset: number;
|
|
537
|
+
}
|
|
417
538
|
export interface RendererOptions {
|
|
418
539
|
/**
|
|
419
540
|
* Target canvas.
|
|
@@ -470,22 +591,34 @@ export interface RendererOptions {
|
|
|
470
591
|
* Texture definitions by key.
|
|
471
592
|
*/
|
|
472
593
|
textureDefinitions: TextureDefinitionMap;
|
|
594
|
+
/**
|
|
595
|
+
* Sorted storage buffer keys.
|
|
596
|
+
*/
|
|
597
|
+
storageBufferKeys?: string[];
|
|
598
|
+
/**
|
|
599
|
+
* Storage buffer definitions by key.
|
|
600
|
+
*/
|
|
601
|
+
storageBufferDefinitions?: Record<string, import('./types.js').StorageBufferDefinition>;
|
|
602
|
+
/**
|
|
603
|
+
* Sorted storage texture keys (textures with storage:true).
|
|
604
|
+
*/
|
|
605
|
+
storageTextureKeys?: string[];
|
|
473
606
|
/**
|
|
474
607
|
* Static render target definitions.
|
|
475
608
|
*/
|
|
476
609
|
renderTargets?: RenderTargetDefinitionMap;
|
|
477
610
|
/**
|
|
478
|
-
* Static render passes.
|
|
611
|
+
* Static render and compute passes.
|
|
479
612
|
*/
|
|
480
|
-
passes?:
|
|
613
|
+
passes?: AnyPass[];
|
|
481
614
|
/**
|
|
482
615
|
* Dynamic render targets provider.
|
|
483
616
|
*/
|
|
484
617
|
getRenderTargets?: () => RenderTargetDefinitionMap | undefined;
|
|
485
618
|
/**
|
|
486
|
-
* Dynamic render passes provider.
|
|
619
|
+
* Dynamic render and compute passes provider.
|
|
487
620
|
*/
|
|
488
|
-
getPasses?: () =>
|
|
621
|
+
getPasses?: () => AnyPass[] | undefined;
|
|
489
622
|
/**
|
|
490
623
|
* Requested output color space.
|
|
491
624
|
*/
|
|
@@ -530,7 +663,16 @@ export interface Renderer {
|
|
|
530
663
|
width: number;
|
|
531
664
|
height: number;
|
|
532
665
|
};
|
|
666
|
+
pendingStorageWrites?: PendingStorageWrite[];
|
|
533
667
|
}) => void;
|
|
668
|
+
/**
|
|
669
|
+
* Returns the GPU buffer for a named storage buffer, if allocated.
|
|
670
|
+
*/
|
|
671
|
+
getStorageBuffer?: (name: string) => GPUBuffer | undefined;
|
|
672
|
+
/**
|
|
673
|
+
* Returns the active GPU device (for readback operations).
|
|
674
|
+
*/
|
|
675
|
+
getDevice?: () => GPUDevice;
|
|
534
676
|
/**
|
|
535
677
|
* Releases GPU resources and subscriptions.
|
|
536
678
|
*/
|
package/dist/core/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/core/types.ts"],"names":[],"mappings":";AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,CAAC;AAE1E;;;;;GAKG;AACH;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,EAAE,GAAG,YAAY,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxB,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,OAAO,EAAE,gBAAgB,CAAC;CAC1B;AAED,MAAM,WAAW,YAAY,CAC5B,KAAK,SAAS,WAAW,GAAG,WAAW,EACvC,MAAM,SAAS,kBAAkB,CAAC,KAAK,CAAC,GAAG,kBAAkB,CAAC,KAAK,CAAC;IAEpE;;OAEG;IACH,IAAI,EAAE,KAAK,CAAC;IACZ;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAA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AmC,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC;CAC/D;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACxB;;OAEG;IACH,MAAM,EAAE,CAAC,KAAK,EAAE;QACf,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,UAAU,CAAC;QACvB,QAAQ,EAAE,UAAU,CAAC;QACrB,QAAQ,EAAE,UAAU,CAAC;QACrB,UAAU,CAAC,EAAE;YACZ,KAAK,EAAE,MAAM,CAAC;YACd,MAAM,EAAE,MAAM,CAAC;SACf,CAAC;QACF,oBAAoB,CAAC,EAAE,mBAAmB,EAAE,CAAC;KAC7C,KAAK,IAAI,CAAC;IACX;;OAEG;IACH,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,SAAS,GAAG,SAAS,CAAC;IAC3D;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,SAAS,CAAC;IAC5B;;OAEG;IACH,OAAO,EAAE,MAAM,IAAI,CAAC;CACpB"}
|
package/dist/index.js
CHANGED
|
@@ -7,5 +7,7 @@ import { loadTexturesFromUrls } from "./core/texture-loader.js";
|
|
|
7
7
|
import { BlitPass } from "./passes/BlitPass.js";
|
|
8
8
|
import { CopyPass } from "./passes/CopyPass.js";
|
|
9
9
|
import { ShaderPass } from "./passes/ShaderPass.js";
|
|
10
|
+
import { ComputePass } from "./passes/ComputePass.js";
|
|
11
|
+
import { PingPongComputePass } from "./passes/PingPongComputePass.js";
|
|
10
12
|
import "./core/index.js";
|
|
11
|
-
export { BlitPass, CopyPass, ShaderPass, createCurrentWritable, createFrameRegistry, createMotionGPURuntimeLoop, defineMaterial, loadTexturesFromUrls, resolveMaterial, toMotionGPUErrorReport };
|
|
13
|
+
export { BlitPass, ComputePass, CopyPass, PingPongComputePass, ShaderPass, createCurrentWritable, createFrameRegistry, createMotionGPURuntimeLoop, defineMaterial, loadTexturesFromUrls, resolveMaterial, toMotionGPUErrorReport };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dispatch context provided to dynamic dispatch callbacks.
|
|
3
|
+
*/
|
|
4
|
+
export interface ComputeDispatchContext {
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
time: number;
|
|
8
|
+
delta: number;
|
|
9
|
+
workgroupSize: [number, number, number];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Options for constructing a `ComputePass`.
|
|
13
|
+
*/
|
|
14
|
+
export interface ComputePassOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Compute shader WGSL source code.
|
|
17
|
+
* Must declare `@compute @workgroup_size(...) fn compute(@builtin(global_invocation_id) ...)`.
|
|
18
|
+
*/
|
|
19
|
+
compute: string;
|
|
20
|
+
/**
|
|
21
|
+
* Dispatch workgroup counts.
|
|
22
|
+
* - Static tuple: `[x]`, `[x, y]`, or `[x, y, z]`
|
|
23
|
+
* - `'auto'`: derived from canvas size / workgroup size
|
|
24
|
+
* - Function: dynamic dispatch based on frame context
|
|
25
|
+
*/
|
|
26
|
+
dispatch?: [number, number?, number?] | 'auto' | ((ctx: ComputeDispatchContext) => [number, number, number]);
|
|
27
|
+
/**
|
|
28
|
+
* Enables/disables this compute pass.
|
|
29
|
+
*/
|
|
30
|
+
enabled?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Compute pass class used within the render graph.
|
|
34
|
+
*
|
|
35
|
+
* Validates compute shader contract, parses workgroup size,
|
|
36
|
+
* and resolves dispatch dimensions. Does **not** manage GPU resources
|
|
37
|
+
* (that responsibility belongs to the renderer).
|
|
38
|
+
*/
|
|
39
|
+
export declare class ComputePass {
|
|
40
|
+
/**
|
|
41
|
+
* Enables/disables this pass without removing it from graph.
|
|
42
|
+
*/
|
|
43
|
+
enabled: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Discriminant flag for render graph to identify compute passes.
|
|
46
|
+
*/
|
|
47
|
+
readonly isCompute: true;
|
|
48
|
+
private compute;
|
|
49
|
+
private workgroupSize;
|
|
50
|
+
private dispatch;
|
|
51
|
+
constructor(options: ComputePassOptions);
|
|
52
|
+
/**
|
|
53
|
+
* Replaces current compute shader and updates workgroup size.
|
|
54
|
+
*
|
|
55
|
+
* @param compute - New compute shader WGSL source.
|
|
56
|
+
* @throws {Error} When shader does not match the compute contract.
|
|
57
|
+
*/
|
|
58
|
+
setCompute(compute: string): void;
|
|
59
|
+
/**
|
|
60
|
+
* Updates dispatch strategy.
|
|
61
|
+
*/
|
|
62
|
+
setDispatch(dispatch: ComputePassOptions['dispatch']): void;
|
|
63
|
+
/**
|
|
64
|
+
* Returns current compute shader source.
|
|
65
|
+
*/
|
|
66
|
+
getCompute(): string;
|
|
67
|
+
/**
|
|
68
|
+
* Returns parsed workgroup size from current compute shader.
|
|
69
|
+
*/
|
|
70
|
+
getWorkgroupSize(): [number, number, number];
|
|
71
|
+
/**
|
|
72
|
+
* Resolves dispatch workgroup counts for current frame.
|
|
73
|
+
*
|
|
74
|
+
* @param ctx - Dispatch context with canvas dimensions and timing.
|
|
75
|
+
* @returns Tuple [x, y, z] workgroup counts.
|
|
76
|
+
*/
|
|
77
|
+
resolveDispatch(ctx: ComputeDispatchContext): [number, number, number];
|
|
78
|
+
/**
|
|
79
|
+
* Releases resources (no-op since GPU resource lifecycle is renderer-managed).
|
|
80
|
+
*/
|
|
81
|
+
dispose(): void;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=ComputePass.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ComputePass.d.ts","sourceRoot":"","sources":["../../src/lib/passes/ComputePass.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;CACxC;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAClC;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;OAKG;IACH,QAAQ,CAAC,EACN,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,GAC1B,MAAM,GACN,CAAC,CAAC,GAAG,EAAE,sBAAsB,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC/D;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;GAMG;AACH,qBAAa,WAAW;IACvB;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAG,IAAI,CAAU;IAEnC,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,aAAa,CAA2B;IAChD,OAAO,CAAC,QAAQ,CAAiC;gBAErC,OAAO,EAAE,kBAAkB;IASvC;;;;;OAKG;IACH,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAOjC;;OAEG;IACH,WAAW,CAAC,QAAQ,EAAE,kBAAkB,CAAC,UAAU,CAAC,GAAG,IAAI;IAI3D;;OAEG;IACH,UAAU,IAAI,MAAM;IAIpB;;OAEG;IACH,gBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;IAI5C;;;;;OAKG;IACH,eAAe,CAAC,GAAG,EAAE,sBAAsB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;IAoBtE;;OAEG;IACH,OAAO,IAAI,IAAI;CAGf"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { assertComputeContract, extractWorkgroupSize } from "../core/compute-shader.js";
|
|
2
|
+
//#region src/lib/passes/ComputePass.ts
|
|
3
|
+
/**
|
|
4
|
+
* Compute pass class used within the render graph.
|
|
5
|
+
*
|
|
6
|
+
* Validates compute shader contract, parses workgroup size,
|
|
7
|
+
* and resolves dispatch dimensions. Does **not** manage GPU resources
|
|
8
|
+
* (that responsibility belongs to the renderer).
|
|
9
|
+
*/
|
|
10
|
+
var ComputePass = class {
|
|
11
|
+
/**
|
|
12
|
+
* Enables/disables this pass without removing it from graph.
|
|
13
|
+
*/
|
|
14
|
+
enabled;
|
|
15
|
+
/**
|
|
16
|
+
* Discriminant flag for render graph to identify compute passes.
|
|
17
|
+
*/
|
|
18
|
+
isCompute = true;
|
|
19
|
+
compute;
|
|
20
|
+
workgroupSize;
|
|
21
|
+
dispatch;
|
|
22
|
+
constructor(options) {
|
|
23
|
+
assertComputeContract(options.compute);
|
|
24
|
+
const workgroupSize = extractWorkgroupSize(options.compute);
|
|
25
|
+
this.compute = options.compute;
|
|
26
|
+
this.workgroupSize = workgroupSize;
|
|
27
|
+
this.dispatch = options.dispatch ?? "auto";
|
|
28
|
+
this.enabled = options.enabled ?? true;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Replaces current compute shader and updates workgroup size.
|
|
32
|
+
*
|
|
33
|
+
* @param compute - New compute shader WGSL source.
|
|
34
|
+
* @throws {Error} When shader does not match the compute contract.
|
|
35
|
+
*/
|
|
36
|
+
setCompute(compute) {
|
|
37
|
+
assertComputeContract(compute);
|
|
38
|
+
const workgroupSize = extractWorkgroupSize(compute);
|
|
39
|
+
this.compute = compute;
|
|
40
|
+
this.workgroupSize = workgroupSize;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Updates dispatch strategy.
|
|
44
|
+
*/
|
|
45
|
+
setDispatch(dispatch) {
|
|
46
|
+
this.dispatch = dispatch ?? "auto";
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Returns current compute shader source.
|
|
50
|
+
*/
|
|
51
|
+
getCompute() {
|
|
52
|
+
return this.compute;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Returns parsed workgroup size from current compute shader.
|
|
56
|
+
*/
|
|
57
|
+
getWorkgroupSize() {
|
|
58
|
+
return [...this.workgroupSize];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Resolves dispatch workgroup counts for current frame.
|
|
62
|
+
*
|
|
63
|
+
* @param ctx - Dispatch context with canvas dimensions and timing.
|
|
64
|
+
* @returns Tuple [x, y, z] workgroup counts.
|
|
65
|
+
*/
|
|
66
|
+
resolveDispatch(ctx) {
|
|
67
|
+
if (this.dispatch === "auto") return [
|
|
68
|
+
Math.ceil(ctx.width / this.workgroupSize[0]),
|
|
69
|
+
Math.ceil(ctx.height / this.workgroupSize[1]),
|
|
70
|
+
Math.ceil(1 / this.workgroupSize[2])
|
|
71
|
+
];
|
|
72
|
+
if (typeof this.dispatch === "function") return this.dispatch(ctx);
|
|
73
|
+
if (Array.isArray(this.dispatch)) return [
|
|
74
|
+
this.dispatch[0],
|
|
75
|
+
this.dispatch[1] ?? 1,
|
|
76
|
+
this.dispatch[2] ?? 1
|
|
77
|
+
];
|
|
78
|
+
return [
|
|
79
|
+
1,
|
|
80
|
+
1,
|
|
81
|
+
1
|
|
82
|
+
];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Releases resources (no-op since GPU resource lifecycle is renderer-managed).
|
|
86
|
+
*/
|
|
87
|
+
dispose() {}
|
|
88
|
+
};
|
|
89
|
+
//#endregion
|
|
90
|
+
export { ComputePass };
|
|
91
|
+
|
|
92
|
+
//# sourceMappingURL=ComputePass.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ComputePass.js","names":[],"sources":["../../src/lib/passes/ComputePass.ts"],"sourcesContent":["import { assertComputeContract, extractWorkgroupSize } from '../core/compute-shader.js';\n\n/**\n * Dispatch context provided to dynamic dispatch callbacks.\n */\nexport interface ComputeDispatchContext {\n\twidth: number;\n\theight: number;\n\ttime: number;\n\tdelta: number;\n\tworkgroupSize: [number, number, number];\n}\n\n/**\n * Options for constructing a `ComputePass`.\n */\nexport interface ComputePassOptions {\n\t/**\n\t * Compute shader WGSL source code.\n\t * Must declare `@compute @workgroup_size(...) fn compute(@builtin(global_invocation_id) ...)`.\n\t */\n\tcompute: string;\n\t/**\n\t * Dispatch workgroup counts.\n\t * - Static tuple: `[x]`, `[x, y]`, or `[x, y, z]`\n\t * - `'auto'`: derived from canvas size / workgroup size\n\t * - Function: dynamic dispatch based on frame context\n\t */\n\tdispatch?:\n\t\t| [number, number?, number?]\n\t\t| 'auto'\n\t\t| ((ctx: ComputeDispatchContext) => [number, number, number]);\n\t/**\n\t * Enables/disables this compute pass.\n\t */\n\tenabled?: boolean;\n}\n\n/**\n * Compute pass class used within the render graph.\n *\n * Validates compute shader contract, parses workgroup size,\n * and resolves dispatch dimensions. Does **not** manage GPU resources\n * (that responsibility belongs to the renderer).\n */\nexport class ComputePass {\n\t/**\n\t * Enables/disables this pass without removing it from graph.\n\t */\n\tenabled: boolean;\n\n\t/**\n\t * Discriminant flag for render graph to identify compute passes.\n\t */\n\treadonly isCompute = true as const;\n\n\tprivate compute: string;\n\tprivate workgroupSize: [number, number, number];\n\tprivate dispatch: ComputePassOptions['dispatch'];\n\n\tconstructor(options: ComputePassOptions) {\n\t\tassertComputeContract(options.compute);\n\t\tconst workgroupSize = extractWorkgroupSize(options.compute);\n\t\tthis.compute = options.compute;\n\t\tthis.workgroupSize = workgroupSize;\n\t\tthis.dispatch = options.dispatch ?? 'auto';\n\t\tthis.enabled = options.enabled ?? true;\n\t}\n\n\t/**\n\t * Replaces current compute shader and updates workgroup size.\n\t *\n\t * @param compute - New compute shader WGSL source.\n\t * @throws {Error} When shader does not match the compute contract.\n\t */\n\tsetCompute(compute: string): void {\n\t\tassertComputeContract(compute);\n\t\tconst workgroupSize = extractWorkgroupSize(compute);\n\t\tthis.compute = compute;\n\t\tthis.workgroupSize = workgroupSize;\n\t}\n\n\t/**\n\t * Updates dispatch strategy.\n\t */\n\tsetDispatch(dispatch: ComputePassOptions['dispatch']): void {\n\t\tthis.dispatch = dispatch ?? 'auto';\n\t}\n\n\t/**\n\t * Returns current compute shader source.\n\t */\n\tgetCompute(): string {\n\t\treturn this.compute;\n\t}\n\n\t/**\n\t * Returns parsed workgroup size from current compute shader.\n\t */\n\tgetWorkgroupSize(): [number, number, number] {\n\t\treturn [...this.workgroupSize];\n\t}\n\n\t/**\n\t * Resolves dispatch workgroup counts for current frame.\n\t *\n\t * @param ctx - Dispatch context with canvas dimensions and timing.\n\t * @returns Tuple [x, y, z] workgroup counts.\n\t */\n\tresolveDispatch(ctx: ComputeDispatchContext): [number, number, number] {\n\t\tif (this.dispatch === 'auto') {\n\t\t\treturn [\n\t\t\t\tMath.ceil(ctx.width / this.workgroupSize[0]),\n\t\t\t\tMath.ceil(ctx.height / this.workgroupSize[1]),\n\t\t\t\tMath.ceil(1 / this.workgroupSize[2])\n\t\t\t];\n\t\t}\n\n\t\tif (typeof this.dispatch === 'function') {\n\t\t\treturn this.dispatch(ctx);\n\t\t}\n\n\t\tif (Array.isArray(this.dispatch)) {\n\t\t\treturn [this.dispatch[0], this.dispatch[1] ?? 1, this.dispatch[2] ?? 1];\n\t\t}\n\n\t\treturn [1, 1, 1];\n\t}\n\n\t/**\n\t * Releases resources (no-op since GPU resource lifecycle is renderer-managed).\n\t */\n\tdispose(): void {\n\t\t// No-op — GPU resources are managed by the renderer.\n\t}\n}\n"],"mappings":";;;;;;;;;AA6CA,IAAa,cAAb,MAAyB;;;;CAIxB;;;;CAKA,YAAqB;CAErB;CACA;CACA;CAEA,YAAY,SAA6B;AACxC,wBAAsB,QAAQ,QAAQ;EACtC,MAAM,gBAAgB,qBAAqB,QAAQ,QAAQ;AAC3D,OAAK,UAAU,QAAQ;AACvB,OAAK,gBAAgB;AACrB,OAAK,WAAW,QAAQ,YAAY;AACpC,OAAK,UAAU,QAAQ,WAAW;;;;;;;;CASnC,WAAW,SAAuB;AACjC,wBAAsB,QAAQ;EAC9B,MAAM,gBAAgB,qBAAqB,QAAQ;AACnD,OAAK,UAAU;AACf,OAAK,gBAAgB;;;;;CAMtB,YAAY,UAAgD;AAC3D,OAAK,WAAW,YAAY;;;;;CAM7B,aAAqB;AACpB,SAAO,KAAK;;;;;CAMb,mBAA6C;AAC5C,SAAO,CAAC,GAAG,KAAK,cAAc;;;;;;;;CAS/B,gBAAgB,KAAuD;AACtE,MAAI,KAAK,aAAa,OACrB,QAAO;GACN,KAAK,KAAK,IAAI,QAAQ,KAAK,cAAc,GAAG;GAC5C,KAAK,KAAK,IAAI,SAAS,KAAK,cAAc,GAAG;GAC7C,KAAK,KAAK,IAAI,KAAK,cAAc,GAAG;GACpC;AAGF,MAAI,OAAO,KAAK,aAAa,WAC5B,QAAO,KAAK,SAAS,IAAI;AAG1B,MAAI,MAAM,QAAQ,KAAK,SAAS,CAC/B,QAAO;GAAC,KAAK,SAAS;GAAI,KAAK,SAAS,MAAM;GAAG,KAAK,SAAS,MAAM;GAAE;AAGxE,SAAO;GAAC;GAAG;GAAG;GAAE;;;;;CAMjB,UAAgB"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { ComputePassOptions, ComputeDispatchContext } from './ComputePass.js';
|
|
2
|
+
/**
|
|
3
|
+
* Options for constructing a `PingPongComputePass`.
|
|
4
|
+
*/
|
|
5
|
+
export interface PingPongComputePassOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Compute shader WGSL source code.
|
|
8
|
+
*/
|
|
9
|
+
compute: string;
|
|
10
|
+
/**
|
|
11
|
+
* Target texture key from `material.textures`.
|
|
12
|
+
* The engine will auto-generate `{target}A` and `{target}B` bindings.
|
|
13
|
+
*/
|
|
14
|
+
target: string;
|
|
15
|
+
/**
|
|
16
|
+
* Number of compute iterations per frame. Default: 1.
|
|
17
|
+
*/
|
|
18
|
+
iterations?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Dispatch workgroup counts (same as ComputePass).
|
|
21
|
+
*/
|
|
22
|
+
dispatch?: ComputePassOptions['dispatch'];
|
|
23
|
+
/**
|
|
24
|
+
* Enables/disables this pass.
|
|
25
|
+
*/
|
|
26
|
+
enabled?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Ping-pong compute pass for iterative GPU simulations.
|
|
30
|
+
*
|
|
31
|
+
* Manages two texture buffers (A/B) and alternates between them each iteration,
|
|
32
|
+
* enabling read-from-previous-write patterns commonly used in fluid simulations,
|
|
33
|
+
* reaction-diffusion, and particle systems.
|
|
34
|
+
*/
|
|
35
|
+
export declare class PingPongComputePass {
|
|
36
|
+
/**
|
|
37
|
+
* Enables/disables this pass without removing it from graph.
|
|
38
|
+
*/
|
|
39
|
+
enabled: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Discriminant flag for render graph to identify compute passes.
|
|
42
|
+
*/
|
|
43
|
+
readonly isCompute: true;
|
|
44
|
+
/**
|
|
45
|
+
* Discriminant flag to identify ping-pong compute passes.
|
|
46
|
+
*/
|
|
47
|
+
readonly isPingPong: true;
|
|
48
|
+
private compute;
|
|
49
|
+
private target;
|
|
50
|
+
private iterations;
|
|
51
|
+
private dispatch;
|
|
52
|
+
private workgroupSize;
|
|
53
|
+
private frameCount;
|
|
54
|
+
constructor(options: PingPongComputePassOptions);
|
|
55
|
+
private static assertIterations;
|
|
56
|
+
/**
|
|
57
|
+
* Returns the texture key holding the latest result.
|
|
58
|
+
* Alternates between `{target}A` and `{target}B` based on total iteration parity.
|
|
59
|
+
*/
|
|
60
|
+
getCurrentOutput(): string;
|
|
61
|
+
/**
|
|
62
|
+
* Advances the internal frame counter (called by renderer after each frame's iterations).
|
|
63
|
+
*/
|
|
64
|
+
advanceFrame(): void;
|
|
65
|
+
/**
|
|
66
|
+
* Replaces compute shader and updates workgroup size.
|
|
67
|
+
*/
|
|
68
|
+
setCompute(compute: string): void;
|
|
69
|
+
/**
|
|
70
|
+
* Updates iteration count.
|
|
71
|
+
*
|
|
72
|
+
* @param count - Must be >= 1.
|
|
73
|
+
*/
|
|
74
|
+
setIterations(count: number): void;
|
|
75
|
+
/**
|
|
76
|
+
* Updates dispatch strategy.
|
|
77
|
+
*/
|
|
78
|
+
setDispatch(dispatch: ComputePassOptions['dispatch']): void;
|
|
79
|
+
/**
|
|
80
|
+
* Returns the target texture key.
|
|
81
|
+
*/
|
|
82
|
+
getTarget(): string;
|
|
83
|
+
/**
|
|
84
|
+
* Returns the current iteration count.
|
|
85
|
+
*/
|
|
86
|
+
getIterations(): number;
|
|
87
|
+
/**
|
|
88
|
+
* Returns current compute shader source.
|
|
89
|
+
*/
|
|
90
|
+
getCompute(): string;
|
|
91
|
+
/**
|
|
92
|
+
* Returns parsed workgroup size.
|
|
93
|
+
*/
|
|
94
|
+
getWorkgroupSize(): [number, number, number];
|
|
95
|
+
/**
|
|
96
|
+
* Resolves dispatch workgroup counts for current frame.
|
|
97
|
+
*/
|
|
98
|
+
resolveDispatch(ctx: ComputeDispatchContext): [number, number, number];
|
|
99
|
+
/**
|
|
100
|
+
* Releases resources (no-op, GPU lifecycle is renderer-managed).
|
|
101
|
+
*/
|
|
102
|
+
dispose(): void;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=PingPongComputePass.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PingPongComputePass.d.ts","sourceRoot":"","sources":["../../src/lib/passes/PingPongComputePass.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAEnF;;GAEG;AACH,MAAM,WAAW,0BAA0B;IAC1C;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,QAAQ,CAAC,EAAE,kBAAkB,CAAC,UAAU,CAAC,CAAC;IAC1C;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;GAMG;A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