Linux "graphics driver stack" explained-the clearest explanation of the relationship between Mesa, dri, X Server, and OpenGL

Source: Internet
Author: User
Document directory
  • More than meets the eye
  • DDX: People's favourite barking tree
  • Mesa dri DRIVER: The Invisible Hero
  • DRM: bridge to the hardware
  • All together now
  • Now, lets make it complicated
  • So, now you know
From: http://yangman.ca/blog/2009/10/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 93 MB download. that'sOver one hundred mega bytesOf 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 special 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. and, for good reason: Historically, when processing ing X11, the DDX was one of the few things that had to be configured by the user, and cocould be selected. this is yourRadeonhd,Radeon,NV, AndIntel.

The main function of these drivers is to provide mode setting: that is, selecting the screen resolution, color 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 favorite 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.

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 callinto 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 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...

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 aggressive action 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 wocould 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 been capable of this for some time.

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

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 participates case, changes were required to libdrm as well.

It shoshould 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 moduleAndA 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 encoded ed 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.