Search code examples
graphicsopengl-esrenderingopengl-es-2.0

Is there any special optimization for commands like glReadPixels on the mobile platform?


glReadPixels reads data from the framebuffer located in the video memory to the main memory. On the PC side, the performance is limited by the PCI-E bandwidth. However, on some mobile platforms, the main memory and the video memory shared the same physical memory. Does it mean that the command of reading data from the video memory to the main memory is faster on the mobile platform? Is there such optimization on the mobile platform?

Reference:https://www.khronos.org/registry/OpenGL-Refpages/es3.0/html/glReadPixels.xhtml


Solution

  • The main reason glReadPixels is usually so incredibly slow is that it introduces a CPU/GPU sync point. The glReadPixels function typically can't complete on the CPU until the GPU has finished rendering. GPU pipelines are very deep regardless of memory architecture, so that wait can be substantial.

    The fix is to use asynchronous reads to a PBO as discussed here: Android OpenGL ES 3.0 PBO instead of glReadPixels(). However, the speed up comes from removing the CPU/GPU sync point rather than having much to do with memory architecture.