playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
130 lines (129 loc) • 5.87 kB
TypeScript
/**
* Interval-based GPU stream compaction for the GSplat GPU sort path. Replaces the
* per-pixel flag+scatter approach with an O(numIntervals) cull pass and a
* workgroup-per-interval scatter pass. Always active when GPU sorting is enabled,
* regardless of the culling toggle.
*
* @ignore
*/
export class GSplatIntervalCompaction {
/**
* @param {GraphicsDevice} device - The graphics device (must support compute).
*/
constructor(device: GraphicsDevice);
/** @type {GraphicsDevice} */
device: GraphicsDevice;
/** @type {StorageBuffer|null} */
compactedSplatIds: StorageBuffer | null;
/** @type {StorageBuffer|null} */
intervalsBuffer: StorageBuffer | null;
/** @type {StorageBuffer|null} */
countBuffer: StorageBuffer | null;
/** @type {PrefixSumKernel|null} */
prefixSumKernel: PrefixSumKernel | null;
/** @type {StorageBuffer|null} */
numSplatsBuffer: StorageBuffer | null;
/** @type {StorageBuffer|null} */
sortElementCountBuffer: StorageBuffer | null;
/** @type {number} */
allocatedCompactedCount: number;
/** @type {number} */
allocatedIntervalCount: number;
/** @type {number} */
allocatedCountBufferSize: number;
/**
* World state version for which intervals were last uploaded. Avoids redundant
* uploads when sortGpu is called repeatedly with the same world state.
*/
_uploadedVersion: number;
/** @type {Compute|null} */
_cullComputePerspective: Compute | null;
/** @type {Compute|null} */
_cullComputeFisheye: Compute | null;
/** @type {Compute|null} */
_scatterCompute: Compute | null;
/** @type {Compute|null} */
_writeIndirectArgsCompute: Compute | null;
/** @type {BindGroupFormat|null} */
_cullBindGroupFormatPerspective: BindGroupFormat | null;
/** @type {BindGroupFormat|null} */
_cullBindGroupFormatFisheye: BindGroupFormat | null;
/** @type {BindGroupFormat|null} */
_scatterBindGroupFormat: BindGroupFormat | null;
/** @type {BindGroupFormat|null} */
_writeArgsBindGroupFormat: BindGroupFormat | null;
/** @type {UniformBufferFormat|null} */
_scatterUniformBufferFormat: UniformBufferFormat | null;
/** @type {UniformBufferFormat|null} */
_writeArgsUniformBufferFormat: UniformBufferFormat | null;
destroy(): void;
/** @private */
private _destroyCullPass;
/** @private */
private _createUniformBufferFormats;
/**
* Creates a cull compute pass for the given mode.
*
* @param {boolean} fisheye - Whether to create the fisheye (cone) variant.
* @returns {{ compute: Compute, bindGroupFormat: BindGroupFormat }} The created compute and bind group format.
* @private
*/
private _createCullPass;
/**
* Returns the cached cull Compute for the given mode, lazily creating it on first use.
*
* @param {boolean} fisheye - Whether fisheye is active.
* @returns {Compute} The cached Compute instance.
* @private
*/
private _getCullCompute;
/** @private */
private _createScatterCompute;
/** @private */
private _createWriteIndirectArgsCompute;
/**
* Ensures all buffers have sufficient capacity.
*
* @param {number} numIntervals - Number of intervals.
* @param {number} totalActiveSplats - Total active splats (max compacted output size).
* @private
*/
private _ensureCapacity;
/**
* Builds and uploads interval metadata from the world state. Called once per
* world state change (not every frame).
*
* @param {GSplatWorldState} worldState - The world state to extract intervals from.
*/
uploadIntervals(worldState: GSplatWorldState): void;
/**
* Runs the full interval compaction pipeline: cull+count, prefix sum, scatter.
*
* @param {GSplatFrustumCuller} frustumCuller - Frustum culler providing bounds/transforms storage buffers and frustum planes.
* @param {number} numIntervals - Total number of intervals.
* @param {number} totalActiveSplats - Total active splats across all intervals.
* @param {boolean} fisheyeEnabled - Whether fisheye cone culling should be used instead of frustum planes.
*/
dispatchCompact(frustumCuller: GSplatFrustumCuller, numIntervals: number, totalActiveSplats: number, fisheyeEnabled: boolean): void;
/**
* Writes indirect draw and dispatch arguments from the prefix sum visible count.
*
* @param {number} drawSlot - Slot index in the device's indirect draw buffer.
* @param {number} dispatchSlotBase - Base slot index in the device's indirect
* dispatch buffer. Key-gen args go to `dispatchSlotBase`; sort args to
* `dispatchSlotBase + 1` onwards (as described by `sortIndirectInfo`).
* @param {number} numIntervals - Total interval count (index into prefix sum for visible count).
* @param {Uint32Array} sortIndirectInfo - Sorter-owned 4-element Uint32 array
* returned by `ComputeRadixSort.prepareIndirect()`, used as a `vec4<u32>`
* uniform by the shader to drive the `writeSortIndirectArgs` helper.
*/
writeIndirectArgs(drawSlot: number, dispatchSlotBase: number, numIntervals: number, sortIndirectInfo: Uint32Array): void;
}
import type { GraphicsDevice } from '../../platform/graphics/graphics-device.js';
import { StorageBuffer } from '../../platform/graphics/storage-buffer.js';
import { PrefixSumKernel } from '../graphics/prefix-sum-kernel.js';
import { Compute } from '../../platform/graphics/compute.js';
import { BindGroupFormat } from '../../platform/graphics/bind-group-format.js';
import { UniformBufferFormat } from '../../platform/graphics/uniform-buffer-format.js';
import type { GSplatWorldState } from './gsplat-world-state.js';
import type { GSplatFrustumCuller } from './gsplat-frustum-culler.js';