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

> Creates a descriptor heap object.

Creates a descriptor heap object.

## Syntax

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

### Parameters

*pDescriptorHeapDesc \[in]*\
Type: const D3D12\_DESCRIPTOR\_HEAP\_DESC \*

A pointer to a [D3D12\_DESCRIPTOR\_HEAP\_DESC](/reference/graphics/d3d12/structs/d3d12_descriptor_heap_desc_public) structure that describes the heap.

*riid*\
Type: const IID &

The globally unique identifier (**GUID**) for the descriptor heap interface. See Remarks.
An input parameter.

*ppvHeap \[out]*\
Type: void \*\*

A pointer to a memory block that receives a pointer to the descriptor heap.
<i>ppvHeap</i> can be NULL, to enable capability testing.
When <i>ppvHeap</i> is NULL, no object will be created and S\_FALSE will be returned when <i>pDescriptorHeapDesc</i> is valid.

### Return value

Type: HRESULT

This method returns **E\_OUTOFMEMORY** if there is insufficient memory to create the descriptor heap object.
See [Direct3D 12 Return Codes](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/d3d12-graphics-reference-returnvalues) for other possible return values.

## Remarks

The **REFIID**, or **GUID**, of the interface to the descriptor heap can be obtained by using the \_\_uuidof() macro. For example, \_\_uuidof([ID3D12DescriptorHeap](/reference/graphics/d3d12/interfaces/id3d12descriptorheap/id3d12descriptorheap_public)) will get the **GUID** of the interface to a descriptor heap.

#### Examples

The [D3D12HelloWorld](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/working-samples) sample uses **ID3D12Device::CreateDescriptorHeap** as follows:

Describe and create a render target view (RTV) descriptor heap.

```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);
}

```

Refer to the [Example Code in the D3D12 Reference](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/notes-on-example-code).

<div class="code" />

## Requirements

**Header:** d3d12\_xs.h or d3d12\_x.h\
**Library:** d3d12\_xs.lib or d3d12\_x.lib\
**Supported Platforms**: XBOX Series consoles and XBOX One family

## See Also

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


## Related topics

- [D3D12_DESCRIPTOR_HEAP_DESC](/reference/graphics/d3d12/structs/d3d12_descriptor_heap_desc_public.md)
- [SetDescriptorHeaps](/reference/graphics/d3d12/interfaces/id3d12graphicscommandlist/methods/id3d12graphicscommandlist_setdescriptorheaps_public.md)
- [CreateSampler](/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_createsampler_public.md)
- [D3D12_CPU_DESCRIPTOR_HANDLE](/reference/graphics/d3d12/structs/d3d12_cpu_descriptor_handle_public.md)
- [ID3D12DescriptorHeap](/reference/graphics/d3d12/interfaces/id3d12descriptorheap/id3d12descriptorheap_public.md)
