Tarik Al Hadethi Download CV

Chromium doesn’t fail when it distrusts your GPU

It switches WebGL to software rendering, keeps reporting a working context, and lets you carry on. The try/catch around my renderer caught nothing, because nothing threw.

My dad opened my site and the animation in the header was crawling. So did a couple of friends. On my machine it ran at 60 fps and had done for weeks, which is the least useful thing a bug can do.

The symptom

The homepage hero is a WebGL prism: 271k triangles, PBR shading, MSAA, redrawn at 60 Hz. On my machine it was fine. On other people’s it crawled.

My first guess was that their machines had no WebGL at all, which is why I had wrapped the renderer in the first place. That guess was reasonable and completely wrong, and it cost me a day of looking at the wrong layer.

Why the error handling never fired

I had the renderer wrapped, on the assumption that a machine without WebGL would throw and fall back. It never threw. Chromium does not refuse when it distrusts a driver: it quietly swaps the backend for SwiftShader and renders on the CPU, and the context it hands back looks entirely healthy from JavaScript.

So the failure mode was not “no WebGL”. It was WebGL that works, on the wrong processor, and there is no exception for that.

Measuring it

Reproduced by forcing the same path Chromium picks on its own:

chrome --headless=new --disable-gpu \
       --use-gl=angle --use-angle=swiftshader \
       --enable-unsafe-swiftshader

On the real page that gives 5.1 fps. The CPU was being handed 271k triangles with PBR and MSAA at 60 Hz and doing exactly what you would expect.

The fix that made things worse

My first version also watched frame times and degraded anything slow. It shipped, and it immediately ruined the experience on a fast machine, because its owner was playing a game at the time.

Frame time cannot tell weak from busy. A driver name is a fact; timing is an inference.

I want to be plain that this shipped. It was not a bad idea I talked myself out of; it was live, and it made the site worse for someone whose hardware was fine. Detection is the driver string now and nothing else.

What ships instead

One full rotation is rendered once, on a real GPU, at full quality: 419 frames, a 13.963 s seamless loop, VP9 with alpha, 979 KB. The software path plays that back. The picture is identical because it is the same renderer’s output; three.js never runs there at all.

The live WebGL path is still primary, and the choice is made per visit from the driver. If Chromium ever trusts those drivers again, those machines get the interactive 3D back with nothing to revert.

Three things that bit me in the bake tool

  • Headless Chrome reports prefers-reduced-motion: reduce by default, so the scene drew one still frame and returned before the render hook existed. No flag overrides it; it has to be patched out.
  • SimpleHTTPRequestHandler is HTTP/1.0 and closed every connection, killing the run just past frame 60. It needs protocol_version = "HTTP/1.1".
  • The CSS reset clamped the video. img, svg, canvas, video { max-width: 100% } plus <video>’s default object-fit: contain letterboxed it smaller than the live scene, 488×530 against 530×530, which looks like a bad bake rather than a CSS bug.

The general lesson

A fallback you have never watched fire is not a fallback. Mine was one line of try/catch that had never once run, guarding against an error the browser had no intention of raising.

The failure worth designing for is not the API refusing. It is the API succeeding while the thing behind it quietly isn’t there: a context that reports healthy and renders on the CPU, a signature that verifies against a key nobody holds, a lock that is taken and then compared against NULL. Nothing throws. Nothing logs. It simply does the job badly on someone else’s machine, and “works on mine” is exactly as true as it is useless.

So detect the fact, not the symptom. The driver’s name is a fact. Frame time is an inference, and I have the shipped regression to prove what inferences cost.

Written while building Clarus.  ·  More writing