On this page

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 GuiPrivate)
target_link_libraries(mytarget PRIVATE Qt6::GuiPrivate)
qmake: QT += gui-private
Since: Qt 6.9
Inherits: QRhiResource

Public Types

(since 6.9) struct NativeShadingRateMap

Public Functions

virtual bool createFrom(QRhiShadingRateMap::NativeShadingRateMap src)
virtual bool createFrom(QRhiTexture *src)
(since 6.13) virtual QSize logicalSize() const

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::VariableRateShadingMapWithTexture 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>. Qt passes the MTLRasterizationRateMap on to the MTLRenderPassDescriptor, and, because Metal then interprets viewports and scissor rectangles in the map's screen space coordinate system, sizes the default scissor and converts viewports and scissors specified via QRhiCommandBuffer accordingly. The size of that coordinate system is reported by logicalSize(). Anything else, such as scaling when sampling the rendered result, is up to the application (or the XR compositor).

[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.

[virtual, since 6.13] QSize QRhiShadingRateMap::logicalSize() const

Returns the size of the logical coordinate space the shading rate map defines, or an invalid QSize when the map does not define one.

Some implementations, Metal in particular, describe a shading rate map in terms of a logical (screen space) size that is mapped onto the physical pixels of the render target. When such a map is attached to a render target, viewports and scissor rectangles are interpreted in the logical coordinate system, and the logical size is typically larger than QRhiRenderTarget::pixelSize(). Applications that derive viewports, scissors, or projection setup from the render target size should use this size instead whenever it is valid.

For implementations where the shading rate map is a tile image covering the render target, such as Vulkan and Direct 3D 12, there is no separate logical coordinate space, and an invalid QSize is returned. The render target's pixel size applies as usual in that case.

This function was introduced in Qt 6.13.

See also QRhiRenderTarget::pixelSize().

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

Reimplements: QRhiResource::resourceType() const.

Returns the resource type.

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.