WasmGPU.compute.kernels.radixSortKeysU32¶
Summary¶
WasmGPU.compute.kernels.radixSortKeysU32 sorts u32 keys in ascending order on the GPU.
You can sort in-place or into a separate output buffer.
For non-in-place mode, output is returned as a storage buffer with sorted keys.
Use this for index preparation, bin ordering, and key-based grouping workflows.
Syntax¶
WasmGPU.compute.kernels.radixSortKeysU32(keys: StorageBuffer, opts?: RadixSortOptions): StorageBuffer
const sorted = wgpu.compute.kernels.radixSortKeysU32(keys, opts);
Parameters¶
| Name | Type | Required | Description |
|---|---|---|---|
keys |
StorageBuffer |
Yes | Input key buffer (u32 values) to sort. |
opts |
RadixSortOptions |
No | Optional sort settings (count, out, inPlace, encoder/label/validation). |
Returns¶
StorageBuffer - Buffer containing sorted keys (either keys for in-place or output buffer for out-of-place).
Type Details¶
type RadixSortOptions = {
encoder?: GPUCommandEncoder;
label?: string;
validateLimits?: boolean;
count?: number;
out?: StorageBuffer;
inPlace?: boolean;
};
Example¶
const canvas = document.querySelector("canvas");
const wgpu = await WasmGPU.create(canvas);
const keys = wgpu.compute.createStorageBuffer({ data: new Uint32Array([9, 3, 11, 1, 7]), copySrc: true, copyDst: true });
const sorted = wgpu.compute.kernels.radixSortKeysU32(keys, { inPlace: false });
console.log(Array.from(await wgpu.compute.readback.readU32(sorted)));