vulkan/wsi: Use the interface from the real modifiers extension
authorJason Ekstrand <jason.ekstrand@intel.com>
Mon, 1 Oct 2018 21:14:24 +0000 (16:14 -0500)
committerMarge Bot <eric+marge@anholt.net>
Fri, 17 Jan 2020 18:27:29 +0000 (18:27 +0000)
The anv implementation still isn't quite complete, but we can at least
start using the structs from the real extension.

v2: Fix circular pNext list (Lionel)

Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3434>

src/freedreno/vulkan/tu_formats.c
src/freedreno/vulkan/tu_image.c
src/intel/vulkan/anv_extensions.py
src/intel/vulkan/anv_formats.c
src/intel/vulkan/anv_image.c
src/intel/vulkan/anv_wsi.c
src/vulkan/wsi/wsi_common.c
src/vulkan/wsi/wsi_common.h

index a0a18c1728d212bc2d9744c051d0a9a5a194b2b7..1f5dfc4a2328629ecc8f79cd9ec484d3857d6713 100644 (file)
@@ -786,20 +786,21 @@ tu_GetPhysicalDeviceFormatProperties2(
    tu_physical_device_get_format_properties(
       physical_device, format, &pFormatProperties->formatProperties);
 
-   struct wsi_format_modifier_properties_list *list =
-      vk_find_struct(pFormatProperties->pNext, WSI_FORMAT_MODIFIER_PROPERTIES_LIST_MESA);
+   VkDrmFormatModifierPropertiesListEXT *list =
+      vk_find_struct(pFormatProperties->pNext, DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT);
    if (list) {
-      VK_OUTARRAY_MAKE(out, list->modifier_properties, &list->modifier_count);
+      VK_OUTARRAY_MAKE(out, list->pDrmFormatModifierProperties,
+                       &list->drmFormatModifierCount);
 
       vk_outarray_append(&out, mod_props) {
-         mod_props->modifier = DRM_FORMAT_MOD_LINEAR;
-         mod_props->modifier_plane_count = 1;
+         mod_props->drmFormatModifier = DRM_FORMAT_MOD_LINEAR;
+         mod_props->drmFormatModifierPlaneCount = 1;
       }
 
       /* TODO: any cases where this should be disabled? */
       vk_outarray_append(&out, mod_props) {
-         mod_props->modifier = DRM_FORMAT_MOD_QCOM_COMPRESSED;
-         mod_props->modifier_plane_count = 1;
+         mod_props->drmFormatModifier = DRM_FORMAT_MOD_QCOM_COMPRESSED;
+         mod_props->drmFormatModifierPlaneCount = 1;
       }
    }
 }
index 83e0d9e9b2a43ba01dafc90ff3d8c9363e655274..1f4c454299d84fdd65ef307159c39cd66291a1d7 100644 (file)
@@ -346,14 +346,15 @@ tu_CreateImage(VkDevice device,
                                    pAllocator, pImage);
 #endif
 
-   const struct wsi_image_create_info *wsi_info =
-      vk_find_struct_const(pCreateInfo->pNext, WSI_IMAGE_CREATE_INFO_MESA);
    uint64_t modifier = DRM_FORMAT_MOD_INVALID;
