From 5e835f79ede885a08f75abdafba48045da247f86 Mon Sep 17 00:00:00 2001 From: Arun-Prasad-V Date: Sat, 17 Feb 2024 01:21:47 +0530 Subject: [PATCH] renamed GL GPU enable param --- README.md | 11 ++--- realsense2_camera/CMakeLists.txt | 14 +++---- .../include/base_realsense_node.h | 11 +++-- realsense2_camera/include/gl_window.h | 2 +- realsense2_camera/launch/rs_launch.py | 2 +- realsense2_camera/src/base_realsense_node.cpp | 8 ++-- realsense2_camera/src/gl_gpu_processing.cpp | 2 +- realsense2_camera/src/parameters.cpp | 14 +++---- realsense2_camera/src/rs_node_setup.cpp | 42 +++++++++---------- 9 files changed, 50 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index 52af27c039..c925020397 100644 --- a/README.md +++ b/README.md @@ -306,19 +306,16 @@ User can set the camera name and camera namespace, to distinguish between camera - 1 -> **copy**: Every gyro message will be attached by the last accel message. - 2 -> **linear_interpolation**: Every gyro message will be attached by an accel message which is interpolated to gyro's timestamp. - Note: When the param *unite_imu_method* is dynamically updated, re-enable either gyro or accel stream for the change to take effect. -- **accelerate_with_gpu**: - - GPU accelerated processing of PointCloud and Colorizer filters. - - integer: - - 0 --> **NO_GPU**: use only CPU for proccessing PointCloud and Colorizer filters - - 1 --> **GL_GPU**: use GLSL to accelerate GPU for processing PointCloud and Colorizer filters +- **accelerate_gpu_with_glsl**: + - Boolean: GPU accelerated with GLSL for processing PointCloud and Colorizer filters. - Note: - To have smooth transition between the processing blocks when this parameter is updated dynamically, the node will: - Stop the video sensors - Do necessary GLSL configuration - And then, start the video sensors - - To enable GPU acceleration, turn ON `BUILD_ACCELERATE_WITH_GPU` during build: + - To enable GPU acceleration, turn ON `BUILD_ACCELERATE_GPU_WITH_GLSL` during build: ```bash - colcon build --cmake-args '-DBUILD_ACCELERATE_WITH_GPU=ON' + colcon build --cmake-args '-DBUILD_ACCELERATE_GPU_WITH_GLSL=ON' ``` #### Parameters that cannot be changed in runtime: diff --git a/realsense2_camera/CMakeLists.txt b/realsense2_camera/CMakeLists.txt index 1d3ad2ac81..380a9707f4 100644 --- a/realsense2_camera/CMakeLists.txt +++ b/realsense2_camera/CMakeLists.txt @@ -117,7 +117,7 @@ find_package(tf2 REQUIRED) find_package(diagnostic_updater REQUIRED) find_package(realsense2 2.54.1) -if (BUILD_ACCELERATE_WITH_GPU) +if (BUILD_ACCELERATE_GPU_WITH_GLSL) find_package(realsense2-gl 2.54.1) endif() if(NOT realsense2_FOUND) @@ -144,7 +144,7 @@ set(SOURCES src/tfs.cpp ) -if (BUILD_ACCELERATE_WITH_GPU) +if (BUILD_ACCELERATE_GPU_WITH_GLSL) list(APPEND SOURCES src/gl_gpu_processing.cpp) endif() @@ -178,8 +178,8 @@ if(${rclcpp_VERSION} VERSION_GREATER_EQUAL "17.0") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DRCLCPP_HAS_OnSetParametersCallbackType") endif() -if (BUILD_ACCELERATE_WITH_GPU) - add_definitions(-DACCELERATE_WITH_GPU) +if (BUILD_ACCELERATE_GPU_WITH_GLSL) + add_definitions(-DACCELERATE_GPU_WITH_GLSL) endif() set(INCLUDES @@ -195,7 +195,7 @@ set(INCLUDES include/profile_manager.h include/image_publisher.h) -if (BUILD_ACCELERATE_WITH_GPU) +if (BUILD_ACCELERATE_GPU_WITH_GLSL) list(APPEND INCLUDES include/gl_window.h) endif() @@ -214,7 +214,7 @@ add_library(${PROJECT_NAME} SHARED ${SOURCES} ) -if (BUILD_ACCELERATE_WITH_GPU) +if (BUILD_ACCELERATE_GPU_WITH_GLSL) set(link_libraries ${realsense2-gl_LIBRARY}) else() set(link_libraries ${realsense2_LIBRARY}) @@ -238,7 +238,7 @@ set(dependencies diagnostic_updater ) -if (BUILD_ACCELERATE_WITH_GPU) +if (BUILD_ACCELERATE_GPU_WITH_GLSL) list(APPEND dependencies realsense2-gl) else() list(APPEND dependencies realsense2) diff --git a/realsense2_camera/include/base_realsense_node.h b/realsense2_camera/include/base_realsense_node.h index 3d808f5e1c..4792f5456c 100755 --- a/realsense2_camera/include/base_realsense_node.h +++ b/realsense2_camera/include/base_realsense_node.h @@ -49,7 +49,7 @@ #include #include -#if defined (ACCELERATE_WITH_GPU) +#if defined (ACCELERATE_GPU_WITH_GLSL) #include #endif @@ -119,7 +119,6 @@ namespace realsense2_camera public: enum class imu_sync_method{NONE, COPY, LINEAR_INTERPOLATION}; - enum class accelerate_with_gpu {NO_GPU, GL_GPU}; protected: class float3 @@ -268,7 +267,7 @@ namespace realsense2_camera void startRGBDPublisherIfNeeded(); void stopPublishers(const std::vector& profiles); -#if defined (ACCELERATE_WITH_GPU) +#if defined (ACCELERATE_GPU_WITH_GLSL) void initOpenGLProcessing(bool use_gpu_processing); void shutdownOpenGLProcessing(); void glfwPollEventCallback(); @@ -354,11 +353,11 @@ namespace realsense2_camera std::shared_ptr _diagnostics_updater; rs2::stream_profile _base_profile; -#if defined (ACCELERATE_WITH_GPU) +#if defined (ACCELERATE_GPU_WITH_GLSL) GLwindow _app; rclcpp::TimerBase::SharedPtr _timer; - accelerate_with_gpu _accelerate_with_gpu; - bool _is_accelerate_with_gpu_changed; + bool _accelerate_gpu_with_glsl; + bool _is_accelerate_gpu_with_glsl_changed; #endif };//end class diff --git a/realsense2_camera/include/gl_window.h b/realsense2_camera/include/gl_window.h index a1cebb7af8..2bca9d4eb5 100644 --- a/realsense2_camera/include/gl_window.h +++ b/realsense2_camera/include/gl_window.h @@ -16,7 +16,7 @@ #include // Include RealSense Cross Platform API -#if defined (ACCELERATE_WITH_GPU) +#if defined (ACCELERATE_GPU_WITH_GLSL) #define GL_SILENCE_DEPRECATION #define GLFW_INCLUDE_GLU diff --git a/realsense2_camera/launch/rs_launch.py b/realsense2_camera/launch/rs_launch.py index fa6dfaabf2..4e7aee856c 100644 --- a/realsense2_camera/launch/rs_launch.py +++ b/realsense2_camera/launch/rs_launch.py @@ -29,7 +29,7 @@ {'name': 'config_file', 'default': "''", 'description': 'yaml config file'}, {'name': 'json_file_path', 'default': "''", 'description': 'allows advanced configuration'}, {'name': 'initial_reset', 'default': 'false', 'description': "''"}, - {'name': 'accelerate_with_gpu', 'default': "0", 'description': '[0-No_GPU, 1-GL_GPU]'}, + {'name': 'accelerate_gpu_with_glsl', 'default': "false", 'description': 'enable GPU acceleration with GLSL'}, {'name': 'rosbag_filename', 'default': "''", 'description': 'A realsense bagfile to run from as a device'}, {'name': 'log_level', 'default': 'info', 'description': 'debug log level [DEBUG|INFO|WARN|ERROR|FATAL]'}, {'name': 'output', 'default': 'screen', 'description': 'pipe node output [screen|log]'}, diff --git a/realsense2_camera/src/base_realsense_node.cpp b/realsense2_camera/src/base_realsense_node.cpp index d35112a968..0202e4e70b 100755 --- a/realsense2_camera/src/base_realsense_node.cpp +++ b/realsense2_camera/src/base_realsense_node.cpp @@ -115,10 +115,10 @@ BaseRealSenseNode::BaseRealSenseNode(rclcpp::Node& node, _imu_sync_method(imu_sync_method::NONE), _is_profile_changed(false), _is_align_depth_changed(false) -#if defined (ACCELERATE_WITH_GPU) +#if defined (ACCELERATE_GPU_WITH_GLSL) ,_app(1280, 720, "RS_GLFW_Window"), - _accelerate_with_gpu(accelerate_with_gpu::NO_GPU), - _is_accelerate_with_gpu_changed(false) + _accelerate_gpu_with_glsl(false), + _is_accelerate_gpu_with_glsl_changed(false) #endif { if ( use_intra_process ) @@ -234,7 +234,7 @@ void BaseRealSenseNode::setupFilters() _cv_mpc.notify_one(); }; -#if defined (ACCELERATE_WITH_GPU) +#if defined (ACCELERATE_GPU_WITH_GLSL) _colorizer_filter = std::make_shared(std::make_shared(), _parameters, _logger); _pc_filter = std::make_shared(std::make_shared(), _node, _parameters, _logger); #else diff --git a/realsense2_camera/src/gl_gpu_processing.cpp b/realsense2_camera/src/gl_gpu_processing.cpp index 8bbf8c4b44..d6b8f883e2 100644 --- a/realsense2_camera/src/gl_gpu_processing.cpp +++ b/realsense2_camera/src/gl_gpu_processing.cpp @@ -18,7 +18,7 @@ using namespace realsense2_camera; using namespace std::chrono_literals; -#if defined (ACCELERATE_WITH_GPU) +#if defined (ACCELERATE_GPU_WITH_GLSL) void BaseRealSenseNode::initOpenGLProcessing(bool use_gpu_processing) { diff --git a/realsense2_camera/src/parameters.cpp b/realsense2_camera/src/parameters.cpp index 0747c49c42..dda0b6133e 100644 --- a/realsense2_camera/src/parameters.cpp +++ b/realsense2_camera/src/parameters.cpp @@ -83,17 +83,17 @@ void BaseRealSenseNode::getParameters() _base_frame_id = (static_cast(std::ostringstream() << _camera_name << "_" << _base_frame_id)).str(); _parameters_names.push_back(param_name); -#if defined (ACCELERATE_WITH_GPU) - param_name = std::string("accelerate_with_gpu"); - _parameters->setParam(param_name, int(accelerate_with_gpu::NO_GPU), +#if defined (ACCELERATE_GPU_WITH_GLSL) + param_name = std::string("accelerate_gpu_with_glsl"); + _parameters->setParam(param_name, false, [this](const rclcpp::Parameter& parameter) { - accelerate_with_gpu temp_value = accelerate_with_gpu(parameter.get_value()); - if (_accelerate_with_gpu != temp_value) + bool temp_value = parameter.get_value(); + if (_accelerate_gpu_with_glsl != temp_value) { - _accelerate_with_gpu = temp_value; + _accelerate_gpu_with_glsl = temp_value; std::lock_guard lock_guard(_profile_changes_mutex); - _is_accelerate_with_gpu_changed = true; + _is_accelerate_gpu_with_glsl_changed = true; } _cv_mpc.notify_one(); }); diff --git a/realsense2_camera/src/rs_node_setup.cpp b/realsense2_camera/src/rs_node_setup.cpp index ad4f8abe8e..191644b83e 100755 --- a/realsense2_camera/src/rs_node_setup.cpp +++ b/realsense2_camera/src/rs_node_setup.cpp @@ -22,10 +22,9 @@ using namespace rs2; void BaseRealSenseNode::setup() { -#if defined (ACCELERATE_WITH_GPU) - bool use_gpu_processing = (_accelerate_with_gpu == accelerate_with_gpu::GL_GPU); - initOpenGLProcessing(use_gpu_processing); - _is_accelerate_with_gpu_changed = false; +#if defined (ACCELERATE_GPU_WITH_GLSL) + initOpenGLProcessing(_accelerate_gpu_with_glsl); + _is_accelerate_gpu_with_glsl_changed = false; #endif setDynamicParams(); startDiagnosticsUpdater(); @@ -47,15 +46,15 @@ void BaseRealSenseNode::monitoringProfileChanges() _cv_mpc.wait_for(lock, std::chrono::milliseconds(time_interval), [&]{return (!_is_running || _is_profile_changed || _is_align_depth_changed - #if defined (ACCELERATE_WITH_GPU) - || _is_accelerate_with_gpu_changed + #if defined (ACCELERATE_GPU_WITH_GLSL) + || _is_accelerate_gpu_with_glsl_changed #endif );}); if (_is_running && (_is_profile_changed || _is_align_depth_changed - #if defined (ACCELERATE_WITH_GPU) - || _is_accelerate_with_gpu_changed + #if defined (ACCELERATE_GPU_WITH_GLSL) + || _is_accelerate_gpu_with_glsl_changed #endif )) { @@ -71,8 +70,8 @@ void BaseRealSenseNode::monitoringProfileChanges() _is_profile_changed = false; _is_align_depth_changed = false; - #if defined (ACCELERATE_WITH_GPU) - _is_accelerate_with_gpu_changed = false; + #if defined (ACCELERATE_GPU_WITH_GLSL) + _is_accelerate_gpu_with_glsl_changed = false; #endif } } @@ -354,13 +353,12 @@ void BaseRealSenseNode::updateSensors() try{ stopRequiredSensors(); - #if defined (ACCELERATE_WITH_GPU) - if (_is_accelerate_with_gpu_changed) + #if defined (ACCELERATE_GPU_WITH_GLSL) + if (_is_accelerate_gpu_with_glsl_changed) { shutdownOpenGLProcessing(); - bool use_gpu_processing = (_accelerate_with_gpu == accelerate_with_gpu::GL_GPU); - initOpenGLProcessing(use_gpu_processing); + initOpenGLProcessing(_accelerate_gpu_with_glsl); } #endif @@ -394,15 +392,15 @@ void BaseRealSenseNode::stopRequiredSensors() // and we are on a video sensor. TODO: explore better options to monitor and update changes // without resetting the whole sensors and topics. if (is_profile_changed || (is_video_sensor && (_is_align_depth_changed - #if defined (ACCELERATE_WITH_GPU) - || _is_accelerate_with_gpu_changed + #if defined (ACCELERATE_GPU_WITH_GLSL) + || _is_accelerate_gpu_with_glsl_changed #endif ))) { std::vector active_profiles = sensor->get_active_streams(); if (is_profile_changed - #if defined (ACCELERATE_WITH_GPU) - || _is_accelerate_with_gpu_changed + #if defined (ACCELERATE_GPU_WITH_GLSL) + || _is_accelerate_gpu_with_glsl_changed #endif ) { @@ -440,8 +438,8 @@ void BaseRealSenseNode::startUpdatedSensors() bool is_video_sensor = (sensor->is() || sensor->is()); if (is_profile_changed || (is_video_sensor && (_is_align_depth_changed - #if defined (ACCELERATE_WITH_GPU) - || _is_accelerate_with_gpu_changed + #if defined (ACCELERATE_GPU_WITH_GLSL) + || _is_accelerate_gpu_with_glsl_changed #endif ))) { @@ -459,8 +457,8 @@ void BaseRealSenseNode::startUpdatedSensors() } if (is_profile_changed - #if defined (ACCELERATE_WITH_GPU) - || _is_accelerate_with_gpu_changed + #if defined (ACCELERATE_GPU_WITH_GLSL) + || _is_accelerate_gpu_with_glsl_changed #endif ) {