Pages

Apr 24, 2012

NaCl and Blacklisted GPU Drivers

With the new flood of Native Client games coming out, 3D is hitting the web more, and more. One of the biggest issues with 3D on the web is the limiting nature of blacklisted drivers. Looking at the crash logs that come through, incorrectly handling blacklisting crashes accounts for the #1 crash report from NaCl applications lately. As such, let's take a look at how to properly respond to this issue.



Why do we have GPU Driver Blacklisting
GPU API can be malicious; more specifically, adding GPU APIs to a web browser opens a door to the drive-by-web that we never had access to before, specifically, we're talking to hardware; And if you've ever delt with hardware before, you know there's edge-cases all over the place that could be exploited incorrectly. Web needs to walk the line between functionality and safety, we need a modern web with advanced, deep interaction, and there's a massive majority of hardware out there that can handle it. The goal then, is to find a line that provides the advanced featuresets of the modern web, and the safety of it as well.

This is where we introduce the concept of a GPU Driver Blacklist. Some drivers have vulnerabilities, or direct stability issues that result in bad end-user experiences, while most of the time, we can work with the hardware vendors to fix the issues, sometimes is not that easy, and as such, we have to restrict that specific driver from running inside of the browser.


NOTE that we restrict the driver, not the GPU ! The GPU, like other hardware, is usually a straightforward device, which bends to the will of it's driver based overload. The device is the one we need to worry about.

Now, it's very important to understand that WebGL (via javascript) and OpenGL ES2 (via Native Client) both use the same back-end inside of chrome; As such, when discussing black-listing, you can use the terms pretty interchangeably.

Khronos keeps a general description of blacklisted devices, which is good to know. (The chrome list is a bit more informative)

Restricting via the chrome web store
Currently, Native Client applications must be installed through the Chrome Web Store to work properly.
CWS provides a barrier flag, which will restrict users from installing your NaCl application if their device is blacklisted.

"requirements": {
  "3D": {
    "features": ["webgl"]
  }
}

Note that there is some nuances here that CWS still needs to fix; If the device is blacklisted, and the app defines the above flag:

  • The app won't show up on the puzzle wall
  • The app WILL show up in a direct search
  • The app WILL show up if you link to it directly
  • When you reach the install page, user will see "This application is not supported on this computer. Installation has been disabled"

The intent is that CWS should filter out games that users can't play so that they don't leave bad feedback to the developer.


Detecting Blacklist via WebGL
If the user can install from CWS (or if you're a hosted app, just browse to your URL), you'll need to catch their issues directly at your webpage. Since WebGL and NaCl share the same rendering path; you can detect for a blacklisted device in javascript before even loading the NaCl module:


function initGLTest(size) {
  var canvas = document.createElement('canvas');
  var gl = canvas.getContext('webgl') ||
           canvas.getContext('experimental-webgl');

  if (gl) {
    return true;
  }

  return false;
}


You should be doing this test before you load your nacl module; More specifically, you should add the EMBED tag to the DOM only after the above test as been successful.

Yes, that means that there should be some series of startup tests you need to perform before actually adding the nacl module to the webpage. You should check my previous post on detecting user setup problems.

Detecting Blacklist via NaCl
If the above WebGL test has passed; chances are that your driver is OK, and you should be good-to-go with creating your NaCl OpenGLES2.0 GLContext.  If creating your context does fail, please try a simpler version of context create to ensure that you're not incorrectly asking for features that the hardware doesn't support. Chances are, you're asking for a resolution, or init feature which is causing the problem.


Test your blacklist response
You can test your blacklist handling by running chrome with the following flags: With these, you can run through all the above scenarios, and test how you handle things.

  • --disable-webgl
  • --disable-pepper-3d-for-untrusted-use
  • --disable-gl-multisampling
  • --disable-accelerated-compositing
  • --disable-accelerated-2d-canva

What to do when you've detected a blacklist response
Firstly, thank the user for using your application.  ;)
Secondly, alert the user of the issue, and direct them to update their graphics drivers to a newer version.
Chrome provides a simple page describing how to do updates, which you should most likely direct your users to in such a case that you've found a blacklist error.
Thirdly, if that doesn't work, humbly apologize to your user about the situation, and try best to explain the reason for the problem. The intent here is that users shouldn't respond to your application with bad ratings because they have blacklisted hardware; You'd be amazed how far an apology goes to help with this.


Other tricky things
-Blacklisted drivers on macs are especially tricky to work with; Apple owns distribution of those drivers, and often distributes them at a seperate frequency than the PC / Linux branches. So it's difficult (nay, impossible sometimes) to direct the user to update their drivers on these devices.

-Make sure you detect feature sets as well; you need to properly test that the GPU supports the specific features your 3D app is using. For example, does this GPU support 4096 textures? Most of these tests can be done in webGL, before you even load your nacl module, but they are critical to test for, as hardware is heterogeneous, and thus your application needs to respond properly.


So, armed with this information, there should be no reason to see any more blacklist crashes coming through Google's crash logs. Right? Good. Because otherwise, I have to send the fear engine after you, or if he's booked, Deep Crow.


~Main

No comments:

Post a Comment