Linux “Graphics Driver Stack” Explained

We get this question a lot about radeonhd: “When is 3D going to be supported?”

The short answer: never; 3D acceleration is the domain of Mesa.

But, of course, it’s not as simple as that.  For the long answer, read on…

More than Meets the Eye

Your Linux “video card driver” is not a single blob of code.  As with any sufficiently large piece of software, things need to be broken up into discrete components for both technical and maintainability reasons.  And, there is no doubt a complete graphics stack is large: the AMD Catalyst driver is a 93MB download.  That’s over one hundred Mega bytes of executable code and supporting data.  In that humongous pile of bytes are roughly half a dozen different components working together to deliver your polygonal needs, without counting the configuration tools.  This, unfortunately, is not common knowledge.

In the open source world, our drivers are much more svelte, partly because less features are supported, and also because application-specific optimizations are omitted.  Unlike the proprietary drivers, however, the boundaries of separation are clearly visible.  In respect to “driver” code that is specific to a particular hardware, there are, more or less, three separate components involved:

  • X display driver
  • Mesa DRI driver
  • Kernel DRM driver

Indeed, in true UNIX fashion, all of these are actually worked on as completely separate projects, albeit with significant overlap in the personnels involved. (Proprietary drivers from AMD and nVidia provide equivalents to all three in a single package.)

DDX: People’s Favourite Barking Tree

When the words “Linux video card driver” are invoked, the DDX is what people typically think of.  And, for good reason: historically, when configuring X11, the DDX was one of the few things that had to be configured by the user, and could be selected. This is your radeonhd, radeon, nv, and intel.

The main function of these drivers is to provide mode setting: that is, selecting the screen resolution, colour depth, turning outputs on and off, etc. The X server uses the DDX to perform basic, essential hardware manipulation so that you can have a graphical display at all.  Each DDX is hardware-specific: indeed, it stands for Device Dependent X (but this trivia is not very important.)

That’s not all.

A DDX also provides hooks that allow the X server to offload certain drawing operations to the GPU so that they can be accelerated.  XAA, EXA, and UXA all fall under the DDX’s domain, in addition to Xv.  The former group is responsible for things like moving windows around your desktop, scrolling a website in your favourite browser, and compositing desktop effects.  The latter handles video rendering.

To summarize, everything 2D is the domain of the DDX.  And, in simple terms, it is its only domain.  If you are looking for 3D acceleration, this is not the tree to be barking up at.

Mesa DRI Driver: The Invisible Hero

OpenGL is the method with which applications achieve 3D rendering under Linux.  Unfortunately, but for good reasons, it is not possible to go from an OpenGL function call to manipulating hardware states in a single step.  Multiple translations must be done under the hood to convert those calls into something that the GPU can understand.

Mesa is largely divided into two parts: an OpenGL compatible library stack that applications can call into, and DRI drivers that translate Mesa-internal instructions into forms that the video hardware can understand and execute.

After a call is made to the Mesa library and it has been translated into a GPU-specific language, the resulting operations need to be sent to the hardware for execution.  Mesa, however, cannot do this without help as it lives in user space:  only kernel space code is allowed to touch hardware directly.  Note that DDX is one of very few exceptions to this rule: it is technically user space code but allowed direct hardware access, for better or worse.

Unfortunately, sending these instructions through the DDX, and hence X, is not fast enough.  This point finally brings us to…

DRM: Bridge to the Hardware

The final piece of the driver stack is the Direct Rendering Manager.  Oversimplified, it exposes certain features of the hardware with an abstraction layer to user space such that applications like Mesa can make use of a GPU more efficiently.

It is also the job of the DRM layer to provide measures that ensure multiple applications that require working closely with the hardware to not step on each other’s toes.

DRM drivers are Linux kernel modules, which are accessed by user space through libdrm.

All Together Now

So, say you have a shiny new RadeonHD 4870.  What driver features would it take to have it “working under Linux”?

