From 9152e3babc6fbe0256f8fd532eb8e007c9a9f3c0 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 28 Sep 2020 18:20:17 +0200 Subject: rhi: vk: Do not copy the entire BufferOp struct for host writes Take only the three things we need. Otherwise we waste time on copying data that is not even relevant to buffer updates at all. Change-Id: I5ed6ae647e23c6f1d0f5f1d973bead2e008f06cc Reviewed-by: Andy Nichols --- src/gui/rhi/qrhivulkan.cpp | 11 +++++------ src/gui/rhi/qrhivulkan_p_p.h | 7 ++++++- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'src/gui/rhi') diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp index 73aa32f08b..5146a2ccc3 100644 --- a/src/gui/rhi/qrhivulkan.cpp +++ b/src/gui/rhi/qrhivulkan.cpp @@ -2929,7 +2929,7 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat QVkBuffer *bufD = QRHI_RES(QVkBuffer, u.buf); Q_ASSERT(bufD->m_type == QRhiBuffer::Dynamic); for (int i = 0; i < QVK_FRAMES_IN_FLIGHT; ++i) - bufD->pendingDynamicUpdates[i].append(u); + bufD->pendingDynamicUpdates[i].append({ u.offset, u.dataSize, u.data }); } else if (u.type == QRhiResourceUpdateBatchPrivate::BufferOp::StaticUpload) { QVkBuffer *bufD = QRHI_RES(QVkBuffer, u.buf); Q_ASSERT(bufD->m_type != QRhiBuffer::Dynamic); @@ -3428,13 +3428,12 @@ void QRhiVulkan::executeBufferHostWritesForSlot(QVkBuffer *bufD, int slot) } int changeBegin = -1; int changeEnd = -1; - for (const QRhiResourceUpdateBatchPrivate::BufferOp &u : qAsConst(bufD->pendingDynamicUpdates[slot])) { - Q_ASSERT(bufD == QRHI_RES(QVkBuffer, u.buf)); - memcpy(static_cast(p) + u.offset, u.data.constData(), size_t(u.dataSize)); + for (const QVkBuffer::DynamicUpdate &u : qAsConst(bufD->pendingDynamicUpdates[slot])) { + memcpy(static_cast(p) + u.offset, u.data.constData(), size_t(u.size)); if (changeBegin == -1 || u.offset < changeBegin) changeBegin = u.offset; - if (changeEnd == -1 || u.offset + u.dataSize > changeEnd) - changeEnd = u.offset + u.dataSize; + if (changeEnd == -1 || u.offset + u.size > changeEnd) + changeEnd = u.offset + u.size; } vmaUnmapMemory(toVmaAllocator(allocator), a); if (changeBegin >= 0) diff --git a/src/gui/rhi/qrhivulkan_p_p.h b/src/gui/rhi/qrhivulkan_p_p.h index 641ad5a87b..f3157c9112 100644 --- a/src/gui/rhi/qrhivulkan_p_p.h +++ b/src/gui/rhi/qrhivulkan_p_p.h @@ -80,7 +80,12 @@ struct QVkBuffer : public QRhiBuffer VkBuffer buffers[QVK_FRAMES_IN_FLIGHT]; QVkAlloc allocations[QVK_FRAMES_IN_FLIGHT]; - QVarLengthArray pendingDynamicUpdates[QVK_FRAMES_IN_FLIGHT]; + struct DynamicUpdate { + int offset; + int size; + QByteArray data; + }; + QVarLengthArray pendingDynamicUpdates[QVK_FRAMES_IN_FLIGHT]; VkBuffer stagingBuffers[QVK_FRAMES_IN_FLIGHT]; QVkAlloc stagingAllocations[QVK_FRAMES_IN_FLIGHT]; struct UsageState { -- cgit v1.2.3