summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/rhi/qrhi.cpp6
-rw-r--r--src/gui/rhi/qrhimetal.mm11
-rw-r--r--tests/manual/rhi/multiwindow_threaded/multiwindow_threaded.cpp4
3 files changed, 17 insertions, 4 deletions
diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp
index d7c1607e57..a29c7e263e 100644
--- a/src/gui/rhi/qrhi.cpp
+++ b/src/gui/rhi/qrhi.cpp
@@ -260,6 +260,12 @@ QT_BEGIN_NAMESPACE
tied to those concepts, however, and is thus a topic that is currently out
of scope, but may be introduced in the future.
+ \note The Metal backend requires that an autorelease pool is available on
+ the rendering thread, ideally wrapping each iteration of the render loop.
+ This needs no action from the users of QRhi when rendering on the main
+ (gui) thread, but becomes important when a separate, dedicated render
+ thread is used.
+
\section3 Resource synchronization
QRhi does not expose APIs for resource barriers or image layout
diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm
index fa537a504b..98b2a9bcac 100644
--- a/src/gui/rhi/qrhimetal.mm
+++ b/src/gui/rhi/qrhimetal.mm
@@ -57,7 +57,8 @@ QT_BEGIN_NAMESPACE
Textures are Private (device local) and a host visible staging buffer is
used to upload data to them. Does not rely on strong objects refs from
command buffers but does rely on the automatic resource tracking of the
- command encoders.
+ command encoders. Assumes that an autorelease pool (ideally per frame) is
+ available on the thread on which QRhi is used.
*/
#if __has_feature(objc_arc)
@@ -1214,10 +1215,12 @@ QRhi::FrameOpResult QRhiMetal::endFrame(QRhiSwapChain *swapChain, QRhi::EndFrame
Q_ASSERT(currentSwapChain == swapChainD);
const bool needsPresent = !flags.testFlag(QRhi::SkipPresent);
- if (needsPresent) {
+ if (needsPresent)
[swapChainD->cbWrapper.d->cb presentDrawable: swapChainD->d->curDrawable];
- swapChainD->d->curDrawable = nil;
- }
+
+ // Must not hold on to the drawable, regardless of needsPresent.
+ // (internally it is autoreleased or something, it seems)
+ swapChainD->d->curDrawable = nil;
__block int thisFrameSlot = currentFrameSlot;
[swapChainD->cbWrapper.d->cb addCompletedHandler: ^(id<MTLCommandBuffer>) {
diff --git a/tests/manual/rhi/multiwindow_threaded/multiwindow_threaded.cpp b/tests/manual/rhi/multiwindow_threaded/multiwindow_threaded.cpp
index 8fda2b73c8..53185bddb2 100644
--- a/tests/manual/rhi/multiwindow_threaded/multiwindow_threaded.cpp
+++ b/tests/manual/rhi/multiwindow_threaded/multiwindow_threaded.cpp
@@ -290,6 +290,10 @@ struct Renderer
void Thread::run()
{
while (active) {
+#ifdef Q_OS_DARWIN
+ QMacAutoReleasePool autoReleasePool;
+#endif
+
if (pendingRender) {
pendingRender = false;
renderer->render(pendingRenderIsNewExpose, false);