Many applications are sensitive to OpenGL pipeline stalls; where a “stop the world” call happens that requires the driver to synchronize the GPU and CPU. Because SilverLining and Triton are usually drawn near the end of your frame when everything needs to synchronize anyhow, this usually isn’t a big issue for us. However, preventing pipeline stalls can still reclaim some valuable performance. Here are some tips on avoiding stalls when using our SDK’s.
Tell Us About Your State
Most pipeline stalls in SilverLining and Triton result from our efforts to capture OpenGL’s state prior to doing our drawing, and restoring it when we’re done. Since our libraries have no direct knowledge of the state of your engine or scene graph, we must do this to ensure our state doesn’t leak into yours.
To avoid this, you can tell us about your application’s viewport and depth range so we don’t have to query it in order to properly restore it when we’re done. Atmosphere::SetViewport(), Atmosphere::SetDepthRange(), Environment::SetViewPort(), and Triton’s opengl-near-clip and opengl-far-clip settings in the Triton.config file may be used for this.
Restore your shaders and render targets
Another source of stalls are our efforts to capture and restore the bound shaders and render targets before we are called. Any call that draws, like Atmosphere::DrawSky(), Atmosphere::DrawObjects(), Atmosphere::GetEnvironmentMap(), and Ocean::Draw() will attempt to do this. If we didn’t our own shaders might remain bound while you start doing your own drawing – and that would be bad.
However, both SilverLining and Triton offer an avoid-opengl-stalls option in SilverLining.config and Triton.config. If you set this to “yes”, we won’t try to restore the bound shaders and render targets. It will become your application’s responsibility to do this instead, surrounding our draw calls. But, it can avoid a stall. This seems to be particularly beneficial when calling Atmosphere::GetEnvironmentMap() to generate a cube map from SilverLining’s sky on demand.
Together, these tips can help your application’s performance be the best it can be!