v3dv: add a refcount mechanism to BOs
Until now we have lived without a refcount mechanism in the driver because in Vulkan the user is responsible for handling the life span of memory allocations for all Vulkan objects, however, imported BOs are tricky because the kernel doesn't refcount so user-space needs to make sure that: 1. When importing a BO into the same device used to create it (self-importing) it does not double free the same BO. 2. Frees imported BOs that were not allocated through the same device. Our initial implementation always freed BOs when requested, so we handled 2) correctly but not 1) and we would double-free self-imported BOs. We tried to fix that in commit d809d9f3 but that broke 2) and we started to leak BOs for some imports. This fixes the problem for good by adding refcounts to BOs so that self-imported BOs have a refcnt > 1 and are only freed when all references are freed. Closes: #5769 Tested-by:Roman Stratiienko <r.stratiienko@gmail.com> Reviewed-by:
Juan A. Suarez <jasuarez@igalia.com> Part-of: <!14392>
- src/broadcom/vulkan/v3dv_bo.c 18 additions, 13 deletionssrc/broadcom/vulkan/v3dv_bo.c
- src/broadcom/vulkan/v3dv_bo.h 2 additions, 0 deletionssrc/broadcom/vulkan/v3dv_bo.h
- src/broadcom/vulkan/v3dv_device.c 20 additions, 35 deletionssrc/broadcom/vulkan/v3dv_device.c
- src/broadcom/vulkan/v3dv_private.h 24 additions, 1 deletionsrc/broadcom/vulkan/v3dv_private.h