wl_display is a specially defined object at id 1. You can acquire a proxy to it using shimizu.Connection.getDisplayProxy. However, this will not be the *wl_display Vulkan is expecting. Any references to Wayland objects in Vulkan will be using libwayland, and will require something that links libwayland, like zig-wayland to use.
It is possible to use shimizu and Vulkan together. I’ve done it for seizer, and you can see the crappy abstraction I made over it here. Note that this code has some cruft, and isn’t necessarily the most succinct. Here’s a high level overview of what needs to be done:
- Connect to the Wayland compositor.
- Acquire a Vulkan instance. This doesn’t require any knowledge of the Wayland compositor, you are just getting access to the GPU initially.
- Check if your Wayland compositor exposes a
zwp_linux_dmabuf_v1object from thelinux-dmabuf-v1protocol. We can make do without this extension, see the addendum for details. - Check if your Vulkan device supports
VK_EXT_external_memory_dma_buf. Same as above, we can make do without, see addendum for details. - Create some images to render into, making sure they have
dma_buf_bit_extset. Normally you are instructed to use the Swapchain extension for this, however, we cannot, as it requireslibwayland. - Create
wl_bufferobjects usinglinux-dmabuf-v1by exportingdma_bufhandles from Vulkan. - Tell Vulkan to render into one of images.
- Attach the associated
wl_bufferto awl_surfaceand commit it. - Mark the Vulkan image/wl_buffer as in use until you receive a release event
- Grab another image/wl_buffer and repeat
And if that giant list didn’t scare you off, congratulations!
You can now render to Wayland without linking libwayland! Unfortunately you will still need to link the appropriate libc.
Addendum: Rendering Without linux-dmabuf-v1
The linux-dmabuf-v1 protocol lets us tell the Wayland compositor about framebuffers/images that are located on the GPU. However, if that is unsupported, we can fall back to copying images from the GPU into main memory, and then passing that to the Wayland compositor. Here’s what to change:
- Replace getting the
zwp_linux_dmabuf_v1global with gettingwl_shm - Replace
VK_EXT_external_memory_dma_bufwithVK_KHR_external_memory_fd - Replace
dma_buf_bit_extwithopaque_fd_bit - Create
wl_buffers using a shared memory pool