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