import type * as THREE from 'three/webgpu'; import type { SplatSorter } from './sorter'; import type { SplatSortMetric } from './splat-mesh-types'; import { type SplatSortRange } from './splat-sort-bounds'; /** Immutable inputs for one worker request, supplied by a dynamic mesh. */ export interface WorkerSortSnapshot { readonly requestId: number; readonly spans: Uint32Array; readonly indices: Uint32Array; /** Center deltas captured with the snapshot, not live pool views. */ readonly centerWrites: readonly { start: number; centers: Float32Array; sourceIds?: Float32Array; }[]; } /** * Stable CPU radix sorter in a Web Worker. Used by the WebGL2 fallback and, * when explicitly selected, alongside WebGPU rendering for Spark-like sort * cadence. Works for static and dynamic-capacity meshes alike: the worker * keeps a mirror of the pool's centers. Dynamic hosts additionally provide an * immutable active-index snapshot, so compaction and slot reuse cannot change * what a request means while the worker is busy. * * One sort/publication runs at a time; requests that arrive while the worker * is busy or its completed snapshot awaits render preparation are declined. * This is the backpressure that guarantees an older complete snapshot still * makes forward progress during continuous loading. */ export declare class WorkerSorter implements SplatSorter { readonly kind: "worker"; readonly passCount = 2; submissionCount: number; private readonly worker; private readonly splatIndexAttribute; private readonly host; private readonly sortMetric; private inFlight; /** Set by {@link dispose}; drops any already-delivered order message. */ private disposed; /** The active spans the in-flight sort was computed against. */ private sentSpans; private completedCount; private lastSubmittedAt; private lastCompletedAt; private lastLatencyMs; private inFlightRequestId; private nextRequestId; constructor(host: WorkerSorterHost, sortMetric?: SplatSortMetric); sort(modelView: THREE.Matrix4, _activeCount: number, bounds: THREE.Sphere, visibleRange?: SplatSortRange | null): boolean; /** Internal timing diagnostics used by the demo's opt-in XR A/B harness. */ snapshot(): { submittedCount: number; completedCount: number; lastSubmittedAt: number; lastCompletedAt: number; lastLatencyMs: number; }; dispose(): void; /** Sends written pool rows to keep the worker's centers mirror current. */ private pushCenters; private pushCenterWrites; private applyOrder; private failInFlight; } /** What the sorter needs from its mesh; see SplatMesh.createSorter. */ export interface WorkerSorterHost { /** Pool capacity in splats. */ readonly capacity: number; /** Splats per pool texture row. */ readonly rowWidth: number; /** The pool's centers backing array (vec4 stride; xyz used). */ readonly centers: Float32Array; /** Source metadata for a unified pool; omitted for a normal mesh. */ readonly perSource?: { readonly sourceIds: Float32Array; readonly matrices: Float32Array; }; readonly splatIndexAttribute: THREE.InstancedBufferAttribute; /** Drains the row spans written since the last call. */ takeDirtyRows(): { start: number; count: number; }[]; /** Captures the exact pending scene that a worker reply may publish. */ captureSnapshot?(): WorkerSortSnapshot | null; /** True while a completed snapshot is waiting for render preparation. */ hasPendingPublication?(): boolean; /** Active ranges as (start, count) pool-index pairs, active-list order. */ getActiveSpans(): Uint32Array; /** * Called after a worker order lands in the draw list, so the host knows the * list holds a sorted permutation (not identity active order) and must fully * resync - not patch - it on the next active-list mutation. */ onOrderApplied?(): void; /** Queues a completed immutable snapshot; the host publishes it before drawing. */ onOrderReady?(requestId: number, order: Uint32Array): void; /** Restores dirty coverage after an asynchronous worker failure. */ onSortFailure?(requestId: number): void; }