From 4f57a4da877ccedaef9d7435741a3fea14fd4b61 Mon Sep 17 00:00:00 2001 From: Patrick Lerda Date: Mon, 22 Jan 2024 15:45:46 +0100 Subject: [PATCH] r600/sfn: fix class Shader object last_alu_with_indirect_reg memory leak For instance, this issue is triggered with "piglit/bin/glsl-vs-arrays -auto -fbo": Direct leak of 104 byte(s) in 1 object(s) allocated from: #0 0x7f2fab415f57 in operator new(unsigned long) (/usr/lib64/libasan.so.6+0xb2f57) #1 0x7f2f9fd9d541 in __gnu_cxx::new_allocator::allocate(unsigned long, void const*) /usr/include/c++/11.4.0/ext/new_allocator.h:127 #2 0x7f2f9fd9d541 in std::allocator_traits >::allocate(std::allocator&, unsigned long) /usr/include/c++/11.4.0/bits/alloc_traits.h:464 #3 0x7f2f9fd9d541 in std::__detail::_Hashtable_alloc, false> > >::_M_allocate_buckets(unsigned long) /usr/include/c++/11.4.0/bits/hashtable_policy.h:1927 #4 0x7f2f9fd9d541 in std::_Hashtable, std::allocator >, std::__detail::_Select1st, std::equal_to, std::hash, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits >::_M_allocate_buckets(unsigned long) /usr/include/c++/11.4.0/bits/hashtable.h:440 #5 0x7f2f9fd9d541 in std::_Hashtable, std::allocator >, std::__detail::_Select1st, std::equal_to, std::hash, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits >::_M_rehash_aux(unsigned long, std::integral_constant) /usr/include/c++/11.4.0/bits/hashtable.h:2382 #6 0x7f2f9fd9d541 in std::_Hashtable, std::allocator >, std::__detail::_Select1st, std::equal_to, std::hash, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits >::_M_rehash(unsigned long, unsigned long const&) /usr/include/c++/11.4.0/bits/hashtable.h:2361 #7 0x7f2f9fd9d541 in std::_Hashtable, std::allocator >, std::__detail::_Select1st, std::equal_to, std::hash, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits >::_M_insert_unique_node(unsigned long, unsigned long, std::__detail::_Hash_node, false>*, unsigned long) /usr/include/c++/11.4.0/bits/hashtable.h:2021 #8 0x7f2f9fd9e7f8 in std::__detail::_Map_base, std::allocator >, std::__detail::_Select1st, std::equal_to, std::hash, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits, true>::operator[](int&&) /usr/include/c++/11.4.0/bits/hashtable_policy.h:741 #9 0x7f2f9fd9f6fe in std::unordered_map, std::equal_to, std::allocator > >::operator[](int&&) /usr/include/c++/11.4.0/bits/unordered_map.h:984 #10 0x7f2f9fd9f6fe in r600::Shader::InstructionChain::visit(r600::AluInstr*) ../src/gallium/drivers/r600/sfn/sfn_shader.cpp:1358 #11 0x7f2f9fd8f309 in r600::Shader::emit_instruction(r600::Instr*) ../src/gallium/drivers/r600/sfn/sfn_shader.cpp:1419 #12 0x7f2f9fd8f822 in r600::RegisterReadHandler::visit(r600::LocalArray&) ../src/gallium/drivers/r600/sfn/sfn_shader.cpp:1040 #13 0x7f2f9fd8e726 in r600::Shader::emit_load_reg_indirect(nir_intrinsic_instr*) ../src/gallium/drivers/r600/sfn/sfn_shader.cpp:993 #14 0x7f2f9fd8de5c in r600::Shader::process_instr(nir_instr*) ../src/gallium/drivers/r600/sfn/sfn_shader.cpp:848 #15 0x7f2f9fd8de5c in r600::Shader::process_block(nir_block*) ../src/gallium/drivers/r600/sfn/sfn_shader.cpp:836 #16 0x7f2f9fd962f2 in r600::Shader::process_cf_node(nir_cf_node*) ../src/gallium/drivers/r600/sfn/sfn_shader.cpp:669 #17 0x7f2f9fdac01a in r600::Shader::process(nir_shader*) ../src/gallium/drivers/r600/sfn/sfn_shader.cpp:537 #18 0x7f2f9fdac3d1 in r600::Shader::translate_from_nir(nir_shader*, pipe_stream_output_info const*, r600_shader*, r600_shader_key const&, r600_chip_class, radeon_family) ../src/gallium/drivers/r600/sfn/sfn_shader.cpp:494 #19 0x7f2f9fb5c8f5 in r600_shader_from_nir ../src/gallium/drivers/r600/r600_sfn.cpp:111 #20 0x7f2f9fb5e50c in r600_pipe_shader_create ../src/gallium/drivers/r600/r600_shader.c:198 #21 0x7f2f9fb96642 in r600_shader_select ../src/gallium/drivers/r600/r600_state_common.c:961 #22 0x7f2f9fb97340 in r600_create_shader_state ../src/gallium/drivers/r600/r600_state_common.c:1056 #23 0x7f2f9e060f82 in st_create_common_variant ../src/mesa/state_tracker/st_program.c:720 #24 0x7f2f9e06e779 in st_get_common_variant ../src/mesa/state_tracker/st_program.c:773 #25 0x7f2f9e06f78d in st_precompile_shader_variant ../src/mesa/state_tracker/st_program.c:1259 #26 0x7f2f9e06f78d in st_finalize_program ../src/mesa/state_tracker/st_program.c:1345 #27 0x7f2f9ead0f20 in st_link_glsl_to_nir ../src/mesa/state_tracker/st_glsl_to_nir.cpp:723 #28 0x7f2f9ead0f20 in st_link_shader ../src/mesa/state_tracker/st_glsl_to_nir.cpp:951 #29 0x7f2f9e9b0d15 in link_program ../src/mesa/main/shaderapi.c:1336 #30 0x7f2f9e9b0d15 in link_program_error ../src/mesa/main/shaderapi.c:1447 Fixes: ddb167e81a18 ("r600/sfn: Handle indirect array load/store dependencies better") Signed-off-by: Patrick Lerda Reviewed-by: Gert Wollny Part-of: (cherry picked from commit 242da61b9d33fe9e3cda9c156303792384ec7e2a) --- .pick_status.json | 2 +- src/gallium/drivers/r600/sfn/sfn_shader.h | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 9c776d86b5a..550bd56adde 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -294,7 +294,7 @@ "description": "r600/sfn: fix class Shader object last_alu_with_indirect_reg memory leak", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "ddb167e81a18c09bd3a4c519e8728e2842d827f1", "notes": null diff --git a/src/gallium/drivers/r600/sfn/sfn_shader.h b/src/gallium/drivers/r600/sfn/sfn_shader.h index ed9fa4f6a9b..c14eee2ab6a 100644 --- a/src/gallium/drivers/r600/sfn/sfn_shader.h +++ b/src/gallium/drivers/r600/sfn/sfn_shader.h @@ -395,7 +395,12 @@ class Shader : public Allocate { Instr *last_kill_instr{nullptr}; Instr *last_lds_access{nullptr}; Instr *last_group_barrier{nullptr}; - std::unordered_map last_alu_with_indirect_reg; + std::unordered_map, + std::equal_to, + Allocator>> + last_alu_with_indirect_reg; bool prepare_mem_barrier{false}; };