You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
WebGL seems underutilized and sorting asynchronously is really handy.
Installation
npm install gpu-sort
Example
import*asgpufrom"gpu-sort";letnumbers=newFloat64Array([5,4,3,2,1,0]);// sort in placegpu.sort(numbers);// sort in place asynchronouslygpu.sortAsync(numbers).then(()=>console.log("sorted!"));
NodeJS support
import*asgpufrom"gpu-sort";// For NodeJS an emulation library must be provided as it doesn't support WebGLgpu.setWebGLContext(require("gl")(1,1));// sort using webgl emulated contextgpu.sort(foo);
When sorting 8bit and 16bit numbers GPU acceleration is disabled (as it seems rather pointless).
The maximum number of elements that can be sorted is constrained by the max texture width squared. For example 4096 ^ 2 = 16,777,216 (32bit) or 4096 ^ 2 / 2 = 8,388,608 (64bit). This can be increased in the future by up to 8 times by multiplexing the data across multiple framebuffers.