Skip to content

Instantly share code, notes, and snippets.

@yorung
Created May 8, 2016 01:25
Show Gist options
  • Select an option

  • Save yorung/ea4b48cc4d0a3aac641897e4eade5ffd to your computer and use it in GitHub Desktop.

Select an option

Save yorung/ea4b48cc4d0a3aac641897e4eade5ffd to your computer and use it in GitHub Desktop.
A wrapper for root signature creation.
ComPtr<ID3D12RootSignature> afCreateRootSignature(int numDescriptors, D3D12_DESCRIPTOR_RANGE descriptors[], int numSamplers, D3D12_STATIC_SAMPLER_DESC samplers[])
{
ComPtr<ID3D12RootSignature> rs;
ComPtr<ID3DBlob> signature;
ComPtr<ID3DBlob> error;
D3D12_ROOT_PARAMETER rootParameter = {};
rootParameter.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
rootParameter.ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
rootParameter.DescriptorTable.NumDescriptorRanges = numDescriptors;
rootParameter.DescriptorTable.pDescriptorRanges = descriptors;
D3D12_ROOT_SIGNATURE_DESC rsDesc = { (UINT)(numDescriptors ? 1 : 0), &rootParameter, (UINT)numSamplers, samplers, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT };
HRESULT hr = D3D12SerializeRootSignature(&rsDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error);
assert(hr == S_OK);
hr = deviceMan.GetDevice()->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&rs));
assert(hr == S_OK);
return rs;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment