Mesa (main): anv,vulkan: Move drm_format_mod to vk_image

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Aug 17 21:47:45 UTC 2021


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

Author: Jason Ekstrand <jason at jlekstrand.net>
Date:   Thu Jul 22 15:47:29 2021 -0500

anv,vulkan: Move drm_format_mod to vk_image

Even though we can't really do the parsing on behalf of the driver (it's
too complicated), storing it in the vk_image lets us provide a common
implementation of vkGetImageDrmFormatModifierPropertiesEXT().  It'll
also be useful in the next few commits for swapchain images.

Reviewed-by: Iago Toral Quiroga <itoral at igalia.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12023>

---

 src/intel/vulkan/anv_image.c       | 47 +++++++++++++-------------------------
 src/intel/vulkan/anv_private.h     |  6 -----
 src/intel/vulkan/genX_cmd_buffer.c |  2 +-
 src/vulkan/util/vk_image.c         | 27 ++++++++++++++++++++++
 src/vulkan/util/vk_image.h         | 13 +++++++++++
 5 files changed, 57 insertions(+), 38 deletions(-)

diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c
index 78ef854ba1f..96f4dee8b59 100644
--- a/src/intel/vulkan/anv_image.c
+++ b/src/intel/vulkan/anv_image.c
@@ -71,7 +71,7 @@ image_aspect_to_binding(struct anv_image *image, VkImageAspectFlags aspect)
       /* We don't advertise DISJOINT for modifiers with aux, and therefore we
        * don't handle queries of the modifier's "aux plane" here.
        */
