Skip to content

Commit

Permalink
fix: replace tbbmalloc with os native implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Oct 19, 2023
1 parent 594ce12 commit 3816e08
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 17 deletions.
4 changes: 0 additions & 4 deletions src/CMakeModules/Bootstrap_Windows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 10 additions & 0 deletions src/common/memshfl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@

namespace caspar {

#ifdef _MSC_VER
static std::shared_ptr<void> create_aligned_buffer(size_t size) {
return std::shared_ptr<void>(_aligned_malloc(size, 64), _aligned_free);
}
#else
static std::shared_ptr<void> create_aligned_buffer(size_t size) {
return std::shared_ptr<void>(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);
Expand Down
5 changes: 2 additions & 3 deletions src/modules/decklink/consumer/decklink_consumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
#include <common/timer.h>

#include <tbb/parallel_for.h>
#include <tbb/scalable_allocator.h>

#include <boost/circular_buffer.hpp>

#include <atomic>
#include <common/memshfl.h>
#include <common/prec_timer.h>
#include <condition_variable>
#include <future>
Expand Down Expand Up @@ -520,8 +520,7 @@ struct decklink_consumer final : public IDeckLinkVideoOutputCallback
nb_samples);
}

std::shared_ptr<void> image_data(scalable_aligned_malloc(decklink_format_desc_.size, 64),
scalable_aligned_free);
std::shared_ptr<void> image_data = create_aligned_buffer(decklink_format_desc_.size);

schedule_next_video(image_data, nb_samples, video_scheduled_);
for (auto& context : secondary_port_contexts_) {
Expand Down
4 changes: 2 additions & 2 deletions src/modules/decklink/consumer/frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace caspar { namespace decklink {

std::shared_ptr<void> convert_to_key_only(const std::shared_ptr<void>& image_data, std::size_t byte_count)
{
auto key_data = std::shared_ptr<void>(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);

Expand Down Expand Up @@ -133,7 +133,7 @@ std::shared_ptr<void> convert_frame_for_port(const core::video_format_desc& chan
const core::const_frame& frame2,
BMDFieldDominance field_dominance)
{
std::shared_ptr<void> image_data(scalable_aligned_malloc(decklink_format_desc.size, 64), scalable_aligned_free);
std::shared_ptr<void> image_data = create_aligned_buffer(decklink_format_desc.size);

if (field_dominance != bmdProgressiveFrame) {
convert_frame(channel_format_desc,
Expand Down
2 changes: 0 additions & 2 deletions src/shell/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions src/shell/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,10 @@
* Author: Robert Nagy, [email protected]
*/

// 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 <crtdbg.h>
#include <stdlib.h>
#else
#include <tbb/tbbmalloc_proxy.h>
#endif

#include "included_modules.h"
Expand Down

0 comments on commit 3816e08

Please sign in to comment.