Render to off-screen MTLTexture first, then draw to CAMetalLayer

370 views
Skip to first unread message

mrousavy

unread,
Dec 1, 2022, 11:10:52 AM12/1/22
to skia-discuss
This is both a Metal-related and a Skia related question, so I wasn't sure where to post this.

I have a MTLTexture, and want to draw that to the CAMetalLayer. 
I thought this would be a simple operation, but all Metal guides I found online seem to set up a lot of stuff (including a .metal shader) where I just wasn't sure if this is the optimal way.

Here's the code I currently have: https://gist.github.com/mrousavy/47d95acf8740ad0782c960b1e5f4359b, but this does not work and fails because something is incorrectly configured on the render pipeline..

Can anyone point me in the right direction to do this easily? 
I'm thinking about just setting up another Skia Surface/Canvas to do that drawing, but I think the overhead of that might be a waste of resources.

mrousavy

unread,
Dec 1, 2022, 11:24:34 AM12/1/22
to skia-discuss
Running the code fails at canvas->flush() for me with the following error:

validateRenderPassDescriptor:782: failed assertion `RenderPass Descriptor Validation Texture at colorAttachment[0] has usage (0x01) which doesn't specify MTLTextureUsageRenderTarget (0x04)`

Jim Van Verth

unread,
Dec 1, 2022, 1:00:37 PM12/1/22
to skia-d...@googlegroups.com
The RenderCommandEncoder at line 52 doesn't invoke a draw command. So you're setting up some state and not doing anything with it.

The error you're getting means that you're setting a texture that's not set up to be a rendertarget as an attachment for the renderpass. I'm not sure where that's happening -- in the code sample you sent it looks like you're setting the drawable texture as the attachment which should be fine.

--
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/101cd90d-67d6-4fd4-ba4f-2e35aafdb304n%40googlegroups.com.


--

Jim Van Verth | Software Engineer | jvan...@google.com | 919-210-7664

Trancy chu

unread,
Mar 9, 2023, 8:41:57 AM3/9/23
to skia-discuss
First your  ‘renderNewFrameToCanvas’ method not called in render()

then error:xxxhas usage (0x01) which doesn't specify MTLTextureUsageRenderTarget,
please check you texture usage where create it, usage should include MTLTextureUsageRenderTarget
Reply all
Reply to author
Forward
0 new messages