The floor is lawa!
And now for something completely different…
When was the last time you were excited about a simple window with nothing but a single background color? Well, I currently am. Let me tell you about it…
This window is notable, because it was created using the ”pure Hare” Wayland client, and the content - as unspectacular as it may be - is rendered with Vulkan.
This may still not sound like much, so allow me to elaborate. First, an important disclaimer: I have had no exposure to Vulkan before this, so do not assume that any of the Vulkan-specifics in the code are “correct”. I merely wanted to get something to work, as sort of boilerplate code that any interested parties can build upon.
Speaking of boilerplate - I did not know what I was getting myself into, but the main takeaway of this project is: you don’t know what boilerplate really means until you’ve written a Vulkan application. Holy cow…
The starting point for this was a modified version of glad, a Vulkan bindings generator. Vladh maintains a version with Hare support, which just needed some minor updates due to Hare language or stdlib changes. Vlad also has a little ”Vulkan hello world”, which was a good starting point, but it doesn’t do much besides making sure you can talk to the Vulkan driver.
I turned to the apparently quite commonly referenced vulkan-tutorial.com. However, at some point you have to deal with either platform-specific stuff or abstraction libraries. The tutorial uses Win32 for demonstration, so I switched to a Vulkan Wayland example instead.
While that example’s approach is rather obvious, it comes with a significant
issue: it uses a Vulkan extension (VK_KHR_wayland_surface
) which in turn uses
the Wayland C library under the hood. And you have to pass
libwayland-compatible objects to Vulkan calls. Using the “pure Hare” Wayland
client, I had no such objects to pass. I briefly investigated using some sort
of hybrid approach, but it quickly became obvious that it would not work out
great, to phrase it carefully.
Instead, I tried a different approach. Given that I am not after high frame rates for elaborate 3D scenery, I checked out a ”headless” Vulkan example. Vulkan just renders to memory, and the result is copied 1 to a Wayland shared buffer. This seems to work quite well. It should also be performant enough for a retained mode GUI, allowing to offload work to the GPU.
If you are still reading, then you probably want to see what I am actually talking about - here you go, it’s called hare-lawa. For me, this will be the foundation for exploring Vulkan a bit. And if anyone is interested in using Vulkan in Hare: this gives you a complete example of a Wayland application that reacts to window resizing (the color changes based on the window size), requests server-side window decorations, and renders the window contents with Vulkan.
As always, for comments or questions, feel free to drop a mail in my public inbox!
-
Note that for “simplicity”, I hardcoded a color format (ABGR8888) that is supported by both my Vulkan driver and my Wayland server, so that no swizzling has to be performed. While I would expect all Vulkan drivers to support it, I am not sure about Wayland implementations. But this is just a little additional step could easily be added.↩︎