<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Hello,</div><div><br></div><div>Please find my comment below:<br></div><div><br><div class="gmail_quote"><div dir="ltr">On Mon, Nov 5, 2018 at 5:36 PM Lionel Landwerlin <<a href="mailto:lionel.g.landwerlin@intel.com">lionel.g.landwerlin@intel.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">We add a function that allows us to check whether a particular<br>
description of a Vulkan format is available for a given device.<br>
<br>
Signed-off-by: Lionel Landwerlin <<a href="mailto:lionel.g.landwerlin@intel.com" target="_blank">lionel.g.landwerlin@intel.com</a>><br>
---<br>
 src/intel/vulkan/anv_formats.c    | 65 ++++++++++++++++++++++++-------<br>
 src/intel/vulkan/anv_image.c      |  4 +-<br>
 src/intel/vulkan/anv_private.h    |  4 +-<br>
 src/intel/vulkan/vk_format_info.h |  2 +-<br>
 4 files changed, 57 insertions(+), 18 deletions(-)<br>
<br>
diff --git a/src/intel/vulkan/anv_formats.c b/src/intel/vulkan/anv_formats.c<br>
index 250af958d2e..c23fc1c5b1f 100644<br>
--- a/src/intel/vulkan/anv_formats.c<br>
+++ b/src/intel/vulkan/anv_formats.c<br>
@@ -42,6 +42,16 @@<br>
       ISL_CHANNEL_SELECT_##a, \<br>
 }<br>
<br>
+static bool all_gens_compatible(const struct gen_device_info *devinfo)<br>
+{<br>
+   return true;<br>
+}<br>
+<br>
+static bool gen11_compatible(const struct gen_device_info *devinfo)<br>
+{<br>
+   return devinfo->gen >= 11;<br>
+}<br>
+<br>
 #define RGBA _ISL_SWIZZLE(RED, GREEN, BLUE, ALPHA)<br>
 #define BGRA _ISL_SWIZZLE(BLUE, GREEN, RED, ALPHA)<br>
 #define RGB1 _ISL_SWIZZLE(RED, GREEN, BLUE, ONE)<br>
@@ -55,6 +65,7 @@<br>
          },                                                     \<br>
       },                                                        \<br>
       .n_planes = 1,                                            \<br>
+      .compatible = all_gens_compatible,                        \<br>
    }<br>
<br>
 #define fmt1(__hw_fmt) \<br>
@@ -69,6 +80,7 @@<br>
          },                                                  \<br>
       },                                                     \<br>
       .n_planes = 1,                                         \<br>
+      .compatible = all_gens_compatible,                     \<br>
    }<br>
<br>
 #define s_fmt(__hw_fmt)                                      \<br>
@@ -80,6 +92,7 @@<br>
          },                                                  \<br>
       },                                                     \<br>
       .n_planes = 1,                                         \<br>
+      .compatible = all_gens_compatible,                     \<br>
    }<br>
<br>
 #define ds_fmt(__fmt1, __fmt2)                               \<br>
@@ -95,6 +108,7 @@<br>
          },                                                  \<br>
       },                                                     \<br>
       .n_planes = 2,                                         \<br>
+      .compatible = all_gens_compatible,                     \<br>
    }<br>
<br>
 #define fmt_unsupported                             \<br>
@@ -130,6 +144,17 @@<br>
       },                                     \<br>
       .n_planes = __n_planes,                \<br>
       .can_ycbcr = true,                     \<br>
+      .compatible = all_gens_compatible,     \<br>
+   }<br>
+<br>
+#define ycbcr_gen_fmt(__n_planes, __compatible, ...)    \<br>
+   {                                                    \<br>
+      .planes = {                                       \<br>
+         __VA_ARGS__,                                   \<br>
+      },                                                \<br>
+      .n_planes = __n_planes,                           \<br>
+      .can_ycbcr = true,                                \<br>
+      .compatible = __compatible,                       \<br>
    }<br>
<br>
 #define fmt_list(__vk_fmt, ...)                                 \<br>
@@ -335,12 +360,22 @@ static const struct anv_format *main_formats[] = {<br>
 };<br>
