Skip to content

Commit

Permalink
Add check for vulkan support in rendering (#589)
Browse files Browse the repository at this point in the history
---------

Signed-off-by: Ian Chen <[email protected]>
  • Loading branch information
iche033 authored Oct 18, 2023
1 parent 872222a commit 9b1b7b0
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions src/plugins/minimal_scene/MinimalScene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
#include <gz/math/Vector2.hh>
#include <gz/math/Vector3.hh>
#include <gz/plugin/Register.hh>
#include <gz/rendering/config.hh>
#include <gz/rendering/Camera.hh>
#include <gz/rendering/RayQuery.hh>
#include <gz/rendering/RenderEngine.hh>
#include <gz/rendering/RenderEngineVulkanExternalDeviceStructs.hh>
#include <gz/rendering/RenderingIface.hh>
#include <gz/rendering/Scene.hh>
#include <gz/rendering/Utils.hh>
Expand All @@ -52,8 +52,10 @@
#include "gz/gui/Helpers.hh"
#include "gz/gui/MainWindow.hh"

#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan)
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan) && \
defined(GZ_RENDERING_HAVE_VULKAN)
# include <QVulkanInstance>
# include <gz/rendering/RenderEngineVulkanExternalDeviceStructs.hh>
#endif

Q_DECLARE_METATYPE(gz::gui::plugins::RenderSync*)
Expand Down Expand Up @@ -584,7 +586,8 @@ rendering::CameraPtr GzRenderer::Camera()
return this->dataPtr->camera;
}

#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan)
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan) && \
defined(GZ_RENDERING_HAVE_VULKAN)
/////////////////////////////////////////////////
/// \brief fillQtInstanceExtensionsToOgre
/// Extract Vulkan Instance extension information to be sent to OgreNext
Expand Down Expand Up @@ -677,7 +680,8 @@ std::string GzRenderer::Initialize(RenderThreadRhi &_rhi)

this->dataPtr->rhiParams["winID"] = std::to_string(quickWindow->winId());

#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan)
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan) && \
defined(GZ_RENDERING_HAVE_VULKAN)
// externalInstance & externalDevice MUST be declared at this scope
// because we save their stack addresses into this->dataPtr->rhiParams
// and must be alive until rendering::engine() returns.
Expand Down Expand Up @@ -805,7 +809,8 @@ void GzRenderer::SetGraphicsAPI(const rendering::GraphicsAPI &_graphicsAPI)
{
gzdbg << "Creating gz-rendering interface for Vulkan" << std::endl;
this->dataPtr->rhiParams["vulkan"] = "1";
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan)
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan) && \
defined(GZ_RENDERING_HAVE_VULKAN)
this->dataPtr->rhi = std::make_unique<GzCameraTextureRhiVulkan>();
#else
this->dataPtr->rhi = std::make_unique<GzCameraTextureRhiOpenGL>();
Expand Down Expand Up @@ -973,7 +978,8 @@ void RenderThread::SetGraphicsAPI(const rendering::GraphicsAPI &_graphicsAPI)

// Create the render interface
if (_graphicsAPI == rendering::GraphicsAPI::OPENGL
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan)
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan) && \
defined(GZ_RENDERING_HAVE_VULKAN)
// Use fallback (GPU -> CPU -> GPU)
|| _graphicsAPI == rendering::GraphicsAPI::VULKAN
#endif
Expand All @@ -982,7 +988,8 @@ void RenderThread::SetGraphicsAPI(const rendering::GraphicsAPI &_graphicsAPI)
gzdbg << "Creating render thread interface for OpenGL" << std::endl;
this->rhi = std::make_unique<RenderThreadRhiOpenGL>(&this->gzRenderer);
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan)
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan) && \
defined(GZ_RENDERING_HAVE_VULKAN)
else if (_graphicsAPI == rendering::GraphicsAPI::VULKAN)
{
gzdbg << "Creating render thread interface for Vulkan" << std::endl;
Expand Down Expand Up @@ -1013,15 +1020,17 @@ std::string RenderThread::Initialize()
TextureNode::TextureNode(QQuickWindow *_window, RenderSync &_renderSync,
const rendering::GraphicsAPI &_graphicsAPI,
rendering::CameraPtr &
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan)
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan) && \
defined(GZ_RENDERING_HAVE_VULKAN)
_camera
#endif
) :
renderSync(_renderSync),
window(_window)
{
if (_graphicsAPI == rendering::GraphicsAPI::OPENGL
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan)
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan) && \
defined(GZ_RENDERING_HAVE_VULKAN)
// Use fallback (GPU -> CPU -> GPU)
|| _graphicsAPI == rendering::GraphicsAPI::VULKAN
#endif
Expand All @@ -1030,7 +1039,8 @@ TextureNode::TextureNode(QQuickWindow *_window, RenderSync &_renderSync,
gzdbg << "Creating texture node render interface for OpenGL" << std::endl;
this->rhi = std::make_unique<TextureNodeRhiOpenGL>(_window);
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan)
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan) && \
defined(GZ_RENDERING_HAVE_VULKAN)
else if (_graphicsAPI == rendering::GraphicsAPI::VULKAN)
{
gzdbg << "Creating texture node render interface for Vulkan" << std::endl;
Expand Down Expand Up @@ -1137,7 +1147,8 @@ void RenderWindowItem::StopRendering()
void RenderWindowItem::Ready()
{
if (this->dataPtr->graphicsAPI == rendering::GraphicsAPI::OPENGL
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan)
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan) && \
defined(GZ_RENDERING_HAVE_VULKAN)
// Use fallback (GPU -> CPU -> GPU)
|| this->dataPtr->graphicsAPI == rendering::GraphicsAPI::VULKAN
#endif
Expand All @@ -1156,7 +1167,8 @@ void RenderWindowItem::Ready()
}

if (this->dataPtr->graphicsAPI == rendering::GraphicsAPI::OPENGL
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan)
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan) && \
defined(GZ_RENDERING_HAVE_VULKAN)
// Use fallback (GPU -> CPU -> GPU)
|| this->dataPtr->graphicsAPI == rendering::GraphicsAPI::VULKAN
#endif
Expand Down Expand Up @@ -1204,7 +1216,8 @@ QSGNode *RenderWindowItem::updatePaintNode(QSGNode *_node,
this->dataPtr->graphicsAPI);

if (this->dataPtr->graphicsAPI == rendering::GraphicsAPI::OPENGL
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan)
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan) && \
defined(GZ_RENDERING_HAVE_VULKAN)
// Use fallback (GPU -> CPU -> GPU)
|| this->dataPtr->graphicsAPI == rendering::GraphicsAPI::VULKAN
#endif
Expand Down

0 comments on commit 9b1b7b0

Please sign in to comment.