2 * Copyright © 2015 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30 #include "anv_private.h"
32 VkResult
anv_CreateDmaBufImageINTEL(
34 const VkDmaBufImageCreateInfo
* pCreateInfo
,
38 ANV_FROM_HANDLE(anv_device
, device
, _device
);
39 struct anv_device_memory
*mem
;
40 struct anv_image
*image
;
44 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DMA_BUF_IMAGE_CREATE_INFO_INTEL
);
46 mem
= anv_device_alloc(device
, sizeof(*mem
), 8,
47 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
49 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
51 mem
->bo
.gem_handle
= anv_gem_fd_to_handle(device
, pCreateInfo
->fd
);
52 if (!mem
->bo
.gem_handle
) {
53 result
= vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
60 mem
->bo
.size
= pCreateInfo
->strideInBytes
* pCreateInfo
->extent
.height
;
62 image
= anv_device_alloc(device
, sizeof(*image
), 8,
63 VK_SYSTEM_ALLOC_TYPE_API_OBJECT
);
65 result
= vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
69 anv_image_create(_device
,
70 &(struct anv_image_create_info
) {
72 .tiling
= ISL_TILING_X
,
73 .stride
= pCreateInfo
->strideInBytes
,
75 &(VkImageCreateInfo
) {
76 .sType
= VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
,
77 .imageType
= VK_IMAGE_TYPE_2D
,
78 .format
= pCreateInfo
->format
,
79 .extent
= pCreateInfo
->extent
,
83 /* FIXME: Need a way to use X tiling to allow scanout */
84 .tiling
= VK_IMAGE_TILING_OPTIMAL
,
85 .usage
= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
,
90 image
= anv_image_from_handle(image_h
);
94 assert(image
->extent
.width
> 0);
95 assert(image
->extent
.height
> 0);
96 assert(image
->extent
.depth
== 1);
98 *pMem
= anv_device_memory_to_handle(mem
);
99 *pImage
= anv_image_to_handle(image
);
104 anv_gem_close(device
, mem
->bo
.gem_handle
);
106 anv_device_free(device
, mem
);