Skip to content
  • Lina Versace's avatar
    anv: Move size check from anv_bo_cache_import() to caller (v2) · 9775894f
    Lina Versace authored
    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 c0a4f56f
        "anv: bo_cache: allow importing a BO larger than needed". [for
        chadv]
    9775894f