Friday 22 February 2013

Seamless xeoEngine Recovery from Lost WebGL Context

The GPU is a shared resource, and there are times when it might be taken away from our WebGL applications, such as when there are too many applications holding them, or when another application does something that ties up the GPU too long (perhaps even a DOS attack via shader, perish the thought). In such cases the operating system or browser may decide to reset the GPU to regain control. 

When this happens, our WebGL apps will need to reallocate their textures, VBOs, shaders etc. on a new context afterwards.

In the demo below, I'm forcing xeoEngine to blow away the WebGL context every ten seconds to demonstrate SceneJS 3.0's automatic scene recovery (notice the glitch every ten seconds):

Check out this Pen!
Under the hood, SceneJS takes care of that recovery seamlessly without disruption to code at higher layers (eg. xeoEngine). When the loss occurs, SceneJS reallocates shaders and buffers from data it retains in its scene graph. xeoEngine just experiences a short delay, then it's back in business without reloading anything off the server or reinitialising app code.

It's surprising how fast recovery can happen - in the BioDigital Human, SceneJS takes around 5-7 seconds to recover a scene containing approximately 2000 meshes and 100 textures.

It's not 100% robust yet, because it can fall over if scene modifications are made while recovering, but we're getting almost no errors relating to lost WebGL context in Human now.

No comments:

Post a Comment