<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Nov 7, 2017 at 6:48 AM, Chad Versace <span dir="ltr"><<a href="mailto:chadversary@chromium.org" target="_blank">chadversary@chromium.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Incremental implementation of VK_EXT_image_drm_format_<wbr>modifier.<br>
---<br>
 src/intel/vulkan/anv_image.c   | 72 ++++++++++++++++++++++++++++++<wbr>++++++++----<br>
 src/intel/vulkan/anv_private.h |  6 ++++<br>
 2 files changed, 72 insertions(+), 6 deletions(-)<br>
<br>
diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c<br>
index ba932ba47c3..8d434293124 100644<br>
--- a/src/intel/vulkan/anv_image.c<br>
+++ b/src/intel/vulkan/anv_image.c<br>
@@ -27,6 +27,7 @@<br>
 #include <unistd.h><br>
 #include <fcntl.h><br>
 #include <sys/mman.h><br>
+#include <drm_fourcc.h><br>
<br>
 #include "anv_private.h"<br>
 #include "util/debug.h"<br>
@@ -35,11 +36,12 @@<br>
 #include "vk_format_info.h"<br>
<br>
 static isl_surf_usage_flags_t<br>
-choose_isl_surf_usage(<wbr>VkImageCreateFlags vk_create_flags,<br>
-                      VkImageUsageFlags vk_usage,<br>
+choose_isl_surf_usage(const VkImageCreateInfo *vk_info,<br>
                       isl_surf_usage_flags_t isl_extra_usage,<br>
                       VkImageAspectFlagBits aspect)<br>
 {<br>
+   VkImageCreateFlags vk_create_flags = vk_info->flags;<br>
+   VkImageUsageFlags vk_usage = vk_info->usage;<br>
    isl_surf_usage_flags_t isl_usage = isl_extra_usage;<br>
<br>
    if (vk_usage & VK_IMAGE_USAGE_SAMPLED_BIT)<br>
@@ -87,11 +89,15 @@ choose_isl_surf_usage(<wbr>VkImageCreateFlags vk_create_flags,<br>
       isl_usage |= ISL_SURF_USAGE_RENDER_TARGET_<wbr>BIT;<br>
    }<br>
<br>
+   if (vk_info->tiling == VK_IMAGE_TILING_DRM_FORMAT_<wbr>MODIFIER_EXT)<br>
+      isl_usage |= ISL_SURF_USAGE_DISABLE_AUX_<wbr>BIT;<br>
+<br>
    return isl_usage;<br>
 }<br>
<br>
 static isl_tiling_flags_t<br>
-choose_isl_tiling_flags(const struct anv_image_create_info *anv_info)<br>
+choose_isl_tiling_flags(const struct anv_image_create_info *anv_info,<br>
+                        const struct isl_drm_modifier_info *isl_mod_info)<br>
 {<br>
    const VkImageCreateInfo *base_info = anv_info->vk_info;<br>
    isl_tiling_flags_t flags = 0;<br>
@@ -100,11 +106,16 @@ choose_isl_tiling_flags(const struct anv_image_create_info *anv_info)<br>
    default:<br>
       unreachable("bad VkImageTiling");<br>
    case VK_IMAGE_TILING_OPTIMAL:<br>
+      assert(isl_mod_info == NULL);<br>
       flags = ISL_TILING_ANY_MASK;<br>
       break;<br>
    case VK_IMAGE_TILING_LINEAR:<br>
+      assert(isl_mod_info == NULL);<br>
       flags = ISL_TILING_LINEAR_BIT;<br>
       break;<br>
+   case VK_IMAGE_TILING_DRM_FORMAT_<wbr>MODIFIER_EXT:<br>
+      flags = 1 << isl_mod_info->tiling;<br>
+      break;<br>
    }<br>
<br>
    if (anv_info->isl_tiling_flags)<br>
@@ -298,8 +309,7 @@ make_surface(const struct anv_device *dev,<br>
    struct anv_surface *anv_surf = &image->planes[plane].surface;<br>
<br>
    const isl_surf_usage_flags_t usage =<br>
-      choose_isl_surf_usage(vk_info-<wbr>>flags, image->usage,<br>
-                            anv_info->isl_extra_usage_<wbr>flags, aspect);<br>
+      choose_isl_surf_usage(vk_info, anv_info->isl_extra_usage_<wbr>flags, aspect);<br>
<br>
    /* If an image is created as BLOCK_TEXEL_VIEW_COMPATIBLE, then we need to<br>
     * fall back to linear on Broadwell and earlier because we aren't<br>
@@ -492,6 +502,38 @@ make_surface(const struct anv_device *dev,<br>
    return VK_SUCCESS;<br>
 }<br>
<br>
+static uint32_t<br>
+score_drm_format_mod(uint64_t mod)<br>
+{<br>
+   switch (mod) {<br>
+   default: unreachable("bad DRM format modifier");<br>
+   case I915_FORMAT_MOD_Y_TILED: return 3;<br>
+   case I915_FORMAT_MOD_X_TILED: return 2;<br>
+   case DRM_FORMAT_MOD_LINEAR: return 1;<br>
+   }<br>
+}<br>
+<br>
+static const struct isl_drm_modifier_info *<br>
+choose_drm_format_mod(const VkImageDrmFormatModifierListCr<wbr>eateInfoEXT *mod_list)<br>
+{<br>
+   uint64_t best_mod = UINT64_MAX;<br>
+   uint32_t best_score = 0;<br>
+<br>
+   for (uint32_t i = 0; i < mod_list-><wbr>drmFormatModifierCount; ++i) {<br>
+      uint64_t mod = mod_list->pDrmFormatModifiers[<wbr>i];<br>
+      uint32_t score = score_drm_format_mod(mod);<br>
+<br>
+      if (score > best_score) {<br>
+         best_mod = mod;<br>
+         best_score = score;<br>
+      }<br>
+   }<br>
+<br>
+   assert(best_score != 0);<br>
+<br>
+   return isl_drm_modifier_get_info(<wbr>best_mod);<br>
+}<br></blockquote><div><br></div><div>We did things slightly differently in intel_screen.c but I like this better.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
 VkResult<br>
 anv_image_create(VkDevice _device,<br>
                  const struct anv_image_create_info *create_info,<br>
@@ -500,11 +542,26 @@ anv_image_create(VkDevice _device,<br>
 {<br>
    ANV_FROM_HANDLE(anv_device, device, _device);<br>
    const VkImageCreateInfo *pCreateInfo = create_info->vk_info;<br>
+   const VkImageDrmFormatModifierListCr<wbr>eateInfoEXT *vk_mod_list = NULL;<br>
+   const struct isl_drm_modifier_info *isl_mod_info = NULL;<br>
    struct anv_image *image = NULL;<br>
    VkResult r;<br>
<br>
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_IMAGE_<wbr>CREATE_INFO);<br>
<br>
+   /* Extract input structs */<br>
+   vk_foreach_struct_const(s, pCreateInfo->pNext) {<br>
+      switch (s->sType) {<br>
+      case VK_STRUCTURE_TYPE_IMAGE_DRM_<wbr>FORMAT_MODIFIER_LIST_CREATE_<wbr>INFO_EXT:<br>
+         vk_mod_list = (const VkImageDrmFormatModifierListCr<wbr>eateInfoEXT *) s;<br>
+         isl_mod_info = choose_drm_format_mod(vk_mod_<wbr>list); <br></blockquote><div><br></div><div>Does image creation need to somehow fail if they choose an invalid modifier?  Or are we just trusting that they enumerate correctly?  I'm fine with just trusting the client but I wanted to double-check.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+         break;<br>
+      default:<br>
+         anv_debug_ignored_stype(s-><wbr>sType);<br>
+         break;<br>
+      }<br>
+   }<br>
+<br>
    anv_assert(pCreateInfo-><wbr>mipLevels > 0);<br>
    anv_assert(pCreateInfo-><wbr>arrayLayers > 0);<br>
    anv_assert(pCreateInfo-><wbr>samples > 0);<br>
@@ -529,11 +586,14 @@ anv_image_create(VkDevice _device,<br>
    image->tiling = pCreateInfo->tiling;<br>
    image->disjoint = pCreateInfo->flags & VK_IMAGE_CREATE_DISJOINT_BIT_<wbr>KHR;<br>
<br>
+   if (isl_mod_info)<br>
+      image->drm_format_mod = isl_mod_info->modifier;<br>
+<br>
    const struct anv_format *format = anv_get_format(image->vk_<wbr>format);<br>
    assert(format != NULL);<br>
<br>
    const isl_tiling_flags_t isl_tiling_flags =<br>
-      choose_isl_tiling_flags(<wbr>create_info);<br>
+      choose_isl_tiling_flags(<wbr>create_info, isl_mod_info);<br>
<br>
    image->n_planes = format->n_planes;<br>
<br>
diff --git a/src/intel/vulkan/anv_<wbr>private.h b/src/intel/vulkan/anv_<wbr>private.h<br>
index e17a52a4a70..2312845570b 100644<br>
--- a/src/intel/vulkan/anv_<wbr>private.h<br>
+++ b/src/intel/vulkan/anv_<wbr>private.h<br>
@@ -2337,6 +2337,12 @@ struct anv_image {<br>
    VkImageUsageFlags usage; /**< Superset of VkImageCreateInfo::usage. */<br>
    VkImageTiling tiling; /** VkImageCreateInfo::tiling */<br>
<br>
+   /**<br>
+    * Must be DRM_FORMAT_MOD_INVALID unless tiling is<br>
+    * VK_IMAGE_TILING_DRM_FORMAT_<wbr>MODIFIER_EXT.<br>
+    */<br>
+   uint64_t drm_format_mod;<br>
+<br>
    VkDeviceSize size;<br>
    uint32_t alignment;<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
2.13.0<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>