summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAurélien Brooke <aurelien@bahiasoft.fr>2022-12-18 15:58:08 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-12-20 09:39:19 +0000
commite4aa207c0286ad568e03e849ec93d915e4b83616 (patch)
tree665d02e2eb16f3043576ec5a1a8bd2750da98a00
parentcb8f6ff206b4c966b6ab1fd185236602d520f96f (diff)
downloadqt3d-e4aa207c0286ad568e03e849ec93d915e4b83616.tar.gz
RHI: fix the leak of QRhiResourceUpdateBatch
There are 2 ways to dispose of a QRhiResourceUpdateBatch obtained with QRhi::nextResourceUpdateBatch(): 1) Either give it to beginPass/endPass/beginComputePass/endComputePass so it is sent to the RHI backend and then automatically released; 2) or call QRhiResourceUpdateBatch::release() if the resource update is not used for any pass. The Qt3D RHI renderer was never disposing of the QRhiResourceUpdateBatch, and could end up exhausting all the 64 batches available in the RHI: "Resource update batch pool exhausted (max is 64)", in addition to consuming a lot of RAM if the buffers or textures are large. To fix this, ensure the QRhiResourceUpdateBatch'es we allocate are always released: when requesting a new one, send the previous one to endPass/endComputePass (1), and when destroying the SubmissionContext, release the one we will not use (2). Change-Id: Ic3fb145b11a8e615c83745f560f019e6c4ee37f7 Reviewed-by: Paul Lemire <paul.lemire@kdab.com> (cherry picked from commit 6b6465032f103a084e416cbddf03f8e83191aea2) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp5
-rw-r--r--src/plugins/renderers/rhi/renderer/renderer.cpp4
2 files changed, 7 insertions, 2 deletions
diff --git a/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp b/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp
index c0afedfdb..0d3ef1e1b 100644
--- a/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp
+++ b/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp
@@ -804,6 +804,11 @@ void SubmissionContext::releaseResources()
m_renderBufferHash.clear();
RHI_UNIMPLEMENTED;
+ if (m_currentUpdates) {
+ m_currentUpdates->release();
+ m_currentUpdates = nullptr;
+ }
+
// Free RHI resources
{
qCDebug(Backend) << Q_FUNC_INFO;
diff --git a/src/plugins/renderers/rhi/renderer/renderer.cpp b/src/plugins/renderers/rhi/renderer/renderer.cpp
index 66b40c21c..45485a6c7 100644
--- a/src/plugins/renderers/rhi/renderer/renderer.cpp
+++ b/src/plugins/renderers/rhi/renderer/renderer.cpp
@@ -2715,7 +2715,7 @@ bool Renderer::executeCommandsSubmission(const RHIPassInfo &passInfo)
if (rv->isCompute()) {
// If we were running draw calls we stop the draw pass
if (inDraw) {
- cb->endPass();
+ cb->endPass(m_submissionContext->m_currentUpdates);
m_submissionContext->m_currentUpdates = m_submissionContext->rhi()->nextResourceUpdateBatch();
inDraw = false;
}
@@ -2734,7 +2734,7 @@ bool Renderer::executeCommandsSubmission(const RHIPassInfo &passInfo)
} else {
// Same logic than above but reversed
if (inCompute) {
- cb->endComputePass();
+ cb->endComputePass(m_submissionContext->m_currentUpdates);
m_submissionContext->m_currentUpdates = m_submissionContext->rhi()->nextResourceUpdateBatch();
inCompute = false;
}