X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fintel%2Fvulkan%2Fanv_intel.c;h=146fc41d8a839398f98c4669a460a43393409028;hb=c9bebae2877e55cdcd94f9f9f3f6805238caeb28;hp=d95d9afe8cfa19daf9e8a508d8a2625d4292fa53;hpb=76fa7b16f474253356d3bf59adc91769dc51f184;p=mesa.git diff --git a/src/intel/vulkan/anv_intel.c b/src/intel/vulkan/anv_intel.c index d95d9afe8cf..146fc41d8a8 100644 --- a/src/intel/vulkan/anv_intel.c +++ b/src/intel/vulkan/anv_intel.c @@ -44,45 +44,61 @@ 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; + + uint64_t bo_flags = ANV_BO_EXTERNAL; + if (device->instance->physicalDevice.supports_48bit_addresses) + bo_flags |= EXEC_OBJECT_SUPPORTS_48B_ADDRESS; + if (device->instance->physicalDevice.use_softpin) + bo_flags |= EXEC_OBJECT_PINNED; + + result = anv_bo_cache_import(device, &device->bo_cache, + pCreateInfo->fd, bo_flags, &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_bo_cache_release(device, &device->bo_cache, 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 +107,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; }