First of all, you need a DDX that can properly mode set the GPU. radeonhd and radeon have both been capable of this for some time.

For fast 2D, again, support needs to be added to the appropriate DDX.  Mostly done, as above.

In terms of accelerated 3D, support from both Mesa and the kernel are required.  As of this writing, work on both are progressing nicely but remain in experimental states.  And, in this particular case, changes were required to libdrm as well.

It should now be clear that, for newer video hardware, there is rarely a trivial answer to the question “Does it work in Linux?”  In fact, it can be downright confusing.

Now, Lets Make It Complicated

Video hardware rarely change completely from generation to generation.  This means that the same code is often times used to operate GPUs from multiple generations.  Understanding which version of which component you need can occasionally become a messy affair.

To draw an example from the Radeon world, R3xx (Radeon 9xxx) and R5xx (Radeon X1xxx) GPUs share a similar 3D engine, but the mode setting engines are drastically different.  Therefore, while you can use the same Mesa DRI driver on both (r300_dri.so), radeonhd will not work on the former.  As for DRM, radeon (note that there is a kernel module and a DDX bearing this name) takes care of everything. (There are, of course, oddities from those generations that do not fit in to this generalization.)

Furthermore, there is currently a push in Linux to move video mode setting into the kernel (Intel is already there).  Kernel Mode Setting, more commonly referred to as KMS, brings the user- and kernel-space separation back to X, relieving the responsibility of hardware manipulation from the DDXes and putting it solely in the DRM drivers.  The details of this topic will—perhaps—be explored another time.

So, Now You Know

Armed with this knowledge, your task is to now educate your fellow Linux users regarding the mistaken concept of “The Linux Graphics Driver”.  Your efforts will, hopefully, help reduce the need for developers to repeat this explanation, again and again.

Tags: , , , ,

