import * as THREE from 'three/webgpu'; import { type SplatShInputs, type Vec3Uniform } from '../core/splat-mesh-material'; import type { SplatModifier } from '../core/splat-modifier'; /** * Throws when a unified work buffer would hold more slots than its draw can * address. The draw-order index is a float32 `splatIndex`, exact only up to * 2²⁴; past it neighbouring slots alias and the draw reads the wrong splats * instead of failing. */ export declare function assertWorkBufferCapacity(capacity: number): void; /** * GPU gather pass for Phase 0 of the unified renderer. It resolves a source * pool's active local centers into a shared world-space storage buffer. The * work-buffer sorter consumes this buffer directly, so source-local pools can * later be heterogeneous (including streamed LOD pools). * * Internal while M15.4's draw path and public source API are completed. */ /** Shared GPU storage for every gathered source in one unified frame. */ export declare class WorkBuffer { readonly capacity: number; /** World-space center xyz; w is display opacity (`visibility × source opacity ×` RAD modifier ratio). */ readonly centers: THREE.StorageBufferAttribute; /** Resolved color and opacity per work slot. */ readonly colors: THREE.StorageBufferAttribute; /** First packed covariance row per work slot. */ readonly covarianceA: THREE.StorageBufferAttribute; /** Second packed covariance row per work slot. */ readonly covarianceB: THREE.StorageBufferAttribute; /** Per-slot isotropic covariance mix (0 = keep Σ, 1 = round dot). */ readonly isotropicMix: THREE.StorageBufferAttribute; /** Per-slot isotropic target sigma radius in screen px (0 = disabled). */ readonly isotropicScreenRadius: THREE.StorageBufferAttribute; /** * Slots past {@link capacity}, reserved so a pipeline warm-up has somewhere * harmless to write. See {@link WorkBufferGather.warmUp}: compiling a compute * pipeline requires actually dispatching it, and dispatching zero workgroups * - while it does compile - makes WebGPU log an "unusual workgroup count of 0" * warning for every source. One workgroup aimed at this tail compiles just the * same, silently, and cannot disturb a drawn slot: admission never allocates * past `capacity` and the draw's `instanceCount` never covers it. */ static readonly SCRATCH_SLOTS = 256; constructor(capacity: number); /** * Drops the JS-heap copies three keeps behind these storage buffers. * * Every one of them is written only by the gather compute pass and read only * by the draw material - the CPU side is zeroes that no code ever reads, and * three's WebGPU backend never frees it on its own. At 72 B/slot that mirror * is ~720 MB of JS heap on a 10M-slot scene. See `storage-attribute-mirror`. * * Safe to call after any dispatch that bound this buffer; a no-op once * settled, and on WebGL2 or a renderer double that has no WebGPU backend. */ releaseCpuMirrors(renderer: THREE.WebGPURenderer): void; private readonly mirrors; } export declare class WorkBufferGather { /** World-space `xyzw` center buffer, one element per unified work slot. */ readonly centers: THREE.StorageBufferAttribute; /** Resolved source RGBA values; production draw consumes this next. */ readonly colors: THREE.StorageBufferAttribute; /** Packed symmetric world-space covariance rows. */ readonly covarianceA: THREE.StorageBufferAttribute; readonly covarianceB: THREE.StorageBufferAttribute; readonly isotropicMix: THREE.StorageBufferAttribute; readonly isotropicScreenRadius: THREE.StorageBufferAttribute; /** Shared target for this source's gathered range. */ readonly workBuffer: WorkBuffer; private readonly capacity; private readonly activeCount; private readonly targetOffset; private readonly sourceMatrix; private readonly cameraViewMatrix; private readonly opacity; private readonly pass; /** * SH-only color write used when cached modifier geometry is still valid. * Null when the source has no spherical harmonics. */ private readonly colorPass; constructor(options: { capacity: number; sourceCapacity: number; sourceIndex: THREE.StorageBufferAttribute; centersTexture: THREE.DataTexture; colorsTexture: THREE.DataTexture; covarianceATexture: THREE.DataTexture; covarianceBTexture: THREE.DataTexture; dataTextureWidth: number; sh?: SplatShInputs | null; modifiers?: readonly SplatModifier[]; channels?: ReadonlyMap; localCameraPosition?: Vec3Uniform; srgbOutput?: boolean; /** * Source stores Spark LOD alpha (`alpha ÷ 2`, `.rad`). Recover the full * `alpha ∈ [0,2]` into `colors.a` from the *original* texture channel so the * shared draw material can classify merged vs leaf without seeing fades. */ lodAlpha?: boolean; /** Reuse one target across all source gather passes. */ workBuffer?: WorkBuffer; }); /** Gathers a source's active pool slots into a contiguous work-buffer range. */ gather(renderer: THREE.WebGPURenderer, activeCount: number, targetOffset: number, sourceMatrix: THREE.Matrix4, cameraViewMatrixOrOpacity?: THREE.Matrix4 | number, opacity?: number): void; /** * Refreshes view-dependent SH color in an existing gathered range. * * Leaves world centers, covariance, and cached modifier visibility untouched. * Callers must have previously {@link gather}ed the same slice. Sources * without spherical harmonics throw: there is no camera-dependent color to * refresh. */ gatherColors(renderer: THREE.WebGPURenderer, activeCount: number, targetOffset: number): void; /** * Compiles this gather's compute pipeline without gathering anything. * * WebGPU compiles a compute pipeline lazily, at its first dispatch - not when * the node graph is built. Measured on a 13-mesh scene, a source's *first* * `gather` took up to 2.0s while every later dispatch of the same pipeline * took under 0.4ms, and because `gather` runs inside `update` that compile * landed whole in one render frame. Running it through the async path here * compiles off the critical frame, so the first real gather finds it ready. * * The dispatch targets {@link WorkBuffer.SCRATCH_SLOTS} past the drawable * capacity rather than dispatching zero workgroups: zero also compiles, but * WebGPU warns about it once per source, and writing into a drawn slot could * leave junk behind when a cached gather is reused instead of re-run. * * Best-effort: a failure here costs only the stall it was meant to avoid, so * callers may ignore it. */ warmUp(renderer: THREE.WebGPURenderer): Promise; /** Releases the gather pipeline. The owner releases the storage attribute. */ dispose(): void; }