> ## 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.

# D3D12SerializeRootSignature

> 序列化可傳遞至 ID3D12Device::CreateRootSignature 的根簽章 1.0 版。

序列化可傳遞至 [ID3D12Device::CreateRootSignature](/zh-TW/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_createrootsignature_public) 的根簽章 1.0 版。

## 語法

```cpp theme={null}
HRESULT D3D12SerializeRootSignature(
    const D3D12_ROOT_SIGNATURE_DESC  pRootSignature,
    D3D_ROOT_SIGNATURE_VERSION Version,
    ID3DBlob  ppBlob,
    ID3DBlob  ppErrorBlob
)
```

### 參數

*pRootSignature \[in]*\
類型：const D3D12\_ROOT\_SIGNATURE\_DESC \*

根簽章的描述，以指向 [D3D12\_ROOT\_SIGNATURE\_DESC](/zh-TW/reference/graphics/d3d12/structs/d3d12_root_signature_desc_public) 結構的指標表示。

*Version \[in]*\
類型：D3D\_ROOT\_SIGNATURE\_VERSION

[D3D\_ROOT\_SIGNATURE\_VERSION](/zh-TW/reference/graphics/d3d12/enums/d3d_root_signature_version_public) 類型的值，指定根簽章的版本。

*ppBlob \[out]*\
類型：ID3DBlob \*\*

指向記憶體區塊的指標，該區塊會接收指向 **ID3DBlob** 介面的指標，您可以使用該介面存取序列化的根簽章。

*ppErrorBlob \[out, optional]*\
類型：ID3DBlob \*\*

指向記憶體區塊的指標，該區塊會接收指向 **ID3DBlob** 介面的指標，您可以使用該介面存取序列化程式錯誤訊息；如果沒有錯誤，則為 **NULL**。

### 傳回值

類型：HRESULT

如果成功，則傳回 **S\_OK**；否則傳回其中一個 [Direct3D 12 傳回碼](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/d3d12-graphics-reference-returnvalues)。

## 備註

自 Windows 10 年度更新版 (14393) 起，此函式已由 [D3D12SerializeVersionedRootSignature](/zh-TW/reference/graphics/d3d12/functions/d3d12serializeversionedrootsignature_public) 取代。

如果應用程式以程序方式產生 [D3D12\_ROOT\_SIGNATURE\_DESC](/zh-TW/reference/graphics/d3d12/structs/d3d12_root_signature_desc_public) 資料結構，則必須在呼叫 **D3D12SerializeRootSignature** 時傳遞指向此 **D3D12\_ROOT\_SIGNATURE\_DESC** 的指標，以產生序列化形式。
接著，應用程式會將 <i>ppBlob</i> 所指向的序列化形式傳遞至 [ID3D12Device::CreateRootSignature](/zh-TW/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_createrootsignature_public)。

如果著色器在撰寫時已包含根簽章，則編譯後的著色器中已包含序列化的根簽章。在此情況下，請將編譯後的著色器 Blob 傳遞至 [ID3D12Device::CreateRootSignature](/zh-TW/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_createrootsignature_public)，以取得執行階段根簽章物件。

函式簽章 PFN\_D3D12\_SERIALIZE\_ROOT\_SIGNATURE 以 typedef 形式提供，因此您可以使用動態連結技術 ([GetProcAddress](https://learn.microsoft.com/en-us/windows/desktop/api/libloaderapi/nf-libloaderapi-getprocaddress)) 而非靜態連結。

#### 範例

建立空的根簽章。

```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 參考中的範例程式碼](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/notes-on-example-code)。

<div class="code" />

## 需求

**標頭：** d3d12\_xs.h 或 d3d12\_x.h\
**程式庫：** d3d12\_xs.lib 或 d3d12\_x.lib\
**支援的平台**：XBOX Series 主機和 XBOX One 系列主機

## 另請參閱

[核心函式](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/direct3d-12-functions)

[建立根簽章](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/creating-a-root-signature)


## Related topics

- [D3D_ROOT_SIGNATURE_VERSION](/zh-TW/reference/graphics/d3d12/enums/d3d_root_signature_version_public.md)
- [D3D12_ROOT_SIGNATURE_DESC](/zh-TW/reference/graphics/d3d12/structs/d3d12_root_signature_desc_public.md)
- [CreateRootSignature](/zh-TW/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_createrootsignature_public.md)
- [D3D12_VERSIONED_ROOT_SIGNATURE_DESC](/zh-TW/reference/graphics/d3d12/structs/d3d12_versioned_root_signature_desc_public.md)
- [ID3D12RootSignature](/zh-TW/reference/graphics/d3d12/interfaces/id3d12rootsignature/id3d12rootsignature_public.md)
