How can I split a single Metal render output across multiple views?

58 views Asked by At

I am trying to render using Metal into a set of 100 views in an NSCollectionView (as an example). I am able to render into each view separately, but the setup time of a render for a single view far outweighs the time for a render, and for 100 views at 120Hz I am passing 12000 commandBuffers each containing one render command to the GPU, which is horrendously slow.

An approach I am trying to take to solve this is to render the contents of all 100 views onto a single drawable, and then somehow distribute sections of that drawable across multiple views. I have tried rendering in to one CAMetalLayer and reusing/transforming it, but a layer can only be attached to one view at a time (and I suspected this would be inefficient anyway).

A working example of the naive implementation (writing directly to individual views) can be found here https://github.com/SirWhiteHat/MetalPerformanceProblem

I have explored the following:

Multiple Render Targets in Metal - addresses drawing the same vertices but with different colorAttachments by modifying the fragment shader, but I need to be able to draw different vertices on to different views which is quite different.

https://developer.apple.com/documentation/metal/textures/creating_and_sampling_textures - I hoped to find clues as to how to take a rendered texture and split it across views, but this seems to address the opposite; taking a texture and rendering it across a quadrangle to a single view, which still leaves me with "how do I split this across multiple views".

I have also found many examples of ways to draw efficiently into a single view, but not something that can then split my result across multiple views.

This question is a follow-up and clarification with more specificity from my previous question Rendering into multiple views with Metal

This may actually be more of a Cocoa question (given a finished Metal drawable, how can I distribute its contents across multiple views?), but I suspect that there will be involvement from Metal itself somehow.

Thank you!

0

There are 0 answers