Is OpenGL really faster than D3D9?

The common knowledge is that drawing stuff in OpenGL is much more faster than in D3D9. I wonder - is this actually true, or just an urban legend? I could very well imagine that setting everything up to draw a single model and then issuing 1000 draw calls for it is faster in OpenGL… but come on, that’s not a very life-like scenario!

At work we now have a D3D9 and an OpenGL renderers on Windows. The original codebase was very much designed for OpenGL, so I had to jump through a lot of hoops to get it fully working on D3D… small differences that add up, like: there’s no object space texgen on D3D, shaders don’t track built-in state (world, modelview matrices, light positions, …), textures in GL vs. textures + sampler state in D3D, and so on. Anyway, the codebase was definitely not designed to exploit D3D strengths and OpenGL weaknesses, more likely the other way around.

But wait! I look at our benchmark tests, and D3D9 is consistently faster than OpenGL. Some examples:

  • Real world scene with lots of shadow casting lights (different objects, different shaders, different lights, different shadow types in one scene):
    • Core Duo with Radeon X1600: 23 FPS D3D9, 13 FPS GL.
    • P4 with GeForce 6800GT: 16 FPS D3D9, 9 FPS GL.
    • Core2 Duo with Radeon HD 2600: 41 FPS D3D9, 35 FPS GL.
  • High object count test (1000 objects, multiple lights, 5 passes per object total):
    • Core Duo with Radeon X1600: 18.3 FPS D3D9, 12.5 FPS GL.
    • P4 with GeForce 6800GT: 13.2 FPS D3D9, 9.4 FPS GL.
    • Core2 Duo with Radeon HD 2600: 34.8 FPS D3D9, 29.3 FPS GL.
  • Dynamic geometry (lots of particle systems) test (this is limited by vertex buffer writing speed and CPU calculating the particles, not draw by calls):
    • Core Duo with Radeon X1600: 170 FPS D3D9, 102 FPS GL.
    • P4 with GeForce 6800GT: 108 FPS D3D9, 74 FPS GL.
    • Core2 Duo with Radeon HD 2600: 325 FPS D3D9, 242 FPS GL.
  • …and so on.

To be fair, there are a couple of tests where on some hardware OpenGL has a slight edge. But in 95% of the cases, D3D9 is faster. Not to mention that we have about 10x less broken hardware/driver workarounds for D3D9 than we have for OpenGL…

What gives? Either our OpenGL code is horribly suboptimal, or “OpenGL is faster!!!!11oneoneeleven” is a myth. I have trouble figuring out in which places our code would be horribly suboptimal, I think we follow all advice given by hardware vendors on how to make OpenGL efficient (not that there is much advice out there though…).

There isn’t much software that can run the same content on both D3D and OpenGL and is suitable for benchmarking. I tried Ogre 3D demos on one machine (GeForce 6800GT card) and guess what? D3D9 is faster in tests that specifically stress draw count (like the instancing demo… D3D9 is faster both in instanced and non-instanced modes).

Am I crazy?

