Parallel processing with OpenGL ES

Parallelism is the concept of multiple processes running at once, either on a single-processor interleaving or multi-core processor. Parallelism allows for increased application throughput and higher responsiveness for input/output. To achieve parallelism within a single application, you can use threads to partition the and run the threads in parallel on the processor(s). OpenGL ES applications inherently use parallelism between the CPU and GPU, but to varying degrees depending on the structure of the code. There is also the option of multiple processes running on the processor and communicating through interprocess communication techniques.

Since BlackBerry 10 is POSIX-compliant, BlackBerry 10 Native SDK supports pthreads. If you're familiar with pthreads, you can use your knowledge to build BlackBerry 10 apps. Because multiple development environments and APIs available on BlackBerry 10, there is alternative threading support as well, such as QThreads or Boost threads.

It is important to note that each OpenGL ES rendering context targets a single thread of execution. If a thread has more than one EGLContext, the results are undefined.

Determining if you can benefit from parallelism

Turning your application into a multi-threaded application can be significant work. It's best to focus on CPU-GPU parallelism first, and then on threading or child processes. To assess whether your application can benefit from threading or multiple processes, you can examine whether your application performs many tasks independent of OpenGL ES rendering, such as artificial intelligence calculations, sounds, or simulating a game world. For example, if you use an application profiler that shows that the GPU is idle significantly more often than the CPU, you can try to split your CPU tasks to achieve higher throughput.

Implementing parallelism in your OpenGL ES application

To implement parallelism, we want to provide the GPU with work constantly. So, we focus on achieving CPU parallelism to off-load more work to the GPU. If you want to implement parallelism in your application, consider the following approaches:
  • Separate your work to work that is related to OpenGL ES and work that is not related toOpenGL ES
  • If there is lots of CPU-bound work, separate the work into multiple threads and make sure that OpenGL ES draws to a single thread
  • If you want to render multiple scenes, you can separate each scene into its own thread, making sure each thread has its own context

Last modified: 2013-12-21

comments powered by Disqus