I've got a rendering pipeline where I'm trying out gpu.js as my shader mechanism. From what I can tell though, while gpu.js can take a typed array buffer as input, there's no way to output to a typed array. So to render the shaded result, I need to convert this buffer (potentially 1080 x 1920 x 4 = 8,294,400 length array buffer) to a typed array.
Doing so, like this:
outputBufferRaw = pixelateMatrix(frameBuffer); // shading = ~30ms (kinda slow)
outputBuffer = new Uint8ClampedArray(outputBufferRaw); // conversion = ~100ms (very slow)
takes ~100ms, far far too slow for a real time rendering pipeline. I suspect that normal arrays are just slow to work with and I need to handle this in a different way that never outputs an untyped array anywhere in the rendering pipeline, that's fair enough, but my question is: Why? Why does is take so long to convert a normal array to a typed array? Why are normal arrays so slow to work with?
outputBufferyet. It's a bit unclear whether the gpu.js function that is restricted on typed array is insidepixelateMatrix, working onframeBuffer, or used for rendering theoutputBuffer(Raw).