14 Responses to 'Is OpenGL really faster than D3D9?'

  1. ReJ

    probably it’s easy to guess IHV time ratio spent optimizing D3D drivers vs OGL ones…

  2. Aras Pranckevičius

    …still that does not explain where “OpenGL is faster!” comes from. Maybe it used to be faster 5 years ago, and no one bothered to check since then?

  3. Ketan

    Do you have option of trying OpenGL app on Quadro cards (Nvidia)? It might be interesting whether numbers remain same or not.

    -km

  4. Aras Pranckevičius

    I only have results for Quadro NVS 110M here (that’s like very low-end notebook CAD card).

    Shadow scene: 19 FPS D3D, 14 FPS GL.
    High object count test: 21 FPS D3D, 20 FPS GL.
    Dynamic geometry test: 231 FPS D3D, 204 FPS GL.

    The same pattern… of course then, NVS 110 is not a high-end Quadro card by any means.

  5. ReJ

    have you (ever) seen any hard numbers comparing OGL and D3D?

  6. Aras Pranckevičius

    I think I saw them once in nvidia presentation (”batch batch batch” from GDC2003). It has a graph on slide 14… now of course that’s a graph in a synthetic test which might correspond to real life scenario or it might not.

    My feeling is that in OpenGL changing the vertex buffer might be more expensive. What is three function calls on D3D (set declaration, VB, IB) is dozens of calls on GL (set VB, IB, issue glFooPointers, issue glEnableClientStates, issue glDisableClientStates, …). Of course there’s no reason why the calls themselves should be expensive, but I don’t have any other explanation (besides “drivers are not optimized that much!” - which might be true).

    Anyway. So I have one slide from GDC2003 presentation, and now some data with our codebase and Ogre3d. The latter ones do not confirm that OpenGL has lower draw call count. So I will believe that it’s a myth, until someone proves me otherwise :)

  7. Ketan

    Thanks Aras for the NVS 110M numbers.
    It is interesting that the difference has reduced a lot compared to other boards. Still a good 10-20% gap.

    p.s. - I assume that this numbers are averaged and not single sample points :)

  8. Aras Pranckevičius

    Of course the numbers are averaged :) With first several frames of each test not counted in to let everything settle down.

  9. yosh64

    hey

    Hmm, I don’t think this is a very good comparison, and vague on details… as you do not indicate the technique you use for rendering models in opengl, so to for direct3d. There are actually quite a few techniques for rendering models in opengl, being the old glBegin()/glEnd() calls, Display Lists, Vertex Arrays, and finally the best/fastest solution (so I thinks) Vertex Buffer Objects.

    I’m not sure of any techniques and such in direct3d, so I can’t comment on those side of things. But yea, I think if you really want to compare things then you should make up a couple of very basic/light, and identical base apps for both opengl and direct3d, that render triangles using their fastest techniques and such. But even this is not realistic, as who just renders plain polygons? I guess you would need to build on each of these base apps adding different things and see what API does what things better. Anyhows I certainly wouldn’t go by the results of any engine, but rather only something designed for such a comparison.

    Anyhows I’d think they would be quite simular, but I dunno.

    Hmm, one thing I’d like to point out is that I find opengl runs much much faster in linux. Well I think this might be due to the design of the operating system, as I remember reading that in winxp the graphics must go through the kernel or something, which is quite slow… well I have no clue about all this though :\.

    cyas

  10. Aras Pranckevičius

    In OpenGL I render with VBOs (with proper static/dynamic flags). In D3D I render through Vertex/Index buffers, which is essentially the same.

    I don’t render just plain triangles; like I said, there are multiple tests (objects with different shaders and spot/point lights with shadow maps; high object count with per-pixel lit shaders; particle systems with textures and blending). The first test is closest to what would be in the real game - different objects, different shaders, different textures, some lights with shadows and some without.

    But yeah, I did not bother to make a standalone as-small-as-possible tests. Just using the Unity engine. Which again, is probably closer to what one would find in a real world scenario.

  11. Samuel Williams

    Hi,

    Have you tried profiling the code to see if there are many differences in your app? Such as, you might get some numbers of where performance is worse/better.

    It could be interesting to see what functions are actually slower or faster, and give us a much better insight into what the numbers are actually telling us.

    Kind regards,
    Samuel

  12. Aras Pranckevičius

    Yes, in OpenGL case more time is spent in the driver.

    Profiling individual D3D/GL entry points is pretty much useless. Both APIs work by “batching things up” into some command buffers, and later submitting them to the graphics card as they have to. So most often the thing where it ends up spending time is either Present/SwapBuffers, or DrawIndexedPrimitive/glDrawElements. Those actually submit and execute all the previously batched calls.

  13. JinxterX

    You’re not crazy :p D3D9 is significantly faster than OpenGL, try the Unigine Sanctuary demo..

    http://unigine.com/download/

  14. archwndas

    Hi there. Recently I did some similar tests in OpenGL both in Windows and Linux. I didn’t test direct 3D of any kind. Just OpenGL i both systems with NVIDIA drivers. The same version of NVIDIA drivers was installed in both systems. I was running Windows XP 32bit Service pack 2 and Linux with Nvidia Drivers.

    The results were amazing. In Linux I had 430 frames per second. In Windows …. 67 frames per second. The difference was huge. The code was rendering a mesh consisting of several triangles lighting both sides no Culling, Local light Local view. Guys this was the same code exactly. Compiled in both systems with g++ in Linux and Visual Studio in Windows. Exactly the same code exactly the same machine exactly the same drivers NVIDIA ones.

    So I guess there is something really wrong with Windows or the Nvidia drivers for Windows.

    Anyone had similar experience? So I guess you should create a simple application drawing a mesh of triangles with one light source and test it both in Linux and Windows pure OpenGL first. This way you will find out if there any problems with OpenGL and Windows platform.

Leave a Reply