Rendering with a rasterization rate map
Create offscreen textures to hold intermediate rasterized data.
Overview
You don’t render data directly to the final render destination using variable rasterization rates. Instead, you allocate textures to use as intermediate targets. You get the sizes for these textures from the rate map. For example, if you specified a rate of 0.5 everywhere, the intermediate texture is half the height and width of the final render target.
The MTLRasterizationRateMap protocol screenSize property gives the dimensions of the final render target. Call the physicalSize(layer:): method on the rate map object to get the size for each layer. Then allocate the textures you need. For example, the following code gets the physical size and allocates a color texture and a depth texture of that size:
To use variable rasterization rates, create a render pass, specifying the intermediate textures as the render targets. Set the rasterizationRateMap property to the rate map you created, as shown below:
After rendering with a rasterization rate map, you need to scale the intermediate textures to fill your destination texture. To convert between screen space and physical fragment space in your shader, bind the rate map data buffer to the shader with type rasterization_rate_map_data, then construct rasterization_rate_map_decoder with the buffer data. For more details, see the “Variable Rasterization Rate” section of the Metal Shading Language Specification and Scaling variable rasterization rate content.