venus: improve WSI support
venus wsi support should be based on host
-
VK_KHR_external_memory
, -
VK_KHR_external_fence
, -
VK_KHR_external_semaphore
, -
VK_EXT_image_drm_format_modifier
, -
VK_EXT_queue_family_foreign
, and - more? (I haven't done my homework yet)
In other words, we want to implement VK_KHR_swapchain
on top of extensions listed above.
The idea is not new and is not tied to venus. For example, the common wsi support in Mesa has a similar idea although it still (rightfully) makes assumptions about the drivers and has internal callbacks for convenience and for efficiency. The Android loader is similar except that it expects VK_ANDROID_native_buffer
. The challenges for venus are that it must use only publicly defined extensions and must not make assumptions (this is the goal; we probably have to make assumptions initially).
A swapchain image should be created with VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT
.
On Linux, the memory will be allocated by venus and VkImageDrmFormatModifierListCreateInfoEXT
should be chained. On Android, the memory has been allocated by gralloc and VkImageDrmFormatModifierExplicitCreateInfoEXT
must be used. We want to make sure the gralloc handle contains enough info to initialize VkImageDrmFormatModifierExplicitCreateInfoEXT
(Chrome OS has a notorious hack to provide the necessary info).
VkExternalMemoryImageCreateInfo
should also be chained. vkGetPhysicalDeviceImageFormatProperties2
should be used for validity check.
Once a swapchain image is created, we can query drm modifier, strides, memory requirements, etc. normally. A memory is allocated and is bound to the swapchain image. On Linux, VkExportMemoryAllocateInfo
should be chained. A dma-buf will be exported and sent to the window system together with the metadata. On Android, VkImportMemoryFdInfoKHR
should be chained.
vkAcquireNextImage2KHR
and vkQueuePresentKHR
will have non-trivial interactions with fencing. There is no clear answer yet. It is to be worked out in #208 (closed).
venus also needs to translate VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
transitions to ownership transfers. That seems doable by patching VkImageMemoryBarrier
and by inserting vkCmdPipelineBarrier
when a subpass has an implicit transition.