| layout | home | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| title | WebGPU Sorting | ||||||||||||||||||||||||||||||||||||||||||
| titleTemplate | Library, Demo, and Docs | ||||||||||||||||||||||||||||||||||||||||||
| hero |
|
||||||||||||||||||||||||||||||||||||||||||
| features |
|
2
GPU sorters
1
Demo playground
4
Core validation commands
1
Root changelog
import { GPUContext, BitonicSorter } from 'webgpu-sorting';
// Initialize WebGPU context
const gpu = new GPUContext();
await gpu.initialize();
// Create sorter
const sorter = new BitonicSorter(gpu);
// Sort data on GPU
const data = new Uint32Array([5, 2, 8, 1, 9, 3, 7, 4, 6, 0]);
const { sortedData } = await sorter.sort(data);
console.log(sortedData); // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]🌐
Chrome 113+
Supported
🌊
Edge 113+
Supported
🦊
Firefox Nightly
Flag Required
🧭
Safari 18+
macOS 14+
GPU sorting becomes advantageous when:
- Array size is large enough - Buffer upload and readback overhead is amortized
- Batch processing - Multiple sorts can share GPU context
- Real-time applications - Low-latency sorting for visualizations, simulations
- Integer-heavy workloads - Radix sort excels on Uint32Array data
Use the interactive demo to measure the crossover point on your own hardware instead of relying on fixed benchmark claims.
graph TB
subgraph CPU["CPU Side"]
A[Input Array] --> B[Generate Data]
B --> C[Create GPU Buffer]
end
subgraph GPU["GPU Compute Shader"]
D[Read Buffer] --> E[Bitonic/Radix Sort]
E --> F[Parallel Passes]
F --> G[Write Sorted Buffer]
end
subgraph Output
G --> H[Read Back to CPU]
H --> I[Validation & Timing]
end
C --> D
Learn more in the Architecture documentation.