I'm trying to use WebGL to speed up computations in a simulation of a small quantum circuit, like what the Quantum Computing Playground does. The problem I'm running into is that readPixels
takes ~10ms, but I want to call it several times per frame while animating in order to get information out of gpu-land and into javascript-land.
As an example, here's my exact use case. The following circuit animation was created by computing things about the state between each column of gates, in order to show the inline-with-the-wire probability-of-being-on graphing:
The way I'm computing those things now, I'd need to call readPixels eight times for the above circuit (once after each column of gates). This is waaaaay too slow at the moment, easily taking 50ms when I profile it (bleh).
What are some tricks for speeding up readPixels in this kind of use case?
- Are there configuration options that significantly affect the speed of readPixels? (e.g. the pixel format, the size, not having a depth buffer)
- Should I try to make the
readPixel
calls all happen at once, after all the render calls have been made (maybe allows some pipelining)? - Should I try to aggregate all the textures I'm reading into a single megatexture and sort things out after a single big read?
- Should I be using a different method to get the information back out of the textures?
- Should I be avoiding getting the information out at all, and doing all the layout and rendering gpu-side (urgh...)?
texImage2D
ortexSubImage2D
. Both has 2 different signatures, one looks same as readPixel. I think it worth to test if it is faster. – Glossy