Skip to content

Commit

Permalink
rhi: Drop QBitArray usage
Browse files Browse the repository at this point in the history
Change-Id: I4ae92e6c8c91111a4593c51ee05443b3bc806c35
Reviewed-by: Andy Nichols <[email protected]>
  • Loading branch information
alpqr committed Sep 29, 2020
1 parent 868866c commit 848ed96
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
19 changes: 12 additions & 7 deletions src/gui/rhi/qrhi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4998,21 +4998,25 @@ 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;
return u;
}
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;
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui/rhi/qrhi_p_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class QRhiImplementation
QThread *implThread;
QRhiProfiler profiler;
QVarLengthArray<QRhiResourceUpdateBatch *, 4> resUpdPool;
QBitArray resUpdPoolMap;
quint64 resUpdPoolMap = 0;
int lastResUpdIdx = -1;
QSet<QRhiResource *> resources;
QSet<QRhiResource *> pendingDeleteResources;
Expand Down
13 changes: 13 additions & 0 deletions tests/auto/gui/rhi/qrhi/tst_qrhi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,19 @@ void tst_QRhi::create()
QVERIFY(resUpd);
resUpd->release();

QRhiResourceUpdateBatch *resUpdArray[64];
for (int i = 0; i < 64; ++i) {
resUpdArray[i] = rhi->nextResourceUpdateBatch();
QVERIFY(resUpdArray[i]);
}
resUpd = rhi->nextResourceUpdateBatch();
QVERIFY(!resUpd);
for (int i = 0; i < 64; ++i)
resUpdArray[i]->release();
resUpd = rhi->nextResourceUpdateBatch();
QVERIFY(resUpd);
resUpd->release();

QVERIFY(!rhi->supportedSampleCounts().isEmpty());
QVERIFY(rhi->supportedSampleCounts().contains(1));

Expand Down

0 comments on commit 848ed96

Please sign in to comment.