> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# RSSetShadingRateImage (XBOX Series consoles)

> The ID3D12GraphicsCommandList5::RSSetShadingRateImage method (d3d12.h) sets the screen-space shading-rate image for variable-rate shading (VRS).

Sets the screen-space shading-rate image for variable-rate shading (VRS). For more info, see [Variable-rate shading (VRS)](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/vrs).
This method requires Tier2 [Variable-rate shading (VRS)](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/vrs) support. See [**D3D12\_FEATURE\_DATA\_D3D12\_OPTIONS6**](/reference/graphics/d3d12/structs/d3d12_feature_data_d3d12_options6_public) and [**D3D12\_VARIABLE\_SHADING\_RATE\_TIER**](/reference/graphics/d3d12/enums/d3d12_variable_shading_rate_tier_public).

## Syntax

```cpp theme={null}
void RSSetShadingRateImage(
    ID3D12Resource  shadingRateImage
)
```

### Parameters

*shadingRateImage*\
Type: ID3D12Resource \*

An optional pointer to an [ID3D12Resource](/reference/graphics/d3d12_xs/interfaces/ID3D12Resource/id3d12resource_xs) representing a screen-space shading-rate image.
If **NULL**, the effect is the same as having a shading-rate image where all values are a shading rate of 1x1.

This texture must have the [**D3D12\_RESOURCE\_STATE\_SHADING\_RATE\_SOURCE**](/reference/graphics/d3d12_x/enums/d3d12_resource_states) state applied.

The tile-size of the shading-rate image can be determined via [**D3D12\_FEATURE\_DATA\_D3D12\_OPTIONS6**](/reference/graphics/d3d12/structs/d3d12_feature_data_d3d12_options6_public).
The size of the shading-rate image should therefore be

```
ceil((float)rtWidth / VRSTileSize), ceil((float)rtHeight / VRSTileSize)
```

The shading-rate image must be a 2D texture with a single mip, and format [**DXGI\_FORMAT\_R8\_UINT**](https://learn.microsoft.com/en-us/windows/win32/api/dxgiformat/ne-dxgiformat-dxgi_format). Each texel must be a value corresponding to [**D3D12\_SHADING\_RATE**](/reference/graphics/d3d12/enums/d3d12_shading_rate_public). It must have layout [**D3D12\_TEXTURE\_LAYOUT\_UNKNOWN**](/reference/graphics/d3d12_x/enums/d3d12_texture_layout) and can't be a depth-stencil, render-target, simultaneous-access, or cross-adapter resource.

As (0, 0) is the top left in DirectX, a too-small or large shading-rate image results in the bottom or right having no shading-rate image area, or the image extending in these directions. When there is excess, it is ignored (but legal), and when the image is too small, all out-of-bounds areas in the bottom and right will have the default shading rate of 1x1 from the image (however, this does not mean that is the final shading rate. The combiners will still be applied to this 1x1 default value).

### Return value

Type: void

None.

## Remarks

For the screen-space shading-rate image to take affect, [**ID3D12GraphicsCommandList5::RSSetShadingRate**](/reference/graphics/d3d12/interfaces/id3d12graphicscommandlist5/methods/id3d12graphicscommandlist5_rssetshadingrate_public) must have been called to set the combiners for shading. Else, with the default combiners (both [**D3D12\_SHADING\_RATE\_COMBINER\_PASSTHROUGH**](/reference/graphics/d3d12/enums/d3d12_shading_rate_combiner_public)), the screen-space shading-rate image is ignored in determining shading granularity.

The second combiner passed to  \[**ID3D12GraphicsCommandList5::RSSetShadingRate**] is the one which applies to the shading-rate image, which occurs after the global shading rate and the per-primitive shading rate have been combined.

The algorithm for final shading-rate is determined by

```cpp theme={null}
postRasterizerRate = ApplyCombiner(Combiners[0], CommandListShadingRate, Primitive->PrimitiveSpecifiedShadingRate);
finalRate = ApplyCombiner(Combiners[1], postRasterizerRate, ScreenSpaceImage[xy]);
```

where `ApplyCombiner` is

```cpp theme={null}
UINT ApplyCombiner(D3D12_SHADING_RATE_COMBINER combiner, UINT a, UINT b)
{
MaxShadingRate = options6.AdditionalShadingRatesSupported ? 4 : 2;
switch (combiner)
{
case D3D12_SHADING_RATE_COMBINER_PASSTHROUGH: // default
return a;
case D3D12_SHADING_RATE_COMBINER_OVERRIDE:
return b;
case D3D12_SHADING_RATE_COMBINER_MAX:
return max(a, b);
case D3D12_SHADING_RATE_COMBINER_MIN:
return min(a, b);
case D3D12_SHADING_RATE_COMBINER_SUM:
return min(MaxShadingRate, a + b);
case default:
return a;
}
}
```

## Requirements

**Header:** d3d12\_xs.h\
**Library:** d3d12\_xs.lib\
**Supported Platforms**: XBOX Series consoles

## See Also

[Variable-rate shading (VRS)](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/vrs)
