Using Metal command queues

71 views
Skip to first unread message

mattl...@live.com

unread,
Aug 18, 2025, 7:40:43 PMAug 18
to skia-discuss
What is the best way to manage command queues when rendering with Metal? Assume I have one or more views on screen.

Do I create one queue and reuse? Does skia manage or release any queues?

I am getting crashes and it seems to be during parts of my view cleanup and things. I am not sure if I am supposed to hold onto things.

My current implememtation is to create a SKMetalView that has a queue for each instance. Then each drawe creates a command buffer.

When the views go out of scope, sometimes a crash will occur. Not 100% sure yet, but is related to the cleanup process.

Just for reference if it helps, this is my original issue that I am trying to solve: https://github.com/mono/SkiaSharp/issues/3178

The crash is pretty consistent, so it is not related to timing. Typically the crash will happen after the second time the view controller is closed.

mattl...@live.com

unread,
Aug 20, 2025, 4:13:24 AMAug 20
to skia-discuss
We were having a look at this code on the side of GrDirectContext::MakeMetal and we notice this (this is one of the deprecated ones):

sk_sp<GrDirectContext> GrDirectContext::MakeMetal(void* device, void* queue,
const GrContextOptions& options) {
sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kMetal, options));
GrMtlBackendContext backendContext = {};
backendContext.fDevice.reset(device);
backendContext.fQueue.reset(queue);

return GrDirectContext::MakeMetal(backendContext, options);
}

Should that sk_sp<GrDirectContext> direct(new GrDirectContext(GrBackendApi::kMetal, options)); line be there?

The call to MakeMetal at the bottom calls another function that also has this line, so it may be a merge issue?

But, I also see that the fDevice and fQueue are using reset. In other code around the repo, I have see retain used instead.

When should we be using reset vs retain?
Reply all
Reply to author
Forward
0 new messages