Metal backend makeImageSnapshot not working

95 views
Skip to first unread message

Giuseppe

unread,
Apr 16, 2022, 4:04:18 AM4/16/22
to skia-discuss
Hello,

I'm having issues with makeImageSnapshot, which apparently returns an empty image. 

The surface is created using SkSurface::MakeFromMTKView and the context using GrDirectContext::MakeMetal.

Any idea how to get the makeImageSnapshot working?

My code is very simple, I just draw a rect, take a snapshot, and then redraw only the snapshot.

Also, another question comes to my mind: is the metal backend considered stable or it's still a work in progress?

Thanks! :)

Greg Daniel

unread,
Apr 16, 2022, 7:20:36 AM4/16/22
to skia-discuss
The metal backend is stable. Is it possible that you're creating your original metal object with the framebufferOnly flag set? In that case it can't be used as an image since it can't be read.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/2a1c5c0f-cd79-40ab-9f9a-9a4d2ce8c2dan%40googlegroups.com.

Giuseppe

unread,
Apr 16, 2022, 8:48:52 AM4/16/22
to skia-discuss
That's great to hear that the metal backend is stable, and you're correct about frameBufferOnly, my mtkview had the flag set to true by default. Setting it to false solves the issue, thanks! 

I have one last question about the SkSurface: I see that I can't reuse the surface between frames, because the view drawable changes. Could re-creating the surface each frame have a negative performance impact? Any way to reuse the surface or suggestions? 

Greg Daniel

unread,
Apr 18, 2022, 10:25:41 AM4/18/22
to skia-discuss
Others with more metal background may be able to correct me, but I believe, as you're seeing, the MTLView gives you a new MTLTexture every frame and you can't depend on getting the same set of textures each time (unlike say Vulkan swapchains which gives you N specific VkImages it rotates through). So unfortunately you will have to recreate the SkSurface every frame. However, since you are just wrapping an already created MTLTexture, the cost of recreating an SkSurface should be fairly cheap. It is mostly the cost of a malloc for the object itself.

Giuseppe

unread,
Apr 19, 2022, 1:03:08 PM4/19/22
to skia-discuss
Great, that was my suspiction. Thanks for confirming and the quick replies!
Reply all
Reply to author
Forward
0 new messages