rhi: vulkan: Support initializing without a Vulkan instance given
Problem is, this has potential issues down the line. For example, if one pops up a QQuickWindow afterwards, also with Vulkan, and wants to do things like enabling the debug layer (QSG_RHI_DEBUG_LAYER and similar), that will not work since the instance is already up. In absence of better solutions, drop a warning as well and keep this undocumented for now. On the plus side, this allows applications to implement things like enumerating adapters with Vulkan and then launching a QQuickWindow with the selected adapter. With other APIs (D3D) this is a breeze, but is impossible here due to the very unfortunate concept of Vulkan instances, and handles such as a VkPhysicalDevice being tied to the instance. An application has no way of knowing what VkInstance Qt Quick will create/use, unless the developer does the extra boilerplate to provide their own, which is an overkill in this case. So offer some way to make this work, even if there are some pitfalls. Change-Id: I1fc11f90cd1bf3fdac945ed5a7221f596368d30e Reviewed-by: Kristoffer Skau <kristoffer.skau@qt.io> Reviewed-by: Andy Nichols <andy.nichols@qt.io> (cherry picked from commit 3c338def89a4e03e3b47e624d83d83785c52037b) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
1efb618b9a
commit
2f632086e9
@ -23,6 +23,7 @@ QT_WARNING_POP
|
||||
#include <qmath.h>
|
||||
#include <QVulkanFunctions>
|
||||
#include <QtGui/qwindow.h>
|
||||
#include <private/qvulkandefaultinstance_p.h>
|
||||
#include <optional>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
@ -407,6 +408,15 @@ QRhiVulkan::QRhiVulkan(QRhiVulkanInitParams *params, QRhiVulkanNativeHandles *im
|
||||
: ofr(this)
|
||||
{
|
||||
inst = params->inst;
|
||||
if (!inst) {
|
||||
// This builds on the fact that Qt Quick also uses QVulkanDefaultInstance. While
|
||||
// this way we can support a null inst, it has consequences, so only do it with a
|
||||
// warning. (e.g. if Qt Quick initializes afterwards, its attempt to set flags on
|
||||
// QVulkanDefaultInstance will be futile)
|
||||
qWarning("QRhi for Vulkan attempted to be initialized without a QVulkanInstance; using QVulkanDefaultInstance.");
|
||||
inst = QVulkanDefaultInstance::instance();
|
||||
}
|
||||
|
||||
maybeWindow = params->window; // may be null
|
||||
requestedDeviceExtensions = params->deviceExtensions;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user