Article

Handling MSAA Depth with Programmable Sample Positions

Use depth render targets and programmable sample positions effectively.

Overview

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 customSamplePositions option that stores depth data in a sample-position-agnostic representation.

Setting the customSamplePositions 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 customSamplePositions 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 MTLStoreAction.store 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.

struct MTLSamplePosition

A sample position on a subpixel grid.

func MTLSamplePositionMake(Float, Float) -> MTLSamplePosition

Returns a new sample position on a subpixel grid.

func setSamplePositions([MTLSamplePosition])

Sets the programmable sample positions for a render pass.

func getSamplePositions() -> [MTLSamplePosition]

Returns the programmable sample positions set for a render pass.