rhi: vulkan: Print vma statistics on out of device memory

Following a vmaCreate* it makes sense to test for
VK_ERROR_OUT_OF_DEVICE_MEMORY and print the allocator statistics
in order to give an idea of the application's (video) memory
usage.

For instance when running on a Raspberry Pi 4, this helps to indicate
that the application is just too big for the device, and is more
informative then just a Failed to create image: -2 message.

Pick-to: 6.6 6.5
Change-Id: I666e2358303894efab9d12d2b3a3d98f0bd3a5b6
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Reviewed-by: Kristoffer Skau <kristoffer.skau@qt.io>
bb10
Laszlo Agocs 2023-09-25 12:09:52 +02:00
parent 266c2d23ae
commit 9f6a2e357b
2 changed files with 21 additions and 2 deletions

View File

@ -3293,6 +3293,12 @@ void QRhiVulkan::prepareUploadSubres(QVkTexture *texD, int layer, int level,
}
}
void QRhiVulkan::printExtraErrorInfo(VkResult err)
{
if (err == VK_ERROR_OUT_OF_DEVICE_MEMORY)
qWarning() << "Out of device memory, current allocator statistics are" << statistics();
}
void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdateBatch *resourceUpdates)
{
QRhiResourceUpdateBatchPrivate *ud = QRhiResourceUpdateBatchPrivate::get(resourceUpdates);
@ -3330,6 +3336,7 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat
bufD->stagingAllocations[currentFrameSlot] = allocation;
} else {
qWarning("Failed to create staging buffer of size %u: %d", bufD->m_size, err);
printExtraErrorInfo(err);
continue;
}
}
@ -3418,6 +3425,7 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat
readback.stagingAlloc = allocation;
} else {
qWarning("Failed to create readback buffer of size %u: %d", readback.byteSize, err);
printExtraErrorInfo(err);
continue;
}
@ -3467,6 +3475,7 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat
&utexD->stagingBuffers[currentFrameSlot], &allocation, nullptr);
if (err != VK_SUCCESS) {
qWarning("Failed to create image staging buffer of size %d: %d", int(stagingSize), err);
printExtraErrorInfo(err);
continue;
}
utexD->stagingAllocations[currentFrameSlot] = allocation;
@ -3623,6 +3632,7 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat
readback.stagingAlloc = allocation;
} else {
qWarning("Failed to create readback buffer of size %u: %d", readback.byteSize, err);
printExtraErrorInfo(err);
continue;
}
@ -5932,7 +5942,8 @@ bool QVkBuffer::create()
}
if (err != VK_SUCCESS) {
qWarning("Failed to create buffer: %d", err);
qWarning("Failed to create buffer of size %u: %d", nonZeroSize, err);
rhiD->printExtraErrorInfo(err);
return false;
}
@ -6345,7 +6356,14 @@ bool QVkTexture::create()
VmaAllocation allocation;
VkResult err = vmaCreateImage(toVmaAllocator(rhiD->allocator), &imageInfo, &allocInfo, &image, &allocation, nullptr);
if (err != VK_SUCCESS) {
qWarning("Failed to create image: %d", err);
qWarning("Failed to create image (with VkImageCreateInfo %ux%u depth %u vkformat 0x%X mips %u layers %u vksamples 0x%X): %d",
imageInfo.extent.width, imageInfo.extent.height, imageInfo.extent.depth,
int(imageInfo.format),
imageInfo.mipLevels,
imageInfo.arrayLayers,
int(imageInfo.samples),
err);
rhiD->printExtraErrorInfo(err);
return false;
}
imageAlloc = allocation;

View File

@ -821,6 +821,7 @@ public:
void updateShaderResourceBindings(QRhiShaderResourceBindings *srb, int descSetIdx = -1);
void ensureCommandPoolForNewFrame();
double elapsedSecondsFromTimestamp(quint64 timestamp[2], bool *ok);
void printExtraErrorInfo(VkResult err);
QVulkanInstance *inst = nullptr;
QWindow *maybeWindow = nullptr;