/** * Experimental compute-foundation product API. * * These exports retain the backing constructor and prototype identities while * exposing only caller-owned inputs, coarse configuration, execution controls, * scalar diagnostics, and disposal. Generated passes, uniforms, workgroup * storage, scratch buffers, schedules, and timestamp contexts remain private to * the implementation. * * @module three-blocks/experimental/compute-foundations */ import type * as THREE from 'three/webgpu'; /** Scalar and vector element types accepted by compute-foundation storage inputs. */ export type ComputeFoundationValueType = 'float' | 'int' | 'uint' | 'vec2' | 'ivec2' | 'uvec2' | 'vec3' | 'ivec3' | 'uvec3' | 'vec4' | 'ivec4' | 'uvec4'; /** * Caller-owned Three.js storage input consumed in place by a compute foundation. * * The foundation never disposes this input. Its element count and node type must * remain unchanged after construction; replace the foundation when either * changes. */ export type ComputeFoundationStorage = THREE.StorageBufferNode; /** Configuration for {@link ComputeRadixSort}. */ export type ComputeRadixSortOptions = { /** Optional caller-owned payload storage reordered in lockstep with the keys. */ values?: ComputeFoundationStorage | undefined; /** Requested compute workgroup width. */ workgroupSize?: number | undefined; /** Key bits consumed by one pass; wider passes trade memory for fewer dispatches. */ radixBits?: 1 | 2 | 4 | undefined; /** Significant key width from one through 32 bits. */ keyBits?: number | undefined; /** Direct dispatch over the configured key capacity. */ indirect?: false | undefined; /** Optional caller-owned active-count storage used to clamp direct work. */ countBuffer?: ComputeFoundationStorage<'uint'> | undefined; } | { /** Optional caller-owned payload storage reordered in lockstep with the keys. */ values?: ComputeFoundationStorage | undefined; /** Requested compute workgroup width. */ workgroupSize?: number | undefined; /** Key bits consumed by one pass; wider passes trade memory for fewer dispatches. */ radixBits?: 1 | 2 | 4 | undefined; /** Significant key width from one through 32 bits. */ keyBits?: number | undefined; /** Indirect dispatch limited by `countBuffer`. */ indirect: true; /** Caller-owned atomic active-count storage required by indirect dispatch. */ countBuffer: ComputeFoundationStorage<'uint'>; }; /** * Stable GPU radix-sort facade. * * Keys and optional payloads are modified in place. `compute()` executes the * complete stable sort. For amortized work, call `computeStep()` with consecutive * pass indices from zero through `passCount - 1`; rendering between partial * passes observes partially sorted data. The first execution initializes the * renderer-specific graph and may throw when WebGPU capabilities are missing. */ export interface ComputeRadixSort { /** Number of key elements configured at construction. */ readonly count: number; /** Significant key width consumed by the sort. */ readonly keyBits: number; /** Key bits consumed by one radix pass. */ readonly radixBits: 1 | 2 | 4; /** Number of passes required for one complete sort. */ readonly passCount: number; /** Workgroup width selected for the compute graph. */ readonly workgroupSize: number; /** Whether the renderer-specific graph has been initialized. */ readonly initialized: boolean; /** Build renderer-specific compute resources without submitting work. */ init(renderer: THREE.Renderer): void; /** Execute every radix pass and leave the result in caller-owned inputs. */ compute(renderer: THREE.Renderer): void; /** Execute one numbered radix pass for an amortized sort. */ computeStep(renderer: THREE.Renderer, passIndex: number): void; /** Release owned scratch resources without disposing caller-owned inputs. */ dispose(): void; } interface ComputeRadixSortConstructor { /** Construct a sorter over caller-owned uint keys and an optional payload. */ new (keys: ComputeFoundationStorage<'uint'>, options?: ComputeRadixSortOptions): ComputeRadixSort; /** Runtime prototype. */ readonly prototype: ComputeRadixSort; } /** Runtime radix-sort constructor with implementation state hidden. */ export declare const ComputeRadixSort: ComputeRadixSortConstructor; /** Configuration for {@link ComputePrefixSum}. */ export interface ComputePrefixSumOptions { /** Power-of-two workgroup width used by the Blelloch scan. */ workgroupSize?: number | undefined; /** Largest replay-time element count supported by the compiled pass topology. */ maxCount?: number | undefined; } /** * In-place exclusive uint prefix-sum facade. * * `compute()` initializes lazily and submits the complete recursive scan in one * ordered batch. The input is both the source and output and remains * caller-owned. Initialization throws on WebGL because shared workgroup memory * is required. Recreate the foundation when the storage element count changes. */ export interface ComputePrefixSum { /** Number of live uint elements scanned in place. */ readonly count: number; /** Maximum element count supported by the compiled recursive topology. */ readonly maxCount: number; /** Number of recursive scan levels. */ readonly hierarchyDepth: number; /** Workgroup width selected for the scan. */ readonly workgroupSize: number; /** Whether the renderer-specific graph has been initialized. */ readonly initialized: boolean; /** Build renderer-specific scan resources without submitting work. */ init(renderer: THREE.Renderer): void; /** Compute the complete exclusive prefix sum into the caller-owned input. */ compute(renderer: THREE.Renderer): void; /** Release owned recursive and scratch resources without disposing the input. */ dispose(): void; } interface ComputePrefixSumConstructor { /** Construct an exclusive scan over caller-owned uint storage. */ new (data: ComputeFoundationStorage<'uint'>, options?: ComputePrefixSumOptions): ComputePrefixSum; /** Runtime prototype. */ readonly prototype: ComputePrefixSum; } /** Runtime prefix-sum constructor with pass and scratch state hidden. */ export declare const ComputePrefixSum: ComputePrefixSumConstructor; /** Configuration for {@link ComputeBitonicSort}. */ export interface ComputeBitonicSortOptions { /** Requested power-of-two workgroup width. */ workgroupSize?: number | undefined; /** Sort ascending when true or descending when false. */ ascending?: boolean | undefined; /** Disable shared-memory stages and use only global-memory passes. */ globalOnly?: boolean | undefined; } /** * Deterministic GPU bitonic-sort facade for `(key, stableId)` uint pairs. * * The caller-owned input is modified in place and its count must be a positive * power of two. `compute()` completes a sort in one call. Repeated * `computeStep()` calls amortize the `stepCount` ordered stages across frames; * rendering before the final stage observes partially sorted data. The first * execution selects a renderer-compatible workgroup size and may throw for * invalid backend limits. */ export interface ComputeBitonicSort { /** Number of `(key, stableId)` pairs configured at construction. */ readonly count: number; /** Workgroup width selected for the active renderer. */ readonly workgroupSize: number; /** Whether results are ordered from smallest to largest. */ readonly ascending: boolean; /** Ordered dispatch count required for one complete sort. */ readonly stepCount: number; /** Whether the renderer-specific graph has been initialized. */ readonly initialized: boolean; /** Build renderer-specific sort resources without submitting work. */ init(renderer: THREE.Renderer): void; /** Execute one stage and automatically wrap after a complete sort. */ computeStep(renderer: THREE.Renderer): void; /** Execute every stage and leave the result in caller-owned input storage. */ compute(renderer: THREE.Renderer): void; /** Release owned scratch resources without disposing caller-owned input. */ dispose(): void; } interface ComputeBitonicSortConstructor { /** Construct a sorter over caller-owned `uvec2` key/id storage. */ new (data: ComputeFoundationStorage<'uvec2'>, options?: ComputeBitonicSortOptions): ComputeBitonicSort; /** Runtime prototype. */ readonly prototype: ComputeBitonicSort; } /** Runtime bitonic-sort constructor with schedules and compute nodes hidden. */ export declare const ComputeBitonicSort: ComputeBitonicSortConstructor; export {};