QVulkanWindow vs. QRHI /QRHI Widget?
-
Both can be used to draw things with vulkan but what exactly is the advantage/difference or better what should i by using for rendering custom 2d scenes with shaders with vulkan.
From what i've read in the documentation QRHI is more flexible especially cause it can be integrated as painting backend for widgets. It also supports other graphics api's but my main focus is vulkan.
-
From QRHI :
Each QRhi instance is backed by a backend for a specific graphics API. The selection of the backend is a run time choice and is up to the application or library that creates the QRhi instance.
See also the example:
#if QT_CONFIG(vulkan) QVulkanInstance inst; #endif // ... // ... // ... // ... #elif QT_CONFIG(vulkan) inst.setExtensions(QRhiVulkanInitParams::preferredInstanceExtensions()); if (inst.create()) { QRhiVulkanInitParams params; params.inst = &inst; rhi.reset(QRhi::create(QRhi::Vulkan, ¶ms)); } else { qFatal("Failed to create Vulkan instance"); } #endif if (rhi) qDebug() << rhi->backendName() << rhi->driverInfo(); else qFatal("Failed to initialize RHI");
So it's up to YOU (the developer) to chose a backend (or leave it dynamic)...
If you force the use of Vulkan and further only use the Vulkan API, you program/code only works with Vulkanand like @SGaist said above... if no Vulkan SDK or libs are found or the system is incompatible with Vulkan at all, your program won't work (you need to handle that also... for example like shown in my example via defines and error handling)
-
Hi,
QRhi is an abstraction layer that can make use of different backends depending on the OS you are running your application on.
QVulkanWindow is dedicated for Vulkan as the name suggests.
If you are only interested in implementing Vulkan code then go with QVulkanWindow.
-
If you write code against QRHI you don't know which backend you get. If you then try to write shaders you basically have the smallest common subset that is supported by all backends. Or you only write against a single backend and others will run into problems you have a hard time to understand and debug. If you want to use Vulkan you should definitely use a QVulkanWidget.
It might be a little complicated to overlay widgets on top the QVulkanWidget. With the QOpenGLWidget this was allowed. There is a thread on StackOverflow that explains that QML on top of QVulkanWidget (through sharing OpenGL with Vulkan) can be used: https://stackoverflow.com/questions/52691818/qt-qvulkanwindow-overlay-widgets. Maybe something similar works with regular widgets (as those can be drawn on a QOpenGLWidget and that might be able to be used by Vulkan...
-
@SimonSchroeder Alright that definitely helps. But one last question to this topic: isn't there a way to force using vulkan with QRHI? Cause obviously QVulkanWindow is probably doing something similar otherwise it would be broken on many systems that don't have vulcan.
-
@StudentScripter QVulkanWindow won't work on system that don't support Vulkan.
It's your responsibility to provide the required libraries along with your application.
-
From QRHI :
Each QRhi instance is backed by a backend for a specific graphics API. The selection of the backend is a run time choice and is up to the application or library that creates the QRhi instance.
See also the example:
#if QT_CONFIG(vulkan) QVulkanInstance inst; #endif // ... // ... // ... // ... #elif QT_CONFIG(vulkan) inst.setExtensions(QRhiVulkanInitParams::preferredInstanceExtensions()); if (inst.create()) { QRhiVulkanInitParams params; params.inst = &inst; rhi.reset(QRhi::create(QRhi::Vulkan, ¶ms)); } else { qFatal("Failed to create Vulkan instance"); } #endif if (rhi) qDebug() << rhi->backendName() << rhi->driverInfo(); else qFatal("Failed to initialize RHI");
So it's up to YOU (the developer) to chose a backend (or leave it dynamic)...
If you force the use of Vulkan and further only use the Vulkan API, you program/code only works with Vulkanand like @SGaist said above... if no Vulkan SDK or libs are found or the system is incompatible with Vulkan at all, your program won't work (you need to handle that also... for example like shown in my example via defines and error handling)
-
-