rhi: vulkan: avoid allocations/deallocations in every beginPass() call

It is not uncommon to have more than 4 total clear values because of all
the color, depth, resolve and shading rate attachments.

Set the stack prealloc of the temporary QVarLengthArray to its maximum
possible size to avoid any heap (de)allocation in this hot path.

For 10 render passes per frame, it saves 600 allocs/deallocs per second.

Change-Id: If44fd075d1c1f9c07809ddc9922c690e9dc3ac3d
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
This commit is contained in:
Aurélien Brooke 2025-02-12 08:47:24 +01:00
parent fa21fc298a
commit 6ec0fd6632

View File

@ -3235,7 +3235,7 @@ void QRhiVulkan::beginPass(QRhiCommandBuffer *cb,
rpBeginInfo.renderArea.extent.width = uint32_t(rtD->pixelSize.width());
rpBeginInfo.renderArea.extent.height = uint32_t(rtD->pixelSize.height());
QVarLengthArray<VkClearValue, 4> cvs;
QVarLengthArray<VkClearValue, (QVkRenderTargetData::MAX_COLOR_ATTACHMENTS + 1) * 2 + 1> cvs;
for (int i = 0; i < rtD->colorAttCount; ++i) {
VkClearValue cv;
cv.color = { { float(colorClearValue.redF()), float(colorClearValue.greenF()), float(colorClearValue.blueF()),