Email or username:

Password:

Forgot your password?
Alyssa Rosenzweig πŸ’œ

3D games on the Apple GPU on Linux, playable at 4K!

Mesa (OpenGL) driver by me, and the GPU kernel driver is by @lina. The shader compiler (part of Mesa) owes to the excellent instruction set reverse-engineering by @dougall.

27 comments
Alyssa Rosenzweig πŸ’œ

@lina @dougall

One task today was optimizing the OpenGL driver so SuperTuxKart would be playable. On Lina's latest stream, she tried to play SuperTuxKart, but it was just too slow.

Why? Every time the application wants to access GPU memory, the driver needs to synchronize access between the CPU and GPU. On a tiler GPU, like Apple's, that synchronization is expensive because it requires flushing out drawing commands. Fortunately, we can skip most of the flushing with some careful driver accounting. With that optimization, SuperTuxKart still works... but now it's fast! βœ¨β€‹

@lina @dougall

One task today was optimizing the OpenGL driver so SuperTuxKart would be playable. On Lina's latest stream, she tried to play SuperTuxKart, but it was just too slow.

Why? Every time the application wants to access GPU memory, the driver needs to synchronize access between the CPU and GPU. On a tiler GPU, like Apple's, that synchronization is expensive because it requires flushing out drawing commands. Fortunately, we can skip most of the flushing with some careful driver accounting....

Alyssa Rosenzweig πŸ’œ

@lina @dougall Another task was getting X11 applications working. On Lina's latest stream, she could try to open X11 applications like xterm and urxvt, but they were unusably glitchy! After getting SuperTuxKart running, I turned to debugging why.

It turns out the culprit was glPointSize(). In OpenGL ES, any time an application renders points, it has to write out the point size as a special variable in the vertex shader. But in OpenGL, the application can omit the write and instead set the point size on the CPU with a glPointSize() call.

Currently, the Asahi Mesa driver handles gl_PointSize variable writes but not glPointSize calls. But that doesn't mean all points will have a "default" size... they'll have undefined sizes! The hardware will read out a variable that's never written, and havoc ensues.

Fortunately, this issue is easy to workaround. All we need to do is add a gl_PointSize write into the vertex shader whenever we see a glPointSize call. Mesa even has common code to do this, we just need to opt-in to using it like Zink does (since layering OpenGL-on-Vulkan has the same problem). So with a single line of code inserted, X11 applications work. Not just xterm and urxvt -- entire desktop environments like MATE seem to render ok, although there's lots of low-hanging performance work to go.

All in all, a good day for Apple GPUs!

@lina @dougall Another task was getting X11 applications working. On Lina's latest stream, she could try to open X11 applications like xterm and urxvt, but they were unusably glitchy! After getting SuperTuxKart running, I turned to debugging why.

It turns out the culprit was glPointSize(). In OpenGL ES, any time an application renders points, it has to write out the point size as a special variable in the vertex shader. But in OpenGL, the application can omit the write and instead set the point size...

Alyssa Rosenzweig πŸ’œ

@lina @dougall While working on these userspace Mesa changes today, I did not hit a single GPU kernel driver bug. Not. A. Single. Bug.

This is thanks to Lina's phenomenal efforts. She took a gamble writing the kernel driver in Rust, knowing it would take longer to get to the first triangle but believing it would make for a more robust driver in the end. She was right.

A few months of Lina's Rust development has produced a more stable driver than years of development in C on certain mainline Linux GPU kernel drivers.

I think... I think I have Rust envy πŸ¦€β€‹

....Or maybe just Lina envy πŸ˜Šβ€‹

@lina @dougall While working on these userspace Mesa changes today, I did not hit a single GPU kernel driver bug. Not. A. Single. Bug.

This is thanks to Lina's phenomenal efforts. She took a gamble writing the kernel driver in Rust, knowing it would take longer to get to the first triangle but believing it would make for a more robust driver in the end. She was right.

emk

@alyssa @lina @dougall I have been super impressed with the early Linux kernel driver work in Rust. I'd built a toy "kernel" while reading the early parts of os.phil-opp.com/ and it was really enjoyable. But seeing that start to happen in a real kernel is amazing.

Coding in Rust just feels solid.

Jonas Greitemann

@alyssa @lina @dougall That is crazy impressive! I wondered how long it would take for Rust inside of Linux to produce tangible benefits. Turns out, not long at all!

karolherbst 🐧 πŸ¦€

@alyssa @lina @dougall I'm really happy that we didn't had a lot of bikeshedding on the Rust topic overall and didn't settle on any compromises either. There were voices of having code touching DRM APIs to not be rust and other nonsensical requests. So I'm glad we as the DRM community "enabled" @lina to work on that :)

ITzTravelInTime

@alyssa @lina @dougall I just hope that way more linux software is moved to rust, especially when it comes to drivers, it just makes sense in the context of low level software to avoid classes of instabilities all together like rust does compared to C.

Btw i also think that linux needs some object oriented driver interfaces, like macOS does, it's amazing how much work it saves for the driver developer.

Asahi Linya (朝ζ—₯γ‚Šγ«γ‚ƒγ€œ)

@ITzTravelInTime @alyssa @dougall Linux is already object oriented! It's just really awkward because it's doing it using a language that isn't ^^;

With Rust abstractions, you end up getting a much more OOP-style interface that fits the kernel APIs better than C! ✨

twitter.com/LinaAsahi/status/1

amarioguy

@alyssa @lina @dougall

nice :) maybe a tad ambitious but linux scheduler in rust eventually? /s

(but seriously the progress on AGX has been amazing, makes me glad to be part of the community lol. i'm debating using rust for the sep driver when that time comes lol)

TellowKrinkle

@alyssa The undefined point sizes happen in Metal as well if you don't write to a `[[point_size]]` output when rendering points. PCSX2 suffered from this for a while until I got a chance to do some screen share debugging with an M1 user.

StuartIanNaylor

@alyssa Have you had chance to check out how Icecream95 is doing with the Mali G610 CSF?

Hector Martin

@StuartIanNaylor icecream95 was banned from fd.o for a reason. Please do not bring him up here.

greatquux

@marcan @StuartIanNaylor damnit you just made me waste 15 minutes trying to dig up all this dirt!

Craig Harrison

@alyssa @lina @dougall That reminds me I *have* to try SuperTuxKart on my M1 Mac Mini.

Go Up