From 09a35044852fe4f835387fbf903f11962a0a954f Mon Sep 17 00:00:00 2001 From: Karmjit Mahil Date: Tue, 12 Nov 2024 15:43:21 +0100 Subject: [PATCH] tu: Fix memory leaks on VK_PIPELINE_COMPILE_REQUIRED For a TU_PIPELINE_GRAPHICS_LIB we were taking a ref to the descriptor set layout but never releasing on VK_PIPELINE_COMPILE_REQUIRED. Since VK_PIPELINE_COMPILE_REQUIRED is technically an error, the user doesn't call vkDestroyPipeline() for it so the descriptor sets referenced were never getting freed. Addresses: ``` Direct leak of 304 byte(s) in 1 object(s) allocated from: #0 0x7fa5a93ee0 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145 #1 0x7fa44bac84 in vk_default_alloc ../src/vulkan/util/vk_alloc.c:26 #2 0x7fa32ea5d8 in vk_alloc ../src/vulkan/util/vk_alloc.h:48 #3 0x7fa32ea60c in vk_zalloc ../src/vulkan/util/vk_alloc.h:56 #4 0x7fa32ea750 in vk_descriptor_set_layout_zalloc ../src/vulkan/runtime/vk_descriptor_set_layout.c:49 #5 0x7fa306fc98 in tu_CreateDescriptorSetLayout(VkDevice_T*, VkDescriptorSetLayoutCreateInfo const*, VkAllocationCallbacks const*, VkDescriptorSetLayout_T**) ../src/freedreno/vulkan/tu_descriptor_set.cc:161 ``` and ``` Direct leak of 48 byte(s) in 1 object(s) allocated from: #0 0x7f9b4b3ee0 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145 #1 0x7f9925e900 in ralloc_size ../src/util/ralloc.c:118 #2 0x7f9925e8d4 in ralloc_context ../src/util/ralloc.c:105 #3 0x7f98b4b214 in tu_pipeline_builder_build<(chip)7> ../src/freedreno/vulkan/tu_pipeline.cc:3898 #4 0x7f98b46bd8 in tu_graphics_pipeline_create<(chip)7> ../src/freedreno/vulkan/tu_pipeline.cc:4203 #5 0x7f98b22588 in VkResult tu_CreateGraphicsPipelines<(chip)7>(VkDevice_T*, VkPipelineCache_T*, unsigned int, VkGraphicsPipelineCreateInfo const*, VkAllocationCallbacks const*, VkPipeline_T**) ../src/freedreno/vulkan/tu_pipeline.cc:4234 ``` seen in: dEQP-VK.pipeline.pipeline_library.shader_module_identifier.pipeline_from_id.graphics.4_variants.no_spec_constants.no_pipeline_cache.all_zeros_id.no_exec_properties.vert_tesc_tese_frag Cc: mesa-stable Signed-off-by: Karmjit Mahil Part-of: (cherry picked from commit 21baf2f6c1f829f7d09162d123fa726f52e800f1) --- .pick_status.json | 2 +- src/freedreno/vulkan/tu_pipeline.cc | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.pick_status.json b/.pick_status.json index 131ec811fbf..1c67ae04764 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -694,7 +694,7 @@ "description": "tu: Fix memory leaks on VK_PIPELINE_COMPILE_REQUIRED", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/freedreno/vulkan/tu_pipeline.cc b/src/freedreno/vulkan/tu_pipeline.cc index c3514e055bc..4aee9c228cf 100644 --- a/src/freedreno/vulkan/tu_pipeline.cc +++ b/src/freedreno/vulkan/tu_pipeline.cc @@ -3926,6 +3926,7 @@ tu_pipeline_builder_build(struct tu_pipeline_builder *builder, result = tu_pipeline_builder_compile_shaders(builder, *pipeline); if (result != VK_SUCCESS) { + tu_pipeline_finish(*pipeline, builder->device, builder->alloc); vk_object_free(&builder->device->vk, builder->alloc, *pipeline); return result; }