From 90e71575fbe62162dec4efe659bd81e45e6c1628 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 10 Mar 2021 14:39:41 +0100 Subject: rhi: metal: Skip unnecessary writes when updating the entire buffer Follow the similar Vulkan change in 20eb40bce92c3e5460cd2540547f3c404fe6dccc and drop the queued up buffer data for a given slot when the current update covers the entire buffer. This is relevant in particular for Qt Quick 3D where such dynamic buffer changes are common. Change-Id: If1e70d78968586b552a5357bc97af10cc61d9611 Reviewed-by: Andy Nichols (cherry picked from commit 0c6375a346551dbf2effb2ea54e1df7de56f0849) Reviewed-by: Qt Cherry-pick Bot --- src/gui/rhi/qrhimetal.mm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm index e6a12067d9..65f46f7f68 100644 --- a/src/gui/rhi/qrhimetal.mm +++ b/src/gui/rhi/qrhimetal.mm @@ -1699,8 +1699,11 @@ void QRhiMetal::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate if (u.type == QRhiResourceUpdateBatchPrivate::BufferOp::DynamicUpdate) { QMetalBuffer *bufD = QRHI_RES(QMetalBuffer, u.buf); Q_ASSERT(bufD->m_type == QRhiBuffer::Dynamic); - for (int i = 0; i < QMTL_FRAMES_IN_FLIGHT; ++i) + for (int i = 0; i < QMTL_FRAMES_IN_FLIGHT; ++i) { + if (u.offset == 0 && u.data.size() == bufD->m_size) + bufD->d->pendingUpdates[i].clear(); bufD->d->pendingUpdates[i].append(u); + } } else if (u.type == QRhiResourceUpdateBatchPrivate::BufferOp::StaticUpload) { // Due to the Metal API the handling of static and dynamic buffers is // basically the same. So go through the same pendingUpdates machinery. -- cgit v1.2.3