diff --git a/src/virtio/vulkan/vn_image.c b/src/virtio/vulkan/vn_image.c index 9226ac68be2..df29ecfee05 100644 --- a/src/virtio/vulkan/vn_image.c +++ b/src/virtio/vulkan/vn_image.c @@ -140,24 +140,22 @@ vn_CreateImage(VkDevice device, struct vn_device *dev = vn_device_from_handle(device); const VkAllocationCallbacks *alloc = pAllocator ? pAllocator : &dev->base.base.alloc; + struct vn_image *img; + VkResult result; - /* TODO wsi_create_native_image uses modifiers or set wsi_info->scanout to - * true. Instead of forcing VK_IMAGE_TILING_LINEAR, we should ask wsi to - * use wsi_create_prime_image instead. - */ +#ifdef VN_USE_WSI_PLATFORM const struct wsi_image_create_info *wsi_info = vk_find_struct_const(pCreateInfo->pNext, WSI_IMAGE_CREATE_INFO_MESA); - VkImageCreateInfo local_create_info; - if (wsi_info && wsi_info->scanout) { - if (VN_DEBUG(WSI)) - vn_log(dev->instance, "forcing scanout image linear"); - local_create_info = *pCreateInfo; - local_create_info.tiling = VK_IMAGE_TILING_LINEAR; - pCreateInfo = &local_create_info; + if (wsi_info) { + assert(wsi_info->scanout); + result = vn_wsi_create_scanout_image(dev, pCreateInfo, alloc, &img); + goto out; } +#endif - struct vn_image *img; - VkResult result = vn_image_create(dev, pCreateInfo, alloc, &img); + result = vn_image_create(dev, pCreateInfo, alloc, &img); + +out: if (result != VK_SUCCESS) return vn_error(dev->instance, result); diff --git a/src/virtio/vulkan/vn_wsi.c b/src/virtio/vulkan/vn_wsi.c index b5bc62a521b..b19cb5f8e1c 100644 --- a/src/virtio/vulkan/vn_wsi.c +++ b/src/virtio/vulkan/vn_wsi.c @@ -11,6 +11,7 @@ #include "vn_wsi.h" #include "vn_device.h" +#include "vn_image.h" #include "vn_queue.h" /* The common WSI support makes some assumptions about the driver. @@ -90,6 +91,30 @@ vn_wsi_fini(struct vn_physical_device *physical_dev) wsi_device_finish(&physical_dev->wsi_device, alloc); } +VkResult +vn_wsi_create_scanout_image(struct vn_device *dev, + const VkImageCreateInfo *create_info, + const VkAllocationCallbacks *alloc, + struct vn_image **out_img) +{ + /* TODO This is the legacy path used by wsi_create_native_image when there + * is no modifier support. Instead of forcing VK_IMAGE_TILING_LINEAR, we + * should ask wsi to use wsi_create_prime_image instead. + * + * In fact, this is not enough when the image is truely used for scanout by + * the host compositor. There can be requirements we fail to meet. We + * should require modifier support at some point. + */ + VkImageCreateInfo local_create_info = *create_info; + local_create_info.tiling = VK_IMAGE_TILING_LINEAR; + create_info = &local_create_info; + + if (VN_DEBUG(WSI)) + vn_log(dev->instance, "forcing scanout image linear"); + + return vn_image_create(dev, create_info, alloc, out_img); +} + /* surface commands */ void diff --git a/src/virtio/vulkan/vn_wsi.h b/src/virtio/vulkan/vn_wsi.h index efed0401b26..bea026049f1 100644 --- a/src/virtio/vulkan/vn_wsi.h +++ b/src/virtio/vulkan/vn_wsi.h @@ -16,12 +16,21 @@ #include "wsi_common.h" #ifdef VN_USE_WSI_PLATFORM + VkResult vn_wsi_init(struct vn_physical_device *physical_dev); void vn_wsi_fini(struct vn_physical_device *physical_dev); + +VkResult +vn_wsi_create_scanout_image(struct vn_device *dev, + const VkImageCreateInfo *create_info, + const VkAllocationCallbacks *alloc, + struct vn_image **out_img); + #else + static inline VkResult vn_wsi_init(UNUSED struct vn_physical_device *physical_dev) { @@ -32,6 +41,7 @@ static inline void vn_wsi_fini(UNUSED struct vn_physical_device *physical_dev) { } + #endif #endif /* VN_WSI_H */