summaryrefslogtreecommitdiffstats
path: root/src/gui/rhi
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/rhi')
-rw-r--r--src/gui/rhi/qrhi.cpp24
-rw-r--r--src/gui/rhi/qrhi_p.h1
-rw-r--r--src/gui/rhi/qrhi_p_p.h7
3 files changed, 30 insertions, 2 deletions
diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp
index f61fa6df59..a74765758c 100644
--- a/src/gui/rhi/qrhi.cpp
+++ b/src/gui/rhi/qrhi.cpp
@@ -4733,6 +4733,24 @@ void QRhiResourceUpdateBatch::merge(QRhiResourceUpdateBatch *other)
}
/*!
+ \return true until the number of buffer and texture operations enqueued
+ onto this batch is below a reasonable limit.
+
+ The return value is false when the number of buffer and/or texture
+ operations added to this batch have reached, or are about to reach, a
+ certain limit. The batch is fully functional afterwards as well, but may
+ need to allocate additional memory. Therefore, a renderer that collects
+ lots of buffer and texture updates in a single batch when preparing a frame
+ may want to consider \l{QRhiCommandBuffer::resourceUpdate()}{submitting the
+ batch} and \l{QRhi::nextResourceUpdateBatch()}{starting a new one} when
+ this function returns false.
+ */
+bool QRhiResourceUpdateBatch::hasOptimalCapacity() const
+{
+ return d->hasOptimalCapacity();
+}
+
+/*!
Enqueues updating a region of a QRhiBuffer \a buf created with the type
QRhiBuffer::Dynamic.
@@ -4997,6 +5015,12 @@ void QRhiResourceUpdateBatchPrivate::merge(QRhiResourceUpdateBatchPrivate *other
textureOps.append(op);
}
+bool QRhiResourceUpdateBatchPrivate::hasOptimalCapacity() const
+{
+ return bufferOps.count() < BUFFER_OPS_STATIC_ALLOC - 16
+ && textureOps.count() < TEXTURE_OPS_STATIC_ALLOC - 16;
+}
+
/*!
Sometimes committing resource updates is necessary without starting a
render pass. Not often needed, updates should typically be passed to
diff --git a/src/gui/rhi/qrhi_p.h b/src/gui/rhi/qrhi_p.h
index d8e54fc9aa..1e86cbc04a 100644
--- a/src/gui/rhi/qrhi_p.h
+++ b/src/gui/rhi/qrhi_p.h
@@ -1403,6 +1403,7 @@ public:
void release();
void merge(QRhiResourceUpdateBatch *other);
+ bool hasOptimalCapacity() const;
void updateDynamicBuffer(QRhiBuffer *buf, int offset, int size, const void *data);
void uploadStaticBuffer(QRhiBuffer *buf, int offset, int size, const void *data);
diff --git a/src/gui/rhi/qrhi_p_p.h b/src/gui/rhi/qrhi_p_p.h
index ef27be6d7d..7fadcfcc1e 100644
--- a/src/gui/rhi/qrhi_p_p.h
+++ b/src/gui/rhi/qrhi_p_p.h
@@ -383,8 +383,10 @@ public:
}
};
- QVarLengthArray<BufferOp, 1024> bufferOps;
- QVarLengthArray<TextureOp, 256> textureOps;
+ static const int BUFFER_OPS_STATIC_ALLOC = 1024;
+ QVarLengthArray<BufferOp, BUFFER_OPS_STATIC_ALLOC> bufferOps;
+ static const int TEXTURE_OPS_STATIC_ALLOC = 256;
+ QVarLengthArray<TextureOp, TEXTURE_OPS_STATIC_ALLOC> textureOps;
QRhiResourceUpdateBatch *q = nullptr;
QRhiImplementation *rhi = nullptr;
@@ -392,6 +394,7 @@ public:
void free();
void merge(QRhiResourceUpdateBatchPrivate *other);
+ bool hasOptimalCapacity() const;
static QRhiResourceUpdateBatchPrivate *get(QRhiResourceUpdateBatch *b) { return b->d; }
};