Memoryless textures with multiple command encoders

Viewed 230

Is memoryless textures available to use with multiple MTLRenderCommandEncoders? For example(in theory) I creating command encoder #1 and memoryless texture #1 and using it as render target, then creating command encoder #2 and memoryless texture #2 as render target but using texture #1 as argument in fragment shader(read only access). Would this work?

1 Answers

Short answer: No, this wouldn't work. You have to do it in a single render command encoder.

I'm guessing you want to read the contents of the whole texture in render encoder #2, which is not possible on tile-based Apple GPUs (the only GPUs that run Metal that will actually support memoryless render targets). If you want to read anything apart from contents of the current tile, you have to store the attachment out to system memory, that's just how tile-based deferred renderers work. For more info refer to this talk and other WWDC talks about tile shaders and game optimizations.

Long answer: At the end of a render encoder, Metal has to execute a store action of your choosing that you passed through MTLRenderPassDescriptor. The reason it has to do it, is that there is a bunch of internal synchronization including fences and barriers that ensures that the next encoder that actually uses the attachments of previous encoder as render targets or a sampled texture can read whatever was written there.

Hope this answers your question.

Related