Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLI to switch to Vulkan & Metal backends #1735

Merged
merged 5 commits into from
Jan 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions include/gz/sim/ServerConfig.hh
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,28 @@ namespace gz
public: void SetRenderEngineServer(
const std::string &_renderEngineServer);

/// \brief Set the render engine server API backend.
/// \param[in] _apiBackend See --render-engine-server-api-backend for
/// possible options
public: void SetRenderEngineServerApiBackend(
const std::string &_apiBackend);

/// \return Api backend for server. See SetRenderEngineServerApiBackend()
const std::string &RenderEngineServerApiBackend() const;

/// \brief Set the render engine gui plugin library.
/// \param[in] _renderEngineGui File containing render engine library.
public: void SetRenderEngineGui(const std::string &_renderEngineGui);

/// \brief Set the render engine gui API backend.
/// \param[in] _apiBackend See --render-engine-gui-api-backend for
/// possible options
public: void SetRenderEngineGuiApiBackend(
const std::string &_apiBackend);

/// \return Api backend for gui. See SetRenderEngineGuiApiBackend()
const std::string &RenderEngineGuiApiBackend() const;

/// \brief Instruct simulation to attach a plugin to a specific
/// entity when simulation starts.
/// \param[in] _info Information about the plugin to load.
Expand Down
45 changes: 45 additions & 0 deletions include/gz/sim/components/RenderEngineServerApiBackend.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (C) 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GZ_SIM_COMPONENTS_RENDERENGINESERVERAPIBACKEND_HH_
#define GZ_SIM_COMPONENTS_RENDERENGINESERVERAPIBACKEND_HH_

#include <string>
#include <gz/sim/components/Factory.hh>
#include <gz/sim/components/Component.hh>
#include <gz/sim/components/Serialization.hh>
#include <gz/sim/config.hh>

namespace gz
{
namespace sim
{
// Inline bracket to help doxygen filtering.
inline namespace GZ_SIM_VERSION_NAMESPACE {
namespace components
{
/// \brief Holds the render engine server API backend name.
using RenderEngineServerApiBackend = Component<std::string,
class RenderEngineServerApiBackendTag, serializers::StringSerializer>;
GZ_SIM_REGISTER_COMPONENT(
"gz_sim_components.RenderEngineServerApiBackend",
RenderEngineServerApiBackend)
}
}
}
}

#endif
9 changes: 7 additions & 2 deletions include/gz/sim/gui/Gui.hh
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ namespace gui
/// \param[in] _waitGui Flag indicating whether the server waits until
/// it receives a world path from GUI.
/// \param[in] _renderEngine --render-engine-gui option
/// \param[in] _renderEngineGuiApiBackend --render-engine-gui-api-backend
/// \return -1 on failure, 0 on success
GZ_SIM_GUI_VISIBLE int runGui(int &_argc, char **_argv,
const char *_guiConfig, const char *_sdfFile, int _waitGui,
const char *_renderEngine = nullptr);
const char *_renderEngine = nullptr,
const char *_renderEngineApiBackend = nullptr);

