summaryrefslogtreecommitdiffstats
path: root/src/intel/vulkan/anv_intel.c
diff options
context:
space:
mode:
authorChad Versace <[email protected]>2017-09-12 14:05:08 -0700
committerChad Versace <[email protected]>2017-10-17 23:46:06 -0700
commit9775894f102535a79186985124087ac859b5ca44 (patch)
treec47baa18a31f78334f82b4ed275e7c9373b7ebe7 /src/intel/vulkan/anv_intel.c
parentfbf39fd7c33d56271d79bdbe039605588c8d84db (diff)
anv: Move size check from anv_bo_cache_import() to caller (v2)
This change prepares for VK_ANDROID_native_buffer. When the user imports a gralloc hande into a VkImage using VK_ANDROID_native_buffer, the user provides no size. The driver must infer the size from the internals of the gralloc buffer. The patch is essentially a refactor patch, but it does change behavior in some edge cases, described below. In what follows, the "nominal size" of the bo refers to anv_bo::size, which may not match the bo's "actual size" according to the kernel. Post-patch, the nominal size of the bo returned from anv_bo_cache_import() is always the size of imported dma-buf according to lseek(). Pre-patch, the bo's nominal size was difficult to predict. If the imported dma-buf's gem handle was not resident in the cache, then the bo's nominal size was align(VkMemoryAllocateInfo::allocationSize, 4096). If it *was* resident, then the bo's nominal size was whatever the cache returned. As a consequence, the first cache insert decided the bo's nominal size, which could be significantly smaller compared to the dma-buf's actual size, as the nominal size was determined by VkMemoryAllocationInfo::allocationSize and not lseek(). I believe this patch cleans up that messy behavior. For an imported or exported VkDeviceMemory, anv_bo::size should now be the true size of the bo, if I correctly understand the problem (which I possibly don't). v2: - Preserve behavior of aligning size to 4096 before checking. [for jekstrand] - Check size with < instead of <=, to match behavior of commit c0a4f56 "anv: bo_cache: allow importing a BO larger than needed". [for chadv]
Diffstat (limited to 'src/intel/vulkan/anv_intel.c')
-rw-r--r--src/intel/vulkan/anv_intel.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/intel/vulkan/anv_intel.c b/src/intel/vulkan/anv_intel.c
index d6bad44091a..885888e82d8 100644
--- a/src/intel/vulkan/anv_intel.c
+++ b/src/intel/vulkan/anv_intel.c
@@ -76,10 +76,22 @@ VkResult anv_CreateDmaBufImageINTEL(
image = anv_image_from_handle(image_h);
result = anv_bo_cache_import(device, &device->bo_cache,
- pCreateInfo->fd, image->size, &mem->bo);
+ pCreateInfo->fd, &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->instace, device,
+ VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR,
+ "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;
+ }
+
if (device->instance->physicalDevice.supports_48bit_addresses)
mem->bo->flags |= EXEC_OBJECT_SUPPORTS_48B_ADDRESS;