<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 | 84 ++++++++++++++++++++++++++++++<wbr>+++++++++-----<br>
 1 file changed, 75 insertions(+), 9 deletions(-)<br>
<br>
diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c<br>
index ec6cdbc6168..bf636ce4b65 100644<br>
--- a/src/intel/vulkan/anv_image.c<br>
+++ b/src/intel/vulkan/anv_image.c<br>
@@ -288,6 +288,7 @@ static VkResult<br>
 make_surface(const struct anv_device *dev,<br>
              struct anv_image *image,<br>
              const struct anv_image_create_info *anv_info,<br>
+             const VkImageExplicitDrmFormatModifi<wbr>erCreateInfoEXT *explicit_drm_info,<br>
              isl_tiling_flags_t tiling_flags,<br>
              VkImageAspectFlagBits aspect)<br>
 {<br>
@@ -308,9 +309,16 @@ make_surface(const struct anv_device *dev,<br>
       anv_get_format_plane(&dev-><wbr>info, image->vk_format, aspect, image->tiling);<br>
    struct anv_surface *anv_surf = &image->planes[plane].surface;<br>
<br>
+   const VkSubresourceLayout *drm_plane_layout = explicit_drm_info ?<br>
+      &explicit_drm_info-><wbr>pPlaneLayouts[plane] : NULL;<br>
+<br>
    const isl_surf_usage_flags_t usage =<br>
       choose_isl_surf_usage(vk_info, anv_info->isl_extra_usage_<wbr>flags, aspect);<br>
<br>
+   uint32_t row_pitch = anv_info->stride;<br>
+   if (explicit_drm_info)<br>
+      row_pitch = drm_plane_layout->rowPitch;<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>
     * guaranteed that we can handle offsets correctly.  On Sky Lake, the<br>
@@ -336,18 +344,71 @@ make_surface(const struct anv_device *dev,<br>
       .array_len = vk_info->arrayLayers,<br>
       .samples = vk_info->samples,<br>
       .min_alignment = 0,<br>
-      .row_pitch = anv_info->stride,<br>
+      .row_pitch = row_pitch,<br>
       .usage = usage,<br>
       .tiling_flags = tiling_flags);<br>
<br>
-   /* isl_surf_init() will fail only if provided invalid input. Invalid input<br>
-    * is illegal in Vulkan.<br>
-    */<br>
-   assert(ok);<br>
+   if (!ok) {<br>
+      /* isl_surf_init() fails only when provided invalid input. Invalid input<br>
+       * is illegal in Vulkan unless<br>
+       * VkImageExplicitDrmFormatModifi<wbr>erCreateInfoEXT is given.<br>
+       */<br>
+      assert(explicit_drm_info);<br>
+      return vk_errorf(dev->instance, dev,<br>
+                       VK_ERROR_INVALID_DRM_FORMAT_<wbr>MODIFIER_PLANE_LAYOUT_EXT,<br>
+                       "isl_surf_init() failed for plane %u", plane);<br>
+   }<br>
<br>
-   image->planes[plane].aux_usage = ISL_AUX_USAGE_NONE;<br>
+   if (explicit_drm_info) {<br>
+      /* The VK_EXT_image_drm_format_<wbr>modifier spec permits support of any<br>
+       * image, but we restrict support to simple images.<br>
+       */<br>
+      assert(aspect == VK_IMAGE_ASPECT_COLOR_BIT);<br>
+      assert(image->type == VK_IMAGE_TYPE_2D);<br>
+      assert(image->array_size == 1);<br>
+      assert(image->samples == 1);<br>
+<br>
+      /* FINISHME: YCbCr images with DRM format modifiers */<br>
+      assert(!anv_get_format(image-><wbr>vk_format)->can_ycbcr);<br>
+<br>
+      if (drm_plane_layout->size < anv_surf->isl.size) {<br>
+         return vk_errorf(dev->instance, dev,<br>
+                          VK_ERROR_INVALID_DRM_FORMAT_<wbr>MODIFIER_PLANE_LAYOUT_EXT,<br>
+                          "VkSubresourceLayout::size too small for plane %u", plane);<br>
+      }<br>
<br>
-   add_surface(image, anv_surf, plane);<br>
+      if (drm_plane_layout->offset & (anv_surf->isl.alignment - 1)) {<br>
+         return vk_errorf(dev->instance, dev,<br>
+                          VK_ERROR_INVALID_DRM_FORMAT_<wbr>MODIFIER_PLANE_LAYOUT_EXT,<br>
+                          "VkSubresourceLayout::offset misaligned for plane "<br>
+                          "%u", plane);<br>
+      }<br>
+<br>
+      if (drm_plane_layout->arrayPitch != 0) {<br>
+         return vk_errorf(dev->instance, dev,<br>
+                          VK_ERROR_INVALID_DRM_FORMAT_<wbr>MODIFIER_PLANE_LAYOUT_EXT,<br>
+                          "VkSubresourceLayout::<wbr>arrayPitch must be 0");<br>
+      }<br>
+<br>
+      if (drm_plane_layout->depthPitch != 0) {<br>
+         return vk_errorf(dev->instance, dev,<br>
+                          VK_ERROR_INVALID_DRM_FORMAT_<wbr>MODIFIER_PLANE_LAYOUT_EXT,<br>
+                          "VkSubresourceLayout::<wbr>depthPitch must be 0");<br>
+      }<br>
+<br>
+      anv_surf->offset = drm_plane_layout->offset;<br>
+<br>
+      image->planes[plane].offset = drm_plane_layout->offset;<br>
+      image->planes[plane].alignment = anv_surf->isl.alignment;<br>
+      image->planes[plane].size = drm_plane_layout->size;<br>
+<br>
+      image->size = image->planes[plane].offset + image->planes[plane].size;<br>
+      image->alignment = image->planes[plane].<wbr>alignment;<br></blockquote><div><br></div><div>This all looks correct for now, but I'm having trouble seeing how CCS will fit into all of this.<br></div><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+   } else {<br>
+      add_surface(image, anv_surf, plane);<br>
+   }<br>
+<br>
+   image->planes[plane].aux_usage = ISL_AUX_USAGE_NONE;<br>
<br>
    /* If an image is created as BLOCK_TEXEL_VIEW_COMPATIBLE, then we need to<br>
     * create an identical tiled shadow surface for use while texturing so we<br>
@@ -543,6 +604,7 @@ anv_image_create(VkDevice _device,<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 VkImageExplicitDrmFormatModifi<wbr>erCreateInfoEXT *explicit_drm_info = NULL;<br>
    const struct isl_drm_modifier_info *isl_mod_info = NULL;<br>
    struct anv_image *image = NULL;<br>
    VkResult r;<br>
@@ -556,6 +618,10 @@ anv_image_create(VkDevice _device,<br>
          vk_mod_list = (const VkImageDrmFormatModifierListCr<wbr>eateInfoEXT *) s;<br>
          isl_mod_info = choose_drm_format_mod(vk_mod_<wbr>list);<br>
          break;<br>
+      case VK_STRUCTURE_TYPE_IMAGE_<wbr>EXCPLICIT_DRM_FORMAT_MODIFIER_<wbr>CREATE_INFO_EXT:<br>
+         explicit_drm_info = (const VkImageExplicitDrmFormatModifi<wbr>erCreateInfoEXT *) s;<br>
+         isl_mod_info = isl_drm_modifier_get_info(<wbr>explicit_drm_info-><wbr>drmFormatModifier);<br></blockquote><div><br></div><div>Let's assert isl_mod_info == NULL both here and in the above case as well.  I'd like to prevent anyone from trying to use both at the same time.<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>
@@ -599,8 +665,8 @@ anv_image_create(VkDevice _device,<br>
<br>
    uint32_t b;<br>
    for_each_bit(b, image->aspects) {<br>
-      r = make_surface(device, image, create_info, isl_tiling_flags,<br>
-                       (1 << b));<br>
+      r = make_surface(device, image, create_info, explicit_drm_info,<br>
+                       isl_tiling_flags, (1 << b));<br>
       if (r != VK_SUCCESS)<br>
          goto fail;<br>
    }<br>
<span class="HOEnZb"><font color="#888888">--<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>