Mesa Developers Debate Using Rust Code In Mesa

From LinuxReviews
Jump to navigationJump to search
Glxgears-with-hud.jpg

The Mesa code-base does not have any code written in the Rust programming language. That could change. Alyssa Rosenzweig has taken the initiative to allow parts of Mesa to be written in Rust.

 Original story by opennet.ru. Originally published 2020-10-04.
English translation by linuxreviews.org 2020-10-06.
This work is licensed under the Creative Commons Attribution-ShareAlike. Rusty-chain.jpg
The Mesa developers are discussing if they should allow Rust within the Mesa source code.

Alyssa Rosenzweig, developer of the Panfrost GPU Mail for the Midgard and Bifrost architectures and the biggest individual contributor to Mesa 20.2.0, has proposed that some parts of Mesa could be (re-)written in the Rust programming language.

"Recently I've been thinking about the potential for the Rust programming language in Mesa. Rust bills itself a safe system programming language with comparable performance to C [0], which is a naturally fit for graphics driver development.

Mesa today is written primarily in C, a notoriously low-level language, with some components in C++. To handle the impedance mismatch, we've built up a number of abstractions in-tree, including multiple ad hoc code generators (GenXML, NIR algebraic passes, Bifrost disassembler). A higher level language can help avoid the web of metaprogramming and effect code that is simpler and easier to reason about. Similarly, a better type system can aid static analysis.

Beyond abstraction, Rust's differentiating feature is the borrow checker to guarantee memory safety. Historically, safety has not been a primary concern of graphics drivers, since drivers are implemented as regular userspace code running in the process of the application calling them. Unfortunately, now that OpenGL is being exposed to untrusted code via WebGL, the driver does become an attack vector."

Mesa-dev: Rust drivers in Mesa, by Alyssa Rosenzweig, October 2nd, 2020

The proposal is being discussed, no concrete decision for or against have been made.

Rust proponents highlight that Rust is better at memory safety which could help eliminate problems with use-after-free. de-referenced null pointers and buffer overflows. Rust support would also allow Mesa to adopt third party code written in Rust such as the Kazan software renderer for Vulkan.

Alyssa Rosenzweig noted that driver security has become a more immediate concern due to technologies like WebGL that allow code which interacts with the Mesa drivers to be executed in web browsers. Mesa does have tools to do automated code analysis to reveal any potential security issues, but they may not be enough.

Rust opponents like Francisco Jerez, who only contributed 23 commits to Mesa 20.2.0, argue that most of the advantages Rust would bring could just as easily be obtained to moving to a modern C++ standard. This would be a better fit with Mesa's existing code-base which is written in very beautiful C.

A more complicated build system is another, in my humble opinion very valid argument, against using Rust in Mesa. Other concerns include the cargo build system pulling all kinds of packages from the Internet, additional build requirements, and the need to include a Rust compiler in order to build a key dependency most Linux distributions include.

The move towards Rust may be favored by AMD who are currently listing a job opening for a "3D Driver Tool Development Engineer" with "Contribute to the development of new tooling with Rust and 3D graphics drivers with C++" among the "Key Responsibilities".

0.00
(0 votes)


Add your comment
LinuxReviews welcomes all comments. If you do not want to be anonymous, register or log in. It is free.