- Qt 6.9
- Qt GUI
- C++ Classes
- QtGuiPrivate
- QRhiShadingRateMap
- Qt 6.9.1 Reference Documentation

# QRhiShadingRateMap Class

An object that wraps a texture or another kind of native 3D API object. More...

Header: | `#include <rhi/qrhi.h>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS Gui)` `target_link_libraries(mytarget PRIVATE Qt6::GuiPrivate)`
qmake: | `QT += gui-private`
Since: | Qt 6.9
Inherits: | QRhiResource

- List of all members, including inherited members

## Public Types

`(since 6.9)` struct | NativeShadingRateMap

## Public Functions

virtual bool | createFrom(QRhiShadingRateMap::NativeShadingRateMap src)
virtual bool | createFrom(QRhiTexture *src)

## Reimplemented Public Functions

virtual QRhiResource::Type | resourceType() const override

## Detailed Description

Note: This is a RHI API with limited compatibility guarantees, see QRhi for details.

For an introduction to Variable Rate Shading (VRS), see https://learn.microsoft.com/en-us/windows/win32/direct3d12/vrs. Qt supports a subset of the VRS features offered by Direct 3D 12 and Vulkan. In addition, Metal's somewhat different mechanism is supported by making it possible to set up a QRhiShadingRateMap with an existing MTLRasterizationRateMap object.

## Member Function Documentation

### `[virtual]` bool QRhiShadingRateMap::createFrom(QRhiShadingRateMap::NativeShadingRateMap src)

Sets up the shading rate map to use a native 3D API shading rate object src.

Returns `true` when successful, `false` when not supported.

Note: This is functional only when the QRhi::VariableRateShadingMap feature is reported as supported, while QRhi::VariableShadingRateMapWithTexture feature is not. Currently this is true for Metal, assuming variable rate shading is supported by the GPU.

Note: With Metal, the `object` field of src is expected to contain an id<MTLRasterizationRateMap>. Note that Qt does not perform anything else apart from passing the MTLRasterizationRateMap on to the MTLRenderPassDescriptor. If any special scaling is required, it is up to the application (or the XR compositor) to perform that.

### `[virtual]` bool QRhiShadingRateMap::createFrom(QRhiTexture *src)

Sets up the shading rate map to use the texture src as the image containing the per-tile shading rates.

Returns `true` when successful, `false` when not supported.

The QRhiShadingRateMap does not take ownership of src.

Note: This is functional only when the QRhi::VariableRateShadingMapWithTexture feature is reported as supported. In practice may be supported on Vulkan and Direct 3D 12 when using modern graphics cards. It will never be supported on OpenGL or Metal, for example.

Note: src must have a format of QRhiTexture::R8UI.

Note: src must have a width of `ceil(render_target_pixel_width / (float)tile_width)` and a height of `ceil(render_target_pixel_height / (float)tile_height)`. It is up to the application to ensure the size of the texture is as expected, using the above formula, at all times. The tile size can be queried via QRhi::resourceLimit() and QRhi::ShadingRateImageTileSize.

Each byte (texel) in the texture corresponds to the shading rate value for one tile. 0 indicates 1x1, while a value of 10 indicates 4x4. See D3D12_SHADING_RATE for other possible values.

### `[override virtual]` QRhiResource::Type QRhiShadingRateMap::resourceType() const

Reimplements: QRhiResource::resourceType() const.

Returns the resource type.