<br>
 static const struct anv_format *ycbcr_formats[] = {<br>
+   /**<br>
+    * On Gen10 and below, the HW sampler won't allow us to have 2 different<br>
+    * view of a same buffer. This was changed on Gen11, so we can now make the<br>
+    * 2 format below use 2 planes. This gives more flexibility in terms of how<br>
+    * we want to same chroma components.<br>
+    */<br>
    fmt_list(VK_FORMAT_G8B8G8R8_422_UNORM,<br>
-            ycbcr_fmt(1,<br>
-                      y_plane(ISL_FORMAT_YCRCB_SWAPUV, RGBA, _ISL_SWIZZLE(BLUE, GREEN, RED, ZERO)))),<br>
+            ycbcr_gen_fmt(2, gen11_compatible,<br>
+                          y_plane(ISL_FORMAT_R8G8_UNORM, RGBA, _ISL_SWIZZLE(GREEN, ZERO, ZERO, ZERO)),<br>
+                          chroma_plane(0, ISL_FORMAT_R8G8B8A8_UNORM, RGBA, _ISL_SWIZZLE(ZERO, BLUE, ZERO, RED), 2, 1)),<br>
+            ycbcr_fmt(1, y_plane(ISL_FORMAT_YCRCB_SWAPUV, RGBA, _ISL_SWIZZLE(BLUE, GREEN, RED, ZERO)))),<br>
    fmt_list(VK_FORMAT_B8G8R8G8_422_UNORM,<br>
-            ycbcr_fmt(1,<br>
-                      y_plane(ISL_FORMAT_YCRCB_SWAPUVY, RGBA, _ISL_SWIZZLE(BLUE, GREEN, RED, ZERO)))),<br>
+            ycbcr_gen_fmt(2, gen11_compatible,<br>
+                          y_plane(ISL_FORMAT_R8G8_UNORM, RGBA, _ISL_SWIZZLE(ZERO, GREEN, ZERO, ZERO)),<br>
+                          chroma_plane(0, ISL_FORMAT_R8G8B8A8_UNORM, RGBA, _ISL_SWIZZLE(BLUE, ZERO, RED, ZERO), 2, 1)),<br>
+            ycbcr_fmt(1, y_plane(ISL_FORMAT_YCRCB_SWAPUVY, RGBA, _ISL_SWIZZLE(BLUE, GREEN, RED, ZERO)))),<br>
    fmt_list(VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM,<br>
             ycbcr_fmt(3,<br>
                       y_plane(ISL_FORMAT_R8_UNORM, RGBA, _ISL_SWIZZLE(GREEN, ZERO, ZERO, ZERO)),<br>
@@ -436,7 +471,7 @@ static const struct {<br>
 };<br>
<br>
 const struct anv_format *<br>
-anv_get_format(VkFormat vk_format)<br>
+anv_get_format(const struct gen_device_info *devinfo, VkFormat vk_format)<br>
 {<br>
    uint32_t enum_offset = VK_ENUM_OFFSET(vk_format);<br>
    uint32_t ext_number = VK_ENUM_EXTENSION(vk_format);<br>
@@ -450,17 +485,19 @@ anv_get_format(VkFormat vk_format)<br>
    if (!format)<br>
       return NULL;<br>
<br>
-   if (format[0].n_planes == 0)<br>
-      return NULL;<br>
+   for (int i = 0; format[i].n_planes != 0; i++) {<br>
+      if (!devinfo || format[i].compatible(devinfo))<br></blockquote><div><br></div>I may be wrong but seems like it could be checked just once before this loop:<br><br>   if (!devinfo)<br>      return (format[0].n_planes != 0) ? &format[0] : NULL;</div><div class="gmail_quote"><br>I guess it is not really matter but anyway just for case if you make v2 patch for some reason :-)<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+         return &format[i];<br>
+   }<br>
<br>
-   return &format[0];<br>
+   return NULL;<br>
 }<br>
<br>
 struct anv_format_plane<br>
 anv_get_format_nth_plane(const struct gen_device_info *devinfo, VkFormat vk_format,<br>
                          uint32_t plane, VkImageTiling tiling)<br>
 {<br>
-   const struct anv_format *format = anv_get_format(vk_format);<br>
+   const struct anv_format *format = anv_get_format(devinfo, vk_format);<br>
    const struct anv_format_plane unsupported = {<br>
       .isl_format = ISL_FORMAT_UNSUPPORTED,<br>
    };<br>
@@ -520,7 +557,7 @@ anv_get_format_plane(const struct gen_device_info *devinfo, VkFormat vk_format,<br>
                      VkImageAspectFlagBits aspect, VkImageTiling tiling)<br>
 {<br>
    uint32_t plane =<br>
-      anv_format_aspect_to_plane(anv_get_format(vk_format), aspect);<br>
+      anv_format_aspect_to_plane(anv_get_format(devinfo, vk_format), aspect);<br>
    return anv_get_format_nth_plane(devinfo, vk_format, plane, tiling);<br>
 }<br>
<br>
@@ -746,7 +783,7 @@ get_wsi_format_modifier_properties_list(const struct anv_physical_device *physic<br>
                                         VkFormat vk_format,<br>
                                         struct wsi_format_modifier_properties_list *list)<br>
 {<br>
-   const struct anv_format *anv_format = anv_get_format(vk_format);<br>
+   const struct anv_format *anv_format = anv_get_format(&physical_device->info, vk_format);<br>
<br>
    VK_OUTARRAY_MAKE(out, list->modifier_properties, &list->modifier_count);<br>
<br>
@@ -789,7 +826,7 @@ void anv_GetPhysicalDeviceFormatProperties(<br>
 {<br>
    ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice);<br>
    const struct gen_device_info *devinfo = &physical_device->info;<br>
-   const struct anv_format *anv_format = anv_get_format(vk_format);<br>
+   const struct anv_format *anv_format = anv_get_format(devinfo, vk_format);<br>
<br>
    *pFormatProperties = (VkFormatProperties) {<br>
       .linearTilingFeatures =<br>
@@ -839,7 +876,7 @@ anv_get_image_format_properties(<br>
    uint32_t maxArraySize;<br>
    VkSampleCountFlags sampleCounts = VK_SAMPLE_COUNT_1_BIT;<br>
    const struct gen_device_info *devinfo = &physical_device->info;<br>
-   const struct anv_format *format = anv_get_format(info->format);<br>
+   const struct anv_format *format = anv_get_format(devinfo, info->format);<br>
<br>
    if (format == NULL)<br>
       goto unsupported;<br>
@@ -1188,7 +1225,7 @@ VkResult anv_CreateSamplerYcbcrConversion(<br>
<br>
    memset(conversion, 0, sizeof(*conversion));<br>
<br>
-   conversion->format = anv_get_format(pCreateInfo->format);<br>
+   conversion->format = anv_get_format(&device->info, pCreateInfo->format);<br>
    conversion->ycbcr_model = pCreateInfo->ycbcrModel;<br>
    conversion->ycbcr_range = pCreateInfo->ycbcrRange;<br>
    conversion->mapping[0] = pCreateInfo->components.r;<br>
diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c<br>
index d0cfd4deef3..d33ca427c5d 100644<br>
--- a/src/intel/vulkan/anv_image.c<br>
+++ b/src/intel/vulkan/anv_image.c<br>
@@ -583,7 +583,7 @@ anv_image_create(VkDevice _device,<br>
    image->type = pCreateInfo->imageType;<br>
    image->extent = pCreateInfo->extent;<br>
    image->vk_format = pCreateInfo->format;<br>
-   image->format = anv_get_format(pCreateInfo->format);<br>
+   image->format = anv_get_format(&device->info, pCreateInfo->format);<br>
    image->aspects = vk_format_aspects(image->vk_format);<br>
    image->levels = pCreateInfo->mipLevels;<br>
    image->array_size = pCreateInfo->arrayLayers;<br>
@@ -1397,7 +1397,7 @@ anv_CreateImageView(VkDevice _device,<br>
     * in expanded_aspects to the image view.<br>
     */<br>
    const struct anv_format *vformat =<br>
-      anv_get_format(iview->vk_format);<br>
+      anv_get_format(&device->info, iview->vk_format);<br>
    bool iplane_bound[3] = { false, };<br>
    for (uint32_t vfplane = 0; vfplane < vformat->n_planes; vfplane++) {<br>
       if ((iview->aspect_mask & vformat->planes[vfplane].aspect) == 0)<br>
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h<br>
index a64db7d952c..4f63bc539ff 100644<br>
--- a/src/intel/vulkan/anv_private.h<br>
+++ b/src/intel/vulkan/anv_private.h<br>
@@ -2559,6 +2559,8 @@ struct anv_format {<br>
    struct anv_format_plane planes[3];<br>
    uint8_t n_planes;<br>
    bool can_ycbcr;<br>
+<br>
+   bool (*compatible)(const struct gen_device_info *devinfo);<br>
 };<br>
<br>
 uint32_t<br>
@@ -2595,7 +2597,7 @@ anv_plane_to_aspect(VkImageAspectFlags image_aspects,<br>
    for_each_bit(b, anv_image_expand_aspects(image, aspects))<br>
<br>
 const struct anv_format *<br>
-anv_get_format(VkFormat format);<br>
+anv_get_format(const struct gen_device_info *devinfo, VkFormat format);<br>
<br>
 struct anv_format_plane<br>
 anv_get_format_nth_plane(const struct gen_device_info *devinfo, VkFormat vk_format,<br>
diff --git a/src/intel/vulkan/vk_format_info.h b/src/intel/vulkan/vk_format_info.h<br>
index 9bcef17b4da..3799b5c3b99 100644<br>
--- a/src/intel/vulkan/vk_format_info.h<br>
+++ b/src/intel/vulkan/vk_format_info.h<br>
@@ -30,7 +30,7 @@<br>
 static inline VkImageAspectFlags<br>
 vk_format_aspects(VkFormat vk_format)<br>
 {<br>
-   const struct anv_format *format = anv_get_format(vk_format);<br>
+   const struct anv_format *format = anv_get_format(NULL, vk_format);<br>
    VkImageAspectFlags aspects = 0;<br>
    for (int p = 0; p < format->n_planes; p++)<br>
       aspects |= format->planes[p].aspect;<br>
-- <br>
2.19.1<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">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/mailman/listinfo/mesa-dev</a><br>
</blockquote></div></div></div></div></div></div></div>