From 2d3cdcce59c65714d950b24f6f1a55777be5643a Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 24 Apr 2023 13:24:12 +0200 Subject: [PATCH] rhi: Add enablers for testing reducing the resource update pools MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ...which comes at the expense of performance. Therefore this is currently an environment variable-based opt-in solution. Change-Id: If884de041f619fef0929ac2cfbdd035092723d51 Reviewed-by: Christian Strømme --- src/gui/rhi/qrhi.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index 516da50f88..7b5acf80b0 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -6296,6 +6296,11 @@ QRhiResourceUpdateBatch *QRhi::nextResourceUpdateBatch() // then reused in subsequent frames. This comes at the expense of using // more memory, but has proven good results when (CPU) profiling typical // Quick/Quick3D apps. + // + // Prefering memory over performance means that we always pick the first + // free batch, and triggering the aggressive deallocating of all backing + // memory (see trimOpLists) before returning it. + static const bool preferMemoryOverPerformance = qEnvironmentVariableIntValue("QT_RHI_MINIMIZE_POOLS"); auto nextFreeBatch = [this]() -> QRhiResourceUpdateBatch * { auto isFree = [this](int i) -> QRhiResourceUpdateBatch * { @@ -6304,7 +6309,8 @@ QRhiResourceUpdateBatch *QRhi::nextResourceUpdateBatch() d->resUpdPoolMap |= mask; QRhiResourceUpdateBatch *u = d->resUpdPool[i]; QRhiResourceUpdateBatchPrivate::get(u)->poolIndex = i; - d->lastResUpdIdx = i; + if (!preferMemoryOverPerformance) + d->lastResUpdIdx = i; return u; } return nullptr; @@ -6333,6 +6339,9 @@ QRhiResourceUpdateBatch *QRhi::nextResourceUpdateBatch() qWarning("Resource update batch pool exhausted (max is 64)"); } + if (preferMemoryOverPerformance && u) + u->d->trimOpLists(); + return u; } @@ -6383,8 +6392,6 @@ bool QRhiResourceUpdateBatchPrivate::hasOptimalCapacity() const void QRhiResourceUpdateBatchPrivate::trimOpLists() { - Q_ASSERT(poolIndex == -1); // must not be in use - // Unlike free(), this is expected to aggressively deallocate all memory // used by both the buffer and texture operation lists. (i.e. using // squeeze() to only keep the stack prealloc of the QVLAs)