D3D12_GRAPHICS_PIPELINE_STATE_DESC
Namespace: D3D12
The D3D12_GRAPHICS_PIPELINE_STATE_DESC
structure describes a graphics pipeline state object (PSO) for Direct3D 12. It encapsulates shader bytecode, rasterizer state, blend state, depth‑stencil state, and other fixed‑function configurations required to render geometry.
Structure Definition
typedef struct D3D12_GRAPHICS_PIPELINE_STATE_DESC {
ID3D12RootSignature* pRootSignature;
D3D12_SHADER_BYTECODE VS;
D3D12_SHADER_BYTECODE PS;
D3D12_SHADER_BYTECODE DS;
D3D12_SHADER_BYTECODE HS;
D3D12_SHADER_BYTECODE GS;
D3D12_STREAM_OUTPUT_DESC StreamOutput;
D3D12_BLEND_DESC BlendState;
UINT SampleMask;
D3D12_RASTERIZER_DESC RasterizerState;
D3D12_DEPTH_STENCIL_DESC DepthStencilState;
D3D12_INPUT_LAYOUT_DESC InputLayout;
D3D12_INDEX_BUFFER_STRIP_CUT_VALUE IBStripCutValue;
D3D12_PRIMITIVE_TOPOLOGY_TYPE PrimitiveTopologyType;
UINT NumRenderTargets;
DXGI_FORMAT RTVFormats[8];
DXGI_FORMAT DSVFormat;
DXGI_SAMPLE_DESC SampleDesc;
UINT NodeMask;
D3D12_CACHED_PIPELINE_STATE CachedPSO;
D3D12_PIPELINE_STATE_FLAGS Flags;
} D3D12_GRAPHICS_PIPELINE_STATE_DESC;
Members
Member | Type | Description |
---|---|---|
pRootSignature | ID3D12RootSignature* | Root signature used by the pipeline. |
VS | D3D12_SHADER_BYTECODE | Vertex shader bytecode. |
PS | D3D12_SHADER_BYTECODE | Pixel (fragment) shader bytecode. |
DS | D3D12_SHADER_BYTECODE | Domain shader bytecode (optional). |
HS | D3D12_SHADER_BYTECODE | Hull shader bytecode (optional). |
GS | D3D12_SHADER_BYTECODE | Geometry shader bytecode (optional). |
StreamOutput | D3D12_STREAM_OUTPUT_DESC | Stream‑output configuration (optional). |
BlendState | D3D12_BLEND_DESC | Blend state for render targets. |
SampleMask | UINT | Sample mask for multisampling. |
RasterizerState | D3D12_RASTERIZER_DESC | Rasterizer state description. |
DepthStencilState | D3D12_DEPTH_STENCIL_DESC | Depth‑stencil state description. |
InputLayout | D3D12_INPUT_LAYOUT_DESC | Vertex input layout. |
IBStripCutValue | D3D12_INDEX_BUFFER_STRIP_CUT_VALUE | Index buffer strip cut value. |
PrimitiveTopologyType | D3D12_PRIMITIVE_TOPOLOGY_TYPE | Type of primitive topology. |
NumRenderTargets | UINT | Number of active render target slots (0‑8). |
RTVFormats | DXGI_FORMAT[8] | Render target view formats. |
DSVFormat | DXGI_FORMAT | Depth‑stencil view format. |
SampleDesc | DXGI_SAMPLE_DESC | Multisample count and quality. |
NodeMask | UINT | Node mask for multi‑GPU systems. |
CachedPSO | D3D12_CACHED_PIPELINE_STATE | Optional cached pipeline state blob. |
Flags | D3D12_PIPELINE_STATE_FLAGS | Additional creation flags. |
Example Usage
#include <d3d12.h>
#include <dxgi1_4.h>
// Assume device and root signature already created
ID3D12Device* device = /* ... */;
ID3D12RootSignature* rootSig = /* ... */;
D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {};
psoDesc.pRootSignature = rootSig;
// Load compiled shader blobs
psoDesc.VS = CD3DX12_SHADER_BYTECODE(CompileShader(L\"Vertex.hlsl\", \"vs_5_0\"));
psoDesc.PS = CD3DX12_SHADER_BYTECODE(CompileShader(L\"Pixel.hlsl\", \"ps_5_0\"));
psoDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT);
psoDesc.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT);
psoDesc.DepthStencilState = CD3DX12_DEPTH_STENCIL_DESC(D3D12_DEFAULT);
psoDesc.SampleMask = UINT_MAX;
psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
psoDesc.NumRenderTargets = 1;
psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
psoDesc.SampleDesc.Count = 1;
// Create the PSO
ID3D12PipelineState* pipelineState = nullptr;
HRESULT hr = device->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&pipelineState));
if (FAILED(hr)) {
// handle error
}
Related Structures
- D3D12_SHADER_BYTECODE
- D3D12_BLEND_DESC
- D3D12_RASTERIZER_DESC
- D3D12_DEPTH_STENCIL_DESC
- D3D12_PRIMITIVE_TOPOLOGY_TYPE
Notes
Show/Hide Implementation Notes
When creating a PSO, all shader stages that are not used can be set to an empty D3D12_SHADER_BYTECODE
(i.e., {nullptr,0}
). The PSO description must be immutable after creation; any change requires a new PSO object.
For optimal performance, consider using D3D12_CACHED_PIPELINE_STATE
to store compiled PSO blobs, especially on platforms where shader compilation can be costly at runtime.