+   if (pCreateInfo->tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
+      const VkImageDrmFormatModifierListCreateInfoEXT *mod_info =
+         vk_find_struct_const(pCreateInfo->pNext,
+                              IMAGE_DRM_FORMAT_MODIFIER_LIST_CREATE_INFO_EXT);
 
-   if (wsi_info) {
       modifier = DRM_FORMAT_MOD_LINEAR;
-      for (unsigned i = 0; i < wsi_info->modifier_count; i++) {
-         if (wsi_info->modifiers[i] == DRM_FORMAT_MOD_QCOM_COMPRESSED)
+      for (unsigned i = 0; i < mod_info->drmFormatModifierCount; i++) {
+         if (mod_info->pDrmFormatModifiers[i] == DRM_FORMAT_MOD_QCOM_COMPRESSED)
             modifier = DRM_FORMAT_MOD_QCOM_COMPRESSED;
       }
    }
index 99076f4d16e65cd236daec6e061958c5c974246b..de57f5f300d621868187b3fcb4fe4a4a252fb966 100644 (file)
@@ -144,6 +144,7 @@ EXTENSIONS = [
     Extension('VK_EXT_global_priority',                   1,
               'device->has_context_priority'),
     Extension('VK_EXT_host_query_reset',                  1, True),
+    Extension('VK_EXT_image_drm_format_modifier',         1, False),
     Extension('VK_EXT_index_type_uint8',                  1, True),
     Extension('VK_EXT_inline_uniform_block',              1, True),
     Extension('VK_EXT_line_rasterization',                1, True),
index 7bd08c8772290afbbe2a7a0c801b998ef3e20847..a1c4923cf2cd7840614523f53041ff44b551d554 100644 (file)
@@ -717,11 +717,12 @@ get_buffer_format_features(const struct gen_device_info *devinfo,
 static void
 get_wsi_format_modifier_properties_list(const struct anv_physical_device *physical_device,
                                         VkFormat vk_format,
-                                        struct wsi_format_modifier_properties_list *list)
+                                        VkDrmFormatModifierPropertiesListEXT *list)
 {
    const struct anv_format *anv_format = anv_get_format(vk_format);
 
-   VK_OUTARRAY_MAKE(out, list->modifier_properties, &list->modifier_count);
+   VK_OUTARRAY_MAKE(out, list->pDrmFormatModifierProperties,
+                    &list->drmFormatModifierCount);
 
    /* This is a simplified list where all the modifiers are available */
    assert(vk_format == VK_FORMAT_B8G8R8_SRGB ||
@@ -751,11 +752,11 @@ get_wsi_format_modifier_properties_list(const struct anv_physical_device *physic
          continue;
 
       vk_outarray_append(&out, mod_props) {
-         mod_props->modifier = modifiers[i];
+         mod_props->drmFormatModifier = modifiers[i];
          if (isl_drm_modifier_has_aux(modifiers[i]))
-            mod_props->modifier_plane_count = 2;
+            mod_props->drmFormatModifierPlaneCount = 2;
          else
-            mod_props->modifier_plane_count = anv_format->n_planes;
+            mod_props->drmFormatModifierPlaneCount = anv_format->n_planes;
       }
    }
 }
@@ -793,7 +794,7 @@ void anv_GetPhysicalDeviceFormatProperties2(
    vk_foreach_struct(ext, pFormatProperties->pNext) {
       /* Use unsigned since some cases are not in the VkStructureType enum. */
       switch ((unsigned)ext->sType) {
-      case VK_STRUCTURE_TYPE_WSI_FORMAT_MODIFIER_PROPERTIES_LIST_MESA:
+      case VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT:
          get_wsi_format_modifier_properties_list(physical_device, format,
                                                  (void *)ext);
          break;
index 14dd88537c148069b3aedddeb1bfdf6e57eff5b4..37e1cae32ae39628559792da1d206bce2bb43839 100644 (file)
@@ -111,6 +111,8 @@ choose_isl_tiling_flags(const struct anv_image_create_info *anv_info,
    case VK_IMAGE_TILING_LINEAR:
       flags = ISL_TILING_LINEAR_BIT;
       break;
+   case VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT:
+      flags = 1 << isl_mod_info->tiling;
    }
 
    if (anv_info->isl_tiling_flags)
@@ -119,9 +121,6 @@ choose_isl_tiling_flags(const struct anv_image_create_info *anv_info,
    if (legacy_scanout)
       flags &= ISL_TILING_LINEAR_BIT | ISL_TILING_X_BIT;
 
-   if (isl_mod_info)
-      flags &= 1 << isl_mod_info->tiling;
-
    assert(flags);
 
    return flags;
@@ -589,10 +588,14 @@ anv_image_create(VkDevice _device,
 
    const struct wsi_image_create_info *wsi_info =
       vk_find_struct_const(pCreateInfo->pNext, WSI_IMAGE_CREATE_INFO_MESA);
-   if (wsi_info && wsi_info->modifier_count > 0) {
+
+   if (pCreateInfo->tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
+      const VkImageDrmFormatModifierListCreateInfoEXT *mod_info =
+         vk_find_struct_const(pCreateInfo->pNext,
+                              IMAGE_DRM_FORMAT_MODIFIER_LIST_CREATE_INFO_EXT);
       isl_mod_info = choose_drm_format_mod(&device->instance->physicalDevice,
-                                           wsi_info->modifier_count,
-                                           wsi_info->modifiers);
+                                           mod_info->drmFormatModifierCount,
+                                           mod_info->pDrmFormatModifiers);
       assert(isl_mod_info);
    }
 
@@ -725,13 +728,13 @@ anv_image_from_swapchain(VkDevice device,
    local_create_info.usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
 
    /* If the image has a particular modifier, specify that modifier. */
-   struct wsi_image_create_info local_wsi_info = {
-      .sType = VK_STRUCTURE_TYPE_WSI_IMAGE_CREATE_INFO_MESA,
-      .modifier_count = 1,
-      .modifiers = &swapchain_image->drm_format_mod,
+   VkImageDrmFormatModifierListCreateInfoEXT local_modifier_info = {
+      .sType = VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_LIST_CREATE_INFO_EXT,
+      .drmFormatModifierCount = 1,
+      .pDrmFormatModifiers = &swapchain_image->drm_format_mod,
    };
    if (swapchain_image->drm_format_mod != DRM_FORMAT_MOD_INVALID)
-      __vk_append_struct(&local_create_info, &local_wsi_info);
+      __vk_append_struct(&local_create_info, &local_modifier_info);
 
    return anv_image_create(device,
       &(struct anv_image_create_info) {
@@ -1066,6 +1069,21 @@ 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 determines the optimal buffer to use for a given
  * VkImageLayout and other pieces of information needed to make that
index ed5d077b4abed3cddda5fb415d556861dee46e7b..29f13a06e1aa77928666ce603b8a12706a4d39aa 100644 (file)
@@ -33,13 +33,6 @@ anv_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName)
    return anv_lookup_entrypoint(&physical_device->info, pName);
 }
 
-static uint64_t
-anv_wsi_image_get_modifier(VkImage _image)
-{
-   ANV_FROM_HANDLE(anv_image, image, _image);
-   return image->drm_format_mod;
-}
-
 static void
 anv_wsi_signal_semaphore_for_memory(VkDevice _device,
                                     VkSemaphore _semaphore,
@@ -97,7 +90,6 @@ anv_init_wsi(struct anv_physical_device *physical_device)
       return result;
 
    physical_device->wsi_device.supports_modifiers = true;
-   physical_device->wsi_device.image_get_modifier = anv_wsi_image_get_modifier;
    physical_device->wsi_device.signal_semaphore_for_memory =
       anv_wsi_signal_semaphore_for_memory;
    physical_device->wsi_device.signal_fence_for_memory =
index e8e38843fceffec164d88f3fd727304d41107531..cc5e233093f7f2be11f36de7561a776bd5f0f0b5 100644 (file)
@@ -90,6 +90,7 @@ wsi_device_init(struct wsi_device *wsi,
    WSI_GET_CB(FreeMemory);
    WSI_GET_CB(FreeCommandBuffers);
    WSI_GET_CB(GetBufferMemoryRequirements);
+   WSI_GET_CB(GetImageDrmFormatModifierPropertiesEXT);
    WSI_GET_CB(GetImageMemoryRequirements);
    WSI_GET_CB(GetImageSubresourceLayout);
    WSI_GET_CB(GetMemoryFdKHR);
@@ -350,11 +351,6 @@ wsi_create_native_image(const struct wsi_swapchain *chain,
    for (int i = 0; i < ARRAY_SIZE(image->fds); i++)
       image->fds[i] = -1;
 
-   struct wsi_image_create_info image_wsi_info = {
-      .sType = VK_STRUCTURE_TYPE_WSI_IMAGE_CREATE_INFO_MESA,
-      .pNext = NULL,
-   };
-
    VkImageCreateInfo image_info = {
       .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
       .flags = 0,
@@ -376,20 +372,24 @@ wsi_create_native_image(const struct wsi_swapchain *chain,
       .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
    };
 
-   __vk_append_struct(&image_info, &image_wsi_info);
+   struct wsi_image_create_info image_wsi_info;
+   VkImageDrmFormatModifierListCreateInfoEXT image_modifier_list;
 
    uint32_t image_modifier_count = 0, modifier_prop_count = 0;
-   struct wsi_format_modifier_properties *modifier_props = NULL;
+   struct VkDrmFormatModifierPropertiesEXT *modifier_props = NULL;
    uint64_t *image_modifiers = NULL;
    if (num_modifier_lists == 0) {
       /* If we don't have modifiers, fall back to the legacy "scanout" flag */
-      image_wsi_info.scanout = true;
+      image_wsi_info = (struct wsi_image_create_info) {
+         .sType = VK_STRUCTURE_TYPE_WSI_IMAGE_CREATE_INFO_MESA,
+         .scanout = true,
+      };
+      __vk_append_struct(&image_info, &image_wsi_info);
    } else {
       /* The winsys can't request modifiers if we don't support them. */
       assert(wsi->supports_modifiers);
-      struct wsi_format_modifier_properties_list modifier_props_list = {
-         .sType = VK_STRUCTURE_TYPE_WSI_FORMAT_MODIFIER_PROPERTIES_LIST_MESA,
-         .pNext = NULL,
+      struct VkDrmFormatModifierPropertiesListEXT modifier_props_list = {
+         .sType = VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT,
       };
       VkFormatProperties2 format_props = {
          .sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2,
@@ -398,10 +398,10 @@ wsi_create_native_image(const struct wsi_swapchain *chain,
       wsi->GetPhysicalDeviceFormatProperties2KHR(wsi->pdevice,
                                                  pCreateInfo->imageFormat,
                                                  &format_props);
-      assert(modifier_props_list.modifier_count > 0);
+      assert(modifier_props_list.drmFormatModifierCount > 0);
       modifier_props = vk_alloc(&chain->alloc,
                                 sizeof(*modifier_props) *
-                                modifier_props_list.modifier_count,
+                                modifier_props_list.drmFormatModifierCount,
                                 8,
                                 VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
       if (!modifier_props) {
@@ -409,11 +409,11 @@ wsi_create_native_image(const struct wsi_swapchain *chain,
          goto fail;
       }
 
-      modifier_props_list.modifier_properties = modifier_props;
+      modifier_props_list.pDrmFormatModifierProperties = modifier_props;
       wsi->GetPhysicalDeviceFormatProperties2KHR(wsi->pdevice,
                                                  pCreateInfo->imageFormat,
                                                  &format_props);
-      modifier_prop_count = modifier_props_list.modifier_count;
+      modifier_prop_count = modifier_props_list.drmFormatModifierCount;
 
       uint32_t max_modifier_count = 0;
       for (uint32_t l = 0; l < num_modifier_lists; l++)
@@ -436,7 +436,7 @@ wsi_create_native_image(const struct wsi_swapchain *chain,
           */
          for (uint32_t i = 0; i < num_modifiers[l]; i++) {
             for (uint32_t j = 0; j < modifier_prop_count; j++) {
-               if (modifier_props[j].modifier == modifiers[l][i])
+               if (modifier_props[j].drmFormatModifier == modifiers[l][i])
                   image_modifiers[image_modifier_count++] = modifiers[l][i];
             }
          }
@@ -447,8 +447,13 @@ wsi_create_native_image(const struct wsi_swapchain *chain,
       }
 
       if (image_modifier_count > 0) {
-         image_wsi_info.modifier_count = image_modifier_count;
-         image_wsi_info.modifiers = image_modifiers;
+         image_modifier_list = (VkImageDrmFormatModifierListCreateInfoEXT) {
+            .sType = VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_LIST_CREATE_INFO_EXT,
+            .drmFormatModifierCount = image_modifier_count,
+            .pDrmFormatModifiers = image_modifiers,
+         };
+         image_info.tiling = VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT;
+         __vk_append_struct(&image_info, &image_modifier_list);
       } else {
          /* TODO: Add a proper error here */
          assert(!"Failed to find a supported modifier!  This should never "
@@ -511,12 +516,20 @@ wsi_create_native_image(const struct wsi_swapchain *chain,
       goto fail;
 
    if (num_modifier_lists > 0) {
-      image->drm_modifier = wsi->image_get_modifier(image->image);
+      VkImageDrmFormatModifierPropertiesEXT image_mod_props = {
+         .sType = VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT,
+      };
+      result = wsi->GetImageDrmFormatModifierPropertiesEXT(chain->device,
+                                                           image->image,
+                                                           &image_mod_props);
+      if (result != VK_SUCCESS)
+         goto fail;
+      image->drm_modifier = image_mod_props.drmFormatModifier;
       assert(image->drm_modifier != DRM_FORMAT_MOD_INVALID);
 
       for (uint32_t j = 0; j < modifier_prop_count; j++) {
-         if (modifier_props[j].modifier == image->drm_modifier) {
-            image->num_planes = modifier_props[j].modifier_plane_count;
+         if (modifier_props[j].drmFormatModifier == image->drm_modifier) {
+            image->num_planes = modifier_props[j].drmFormatModifierPlaneCount;
             break;
          }
       }
index 3e3f79b1a4a92cee4fe595c60963a401ccce52b4..8d63303933102824bb0d0ead60159b74dcf0233d 100644 (file)
@@ -35,7 +35,6 @@
  */
 #define VK_STRUCTURE_TYPE_WSI_IMAGE_CREATE_INFO_MESA (VkStructureType)1000001002
 #define VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA (VkStructureType)1000001003
-#define VK_STRUCTURE_TYPE_WSI_FORMAT_MODIFIER_PROPERTIES_LIST_MESA (VkStructureType)1000001004
 #define VK_STRUCTURE_TYPE_WSI_SURFACE_SUPPORTED_COUNTERS_MESA (VkStructureType)1000001005
 #define VK_STRUCTURE_TYPE_WSI_MEMORY_SIGNAL_SUBMIT_INFO_MESA (VkStructureType)1000001006
 
@@ -43,9 +42,6 @@ struct wsi_image_create_info {
     VkStructureType sType;
     const void *pNext;
     bool scanout;
-
-    uint32_t modifier_count;
-    const uint64_t *modifiers;
 };
 
 struct wsi_memory_allocate_info {
@@ -54,20 +50,6 @@ struct wsi_memory_allocate_info {
     bool implicit_sync;
 };
 
-struct wsi_format_modifier_properties {
-   uint64_t modifier;
-   uint32_t modifier_plane_count;
-};
-
-/* Chain in for vkGetPhysicalDeviceFormatProperties2KHR */
-struct wsi_format_modifier_properties_list {
-   VkStructureType sType;
-   const void *pNext;
-
-   uint32_t modifier_count;
-   struct wsi_format_modifier_properties *modifier_properties;
-};
-
 /* To be chained into VkSurfaceCapabilities2KHR */
 struct wsi_surface_supported_counters {
    VkStructureType sType;
@@ -166,6 +148,7 @@ struct wsi_device {
    WSI_CB(FreeMemory);
    WSI_CB(FreeCommandBuffers);
    WSI_CB(GetBufferMemoryRequirements);
+   WSI_CB(GetImageDrmFormatModifierPropertiesEXT);
    WSI_CB(GetImageMemoryRequirements);
    WSI_CB(GetImageSubresourceLayout);
    WSI_CB(GetMemoryFdKHR);