Handling MSAA Depth with Programmable Sample Positions

Use depth render targets and programmable sample positions effectively.


Depth data for render targets is usually stored in a compressed format that requires evaluation at specific sample positions for proper decompression. Depth render targets can now specify a MTLStoreActionOptionCustomSamplePositions option that stores depth data in a sample-position-agnostic representation.

Setting the MTLStoreActionOptionCustomSamplePositions option indicates that the depth data will be read in a subsequent render pass, or blit operation, that's unaware of the programmable sample positions used to generate the data. For example, reading per-sample depth data within a fragment function that uses different programmable sample positions; or, issuing a copy operation from the MSAA depth data to another resource.

If you specify a MTLStoreActionOptionCustomSamplePositions option, Metal may decompress the depth render target and store the resulting data in its decompressed form. If you don't change programmable sample positions in a subsequent render pass, specify a MTLStoreActionStore action instead with the MTLStoreActionOptionNone option to improve performance.

See Also

Using Programmable Sample Positions

Positioning Samples Programmatically

Configure the position of samples when rendering to a multisampled render target.


A sample position on a subpixel grid.


Returns a new sample position on a subpixel grid.

- setSamplePositions:count:

Sets the programmable sample positions for a render pass.

- getSamplePositions:count:

Retrieves the programmable sample positions set for a render pass.