Tales of the M1 GPU
In order to handle all these moving parts in a reasonably safe way, modern GPU drivers are split into two parts: a user space driver and a kernel driver. The user space part is in charge of compiling shader programs and translating API calls (like OpenGL or Vulkan) into the specific command lists that the command processor will use to render the scene. Meanwhile, the kernel part is in charge of managing the MMU and handling memory allocation/deallocation from different apps, as well as deciding how and when to send their commands to the command processor. All modern GPU drivers work this way, on all major OSes!
Between the user space driver and the kernel driver, there is some kind of custom API that is customized for each GPU family. These APIs are usually different for every driver! In Linux we call that the UAPI, but every OS has something similar. This UAPI is what lets the user space part ask the kernel to allocate/deallocate memory and submit command lists to the GPU.
That means that in order to make the M1 GPU work with Asahi Linux, we need two bits: a kernel driver and a user space driver!
Also: Lina: Tales of the M1 GPU [LWN.net]
UPDATE
-
Linux on Apple Silicon Macs Is Now Good Enough for Gaming
Even though the M1 and M2 chips in modern Macs are based on ARM processor designs, they aren’t like any other ARM designs. That has made porting Linux to new Macs a difficult challenge, but there has been some impressive progress recently.
Much of the work around porting desktop Linux to Apple Silicon (M1 & M2) Mac computers has been under the Asahi Linux project, which already offers a desktop distribution that can boot natively on many models. Even though Linux has supported ARM chips for years, largely due to Google’s use of Linux for the Android kernel and devices like the Raspberry Pi, making everything work on Apple Silicon has been a challenge.
The core operating system and desktop experience has been working on Asahi Linux for a while now, so some developers have moved onto proper graphics support. Alyssa Rosenzweig helped reverse engineer the GPU in the M1 chip to create a user space driver, based on documentation work by Dougall Johnson. However, a kernel-level driver was still missing — a task taken up by VTuber Asahi Linya.
Asahi Lina explained in a blog post, “just like other parts of the M1 chip, the GPU has a coprocessor called an “ASC” that runs Apple firmware and manages the GPU. This coprocessor is a full ARM64 CPU running an Apple-proprietary real-time OS called RTKit… and it is in charge of everything! It handles power management, command scheduling and preemption, fault recovery, and even performance counters, statistics, and things like temperature measurement! In fact, the macOS kernel driver doesn’t communicate with the GPU hardware at all.”