X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fintel%2Fvulkan%2Fanv_intel.c;h=1b6fd32b00dee0106b07fe69b80b872ee6262ae4;hb=f71e93db0ab2d00602fe5235fad6583887ffd754;hp=d95d9afe8cfa19daf9e8a508d8a2625d4292fa53;hpb=7f6a0cb29c89a03441be744680a2145445be3a3c;p=mesa.git diff --git a/src/intel/vulkan/anv_intel.c b/src/intel/vulkan/anv_intel.c index d95d9afe8cf..1b6fd32b00d 100644 --- a/src/intel/vulkan/anv_intel.c +++ b/src/intel/vulkan/anv_intel.c @@ -44,45 +44,56 @@ VkResult anv_CreateDmaBufImageINTEL( 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->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, + &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->instance, 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); @@ -91,10 +102,15 @@ VkResult anv_CreateDmaBufImageINTEL( *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: - anv_free2(&device->alloc, pAllocator, mem); + vk_free2(&device->alloc, pAllocator, mem); return result; }