Mesa (main): anv: Add get/set_tiling helpers

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Nov 9 03:12:53 UTC 2021


Module: Mesa
Branch: main
Commit: 0967584549fa12c754e594dfaf5ac9d7671e7b18
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=0967584549fa12c754e594dfaf5ac9d7671e7b18

Author: Jason Ekstrand <jason at jlekstrand.net>
Date:   Sat Oct 30 15:47:38 2021 -0500

anv: Add get/set_tiling helpers

These are only required WSI cases and Android but still better to have
them in a central place.

Reviwed-by: Paulo Zanoni <paulo.r.zanoni at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13610>

---

 src/intel/vulkan/anv_allocator.c | 32 ++++++++++++++++++++++++++++++++
 src/intel/vulkan/anv_android.c   | 27 ++++++---------------------
 src/intel/vulkan/anv_device.c    | 13 +++++--------
 src/intel/vulkan/anv_image.c     | 30 +++++++-----------------------
 src/intel/vulkan/anv_private.h   |  7 +++++++
 5 files changed, 57 insertions(+), 52 deletions(-)

diff --git a/src/intel/vulkan/anv_allocator.c b/src/intel/vulkan/anv_allocator.c
index 02987e210c3..d43e5626cd7 100644
--- a/src/intel/vulkan/anv_allocator.c
+++ b/src/intel/vulkan/anv_allocator.c
@@ -2019,6 +2019,38 @@ anv_device_export_bo(struct anv_device *device,
    return VK_SUCCESS;
 }
 
+VkResult
+anv_device_get_bo_tiling(struct anv_device *device,
+                         struct anv_bo *bo,
+                         enum isl_tiling *tiling_out)
+{
+   int i915_tiling = anv_gem_get_tiling(device, bo->gem_handle);
+   if (i915_tiling < 0) {
+      return vk_errorf(device, VK_ERROR_INVALID_EXTERNAL_HANDLE,
+                       "failed to get BO tiling: %m");
+   }
+
+   *tiling_out = isl_tiling_from_i915_tiling(i915_tiling);
+
+   return VK_SUCCESS;
+}
+
+VkResult
+anv_device_set_bo_tiling(struct anv_device *device,
+                         struct anv_bo *bo,
+                         uint32_t row_pitch_B,
+                         enum isl_tiling tiling)
+{
+   int ret = anv_gem_set_tiling(device, bo->gem_handle, row_pitch_B,
+                                isl_tiling_to_i915_tiling(tiling));
+   if (ret) {
+      return vk_errorf(device, VK_ERROR_OUT_OF_DEVICE_MEMORY,
+                       "failed to set BO tiling: %m");
+   }
+
+   return VK_SUCCESS;
+}
+
 static bool
 atomic_dec_not_one(uint32_t *counter)
 {
diff --git a/src/intel/vulkan/anv_android.c b/src/intel/vulkan/anv_android.c
index eef859ae249..32a43fc7561 100644
--- a/src/intel/vulkan/anv_android.c
+++ b/src/intel/vulkan/anv_android.c
@@ -522,28 +522,13 @@ anv_image_init_from_gralloc(struct anv_device *device,
                        "failed to import dma-buf from VkNativeBufferANDROID");
    }
 
