> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# CreateRootSignature

> 创建根签名布局。

创建根签名布局。

## 语法

```cpp theme={null}
HRESULT CreateRootSignature(
    UINT nodeMask,
    const void  pBlobWithRootSignature,
    SIZE_T blobLengthInBytes,
    const IID & riid,
    void  ppvRootSignature
)
```

### 参数

*nodeMask \[in]*\
类型：UINT

对于单 GPU 操作，将其设置为零。如果有多个 GPU 节点，则设置位以标识要将根签名应用于的节点（设备的物理适配器）。
掩码中的每一位都对应一个节点。
请参阅 [多适配器系统](https://learn.microsoft.com/en-us/windows/win32/direct3d12/multi-engine)。

*pBlobWithRootSignature \[in]*\
类型：const void \*

指向序列化签名的源数据的指针。

*blobLengthInBytes \[in]*\
类型：**[SIZE\_T](https://learn.microsoft.com/en-us/windows/win32/WinProg/windows-data-types)**

<i>pBlobWithRootSignature</i> 指向的内存块的大小（以字节为单位）。

*riid*\
类型：const IID &

根签名接口的全局唯一标识符 (**GUID**)。请参阅备注。
输入参数。

*ppvRootSignature \[out]*\
类型：void \*\*

指向内存块的指针，该内存块接收指向根签名的指针。

### 返回值

类型：HRESULT

如果成功，则返回 **S\_OK**；否则，返回 [Direct3D 12 返回代码](https://learn.microsoft.com/en-us/windows/win32/direct3d12/d3d12-graphics-reference-returnvalues) 之一。

如果 <i>pBlobWithRootSignature</i> 指向的 blob 无效，此方法返回 **E\_INVALIDARG**。

## 备注

如果应用程序按程序生成 [D3D12\_ROOT\_SIGNATURE\_DESC](/reference/graphics/d3d12/structs/d3d12_root_signature_desc_public) 数据结构，则必须在对 [D3D12SerializeRootSignature](/reference/graphics/d3d12/functions/d3d12serializerootsignature_public) 的调用中传递指向此 **D3D12\_ROOT\_SIGNATURE\_DESC** 的指针以生成序列化形式。
然后，应用程序在对 **ID3D12Device::CreateRootSignature** 的调用中将序列化形式传递给 <i>pBlobWithRootSignature</i>。

可以使用 \_\_uuidof() 宏获取根签名布局接口的 **REFIID** 或 **GUID**。
例如，\_\_uuidof([ID3D12RootSignature](/reference/graphics/d3d12/interfaces/id3d12rootsignature/id3d12rootsignature_public)) 将获取根签名接口的 **GUID**。

#### 示例

[D3D12HelloTriangle](https://learn.microsoft.com/en-us/windows/win32/direct3d12/working-samples) 示例按以下方式使用 **ID3D12Device::CreateRootSignature**：

创建一个空的根签名。

```cpp theme={null}
CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
rootSignatureDesc.Init(0, nullptr, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);

ComPtr<ID3DBlob> signature;
ComPtr<ID3DBlob> error;
ThrowIfFailed(D3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error));
ThrowIfFailed(m_device->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&m_rootSignature)));

```

## 要求

**头文件：** d3d12\_xs.h 或 d3d12\_x.h\
**库：** d3d12\_xs.lib 或 d3d12\_x.lib\
**支持的平台**：XBOX Series 主机和 XBOX One 系列

## 另请参阅

[ID3D12Device](/reference/graphics/d3d12_x/interfaces/id3d12device/id3d12device)


## Related topics

- [D3D12SerializeRootSignature](/zh-CN/reference/graphics/d3d12/functions/d3d12serializerootsignature_public.md)
- [D3D12CreateRootSignatureDeserializer](/zh-CN/reference/graphics/d3d12/functions/d3d12createrootsignaturedeserializer_public.md)
- [D3D12CreateVersionedRootSignatureDeserializer](/zh-CN/reference/graphics/d3d12/functions/d3d12createversionedrootsignaturedeserializer_public.md)
- [CreateCommandSignature](/zh-CN/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_createcommandsignature_public.md)
- [D3D_ROOT_SIGNATURE_VERSION](/zh-CN/reference/graphics/d3d12/enums/d3d_root_signature_version_public.md)
