Loading the resolveTexture?

I have a painting app and I'm trying to add a layers feature. My latest confusion over disappearing brush strokes leads to this code...


let rpd = MTLRenderPassDescriptor()

rpd.colorAttachments[0].texture = sharedMultiSampleTexture

rpd.colorAttachments[0].resolveTexture = layer.flattened

rpd.colorAttachments[0].loadAction = .load

rpd.colorAttachments[0].storeAction = .multisampleResolve

let renc = commandBuffer.makeRenderCommandEncoder(descriptor: rpd)

[ ... draw brush marks ... ]


I'm trying to render anti-aliased shapes to the MTLTexture `layer.flattened` and have them accumulate over multiple passes through this code. I think the `loadAction = .load` would accumulate results, if I weren't using multisampling. But it seems the resolveTexture is cleared and overwritten every time. Is there no equivalent of `loadAction = .load` for the resolve texture? ... Or maybe I've misdiagnosed the problem completely...


Rob

Replies

This line:


rpd.colorAttachments[0].loadAction = .load


Loads the contents of sharedMultiSampleTexture not the resolve texture. When performing multisample antialiasing, all your rendering goes to sharedMultiSampleTexture. Nothing is directly drawing to layer.flattened. When your render pass ends, the .multisampleResolve action you specify, indicates that the high density pixels you've drawn should be resolved to layer.flattened. This completely overwrites the contents of layer.flattened.


I'm not clear on exactly what you're trying to accomplish with brush strokes, but I think the problem could be resolve by your setting the store action to .storeAndMultisampleResolvefor the store action as follows:


rpd.colorAttachments[0].storeAction = .storeAndMultisampleResolve


This will store the contents of sharedMutliSample texture so that your .load action will load those contents written in a previous pass (or brush strokes)

Okay, I see. Now that I've added layers to the drawing app, I have more MTLTextures hanging around, and I'm worried about using too much memory. So I didn't want to a multisampled MTLTexture in each layer. I may add another step (using either a render or compute encoder) to copy the `resolveTexture` to the layer's texture, which is accumulating the drawing.


Rob