From Microsoft Docs, I can specify the root signature of my shader in HLSL. How do I use it though?

Since at the beginning of the command list, root signature is undefined. I need to use ID3D12GraphicsCommandList::SetComputeRootSignature(ID3D12RootSignature*) or ID3D12GraphicsCommandList::SetGraphicsRootSignature(ID3D12RootSignature*) set root signature, but having specified in HLSL instead of C++ code, I do not have a pointer to my root signature objects, how should it be done then?


1 Answer 1


You can provide any compiled shader blob that contains the desired root signature defined in HLSL when creating the root signature object:

Microsoft::WRL::ComPtr<ID3D12RootSignature> m_rootSignature

// Create root signature.
auto vertexShaderBlob = DX::ReadData(L"VertexShader.cso");

    device->CreateRootSignature(0, vertexShaderBlob.data(), vertexShaderBlob.size(),


// Use root signature

The DX::ReadData function just loads the binary blob from disk (source here). The DX::ThrowIfFailed helper is explained here.

If you are using FXC.EXE you can also build a shader with the HLSL defined root signature using the rootsig_1_0 or rootsig_1_1 profile and the resulting compiled binary object will just have the root signature in it.

  • \$\begingroup\$ That worked! I was used to using D3D12SerializeVersionedRootSignature to produce the blob and didn't know the blob from compiling the shader can be used for it as well. Thank you. \$\endgroup\$
    – user135033
    Commented Jan 17, 2020 at 12:32

You must log in to answer this question.