From 9301b637cfe82e4ad671aac22102ad95e9fda0a2 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Tue, 4 May 2021 13:30:35 -0500 Subject: [PATCH] anv: Check offset instead of alloc_size for freeing surface states Reviewed-by: Lionel Landwerlin Part-of: --- src/intel/vulkan/anv_image.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index d041af77b23..e47e525affa 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -2911,22 +2911,26 @@ anv_DestroyImageView(VkDevice _device, VkImageView _iview, return; for (uint32_t plane = 0; plane < iview->n_planes; plane++) { - if (iview->planes[plane].optimal_sampler_surface_state.state.alloc_size > 0) { + /* Check offset instead of alloc_size because this they might be + * device->null_surface_state which always has offset == 0. We don't + * own that one so we don't want to accidentally free it. + */ + if (iview->planes[plane].optimal_sampler_surface_state.state.offset) { anv_state_pool_free(&device->surface_state_pool, iview->planes[plane].optimal_sampler_surface_state.state); } - if (iview->planes[plane].general_sampler_surface_state.state.alloc_size > 0) { + if (iview->planes[plane].general_sampler_surface_state.state.offset) { anv_state_pool_free(&device->surface_state_pool, iview->planes[plane].general_sampler_surface_state.state); } - if (iview->planes[plane].storage_surface_state.state.alloc_size > 0) { + if (iview->planes[plane].storage_surface_state.state.offset) { anv_state_pool_free(&device->surface_state_pool, iview->planes[plane].storage_surface_state.state); } - if (iview->planes[plane].writeonly_storage_surface_state.state.alloc_size > 0) { + if (iview->planes[plane].writeonly_storage_surface_state.state.offset) { anv_state_pool_free(&device->surface_state_pool, iview->planes[plane].writeonly_storage_surface_state.state); }