I can't find any examples online for how to do full-screen antialiasing with Metal. The only thing that comes up with Google is the Apple doc page for MTLRenderPassAttachmentDescriptor. Does anyone know of any sample code or examples that describe how to do this?
So there are 2 ways to get MSAA to work.
1) Create a texture with a sampleCount greater than one. This texture will serve as the MSAA texture you will render to. You may also want to create a depth or stencil texture with matching sampleCounts. (On iOS, you can likely make this texture a "memoryless" texture)
2) Create (or obtain) a single sampled color (and/or depth stencil) texture that you want resolve into. This will serve as the downsampled version of the texture Metal will resolve into to. I say "or obtain" previously because this texture is often the drawable's texture obtained from the CAMetalLayer or MTKView. If this is the case, you don't create the texture yourself.
5) Set the texture you obtained in step 2 as the attachment's '
resolveTexture
' for the corresponding render attachment in the render pass descriptor6) Set the store action of the attachment in the render pass descriptor to 'MTLStoreActionMultisampleResolve'. This will tell Metal that when the render pass is complete, it should resolve your multisample rendering into the resolve texture.
As far as samples go, this Forward Plus With Tile Shading sample is the most recent and will run on iOS with an A11. This Adopting Metal II sample also uses MSAA and will run on macOS and is written in Swift.