19

I want to include a few "bells and whistles" features on a site I'm currently developing, but I don't want to bog down the entire machine for my users. Is there a way I can test to see if the current browser is GPU accelerated?

I could just check against UserAgents, but I've always heard it's not accurate enough to trust.

I guess I could build a canvas element, make quite a few drawing calls, and time them? Anything under a certain threshold I could consider good enough for my superfluous extras? Would this be good enough?

JYelton
  • 35,664
  • 27
  • 132
  • 191
Emrikol
  • 291
  • 1
  • 4

2 Answers2

6

Why does it matter if its GPU accelerated? The only thing that should matter is performance.

So timing the canvas element is the better choice even if you could find out if there is GPU acceleration or not.

CodesInChaos
  • 106,488
  • 23
  • 218
  • 262
  • 1
    Well, I was just hoping that if there were some sort of GPUEnabled flag I could check it would give me a definitive yes or no on their capabilities without resorting to some hack. – Emrikol Feb 11 '11 at 18:16
  • 1
    My point is that GPU acceleration is just an implementation detail you should not care about. IMO checking for GPU acceleration when you really want to know if the performance cost is acceptable is hackish, and not the other way round. – CodesInChaos Feb 11 '11 at 18:44
  • 2
    Why? If GPU composting is enabled, then it is assured that their machine and graphics card are more than powerful enough. One cannot simply enable acceleration on their RIVA TNT2 card. If I were to just run a benchmark, it is variable depending on what else the machine is doing. If another CPU intensive process is running, then I could get a false negative. – Emrikol Feb 11 '11 at 18:58
  • @Emrikol Not at all. For example, note that [enabling GPU Acceleration massively slows down some operations in Firefox 4](http://stackoverflow.com/questions/4899799/whats-the-best-way-to-set-a-single-pixel-in-an-html5-canvas/4900656#4900656): HTML5 Canvas `putImageData()` becomes about 80x _slower_ with hardware acceleration _on_. – Phrogz Feb 11 '11 at 19:40
  • @Phrogz I have to point out that the SO link you provided refers to a bug in FF 4. The post author says that same operation runs faster with GPU acceleration in FF 3.6 than without. GPU acceleration itself isn't slower (in this case), it's just that the Mozilla team broke something going from 3.6 to 4.0. There's still a valid point here for @Emrikol: a more complicated system has more things to go wrong. He may get the performance he's looking for, but may have more to debug as well. – Eric Hu May 23 '11 at 21:53
  • hardware acceleration does indeed play a role for how videos and images are rendered, especially in regards to colour: https://productforums.google.com/forum/#!msg/chrome/-FxOCYv_RfU/AOmWjWdaEQAJ – darwin Jan 09 '19 at 06:59
1

The best way that won't be fooled by browser UserAgent hacks is checking support for latest features included in the browser versions that support the GPU acceleration. You'd need to do some digging to find what was added in the same versions as the GPU acceleration to do that.

Just keep in mind that GPU support for canvas at the moment works only on Windows - so you'd have to take all the OSX running machines out of equation and only in ie9, chrome 11 and firefox 4 - all of them either RC, betas, or dev builds.

for IE9 for example: only IE have scrollabar color CSS properties and only IE9 form all the IEs supports css opacity

function isIE9() {
    var bodyStyle = document.body.style;
    return (bodyStyle.scrollbar3dLightColor != undefined && bodyStyle.opacity != undefined)
}
Tom Tu
  • 9,573
  • 35
  • 37
  • Something like that would be fine. There is no added functionality I'm looking for and no content would be missed by users of other systems/older browsers. They would just miss out on useless animations and such. I would rather the user just not view them instead of running at 4 fps on a Pentium II. – Emrikol Feb 11 '11 at 18:20
  • @Emrikol yeah I believe this to be the best approach, if the effects you are planning can't be replaced by some less fancy ones that would require less CPU it's better not to add them at all if they were to freeze the browser or even hang it. Though you could always add some kind of ribbon on top of the page with message that there is something cool to see if you had newer browser - I for example would sure miss it if I didn't see it :) – Tom Tu Feb 11 '11 at 18:33
  • 1
    My browser supports all the latest features -- my aging computer, however, does not. Checking for the browser features would give you a false positive in my case, and bog my computer down horribly. – Stephen P Feb 11 '11 at 19:58
  • @Stephen P, If your aging computer had a powerful enough GPU to support offloading, and it is enabled, then it may not bog down. My original idea was to get a rough estimate of a user's PC by testing it against the minimum requirements for GPU browser acceleration. – Emrikol Feb 11 '11 at 20:49
  • 3
    @Emrikol, I agree, but I *don't* have a GPU, and my box is old, but asking the *Browser* could tell you "Yes, I, the Browser, support that" without telling you "except that there's no GPU in this clunker" which would lead to a false positive. – Stephen P Feb 12 '11 at 01:43