diff --git a/addons/gdcef/build.py b/addons/gdcef/build.py index d76239a..757fb64 100755 --- a/addons/gdcef/build.py +++ b/addons/gdcef/build.py @@ -58,6 +58,8 @@ # Godot .gdns and .gdnlib files inside the libs folders in GDCEF_EXAMPLES_PATH the # demos folder. CEF_ARTIFACTS_FOLDER_NAME = "cef_artifacts" +# Use OpenMP for using CPU parallelim (i.e. for copying textures) +CEF_USE_CPU_PARALLELISM = "yes" # or "no" ############################################################################### ### Project internal paths local from this script. Do not change them! @@ -401,13 +403,15 @@ def gdnative_scons_cmd(plateform): "cef_artifacts_folder=\\\"" + CEF_ARTIFACTS_FOLDER_NAME + "\\\"", "build_path=" + CEF_ARTIFACTS_BUILD_PATH, "target=" + MODULE_TARGET, "--jobs=" + NPROC, - "arch=" + ARCHI, "platform=" + plateform], check=True) + "arch=" + ARCHI, "platform=" + plateform, + "cpu_parallelism=" + CEF_USE_CPU_PARALLELISM], check=True) else: run(SCONS + ["api_path=" + GODOT_CPP_API_PATH, "cef_artifacts_folder=\\\"" + CEF_ARTIFACTS_FOLDER_NAME + "\\\"", "build_path=" + CEF_ARTIFACTS_BUILD_PATH, "target=" + MODULE_TARGET, "--jobs=" + NPROC, - "platform=" + plateform], check=True) + "platform=" + plateform, + "cpu_parallelism=" + CEF_USE_CPU_PARALLELISM], check=True) ############################################################################### ### Compile Godot CEF module named GDCef and its subprocess diff --git a/addons/gdcef/gdcef/SConstruct b/addons/gdcef/gdcef/SConstruct index a5931fb..be9a5d3 100644 --- a/addons/gdcef/gdcef/SConstruct +++ b/addons/gdcef/gdcef/SConstruct @@ -49,6 +49,7 @@ opts.Add(BoolVariable('use_llvm', 'Use the LLVM / Clang compiler', 'no')) opts.Add(PathVariable('api_path', 'Godot C++ API', '')) opts.Add(PathVariable('build_path', 'Build path', '')) opts.Add(PathVariable('cef_artifacts_folder', 'CEF artifacts folder', '', PathVariable.PathAccept)) +opts.Add(BoolVariable('cpu_parallelism', 'Use CPU parallelism', 'yes')) # Updates the environment with the option variables. opts.Update(env) @@ -163,6 +164,12 @@ if platform == 'linux' or platform == 'osx': '-Werror=implicit-function-declaration', '-Wtautological-compare']) +# OpenMP +if env['cpu_parallelism']: + env.Append(CCFLAGS=['-fopenmp']) + env.Append(CXXFLAGS=['-fopenmp']) + env.Append(LINKFLAGS=['-fopenmp']) + # User defines env.Append(CXXFLAGS=['-DCEF_ARTIFACTS_FOLDER=' + env['cef_artifacts_folder']]) diff --git a/addons/gdcef/gdcef/src/gdbrowser.cpp b/addons/gdcef/gdcef/src/gdbrowser.cpp index 3a116b9..ddf1210 100644 --- a/addons/gdcef/gdcef/src/gdbrowser.cpp +++ b/addons/gdcef/gdcef/src/gdbrowser.cpp @@ -31,9 +31,9 @@ #include #include #include -#define USING_CONCURRENCY 1 -#if USING_CONCURRENCY -#include + +#ifdef _OPENMP +# include #endif //------------------------------------------------------------------------------ @@ -109,6 +109,14 @@ godot::String GDBrowserView::getError() int GDBrowserView::init(godot::String const& url, CefBrowserSettings const& settings, CefWindowInfo const& window_info) { +#ifdef _OPENMP + #pragma omp parallel + { + #pragma omp single + GDCEF_DEBUG_VAL("OpenMP number of threads = " << omp_get_num_threads()); + } +#endif + // Create a new browser using the window parameters specified by // |windowInfo|. If |request_context| is empty the global request context // will be used. This method can only be called on the browser process UI @@ -186,7 +194,7 @@ void GDBrowserView::onPaint(CefRefPtr /*browser*/, // Copy CEF image buffer to Godot PoolByteArray m_data.resize(TEXTURE_SIZE); - // Copy per line func for concurrency + // Copy per line func for OpenMP/PPL unsigned char* imageData = m_data.ptrw(); const unsigned char* cbuffer = (const unsigned char*)buffer; auto doCopyLine = [imageData, cbuffer, width, COLOR_CHANELS](int line, int x, int copyWidth) @@ -205,15 +213,15 @@ void GDBrowserView::onPaint(CefRefPtr /*browser*/, if (bResized) { -#if USING_CONCURRENCY - concurrency::parallel_for(0, height, - std::bind(doCopyLine, std::placeholders::_1, 0, width)); -#else + // PPL + //concurrency::parallel_for(0, height, + // std::bind(doCopyLine, std::placeholders::_1, 0, width)); + + #pragma omp parallel for (int y = 0; y < height; ++y) { doCopyLine(y, 0, width); } -#endif // Copy Godot PoolByteArray to Godot texture. m_image->set_data(width, height, false, godot::Image::FORMAT_RGBA8, m_data); @@ -223,15 +231,15 @@ void GDBrowserView::onPaint(CefRefPtr /*browser*/, { for (const CefRect& rect : dirtyRects) { -#if USING_CONCURRENCY - concurrency::parallel_for(rect.y, rect.y + rect.height, - std::bind(doCopyLine, std::placeholders::_1, rect.x, rect.width)); -#else + //PPL + //concurrency::parallel_for(rect.y, rect.y + rect.height, + // std::bind(doCopyLine, std::placeholders::_1, rect.x, rect.width)); + + #pragma omp parallel for (int y = rect.y; y < rect.y + rect.height; ++y) { doCopyLine(y, rect.x, rect.width); } -#endif } // Copy Godot PoolByteArray to Godot texture.