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

# CreateHeap

> 创建一个可与放置资源和保留资源一起使用的堆。

创建一个可与放置资源和保留资源一起使用的堆。

## 语法

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

### 参数

*pDesc \[in]*\
类型：const D3D12\_HEAP\_DESC \*

指向常量 **D3D12\_HEAP\_DESC** 结构体的指针，该结构体描述堆。

*riid \[in]*\
类型：const IID &

要在 *ppvHeap* 中返回的堆接口的全局唯一标识符 (**GUID**) 的引用。

虽然 *riidResource* 最常是 [ID3D12Heap](/reference/graphics/d3d12/interfaces/id3d12heap/id3d12heap_public) 的 **GUID**，但它也可以是任何接口的 **GUID**。如果资源对象不支持此 **GUID** 的接口，则创建失败并返回 **E\_NOINTERFACE**。

*ppvHeap \[out, optional]*\
类型：void \*\*

可选指针，指向接收所创建堆对象的所请求接口指针的内存块。

*ppvHeap* 可以为 `nullptr`，以启用功能测试。当 *ppvHeap* 为 `nullptr` 时，不会创建对象，并且当 *pDesc* 有效时返回 **S\_FALSE**。

### 返回值

类型：HRESULT

如果函数成功，则返回 **S\_OK**。否则，返回 [**HRESULT**](https://learn.microsoft.com/en-us/windows/desktop/com/structure-of-com-error-codes) [错误代码](https://learn.microsoft.com/en-us/windows/win32/com/com-error-codes-10)。

| 返回值            | 说明           |
| -------------- | ------------ |
| E\_OUTOFMEMORY | 没有足够的内存来创建堆。 |

有关其他可能的返回值，请参阅 [Direct3D 12 返回代码](https://learn.microsoft.com/en-us/windows/win32/direct3d12/d3d12-graphics-reference-returnvalues)。

## 备注

**CreateHeap** 创建一个可与放置资源和保留资源一起使用的堆。

在释放对堆的最后一个引用之前，您的应用程序必须确保 GPU 将不再读取或写入此堆。

放置资源对象保留其创建所在堆的引用；但保留资源不会为堆的每个映射保留一个引用。

## 要求

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

## 另请参阅

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

[共享堆](https://learn.microsoft.com/en-us/windows/win32/direct3d12/shared-heaps)


## Related topics

- [CreateHeap1 (XBOX Series 主机)](/zh-CN/reference/graphics/d3d12/interfaces/id3d12device4/methods/id3d12device4_createheap1_public.md)
- [D3D12_FEATURE_DATA_EXISTING_HEAPS](/zh-CN/reference/graphics/d3d12/structs/d3d12_feature_data_existing_heaps_public.md)
- [CreateDescriptorHeap](/zh-CN/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_createdescriptorheap_public.md)
- [CreateQueryHeap](/zh-CN/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_createqueryheap_public.md)
- [ApuCreateHeap](/zh-CN/reference/audio/apu/functions/apucreateheap.md)
