Mesa (master): turnip: rework android gralloc path so it doesn't call tu_image_create

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Nov 2 19:40:31 UTC 2020


Module: Mesa
Branch: master
Commit: 990343b70da7969e84730980c312404ab2509a22
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=990343b70da7969e84730980c312404ab2509a22

Author: Jonathan Marek <jonathan at marek.ca>
Date:   Tue Sep 29 21:27:50 2020 -0400

turnip: rework android gralloc path so it doesn't call tu_image_create

Signed-off-by: Jonathan Marek <jonathan at marek.ca>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7406>

---

 src/freedreno/vulkan/tu_android.c | 58 +++++++++++++++++++--------------------
 src/freedreno/vulkan/tu_image.c   | 32 +++++++++++++--------
 src/freedreno/vulkan/tu_private.h | 19 ++++++-------
 3 files changed, 58 insertions(+), 51 deletions(-)

diff --git a/src/freedreno/vulkan/tu_android.c b/src/freedreno/vulkan/tu_android.c
index 1a0557458c0..58238302960 100644
--- a/src/freedreno/vulkan/tu_android.c
+++ b/src/freedreno/vulkan/tu_android.c
@@ -115,33 +115,21 @@ tu_hal_close(struct hw_device_t *dev)
    return -1;
 }
 
-/**
- * Creates the VkImage using the gralloc handle in *gralloc_info.
- *
- * We support two different grallocs here, gbm_gralloc, and the qcom gralloc
- * used on Android phones.
- */
+/* get dma-buf and modifier from gralloc info */
 VkResult
