How does a GPU particle system emit, age, move and kill particles each frame and keep a compact list of the living without CPU readback?
answer
- a fixed pool of slots
- free slots on a stack
- two lists of live indices
- atomic counters hand out slots
- the GPU writes its own draw count
basics
~20 sGPU particles live in a fixed pool with a stack of free slots and alive index lists. Passes pop slots to emit, age and move particles, free the expired, and append survivors to a new list whose atomic count drives an indirect draw.
solid answer
~50 sParticles live in a fixed-size pool in GPU memory. A **dead list** holds the indices of free slots and an **alive list** holds the indices of live particles, each with an atomic counter. The emit pass pops free indices from the dead list, initialises those particles and appends them to the alive list. The update pass runs one thread per alive index: it adds the frame time to age, kills a particle past its lifetime by pushing its index back on the dead list, and moves survivors with a simple velocity step before appending their index to a second alive list for the next frame. That append is the compaction: survivors take consecutive slots of the new list, with no gaps, and only indices move, never particle data. A tiny pass copies the survivor count into the arguments of an indirect draw, so the CPU never reads a count back.
code
pseudocode · 26 lines// atomicAdd(counter, n) adds n and returns the value from before the add
// dt is the frame time; deadAtStart is deadCount copied before the emit pass
// Emit pass: one thread per requested new particle
function emit(t):
if t >= min(emitRequest, deadAtStart):
return // no free slot for this thread
slot = atomicAdd(deadCount, -1) - 1 // top of the dead stack
index = deadList[slot]
particles[index] = spawn(emitter, t) // age 0, random lifetime
aliveA[atomicAdd(aliveACount, 1)] = index
// Update pass: one thread per entry of aliveA
function update(t):
if t >= aliveACount:
return
index = aliveA[t]
p = particles[index]
p.age = p.age + dt
if p.age >= p.lifetime:
deadList[atomicAdd(deadCount, 1)] = index // free the slot
return
p.velocity = p.velocity + gravity * dt
p.position = p.position + p.velocity * dt
particles[index] = p
aliveB[atomicAdd(aliveBCount, 1)] = index // compact survivorsgo deeper
Recall the pieces: a fixed pool of particles, a list of free slots, a list of live ones, and passes that emit, update and draw on the GPU.
Walk through one frame: pop free slots to emit, age and move, push the expired back, append survivors, then write the draw count without a readback.
Explain the atomic counters and why appends compact the list, then handle pool exhaustion, the shuffled order that blended particles must sort, and clamping long frames.
Set particle pool budgets per effect and per platform, and decide what happens when one is full, so a crowded scene degrades predictably instead of silently.
## Why update particles on the GPU A CPU particle system updates every particle and uploads the results each frame. With hundreds of thousands of particles, both the update and the upload get expensive. A **GPU particle system** keeps particle state in GPU memory, updates it in compute passes and draws straight from it. Nothing needs to travel back to the CPU; the CPU only sends emitter parameters down, such as how many particles to spawn this frame and where. ## The data layout | Buffer | Holds | Size | |---|---|---| | Particle pool | position, velocity, age, lifetime, size, colour per slot | fixed maximum | | Dead list and counter | indices of free slots, used as a stack | pool size | | Alive list A and counter | indices of particles alive this frame | pool size | | Alive list B and counter | indices of survivors for next frame | pool size | | Draw arguments | instance or vertex count for an indirect draw | a few integers | At start every index is on the dead list and the dead counter equals the pool size. All counters use atomic adds, so many threads can claim slots at once without colliding. ## One frame, step by step 1. **Emit.** Copy the dead counter to a snapshot before the pass. Launch one thread per requested new particle, and let only as many threads as the snapshot allows continue, so the dead list cannot underflow. Each continuing thread pops an index with an atomic decrement, initialises that slot (position from the emitter's shape, a starting velocity, age zero, a lifetime from a random range) and appends the index to alive list A. 2. **Update.** Run one thread per entry of alive list A, either dispatched for the whole pool with an early exit or sized from the alive counter. Add the frame time to age. If age has reached lifetime, push the index back on the dead list; otherwise move the particle and append its index to alive list B. 3. **Write draw arguments.** A one-thread pass copies alive list B's counter into the indirect draw's instance count. 4. **Draw.** The vertex stage reads each instance's index from alive list B and expands that particle into a camera-facing quad. 5. **Swap.** Alive list B becomes next frame's list A, and the new list B's counter is reset to zero. Each pass must see the previous pass's writes; recording these dispatches and the synchronisation between them is a GPU submission subject. The update's "move" is usually one explicit step, velocity plus gravity times the frame time and then position plus velocity times the frame time, which is plenty for cosmetic particles; integration schemes in general are a physics subject. ## Compaction without readback - **The append is the compaction.** Survivors claim consecutive entries of alive list B through an atomic counter, so the list has no gaps however many particles died. Particle data never moves; only small indices do. - **The dead list makes emission cheap.** No thread scans the pool for a free slot; popping the stack is constant time. - **The counter feeds the draw.** Because the GPU writes its own draw arguments, the CPU never waits for a count, and the frame never stalls on a readback. - **Order is not stable.** Atomic appends land in whatever order threads arrive, so the alive lists are shuffled every frame; anything that needs order must sort. ## Traps - **Pool exhaustion.** When the dead list is empty, emission silently stops. Size pools per effect and decide whether to drop new particles or recycle the oldest. - **Blended particles still need a sort.** For over-blended smoke, write each alive particle's view depth and index into a key list and sort it on the GPU before drawing; additive particles skip this. - **Long frames.** One long frame ages and moves every particle in one large step, which can tunnel particles through what they should hit; clamp the frame time the update uses. - **Collisions.** Cheap effects collide against the scene depth, treating it as a surface seen from the camera; anything off screen or hidden behind something is invisible to that test, so particles can fall through it.
- Why not simply loop over the whole pool every frame and skip dead particles?It works, and small effects do it, but every frame then touches every slot, and the draw must cover the whole pool with dead particles collapsed to nothing in the vertex stage. Alive and dead index lists make both the update and the draw proportional to live particles, and the dead list makes finding a free slot constant time instead of a scan.
- How do you sort GPU particles for alpha blending?Write each alive particle's view depth and index into a key list, sort it on the GPU with a parallel sort such as bitonic or radix, and draw in that order. The cost grows with particle count every frame, so effects that can use additive or premultiplied additive blending skip it, and dense smoke often settles for sorting per emitter and accepting small errors.
- The CPU must read the alive count back each frame to issue the draw.
- Dead particles must be moved out of the pool to keep it compact.
- Each particle needs a full rigid-body solver to move correctly.
- Appending survivors with an atomic counter keeps them in their original order.
- A GPU particle system needs no limit, because the GPU allocates slots as needed.