Page MenuHome

Metal: Fix memory leaks.
ClosedPublic

Authored by Jason Fielder (jason_apple) on Nov 7 2022, 6:24 PM.

Details

Summary

Fix a number of small memory leaks in the Metal backend. Unreleased blit shader objects and temporary textures addressed. Static memory manager modified to defer creation until use. Added reference count tracker to shared memory manager across contexts, such that cached memory allocations will be released if all contexts are destroyed and re-initialized.

Authored by Apple: Michael Parkin-White

Ref T96261

Diff Detail

Repository
rB Blender

Event Timeline

Jason Fielder (jason_apple) requested review of this revision.Nov 7 2022, 6:24 PM
Jason Fielder (jason_apple) created this revision.
Clément Foucault (fclem) requested changes to this revision.Nov 22 2022, 12:12 PM

I am just unsure about this refcount not being atomic guarded. The rest of the patch looks good.

source/blender/gpu/metal/mtl_context.hh
609–612

Shouldn't these be protected for multithreading? (Render, IconRenderPreview etc...)

source/blender/gpu/metal/mtl_texture.hh
168–169

It is always good to provide default values to members.

This revision now requires changes to proceed.Nov 22 2022, 12:12 PM

I am just unsure about this refcount not being atomic guarded. The rest of the patch looks good.

Ah yes, this may be something I need to look into in a bit more depth across contexts. My previous understanding may have had a few holes, as I had previously thought certain aspects of context creation/deletion was thread-safe, in terms of exclusivity, due to its use of certain OpenGL calls during initialisation. However, while I know certain operations could happen asynchronously and such cases are handled by the memory manager, it may not account for all cases, such as this one.

I'll perform a dedicated pass of multi-threaded stress-testing and re-evaluate the implementation here. While an atomic counter would solve the ref count, other parts of the memory manager, such as the update_pools routine may need to be checked. Core allocation/de-allocation is thread-safe, but higher-level management is not always, due to previous assumptions on simultaneous GPU context use.

Thanks for raising this however!

Fix a number of small memory leaks in the Metal backend. Unreleased blit shader objects and temporary textures addressed. Static memory manager modified to defer creation until use. Added reference count tracker to shared memory manager across contexts, such that cached memory allocations will be released if all contexts are destroyed and re-initialized.

This revision is now accepted and ready to land.Dec 8 2022, 5:30 PM
This revision was automatically updated to reflect the committed changes.