op.sortPass
A compare-and-swap sort that converges a little more every frame: passes swaps per frame, alternating odd and even pairs and the two buffers.
op.sortPass(opts: {passes: (f: GridFrame) => number; pass: (parity: 0 | 1, side: 'A' | 'B') => ComputeStep}): SortPassStage
Import sim from shaders/std and use sim.grids.op.sortPass.
side() tells publish which buffer holds the current order.
Parameters
| Name | Type | Notes |
|---|---|---|
opts | {passes: (f: GridFrame) => number; pass: (parity: 0 | 1, side: 'A' | 'B') => ComputeStep} |
Example
const sort = op.sortPass({passes: () => 1 + Math.round(strength * 4), pass: (parity, side) => (parity ? swap1 : swap0).with(side === 'A' ? groupAB : groupBA)})
Tip. The alternation continues across frames instead of restarting, which is what makes the sort settle bit by bit.
See also
op.publish— The last stage: write the state into the texture the layer samples.op.iterate— Run a stepcounttimes this frame.