From 318ae49f1e5349e1d06541826c8a87aaa67055d5 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 20 Feb 2025 16:42:22 +0100 Subject: [PATCH] Cleanup: Remove `void *` handling from `MEM_freen`. Followup to 48e26c3afe, and discussions in !134771 about keeping 'C-style' and 'C++ template type-safe style' implementations of our guardedalloc separated. And it makes `MEM_freeN` code simpler. Also skip type-checking in `MEM_freeN` only with MSVC, as clang-cl on windows-arm64 does work fine with DNA structs using `DNA_DEFINE_CXX_METHODS`. Pull Request: https://projects.blender.org/blender/blender/pulls/134861 --- intern/guardedalloc/MEM_guardedalloc.h | 24 +++++++------------ .../render_graph/nodes/vk_pipeline_data.cc | 5 +++- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/intern/guardedalloc/MEM_guardedalloc.h b/intern/guardedalloc/MEM_guardedalloc.h index 9531c71ff8f..79f8a311185 100644 --- a/intern/guardedalloc/MEM_guardedalloc.h +++ b/intern/guardedalloc/MEM_guardedalloc.h @@ -201,7 +201,7 @@ extern size_t (*MEM_get_peak_memory)(void) ATTR_WARN_UNUSED_RESULT; # define MEM_SAFE_FREE(v) \ do { \ if (v) { \ - MEM_freeN>>(v); \ + MEM_freeN(v); \ (v) = nullptr; \ } \ } while (0) @@ -399,21 +399,15 @@ template inline T *MEM_cnew(const char *allocation_name, const T &ot template inline void MEM_freeN(T *ptr) { - if constexpr (std::is_void_v) { - mem_guarded::internal::mem_freeN_ex(const_cast(ptr), - mem_guarded::internal::AllocationType::ALLOC_FREE); - } - else { -# ifndef _WIN32 - /* MSVC seems to consider C-style types using the MEM_CXX_CLASS_ALLOC_FUNCS as non-trivial. GCC - * and clang (both on linux and OSX) do not. - * - * So for now, disable the triviality check on Windows. */ - static_assert(std::is_trivial_v, "For non-trivial types, MEM_delete must be used."); +# ifndef _MSC_VER + /* MSVC seems to consider C-style types using the DNA_DEFINE_CXX_METHODS as non-trivial. GCC + * and clang (both on linux, OSX and clang-cl on Windows on Arm) do not. + * + * So for now, disable the triviality check on MSVC. */ + static_assert(std::is_trivial_v, "For non-trivial types, MEM_delete must be used."); # endif - mem_guarded::internal::mem_freeN_ex(const_cast(static_cast(ptr)), - mem_guarded::internal::AllocationType::ALLOC_FREE); - } + mem_guarded::internal::mem_freeN_ex(const_cast(static_cast(ptr)), + mem_guarded::internal::AllocationType::ALLOC_FREE); } /** Allocation functions (for C++ only). */ diff --git a/source/blender/gpu/vulkan/render_graph/nodes/vk_pipeline_data.cc b/source/blender/gpu/vulkan/render_graph/nodes/vk_pipeline_data.cc index ca9fbd0243e..f78c19c164a 100644 --- a/source/blender/gpu/vulkan/render_graph/nodes/vk_pipeline_data.cc +++ b/source/blender/gpu/vulkan/render_graph/nodes/vk_pipeline_data.cc @@ -56,7 +56,10 @@ void vk_pipeline_data_build_commands(VKCommandBufferInterface &command_buffer, void vk_pipeline_data_free(VKPipelineData &data) { - MEM_SAFE_FREE(data.push_constants_data); + if (data.push_constants_data) { + MEM_freeN(const_cast(data.push_constants_data)); + data.push_constants_data = nullptr; + } } void vk_index_buffer_binding_build_links(VKResourceStateTracker &resources,