radv: fix missing implementation of creating images from swapchains
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 11 Jan 2023 08:14:08 +0000 (09:14 +0100)
committerEric Engestrom <eric@engestrom.ch>
Thu, 26 Jan 2023 15:40:30 +0000 (15:40 +0000)
These pNext structs are part of VK_KHR_swapchain which is core Vulkan
1.1 but they were missing. Loosely based on ANV.

Passed WSI CTS.

Cc: 22.3 mesa-stable
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/7797
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20641>
(cherry picked from commit 2a5d7f4926c8b3dc702d3ee0e216c563ba7e94db)

.pick_status.json
src/amd/vulkan/radv_device.c
src/amd/vulkan/radv_image.c

index 1830b00..c719527 100644 (file)
         "description": "radv: fix missing implementation of creating images from swapchains",
         "nominated": true,
         "nomination_type": 0,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": null
     },
index 3a3786d..90d037a 100644 (file)
@@ -6155,6 +6155,22 @@ radv_BindImageMemory2(VkDevice _device, uint32_t bindInfoCount,
       RADV_FROM_HANDLE(radv_device_memory, mem, pBindInfos[i].memory);
       RADV_FROM_HANDLE(radv_image, image, pBindInfos[i].image);
 
+      /* Ignore this struct on Android, we cannot access swapchain structures there. */
+#ifdef RADV_USE_WSI_PLATFORM
+      const VkBindImageMemorySwapchainInfoKHR *swapchain_info =
+         vk_find_struct_const(pBindInfos[i].pNext, BIND_IMAGE_MEMORY_SWAPCHAIN_INFO_KHR);
+
+      if (swapchain_info && swapchain_info->swapchain != VK_NULL_HANDLE) {
+         struct radv_image *swapchain_img =
+            radv_image_from_handle(wsi_common_get_image(
+                                   swapchain_info->swapchain, swapchain_info->imageIndex));
+
+         image->bindings[0].bo = swapchain_img->bindings[0].bo;
+         image->bindings[0].offset = swapchain_img->bindings[0].offset;
+         continue;
+      }
+#endif
+
       if (mem->alloc_size) {
          VkImageMemoryRequirementsInfo2 info = {
             .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2,
index 5047cdf..4c62247 100644 (file)
@@ -2400,7 +2400,7 @@ radv_image_queue_family_mask(const struct radv_image *image,
 }
 
 VKAPI_ATTR VkResult VKAPI_CALL
-radv_CreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo,
+radv_CreateImage(VkDevice _device, const VkImageCreateInfo *pCreateInfo,
                  const VkAllocationCallbacks *pAllocator, VkImage *pImage)
 {
 #ifdef ANDROID
@@ -2408,7 +2408,22 @@ radv_CreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo,
       vk_find_struct_const(pCreateInfo->pNext, NATIVE_BUFFER_ANDROID);
 
    if (gralloc_info)
-      return radv_image_from_gralloc(device, pCreateInfo, gralloc_info, pAllocator, pImage);
+      return radv_image_from_gralloc(_device, pCreateInfo, gralloc_info, pAllocator, pImage);
+#endif
+
+#ifdef RADV_USE_WSI_PLATFORM
+   /* Ignore swapchain creation info on Android. Since we don't have an implementation in Mesa,
+    * we're guaranteed to access an Android object incorrectly.
+    */
+   RADV_FROM_HANDLE(radv_device, device, _device);
+   const VkImageSwapchainCreateInfoKHR *swapchain_info =
+      vk_find_struct_const(pCreateInfo->pNext, IMAGE_SWAPCHAIN_CREATE_INFO_KHR);
+   if (swapchain_info && swapchain_info->swapchain != VK_NULL_HANDLE) {
+      return wsi_common_create_swapchain_image(device->physical_device->vk.wsi_device,
+                                               pCreateInfo,
+                                               swapchain_info->swapchain,
+                                               pImage);
+   }
 #endif
 
    const struct wsi_image_create_info *wsi_info =
@@ -2416,7 +2431,7 @@ radv_CreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo,
    bool scanout = wsi_info && wsi_info->scanout;
    bool prime_blit_src = wsi_info && wsi_info->buffer_blit_src;
 
-   return radv_image_create(device,
+   return radv_image_create(_device,
                             &(struct radv_image_create_info){
                                .vk_info = pCreateInfo,
                                .scanout = scanout,