radv/amdgpu: make sure to reset the number of BO when there is no ranges
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Fri, 17 Jun 2022 07:10:00 +0000 (09:10 +0200)
committerMarge Bot <emma+marge@anholt.net>
Mon, 20 Jun 2022 06:43:53 +0000 (06:43 +0000)
If an application binds a sparse resource and then unbind it with NULL,
the number of "real" BOs in the virtual BO list should be reset to 0.
Otherwise, it might use a dangling BO reference if it's destroyed just
after being unbound.

Cc: mesa-stable
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17085>

src/amd/vulkan/winsys/amdgpu/radv_amdgpu_bo.c

index c29dd15..1c3b466 100644 (file)
@@ -93,12 +93,16 @@ radv_amdgpu_winsys_rebuild_bo_list(struct radv_amdgpu_winsys_bo *bo)
 
    qsort(bo->bos, temp_bo_count, sizeof(struct radv_amdgpu_winsys_bo *), &bo_comparator);
 
-   uint32_t final_bo_count = 1;
-   for (uint32_t i = 1; i < temp_bo_count; ++i)
-      if (bo->bos[i] != bo->bos[i - 1])
-         bo->bos[final_bo_count++] = bo->bos[i];
+   if (!temp_bo_count) {
+      bo->bo_count = 0;
+   } else {
+      uint32_t final_bo_count = 1;
+      for (uint32_t i = 1; i < temp_bo_count; ++i)
+         if (bo->bos[i] != bo->bos[i - 1])
+            bo->bos[final_bo_count++] = bo->bos[i];
 
-   bo->bo_count = final_bo_count;
+      bo->bo_count = final_bo_count;
+   }
 
    return VK_SUCCESS;
 }