Ekstrand: How to write a Vulkan driver in 2022

Post Syndicated from original https://lwn.net/Articles/889176/

Over on the Collabora blog, Jason Ekstrand has a detailed look at writing a Vulkan graphics driver in today’s world. “Not only has Vulkan grown, but Mesa has as well, and we’ve built up quite a suite of utilities and helpers for making writing Vulkan drivers easier.” The blog post takes the form of a tutorial of sorts, though the end result is not a functioning Vulkan driver the framework of one is shown.

At the time we were developing ANV (the Intel Vulkan driver), the Vulkan spec itself was still under development and everything was constantly in flux. There were no best practices; there were barely even tools. Everyone working on Vulkan was making it up as they went because it was a totally new API. Most of the code we wrote was purpose-built for the Intel driver because there were no other Mesa drivers to share code. (Except for the short-lived LunarG Intel driver based in ilo, which we were replacing.) If we had tried to build abstractions, they could have gotten shot to pieces at any moment by a spec change. (We rewrote the descriptor set layout code from scratch at least five or six times before the driver ever shipped.) It was frustrating, exhausting, and a whole lot of fun.

These days, however, the Vulkan spec has been stable and shipping for six years, the tooling and testing situation is pretty solid, and there are six Vulkan drivers in the Mesa tree with more on the way. We’ve also built up a lot of common infrastructure. This is important both because it makes writing a Vulkan driver easier and because it lets us fix certain classes of annoying bugs in a common place instead of everyone copying and pasting those bugs.