diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2022-11-28 16:07:15 +0100 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2022-12-16 17:49:28 +0000 |
commit | 4d36a83b6d665f5b022cf46e4a5349f8974c1fdb (patch) | |
tree | 3339dd808320302e871ae6a5797595e56b030053 | |
parent | c7425aa2950bfd47fdf390478616d1a383528886 (diff) |
rhi: vk: Fix up some legacy queue (family) index inconsistencies
Relevant mainly if we want to consistently expose these as the
theoretically correct uint32_t/quint32 from Qt Quick's
QSGRendererInterface. (not that int is not sufficient for
indexing the typical 3-4 families and 2-16 queues per family)
Some checks are not actually needed since the family index
must always be valid after create().
Pick-to: 6.5
Task-number: QTBUG-108895
Change-Id: I474ccea51a81e7a096281604ff79b7db4cdd2484
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
-rw-r--r-- | src/gui/rhi/qrhivulkan.cpp | 49 | ||||
-rw-r--r-- | src/gui/rhi/qrhivulkan_p.h | 4 | ||||
-rw-r--r-- | src/gui/rhi/qrhivulkan_p_p.h | 4 | ||||
-rw-r--r-- | tests/auto/gui/rhi/qrhi/tst_qrhi.cpp | 2 |
4 files changed, 28 insertions, 31 deletions
diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp index da6d0fd0ae..ea7d40fef2 100644 --- a/src/gui/rhi/qrhivulkan.cpp +++ b/src/gui/rhi/qrhivulkan.cpp @@ -23,6 +23,7 @@ QT_WARNING_POP #include <qmath.h> #include <QVulkanFunctions> #include <QtGui/qwindow.h> +#include <optional> QT_BEGIN_NAMESPACE @@ -433,25 +434,28 @@ bool QRhiVulkan::create(QRhi::Flags flags) // We only support combined graphics+present queues. When it comes to // compute, only combined graphics+compute queue is used, compute gets // disabled otherwise. - gfxQueueFamilyIdx = -1; - int computelessGfxQueueCandidateIdx = -1; + std::optional<uint32_t> gfxQueueFamilyIdxOpt; + std::optional<uint32_t> computelessGfxQueueCandidateIdxOpt; queryQueueFamilyProps(); - for (int i = 0; i < queueFamilyProps.size(); ++i) { - qCDebug(QRHI_LOG_INFO, "queue family %d: flags=0x%x count=%d", + const uint32_t queueFamilyCount = uint32_t(queueFamilyProps.size()); + for (uint32_t i = 0; i < queueFamilyCount; ++i) { + qCDebug(QRHI_LOG_INFO, "queue family %u: flags=0x%x count=%u", i, queueFamilyProps[i].queueFlags, queueFamilyProps[i].queueCount); - if (gfxQueueFamilyIdx == -1 + if (!gfxQueueFamilyIdxOpt.has_value() && (queueFamilyProps[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) - && (!maybeWindow || inst->supportsPresent(physDev, uint32_t(i), maybeWindow))) + && (!maybeWindow || inst->supportsPresent(physDev, i, maybeWindow))) { if (queueFamilyProps[i].queueFlags & VK_QUEUE_COMPUTE_BIT) - gfxQueueFamilyIdx = i; - else if (computelessGfxQueueCandidateIdx == -1) - computelessGfxQueueCandidateIdx = i; + gfxQueueFamilyIdxOpt = i; + else if (!computelessGfxQueueCandidateIdxOpt.has_value()) + computelessGfxQueueCandidateIdxOpt = i; } } - if (gfxQueueFamilyIdx == -1) { - if (computelessGfxQueueCandidateIdx != -1) { - gfxQueueFamilyIdx = computelessGfxQueueCandidateIdx; + if (gfxQueueFamilyIdxOpt.has_value()) { + gfxQueueFamilyIdx = gfxQueueFamilyIdxOpt.value(); + } else { + if (computelessGfxQueueCandidateIdxOpt.has_value()) { + gfxQueueFamilyIdx = computelessGfxQueueCandidateIdxOpt.value(); } else { qWarning("No graphics (or no graphics+present) queue family found"); return false; @@ -461,7 +465,7 @@ bool QRhiVulkan::create(QRhi::Flags flags) VkDeviceQueueCreateInfo queueInfo = {}; const float prio[] = { 0 }; queueInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; - queueInfo.queueFamilyIndex = uint32_t(gfxQueueFamilyIdx); + queueInfo.queueFamilyIndex = gfxQueueFamilyIdx; queueInfo.queueCount = 1; queueInfo.pQueuePriorities = prio; @@ -619,7 +623,7 @@ bool QRhiVulkan::create(QRhi::Flags flags) VkCommandPoolCreateInfo poolInfo = {}; poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; - poolInfo.queueFamilyIndex = uint32_t(gfxQueueFamilyIdx); + poolInfo.queueFamilyIndex = gfxQueueFamilyIdx; for (int i = 0; i < QVK_FRAMES_IN_FLIGHT; ++i) { VkResult err = df->vkCreateCommandPool(dev, &poolInfo, nullptr, &cmdPool[i]); if (err != VK_SUCCESS) { @@ -628,13 +632,10 @@ bool QRhiVulkan::create(QRhi::Flags flags) } } - if (gfxQueueFamilyIdx < 0) { - // this is when importParams is faulty and did not specify the queue family index - qWarning("No queue family index provided"); - return false; - } + qCDebug(QRHI_LOG_INFO, "Using queue family index %u and queue index %u", + gfxQueueFamilyIdx, gfxQueueIdx); - df->vkGetDeviceQueue(dev, uint32_t(gfxQueueFamilyIdx), gfxQueueIdx, &gfxQueue); + df->vkGetDeviceQueue(dev, gfxQueueFamilyIdx, gfxQueueIdx, &gfxQueue); if (queueFamilyProps.isEmpty()) queryQueueFamilyProps(); @@ -7353,11 +7354,9 @@ bool QVkSwapChain::ensureSurface() surface = surf; QRHI_RES_RHI(QRhiVulkan); - if (rhiD->gfxQueueFamilyIdx != -1) { - if (!rhiD->inst->supportsPresent(rhiD->physDev, uint32_t(rhiD->gfxQueueFamilyIdx), m_window)) { - qWarning("Presenting not supported on this window"); - return false; - } + if (!rhiD->inst->supportsPresent(rhiD->physDev, rhiD->gfxQueueFamilyIdx, m_window)) { + qWarning("Presenting not supported on this window"); + return false; } quint32 formatCount = 0; diff --git a/src/gui/rhi/qrhivulkan_p.h b/src/gui/rhi/qrhivulkan_p.h index d2c928ccb8..f592cf7e54 100644 --- a/src/gui/rhi/qrhivulkan_p.h +++ b/src/gui/rhi/qrhivulkan_p.h @@ -36,8 +36,8 @@ struct Q_GUI_EXPORT QRhiVulkanNativeHandles : public QRhiNativeHandles VkPhysicalDevice physDev = VK_NULL_HANDLE; // to import a device and queue VkDevice dev = VK_NULL_HANDLE; - int gfxQueueFamilyIdx = -1; - int gfxQueueIdx = 0; + quint32 gfxQueueFamilyIdx = 0; + quint32 gfxQueueIdx = 0; VkQueue gfxQueue = VK_NULL_HANDLE; // and optionally, the mem allocator void *vmemAllocator = nullptr; diff --git a/src/gui/rhi/qrhivulkan_p_p.h b/src/gui/rhi/qrhivulkan_p_p.h index fceb3efd1d..22214723ae 100644 --- a/src/gui/rhi/qrhivulkan_p_p.h +++ b/src/gui/rhi/qrhivulkan_p_p.h @@ -821,8 +821,8 @@ public: VkPhysicalDevice physDev = VK_NULL_HANDLE; VkDevice dev = VK_NULL_HANDLE; VkCommandPool cmdPool[QVK_FRAMES_IN_FLIGHT] = {}; - int gfxQueueFamilyIdx = -1; - int gfxQueueIdx = 0; + quint32 gfxQueueFamilyIdx = 0; + quint32 gfxQueueIdx = 0; VkQueue gfxQueue = VK_NULL_HANDLE; quint32 timestampValidBits = 0; bool importedAllocator = false; diff --git a/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp b/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp index 9a5ce3c5a3..a6b8a94273 100644 --- a/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp +++ b/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp @@ -466,8 +466,6 @@ void tst_QRhi::nativeHandles() const QRhiVulkanNativeHandles *vkHandles = static_cast<const QRhiVulkanNativeHandles *>(rhiHandles); QVERIFY(vkHandles->physDev); QVERIFY(vkHandles->dev); - QVERIFY(vkHandles->gfxQueueFamilyIdx >= 0); - QVERIFY(vkHandles->gfxQueueIdx >= 0); QVERIFY(vkHandles->gfxQueue); QVERIFY(vkHandles->vmemAllocator); } |