Browse Source

TBB is now a dependency of lib. Implemented multithreaded xBRZ scale

Ivan Savenko 1 year ago
parent
commit
f0448acaa3

+ 1 - 5
AI/BattleAI/CMakeLists.txt

@@ -37,11 +37,7 @@ else()
 endif()
 
 target_include_directories(BattleAI PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
-target_link_libraries(BattleAI PRIVATE vcmi TBB::tbb)
+target_link_libraries(BattleAI PRIVATE vcmi)
 
 vcmi_set_output_dir(BattleAI "AI")
 enable_pch(BattleAI)
-
-if(APPLE_IOS AND NOT USING_CONAN)
-	install(IMPORTED_RUNTIME_ARTIFACTS TBB::tbb LIBRARY DESTINATION ${LIB_DIR}) # CMake 3.21+
-endif()

+ 0 - 4
AI/CMakeLists.txt

@@ -8,10 +8,6 @@ else()
 	option(FORCE_BUNDLED_FL "Force to use FuzzyLite included into VCMI's source tree" OFF)
 endif()
 
-if(TBB_FOUND AND MSVC)
-	   install_vcpkg_imported_tgt(TBB::tbb)
-endif()
-
 #FuzzyLite uses MSVC pragmas in headers, so, we need to disable -Wunknown-pragmas
 if(MINGW)
     add_compile_options(-Wno-unknown-pragmas)

+ 1 - 5
AI/Nullkiller/CMakeLists.txt

@@ -157,11 +157,7 @@ else()
 endif()
 
 target_include_directories(Nullkiller PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
-target_link_libraries(Nullkiller PUBLIC vcmi fuzzylite::fuzzylite TBB::tbb)
+target_link_libraries(Nullkiller PUBLIC vcmi fuzzylite::fuzzylite)
 
 vcmi_set_output_dir(Nullkiller "AI")
 enable_pch(Nullkiller)
-
-if(APPLE_IOS AND NOT USING_CONAN)
-	install(IMPORTED_RUNTIME_ARTIFACTS TBB::tbb LIBRARY DESTINATION ${LIB_DIR}) # CMake 3.21+
-endif()

+ 5 - 1
CMakeLists.txt

@@ -519,7 +519,7 @@ if(ENABLE_LAUNCHER OR ENABLE_EDITOR)
 	endif()
 endif()
 
-if(ENABLE_CLIENT)
+if(NOT ENABLE_MINIMAL_LIB)
 	find_package(TBB REQUIRED)
 endif()
 
@@ -722,6 +722,10 @@ endif()
 
 
 if(WIN32)
+	if(TBB_FOUND AND MSVC)
+		   install_vcpkg_imported_tgt(TBB::tbb)
+	endif()
+
 	if(USING_CONAN)
 		#Conan imports enabled
 		vcmi_install_conan_deps("\${CMAKE_INSTALL_PREFIX}")

+ 10 - 1
client/renderSDL/SDL_Extensions.cpp

@@ -19,6 +19,8 @@
 
 #include "../../lib/GameConstants.h"
 
+#include <tbb/parallel_for.h>
+
 #include <SDL_render.h>
 #include <SDL_surface.h>
 #include <SDL_version.h>
@@ -667,7 +669,14 @@ SDL_Surface * CSDL_Ext::scaleSurfaceIntegerFactor(SDL_Surface * surf, int factor
 	const uint32_t * srcPixels = static_cast<const uint32_t*>(intermediate->pixels);
 	uint32_t * dstPixels = static_cast<uint32_t*>(ret->pixels);
 
-	xbrz::scale(factor, srcPixels, dstPixels, intermediate->w, intermediate->h, xbrz::ColorFormat::ARGB);
+	// avoid excessive granulation - xBRZ prefers at least 8-16 lines per task
+	// TODO: compare performance and size of images, recheck values for potentially better parameters
+	const int granulation = std::clamp(surf->h / 64 * 8, 8, 64);
+
+	tbb::parallel_for(tbb::blocked_range<size_t>(0, intermediate->h, granulation), [&](const tbb::blocked_range<size_t> & r)
+	{
+		xbrz::scale(factor, srcPixels, dstPixels, intermediate->w, intermediate->h, xbrz::ColorFormat::ARGB, {}, r.begin(), r.end());
+	});
 
 	SDL_FreeSurface(intermediate);
 

+ 3 - 1
lib/CMakeLists.txt

@@ -731,7 +731,7 @@ endif()
 
 set_target_properties(vcmi PROPERTIES COMPILE_DEFINITIONS "VCMI_DLL=1")
 target_link_libraries(vcmi PUBLIC
-	minizip::minizip ZLIB::ZLIB
+	minizip::minizip ZLIB::ZLIB TBB::tbb
 	${SYSTEM_LIBS} Boost::boost Boost::thread Boost::filesystem Boost::program_options Boost::locale Boost::date_time
 )
 
@@ -796,6 +796,8 @@ if(NOT ENABLE_STATIC_LIBS)
 endif()
 
 if(APPLE_IOS AND NOT USING_CONAN)
+	install(IMPORTED_RUNTIME_ARTIFACTS TBB::tbb LIBRARY DESTINATION ${LIB_DIR}) # CMake 3.21+
+
 	get_target_property(LINKED_LIBS vcmi LINK_LIBRARIES)
 	foreach(LINKED_LIB IN LISTS LINKED_LIBS)
 		if(NOT TARGET ${LINKED_LIB})