-
Notifications
You must be signed in to change notification settings - Fork 24
Fix Metal command buffer ownership in command lists #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1196,8 +1196,6 @@ namespace plume { | |
| // Create texture with configured descriptor and alignment | ||
| MTL::TextureDescriptor *descriptor = MTL::TextureDescriptor::textureBufferDescriptor(pixelFormat, width, options, usage); | ||
| this->texture = buffer->mtl->newTexture(descriptor, 0, bytesPerRow); | ||
|
|
||
| descriptor->release(); | ||
| } | ||
|
|
||
| MetalBufferFormattedView::~MetalBufferFormattedView() { | ||
|
|
@@ -2238,7 +2236,9 @@ namespace plume { | |
| } | ||
|
|
||
| MetalCommandList::~MetalCommandList() { | ||
| mtl->release(); | ||
| if (mtl != nullptr) { | ||
|
DarioSamo marked this conversation as resolved.
|
||
| mtl->release(); | ||
| } | ||
|
|
||
| for (auto& fenceSet : fences) { | ||
| for (auto* fence : fenceSet) { | ||
|
|
@@ -2253,6 +2253,7 @@ namespace plume { | |
| assert(mtl == nullptr); | ||
| startedEncoding = false; | ||
| mtl = queue->mtl->commandBufferWithUnretainedReferences(); | ||
| mtl->retain(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding a retain here is right but also needs an autorelease pool around this function. |
||
| mtl->setLabel(MTLSTR("RT64 Command List")); | ||
|
|
||
| // Reset fence waits and updates for new command list. | ||
|
|
@@ -3551,6 +3552,7 @@ namespace plume { | |
| if (activeBlitEncoder == nullptr) { | ||
| activeBlitEncoder = mtl->blitCommandEncoder(device->sharedBlitDescriptor); | ||
| activeBlitEncoder->setLabel(MTLSTR("Copy Blit Encoder")); | ||
| activeBlitEncoder->retain(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A brief review of all "commandEncoder" command tells me not every one of them are using retain() and some are using release() despite that. CC @squidbus should all command encoders need to manually increase and decrease the refcount when created and destroyed?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 I was hesitant to make more sweeping changes than were necessary to stop crashes. My read is that pointers that can escape the function should be retained/released but I'm far from an expert at this stuff.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, retain here is right but needs an autoreleasepool around this. These were also addressed in #95, there's a missing pair for
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Only if it's kept outside the scope of the function, otherwise an autoreleasepool will free it. Although these missing retains did not have an autoreleasepool so they were living longer.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it worth just waiting for #95 to merge then?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd be best to clean up the logic of auto-release pools in that PR for sure, and then we can look at retain()/release() logic to be done where it's necessary. |
||
|
|
||
| startedEncoding = true; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the opposite problem, we did not own TextureDescriptor and the autorelease pool (?) should take care of it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to add an autoreleasepool to this function then.