Add scoped autoreleasepool to tests and examples

This ensures ObjC objects do not leak. On non-Apple
platforms, the scope does nothing.

Fixed: dawn:546
Change-Id: Id43702e6536bf9cb37825a5449511e10cf0734f5
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/55841
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Austin Eng
2021-06-24 19:21:31 +00:00
committed by Dawn LUCI CQ
parent b911a96fcd
commit 700a5fb869
13 changed files with 169 additions and 8 deletions

View File

@@ -61,7 +61,7 @@ namespace dawn_native { namespace metal {
// The encoder is created autoreleased. Retain it to avoid the autoreleasepool from
// draining from under us.
mBlit = [*mCommands blitCommandEncoder];
mBlit.Acquire([[*mCommands blitCommandEncoder] retain]);
}
return mBlit.Get();
}
@@ -82,9 +82,9 @@ namespace dawn_native { namespace metal {
ASSERT(!mInEncoder);
mInEncoder = true;
// The encoder is created autoreleased. Retain it to avoid the autoreleasepool from draining
// from under us.
mCompute = [*mCommands computeCommandEncoder];
// The encoder is created autoreleased. Retain it to avoid the autoreleasepool from
// draining from under us.
mCompute.Acquire([[*mCommands computeCommandEncoder] retain]);
return mCompute.Get();
}
@@ -104,9 +104,9 @@ namespace dawn_native { namespace metal {
ASSERT(!mInEncoder);
mInEncoder = true;
// The encoder is created autoreleased. Retain it to avoid the autoreleasepool from draining
// from under us.
mRender = [*mCommands renderCommandEncoderWithDescriptor:descriptor];
// The encoder is created autoreleased. Retain it to avoid the autoreleasepool from
// draining from under us.
mRender.Acquire([[*mCommands renderCommandEncoderWithDescriptor:descriptor] retain]);
return mRender.Get();
}

View File

@@ -308,7 +308,8 @@ namespace dawn_native { namespace metal {
// The MTLCommandBuffer will be autoreleased by default.
// The autorelease pool may drain before the command buffer is submitted. Retain so it
// stays alive.
mCommandContext = CommandRecordingContext([*mCommandQueue commandBuffer]);
mCommandContext =
CommandRecordingContext(AcquireNSPRef([[*mCommandQueue commandBuffer] retain]));
}
return &mCommandContext;
}