assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_DMA_BUF_IMAGE_CREATE_INFO_INTEL);
- mem = anv_alloc2(&device->alloc, pAllocator, sizeof(*mem), 8,
+ mem = vk_alloc2(&device->vk.alloc, pAllocator, sizeof(*mem), 8,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (mem == NULL)
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
- mem->bo.gem_handle = anv_gem_fd_to_handle(device, pCreateInfo->fd);
- if (!mem->bo.gem_handle) {
- result = vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY);
- goto fail;
- }
-
- mem->bo.map = NULL;
- mem->bo.index = 0;
- mem->bo.offset = 0;
- mem->bo.size = pCreateInfo->strideInBytes * pCreateInfo->extent.height;
-
- anv_image_create(_device,
+ result = anv_image_create(_device,
&(struct anv_image_create_info) {
.isl_tiling_flags = ISL_TILING_X_BIT,
.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,
- .arrayLayers = 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,
- }},
- pAllocator, &image_h);
+ .vk_info = &(VkImageCreateInfo) {
+ .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
+ .imageType = VK_IMAGE_TYPE_2D,
+ .format = pCreateInfo->format,
+ .extent = pCreateInfo->extent,
+ .mipLevels = 1,
+ .arrayLayers = 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,
+ }
+ }, pAllocator, &image_h);
+ if (result != VK_SUCCESS)
+ goto fail;
image = anv_image_from_handle(image_h);
- image->bo = &mem->bo;
- image->offset = 0;
+
+ result = anv_device_import_bo(device, pCreateInfo->fd,
+ ANV_BO_ALLOC_IMPLICIT_SYNC,
+ 0 /* address */,
+ &mem->bo);
+ if (result != VK_SUCCESS)
+ goto fail_import;
+
+ VkDeviceSize aligned_image_size = align_u64(image->size, 4096);
+
+ if (mem->bo->size < aligned_image_size) {
+ result = vk_errorf(device, device, VK_ERROR_INVALID_EXTERNAL_HANDLE,
+ "dma-buf too small for image in "
+ "vkCreateDmaBufImageINTEL: %"PRIu64"B < %"PRIu64"B",
+ mem->bo->size, aligned_image_size);
+ anv_device_release_bo(device, mem->bo);
+ goto fail_import;
+ }
+
+ image->planes[0].address = (struct anv_address) {
+ .bo = mem->bo,
+ .offset = 0,
+ };
assert(image->extent.width > 0);
assert(image->extent.height > 0);
*pMem = anv_device_memory_to_handle(mem);
*pImage = anv_image_to_handle(image);
+ close(pCreateInfo->fd);
+
return VK_SUCCESS;
+ fail_import:
+ vk_free2(&device->vk.alloc, pAllocator, image);
+
fail:
- anv_free2(&device->alloc, pAllocator, mem);
+ vk_free2(&device->vk.alloc, pAllocator, mem);
return result;
}