[Mesa-dev] [PATCH 09/28] anv/image: Implement the wsi "extension"

Jason Ekstrand jason at jlekstrand.net
Thu Nov 16 21:28:57 UTC 2017


---
 src/intel/vulkan/anv_image.c   | 43 +++++++++++++++++++++++++++++++++++++++---
 src/intel/vulkan/anv_private.h |  2 ++
 2 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c
index 41fe3d8..3e94a76 100644
--- a/src/intel/vulkan/anv_image.c
+++ b/src/intel/vulkan/anv_image.c
@@ -91,7 +91,8 @@ choose_isl_surf_usage(VkImageCreateFlags vk_create_flags,
 }
 
 static isl_tiling_flags_t
-choose_isl_tiling_flags(const struct anv_image_create_info *anv_info)
+choose_isl_tiling_flags(const struct anv_image_create_info *anv_info,
+                        bool is_wsi_image)
 {
    const VkImageCreateInfo *base_info = anv_info->vk_info;
    isl_tiling_flags_t flags = 0;
@@ -100,7 +101,10 @@ choose_isl_tiling_flags(const struct anv_image_create_info *anv_info)
    default:
       unreachable("bad VkImageTiling");
    case VK_IMAGE_TILING_OPTIMAL:
-      flags = ISL_TILING_ANY_MASK;
+      if (is_wsi_image)
+         flags = ISL_TILING_X_BIT;
+      else
+         flags = ISL_TILING_ANY_MASK;
       break;
    case VK_IMAGE_TILING_LINEAR:
       flags = ISL_TILING_LINEAR_BIT;
@@ -505,6 +509,18 @@ anv_image_create(VkDevice _device,
 
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO);
 
+   bool is_wsi_image = false;
+   vk_foreach_struct_const(s, pCreateInfo->pNext) {
+      switch (s->sType) {
+      case WSI_STRUCTURE_TYPE_IMAGE_CREATE_INFO:
+         is_wsi_image = true;
+         break;
+      default:
+         anv_debug_ignored_stype(s->sType);
+         break;
+      }
+   }
+
    anv_assert(pCreateInfo->mipLevels > 0);
    anv_assert(pCreateInfo->arrayLayers > 0);
    anv_assert(pCreateInfo->samples > 0);
@@ -527,13 +543,14 @@ anv_image_create(VkDevice _device,
    image->samples = pCreateInfo->samples;
    image->usage = pCreateInfo->usage;
    image->tiling = pCreateInfo->tiling;
+   image->is_wsi_image = is_wsi_image;
    image->disjoint = pCreateInfo->flags & VK_IMAGE_CREATE_DISJOINT_BIT_KHR;
 
    const struct anv_format *format = anv_get_format(image->vk_format);
    assert(format != NULL);
 
    const isl_tiling_flags_t isl_tiling_flags =
-      choose_isl_tiling_flags(create_info);
+      choose_isl_tiling_flags(create_info, is_wsi_image);
 
    image->n_planes = format->n_planes;
 
@@ -617,6 +634,26 @@ anv_image_bind_memory_plane(struct anv_device *device,
    image->planes[plane].bo = memory->bo;
    image->planes[plane].bo_offset = memory_offset;
 
+   if (image->is_wsi_image) {
+      /* We need to set the WRITE flag on window system buffers so that GEM
+       * will know we're writing to them and synchronize uses on other rings
+       * (eg if the display server uses the blitter ring).
+       */
+      memory->bo->flags &= ~EXEC_OBJECT_ASYNC;
+      memory->bo->flags |= EXEC_OBJECT_WRITE;
+
+      struct isl_surf *surf = &image->planes[0].surface.isl;
+      int ret = anv_gem_set_tiling(device, memory->bo->gem_handle,
+                                   surf->row_pitch,
+                                   isl_tiling_to_i915_tiling(surf->tiling));
+      if (ret) {
+         /* FINISHME: Choose a better error. */
+         return vk_errorf(device->instance, device,
+                          VK_ERROR_OUT_OF_DEVICE_MEMORY,
+                          "set_tiling failed: %m");
+      }
+   }
+
    return VK_SUCCESS;
 }
 
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index e17a52a..7d8a6bc 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -2340,6 +2340,8 @@ struct anv_image {
    VkDeviceSize size;
    uint32_t alignment;
 
+   bool is_wsi_image;
+
    /* Whether the image is made of several underlying buffer objects rather a
     * single one with different offsets.
     */
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list