Skip to content

RenderTargetState

Chuck Walbourn edited this page Aug 19, 2025 · 12 revisions
DirectXTK

When creating Pipeline State Objects (PSO), DirectX 12 requires knowing the render target format, the depth/stencil buffer format, number of render targets, etc. that will be used for rendering. This information is wrapped up by this helper structure which is used by Effects and SpriteBatch.

Related tutorial: Sprites and textures, Simple rendering

class DirectX::RenderTargetState

Header

#include "RenderTargetState.h"

Usage

Initialization

Typically used during resource creation, with a simple initialization case such as the following (assuming your render target's format is DXGI_FORMAT_B8G8R8A8_UNORM and the depth/stencil buffer is DXGI_FORMAT_D32_FLOAT):

RenderTargetState rtState(DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_D32_FLOAT);

If using the DeviceResources abstraction, it should be:

RenderTargetState rtState(m_deviceResources->GetBackBufferFormat(),
    m_deviceResources->GetDepthBufferFormat());

MSAA

If you use an multisample anti-aliasing render target, be sure to set the matching sample count:

RenderTargetState rtState(msaaBackbufferformat, msaaDepthBufferFormat);
rtState.sampleDesc.Count = 4; // <--- 4x MSAA

MRT

If using multiple render targets, be sure to set the format for each one:

RenderTargetState rtState(renderTargetformat, depthBufferFormat);
rtState.numRenderTargets = 3; // <--- doing three render targets at once
// rtState.rtvFormats[0] is set by the ctor above
rtState.rtvFormats[1] = bufferFormatOfSecondRenderTarget;
rtState.rtvFormats[2] = bufferFormatOfThirdRenderTarget;

HDR

When doing High Dynamic Range rendering, you typically use one RenderTargetState for the HDR render target, and then another for the UI that is drawn after tone-mapping.

RenderTargetState hdrState(m_hdrScene->GetFormat(), m_deviceResources->GetDepthBufferFormat());

// Use hdrState for 3D HDR scene objects (Model, Effects, etc.)

RenderTargetState rtState(m_deviceResources->GetBackBufferFormat(), DXGI_FORMAT_UNKNOWN);

// Use rtState for UI-related objects (SpriteBatch, ToneMapPostProcess, etc.)

SwapChain

There are ctors that take DXGI_SWAP_CHAIN_DESC or DXGI_SWAP_CHAIN_DESC1 for the render target format and MSAA sample settings.

Fields

  • sampleMask is the sample mask for the render target. See D3D12_GRAPHICS_PIPELINE_STATE_DESC.SampleMask. It defaults to having all bits set.

  • numRenderTargets is the number of simultaneous render targets.

  • rtvFormats is an array of render target formats.

  • dsvFormat is the depth/stencil format or DXGI_FORMAT_UNKNOWN.

  • sampleDesc is the MSAA sample description for the render target.

  • nodeMask is the node mask for the render target for Multi-GPU usage. See D3D12_GRAPHICS_PIPELINE_STATE_DESC.NodeMask. It defaults to 0.

Exceptions

This class does not throw C++ exceptions, and is marked noexcept.

For Use

  • Universal Windows Platform apps
  • Windows desktop apps
  • Windows 11
  • Windows 10
  • Xbox One
  • Xbox Series X|S

Architecture

  • x86
  • x64
  • ARM64

For Development

  • Visual Studio 2022
  • Visual Studio 2019 (16.11)
  • clang/LLVM v12 - v20
  • MinGW 12.2, 13.2
  • CMake 3.21

Related Projects

DirectX Tool Kit for DirectX 11

DirectXMesh

DirectXTex

DirectXMath

Tools

Test Suite

Model Viewer

Content Exporter

DxCapsViewer

See also

DirectX Landing Page

Clone this wiki locally