-   int i915_tiling = anv_gem_get_tiling(device, bo->gem_handle);
-   switch (i915_tiling) {
-   case I915_TILING_NONE:
-      anv_info.isl_tiling_flags = ISL_TILING_LINEAR_BIT;
-      break;
-   case I915_TILING_X:
-      anv_info.isl_tiling_flags = ISL_TILING_X_BIT;
-      break;
-   case I915_TILING_Y:
-      anv_info.isl_tiling_flags = ISL_TILING_Y0_BIT;
-      break;
-   case -1:
-      result = vk_errorf(device, VK_ERROR_INVALID_EXTERNAL_HANDLE,
-                         "DRM_IOCTL_I915_GEM_GET_TILING failed for "
-                         "VkNativeBufferANDROID");
-      goto fail_tiling;
-   default:
-      result = vk_errorf(device, VK_ERROR_INVALID_EXTERNAL_HANDLE,
-                         "DRM_IOCTL_I915_GEM_GET_TILING returned unknown "
-                         "tiling %d for VkNativeBufferANDROID", i915_tiling);
-      goto fail_tiling;
+   enum isl_tiling tiling;
+   result = anv_device_get_bo_tiling(device, bo, &tiling);
+   if (result != VK_SUCCESS) {
+      return vk_errorf(device, result,
+                       "failed to get tiling from VkNativeBufferANDROID");
    }
+   anv_info.isl_tiling_flags = 1u << tiling;
 
    enum isl_format format = anv_get_isl_format(&device->info,
                                                base_info->format,
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index 65211db1fed..ede7ddd0faf 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -3866,15 +3866,12 @@ VkResult anv_AllocateMemory(
        * the BO.  In this case, we have a dedicated allocation.
        */
       if (image->vk.wsi_legacy_scanout) {
-         const uint32_t i915_tiling =
-            isl_tiling_to_i915_tiling(image->planes[0].primary_surface.isl.tiling);
-         int ret = anv_gem_set_tiling(device, mem->bo->gem_handle,
-                                      image->planes[0].primary_surface.isl.row_pitch_B,
-                                      i915_tiling);
-         if (ret) {
+         const struct isl_surf *surf = &image->planes[0].primary_surface.isl;
+         result = anv_device_set_bo_tiling(device, mem->bo,
+                                           surf->row_pitch_B,
+                                           surf->tiling);
+         if (result != VK_SUCCESS) {
             anv_device_release_bo(device, mem->bo);
-            result = vk_errorf(device, VK_ERROR_OUT_OF_DEVICE_MEMORY,
-                               "failed to set BO tiling: %m");
             goto fail;
          }
       }
diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c
index f8f7cd1a003..bf63417b61a 100644
--- a/src/intel/vulkan/anv_image.c
+++ b/src/intel/vulkan/anv_image.c
@@ -1569,30 +1569,14 @@ resolve_ahw_image(struct anv_device *device,
    VkResult result;
 
    /* Check tiling. */
-   int i915_tiling = anv_gem_get_tiling(device, mem->bo->gem_handle);
-   VkImageTiling vk_tiling;
-   isl_tiling_flags_t isl_tiling_flags = 0;
-
-   switch (i915_tiling) {
-   case I915_TILING_NONE:
-      vk_tiling = VK_IMAGE_TILING_LINEAR;
-      isl_tiling_flags = ISL_TILING_LINEAR_BIT;
-      break;
-   case I915_TILING_X:
-      vk_tiling = VK_IMAGE_TILING_OPTIMAL;
-      isl_tiling_flags = ISL_TILING_X_BIT;
-      break;
-   case I915_TILING_Y:
-      vk_tiling = VK_IMAGE_TILING_OPTIMAL;
-      isl_tiling_flags = ISL_TILING_Y0_BIT;
-      break;
-   case -1:
-   default:
-      unreachable("Invalid tiling flags.");
-   }
+   enum isl_tiling tiling;
+   result = anv_device_get_bo_tiling(device, mem->bo, &tiling);
+   assert(result == VK_SUCCESS);
 
-   assert(vk_tiling == VK_IMAGE_TILING_LINEAR ||
-          vk_tiling == VK_IMAGE_TILING_OPTIMAL);
+   VkImageTiling vk_tiling =
+      tiling == ISL_TILING_LINEAR ? VK_IMAGE_TILING_LINEAR :
+                                    VK_IMAGE_TILING_OPTIMAL;
+   isl_tiling_flags_t isl_tiling_flags = (1u << tiling);
 
    /* Check format. */
    VkFormat vk_format = vk_format_from_android(desc.format, desc.usage);
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index 86a8bc39c19..3fdbfce1c8d 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -1390,6 +1390,13 @@ VkResult anv_device_import_bo(struct anv_device *device, int fd,
                               struct anv_bo **bo);
 VkResult anv_device_export_bo(struct anv_device *device,
                               struct anv_bo *bo, int *fd_out);
+VkResult anv_device_get_bo_tiling(struct anv_device *device,
+                                  struct anv_bo *bo,
+                                  enum isl_tiling *tiling_out);
+VkResult anv_device_set_bo_tiling(struct anv_device *device,
+                                  struct anv_bo *bo,
+                                  uint32_t row_pitch_B,
+                                  enum isl_tiling tiling);
 void anv_device_release_bo(struct anv_device *device,
                            struct anv_bo *bo);
 



More information about the mesa-commit mailing list