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
,
35 const VkAllocationCallbacks
* pAllocator
,
39 ANV_FROM_HANDLE(anv_device
, device
, _device
);
40 struct anv_device_memory
*mem
;
41 struct anv_image
*image
;
45 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_DMA_BUF_IMAGE_CREATE_INFO_INTEL
);
47 mem
= vk_alloc2(&device
->vk
.alloc
, pAllocator
, sizeof(*mem
), 8,
48 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
50 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
52 result
= anv_image_create(_device
,
53 &(struct anv_image_create_info
) {
54 .isl_tiling_flags
= ISL_TILING_X_BIT
,
55 .stride
= pCreateInfo
->strideInBytes
,
56 .vk_info
= &(VkImageCreateInfo
) {
57 .sType
= VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
,
58 .imageType
= VK_IMAGE_TYPE_2D
,
59 .format
= pCreateInfo
->format
,
60 .extent
= pCreateInfo
->extent
,
64 /* FIXME: Need a way to use X tiling to allow scanout */
65 .tiling
= VK_IMAGE_TILING_OPTIMAL
,
66 .usage
= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
,
69 }, pAllocator
, &image_h
);
70 if (result
!= VK_SUCCESS
)
73 image
= anv_image_from_handle(image_h
);
75 result
= anv_device_import_bo(device
, pCreateInfo
->fd
,
76 ANV_BO_ALLOC_IMPLICIT_SYNC
,
79 if (result
!= VK_SUCCESS
)
82 VkDeviceSize aligned_image_size
= align_u64(image
->size
, 4096);
84 if (mem
->bo
->size
< aligned_image_size
) {
85 result
= vk_errorf(device
, device
, VK_ERROR_INVALID_EXTERNAL_HANDLE
,
86 "dma-buf too small for image in "
87 "vkCreateDmaBufImageINTEL: %"PRIu64
"B < %"PRIu64
"B",
88 mem
->bo
->size
, aligned_image_size
);
89 anv_device_release_bo(device
, mem
->bo
);
93 image
->planes
[0].address
= (struct anv_address
) {
98 assert(image
->extent
.width
> 0);
99 assert(image
->extent
.height
> 0);
100 assert(image
->extent
.depth
== 1);
102 *pMem
= anv_device_memory_to_handle(mem
);
103 *pImage
= anv_image_to_handle(image
);
105 close(pCreateInfo
->fd
);
110 vk_free2(&device
->vk
.alloc
, pAllocator
, image
);
113 vk_free2(&device
->vk
.alloc
, pAllocator
, mem
);