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

Conversation

darksylinc
Copy link
Contributor

@darksylinc darksylinc commented Sep 25, 2022

🎉 New feature

Order in which PRs must be merged

  1. Add necessary headers for Vulkan QML GUI backend gz-rendering#706
  2. Add fallback rendering for other APIs gz-gui#357
    • or optionally, merge this one as part of the next one aka PR 467, which includes it
  3. Add Vulkan QML backend gz-gui#467
  4. This PR.

Summary

This PR adds the following CLI options:

  • --render-engine-gui-api-backend [arg]
  • --render-engine-server-api-backend [arg]
  • --render-engine-api-backend [arg]

The default is metal in Apple systems, and opengl in the rest; and the other option being vulkan.

This setting gets forwarded to the other components so it actually gets applied.

Test it

After merging all dependent PRs, run:

gz help sim

For help with the new CLI options

To test everything:

gz sim segmentation_camera.sdf -v4 --render-engine-api-backend vulkan

Server only:

gz sim segmentation_camera.sdf -v4 -s -r --render-engine-server-api-backend vulkan

GUI only:

gz sim -v4 -g --render-engine-gui-api-backend vulkan

And see the Ogre.log to check Vulkan is being used.

I use segmentation_camera.sdf because it forces the server to render.

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

@azeey
Copy link
Contributor

azeey commented Nov 21, 2022

Needs version bump

@darksylinc
Copy link
Contributor Author

Rebased!

Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar>
Signed-off-by: Matias N. Goldberg <dark_sylinc@yahoo.com.ar>
@iche033
Copy link
Contributor

iche033 commented Dec 28, 2022

rebased.

{
serverConfig.SetRenderEngineServerApiBackend(_renderEngineServerApiBackend);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a warning about unused _renderEngineGuiApiBackend variable

add a check _renderEngineGuiApiBackend?

+  if (_renderEngineGuiApiBackend != nullptr)
+  {
+    serverConfig.SetRenderEngineGuiApiBackend(_renderEngineGuiApiBackend);
+  }
+

seems to work fine without these changes though

Copy link
Contributor Author

@darksylinc darksylinc Dec 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is what I remember, then what happened is that I got confused.

If I understood correctly it appears that Gazebo has two ways of setting data from Server to Gui:

  1. Via CLI when launching the gui (e.g. gz sim -g --render-engine-gui-api-backend vulkan)
  2. Via GUI asking server what was the Server launched with (e.g. gz sim -s --render-engine-gui-api-backend vulkan and then gz sim -g)
    • It doesn't look like this codepath works anymore
    • I could be wrong

The reason being is that _renderEngineGui is being asked for (I didn't write that code) and is later read via message passing by the GUI from server; but from the looks of it, this path is broken or deprecated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason being is that _renderEngineGui is being asked for (I didn't write that code) and is later read via message passing by the GUI from server; but from the looks of it, this path is broken or deprecated.

likely broken. I added the check for _renderEngineGuiApiBackend in 8a19054 and will need to fix this issue later.

else if (this->dataPtr->apiBackend == "metal")
{
params["metal"] = "1";
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set params["metal"] = "1" if this->dataPtr->apiBackend is empty string on APPLE?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly, no.

Because the higher level code should insist on using "metal" (and by higher level, I mean MinimalScene).

If the string is empty that means something went wrong with MinimalScene in gz-gui; and gz-gui will initialize Qt with OpenGL instead of Metal. See GzRenderer::SetGraphicsAPI & RenderThread::SetGraphicsAPI.

Qt must be initialized with Metal for this to work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I see that the gui does the right thing and set the api backend to metal. I added a change in the sensors system to do the same thing in 5d9a5fc

Signed-off-by: Ian Chen <ichen@openrobotics.org>
Signed-off-by: Ian Chen <ichen@openrobotics.org>
Signed-off-by: Ian Chen <ichen@openrobotics.org>
@iche033
Copy link
Contributor

iche033 commented Jan 5, 2023

@osrf-jenkins run tests please

@codecov
Copy link

codecov bot commented Jan 6, 2023

Codecov Report

Merging #1735 (4595e0c) into main (5fe83a3) will decrease coverage by 0.01%.
The diff coverage is 65.30%.

@@            Coverage Diff             @@
##             main    #1735      +/-   ##
==========================================
- Coverage   64.49%   64.47%   -0.02%     
==========================================
  Files         341      342       +1     
  Lines       27098    27141      +43     
==========================================
+ Hits        17477    17500      +23     
- Misses       9621     9641      +20     
Impacted Files Coverage Δ
include/gz/sim/ServerConfig.hh 100.00% <ø> (ø)
include/gz/sim/rendering/RenderUtil.hh 100.00% <ø> (ø)
.../plugins/component_inspector/ComponentInspector.cc 5.42% <0.00%> (-0.05%) ⬇️
src/rendering/RenderUtil.cc 39.66% <58.33%> (+0.10%) ⬆️
src/gui/Gui.cc 68.22% <66.66%> (ø)
src/gz.cc 66.48% <66.66%> (+0.72%) ⬆️
src/systems/sensors/Sensors.cc 63.07% <71.42%> (+0.18%) ⬆️
src/ServerConfig.cc 83.15% <83.33%> (+<0.01%) ⬆️
.../gz/sim/components/RenderEngineServerApiBackend.hh 100.00% <100.00%> (ø)
src/LevelManager.cc 89.27% <100.00%> (+0.08%) ⬆️
... and 1 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@iche033
Copy link
Contributor

iche033 commented Jan 13, 2023

@osrf-jenkins run tests please

@iche033 iche033 merged commit 31846cc into gazebosim:main Jan 14, 2023
@iche033 iche033 added the 🎵 harmonic Gazebo Harmonic label Feb 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎵 harmonic Gazebo Harmonic needs upstream release Blocked by a release of an upstream library
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants