Builtin Library
- ..
- README.md2.3 KB
- bindings.yaml2.2 KB
- shader.wgsl6.1 KB
README.md
scan
The prefix fold of a run of elements, whole or per segment: running sums,
running least and greatest, running products. (The running product of 4x4
matrices is scan_mat4.)
| Specialize | Options | Meaning |
|---|---|---|
T | f32, i32, vec2 to vec4 of either | the element; a vector scans lane by lane |
OP | add, min, max, mul | the operator |
params.exclusive picks the fold of the elements before each one or the fold up
to and including it. The first element of a group has nothing before it: an
exclusive scan holds 0 there for add, 1 for mul, and the element itself for
min and max. total holds the fold of each group, 0 for an empty group. A
segmented scan (params.segments above 0, the number of segments) restarts at
each start in starts; an unsegmented one binds any one-word run there.
One workgroup scans one group at a time, a tile of 128 elements at a time, with
the fold of everything before a tile carried into the next. The dispatch size
n is the number of elements; any workgroup count from 1 up scans every group.
Exact: the order of combination is fixed, so the same run gives the same bits on every dispatch, and an integer scan is the exact integer answer.
Over a live count (COUNT=device, see the abi README) n is the capacity and the
first domain_count elements are the run. Every slot of dst at or past it holds the
total of the last group (the whole run, or the last segment; 0 for an empty one), which
is the scan of the run padded with the operator's identity. An i32 scan's total is a count another kernel takes as its
domain ({ count = total, capacity = ... }). It binds 5 storage buffers (4 in the plain
variant).
Over live segments (SEGMENTS=device) params.segments is the most segments there can be, which sizes total, and the
first segment_count of them are live: a segment past them is not scanned, and a run of no live segments scans nothing.
It binds one storage buffer more than the variant it extends.
Nodes that need offsets, running totals or arc lengths run it, among them core.make, core.select, core.edges,
core.arclength, core.realize, core.sample_curve, core.sample.surface, attribute.accumulate and
sim.particles.