After two years of work to reverse engineer Apple Silicon GPU instruction set and to implement the kernel driver, Asahi Linux has finally got an alpha-quality release of its GPU driver that is already good enough to run a smooth desktop experience and some games, Asahi developers Alyssa Rosenzweig and Asahi Lina say.
This release features work-in-progress OpenGL 2.1 and OpenGL ES 2.0 support for all current Apple M-series systems. That’s enough for hardware acceleration with desktop environments, like GNOME and KDE. It’s also enough for older 3D games, like Quake3 and Neverball. While there’s always room for improvement, the driver is fast enough to run all of the above at 60 frames per second at 4K.
Being still an alpha release, there is still much work to do before the GPU driver becomes complete and stable. In particular, OpenGL 3 is still in early stage and Vulkan support is only nascent, although it can reuse the driver, the compiler, and some source code shared with the OpenGL driver. Additionally, the current OpenGL implementation has not passed yet the OpenGL (ES) conformance tests.
The Asahi GPU driver leverages a number of open source projects that provide solid foundations for the reverse engineering effort that the team is carrying through:
The compiler implements a “NIR” backend, where NIR is a powerful intermediate representation, including GLSL to NIR translation. The kernel driver users the “Direct Rendering Manager” (DRM) subsystem of the Linux kernel to minimize boilerplate. Finally, the OpenGL driver implements the “Gallium3D” API inside of Mesa, the home for open source OpenGL and Vulkan drivers.
The GPU driver itself is written in Rust and, being it the first Linux GPU driver, Asahi Linux had to not only implement it but also write the Rust abstractions for the Linux DRM graphics subsystem, including a wrapper around the the kernel C code to provide a safe Rust API.
On August 18th, I started writing the Rust driver. Initially it relied on C code for the MMU handling (partially copied from the Panfrost driver), though later I decided to rewrite all of that in Rust. Over the next few weeks, I added the Rust GPU object system I had prototyped before, and then reimplemented all the other parts of the Python demo driver in Rust.
According to Asahi Lina, Rust has proved to be a great language to write critical code. Rust does nor eliminate all causes for bugs automatically, says Lina, but it enables a coding style where you create safe abstractions around unsafe code, which helps constraining the regions of your codebase that need a thorough auditing, testing, and reviewing.
The alpha GPU driver can be installed directly using the pacman
package manager if you run the linux-asahi-edge kernel.
Besides the new GPU driver, Asahi Linux has been advancing lately, improving support for USB 3, audio management, backlighting, power management, and more.