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 check for vulkan support in rendering #589

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Changes from all 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
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