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

# CreateQueryHeap

> Creates a query heap. A query heap contains an array of queries.

Creates a query heap.
A query heap contains an array of queries.

## Syntax

```cpp theme={null}
HRESULT CreateQueryHeap(
    const D3D12_QUERY_HEAP_DESC  pDesc,
    const IID & riid,
    void  ppvHeap
)
```

### Parameters

*pDesc \[in]*\
Type: const D3D12\_QUERY\_HEAP\_DESC \*

Specifies the query heap in a [D3D12\_QUERY\_HEAP\_DESC](/reference/graphics/d3d12/structs/d3d12_query_heap_desc_public) structure.

*riid*\
Type: const IID &

Specifies a REFIID that uniquely identifies the heap.

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

Specifies a pointer to the heap, that will be returned on successful completion of the method.
<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>pDesc</i> is valid.

### Return value

Type: HRESULT

This method returns one of the [Direct3D 12 Return Codes](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/d3d12-graphics-reference-returnvalues).

## Remarks

Refer to [Queries](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/queries) for more information.

#### Examples

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

Create a query heap and a query result buffer.

```cpp theme={null}
// Pipeline objects.
D3D12_VIEWPORT m_viewport;
D3D12_RECT m_scissorRect;
ComPtr<IDXGISwapChain3> m_swapChain;
ComPtr<ID3D12Device> m_device;
ComPtr<ID3D12Resource> m_renderTargets[FrameCount];
ComPtr<ID3D12CommandAllocator> m_commandAllocators[FrameCount];
ComPtr<ID3D12CommandQueue> m_commandQueue;
ComPtr<ID3D12RootSignature> m_rootSignature;
ComPtr<ID3D12DescriptorHeap> m_rtvHeap;
ComPtr<ID3D12DescriptorHeap> m_cbvHeap;
ComPtr<ID3D12DescriptorHeap> m_dsvHeap;
ComPtr<ID3D12QueryHeap> m_queryHeap;
UINT m_rtvDescriptorSize;
UINT m_cbvSrvDescriptorSize;
UINT m_frameIndex;

// Synchronization objects.
ComPtr<ID3D12Fence> m_fence;
UINT64 m_fenceValues[FrameCount];
HANDLE m_fenceEvent;

// Asset objects.
ComPtr<ID3D12PipelineState> m_pipelineState;
ComPtr<ID3D12PipelineState> m_queryState;
ComPtr<ID3D12GraphicsCommandList> m_commandList;
ComPtr<ID3D12Resource> m_vertexBuffer;
ComPtr<ID3D12Resource> m_constantBuffer;
ComPtr<ID3D12Resource> m_depthStencil;
ComPtr<ID3D12Resource> m_queryResult;
D3D12_VERTEX_BUFFER_VIEW m_vertexBufferView;

```

```cpp theme={null}
// Describe and create a heap for occlusion queries.
D3D12_QUERY_HEAP_DESC queryHeapDesc = {};
queryHeapDesc.Count = 1;
queryHeapDesc.Type = D3D12_QUERY_HEAP_TYPE_OCCLUSION;
ThrowIfFailed(m_device->CreateQueryHeap(&queryHeapDesc, IID_PPV_ARGS(&m_queryHeap)));

```

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_QUERY_HEAP_DESC](/reference/graphics/d3d12/structs/d3d12_query_heap_desc_public.md)
- [D3D12_QUERY_DATA_PIPELINE_STATISTICS](/reference/graphics/d3d12/structs/d3d12_query_data_pipeline_statistics_public.md)
- [D3D12_QUERY_DATA_SO_STATISTICS](/reference/graphics/d3d12/structs/d3d12_query_data_so_statistics_public.md)
- [ID3D12QueryHeap](/reference/graphics/d3d12/interfaces/id3d12queryheap/id3d12queryheap_public.md)
- [CreateHeap](/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_createheap_public.md)
