vk: Use anv_image_create() for creating dmabuf VkImage
authorKristian Høgsberg Kristensen <kristian.h.kristensen@intel.com>
Fri, 14 Aug 2015 17:02:19 +0000 (10:02 -0700)
committerKristian Høgsberg Kristensen <kristian.h.kristensen@intel.com>
Mon, 17 Aug 2015 18:41:19 +0000 (11:41 -0700)
We need to make sure we use the VkImage infrastructure for creating
dmabuf images.

Signed-off-by: Kristian Høgsberg Kristensen <kristian.h.kristensen@intel.com>
src/vulkan/anv_image.c
src/vulkan/anv_intel.c
src/vulkan/anv_private.h
src/vulkan/anv_x11.c

index 21099cb77301a5a271611fca7e27c7edc62745f8..2937c2e76e56db2f7ae6e048a57ee50cb685acee 100644 (file)
@@ -181,8 +181,10 @@ anv_image_make_surface(const struct anv_image_create_info *create_info,
     */
    assert(anv_is_aligned(qpitch, j));
 
-   const uint32_t stride = align_u32(mt_width * format_info->cpp,
-                                     tile_info->width);
+   uint32_t stride = align_u32(mt_width * format_info->cpp, tile_info->width);
+   if (create_info->stride > 0)
+      stride = create_info->stride;
+
    const uint32_t size = stride * align_u32(mt_height, tile_info->height);
    const uint32_t offset = align_u32(*inout_image_size,
                                      tile_info->surface_alignment);
index 9fc06aef6f80e19e3f93c6d86c6b5df3cf7ee49e..f64e2dcb1e4d4c96d543ad3bd71e90eb39f6ef49 100644 (file)
@@ -39,6 +39,7 @@ VkResult anv_CreateDmaBufImageINTEL(
    struct anv_device_memory *mem;
    struct anv_image *image;
    VkResult result;
+   VkImage image_h;
 
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_DMA_BUF_IMAGE_CREATE_INFO_INTEL);
 
@@ -65,19 +66,30 @@ VkResult anv_CreateDmaBufImageINTEL(
       goto fail_mem;
    }
 
-   *image = (struct anv_image) {
-      .bo = &mem->bo,
-      .offset = 0,
-      .type = VK_IMAGE_TYPE_2D,
-      .extent = pCreateInfo->extent,
-      .size = mem->bo.size,
-
-      .primary_surface = {
-         .offset = 0,
-         .stride = pCreateInfo->strideInBytes,
+   anv_image_create(_device,
+      &(struct anv_image_create_info) {
+         .force_tile_mode = true,
          .tile_mode = XMAJOR,
-      },
-   };
+         .stride = pCreateInfo->strideInBytes,
+         .vk_info =
+      &(VkImageCreateInfo) {
+         .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
+         .imageType = VK_IMAGE_TYPE_2D,
+         .format = pCreateInfo->format,
+         .extent = pCreateInfo->extent,
+         .mipLevels = 1,
+         .arraySize = 1,
+         .samples = 1,
+         /* FIXME: Need a way to use X tiling to allow scanout */
+         .tiling = VK_IMAGE_TILING_OPTIMAL,
+         .usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
+         .flags = 0,
+      }},
+      &image_h);
+
+   image = anv_image_from_handle(image_h);
+   image->bo = &mem->bo;
+   image->offset = 0;
 
    assert(image->extent.width > 0);
    assert(image->extent.height > 0);
index d53f63d5d27b1209f4c65a6322147524b12e0ece..d517814847c1405cf69bea8af0e238071f3d8a3c 100644 (file)
@@ -996,6 +996,7 @@ struct anv_image_create_info {
    const VkImageCreateInfo *vk_info;
    bool force_tile_mode;
    uint8_t tile_mode;
+   uint32_t stride;
 };
 
 VkResult anv_image_create(VkDevice _device,
index 9ffce8d8cbf4f069f7c6f2117bb360fbafa67e0d..cc11a5fc7622f850d380fc7f582e8cd07ef04fb4 100644 (file)
@@ -121,6 +121,7 @@ VkResult anv_CreateSwapChainWSI(
          &(struct anv_image_create_info) {
             .force_tile_mode = true,
             .tile_mode = XMAJOR,
+            .stride = 0,
             .vk_info =
          &(VkImageCreateInfo) {
             .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,