-tu_image_from_gralloc(VkDevice device_h,
-                      const VkImageCreateInfo *base_info,
-                      const VkNativeBufferANDROID *gralloc_info,
-                      const VkAllocationCallbacks *alloc,
-                      VkImage *out_image_h)
+tu_gralloc_info(struct tu_device *device,
+                const VkNativeBufferANDROID *gralloc_info,
+                int *dma_buf,
+                uint64_t *modifier)
 
 {
-   TU_FROM_HANDLE(tu_device, device, device_h);
-   VkImage image_h = VK_NULL_HANDLE;
-   struct tu_image *image = NULL;
-   VkResult result;
-   bool ubwc = false;
-
    const uint32_t *handle_fds = (uint32_t *)gralloc_info->handle->data;
    const uint32_t *handle_data = &handle_fds[gralloc_info->handle->numFds];
-   int dma_buf;
+   bool ubwc = false;
 
    if (gralloc_info->handle->numFds == 1) {
       /* gbm_gralloc.  TODO: modifiers support */
-      dma_buf = handle_fds[0];
+      *dma_buf = handle_fds[0];
    } else if (gralloc_info->handle->numFds == 2) {
       /* Qualcomm gralloc, find it at:
        *
@@ -174,7 +162,7 @@ tu_image_from_gralloc(VkDevice device_h,
        * of CPU-side metadata.  I haven't found any need for the metadata buffer
        * yet.  See qdMetaData.h for what's in the metadata fd.
        */
-      dma_buf = handle_fds[0];
+      *dma_buf = handle_fds[0];
    } else {
       return vk_errorf(device->instance, VK_ERROR_INVALID_EXTERNAL_HANDLE,
                        "VkNativeBufferANDROID::handle::numFds is %d, "
@@ -182,13 +170,27 @@ tu_image_from_gralloc(VkDevice device_h,
                        gralloc_info->handle->numFds);
    }
 
-   result = tu_image_create(device_h, base_info, alloc, &image_h,
-                            ubwc ?
-                            DRM_FORMAT_MOD_QCOM_COMPRESSED :
-                            DRM_FORMAT_MOD_LINEAR,
-                            NULL);
-   if (result != VK_SUCCESS)
-      return result;
+   *modifier = ubwc ? DRM_FORMAT_MOD_QCOM_COMPRESSED : DRM_FORMAT_MOD_LINEAR;
+   return VK_SUCCESS;
+
+
+}
+
+/**
+ * Creates the VkImage using the gralloc handle in *gralloc_info.
+ *
+ * We support two different grallocs here, gbm_gralloc, and the qcom gralloc
+ * used on Android phones.
+ */
+VkResult
+tu_import_memory_from_gralloc_handle(VkDevice device_h,
+                                     int dma_buf,
+                                     const VkAllocationCallbacks *alloc,
+                                     VkImage image_h)
+
+{
+   struct tu_image *image = NULL;
+   VkResult result;
 
    image = tu_image_from_handle(image_h);
 
@@ -223,8 +225,6 @@ tu_image_from_gralloc(VkDevice device_h,
    tu_BindImageMemory(device_h, image_h, memory_h, 0);
 
    image->owned_memory = memory_h;
-   /* Don't clobber the out-parameter until success is certain. */
-   *out_image_h = image_h;
 
    return VK_SUCCESS;
 
diff --git a/src/freedreno/vulkan/tu_image.c b/src/freedreno/vulkan/tu_image.c
index d6684db089e..dde843e1d6b 100644
--- a/src/freedreno/vulkan/tu_image.c
+++ b/src/freedreno/vulkan/tu_image.c
@@ -81,7 +81,7 @@ tu6_plane_index(VkFormat format, VkImageAspectFlags aspect_mask)
    }
 }
 
-VkResult
+static VkResult
 tu_image_create(VkDevice _device,
                 const VkImageCreateInfo *pCreateInfo,
                 const VkAllocationCallbacks *alloc,
@@ -698,15 +698,6 @@ tu_CreateImage(VkDevice device,
                const VkAllocationCallbacks *pAllocator,
                VkImage *pImage)
 {
-#ifdef ANDROID
-   const VkNativeBufferANDROID *gralloc_info =
-      vk_find_struct_const(pCreateInfo->pNext, NATIVE_BUFFER_ANDROID);
-
-   if (gralloc_info)
-      return tu_image_from_gralloc(device, pCreateInfo, gralloc_info,
-                                   pAllocator, pImage);
-#endif
-
    uint64_t modifier = DRM_FORMAT_MOD_INVALID;
    const VkSubresourceLayout *plane_layouts = NULL;
 
@@ -739,7 +730,26 @@ tu_CreateImage(VkDevice device,
          modifier = DRM_FORMAT_MOD_LINEAR;
    }
 
-   return tu_image_create(device, pCreateInfo, pAllocator, pImage, modifier, plane_layouts);
+#ifdef ANDROID
+   const VkNativeBufferANDROID *gralloc_info =
+      vk_find_struct_const(pCreateInfo->pNext, NATIVE_BUFFER_ANDROID);
+   int dma_buf;
+   if (gralloc_info) {
+      VkResult result = tu_gralloc_info(device, gralloc_info, &dma_buf, &modifier);
+      if (result != VK_SUCCESS)
+         return result;
+   }
+#endif
+
+   VkResult result = tu_image_create(device, pCreateInfo, pAllocator, pImage, modifier, plane_layouts);
+   if (result != VK_SUCCESS)
+      return result;
+
+#ifdef ANDROID
+   if (gralloc_info)
+      return tu_import_memory_from_gralloc_handle(device, dma_buf, pAllocator, *pImage);
+#endif
+   return VK_SUCCESS;
 }
 
 void
diff --git a/src/freedreno/vulkan/tu_private.h b/src/freedreno/vulkan/tu_private.h
index 0b18d8e6067..614094135df 100644
--- a/src/freedreno/vulkan/tu_private.h
+++ b/src/freedreno/vulkan/tu_private.h
@@ -1369,19 +1369,16 @@ tu_cs_image_stencil_ref(struct tu_cs *cs, const struct tu_image_view *iview, uin
    ((iview->x & ~A6XX_##x##_COLOR_FORMAT__MASK) | A6XX_##x##_COLOR_FORMAT(FMT6_8_UINT))
 
 VkResult
-tu_image_create(VkDevice _device,
-                const VkImageCreateInfo *pCreateInfo,
-                const VkAllocationCallbacks *alloc,
-                VkImage *pImage,
-                uint64_t modifier,
-                const VkSubresourceLayout *plane_layouts);
+tu_gralloc_info(struct tu_device *device,
+                const VkNativeBufferANDROID *gralloc_info,
+                int *dma_buf,
+                uint64_t *modifier);
 
 VkResult
-tu_image_from_gralloc(VkDevice device_h,
-                      const VkImageCreateInfo *base_info,
-                      const VkNativeBufferANDROID *gralloc_info,
-                      const VkAllocationCallbacks *alloc,
-                      VkImage *out_image_h);
+tu_import_memory_from_gralloc_handle(VkDevice device_h,
+                                     int dma_buf,
+                                     const VkAllocationCallbacks *alloc,
+                                     VkImage image_h);
 
 void
 tu_image_view_init(struct tu_image_view *iview,



More information about the mesa-commit mailing list