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(). Task-number: QTBUG-108895 Change-Id: I474ccea51a81e7a096281604ff79b7db4cdd2484 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io> (cherry picked from commit 4d36a83b6d665f5b022cf46e4a5349f8974c1fdb) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
5036562bd2
commit
6ff96b2dce
@ -23,6 +23,7 @@ QT_WARNING_POP
|
|||||||
#include <qmath.h>
|
#include <qmath.h>
|
||||||
#include <QVulkanFunctions>
|
#include <QVulkanFunctions>
|
||||||
#include <QtGui/qwindow.h>
|
#include <QtGui/qwindow.h>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
@ -433,25 +434,28 @@ bool QRhiVulkan::create(QRhi::Flags flags)
|
|||||||
// We only support combined graphics+present queues. When it comes to
|
// We only support combined graphics+present queues. When it comes to
|
||||||
// compute, only combined graphics+compute queue is used, compute gets
|
// compute, only combined graphics+compute queue is used, compute gets
|
||||||
// disabled otherwise.
|
// disabled otherwise.
|
||||||
gfxQueueFamilyIdx = -1;
|
std::optional<uint32_t> gfxQueueFamilyIdxOpt;
|
||||||
int computelessGfxQueueCandidateIdx = -1;
|
std::optional<uint32_t> computelessGfxQueueCandidateIdxOpt;
|
||||||
queryQueueFamilyProps();
|
queryQueueFamilyProps();
|
||||||
for (int i = 0; i < queueFamilyProps.size(); ++i) {
|
const uint32_t queueFamilyCount = uint32_t(queueFamilyProps.size());
|
||||||
qCDebug(QRHI_LOG_INFO, "queue family %d: flags=0x%x count=%d",
|
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);
|
i, queueFamilyProps[i].queueFlags, queueFamilyProps[i].queueCount);
|
||||||
if (gfxQueueFamilyIdx == -1
|
if (!gfxQueueFamilyIdxOpt.has_value()
|
||||||
&& (queueFamilyProps[i].queueFlags & VK_QUEUE_GRAPHICS_BIT)
|
&& (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)
|
if (queueFamilyProps[i].queueFlags & VK_QUEUE_COMPUTE_BIT)
|
||||||
gfxQueueFamilyIdx = i;
|
gfxQueueFamilyIdxOpt = i;
|
||||||
else if (computelessGfxQueueCandidateIdx == -1)
|
else if (!computelessGfxQueueCandidateIdxOpt.has_value())
|
||||||
computelessGfxQueueCandidateIdx = i;
|
computelessGfxQueueCandidateIdxOpt = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (gfxQueueFamilyIdx == -1) {
|
if (gfxQueueFamilyIdxOpt.has_value()) {
|
||||||
if (computelessGfxQueueCandidateIdx != -1) {
|
gfxQueueFamilyIdx = gfxQueueFamilyIdxOpt.value();
|
||||||
gfxQueueFamilyIdx = computelessGfxQueueCandidateIdx;
|
} else {
|
||||||
|
if (computelessGfxQueueCandidateIdxOpt.has_value()) {
|
||||||
|
gfxQueueFamilyIdx = computelessGfxQueueCandidateIdxOpt.value();
|
||||||
} else {
|
} else {
|
||||||
qWarning("No graphics (or no graphics+present) queue family found");
|
qWarning("No graphics (or no graphics+present) queue family found");
|
||||||
return false;
|
return false;
|
||||||
@ -461,7 +465,7 @@ bool QRhiVulkan::create(QRhi::Flags flags)
|
|||||||
VkDeviceQueueCreateInfo queueInfo = {};
|
VkDeviceQueueCreateInfo queueInfo = {};
|
||||||
const float prio[] = { 0 };
|
const float prio[] = { 0 };
|
||||||
queueInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
|
queueInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
|
||||||
queueInfo.queueFamilyIndex = uint32_t(gfxQueueFamilyIdx);
|
queueInfo.queueFamilyIndex = gfxQueueFamilyIdx;
|
||||||
queueInfo.queueCount = 1;
|
queueInfo.queueCount = 1;
|
||||||
queueInfo.pQueuePriorities = prio;
|
queueInfo.pQueuePriorities = prio;
|
||||||
|
|
||||||
@ -619,7 +623,7 @@ bool QRhiVulkan::create(QRhi::Flags flags)
|
|||||||
|
|
||||||
VkCommandPoolCreateInfo poolInfo = {};
|
VkCommandPoolCreateInfo poolInfo = {};
|
||||||
poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
|
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) {
|
for (int i = 0; i < QVK_FRAMES_IN_FLIGHT; ++i) {
|
||||||
VkResult err = df->vkCreateCommandPool(dev, &poolInfo, nullptr, &cmdPool[i]);
|
VkResult err = df->vkCreateCommandPool(dev, &poolInfo, nullptr, &cmdPool[i]);
|
||||||
if (err != VK_SUCCESS) {
|
if (err != VK_SUCCESS) {
|
||||||
@ -628,13 +632,10 @@ bool QRhiVulkan::create(QRhi::Flags flags)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gfxQueueFamilyIdx < 0) {
|
qCDebug(QRHI_LOG_INFO, "Using queue family index %u and queue index %u",
|
||||||
// this is when importParams is faulty and did not specify the queue family index
|
gfxQueueFamilyIdx, gfxQueueIdx);
|
||||||
qWarning("No queue family index provided");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
df->vkGetDeviceQueue(dev, uint32_t(gfxQueueFamilyIdx), gfxQueueIdx, &gfxQueue);
|
df->vkGetDeviceQueue(dev, gfxQueueFamilyIdx, gfxQueueIdx, &gfxQueue);
|
||||||
|
|
||||||
if (queueFamilyProps.isEmpty())
|
if (queueFamilyProps.isEmpty())
|
||||||
queryQueueFamilyProps();
|
queryQueueFamilyProps();
|
||||||
@ -7353,11 +7354,9 @@ bool QVkSwapChain::ensureSurface()
|
|||||||
surface = surf;
|
surface = surf;
|
||||||
|
|
||||||
QRHI_RES_RHI(QRhiVulkan);
|
QRHI_RES_RHI(QRhiVulkan);
|
||||||
if (rhiD->gfxQueueFamilyIdx != -1) {
|
if (!rhiD->inst->supportsPresent(rhiD->physDev, rhiD->gfxQueueFamilyIdx, m_window)) {
|
||||||
if (!rhiD->inst->supportsPresent(rhiD->physDev, uint32_t(rhiD->gfxQueueFamilyIdx), m_window)) {
|
qWarning("Presenting not supported on this window");
|
||||||
qWarning("Presenting not supported on this window");
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 formatCount = 0;
|
quint32 formatCount = 0;
|
||||||
|
@ -36,8 +36,8 @@ struct Q_GUI_EXPORT QRhiVulkanNativeHandles : public QRhiNativeHandles
|
|||||||
VkPhysicalDevice physDev = VK_NULL_HANDLE;
|
VkPhysicalDevice physDev = VK_NULL_HANDLE;
|
||||||
// to import a device and queue
|
// to import a device and queue
|
||||||
VkDevice dev = VK_NULL_HANDLE;
|
VkDevice dev = VK_NULL_HANDLE;
|
||||||
int gfxQueueFamilyIdx = -1;
|
quint32 gfxQueueFamilyIdx = 0;
|
||||||
int gfxQueueIdx = 0;
|
quint32 gfxQueueIdx = 0;
|
||||||
VkQueue gfxQueue = VK_NULL_HANDLE;
|
VkQueue gfxQueue = VK_NULL_HANDLE;
|
||||||
// and optionally, the mem allocator
|
// and optionally, the mem allocator
|
||||||
void *vmemAllocator = nullptr;
|
void *vmemAllocator = nullptr;
|
||||||
|
@ -821,8 +821,8 @@ public:
|
|||||||
VkPhysicalDevice physDev = VK_NULL_HANDLE;
|
VkPhysicalDevice physDev = VK_NULL_HANDLE;
|
||||||
VkDevice dev = VK_NULL_HANDLE;
|
VkDevice dev = VK_NULL_HANDLE;
|
||||||
VkCommandPool cmdPool[QVK_FRAMES_IN_FLIGHT] = {};
|
VkCommandPool cmdPool[QVK_FRAMES_IN_FLIGHT] = {};
|
||||||
int gfxQueueFamilyIdx = -1;
|
quint32 gfxQueueFamilyIdx = 0;
|
||||||
int gfxQueueIdx = 0;
|
quint32 gfxQueueIdx = 0;
|
||||||
VkQueue gfxQueue = VK_NULL_HANDLE;
|
VkQueue gfxQueue = VK_NULL_HANDLE;
|
||||||
quint32 timestampValidBits = 0;
|
quint32 timestampValidBits = 0;
|
||||||
bool importedAllocator = false;
|
bool importedAllocator = false;
|
||||||
|
@ -463,8 +463,6 @@ void tst_QRhi::nativeHandles()
|
|||||||
const QRhiVulkanNativeHandles *vkHandles = static_cast<const QRhiVulkanNativeHandles *>(rhiHandles);
|
const QRhiVulkanNativeHandles *vkHandles = static_cast<const QRhiVulkanNativeHandles *>(rhiHandles);
|
||||||
QVERIFY(vkHandles->physDev);
|
QVERIFY(vkHandles->physDev);
|
||||||
QVERIFY(vkHandles->dev);
|
QVERIFY(vkHandles->dev);
|
||||||
QVERIFY(vkHandles->gfxQueueFamilyIdx >= 0);
|
|
||||||
QVERIFY(vkHandles->gfxQueueIdx >= 0);
|
|
||||||
QVERIFY(vkHandles->gfxQueue);
|
QVERIFY(vkHandles->gfxQueue);
|
||||||
QVERIFY(vkHandles->vmemAllocator);
|
QVERIFY(vkHandles->vmemAllocator);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user