-
Notifications
You must be signed in to change notification settings - Fork 44
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 Metal support to MinimalScene and Qt Application #323
Add Metal support to MinimalScene and Qt Application #323
Conversation
@ahcorde the latest changes should fix the OpenGL context issue. The renderer needs to be quite careful to ensure the OpenGL context is associated with the correct thread at the correct time. Both Metal and OpenGL should now be able to use the "threaded" OSG render engine - which will improve performance. Here's my take on the thread affinity Threads
Initialisation
As there are a lot of small changes and a couple of GitHub edits which are missing signoff I'm going to rebase and squash to clean everything up. |
b96632f
to
c91214a
Compare
I'm testing this on Ubuntu with OpenGL. It working mostly fine. However, when I tried running ign-gazebo with backtrace
Do you get this issue? |
Seeing something similar with Metal in that example (on the server side) - let me take a look.
I'm a bit stuck for testing on Ubuntu at the moment - I had been testing using a VMware Fusion Ubuntu VM which had worked well with Edifice (which actually runs with hardware GPU acceleration enabled on the VM). But with ogre2.2 dropping OpenGL < 4.2 support that no longer works and software (llvmpipe) rendering is not functioning properly for Fortress and above either. Update Looks like there are some OpenGL calls in //////////////////////////////////////////////////
void Ogre2DepthCamera::Render()
{
// GL_DEPTH_CLAMP was disabled in later version of ogre2.2
// however our shaders rely on clamped values so enable it for this sensor
#ifndef _WIN32
glEnable(GL_DEPTH_CLAMP);
#endif and similar blocks for other camera sensors. The PR does change how the OpenGL context is initialised and moved - so it could be that. |
Disabling the
fixes the issue I was seeing with Will need a PR for Still looking into what might be going on with OpenGL... |
ah yes. Here is a PR to fix the issue: gazebosim/gz-rendering#509
hmm ok I'll play around a bit and see what's causing the issue |
Hi @iche033 - I've just been through updating all my dependencies on the latest for garden and I think all the upstream changes are in for this PR now. Question: the issue noted above re. sensors has to do with the accompanying PR in |
we can get this in first since it looks like the issue is mainly in ign-gazebo. I'll take another look at the changes |
Thank you, that would be great. Is there an update to the ogre2.2 version required for garden? I've noticed this exception after pulling changes into rendering, gui, sensors and gazebo. libc++abi: terminating with uncaught exception of type Ogre::InvalidParametersException: OGRE EXCEPTION(2:InvalidParametersException): Named constants have not been initialised, perhaps a compile error. in GpuProgramParameters::_findNamedConstantDefinition at /Users/rhys/Code/ogre/ogre-next2.2/OgreMain/src/OgreGpuProgramParams.cpp (line 2210)
Stack trace (most recent call last) in thread 123145547399168:
#2 Object "libsystem_platform.dylib", at 0x7fff204f9d7c, in _sigtramp + 28
#1 Object "libignition-tools-backward.dylib", at 0x10da90fad, in backward::SignalHandling::sig_handler(int, __siginfo*, void*) + 13
#0 Object "libignition-tools-backward.dylib", at 0x10da91016, in backward::SignalHandling::handleSignal(int, __siginfo*, void*) + 70
zsh: abort ign gazebo -v4 -r -s src/ign-gazebo/examples/worlds/depth_camera_sensor.sdf At first I though it might be an Xcode version, as I was linking against the There is also a LOD type issue that has crept in which I'm trying to find the cause of. gazebo_rendering_lod_2022-01.mov |
Thanks @scpeters, I think that patch was intended to go in osrf/homebrew-simulation#1645 but was accidentally missed. That should complete all the upstream dependencies for this PR. |
Great to know it's running on the new macbooks. I build on macOS leaving SIP enabled using the following build command: colcon build --merge-install --cmake-args \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_MACOSX_RPATH=FALSE \
-DCMAKE_INSTALL_NAME_DIR=$(pwd)/install/lib The binaries are not relocatable, but that isn't so much of an issue. Are the other RPATH patches to deal with the different location that brew installs to on |
yeah I saw that you mentioned the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've managed to get this working on my Mac laptop. Is it possible to automatically set the graphics_api
parameter to metal
on macOS? I don't think we should require users to modify their gui.config
file in order to use it.
<graphics_api>metal</graphics_api>
- Add list of available graphics APIs - Set default graphics API to 'metal' if the platform is Apple, otherwise use 'opengl'. Signed-off-by: Rhys Mainwaring <[email protected]>
I've changed the default graphics_api in MinimalScene to be platform specific. It can still be customised if needed (in case OpenGL is re-enabled on macOS or other choices such as Vulkan become available). An alternative would be to provide a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I only have some suggestions related with the style
This PR likely overlaps / conflicts with mine (#357) but that's not a problem. This one should be higher priority and I'll fix the problems in my PR after this one is merged. |
Thanks @ahcorde, your suggestions have been adopted. |
Thank you for your great work, I will test this locally again and I will merge it |
Last 2 commits are not signed, do you mind to fix it ? |
I'm able to run Here you can find the backtrace:
```
Stack trace (most recent call last) in thread 123145463980032:
#26 Object "libsystem_pthread.dylib", at 0x7fff208da8fc, in _pthread_start + 224
#25 Object "libignition-gazebo7-sensors-system.", at 0x12020ff85, in void* std::__1::__thread_proxy >, void (ignition::gazebo::v7::systems::SensorsPrivate::*)(), ignition::gazebo::v7::systems::SensorsPrivate*> >(void*) + 101
#24 Object "libignition-gazebo7-sensors-system.", at 0x1202107ae, in void std::__1::__thread_execute >, void (ignition::gazebo::v7::systems::SensorsPrivate::*)(), ignition::gazebo::v7::systems::SensorsPrivate*, 2ul>(std::__1::tuple >, void (ignition::gazebo::v7::systems::SensorsPrivate::*)(), ignition::gazebo::v7::systems::SensorsPrivate*>&, std::__1::__tuple_indices<2ul>) + 62
#23 Object "libignition-gazebo7-sensors-system.", at 0x12021086e, in decltype(*(std::__1::forward(fp0)).*fp()) std::__1::__invoke(void (ignition::gazebo::v7::systems::SensorsPrivate::*&&)(), ignition::gazebo::v7::systems::SensorsPrivate*&&) + 110
#22 Object "libignition-gazebo7-sensors-system.", at 0x1201d36eb, in ignition::gazebo::v7::systems::SensorsPrivate::RenderThread() + 187
#21 Object "libignition-gazebo7-sensors-system.", at 0x1201d2b8a, in ignition::gazebo::v7::systems::SensorsPrivate::RunOnce() + 202
#20 Object "libignition-gazebo7-rendering.7.0.0", at 0x12066d211, in ignition::gazebo::v7::RenderUtil::Update() + 4273
#19 Object "libignition-gazebo7-rendering.7.0.0", at 0x1209df279, in ignition::gazebo::v7::SceneManager::CreateVisual(unsigned long long, sdf::v13::Visual const&, unsigned long long) + 2121
#18 Object "libignition-gazebo7-rendering.7.0.0", at 0x1209e0882, in ignition::gazebo::v7::SceneManager::LoadGeometry(sdf::v13::Geometry const&, ignition::math::v7::Vector3&, ignition::math::v7::Pose3&) + 1826
#17 Object "libignition-rendering7.7.0.0~pre1.d", at 0x1234a06e7, in ignition::rendering::v7::BaseScene::CreatePlane() + 151
#16 Object "libignition-rendering7-ogre.7.0.0~p", at 0x1250e5fb2, in ignition::rendering::v7::OgreScene::CreatePlaneImpl(unsigned int, std::__1::basic_string, std::__1::allocator > const&) + 114
#15 Object "libignition-rendering7-ogre.7.0.0~p", at 0x1250e6171, in ignition::rendering::v7::OgreScene::CreateMeshImpl(unsigned int, std::__1::basic_string, std::__1::allocator > const&, std::__1::basic_string, std::__1::allocator > const&) + 113
#14 Object "libignition-rendering7-ogre.7.0.0~p", at 0x1250e6207, in ignition::rendering::v7::OgreScene::CreateMeshImpl(unsigned int, std::__1::basic_string, std::__1::allocator > const&, ignition::rendering::v7::MeshDescriptor const&) + 87
#13 Object "libignition-rendering7-ogre.7.0.0~p", at 0x125050b3f, in ignition::rendering::v7::OgreMeshFactory::Create(ignition::rendering::v7::MeshDescriptor const&) + 175
#12 Object "libignition-rendering7-ogre.7.0.0~p", at 0x125051062, in ignition::rendering::v7::OgreMeshFactory::OgreEntity(ignition::rendering::v7::MeshDescriptor const&) + 34
#11 Object "libignition-rendering7-ogre.7.0.0~p", at 0x1250511a5, in ignition::rendering::v7::OgreMeshFactory::Load(ignition::rendering::v7::MeshDescriptor const&) + 101
#10 Object "libignition-rendering7-ogre.7.0.0~p", at 0x125053052, in ignition::rendering::v7::OgreMeshFactory::LoadImpl(ignition::rendering::v7::MeshDescriptor const&) + 6418
#9 Object "RenderSystem_GL.1.9.0.dylib", at 0x126fd984e, in Ogre::HardwareBufferManager::createVertexBuffer(unsigned long, unsigned long, Ogre::HardwareBuffer::Usage, bool) + 22
#8 Object "RenderSystem_GL.1.9.0.dylib", at 0x126fcaa58, in Ogre::GLHardwareBufferManagerBase::createVertexBuffer(unsigned long, unsigned long, Ogre::HardwareBuffer::Usage, bool) + 80
#7 Object "RenderSystem_GL.1.9.0.dylib", at 0x126fcf0ac, in Ogre::GLHardwareVertexBuffer::GLHardwareVertexBuffer(Ogre::HardwareBufferManagerBase*, unsigned long, unsigned long, Ogre::HardwareBuffer::Usage, bool) + 64
#6 Object "libGL.dylib", at 0x7fff6bff1e67, in glGenBuffersARB + 19
#5 Object "libsystem_platform.dylib", at 0x7fff2091fd7c, in _sigtramp + 28
#4 Object "libignition-tools-backward.dylib", at 0x10ac60422, in backward::SignalHandling::sig_handler(int, __siginfo*, void*) + 34
#3 Object "libignition-tools-backward.dylib", at 0x10ac6066a, in backward::SignalHandling::handleSignal(int, __siginfo*, void*) + 106
#2 Object "libignition-tools-backward.dylib", at 0x10ac60788, in backward::StackTraceImpl::load_from(void*, unsigned long, void*, void*) + 56
#1 Object "libignition-tools-backward.dylib", at 0x10ac608e1, in backward::StackTraceImpl::load_here(unsigned long, void*, void*) + 129
#0 Object "libignition-tools-backward.dylib", at 0x10ac620f0, in unsigned long backward::details::unwind::callback>(backward::StackTraceImpl::callback, unsigned long) + 32
Segmentation fault: 11
```
|
my bad, I forgot to use only ogre2. All good! |
Co-authored-by: Alejandro Hernández Cordero <[email protected]> Signed-off-by: Rhys Mainwaring <[email protected]>
Co-authored-by: Alejandro Hernández Cordero <[email protected]> Signed-off-by: Rhys Mainwaring <[email protected]>
d5cc37e
to
f22261c
Compare
Should be good now, btw is there an automated way to add the sign-off when committing from the review page in GitHub? |
sadly no, I copy and paste it into the commit message when using the web UI |
🎉 New feature
Partially completes #314
Summary
This PR allows MinimalScene to use either OpenGL or Metal render systems.
Approach
Additional classes are introduced to the MinimalScene plugin folder to abstract the render hardware interfaces. These classes are declared in
MinimalSceneRhi.hh
:IgnCameraTextureRhi
RenderThreadRhi
TextureNodeRhi
The suffix abbreviation
Rhi
for render hardware interface is borrowed from Qt.Implementations for OpenGL and Metal are declared in:
MinimalSceneRhiOpenGL.hh
MinimalSceneRhiMetal.hh
The existing classes in
MinimalScene.hh
are modified to forward rendering calls to the (virtual) render hardware interface functions. There are some ABI breaking changes required in order to handle both OpenGL and Metal GPU texture objects.We used forwarding rather than abstracting and subclassing the existing classes in
MinimalScene.hh
as it does not require introducing and registering additional Qt objects.Platform configuration
Application.cc
is modified to support either OpenGL or Metal. If the platform is Metal the graphics API is selected to be Metal, otherwise it is OpenGL.Test it
Still to do - provide a standalone test in ign-gui for Metal support.
The feature can be tested using ignition gazebo by also building the PR that adds Metal support to Gazebo:
Note: this PR does not provide a Metal version of the gamma adjustment (to follow). As a result the scene looks darker than the OpenGL version. If you want to lighten the scene you can cherry-pick this commit into ign-gui.
A working document describing how to build Ignition for Metal support is here: https://github.com/srmainwaring/ign-rendering/wiki. The main change to note is that the MinimalScene plugin element to override the default graphics interface is now
<graphics_api>metal</graphics_api>
Tests
Most of the tests are disabled on macOS. The tests passed on an Ubuntu 20.04 VM running the llvmpipe driver (software rasterizer).
Code check
There is a code check failure concerning the use of
static_cast
vsreinterpret_cast
inMinimalSceneRhi.cc
. The code has been updated but the CI test does not appear to be using latest version of the code?Checklist
codecheck
passed (See contributing)Note to maintainers: Remember to use Squash-Merge