/// \brief Create a Gazebo GUI application
/// \param[in] _argc Number of command line arguments (Used when running
Expand Down Expand Up @@ -110,12 +112,15 @@ namespace gui
/// \param[in] _waitGui True if the server is waiting for the GUI to decide on
/// a starting world.
/// \param[in] _renderEngine --render-engine-gui option
/// \param[in] _renderEngineGuiApiBackend --render-engine-gui-api-backend
/// option
/// \return Newly created application.
GZ_SIM_GUI_VISIBLE
std::unique_ptr<gz::gui::Application> createGui(
int &_argc, char **_argv, const char *_guiConfig,
const char *_defaultGuiConfig, bool _loadPluginsFromSdf,
const char *_sdfFile, int _waitGui, const char *_renderEngine = nullptr);
const char *_sdfFile, int _waitGui, const char *_renderEngine = nullptr,
const char *_renderEngineGuiApiBackend = nullptr );
} // namespace gui
} // namespace GZ_SIM_VERSION_NAMESPACE
} // namespace sim
Expand Down
9 changes: 9 additions & 0 deletions include/gz/sim/rendering/RenderUtil.hh
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ inline namespace GZ_SIM_VERSION_NAMESPACE {
/// \return Name of the rendering engine
public: std::string EngineName() const;

/// \brief Set the API backend the rendering engine will use
/// \param[in] _apiBackend Name of the api backend.
/// See --render-engine-server-api-backend for possible options
public: void SetApiBackend(const std::string &_apiBackend);

/// \brief Get the API backend the rendering engine used
/// \return Name of the API backend. May be empty.
public: std::string ApiBackend() const;

/// \brief Set the headless mode
/// \param[in] _headless Set to true to enable headless mode.
public: void SetHeadlessRendering(const bool &_headless);
Expand Down
5 changes: 5 additions & 0 deletions src/LevelManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "gz/sim/components/PhysicsEnginePlugin.hh"
#include "gz/sim/components/Pose.hh"
#include "gz/sim/components/RenderEngineGuiPlugin.hh"
#include "gz/sim/components/RenderEngineServerApiBackend.hh"
#include "gz/sim/components/RenderEngineServerHeadless.hh"
#include "gz/sim/components/RenderEngineServerPlugin.hh"
#include "gz/sim/components/Scene.hh"
Expand Down Expand Up @@ -150,6 +151,10 @@ void LevelManager::ReadLevelPerformerInfo()
components::RenderEngineServerPlugin(
this->runner->serverConfig.RenderEngineServer()));

this->runner->entityCompMgr.CreateComponent(this->worldEntity,
components::RenderEngineServerApiBackend(
this->runner->serverConfig.RenderEngineServerApiBackend()));

this->runner->entityCompMgr.CreateComponent(this->worldEntity,
components::RenderEngineServerHeadless(
this->runner->serverConfig.HeadlessRendering()));
Expand Down
35 changes: 35 additions & 0 deletions src/ServerConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,9 @@ class gz::sim::ServerConfigPrivate
resourceCache(_cfg->resourceCache),
physicsEngine(_cfg->physicsEngine),
renderEngineServer(_cfg->renderEngineServer),
renderEngineServerApiBackend(_cfg->renderEngineServerApiBackend),
renderEngineGui(_cfg->renderEngineGui),
renderEngineGuiApiBackend(_cfg->renderEngineGuiApiBackend),
plugins(_cfg->plugins),
networkRole(_cfg->networkRole),
networkSecondaries(_cfg->networkSecondaries),
Expand Down Expand Up @@ -307,10 +309,18 @@ class gz::sim::ServerConfigPrivate
/// will be used.
public: std::string renderEngineServer = "";

/// \brief String on which API to select.
/// See --render-engine-server-api-backend for possible options
public: std::string renderEngineServerApiBackend = "";

/// \brief File containing render engine gui plugin. If empty, OGRE2
/// will be used.
public: std::string renderEngineGui = "";

/// \brief String on which API to select.
/// See --render-engine-gui-api-backend for possible options
public: std::string renderEngineGuiApiBackend = "";

/// \brief List of plugins to load.
public: std::list<ServerConfig::PluginInfo> plugins;

Expand Down Expand Up @@ -592,6 +602,19 @@ void ServerConfig::SetRenderEngineServer(const std::string &_engine)
this->dataPtr->renderEngineServer = engine;
}

/////////////////////////////////////////////////
void ServerConfig::SetRenderEngineServerApiBackend(
const std::string &_apiBackend)
{
this->dataPtr->renderEngineServerApiBackend = _apiBackend;
}

/////////////////////////////////////////////////
const std::string &ServerConfig::RenderEngineServerApiBackend() const
{
return this->dataPtr->renderEngineServerApiBackend;
}

/////////////////////////////////////////////////
void ServerConfig::SetHeadlessRendering(const bool _headless)
{
Expand Down Expand Up @@ -626,6 +649,18 @@ void ServerConfig::SetRenderEngineGui(const std::string &_engine)
this->dataPtr->renderEngineGui = engine;
}

/////////////////////////////////////////////////
void ServerConfig::SetRenderEngineGuiApiBackend(const std::string &_apiBackend)
{
this->dataPtr->renderEngineGuiApiBackend = _apiBackend;
}

/////////////////////////////////////////////////
const std::string &ServerConfig::RenderEngineGuiApiBackend() const
{
return this->dataPtr->renderEngineGuiApiBackend;
}

/////////////////////////////////////////////////
void ServerConfig::AddPlugin(const ServerConfig::PluginInfo &_info)
{
Expand Down
52 changes: 46 additions & 6 deletions src/cmd/cmdsim.rb.in
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,36 @@ COMMANDS = { 'sim' =>
" Make sure custom plugins are in \n"\
" GZ_SIM_RENDER_ENGINE_PATH. \n"\
"\n"\
" --render-engine-api-backend [arg] \n"\
" API to use for both the Server & GUI. \n"\
" Possible values for ogre2: \n"\
" - opengl (default) \n"\
" - vulkan (beta) \n"\
" - metal (Apple only, default for Apple) \n"\
" Note: If using Vulkan in the GUI and gz-gui \n"\
" was built against Qt < 5.15.2, it may be very \n"\
" slow. \n"\
"\n"\
" --render-engine-gui [arg] Gazebo Rendering engine plugin to load for \n"\
" the GUI. Gazebo will use OGRE2 by default. \n"\
" (ogre2) \n"\
" Make sure custom plugins are in \n"\
" GZ_SIM_RENDER_ENGINE_PATH. \n"\
"\n"\
" --render-engine-gui-api-backend [arg] \n"\
" Same as --render-engine-api-backend but only \n"\
" for the GUI. \n"\
"\n"\
" --render-engine-server [arg] Gazebo Rendering engine plugin to load for \n"\
" the server. Gazebo will use OGRE2 by default. \n"\
" (ogre2) \n"\
" Make sure custom plugins are in \n"\
" GZ_SIM_RENDER_ENGINE_PATH. \n"\
"\n"\
" --render-engine-server-api-backend [arg] \n"\
" Same as --render-engine-api-backend but only \n"\
" for the server. \n"\
"\n"\
" --version Print Gazebo version information. \n"\
"\n"\
" -z [arg] Update rate in Hertz. \n"\
Expand Down Expand Up @@ -230,9 +248,11 @@ class Cmd
'gui_config' => '',
'physics_engine' => '',
'render_engine_gui' => '',
'render_engine_gui_api_backend' => '',
'render_engine_server' => '',
'wait_gui' => 1,
'render_engine_server_api_backend' => '',
'headless-rendering' => 0,
'wait_gui' => 1,
'seed' => 0
}

Expand Down Expand Up @@ -313,13 +333,23 @@ class Cmd
opts.on('--render-engine-gui [arg]', String) do |g|
options['render_engine_gui'] = g
end
opts.on('--render-engine-gui-api-backend [arg]', String) do |a|
options['render_engine_gui_api_backend'] = a
end
opts.on('--render-engine-server [arg]', String) do |k|
options['render_engine_server'] = k
end
opts.on('--render-engine-server-api-backend [arg]', String) do |a|
options['render_engine_server_api_backend'] = a
end
opts.on('--render-engine [arg]', String) do |f|
options['render_engine_gui'] = f
options['render_engine_server'] = f
end
opts.on('--render-engine-api-backend [arg]', String) do |a|
options['render_engine_gui_api_backend'] = a
options['render_engine_server_api_backend'] = a
end
opts.on('--version') do
options['version'] = '1'
end
Expand Down Expand Up @@ -465,10 +495,12 @@ Please use [GZ_SIM_RESOURCE_PATH] instead."
const char *, int, int, const char *,
int, int, int, const char *, const char *,
const char *, const char *, const char *,
const char *, const char *,
const char *, int, int, float, int)'

# Import the runGui function
Importer.extern 'int runGui(const char *, const char *, int, const char *)'
Importer.extern 'int runGui(const char *, const char *, int,
const char *, const char *)'

