if (mem == NULL)
return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
- uint64_t size = (uint64_t)pCreateInfo->strideInBytes * pCreateInfo->extent.height;
-
- result = anv_bo_cache_import(device, &device->bo_cache,
- pCreateInfo->fd, size, &mem->bo);
- if (result != VK_SUCCESS)
- goto fail;
-
- if (device->instance->physicalDevice.supports_48bit_addresses)
- mem->bo->flags |= EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
-
- 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->alloc, pAllocator, image);
+
fail:
vk_free2(&device->alloc, pAllocator, mem);