Repository navigation
Description
Traditionally, the density of fragment shader invocations for a given triangle is constant across the framebuffer. Variable Rasterization Rate is a feature that can run more fragment shader invocations in areas of high importance, and fewer fragment shader invocations in areas of low importance.
Motivation
The main motivation for variable rasterization rate is to increase performance by decreasing the total number of fragment shader invocations. This means that using this feature is “lossy” in that it negatively effects the resulting rendering. However, the density of fragment shader invocations is finely tunable, which means that its effect can be tweaked to find a good balance between performance and quality.
Apple released a Metal sample recently which uses variable rate rasterization on the Amazon Lumberyard Bistro scene. It includes a flag which can be used to trivially turn variable rasterization rate on and off. The sample is open source, so it’s easy to add tracking information to gather frame times. Here are the results:
Using variable rasterization rate for this scene causes a 31% reduction in frame time (which corresponds to a 45% increase in fps). Here are the images of variable rasterization rate on and off, so you can judge the quality:
To me, the visual quality looks quite comparable.
Difficulty
This feature has lots of effects in various parts of the API. It affects things like sample shading, multisampling, and shader derivative functions. Fully specifying this and finding the parts that are interoperable will take time.
Vulkan
VK_NV_shading_rate_image and SPV_NV_shading_rate: 4% Windows, 2% Linux, 0% Android. The shading rate is represented as a uint8 texture, where each texel represents a 16x16 block of pixels in the framebuffer. The texture itself isn’t put into bind groups like other textures; instead, it’s just bound with a special-purpose command enqueued into the command buffer.
The meaning of each texel is an index into a palette. The palette is defined at pipeline creation time, and if the device supports it, can be modified by a command enqueued into the command buffer. The palette itself is a 1d array of enums, where each enum defines a particular rate (e.g. VK_SHADING_RATE_PALETTE_ENTRY_2_INVOCATIONS_PER_PIXEL_NV).
Optionally, you can also configure the sample locations for each of these enum values.
D3D12
There are two tiers of support. The first tier only lets you set a single scalar (via a command list command) which affects the rasterization rate for any successive draw commands.
The second tier lets you bind a texture as a rate map via a command list command. Each texel in the texture represents a tile in the framebuffer, and you can query the tile size. There’s no “palette” like in Vulkan. The values in the rate map represent the enum density enum values themselves.
Interestingly, you can’t render to the texture being used as the rate map. The only ways you can populate it are to write into it via a UAV, or copy into it.
Also, the second tier adds support for SV_ShadingRate, a semantic emitted by the vertex / geometry shader which controls the rasterization rate at a per-triangle granularity. It’s present in Shader Model 6.4.
Because there are 3 different ways of specifying rasterization rates (a per-draw-call scalar, a rate map in a texture, and a per-triangle semantic), D3D includes a system of “combiners” which combine these 3 signals into a final rasterization rate. These combiners are configurable.
Metal
Support is only present in iOS, not macOS. You can create a MTLRasterizationRateMap, but this doesn’t hold a texture. Instead, you give it two 1-D arrays of scalar values. These scalar values can vary between 1.0, which represents full resolution shading, and 0.0, which represents minimum resolution shading. The arrays get mapped (stretched) across the width and height of the framebuffer, respectively. Therefore, for a particular region of the framebuffer, that region’s rate is proportional to one of the scalars in the first array and another one fo the scalars in the second array.
In order to use the rate map, you have to do a two-pass algorithm. In the first pass, you render your scene into a small texture using the rate map. Then, for the second pass, you render your scene into the normal-sized framebuffer, and sample from the output texture of the first pass.
You ask the rate map for the size of that intermediate texture, and use the rate map by specifying it in the render pass descriptor. If you look at this texture directly, straight lines in the image will look curved because the rasterization rate changes throughout the image. In the second pass, you have to know where to sample the small texture in the correct place. You do this by telling the rate map to copy itself into a MTLBuffer, and binding the buffer as a resource in the shader. The shading language includes a new opaque type, rasterization_rate_map_data, which exposes an API to let you convert between arbitrary points on the real destination and the input texture.
Recommendation
The palette only exists in Vulkan. The per-draw-call rasterization scalar can’t be represented in Metal without interrupting the render pass. The per-triangle HLSL semantic also can’t be represented in Metal. The texture-based rasterization map also can’t be represented in Metal, because Metal only lets you specify two 1-D arrays. However, the Metal approach can be represented in both Vulkan and D3D by expanding those two 1D arrays into a full texture.
In the interest of interoperability, having a single WebGPU extension that works the same way on all platforms / native APIs is valuable. A good place to start would be a single extension that represents the Metal feature set because it can provide benefit on all platforms / native APIs. The two passes would probably be handled similarly to how we handle multisample resolves today, except the runtime would allocate the intermediate texture. If there is demand for the non-portable features of the other APIs (e.g. the palette, or the per-triangle semantic), then we can consider those for additional extensions.

