diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2020-10-13 19:29:00 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2020-10-16 09:48:09 +0200 |
commit | 0461c535fcb26ea231ee8645e67ef2e8d4429e95 (patch) | |
tree | edfaba6cc782e0a3c281d28aa2956ae2a3ddedd4 /src/gui/rhi/qrhi_p_p.h | |
parent | 802d98d318d1dabf377d1030b81e99fe57f1b483 (diff) |
rhi: Further reduce copying in the command buffer
Change-Id: I2e2ff5f4b8aa91d0accb01108a5199b98c371455
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
Diffstat (limited to 'src/gui/rhi/qrhi_p_p.h')
-rw-r--r-- | src/gui/rhi/qrhi_p_p.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/gui/rhi/qrhi_p_p.h b/src/gui/rhi/qrhi_p_p.h index 491f0c6f26..8a85227bae 100644 --- a/src/gui/rhi/qrhi_p_p.h +++ b/src/gui/rhi/qrhi_p_p.h @@ -655,6 +655,38 @@ private: Q_DECLARE_TYPEINFO(QRhiPassResourceTracker::Buffer, Q_MOVABLE_TYPE); Q_DECLARE_TYPEINFO(QRhiPassResourceTracker::Texture, Q_MOVABLE_TYPE); +template<typename T, int GROW = 1024> +class QRhiBackendCommandList +{ +public: + QRhiBackendCommandList() = default; + ~QRhiBackendCommandList() { delete v; } + inline void reset() { p = 0; } + inline bool isEmpty() const { return p == 0; } + inline T &get() { + if (p == a) { + a += GROW; + T *nv = new T[a]; + if (v) { + memcpy(nv, v, p * sizeof(T)); + delete[] v; + } + v = nv; + } + return v[p++]; + } + inline void unget() { --p; } + inline T *cbegin() const { return v; } + inline T *cend() const { return v + p; } + inline T *begin() { return v; } + inline T *end() { return v + p; } +private: + Q_DISABLE_COPY(QRhiBackendCommandList) + T *v = nullptr; + int a = 0; + int p = 0; +}; + QT_END_NAMESPACE #endif |