From b4cc10b3427bdf1f172094f991c38c6ec94bbc19 Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Fri, 17 Jun 2022 09:10:00 +0200 Subject: [PATCH] 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 Reviewed-by: Bas Nieuwenhuizen Part-of: --- src/amd/vulkan/winsys/amdgpu/radv_amdgpu_bo.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_bo.c b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_bo.c index c29dd15..1c3b466 100644 --- a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_bo.c +++ b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_bo.c @@ -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; } -- 2.7.4