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 necessary headers for Vulkan QML GUI backend #706

Merged
merged 7 commits into from
Oct 15, 2022

Conversation

darksylinc
Copy link
Contributor

@darksylinc darksylinc commented Aug 14, 2022

🎉 New feature

No ticket is associated with this feature.

Order in which PRs must be merged

  1. This PR.
  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. Add CLI to switch to Vulkan & Metal backends gz-sim#1735

Summary

The GUI component needs to send the Vulkan device to Rendering component, which in turns sends it to OgreNext. There were various possible solutions:

  1. gz-gui gets linked against OgreNext
  2. gz-rendering gets linked against Qt
  3. The solution in this PR, where a few structs are added to get passed around and perform Qt -> OgreNext conversions while both components are reasonably isolated from each other.

This PR adds the following structs:

  • GzVulkanExternalInstance (mirrors Ogre::VulkanExternalInstance without depending on OgreNext)
  • GzVulkanExternalDevice (mirrors Ogre::VulkanExternalDevice without depending on OgreNext)

These structs are filled by gz-gui and passed to gz-rendering via "external_instance" and "external_device".

The new code is guarded using #ifdef OGRE_BUILD_RENDERSYSTEM_VULKAN because if OgreNext wasn't built with Vulkan support, then it is extremely likely the Vulkan SDK isn't present (i.e. Apple systems) which means including RenderEngineVulkanExternalDeviceStructs.hh will cause errors.

Test it

To test this code we need gazebosim/gz-gui#467 however we could add test coverage by creating a Vulkan Device in a test and testing this interface.

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.

@codecov
Copy link

codecov bot commented Aug 14, 2022

Codecov Report

Merging #706 (5639156) into main (581aaab) will decrease coverage by 0.10%.
The diff coverage is 28.12%.

@@            Coverage Diff             @@
##             main     #706      +/-   ##
==========================================
- Coverage   74.18%   74.07%   -0.11%     
==========================================
  Files         159      159              
  Lines       14381    14408      +27     
==========================================
+ Hits        10668    10673       +5     
- Misses       3713     3735      +22     
Impacted Files Coverage Δ
include/gz/rendering/Camera.hh 100.00% <ø> (ø)
include/gz/rendering/RenderTarget.hh 100.00% <ø> (ø)
ogre2/src/Ogre2Camera.cc 84.57% <0.00%> (-1.98%) ⬇️
ogre2/src/Ogre2RenderTarget.cc 81.17% <14.28%> (-2.20%) ⬇️
include/gz/rendering/base/BaseCamera.hh 66.66% <33.33%> (-0.94%) ⬇️
include/gz/rendering/base/BaseRenderTarget.hh 79.12% <50.00%> (-1.57%) ⬇️
ogre2/src/Ogre2RenderEngine.cc 76.67% <75.00%> (+0.09%) ⬆️

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

@iche033 iche033 changed the base branch from main to gz-rendering7 August 25, 2022 00:10
@iche033 iche033 changed the base branch from gz-rendering7 to main August 25, 2022 00:11
@iche033
Copy link
Contributor

iche033 commented Aug 25, 2022

we could target / backport this to gz-rendering7 in case gazebosim/gz-gui#467 works on Garden

Needed by Vulkan QML integration

Signed-off-by: Matias N. Goldberg <[email protected]>
Needed by QML Vulkan integration.

Signed-off-by: Matias N. Goldberg <[email protected]>
@darksylinc darksylinc force-pushed the qml-vulkan-rebased-main branch from 60c1d9e to 15137d2 Compare September 24, 2022 22:35
Copy link
Contributor

@iche033 iche033 left a comment

Choose a reason for hiding this comment

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

changes look fine. Just need to fix Jammy build by adding vulkan dependency

Signed-off-by: Matias N. Goldberg <[email protected]>
@iche033
Copy link
Contributor

iche033 commented Oct 10, 2022

Can you add libvulkan-dev in the jammy apt packages file to see if it fixes Jammy CI build?

Signed-off-by: Matias N. Goldberg <[email protected]>
@darksylinc
Copy link
Contributor Author

OK I just did. Let's cross fingers 🤞

@iche033
Copy link
Contributor

iche033 commented Oct 13, 2022

the jammy build got further. Now it complains about the 2 macros in this block.

