How DRI and DRM Work

Introduction

This page is intended as an introduction to what DRI and DRM are, how they fit into the overall structure of X, Mesa and so on, and why you should care about it if you're developing applications which make use of graphics acceleration. It's written with the SMedia Glamo chip of the Openmoko Neo FreeRunner in mind, but many of the concepts are generally applicable to all graphics hardware. However, more advanced hardware is generally a lot more complicated than the technology described here...

The Hardware

The graphics processor (GPU) is separate from the main CPU, and has its own memory. The graphics chip can't access the main system memory at all [1], but** the graphics memory ("VRAM") can be mapped into the CPU's address space and then written to or read from**. If we didn't care about accelerated graphics, we would just program the GPU to display a section of its VRAM on the LCD screen, and write what we wanted to display.

But we want to do some slightly more exciting things. To use acceleration features, a sequence of commands has to be written to a circular buffer, in VRAM, of commands. Circular in this sense means that when there is no more space left at the end of the buffer, writing begins again at the start of the buffer. Hopefully the buffer is long enough that the program can write a significant number of commands, then go away and do something else while they execute.

Commands submitted via this buffer (known as the "command queue", "ring buffer" or similar) generally need to refer to other buffers in VRAM. For instance, if we told the GPU to turn the entire screen blue, we would need to send a command sequence which described that a flood fill operation was to be performed, that it was to be done using the colour blue, and that the buffer to be filled with blue was the same buffer we previously told it to display on the LCD.

Historical Situation

Previously, all applications which used hardware acceleration would contain a full implementation of the code required to allocate VRAM for the command queue, program the command queue processor (part of the GPU) to read commands from the newly allocated buffer, and to keep updating its configuration every time new commands were written. There'd also be a lot of error-checking to be done to make sure everything went smoothly. In addition, it'd have to handle memory management if it wanted to allocate more buffers in VRAM - for instance, to hold the contents of offscreen windows ready to be quickly copied onto the screen. This is a lot of programming, but is the situation we currently have with the Glamo chip. The X server (both the old Kdrive-based server (Xglamo) and the more recent X.org driver xf86-video-glamo) contains command queue handling code, as does the accelerated version of mplayer.

It's pretty clear that multiple applications can't simultaneously use the acceleration - they'd both be trying to manage a single command queue and pool of VRAM in their own ways, and the results could range from instability to outright catastrophe. This is one of the things DRI is here to fix.

DRM - Kernel Level Support

The Direct Rendering Manager, DRM, is the kernel part of the wider Direct Rendering Infrastructure (DRI). With DRM, all the command queue and VRAM handling is done by the kernel, and there's an ioctl interface through which userspace programs can ask it to do things. For example, a program might ask to allocate some VRAM, and the DRM will return a unique handle by which the program can refer to the newly allocated VRAM. The kernel, aware of the requests from the multiple programs, can coordinate memory management across them all. If the program needed to read or write its VRAM, it could ask the kernel to map the memory into the program's address space. The subset of the DRM ioctl interface which takes care of memory is called GEM [2].

Command queue handling is similar. If the program wanted to submit a sequence of commands, it could call another ioctl with its commands, and the kernel would add it to the command queue. Part of the beauty of all this is that only the kernel has to know where the objects in VRAM actually reside at any point, and it can move some of them out of VRAM if space becomes tight. Userspace programs just use their unique handles to refer to memory, and let the kernel take care of making sure that the correct buffers are in the right places at the right times.

Finally, there's a library ("libDRM") which exists to make handling DRM's ioctls a little easier.

EXA - X Server Acceleration

I mentioned that the X server used to be one of the programs which wanted to access the hardware to send command sequences. With DRM in place, the X server uses the ioctl interface to pass its commands down to the kernel. The GEM interface is used to allocate VRAM for offscreen pixmaps.

DRI - X Server Support

"DRI" could be taken to mean the overall infrastructure which makes accelerated rendering possible. The DRI interface, which is what this section is about, is specific to X. It consists of a handful of X requests by which X clients can request that the X server allows it to carry out accelerated rendering to a particular window. The client asks for a handle for the window, and uses that handle to tell the kernel to draw things, for instance using the 3D engine of the graphics hardware. When it's finished drawing a frame, the client asks the X server to swap the buffers (assuming, say, a double-buffered OpenGL context) so that the contents are visible on the screen.

DRI is just one way to use the underlying DRM framework. For instance, there are other graphics systems (such as Wayland) which also use DRM to access the hardware.

KMS - Kernel Modesetting

There's just one more piece to the puzzle, which is called KMS. This could be the subject of a whole new article, but here's a short overview. Previously, the X driver would directly program the hardware, just as it had to program the command queue engine itself. With KMS, it can ask the kernel to set a certain display resolution, colour depth, or whatever. At the same time, the X driver can send the kernel its handle for a memory buffer which should be used as the contents of the screen. Since the kernel is in complete control of the actual programming of the hardware, it can switch back in the case of, say, a kernel panic or X server crash.

Conclusion

This mostly isn't as complicated as it sounds...! For examples of what programs which use DRM look like, take a look at the Glamo DRI tests. Despite the name, most of these just test DRM, and are independent of the higher-level DRI interfaces.

From: https://www.bitwiz.org.uk/s/how-dri-and-drm-work.html

How DRI and DRM Work的更多相关文章

  1. AM335x(TQ335x)学习笔记——LCD驱动移植

    TI的LCD控制器驱动是非常完善的,共通的地方已经由驱动封装好了,与按键一样,我们可以通过DTS配置完成LCD的显示.下面,我们来讨论下使用DTS方式配置内核完成LCD驱动的思路. (1)初步分析 由 ...

  2. 如何理解显示卡的驱动模块(DDX,DRM,DRI,XVMC)

    如何理解显示卡的驱动模块(DDX,DRM,DRI,XVMC) 1)DDX是什么 DDX是X服务器的2D驱动模块,例如via_drv.so. 2D的显示加速,包括xvideo也是由它负责. 它会初始化硬 ...

  3. Linux中的DRM

    如果在搜索引擎离搜索 DRM 映入眼帘的尽是Digital Rights Managemen,也就是数字版权加密保护技术.这当然不是我们想要的解释.在类unix世界中还有一个DRM即The Direc ...

  4. 【原创】Linux环境下的图形系统和AMD R600显卡编程(2)——Framebuffer、DRM、EXA和Mesa简介【转】

    转自:http://www.cnblogs.com/shoemaker/p/linux_graphics02.html 1. Framebuffer Framebuffer驱动提供基本的显示,fram ...

  5. Linux环境下的图形系统和AMD R600显卡编程(2)——Framebuffer、DRM、EXA和Mesa简介

    转:https://www.cnblogs.com/shoemaker/p/linux_graphics02.html 1. Framebuffer Framebuffer驱动提供基本的显示,fram ...

  6. Linux Graphic DRI Wayland 显示子系统

    转:https://blog.csdn.net/u013165704/article/details/80709547 1. 前言 上篇文章(Linux graphic subsytem(1)_概述) ...

  7. 【ARM-Linux开发】DRM学习(一)

    http://www.landley.NET/kdocs/htmldocs/drm.html 非常好的一个链接,直接把DRM说的很透.很多API的功能都写全了. Table of Contents 1 ...

  8. linux DRM/KMS 测试工具 modetest、kmscude、igt-gpu-tools (一)

    这里整理几个在学习Linux DRM/KMS中用到的几个工具,modetest.kmscude.igt-gpu-tools. 简介: modetest 是由libdrm提供的测试程序,可以查询显示设备 ...

  9. linux DRM/KMS 测试工具 modetest、kmscude、igt-gpu-tools (二)

    kmscube   kmscube is a little demonstration program for how to drive bare metal graphics without a c ...

随机推荐

  1. Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2) E. Let Them Slide(数据结构+差分)

     题意:问你有n个长度总和为n的数组 你可以移动数组 但不能移出长度为w的矩形框 问你每一列的最大值是多少? 思路:只有一次询问 我们可以考虑差分来解决 然后对于每一行数组 我们可以用数据结构维护一下 ...

  2. [ICPC 2018 宁夏邀请赛] A-Maximum Element In A Stack(思维)

    >传送门< 前言 辣鸡网络赛,虽然我是个菜鸡,然而好几个队伍十几分钟就AK???我心态那会彻底崩了,后来群里炸了,话题直接上知乎热搜,都是2018ICPC宁夏网络赛原题,这怎么玩,拼手速? ...

  3. 【bzoj 3232】圈地游戏(算法效率--01分数规划+图论--最小割)

    题目:DZY家的后院有一块地,由N行M列的方格组成,格子内种的菜有一定的价值,并且每一条单位长度的格线有一定的费用.DZY喜欢在地里散步.他总是从任意一个格点出发,沿着格线行走直到回到出发点,且在行走 ...

  4. tomacat配置虚拟主机 && 配置缺省页面

    在conf文件夹下的server.xml文件中 在c盘建立一个sina文件夹,里面建立一个mail文件夹,在mail文件夹下面建立一个1.html网页 你配置完如果直接访问http://www.sin ...

  5. 【POJ 1148】Utopia Divided

    Utopia Divided 题目链接:POJ 1148 题目大意 在一个坐标系中,一个点一开始在原点,然后被要求每次走到一个规定的象限内. 你有一些互不相同的数,每次你可以选每选过的两个,正负性可以 ...

  6. 5.2 spring5源码--spring AOP源码分析三---切面源码分析

    一. AOP切面源码分析 源码分析分为三部分 1. 解析切面 2. 创建动态代理 3. 调用 源码的入口 源码分析的入口, 从注解开始: 组件的入口是一个注解, 比如启用AOP的注解@EnableAs ...

  7. 通过修改etcd来设置或修改节点flannel子网信息

    在首次启动flannel服务的时候可以手动指定subnet.env文件,配置所在节点的flannel子网网段,如果不指定配置文件,flannel将自动分配一个子网网段并生成配置文件 /var/run/ ...

  8. HDU 6155 Subsequence Count(矩阵 + DP + 线段树)题解

    题意:01串,操作1:把l r区间的0变1,1变0:操作2:求出l r区间的子序列种数 思路:设DP[i][j]为到i为止以j结尾的种数,假设j为0,那么dp[i][0] = dp[i - 1][1] ...

  9. ZOJ 3430 Detect the Virus(AC自动机 + 模拟)题解

    题意:问你主串有几种模式串.但是所有串都是加密的,先解码.解码过程为:先把串按照他给的映射表变成6位数二进制数,然后首尾衔接变成二进制长串,再8位8位取变成新的数,不够的补0.因为最多可能到255,所 ...

  10. 3D 室内装修线设计软件

    3D 室内装修线设计软件 WebGL & canvas https://threejs.org/ xgqfrms 2012-2020 www.cnblogs.com 发布文章使用:只允许注册用 ...