*

kms_swrast: A hardware-backed graphics driver

Robert Foss avatar

Posted on 01/08/2018 by Robert Foss

Share this post:

Presenting kms_swrast, a new, hardware-backed, software graphics driver, built upon the Mesa gallium driver framework, which uses kernel kms drm nodes for memory allocation.

Stack overview

Let's start with having a look at a high level overview of what the graphics stack looks like.

Linux graphics stack

Before digging too much further into this, lets cover some terminology.

DRM - Direct Rendering Manager - is the Linux kernel graphics subsystem, which contains all of the graphics drivers and does all of the interfacing with hardware.
The DRM subsystem implements the KMS - kernel mode setting - API.

Mode setting is essentially configuring output settings like resolution for the displays that are being used. And doing it using the kernel means that userspace doesn't need access to setting these things directly.

Mesa internals

The DRM subsystem talks to the hardware and Mesa is used by applications through the APIs it implements. APIs like OpenGL, OpenGL ES, Vulkan, etc. All of Mesa is built ontop of DRM and libdrm.

libdrm is a userspace library that wraps the DRM subsystem in order to simplify talking to drivers and avoiding common bugs in every user of DRM.

kms_swrast diagram

Looking inside Mesa we find the Gallium driver framework. It is what most of the Mesa drivers are built using, with the Intel i965 driver being the major exception.

kms_swrast is built using Gallium, with the intention of re-using as much of the infrastructure provided by Gallium and KMS as possible instead.

kms_swrast itself is backed by a backend, like softpipe or the faster llvmpipe, which actually implements the 3D primitives and functionality needed in order to reach OpenGL and OpenGL ES compliance.

Softpipe is the older and less complicated of the two implementations, whereas is llvmpipe is newer and relies on LLVM as an external dependency.
But as a result llvmpipe support JIT-compilation for example, which makes it a lot faster.

Why is this a good idea?

Re-using the Gallium framework gives you a lot of things for free. And the driver can remain relatively lightweight.

Apart from the features that Gallium provides today, you'll also get free access to new features in the future, without having to write them yourself.
And since Gallium is shared between many drivers, it will be better tested and have fewer bugs than any one driver.

kms_swrast is built using DRM and actual kernel drivers, but no rendering hardware is actually used. Which may seem a bit odd.

So why are the kernel drivers used for a software renderer? The answer is two-fold.

It is what Gallium expects, and in order to not have to make invasive changes to it, just providing it with access to some driver is the simplest possible solution. Since the actual hardware is mostly unused, it doesn't really matter what hardware you use.

The DRM driver is actually only used for a single thing, to allocate a slice of memory which can be used to render pixels to and then be sent to the display.

Thanks

This post has been a part of work undertaken by my employer Collabora.


Visit Robert's blog.

Comments (2)

  1. Salekin:
    Aug 03, 2018 at 06:12 AM

    What are the steps to get this on Ubuntu 18.08?

    Reply to this comment

    Reply to this comment

    1. Robert Foss:
      Aug 03, 2018 at 11:52 AM

      Hey Salekin,

      This code is written for the Android platform, so it isn't available for Ubuntu.
      That being said, you can already run llvmpipe as a fallback on Ubuntu 18.04.

      https://gitlab.collabora.com/robertfoss/mesa/commits/kms_swrast_v3

      Reply to this comment

      Reply to this comment


Add a Comment






Allowed tags: <b><i><br>Add a new comment:


Latest Blog Posts

A dream come true: Android is finally using DRM/KMS

17/12/2018

Released a few months ago, the Google Pixel 3 is the first Android phone running with the mainline graphics stack. A feat that was deemed…

Convincing your manager that upstreaming is in their best interest

28/11/2018

In an ideal world, everyone would implicitly understand that it just makes good business sense to upstream some of the modifications made…

Metrics for test suite comprehensiveness

23/11/2018

How can we measure the comprehensiveness of a test suite? Code coverage is the standard metric used in the industry and makes intuitive…

Gaining eBPF vision: A new way to trace Linux filesystem disk requests

21/11/2018

A real-world use case of eBPF tracing to understand file access patterns in the Linux kernel and optimize large applications.

Quick hack: Speed up your GitLab CI

06/11/2018

Did you know you could register your own PC, or a spare laptop collecting dust in a drawer, to get instant CI going on GitLab? Not only…

Introducing Zink, an OpenGL implementation on top of Vulkan

31/10/2018

For the last month or so, I've been playing with a new project during my work at Collabora, and as I've already briefly talked about at…

Open Since 2005 logo

We use cookies on this website to ensure that you get the best experience. By continuing to use this website you are consenting to the use of these cookies. To find out more please follow this link.

Collabora Ltd © 2005-2018. All rights reserved. Website sitemap.