skip to content

When a game needs many simulated capes and flags at once, how do you decide between simulating cloth on the CPU or the GPU, and what changes in the solver?

level: principalimportance: should knowfreq 18%

answer

  1. who already owns each processor
  2. readback latency for gameplay
  3. Gauss-Seidel is sequential
  4. Jacobi averages, converges slower
  5. graph colouring into independent sets

basics

~20 s

Weigh cloth count and particle budget against who already uses each processor's frame time, whether gameplay must read the cloth back, and platform spread; on the GPU, Gauss-Seidel order gives way to Jacobi averaging or graph-coloured batches.

solid answer

~50 s

Start from the budget, not the hardware. If the GPU is already the bottleneck from rendering, moving cloth there only moves the problem; if the CPU is the bottleneck and the cloth is cosmetic, the GPU wins, and its results feed the vertex data without an upload. Anything gameplay must read in the same frame, such as a rope bridge the player stands on, stays on the CPU, because GPU results usually arrive a frame or more later. On the GPU the sequential **Gauss-Seidel** sweep cannot run unchanged, because constraints sharing a particle race. Either use **Jacobi**: each constraint computes its correction from the same positions, corrections are summed per particle and averaged, often with a relaxation factor, which parallelises fully but converges slower. Or **graph-colour** the constraints into sets that share no particle and run the colours in sequence. The same colouring also feeds SIMD on the CPU.

go deeper

for a junior

Recall that cloth can run on either processor, and that the GPU needs a parallel-friendly constraint solver.

for a middle

Explain why Gauss-Seidel races when parallelised and how Jacobi averaging and graph colouring each fix it.

for a senior

Show the costs: Jacobi's slower convergence, atomic accumulation and determinism, readback latency, and colouring computed once per asset.

for a principal

Own the policy: which cloth classes run where per platform, level of detail, budgets per processor, and the CPU fallback for gameplay cloth.

## What the decision turns on A lead deciding where cloth runs is spending frame time, not choosing a faster chip. The questions that settle it: - **Who already owns each processor.** In many games rendering keeps the GPU busy while gameplay, animation and audio share the CPU cores. Cloth goes where there is headroom on the platforms you ship, which may differ per platform. - **How much cloth.** A few hundred particles for one hero cape fits easily in a CPU job; dozens of capes and flags with thousands of particles each favour a massively parallel processor. - **Who reads the result.** Cosmetic cloth is only drawn, so GPU results can feed the vertex data directly without an upload. Cloth gameplay depends on, such as a rope bridge the player walks across or a banner that blocks a sightline, must be read by the CPU. GPU results usually reach the CPU a frame or more later, and waiting for them stalls both processors. - **Collision inputs.** Body proxies, wind and the world colliders must be on whichever side runs the solver, every frame. - **Determinism.** GPU accumulation with atomic additions sums floats in a varying order, so results can differ run to run. That matters only for cloth that feeds gameplay, replays or lockstep. - **Team and tools.** A GPU solver needs debugging and profiling skills and a fallback for platforms without spare GPU time. ## Why the solver changes The usual cloth solver is **Gauss-Seidel**: constraints are projected one after another, each seeing positions already corrected by earlier ones. That converges fast per iteration but is sequential. Run every constraint in its own thread unchanged and two constraints sharing a particle read the same old position and race to write it, losing corrections. Two parallel shapes fix it, described in the next two sections. ## Jacobi projection Every constraint computes its correction from the same positions at the start of the iteration. Corrections are accumulated per particle, then applied together: 1. For each constraint in parallel, compute each particle's correction and add it to that particle's accumulator, with atomic adds or a gather per particle. 2. For each particle in parallel, divide the sum by the number of constraints that touched it, often scaled by a relaxation factor, and apply it. 3. Repeat for the next iteration. Averaging stops neighbouring corrections from overshooting when added together, but information moves more slowly than in Gauss-Seidel, so Jacobi needs more iterations or substeps for the same stiffness. ## Graph colouring Partition the constraints into **colours** so that no two constraints of one colour share a particle. Within a colour every projection is independent and runs in parallel; colours run one after another. The result is still Gauss-Seidel, only in colour order, because each colour sees the previous colour's corrections, so it keeps that method's faster convergence. On a regular grid a handful of colours covers the structural, shear and bending constraints. The colouring depends only on connectivity, so it is computed once when the cloth asset is built and recomputed only if the cloth tears. The colouring also helps the CPU: constraints of one colour can be packed into SIMD lanes with no conflicts. ## Comparing the two placements | | CPU in jobs | GPU compute | |---|---|---| | Best for | few cloths, gameplay-read cloth | many cosmetic cloths | | Latency to gameplay | same frame | usually a frame or more | | Solver shape | Gauss-Seidel, coloured SIMD | Jacobi or coloured batches | | Determinism | straightforward | needs care with accumulation order | | Main risk | CPU frame budget | GPU frame budget | ## A policy a lead sets There is rarely one answer for a whole game. A workable policy: - **gameplay cloth on the CPU**, deterministic, in the same frame; - **cosmetic cloth where the budget is**, usually the GPU on platforms with headroom; - **level of detail**: fewer particles, fewer substeps or animation-only cloth at a distance; - **per-platform budgets**, with the CPU path as the fallback where GPU time is short.

  • Why does a Jacobi cloth solver need more iterations than Gauss-Seidel for the same stiffness?
    In Gauss-Seidel each projection sees the corrections already made this iteration, so an adjustment can spread along a chain within one sweep. Jacobi computes every correction from the same old positions and then averages them, so each iteration moves information only one constraint further and the averaging damps the steps.
  • Which cloth would you keep on the CPU even if most cloth runs on the GPU?
    Anything gameplay reads in the same frame: a rope bridge the player stands on, a curtain that blocks line of sight, cloth that triggers sounds or events. Reading GPU results back stalls or lags by a frame, and gameplay-relevant cloth may need determinism for replays.

Graph colouring is like timetabling exams so that no student sits two at once: every exam in one time slot runs in parallel, and the slots run one after another. Constraints are the exams, and particles are the students.

  • The GPU is always faster for cloth, so moving it there is free.
  • A Gauss-Seidel loop parallelises by giving every constraint its own thread unchanged.
  • Jacobi projection converges as fast per iteration as Gauss-Seidel.
  • Gameplay can read GPU cloth positions in the same frame at no cost.
  • Graph colouring must be recomputed every frame as the cloth moves.