build error here
  /github/workspace/ogre2/src/Ogre2RenderEngine.cc:47:59: error: expected identifier before numeric constant
     47 | #    define VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_KHR 0x00200000
        |                                                           ^~~~~~~~~~
  /github/workspace/ogre2/src/Ogre2RenderEngine.cc:47:59: error: expected '}' before numeric constant
  In file included from /usr/include/OGRE-2.3/RenderSystems/Vulkan/OgreVulkanQueue.h:37,
                   from /usr/include/OGRE-2.3/RenderSystems/Vulkan/OgreVulkanDevice.h:34,
                   from /github/workspace/ogre2/src/Ogre2RenderEngine.cc:51:
  /usr/include/vulkan/vulkan_core.h:1941:31: note: to match this '{'
   1941 | typedef enum VkAccessFlagBits {
        |                               ^
  /github/workspace/ogre2/src/Ogre2RenderEngine.cc:47:59: error: expected unqualified-id before numeric constant
     47 | #    define VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_KHR 0x00200000
        |                                                           ^~~~~~~~~~
  In file included from /usr/include/OGRE-2.3/RenderSystems/Vulkan/OgreVulkanQueue.h:37,
                   from /usr/include/OGRE-2.3/RenderSystems/Vulkan/OgreVulkanDevice.h:34,
                   from /github/workspace/ogre2/src/Ogre2RenderEngine.cc:51:
  /usr/include/vulkan/vulkan_core.h:1976:3: error: declaration does not declare anything [-fpermissive]
   1976 | } VkAccessFlagBits;
        |   ^~~~~~~~~~~~~~~~
  In file included from /usr/include/OGRE-2.3/RenderSystems/Vulkan/OgreVulkanQueue.h:37,
                   from /usr/include/OGRE-2.3/RenderSystems/Vulkan/OgreVulkanDevice.h:34,
                   from /github/workspace/ogre2/src/Ogre2RenderEngine.cc:51:
  /usr/include/vulkan/vulkan_core.h:14312:1: error: expected declaration before '}' token
  14312 | }
        | ^
  In file included from /github/workspace/ogre2/src/Ogre2RenderEngine.cc:51:
  /usr/include/OGRE-2.3/RenderSystems/Vulkan/OgreVulkanDevice.h:172:59: error: 'VK_ACCESS_SHADING_RATE_IMAGE_READ_BIT_NV' was not declared in this scope; did you mean 'VK_ACCESS_2_SHADING_RATE_IMAGE_READ_BIT_NV'?
    172 |           VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_KHR | VK_ACCESS_SHADING_RATE_IMAGE_READ_BIT_NV |
        |                                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        |                                                           VK_ACCESS_2_SHADING_RATE_IMAGE_READ_BIT_NV
  /usr/include/OGRE-2.3/RenderSystems/Vulkan/OgreVulkanDevice.h:173:11: error: 'VK_ACCESS_FRAGMENT_DENSITY_MAP_READ_BIT_EXT' was not declared in this scope; did you mean 'VK_ACCESS_2_FRAGMENT_DENSITY_MAP_READ_BIT_EXT'?
    173 |           VK_ACCESS_FRAGMENT_DENSITY_MAP_READ_BIT_EXT | VK_ACCESS_COMMAND_PREPROCESS_READ_BIT_NV );
        |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        |           VK_ACCESS_2_FRAGMENT_DENSITY_MAP_READ_BIT_EXT
  make[2]: *** [ogre2/src/CMakeFiles/gz-rendering8-ogre2.dir/build.make:594: ogre2/src/CMakeFiles/gz-rendering8-ogre2.dir/Ogre2RenderEngine.cc.o] Error 1

I reproduced it on Jammy. If I comment those two #defines, it builds though.

Signed-off-by: Matias N. Goldberg <[email protected]>
@darksylinc
Copy link
Contributor Author

darksylinc commented Oct 13, 2022

Ahhhhh!!! That error is so annoying.

The #define VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_KHR is needed as a workaround because the flag is not defined in the headers included by focal, but jammy uses a newer version.

I think the problem is that # ifndef VK_NV_device_generated_commands and #ifndef VK_NV_ray_tracing guards are failing because vulkan/vulkan_core.h had not been included yet.

I just pushed a fix. Let's hope that fixes it.

Copy link
Contributor

@iche033 iche033 left a comment

Choose a reason for hiding this comment

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

CI is green!

@iche033 iche033 merged commit b197260 into gazebosim:main Oct 15, 2022
@iche033 iche033 mentioned this pull request Dec 9, 2022
8 tasks
@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
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants