From 3816e08f5b89cd1139a4c46a47bb1aef2b6b15f4 Mon Sep 17 00:00:00 2001 From: Julian Waller Date: Thu, 5 Oct 2023 15:36:31 +0100 Subject: [PATCH] fix: replace tbbmalloc with os native implementations --- src/CMakeModules/Bootstrap_Windows.cmake | 4 ---- src/common/memshfl.h | 10 ++++++++++ src/modules/decklink/consumer/decklink_consumer.cpp | 5 ++--- src/modules/decklink/consumer/frame.cpp | 4 ++-- src/shell/CMakeLists.txt | 2 -- src/shell/main.cpp | 6 ------ 6 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/CMakeModules/Bootstrap_Windows.cmake b/src/CMakeModules/Bootstrap_Windows.cmake index 2f3fe5085a..14cb9509e6 100644 --- a/src/CMakeModules/Bootstrap_Windows.cmake +++ b/src/CMakeModules/Bootstrap_Windows.cmake @@ -113,10 +113,6 @@ set(TBB_BIN_PATH "${PACKAGES_FOLDER}/tbb/bin/intel64") link_directories("${PACKAGES_FOLDER}/tbb/lib/intel64") casparcg_add_runtime_dependency("${TBB_BIN_PATH}/tbb12.dll") casparcg_add_runtime_dependency("${TBB_BIN_PATH}/tbb12_debug.dll") -casparcg_add_runtime_dependency("${TBB_BIN_PATH}/tbbmalloc.dll") -casparcg_add_runtime_dependency("${TBB_BIN_PATH}/tbbmalloc_debug.dll") -casparcg_add_runtime_dependency("${TBB_BIN_PATH}/tbbmalloc_proxy.dll") -casparcg_add_runtime_dependency("${TBB_BIN_PATH}/tbbmalloc_proxy_debug.dll") # GLEW set(GLEW_INCLUDE_PATH "${PACKAGES_FOLDER}/glew/include") diff --git a/src/common/memshfl.h b/src/common/memshfl.h index e9b1e4ac10..71ab527d10 100644 --- a/src/common/memshfl.h +++ b/src/common/memshfl.h @@ -34,6 +34,16 @@ namespace caspar { +#ifdef _MSC_VER +static std::shared_ptr create_aligned_buffer(size_t size) { + return std::shared_ptr(_aligned_malloc(size, 64), _aligned_free); +} +#else +static std::shared_ptr create_aligned_buffer(size_t size) { + return std::shared_ptr(aligned_alloc(64, size), free); +} +#endif + static void* aligned_memshfl(void* dest, const void* source, size_t count, int m1, int m2, int m3, int m4) { __m128i* dest128 = reinterpret_cast<__m128i*>(dest); diff --git a/src/modules/decklink/consumer/decklink_consumer.cpp b/src/modules/decklink/consumer/decklink_consumer.cpp index 01f166814d..82d6889ea7 100644 --- a/src/modules/decklink/consumer/decklink_consumer.cpp +++ b/src/modules/decklink/consumer/decklink_consumer.cpp @@ -43,11 +43,11 @@ #include #include -#include #include #include +#include #include #include #include @@ -520,8 +520,7 @@ struct decklink_consumer final : public IDeckLinkVideoOutputCallback nb_samples); } - std::shared_ptr image_data(scalable_aligned_malloc(decklink_format_desc_.size, 64), - scalable_aligned_free); + std::shared_ptr image_data = create_aligned_buffer(decklink_format_desc_.size); schedule_next_video(image_data, nb_samples, video_scheduled_); for (auto& context : secondary_port_contexts_) { diff --git a/src/modules/decklink/consumer/frame.cpp b/src/modules/decklink/consumer/frame.cpp index c771bbb693..89da192099 100644 --- a/src/modules/decklink/consumer/frame.cpp +++ b/src/modules/decklink/consumer/frame.cpp @@ -31,7 +31,7 @@ namespace caspar { namespace decklink { std::shared_ptr convert_to_key_only(const std::shared_ptr& image_data, std::size_t byte_count) { - auto key_data = std::shared_ptr(scalable_aligned_malloc(byte_count, 64), scalable_aligned_free); + auto key_data = create_aligned_buffer(byte_count); aligned_memshfl(key_data.get(), image_data.get(), byte_count, 0x0F0F0F0F, 0x0B0B0B0B, 0x07070707, 0x03030303); @@ -133,7 +133,7 @@ std::shared_ptr convert_frame_for_port(const core::video_format_desc& chan const core::const_frame& frame2, BMDFieldDominance field_dominance) { - std::shared_ptr image_data(scalable_aligned_malloc(decklink_format_desc.size, 64), scalable_aligned_free); + std::shared_ptr image_data = create_aligned_buffer(decklink_format_desc.size); if (field_dominance != bmdProgressiveFrame) { convert_frame(channel_format_desc, diff --git a/src/shell/CMakeLists.txt b/src/shell/CMakeLists.txt index 519100f24a..edd9ca4fda 100644 --- a/src/shell/CMakeLists.txt +++ b/src/shell/CMakeLists.txt @@ -54,9 +54,7 @@ if (MSVC) Winmm.lib Ws2_32.lib optimized tbb.lib - optimized tbbmalloc.lib debug tbb_debug.lib - debug tbbmalloc_debug.lib OpenGL32.lib glew32.lib openal32.lib diff --git a/src/shell/main.cpp b/src/shell/main.cpp index 3c0dafc094..8c9ebe679f 100644 --- a/src/shell/main.cpp +++ b/src/shell/main.cpp @@ -19,16 +19,10 @@ * Author: Robert Nagy, ronag89@gmail.com */ -// tbbmalloc_proxy: -// Replace the standard memory allocation routines in Microsoft* C/C++ RTL -// (malloc/free, global new/delete, etc.) with the TBB memory allocator. - #if defined _DEBUG && defined _MSC_VER #define _CRTDBG_MAP_ALLOC #include #include -#else -#include #endif #include "included_modules.h"