Learn about accessing multisample tracking data within a tile shader, enabling development of custom MSAA resolve algorithms, and more.
Multisample antialiasing (MSAA) is a technique used to improve the appearance of primitive edges by using multiple depth and color samples for each pixel. Figure 1 shows a triangle rendered without MSAA. Because each pixel has a single sample position, it’s either covered or not covered by the triangle, leading to jagged edges.
Figure 2 shows the same triangle rendered using 4x MSAA; that is, each pixel has four sampling positions. The graphics processing unit (GPU) averages the colors of each sample within the pixel to determine a final color. This process results in a smoother appearance and reduces the jagged edges.
Apple’s A-Series GPUs have an efficient MSAA implementation. The hardware tracks whether each pixel contains a primitive edge so that your blending executes per sample only when necessary. If all samples in a pixel are covered by a single primitive, the GPU blends only once for the entire pixel.
Imageblock Sample Coverage Control
Metal 2 on A11 tracks the number of unique samples (or colors) for each pixel, updating this information as new primitives are rendered. For example, the pixel in Figure 3 contains the edges of two overlapping triangles, and the sample positions are covered by three unique colors. In current A-Series GPUs, this pixel blends each of the three covered samples. On the A11 GPU, this pixel blends only twice because two of the covered samples share the same color. In this case, the color at index 1 is a blend of green and pink, and the color at index 2 is pink.
Metal 2 on A11 can reduce the number of unique colors in a pixel. In Figure 4, an additional opaque triangle is rendered on top of the earlier primitives. Because all of the samples are covered by the new triangle and can be represented by a single color, the A11 GPU merges the three colors into one.
Additionally, you can access and modify sample coverage data in tile shaders to implement custom resolve algorithms. For example, given a complex scene containing separate render phases for opaque and translucent geometry, you can add a tile shader to resolve the sample data for the opaque geometry before blending the translucent geometry. With Metal 2 on A11, this tile shader works on data in local memory and can be part of the opaque geometry phase, as shown in Figure 5.