radv/amdgpu: make sure to reset the number of BO when there is no ranges

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>
This commit is contained in:
Samuel Pitoiset 2022-06-17 09:10:00 +02:00 committed by Marge Bot
parent 29f34cc806
commit b4cc10b342

View 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;
}