# If playback is specified, and the user has not specified a
# custom gui config, set the gui config to load the playback
Expand Down Expand Up @@ -504,7 +536,10 @@ See https://github.com/gazebosim/gz-sim/issues/168 for more info."
options['record-path'], options['record-resources'],
options['log-overwrite'], options['log-compress'],
options['playback'], options['physics_engine'],
options['render_engine_server'], options['render_engine_gui'],
options['render_engine_server'],
options['render_engine_server_api_backend'],
options['render_engine_gui'],
options['render_engine_gui_api_backend'],
options['file'], options['record-topics'].join(':'),
options['wait_gui'],
options['headless-rendering'], options['record-period'],
Expand All @@ -516,7 +551,8 @@ See https://github.com/gazebosim/gz-sim/issues/168 for more info."
Process.setpgid(0, 0)
Process.setproctitle('gz sim gui')
Importer.runGui(options['gui_config'], options['file'],
options['wait_gui'], options['render_engine_gui'])
options['wait_gui'], options['render_engine_gui'],
options['render_engine_gui_api_backend'])
end

Signal.trap("INT") {
Expand All @@ -543,7 +579,10 @@ See https://github.com/gazebosim/gz-sim/issues/168 for more info."
options['record-path'], options['record-resources'],
options['log-overwrite'], options['log-compress'],
options['playback'], options['physics_engine'],
options['render_engine_server'], options['render_engine_gui'],
options['render_engine_server'],
options['render_engine_server_api_backend'],
options['render_engine_gui'],
options['render_engine_gui_api_backend'],
options['file'], options['record-topics'].join(':'),
options['wait_gui'], options['headless-rendering'],
options['record-period'], options['seed'])
Expand All @@ -557,7 +596,8 @@ See https://github.com/gazebosim/gz-sim/issues/168 for more info."

ENV['RMT_PORT'] = '1501'
Importer.runGui(options['gui_config'], options['file'],
options['wait_gui'], options['render_engine_gui'])
options['wait_gui'], options['render_engine_gui'],
options['render_engine_gui_api_backend'])
end
rescue
puts "Library error: Problem running [#{options['command']}]() "\
Expand Down
15 changes: 8 additions & 7 deletions src/gui/Gui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,15 @@ std::unique_ptr<gz::gui::Application> createGui(
const char *_renderEngine)
{
return createGui(_argc, _argv, _guiConfig, _defaultGuiConfig,
_loadPluginsFromSdf, nullptr, 0, _renderEngine);
_loadPluginsFromSdf, nullptr, 0, _renderEngine, nullptr);
}

//////////////////////////////////////////////////
std::unique_ptr<gz::gui::Application> createGui(
int &_argc, char **_argv, const char *_guiConfig,
const char *_defaultGuiConfig, bool _loadPluginsFromSdf,
const char *_sdfFile, int _waitGui, const char *_renderEngine)
int &_argc, char **_argv, const char *_guiConfig,
const char *_defaultGuiConfig, bool _loadPluginsFromSdf, const char *_sdfFile,
int _waitGui, const char *_renderEngine,
const char *_renderEngineGuiApiBackend)
{
gz::common::SignalHandler sigHandler;
bool sigKilled = false;
Expand Down Expand Up @@ -274,7 +275,7 @@ std::unique_ptr<gz::gui::Application> createGui(

// Launch main window
auto app = std::make_unique<gz::gui::Application>(
_argc, _argv, gz::gui::WindowType::kMainWindow);
_argc, _argv, gz::gui::WindowType::kMainWindow, _renderEngineGuiApiBackend);

app->AddPluginPath(GZ_SIM_GUI_PLUGIN_INSTALL_DIR);

Expand Down Expand Up @@ -507,10 +508,10 @@ int runGui(int &_argc, char **_argv, const char *_guiConfig,
//////////////////////////////////////////////////
int runGui(int &_argc, char **_argv,
const char *_guiConfig, const char *_sdfFile, int _waitGui,
const char *_renderEngine)
const char *_renderEngine, const char *_renderEngineGuiApiBackend)
{
auto app = sim::gui::createGui(_argc, _argv, _guiConfig, nullptr, true,
_sdfFile, _waitGui, _renderEngine);
_sdfFile, _waitGui, _renderEngine, _renderEngineGuiApiBackend);
if (nullptr != app)
{
// Run main window.
Expand Down
Loading