Blended splats and particles draw back to front, so their order changes whenever the camera moves. A list drawn by depth, or grouped by a cell or a material, needs the same thing: keys a wrote, sorted, with the index of each key’s row beside it. sorter.create sorts a buffer of keys in a compute pass of your , and moves a payload buffer with them. Keys that compare equal keep their order.
Eight keys sorted by ones digit, then by tens digit
Try Tap a key, or use the arrow keys, to follow it and its payload letter through the passes. Keys with the same digit keep the order the last pass left them, so the two 42s never swap.
Creates a stable radix sort of a buffer of keys, eight bits a pass, which carries a payload
along. Keys that compare equal keep their order, so a sort repeats exactly. Its cost follows the
buffer's length and keyBits, not the keys' order. An f32 sort ranks -0 and +0 equal.
@owns ― buffers, pipelines, bind groups: counts per 2 048 keys, a copy of the keys and payload to
sort through, and the scan of the counts
@records ― sort in a compute pass after whatever writes the keys
@param ― keys the buffer to sort, with storage usage
Holds a payload, such as indices into your own data, that moves with its key. It has as many
elements as keys. With out, it requires out.values. Default no payload.
Clamps each key into [min, max]. Integer keys sort from min, in the bits max - min
needs; f32 keys sort in 2^keyBits even steps, where keys in one step keep their order.
Default the whole range of the key's type.
range:[0,1],
Options<K extends Key = Key,V extends d.AnyWgslData= AnyWgslData>.keyBits?: number |undefined
Sorts by this many low bits of the key that range or key makes, eight a pass. Below 32 on
i32 and f32 keys requires range or key. Default what range needs, or 32.
Records a frame into one encoder and submits once, with a clock. Borrows the root. The
synchronous recorder borrows each frame's encoder.
@submits ― always once a frame after your recorder returns, and again at each frame.submit()
@param ― record your frame, recorded into each frame's encoder
@returns ― a loop you run with each frame's time and destroy
create(
constroot:TgpuRoot
root,(
frame:frames.Frame
frame)=>{
const
constcompute:TgpuComputePass
compute=
frame:frames.Frame
frame.
Frame.encoder: TgpuCommandEncoder
Records commands for submission after the recorder returns. submit() replaces this encoder.
Read it at each call instead of keeping it, and let the frame submit it.
values moves with the keys, element for element. It is usually each key’s index, which a later kernel or draw reads its row through. The sort runs in place by default. With out, it writes the sorted keys and payload to other buffers and leaves keys and values as they were; this also saves the copy back that an odd number of passes ends with in place.
sort(pass) records a count, a scan and a scatter per eight bits, and sets its own pipelines and . Record it in a compute pass after the kernel that writes the keys.
Every sort covers the whole buffer. Give unused a key that sorts last, as grid.radix does for empty slots.
A sorter holds a second copy of the keys and payload to sort through, and 1 KB of counts per 2 048 keys.
rowA row is one object's values in a buffer, such as one enemy, one particle or one light.Objects are rows in buffers →
kernelA kernel is a compute function that the GPU runs many times at once, each run on its own thread.A frame in plain TypeGPU →
frameA frame is one turn of the loop, and the object your function gets for it, which holds the encoder, the time and the time since the last frame.You own the frame →
bind groupA bind group is a set of buffers, textures and samplers that a pipeline reads, and a pipeline has room for four.Words →
slotA slot is a row's place in its buffers, which a new row can take once the first is removed.Row ids →