From 848ed9644c5ddd4b761f7b5184658b6131027e7a Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 28 Sep 2020 13:19:52 +0200 Subject: rhi: Drop QBitArray usage Change-Id: I4ae92e6c8c91111a4593c51ee05443b3bc806c35 Reviewed-by: Andy Nichols --- src/gui/rhi/qrhi.cpp | 19 ++++++++++++------- src/gui/rhi/qrhi_p_p.h | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) (limited to 'src/gui/rhi') diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index 21542930ac..151e1268f6 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -4998,13 +4998,17 @@ void QRhiResourceUpdateBatch::generateMips(QRhiTexture *tex) \note Can be called outside beginFrame() - endFrame() as well since a batch instance just collects data on its own, it does not perform any operations. + + \warning The maximum number of batches is 64. When this limit is reached, + the function will return null until a batch is returned to the pool. */ QRhiResourceUpdateBatch *QRhi::nextResourceUpdateBatch() { auto nextFreeBatch = [this]() -> QRhiResourceUpdateBatch * { auto isFree = [this](int i) -> QRhiResourceUpdateBatch * { - if (!d->resUpdPoolMap.testBit(i)) { - d->resUpdPoolMap.setBit(i); + const quint64 mask = 1ULL << quint64(i); + if (!(d->resUpdPoolMap & mask)) { + d->resUpdPoolMap |= mask; QRhiResourceUpdateBatch *u = d->resUpdPool[i]; QRhiResourceUpdateBatchPrivate::get(u)->poolIndex = i; d->lastResUpdIdx = i; @@ -5012,7 +5016,7 @@ QRhiResourceUpdateBatch *QRhi::nextResourceUpdateBatch() } return nullptr; }; - const int poolSize = d->resUpdPoolMap.count(); + const int poolSize = d->resUpdPool.size(); for (int i = d->lastResUpdIdx + 1; i < poolSize; ++i) { if (QRhiResourceUpdateBatch *u = isFree(i)) return u; @@ -5027,13 +5031,13 @@ QRhiResourceUpdateBatch *QRhi::nextResourceUpdateBatch() QRhiResourceUpdateBatch *u = nextFreeBatch(); if (!u) { const int oldSize = d->resUpdPool.count(); - const int newSize = oldSize + 4; + const int newSize = oldSize + qMin(4, qMax(0, 64 - oldSize)); d->resUpdPool.resize(newSize); - d->resUpdPoolMap.resize(newSize); for (int i = oldSize; i < newSize; ++i) d->resUpdPool[i] = new QRhiResourceUpdateBatch(d); u = nextFreeBatch(); - Q_ASSERT(u); + if (!u) + qWarning("Resource update batch pool exhausted (max is 64)"); } return u; @@ -5046,7 +5050,8 @@ void QRhiResourceUpdateBatchPrivate::free() activeBufferOpCount = 0; activeTextureOpCount = 0; - rhi->resUpdPoolMap.clearBit(poolIndex); + const quint64 mask = 1ULL << quint64(poolIndex); + rhi->resUpdPoolMap &= ~mask; poolIndex = -1; } diff --git a/src/gui/rhi/qrhi_p_p.h b/src/gui/rhi/qrhi_p_p.h index 51b3645b9d..3b68b5d078 100644 --- a/src/gui/rhi/qrhi_p_p.h +++ b/src/gui/rhi/qrhi_p_p.h @@ -227,7 +227,7 @@ private: QThread *implThread; QRhiProfiler profiler; QVarLengthArray resUpdPool; - QBitArray resUpdPoolMap; + quint64 resUpdPoolMap = 0; int lastResUpdIdx = -1; QSet resources; QSet pendingDeleteResources; -- cgit v1.2.3