-      assert(!isl_drm_modifier_has_aux(image->drm_format_mod));
+      assert(!isl_drm_modifier_has_aux(image->vk.drm_format_mod));
 
       plane = aspect - VK_IMAGE_ASPECT_MEMORY_PLANE_0_BIT_EXT;
    } else {
@@ -482,7 +482,7 @@ add_aux_state_tracking_buffer(struct anv_device *device,
    enum anv_image_memory_binding binding =
       ANV_IMAGE_MEMORY_BINDING_PLANE_0 + plane;
 
-   if (image->drm_format_mod != DRM_FORMAT_MOD_INVALID)
+   if (image->vk.drm_format_mod != DRM_FORMAT_MOD_INVALID)
        binding = ANV_IMAGE_MEMORY_BINDING_PRIVATE;
 
    /* We believe that 256B alignment may be sufficient, but we choose 4K due to
@@ -687,8 +687,8 @@ add_aux_surface_if_supported(struct anv_device *device,
          enum anv_image_memory_binding binding =
             ANV_IMAGE_MEMORY_BINDING_PLANE_0 + plane;
 
-         if (image->drm_format_mod != DRM_FORMAT_MOD_INVALID &&
-             !isl_drm_modifier_has_aux(image->drm_format_mod))
+         if (image->vk.drm_format_mod != DRM_FORMAT_MOD_INVALID &&
+             !isl_drm_modifier_has_aux(image->vk.drm_format_mod))
             binding = ANV_IMAGE_MEMORY_BINDING_PRIVATE;
 
          result = add_surface(device, image, &image->planes[plane].aux_surface,
@@ -897,8 +897,8 @@ check_memory_bindings(const struct anv_device *device,
       if (anv_surface_is_valid(&plane->aux_surface)) {
          enum anv_image_memory_binding binding = primary_binding;
 
-         if (image->drm_format_mod != DRM_FORMAT_MOD_INVALID &&
-             !isl_drm_modifier_has_aux(image->drm_format_mod))
+         if (image->vk.drm_format_mod != DRM_FORMAT_MOD_INVALID &&
+             !isl_drm_modifier_has_aux(image->vk.drm_format_mod))
             binding = ANV_IMAGE_MEMORY_BINDING_PRIVATE;
 
          /* Display hardware requires that the aux surface start at
@@ -915,7 +915,7 @@ check_memory_bindings(const struct anv_device *device,
       if (plane->fast_clear_memory_range.size > 0) {
          enum anv_image_memory_binding binding = primary_binding;
 
-         if (image->drm_format_mod != DRM_FORMAT_MOD_INVALID)
+         if (image->vk.drm_format_mod != DRM_FORMAT_MOD_INVALID)
             binding = ANV_IMAGE_MEMORY_BINDING_PRIVATE;
 
          /* We believe that 256B alignment may be sufficient, but we choose 4K
@@ -957,14 +957,14 @@ check_drm_format_mod(const struct anv_device *device,
                      const struct anv_image *image)
 {
    /* Image must have a modifier if and only if it has modifier tiling. */
-   assert((image->drm_format_mod != DRM_FORMAT_MOD_INVALID) ==
+   assert((image->vk.drm_format_mod != DRM_FORMAT_MOD_INVALID) ==
           (image->vk.tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT));
 
-   if (image->drm_format_mod == DRM_FORMAT_MOD_INVALID)
+   if (image->vk.drm_format_mod == DRM_FORMAT_MOD_INVALID)
       return VK_SUCCESS;
 
    const struct isl_drm_modifier_info *isl_mod_info =
-      isl_drm_modifier_get_info(image->drm_format_mod);
+      isl_drm_modifier_get_info(image->vk.drm_format_mod);
 
    /* Driver must support the modifier. */
    assert(isl_drm_modifier_get_score(&device->info, isl_mod_info->modifier));
@@ -1291,11 +1291,11 @@ anv_image_create(VkDevice _device,
       }
 
       assert(isl_mod_info);
+      assert(image->vk.drm_format_mod == DRM_FORMAT_MOD_INVALID);
+      image->vk.drm_format_mod = isl_mod_info->modifier;
    }
 
    image->needs_set_tiling = wsi_info && wsi_info->scanout;
-   image->drm_format_mod = isl_mod_info ? isl_mod_info->modifier :
-                                          DRM_FORMAT_MOD_INVALID;
 
    for (int i = 0; i < ANV_IMAGE_MEMORY_BINDING_END; ++i) {
       image->bindings[i] = (struct anv_image_binding) {
@@ -1406,10 +1406,10 @@ anv_image_from_swapchain(VkDevice device,
    VkImageDrmFormatModifierListCreateInfoEXT local_modifier_info = {
       .sType = VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_LIST_CREATE_INFO_EXT,
       .drmFormatModifierCount = 1,
-      .pDrmFormatModifiers = &swapchain_image->drm_format_mod,
+      .pDrmFormatModifiers = &swapchain_image->vk.drm_format_mod,
    };
 
-   if (swapchain_image->drm_format_mod != DRM_FORMAT_MOD_INVALID)
+   if (swapchain_image->vk.drm_format_mod != DRM_FORMAT_MOD_INVALID)
       __vk_append_struct(&local_create_info, &local_modifier_info);
 
    assert(swapchain_image->vk.image_type == local_create_info.imageType);
@@ -1846,7 +1846,7 @@ void anv_GetImageSubresourceLayout(
          unreachable("bad VkImageAspectFlags");
       }
 
-      if (mem_plane == 1 && isl_drm_modifier_has_aux(image->drm_format_mod)) {
+      if (mem_plane == 1 && isl_drm_modifier_has_aux(image->vk.drm_format_mod)) {
          assert(image->n_planes == 1);
          /* If the memory binding differs between primary and aux, then the
           * returned offset will be incorrect.
@@ -1887,21 +1887,6 @@ void anv_GetImageSubresourceLayout(
    }
 }
 
-VkResult anv_GetImageDrmFormatModifierPropertiesEXT(
-    VkDevice                                    device,
-    VkImage                                     _image,
-    VkImageDrmFormatModifierPropertiesEXT*      pProperties)
-{
-   ANV_FROM_HANDLE(anv_image, image, _image);
-
-   assert(pProperties->sType ==
-          VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT);
-
-   pProperties->drmFormatModifier = image->drm_format_mod;
-
-   return VK_SUCCESS;
-}
-
 /**
  * This function returns the assumed isl_aux_state for a given VkImageLayout.
  * Because Vulkan image layouts don't map directly to isl_aux_state enums, the
@@ -1962,7 +1947,7 @@ anv_layout_to_aux_state(const struct intel_device_info * const devinfo,
       assert(image->vk.aspects == VK_IMAGE_ASPECT_COLOR_BIT);
 
       enum isl_aux_state aux_state =
-         isl_drm_modifier_get_default_aux_state(image->drm_format_mod);
+         isl_drm_modifier_get_default_aux_state(image->vk.drm_format_mod);
 
       switch (aux_state) {
       default:
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index a5ed4c1be3a..0ff036bef4a 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -3961,12 +3961,6 @@ struct anv_image {
     */
    bool needs_set_tiling;
 
-   /**
-    * Must be DRM_FORMAT_MOD_INVALID unless tiling is
-    * VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT.
-    */
-   uint64_t drm_format_mod;
-
    /**
     * Image has multi-planar format and was created with
     * VK_IMAGE_CREATE_DISJOINT_BIT.
diff --git a/src/intel/vulkan/genX_cmd_buffer.c b/src/intel/vulkan/genX_cmd_buffer.c
index da793ab28a3..89f81b032ac 100644
--- a/src/intel/vulkan/genX_cmd_buffer.c
+++ b/src/intel/vulkan/genX_cmd_buffer.c
@@ -1184,7 +1184,7 @@ transition_color_buffer(struct anv_cmd_buffer *cmd_buffer,
           final_layout != VK_IMAGE_LAYOUT_PREINITIALIZED);
    const struct isl_drm_modifier_info *isl_mod_info =
       image->vk.tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT
-      ? isl_drm_modifier_get_info(image->drm_format_mod)
+      ? isl_drm_modifier_get_info(image->vk.drm_format_mod)
       : NULL;
 
    const bool src_queue_external =
diff --git a/src/vulkan/util/vk_image.c b/src/vulkan/util/vk_image.c
index 663a2090eb5..e583459f564 100644
--- a/src/vulkan/util/vk_image.c
+++ b/src/vulkan/util/vk_image.c
@@ -25,7 +25,12 @@
 
 #include <vulkan/vulkan_android.h>
 
+#ifndef _WIN32
+#include <drm-uapi/drm_fourcc.h>
+#endif
+
 #include "vk_alloc.h"
+#include "vk_common_entrypoints.h"
 #include "vk_device.h"
 #include "vk_format.h"
 #include "vk_util.h"
@@ -95,6 +100,10 @@ vk_image_init(struct vk_device *device,
    else
       image->external_handle_types = 0;
 
+#ifndef _WIN32
+   image->drm_format_mod = ((1ULL << 56) - 1) /* DRM_FORMAT_MOD_INVALID */;
+#endif
+
 #ifdef ANDROID
    const VkExternalFormatANDROID *ext_format =
       vk_find_struct_const(pCreateInfo->pNext, EXTERNAL_FORMAT_ANDROID);
@@ -140,6 +149,24 @@ vk_image_destroy(struct vk_device *device,
    vk_object_free(device, alloc, image);
 }
 
+#ifndef _WIN32
+VKAPI_ATTR VkResult VKAPI_CALL
+vk_common_GetImageDrmFormatModifierPropertiesEXT(UNUSED VkDevice device,
+                                                 VkImage _image,
+                                                 VkImageDrmFormatModifierPropertiesEXT *pProperties)
+{
+   VK_FROM_HANDLE(vk_image, image, _image);
+
+   assert(pProperties->sType ==
+          VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT);
+
+   assert(image->tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT);
+   pProperties->drmFormatModifier = image->drm_format_mod;
+
+   return VK_SUCCESS;
+}
+#endif
+
 void
 vk_image_set_format(struct vk_image *image, VkFormat format)
 {
diff --git a/src/vulkan/util/vk_image.h b/src/vulkan/util/vk_image.h
index 9a694b24824..5ff55377aef 100644
--- a/src/vulkan/util/vk_image.h
+++ b/src/vulkan/util/vk_image.h
@@ -53,6 +53,19 @@ struct vk_image {
    /* VK_KHR_external_memory */
    VkExternalMemoryHandleTypeFlags external_handle_types;
 
+#ifndef _WIN32
+   /* VK_EXT_drm_format_modifier
+    *
+    * Initialized by vk_image_create/init() to DRM_FORMAT_MOD_INVALID.  It's
+    * the job of the driver to parse the VK_EXT_drm_format_modifier extension
+    * structs and choose the actual modifier.
+    *
+    * Must be DRM_FORMAT_MOD_INVALID unless tiling is
+    * VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT.
+    */
+   uint64_t drm_format_mod;
+#endif
+
 #ifdef ANDROID
    /* VK_ANDROID_external_memory_android_hardware_buffer */
    uint64_t android_external_format;



More information about the mesa-commit mailing list