25 Responses to “Linux “Graphics Driver Stack” Explained”

  1. Tweets that mention Geek on Two Wheels » Blog Archive » Linux “Graphics Driver Stack” Explained -- Topsy.com Says:

    [...] This post was mentioned on Twitter by Yang Zhao and Yang Zhao, Chris Demwell. Chris Demwell said: RT @yangaroo The " #Linux Graphics Driver Stack": http://bit.ly/4bk7Iu [...]

  2. rofrol's status on Sunday, 18-Oct-09 09:13:20 UTC - Identi.ca Says:

    [...] Linux “Graphics Driver Stack” Explained http://yangman.ca/blog/2009/10/15/linux-graphics-driver-stack-explained/ [...]

  3. koala_man Says:

    Excellent info, thanks!

  4. magnus Says:

    Thanks for this very informative article.

  5. Didier Says:

    Excellent post. I will just suggest to add schemas to explain how the different components work together for 2D and 3D applications, with and without KMS kernel support.

  6. chomwitt Says:

    Very informative article. A question i have is where xorg’s packages fit in the picture you described?
    Is xorg offering only a DDX and the rest (window system etc) are unlreated to the “graphic driver” concept ?

  7. nanonyme Says:

    This is a bit out of date. Nowadays radeonhd is pretty much dead and KMS isn’t something that will happen some day but something most radeon ddx users use.

  8. dE_logics Says:

    That clears things up.

  9. 3d graphics on Linux | bobbyratliff Says:

    [...] The “driver” that is specified in xorg.conf is actually a relatively basic driver that performs the 2D tasks, including compositing and video acceleration. All 3D calls are passed on to Mesa. See the section about DDX (Display Driver for X) in Linux Graphics Driver Stack Explained. [...]

  10. onlinetips Says:

    onlinetips…

    [...]Linux “Graphics Driver Stack” Explained « Geek on Two Wheels[...]…

  11. Linux Server Tutorials Says:

    Linux Server Tutorials…

    [...]Linux “Graphics Driver Stack” Explained « Geek on Two Wheels[...]…

  12. Best Baby Monitors Says:

    This is best informative article , give some more pictures
    thanks a lot for this informative article..

  13. Interior Decorating Says:

    Yea, nice article but it definitely needs more graphics.

  14. 019 JSJ Browserify with James Halliday Says:

    [...] Linux Graphic Stack Explained (blog post) (Tim) [...]

  15. Linux Graphics Stack Questions Says:

    [...] is a graphics card driver made up of? I read this: http://yangman.ca/blog/2009/10/linux…ack-explained/ a) So if one is referring to a graphics card's kernel driver is this always a DRM driver? b) Could [...]

  16. Morgan Says:

    It’s not his primary residence, but Rocky might be willing to put in their use for the results they are hired for. Mix a 50/50 solution of white wine vinegar work well on this type of protection because you are commercial ltd cheltenham pumice stone. Every homeowner should realize the importance of understanding howchemicals we interact with regularlyaffect us.

  17. phen375 Says:

    Well it is true superior in order that you can melt away anything you try to eat.
    Here we expel a few common myths truly is absent by many medical checks to validate its usefulness and
    protection. Always get plenty tablet allows somebody by way of bettering their own metabolism by using a process able
    to seeing that thermogenosis. To read more regarding stop via content potential buyers.
    Nonetheless there are tons of press and concrete figures which might
    be swirling around the web from it program, you should be pairing your upper and
    lower body exercises back to back. Yet back again you are sleeping,
    accept a a greater level of unwanted weight with exercising,
    hugely boosting excess fat reducing of the first 7 days.

    It promotes one’s body heat that is is important to not live a sedentary live of watching TV and eating twinkies. Even though Phen375 is amongst the well-liked fat burning supplement today, in addition to although it sporting activities ths major business within the weight loss will power will be required. Check out our own goods and this is our own be certain that you shall of beneficial motives is undoubtedly protecting your. phen375Feed on 5-6 compact daily meals to keep your energy that, we have a build-up connected with surplus fat. Exactly what is great regarding this, you just need get in an effort to aid you shed those people spare calories from fat. One of the types of fat loss diet pills are called fat burners, and employed in blend having a wholesome, very low-body excess fat dietary program and moderate exercise. Hunger controller Along with burning up capability,there’s also fat cherished discovering media discovered extra details about these body fat burner.

  18. feee3.com Says:

    Undeniably consider that which you said. Your favourite reason seemed to be at the net the easiest thing to be mindful of. I say to you, I certainly get annoyed even as folks think about concerns that they just don’t recognise about. You controlled to hit the nail upon the top and also outlined out the whole thing without having side-effects , people could take a signal. Will likely be back to get more. Thanks

  19. Электронная Москва, Москва, Сайт о Москве, Моя Москва Says:

    Heya i’m for the first time here. I found this board and I to find It truly helpful & it helped me out much. I am hoping to provide one thing again and aid others such as you aided me.

  20. Maisie Says:

    Good depth .

  21. Chiropractors Says:

    At times its safer to just take a step back and comprehend that not everybody shares your beliefs

  22. Loree Kotte Says:

    I’m extremely pleased to uncover this site. I need to to thank you for your time for this particularly fantastic read!! I definitely appreciated every part of it and i also have you saved to fav to check out new stuff in your web site.

  23. learn russian grammar Says:

    I just like the helpful information you supply for your articles. I’ll bookmark your weblog and take a look at once more right here regularly. I’m slightly sure I will be informed many new stuff right here! Good luck for the next!

  24. god hates fags Says:

    hello!,I really like your writing very so much! share we be in contact extra approximately your article on AOL? I need an expert on this area to solve my problem. May be that is you! Taking a look ahead to look you.

  25. viagra Says:

    You actually make it appear really easy together with your presentation
    however I in finding this topic to be actually one thing that I think I might by no means understand.

    It sort of feels too complex and extremely broad for
    me. I am looking forward on your subsequent put up, I’ll attempt to get the hold of it!

Leave a Reply