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

# CreateDescriptorHeap

> 建立描述元堆積物件。

建立描述元堆積物件。

## 語法

```cpp theme={null}
HRESULT CreateDescriptorHeap(
    const D3D12_DESCRIPTOR_HEAP_DESC  pDescriptorHeapDesc,
    const IID & riid,
    void  ppvHeap
)
```

### 參數

*pDescriptorHeapDesc \[in]*\
類型：const D3D12\_DESCRIPTOR\_HEAP\_DESC \*

指向描述堆積之 [D3D12\_DESCRIPTOR\_HEAP\_DESC](/zh-TW/reference/graphics/d3d12/structs/d3d12_descriptor_heap_desc_public) 結構的指標。

*riid*\
類型：const IID &

描述元堆積介面的全域唯一識別碼 (**GUID**)。請參閱＜備註＞。
輸入參數。

*ppvHeap \[out]*\
類型：void \*\*

指向記憶體區塊的指標，該區塊會接收指向描述元堆積的指標。
<i>ppvHeap</i> 可以是 NULL，以啟用功能測試。
當 <i>ppvHeap</i> 為 NULL 時，不會建立任何物件，且當 <i>pDescriptorHeapDesc</i> 有效時會傳回 S\_FALSE。

### 傳回值

類型：HRESULT

如果記憶體不足而無法建立描述元堆積物件，此方法會傳回 **E\_OUTOFMEMORY**。
如需其他可能的傳回值，請參閱 [Direct3D 12 傳回碼](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/d3d12-graphics-reference-returnvalues)。

## 備註

描述元堆積介面的 **REFIID** (或 **GUID**) 可以使用 \_\_uuidof() 巨集取得。例如，\_\_uuidof([ID3D12DescriptorHeap](/zh-TW/reference/graphics/d3d12/interfaces/id3d12descriptorheap/id3d12descriptorheap_public)) 會取得描述元堆積介面的 **GUID**。

#### 範例

[D3D12HelloWorld](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/working-samples) 範例使用 **ID3D12Device::CreateDescriptorHeap** 的方式如下：

描述並建立轉譯目標檢視 (RTV) 描述元堆積。

```cpp theme={null}
// Create descriptor heaps.
{
// Describe and create a render target view (RTV) descriptor heap.
D3D12_DESCRIPTOR_HEAP_DESC rtvHeapDesc = {};
rtvHeapDesc.NumDescriptors = FrameCount;
rtvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
rtvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
ThrowIfFailed(m_device->CreateDescriptorHeap(&rtvHeapDesc, IID_PPV_ARGS(&m_rtvHeap)));

m_rtvDescriptorSize = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
}

// Create frame resources.
{
CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(m_rtvHeap->GetCPUDescriptorHandleForHeapStart());

// Create a RTV for each frame.
for (UINT n = 0; n < FrameCount; n++)
{
ThrowIfFailed(m_swapChain->GetBuffer(n, IID_PPV_ARGS(&m_renderTargets[n])));
m_device->CreateRenderTargetView(m_renderTargets[n].Get(), nullptr, rtvHandle);
rtvHandle.Offset(1, m_rtvDescriptorSize);
}

```

請參閱 [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 系列

## 另請參閱

[ID3D12Device](/zh-TW/reference/graphics/d3d12_x/interfaces/id3d12device/id3d12device)


## Related topics

- [D3D12_DESCRIPTOR_HEAP_DESC](/zh-TW/reference/graphics/d3d12/structs/d3d12_descriptor_heap_desc_public.md)
- [SetDescriptorHeaps](/zh-TW/reference/graphics/d3d12/interfaces/id3d12graphicscommandlist/methods/id3d12graphicscommandlist_setdescriptorheaps_public.md)
- [D3D12_CPU_DESCRIPTOR_HANDLE](/zh-TW/reference/graphics/d3d12/structs/d3d12_cpu_descriptor_handle_public.md)
- [ID3D12DescriptorHeap](/zh-TW/reference/graphics/d3d12/interfaces/id3d12descriptorheap/id3d12descriptorheap_public.md)
- [D3D12_DESCRIPTOR_HEAP_TYPE](/zh-TW/reference/graphics/d3d12/enums/d3d12_descriptor_heap_type_public.md)
