/** * GPU Buffer Management for Particle Physics * * Manages WebGPU buffers for particle positions, velocities, and states. * Implements double-buffering (ping-pong) for efficient compute shader execution. * * @module gpu/GPUBuffers */ import type { WebGPUContext } from './WebGPUContext.js'; export interface ParticleBufferData { /** Particle positions (vec4: x, y, z, radius) */ positions: Float32Array; /** Particle velocities (vec4: vx, vy, vz, mass) */ velocities: Float32Array; /** Particle states (vec4: active, sleeping, health, userData) */ states: Float32Array; } export interface GPUBufferSet { /** Position buffer (read) */ positionsRead: GPUBuffer; /** Position buffer (write) */ positionsWrite: GPUBuffer; /** Velocity buffer (read) */ velocitiesRead: GPUBuffer; /** Velocity buffer (write) */ velocitiesWrite: GPUBuffer; /** State buffer (read) */ statesRead: GPUBuffer; /** State buffer (write) */ statesWrite: GPUBuffer; /** Uniform buffer (simulation params) */ uniforms: GPUBuffer; } export interface UniformData { /** Simulation timestep (seconds) */ dt: number; /** Gravity acceleration (m/s²) */ gravity: number; /** Ground plane Y position */ groundY: number; /** Restitution coefficient (bounciness) */ restitution: number; /** Friction coefficient */ friction: number; /** Particle count */ particleCount: number; /** Padding for alignment (vec4) */ _pad1: number; _pad2: number; } /** * GPU Buffer Manager * * Manages WebGPU buffers for particle physics simulation using double-buffering. * Each frame, read and write buffers are swapped (ping-pong pattern). * * @example * ```typescript * const bufferManager = new GPUBufferManager(context, 100000); * await bufferManager.initialize(); * * // Upload initial particle data * bufferManager.uploadParticleData({ * positions: initialPositions, * velocities: initialVelocities, * states: initialStates, * }); * * // Run simulation * for (let frame = 0; frame < 1000; frame++) { * // Compute shader reads from Read buffers, writes to Write buffers * await computePass.dispatch(); * * // Swap buffers for next frame * bufferManager.swap(); * } * * // Download results * const results = await bufferManager.downloadParticleData(); * ``` */ export declare class GPUBufferManager { private context; private device; private particleCount; private buffers; private positionBufferSize; private velocityBufferSize; private stateBufferSize; private uniformBufferSize; constructor(context: WebGPUContext, particleCount: number); /** * Initialize GPU buffers */ initialize(): Promise; /** * Create a storage buffer */ private createStorageBuffer; /** * Upload particle data to GPU */ uploadParticleData(data: ParticleBufferData): void; /** * Upload uniform data (simulation parameters) */ uploadUniformData(uniforms: UniformData): void; /** * Download particle data from GPU (for rendering or analysis) * * Note: This is an async operation that stalls the pipeline. * Use sparingly (e.g., once per frame for rendering). */ downloadParticleData(): Promise; /** * Create a staging buffer for GPU→CPU readback */ private createStagingBuffer; /** * Swap read/write buffers (ping-pong) * * After a compute pass, the "write" buffers contain the new state. * This function swaps read ↔ write so the next pass can read the latest data. */ swap(): void; /** * Get buffer set for binding to compute pipeline */ getBuffers(): GPUBufferSet; /** * Get particle count */ getParticleCount(): number; /** * Destroy buffers and free GPU memory */ destroy(): void; } /** * Helper: Create initial particle data arrays * * @example * ```typescript * const data = createInitialParticleData(10000, { * positionRange: { min: -10, max: 10 }, * radius: 0.1, * }); * * bufferManager.uploadParticleData(data); * ``` */ export declare function createInitialParticleData(count: number, options?: { positionRange?: { min: number; max: number; }; radius?: number; mass?: number; }): ParticleBufferData; //# sourceMappingURL=GPUBuffers.d.ts.map