In DirectX 12 a root signature is essentially the “function signature” for your shaders—it tells the GPU what resources (textures, buffers, samplers, constants) your shaders will need, and where in GPU-visible memory to find them.
Think of it like this:
• In C/C++ you declare a function:
int Add(int a, int b);
That signature says “I need two ints.”
• In DX12 you declare a root signature: it says “my shaders need these CBVs, SRVs/UAVs, descriptor tables, constants, and samplers.”
Why it matters
- Explicit binding
Unlike DX11’s hidden bindings, DX12 makes you declare up front all the resources your shaders will use.
- Performance
Keeping your root signature small and tightly packed lets the driver set up your shaders more efficiently.
- Validation
The GPU can catch mismatches between what your app binds and what the shader expects.
Root‐signature building blocks
• Root Parameters
• Root constants (up to 256 bits of immediate data)
• Root descriptors (a single CBV/SRV/UAV slot)
• Descriptor tables (arrays of descriptors in a descriptor heap)
• Static Samplers
Samplers baked into the root signature—no need to bind them at draw time.
A Minimal Example
HLSL side:
// Tells the compiler what to generate behind the scenes
// b0 = CBV at register b0
// t0 = Texture2D at t0
// s0 = SamplerState at s0
RootSignature
(
"CBV(b0), TEXTURE(t0), SAMPLER(s0)"
);
struct VSOut
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD;
};
Texture2D g_Texture : register(t0);
SamplerState g_Sampler : register(s0);
cbuffer SceneCB : register(b0)
{
matrix ViewProj;
};
VSOut VSMain(...);
float4 PSMain(VSOut input) : SV_TARGET
{
return g_Texture.Sample(g_Sampler, input.uv);
}
C++ side (using the D3DX12 helper):
// Define one descriptor table with a CBV (b0), one SRV (t0), and one sampler (s0)
CD3DX12_ROOT_PARAMETER1 rootParams[3];
// CBV at b0
rootParams[0].InitAsConstantBufferView(0);
// SRV descriptor table at t0
CD3DX12_DESCRIPTOR_RANGE1 ranges[1];
ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0);
rootParams[1].InitAsDescriptorTable(1, &ranges[0]);
// Static sampler at s0
CD3DX12_STATIC_SAMPLER_DESC samplerDesc(
0, // shaderRegister
D3D12_FILTER_MIN_MAG_MIP_LINEAR // filter
);
// Build the root signature
CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC desc;
desc.Init_1_1(
_countof(rootParams), rootParams,
1, &samplerDesc,
D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT
);
ComPtr<ID3DBlob> sigBlob, errorBlob;
D3DX12SerializeVersionedRootSignature(&desc, D3D_ROOT_SIGNATURE_VERSION_1_1, &sigBlob, &errorBlob);
device->CreateRootSignature(0, sigBlob->GetBufferPointer(), sigBlob->GetBufferSize(), IID_PPV_ARGS(&rootSignature));