简体   繁体   English

为什么从无类型数组到Uint8ClampedArray的转换这么慢?

[英]Why is conversion from an untyped array to Uint8ClampedArray so slow?

I've got a rendering pipeline where I'm trying out gpu.js as my shader mechanism. 我有一个渲染管道,在那里我正在尝试使用gpu.js作为着色器机制。 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. 据我所知,尽管gpu.js可以将类型化数组缓冲区作为输入,但无法输出到类型化数组。 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. 因此,要渲染着色结果,我需要将此缓冲区(可能为1080 x 1920 x 4 = 8,294,400长度的数组缓冲区)转换为类型数组。

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. 大约需要100毫秒,对于实时渲染管道来说太慢了。 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? 为什么普通阵列使用起来这么慢?

gpu.js now outputs typed (Float32) arrays or arrays of Float32Array for multidimensional. gpu.js现在输出用于多维的类型化(Float32)数组或Float32Array数组。 The slowest part will be gl.readPixels, best to use textures to keep the values in GPU RAM as much as possible. 最慢的部分是gl.readPixels,最好使用纹理将值尽可能多地保留在GPU RAM中。 Also creating a buffer this size to read back into is not insignificant. 同样,创建一个大小可以读回的缓冲区并不是无关紧要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从Javascript Uint8ClampedArray获取位 - Getting bits from Javascript Uint8ClampedArray 将Uint8ClampedArray转换为常规数组 - Convert Uint8ClampedArray to regular array forEach for Uint8ClampedArray - forEach for Uint8ClampedArray 为什么将 Uint8Array 复制到 Uint8ClampedArray 比将 Uint8Array 复制到新的 Uint8Array 慢? - Why is copying a Uint8Array to a Uint8ClampedArray slower than copying a Uint8Array to a new Uint8Array? Uint8Array和Uint8ClampedArray之间的区别 - Difference between Uint8Array and Uint8ClampedArray Uint8ClampedArray 到 Uint8Array 到 base64 - Uint8ClampedArray to Uint8Array to base64 在Firefox中将Uint8ClampedArray设置为ImageData非常慢 - Setting Uint8ClampedArray to ImageData is very slow in Firefox 使用putImageData()和UInt8ClampedArray从HTML5 Canvas中的3D数组渲染1个像素 - Render 1 pixel from a 3D array in a HTML5 Canvas using putImageData() and an UInt8ClampedArray 为什么 new Uint8ClampedArray 的 new ImageData 会创建黑白图像 - Why does new ImageData from new Uint8ClampedArray create a black and white image 来自Canvas的getImageData之后,通过Ajax将uint8clampedarray数组发送到JavaScript中的C# - Sending uint8clampedarray Array via ajax to c# in javaScript after getImageData from Canvas
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM