import { type SmokeDivisor, type BrickSize, type SimulationFrame, type SimulationGrid, type Vec3, type VelocityDivisor } from './types.ts'; /** The bricks from `lo` to `hi`, inclusive. */ export interface BrickBox { lo: Vec3; hi: Vec3; } /** What the renderer reads of the bricks (VolumeLighting). */ export interface RenderBricks { /** Changes whenever the boxes or the tiles do. */ version: number; /** The boxes of bricks the renderer marches, one per cluster of tiles with something to * draw; none overlaps another. */ boxes: readonly BrickBox[]; /** Every tile slot's tile coordinates and the box holding its cluster, or -1, four words * a slot. */ tiles: Int32Array; /** Each brick id's page (pool.wgsl), or -1. */ pages: GPUBuffer; /** The bricks that computed in the latest step, which hold every slot: a count, then a * brick id each. */ active: GPUBuffer; /** The bricks the latest step zeroed: a count, then a brick id and its page each, the * top bit marking a slot given that step (fluid-allocation.wgsl zeroBrick). */ zeroed: GPUBuffer; /** Indirect dispatch arguments of a workgroup per active/zeroed brick, and of * fine-grid and smoke-cache workgroups per active brick (bricks.wgsl), at these offsets. */ dispatch: GPUBuffer; activeOffset: number; zeroedOffset: number; fieldOffset: number; smokeOffset: number; } /** * Grid-based fire and smoke on a sparse brick pool in world space. The world is a lattice * of independently sized fine-cell bricks, grouped into tiles of 4x4x4 bricks (TileDirectory). * Tiles cover the sources and the content; inside them, only bricks near content and * sources hold storage: each owns a slot of the pool textures, found through its page, so * memory follows the content (pool.wgsl, tiles.wgsl). */ export declare class FluidSimulation { readonly device: GPUDevice; /** Flame, heat and fuel cell size in meters. Smoke may use larger cells. */ readonly voxelSize: number; velocityDivisor: VelocityDivisor; readonly smokeDivisor: SmokeDivisor; readonly scalarMacCormack: boolean; readonly smokeBrickCells: number; private smokePools; /** Canonical smoke density: separate R16F pools in the coarser modes. */ get smoke(): GPUTexture; /** The scalar predictor is dead after evolution, so rendering can reuse it for * smoothed density. The next timestep overwrites it before transport reads it. */ get renderScratch(): GPUTexture; /** Rendering borrows the dead coarse predictor; absent-neighbor aprons must be * restored before the next corrected transport reads it. */ get renderSmokeScratch(): GPUTexture; /** Field cells per brick side. */ readonly brickCells: BrickSize; /** log2 of `brickCells`: bricks are a power of two cells on a side. */ readonly brickShift: number; /** Velocity cells per brick side, derived from the independent brick size. */ readonly velocityBrickCells: number; readonly velocityBrickShift: number; /** Slots per row and per layer of every pool (types.ts poolSide). */ readonly poolSide: number; /** Most field voxels the pools may hold. They grow toward it as content spreads; past * it, bricks the content reaches stay empty and `poolLimited` is set. */ voxelBudget: number; /** Slots the pools hold, and slots in use at the latest measurement. */ poolSlots: number; usedSlots: number; /** Sources of the previous step: a new one wants its slots at once. */ private sourceIds; /** At the latest measurement, bricks the content reached went without slots. */ poolLimited: boolean; /** What still counts as content. Content keeps its bricks active and its tiles alive. */ cutoff: number; /** Active bricks at the latest measurement. */ activeBrickCount: number; time: number; steps: number; /** Heat, normalized flame lifetime and fuel in YZW. X holds smoke density in Full * mode, or this step's smoke production in coarser modes. Scratch swaps each step. */ field: GPUTexture; velocity: GPUTexture; /** Authored target velocity divergence from flame evolution, in inverse seconds. */ expansionRate: GPUTexture; private velocityBack; private fieldForward; private predictorApronDirty; private smokePredictorApronDirty; private fieldCorrected; /** Velocity bounds occupy the velocity cells inside each fine scratch slot. Bounds * die before scalar transport overwrites these textures. Derive the pair so field * swaps and pool growth always expose the current scratch, never live scalar state. */ private get velocityScratch(); /** Exact backward-trace addresses, reused after velocity correction for scalar * transport. R32Uint words, one per field cell or two per velocity cell; no apron * because each correction reads only the address stored at its own cell. */ private donors; private curl; /** Rows of slots the pool textures hold (types.ts poolRows). */ private poolRows; /** The most slots the 3D texture limit allows. */ private readonly maxSlots; /** A stack of free slots, then its count and failed allocations. */ private freeSlots; /** Pressure's ping-pong pair and the divergence, in half precision and slot order: a * velocity brick's cells per slot (pressure.wgsl). */ private pressure; private divergence; private poolState; /** Slots to grow the pools to before the next step. */ private poolTarget; /** Measurements of steps before this one predate the last growth. */ private poolGrownAt; private directory; private tiles; /** The directory's hash of tile coordinates (rgba32sint, `HASH_ROW` entries a row). */ private tileTable; /** The clusters and each tile slot's coordinates and cluster, as the tables were last * built (TileDirectory). */ private clusters; private clusterTiles; /** Tiles with content at the latest measurement, each with the bricks that held it * (bits x, 4 + y and 8 + z, fluid-content.wgsl), and the step it measured. */ private contentTiles; private contentStep; /** The renderer's boxes, the clusters they belong to, and the tile table naming each * tile's box (RenderBricks). */ private renderBoxes; private renderClusters; private renderTiles; private renderVersion; /** The tiles changed since the boxes were last made. */ private renderStale; /** Indirect dispatch sizes for the active and zeroed bricks. */ private dispatchArgs; /** The pressure buffer holding the latest solution. */ private latestPressure; private activityReads; /** Includes idle and mapping buffers so reset/dispose cannot lose an in-flight * readback whose promise resolves after the simulation was released. */ private activityBuffers; /** Counts resets: measurements of steps before the last one are dropped. */ private epoch; private pipelines; private pressureSolver?; private bindings; private ids; private nextId; private forceFields; /** Parameters for kernels that write the field grid and the velocity grid. */ private fieldUniform; private smokeUniform; private velocityUniform; /** The slots a grown pool added (fluid-pool-growth.wgsl PoolGrowth). */ private growthUniform; private flameUniform; private flameRamps; /** The scene's storage buffers, grown to fit what the host packs into them each step: * emitters, colliders and mesh collider occupancy, mesh emission and its tables by * brick, forces and their mesh coverage, and what reaches each tile. */ private scene; /** Each slot's solid cells, one bit a field cell (solids.wgsl). */ private solids; /** The colliders changed: draw them into every brick's solid cells. */ private solidsStale; /** Mesh collider occupancy as uploaded, and each mask's first word there. */ private occupancy; private occupancyOffsets; /** Mesh emission records as uploaded, and the brick ids their tables follow. */ private meshRecords?; private meshVersion; private meshCount; /** World bounds of each mesh source's samples. */ private meshBounds; private uploads; private meshRasterizer; private sampler; private noise?; private uniformData; /** Conservative lifetime history. Once fire is possible, retain its transport until * reset: removing an emitter or disabling fuel does not remove existing flame. */ private mayHaveFlame; /** Below the ground, world y < 0, is solid, and no tile is created there. */ ground: boolean; /** Colliders of the latest step. */ private colliderCount; private constructor(); static create(device: GPUDevice, grid: SimulationGrid): Promise; /** Velocity cell size in meters. */ get velocitySpacing(): number; /** A tile's side in meters. */ private get tileSize(); /** Conservative count of the source box plus its stencil/motion halo. Match * sourceNear in fluid-allocation.wgsl so the old full-brick halo does not over-reserve memory. */ private sourceBricks; /** Empty pools of one layer of slots, and no tiles. */ private allocate; /** A pool texture with the current rows of slots: a brick plus an apron per slot. */ private poolTexture; /** Shared scratch: four packed bounds words per texel with Fine Detail enabled, * otherwise one coordinate word. Velocity uses X in two texels. */ private createDonors; /** Half-precision scalars of every velocity cell of `slots` slots. */ private slotScalars; /** The solid cells of `slots` slots: a bit per field cell. */ private slotSolids; /** Write `data` to a scene buffer, growing it to fit: half again what it needs. */ private upload; /** A 2D integer texture of the tile directory (tiles.wgsl). */ private directoryTexture; /** Fill rows `from` to `to` of the brick entries with -1: bricks without slots. */ private clearEntries; /** Tile resources for `capacity` tile slots: no brick has a slot. */ private createTiles; private destroyTiles; /** Upload the directory after its tiles changed: grow the tile resources to hold every * tile slot, keeping each brick's page, state, flags, entry and record; and start new * tiles' bricks without slots. */ private applyTiles; private pressureBricks; /** Most slots the pools may hold: the voxel budget, within the device's limits. */ private slotLimit; reset(): void; /** What the renderer reads of the bricks. */ get renderBricks(): RenderBricks; /** Requested bytes of owned GPU resources, including capacity, uniform buffers and * pending readbacks. Scene mesh/force data has separate getters; rendering owns its * page table. This excludes backend alignment and transient growth overlap. */ get memoryBytes(): number; get forceMemoryBytes(): number; get meshMemoryBytes(): number; /** Need the tiles within `margin` meters of the world box `lo` to `hi`. */ private needBox; /** The bricks that overlap the world box `lo` to `hi`. */ private bricksOver; /** Keep the tiles the step needs: around every source, the bricks it reaches (two * bricks, buildBricks in fluid-allocation.wgsl) and a tile of margin; and around every tile that * held content, a tile of margin. Tiles nothing needs linger, then close. Then box what * the renderer draws. */ private updateTiles; /** Box what the renderer draws in each cluster of tiles: the bricks with content at the * latest measurement and the bricks of `extra` boxes, with margin, * within the cluster's tiles. Clusters with none of these get no box. */ private updateBoxes; /** Decide each brick's state, free the slots bricks no longer want and give slots to * bricks that want one, in brick order; then build the neighbor tables, and with * `colliders`, draw them into the new slots' solid cells, or into every slot's after * they changed. */ private encodeAllocation; /** Zero the listed bricks in every pool, and their pressure. */ private encodeZeroing; /** Grow the pools to hold `target` slots, keeping only live state. Predictor, * correction and bounds scratch is rewritten before it is next sampled. */ private growPool; private releasePools; /** Write the grid parameters: the last frame's, with the cell sizes, the pools' layout * and the brick ids. Slots past the voxel budget are held back from allocation. */ private writeUniforms; /** The id of world brick `brick`, or -1 outside every tile (tiles.wgsl). */ private brickId; /** * Pack the step's emitters, colliders, forces and mesh emission into the scene buffers, * and list for every tile what reaches it: emitters within the two bricks a source * allocates, forces within a brick, and colliders. Changed colliders redraw every * slot's solid cells. Returns the counts the parameters need. */ private packScene; step(frame: SimulationFrame, dt?: number): void; private substep; /** The solver field a debug view shows, copied into `solverFieldTexture` after every * step: the pressure, or the divergence it solved for. */ private solverField?; /** Pressure/divergence occupy the velocity cells and their apron inside each fine * correction-scratch slot. Rendering samples this layout with the fine slot stride. * No kernel reads this scratch between steps. */ get solverFieldTexture(): GPUTexture; /** Show `field` in `solverFieldTexture`, now and after every step, or stop copying. */ showSolverField(field: 'pressure' | 'divergence' | undefined): void; private encodeSolverField; /** Bind and dispatch one fluid kernel. `workgroups` sizes a dense dispatch. */ private encode; /** A number naming each bound resource, for bind group reuse. */ private id; private activityRead; private discardActivityRead; private releaseActivityReads; /** Note the tiles that held content, by the tile coordinates the step ran with, and * plan pool growth from the slots the step wanted. */ private readActivity; /** The bricks that computed at the latest step, in world space: those with a slot. For * the brick debug view. */ readBricks(): Promise<{ min: Vec3; max: Vec3; }[]>; dispose(): void; }