Attempting to use virtio-gpu on Apple Silicon
Just a quick write-up of my most recent attempt to use virtio-gpu on my M2 MacBook Pro, so I (or anybody else) has something to refer to when trying again in future. I decided to try again today because Asahi Linux just released their GPU driver[1]. The result of the experiment was the discovery that virglrenderer requires OpenGL (ES) 3.1[2], but Asahi's driver currently only supports OpenGL (ES) 2. Quoting the release announcement:
What’s next? Supporting more applications. While OpenGL (ES) 2 suffices for some applications, newer ones (especially games) demand more OpenGL features. OpenGL (ES) 3 brings with it a slew of new features, like multiple render targets, multisampling, and transform feedback. Work on these features is well under way, but they will each take a great deal of additional development effort, and all are needed before OpenGL (ES) 3.0 is available.
So for us, it sounds like the thing to do is to wait until newer OpenGL (ES) is supported, and then try again. Anyway, here's what I did: First, I installed installed the GPU drivers on my Asahi install following the instructions in the release announcement. Then, I checked out the wayland branches for Spectrum and Spectrum's Nixpkgs, and grabbed the CARGO_TARGET_*_LINKER and PKG_CONFIG_WAYLAND_PROTOCOLS_PKGDATADIR fixes from commit fb60a5c9473b0796738aa1b1443b8ee5e5ecd1cb to fix the crosvm build on ARM. Then I checked the AsahiLinux/PKGBUILDs repository to see where their mesa sources lived, and found them using commit af7db4903008b012bca13558261d552ed0828b7d from https://gitlab.freedesktop.org/asahi/mesa.git. This Mesa tree was more recent than the one in our Wayland branch, so I needed to backport some Nixpkgs changes to be able to build it. I cherry-picked the following commits: 952dbf0a4ae mesa: build more Vulkan drivers on aarch64-linux 906947555d2 mesa: 22.2.2 -> 22.2.3 7a222ffee31 mesa: fix build on darwin 8d7db0597f9 mesa: rm unused attributes aa8d873a4eb mesa: 22.2.1 -> 22.2.2 33a5279d620 mesa: add vulkanLayers option and default it to device-select, overlay b4b99f16da9 mesa: re-enable video-codecs 445887f636e mesa: 22.1.7 -> 22.2.1 dd3fc581129 mesa: Install radv override configs into $out 40ee116f25a spirv-llvm-translator_14: init at 14.0.0 ea2ca5e6394 spirv-llvm-translator: version depends on llvm version And then I applied Nixpkgs PR #204125, which at the time of writing is still a draft. At this point, I was able to build Mesa 22.3, and then swap in the asahi sources. To get the right drivers to build, I set galliumDrivers to ["swrast" "virgl" "kmsro" "asahi"] and enableGalliumNine to false. Finally, I set up /run/opengl-driver to be a symlink to mesa's drivers output, since that path doesn't usually exist on non-NixOS. To debug why it wasn't working, on Puck's advice I ran the VM in the img/app development shell like this: nix-shell --arg run ../../vm/app/hello-wayland.nix \ --run 'make clean && LIBGL_DEBUG=verbose MESA_DEBUG=1 EGL_LOG_LEVEL=debug make -j4 run VMM=crosvm' This produced (among others) the following message: libEGL debug: context api is 0x40 while config supports 0xd Puck looked up the value of these constants, and determined that it means it doesn't find the required OpenGL (ES) version. [1]: https://asahilinux.org/2022/12/gpu-drivers-now-in-asahi-linux/ [2]: https://gitlab.freedesktop.org/virgl/virglrenderer/-/issues/202
On ke, joulu 7 2022 at 11.54.40 +00:00:00, Alyssa Ross
This Mesa tree was more recent than the one in our Wayland branch, so I needed to backport some Nixpkgs changes to be able to build it. I cherry-picked the following commits:
952dbf0a4ae mesa: build more Vulkan drivers on aarch64-linux 906947555d2 mesa: 22.2.2 -> 22.2.3 7a222ffee31 mesa: fix build on darwin 8d7db0597f9 mesa: rm unused attributes aa8d873a4eb mesa: 22.2.1 -> 22.2.2 33a5279d620 mesa: add vulkanLayers option and default it to device-select, overlay b4b99f16da9 mesa: re-enable video-codecs 445887f636e mesa: 22.1.7 -> 22.2.1 dd3fc581129 mesa: Install radv override configs into $out 40ee116f25a spirv-llvm-translator_14: init at 14.0.0 ea2ca5e6394 spirv-llvm-translator: version depends on llvm version
If you're going to update Mesa package -- I could try to enable acceleration in waypipe if I have Mesa build ? -- vadik likholetov
On Thu, Dec 08, 2022 at 10:53:08AM +0200, vadik likholetov wrote:
On ke, joulu 7 2022 at 11.54.40 +00:00:00, Alyssa Ross
wrote: This Mesa tree was more recent than the one in our Wayland branch, so I needed to backport some Nixpkgs changes to be able to build it. I cherry-picked the following commits:
952dbf0a4ae mesa: build more Vulkan drivers on aarch64-linux 906947555d2 mesa: 22.2.2 -> 22.2.3 7a222ffee31 mesa: fix build on darwin 8d7db0597f9 mesa: rm unused attributes aa8d873a4eb mesa: 22.2.1 -> 22.2.2 33a5279d620 mesa: add vulkanLayers option and default it to device-select, overlay b4b99f16da9 mesa: re-enable video-codecs 445887f636e mesa: 22.1.7 -> 22.2.1 dd3fc581129 mesa: Install radv override configs into $out 40ee116f25a spirv-llvm-translator_14: init at 14.0.0 ea2ca5e6394 spirv-llvm-translator: version depends on llvm version
If you're going to update Mesa package -- I could try to enable acceleration in waypipe if I have Mesa build ?
Well, this attempt was a failure, so I won't be bringing in these Mesa updates, but I will soon be rebasing the Wayland branches onto Spectrum's rootfs branch, which will bring in a recent Mesa. I don't think it will help you with the acceleration, though. Mesa just isn't really compatible with static linking. For acceleration, you probably need to be using pkgsMusl.waypipe, which will be dynamically linked and probably have working Mesa.
participants (2)
-
Alyssa Ross
-
vadik likholetov