Activity
add todos in createView tests (gpuweb#450)
Kangz commentedon Sep 8, 2023
mwyrzykowski commentedon Mar 25, 2026
This issue is a few years old but macOS now supports VRR as well
AlbinBernhardssonARM commentedon Mar 31, 2026
For Vulkan, there is now the cross-vendor
VK_KHR_fragment_shading_rate, which basically matches VRS in DX12. The shading rate can be set per-pipeline, per-primitive and with a shading rate attachment. They can be combined with combiner ops.There is no per-pipeline defined palette. See the GLSL extension for how they're encoded.
In typical Vulkan fashion, rather than having different tiers, each feature is independent and has to be queried. It is theoretically possible to have a device which support only shading rate attachments but not per-pipeline/per-primitive shading rates, though this seems unlikely.
The supported shading rates are queried with
vkGetPhysicalDeviceFragmentShadingRatesKHRand interact with the MSAA sample count and pre-rotation. Note that eg. a device which supports 4x4 might support 2x4 but not 1x4 (this is true for Arm and Nvidia). It's also theoretically possible for a device to support 2x4 but not 4x2 (I don't know if such a device exists).For the shading rate attachment, the size each texel represents is configurable, but many devices expose only a single configuration. AMD supports 8x8. Nvidia supports 16x16. Arm supports 8x8, 16x16 and 32x32.
Combiner ops are split into trivial and non-trivial. Trivial ones are KEEP/REPLACE, which are always supported. MIN/MAX/MUL need
fragmentShadingRateNonTrivialCombinerOps. The first Mali generation with VRS (G715) did not support this but it was added in G720.It's important to note that variable rasterization rate in Metal controls the rasterization rate*. VRS only controls the fragment shading rate, but leaves the rasterization rate intact. These are similar, but not the same. VRS preserves geometry detail, as rasterization still happens at the full rate. This also means it writes out the full framebuffer, just some texels will have the same value (one fragment shader invocation result written to multiple texels). VRS only saves on fragment shader invocations, not write BW (though saving fragment shader invocations can improve read BW).
There is a Vulkan extension which more closely resembles VRR in Metal:
VK_EXT_fragment_density_map(and the follow-upVK_EXT_fragment_density_map2).VK_EXT_fragment_density_mapis available on more mobile devices thanVK_KHR_fragment_shading_rate(true even if requiring v2), but on desktop the situation is the opposite.Vulkan-Samples has samples for fragment shading rate and fragment density map.
* Not a Metal expert. This is how I have understood it.
kainino0x commentedon Mar 31, 2026
It sounds like Metal only has VRR and D3D12 only has VRS, then? That probably throws a wrench in any efforts to make a backend-portable extension...
AlbinBernhardssonARM commentedon Apr 2, 2026
Regarding the shading rate attachment / density map:
In VRS, the shading rate attachment is just an R8 image which encodes the shading rate. It can be written to like any normal image (render pass, compute shader). It's read at the start of the render pass which uses it (
VK_PIPELINE_STAGE_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR). So you could either upload the data from CPU (eg. from some XR API) or generate it on the GPU by eg. looking at motion vectors to determine areas of the screen that will be motion blurred and so can be done in lower detail.In FDM, the density map is read at different points depending on image view creation flags:
vkCmdBeginRenderPass(on host!)fragmentDensityMapVK_IMAGE_VIEW_CREATE_FRAGMENT_DENSITY_MAP_DEFERRED_BIT_EXTvkEndCommandBuffer(on host!)fragmentDensityMapDeferredVK_IMAGE_VIEW_CREATE_FRAGMENT_DENSITY_MAP_DYNAMIC_BIT_EXTVK_PIPELINE_STAGE_FRAGMENT_DENSITY_PROCESS_BIT_EXT)fragmentDensityMapDynamicThus, only with
fragmentDensityMapDynamiccan you generate an attachment on the GPU at run-time (eg. the motion vector example). Otherwise the density map has to be known at encode time.Whether using VRS or FDM, the shading rate attachment / density map handed to us by the user will need to be sanitized.
In VRS, the shading rate attachment shouldn't contain shading rates > 4.
In FDM, the density map shouldn't contain 0.
Regarding the render targets you render into when using VRS/FDM:
VRS: Just a regular attachment. Nothing special.
FDM: Has to be created with
VK_IMAGE_CREATE_SUBSAMPLED_BIT_EXTunlessfragmentDensityMapNonSubsampledImages. Subsampled images have a number of restrictions. Most importantly they can only be sampled from through special samplers.Interaction with multiview:
Both VRS and FDM support creating shading rate attachments / density maps with multiple layers and will use the same layer index as the attachments being rendered into. So you can have a separate shading rate attachment / density map per view.
kainino0x commentedon Apr 3, 2026
Commenting to mention WebXR, just for searchability, since this is relevant to WebXR.
Kangz commentedon Apr 28, 2026
GPU Web WG 2026-04-01 Atlantic-time
cabanier commentedon May 27, 2026
I put a proposal here: #6271