From 5e39eeee761ff311ba57324209bca66ce920bf1b Mon Sep 17 00:00:00 2001 From: Rhys Mainwaring Date: Thu, 5 Aug 2021 14:46:33 +0100 Subject: [PATCH] [Metal] Add Metal support for macOS Update ign command script - Remove server only setting for macOS Enable the sensors server plugin to run on macOS - Initialise the render engine for sensors on the main thread - Platform specific OpenGL context code must be moved elsewhere. - Ensure the active OpenGL context is associated with the render thread post initialisation Enable the Gazebo GUI to run on macOS - Move the RenderThread object to the render thread at the same time as a the OpenGL context Reinstate render synchronisation - Reinstate Ignition / QML serial rendering IgnRenderer::Render. - Allow IgnRenderer::Render to accept a nullptr so it can be called without render sync from the main thread before the render thread is started. Update QML - Add missing properties for tooltopDelay Configure the Qt scene graph to use the Metal backend - Force the gazebo application to use the Metal backend for the Qt scene graph - Move Metal scene graph backend to ign::gui::Application Modify sensors to use Metal - Set the render system parameter to use Metal Default to Metal on macOS, otherwise use OpenGL - Add preprocessor checks to use the Metal graphics API for __APPLE__ Signed-off-by: Rhys Mainwaring --- src/cmd/cmdgazebo.rb.in | 13 ------------- .../plugins/component_inspector/Boolean.qml | 2 ++ src/gui/plugins/modules/TypeIcon.qml | 2 ++ .../plugins/visualize_lidar/VisualizeLidar.qml | 3 +++ src/rendering/RenderUtil.cc | 9 +++++++++ src/systems/sensors/Sensors.cc | 18 ++++++++++++++++-- 6 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/cmd/cmdgazebo.rb.in b/src/cmd/cmdgazebo.rb.in index dfb46fec7b1..802bc417c2e 100755 --- a/src/cmd/cmdgazebo.rb.in +++ b/src/cmd/cmdgazebo.rb.in @@ -446,13 +446,6 @@ has properly set the DYLD_LIBRARY_PATH environment variables." # Neither the -s nor -g options were used, so run both the server # and gui. if options['server'] == 0 && options['gui'] == 0 - - if plugin.end_with? ".dylib" - puts "`ign gazebo` currently only works with the -s argument on macOS. -See https://github.com/ignitionrobotics/ign-gazebo/issues/44 for more info." - exit(-1) - end - serverPid = Process.fork do ENV['RMT_PORT'] = '1500' Process.setpgid(0, 0) @@ -504,12 +497,6 @@ See https://github.com/ignitionrobotics/ign-gazebo/issues/44 for more info." options['headless-rendering']) # Otherwise run the gui else options['gui'] - if plugin.end_with? ".dylib" - puts "`ign gazebo` currently only works with the -s argument on macOS. -See https://github.com/ignitionrobotics/ign-gazebo/issues/44 for more info." - exit(-1) - end - ENV['RMT_PORT'] = '1501' Importer.runGui(options['gui_config'], options['render_engine_gui']) end diff --git a/src/gui/plugins/component_inspector/Boolean.qml b/src/gui/plugins/component_inspector/Boolean.qml index c993bd5dd54..a832caa0aab 100644 --- a/src/gui/plugins/component_inspector/Boolean.qml +++ b/src/gui/plugins/component_inspector/Boolean.qml @@ -34,6 +34,8 @@ Rectangle { // Horizontal margins property int margin: 5 + property int tooltipDelay: 500 + RowLayout { anchors.fill: parent diff --git a/src/gui/plugins/modules/TypeIcon.qml b/src/gui/plugins/modules/TypeIcon.qml index 4e8c1a308e6..0336b9a56e0 100644 --- a/src/gui/plugins/modules/TypeIcon.qml +++ b/src/gui/plugins/modules/TypeIcon.qml @@ -31,6 +31,8 @@ Image { */ property string entityType: '' + property int tooltipDelay: 500 + /** * Image address according to type */ diff --git a/src/gui/plugins/visualize_lidar/VisualizeLidar.qml b/src/gui/plugins/visualize_lidar/VisualizeLidar.qml index fa6fdea0272..b018d985404 100644 --- a/src/gui/plugins/visualize_lidar/VisualizeLidar.qml +++ b/src/gui/plugins/visualize_lidar/VisualizeLidar.qml @@ -30,6 +30,9 @@ GridLayout { anchors.leftMargin: 10 anchors.rightMargin: 10 + property int tooltipDelay: 500 + property int tooltipTimeout: 1000 + CheckBox { Layout.alignment: Qt.AlignHCenter id: displayVisual diff --git a/src/rendering/RenderUtil.cc b/src/rendering/RenderUtil.cc index ff14b22a032..fd6a5cc481f 100644 --- a/src/rendering/RenderUtil.cc +++ b/src/rendering/RenderUtil.cc @@ -2536,11 +2536,20 @@ void RenderUtil::Init() rendering::setPluginPaths(pluginPath.PluginPaths()); std::map params; +#ifdef __APPLE__ + // TODO(srmainwaring): implement facility for overriding the default + // graphics API in macOS, in which case there are restrictions on + // the version of OpenGL used. + params["metal"] = "1"; +#else if (this->dataPtr->useCurrentGLContext) params["useCurrentGLContext"] = "1"; +#endif + if (this->dataPtr->isHeadlessRendering) params["headless"] = "1"; params["winID"] = this->dataPtr->winID; + this->dataPtr->engine = rendering::engine(this->dataPtr->engineName, params); if (!this->dataPtr->engine) { diff --git a/src/systems/sensors/Sensors.cc b/src/systems/sensors/Sensors.cc index 366d81c46e7..231ad06727e 100644 --- a/src/systems/sensors/Sensors.cc +++ b/src/systems/sensors/Sensors.cc @@ -210,7 +210,7 @@ void SensorsPrivate::WaitForInit() this->renderUtil.SetBackgroundColor(*this->backgroundColor); if (this->ambientLight) this->renderUtil.SetAmbientLight(*this->ambientLight); - this->renderUtil.Init(); + this->scene = this->renderUtil.Scene(); this->scene->SetCameraPassCountPerGpuFlush(6u); this->initialized = true; @@ -461,7 +461,21 @@ void Sensors::Update(const UpdateInfo &_info, EntityComponentManager &_ecm) { IGN_PROFILE("Sensors::Update"); - std::unique_lock lock(this->dataPtr->renderMutex); + + if (!this->dataPtr->initialized && + (_ecm.HasComponentType(components::Camera::typeId) || + _ecm.HasComponentType(components::DepthCamera::typeId) || + _ecm.HasComponentType(components::GpuLidar::typeId) || + _ecm.HasComponentType(components::RgbdCamera::typeId) || + _ecm.HasComponentType(components::ThermalCamera::typeId))) + { + igndbg << "Initialization needed" << std::endl; + std::unique_lock lock(this->dataPtr->renderMutex); + + // Initialise render engine on main thread + this->dataPtr->renderUtil.Init(); + } + if (this->dataPtr->running && this->dataPtr->initialized) { this->dataPtr->renderUtil.UpdateECM(_info, _ecm);