openglx11vulkanpixmap

Vulkan and X11 Pixmap


I'm writing an X11 window manager with a Vulkan based compositor. I'm wondering if there's a way to efficiently load window pixmaps as textures.

In OpenGL, one would directly use the EXT_texture_from_pixmap extension to bind the pixmap to a texture. In Vulkan there is no such thing as far as I know.

I've been looking into inter-operation between Vulkan and OpenGL, ie. create a GL context just to use the pixmap extension, and then use the external_objects and such extensions to bring the loaded texture available for Vulkan. But on my Intel HD 630 it seems that the required GL_EXT_memory_object is not available (using Mesa 18.3 dev and latest kernel, if there's a way to enable it somehow, that'd be great).

Currently as a workaround I'm using CPU to get the pixels from the pixmap and then staging it to GPU memory. Obviously this can be very slow with high resolutions, even when restricting the upload to damaged regions only.

What would be the best way to efficiently retrieve the pixmap contents to be used in Vulkan based renderer?


Solution

  • The correct way to handle this is to use the xcb DRI3 extension to get the DMA-buf fd of the pixmap, after which we can import the memory using VK_KHR_external_memory_fd and VK_EXT_external_memory_dma_buf. Additionally, VK_EXT_image_drm_format_modifier will be required to deal with the vendor specific format of the buffer (specified by the DRM modifier), but unfortunately this extension is not available yet. Until that happens, one could maybe workaround with GBM to convert the internal format and tiling of the buffer to linear, after which the import should become relatively simple.