From d587d3fecd3557aa24eea5d9b6fc0e125d5f6eb6 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 24 Apr 2023 13:19:21 +0200 Subject: [PATCH] rhi: Improve deferred delete docs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I533e44d73ad1aebf72ef2e28c90c51f5effb8977 Reviewed-by: MÃ¥rten Nordheim --- src/gui/rhi/qrhi.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index 4a2ca82d45..cf822d0a74 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -2130,6 +2130,28 @@ QRhiResource::~QRhiResource() If the QRhi that created this object is already destroyed, the object is deleted immediately. + Using deleteLater() can be a useful convenience in many cases, and it + complements the low-level guarantee (that the underlying native graphics + objects are never destroyed until it is safe to do so and it is known for + sure that they are not used by the GPU in an still in-flight frame), by + offering a way to make sure the C++ object instances (of QRhiBuffer, + QRhiTexture, etc.) themselves also stay valid until the end of the current + frame. + + The following example shows a convenient way of creating a throwaway buffer + that is only used in one frame and gets automatically released (both the + underlying native objects and the C++ QRhiBuffer object) in endFrame(): + + \badcode + rhi->beginFrame(swapchain); + buf = rhi->newBuffer(...); + buf->deleteLater(); // ! + u = rhi->nextResourceUpdateBatch(); + u->uploadStaticBuffer(buf, data); + ... // draw with buf + rhi->endFrame(); + \endcode + \sa destroy() */ void QRhiResource::deleteLater()