0

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?

6
  • That's about 12 nanoseconds per value, which doesn't seem that slow at all. Commented May 26, 2018 at 17:08
  • 1
    @Pointy it's slow in the world of rendering. compared to that shader which does far more operations for each of those 8,294,400 values all in under 30ms (and thats even slow for a shader, limiting the output to less than 30FPS) Commented May 26, 2018 at 17:15
  • "Why does it take so long?" - because it needs to explicitly copy and cast every single value to an uint8. Commented May 26, 2018 at 21:01
  • 1
    "to render the shaded result, I need to convert this buffer to a typed array" - do you really? You haven't shown what you're doing with outputBuffer yet. It's a bit unclear whether the gpu.js function that is restricted on typed array is inside pixelateMatrix, working on frameBuffer, or used for rendering the outputBuffer(Raw). Commented May 26, 2018 at 21:06
  • 1
    "here's no way to make gpu.js output a typed array" - sound like a missing feature to me. File an issue at their github repo! Commented May 26, 2018 at 21:07

1 Answer 1

0

gpu.js now outputs typed (Float32) arrays or arrays of Float32Array for multidimensional. The slowest part will be gl.readPixels, best to use textures to keep the values in GPU RAM as much as possible. Also creating a buffer this size to read back into is not insignificant.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.