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

# CreateCommandAllocator

> 创建命令分配器对象。

创建命令分配器对象。

## 语法

```cpp theme={null}
HRESULT CreateCommandAllocator(
    D3D12_COMMAND_LIST_TYPE type,
    const IID & riid,
    void  ppCommandAllocator
)
```

### 参数

*type \[in]*\
类型：D3D12\_COMMAND\_LIST\_TYPE

[D3D12\_COMMAND\_LIST\_TYPE](/reference/graphics/d3d12_x/enums/d3d12_command_list_type) 类型的值，用于指定要创建的命令分配器的类型。
命令分配器的类型可以是记录直接命令列表或捆绑包的类型。

*riid*\
类型：const IID &

命令分配器接口（[ID3D12CommandAllocator](/reference/graphics/d3d12_x/interfaces/ID3D12CommandAllocator/id3d12commandallocator)）的全局唯一标识符 (**GUID**)。
可以使用 \_\_uuidof() 宏获取命令分配器接口的 **REFIID** 或 **GUID**。
例如，\_\_uuidof(ID3D12CommandAllocator) 将获取命令分配器接口的 **GUID**。

*ppCommandAllocator \[out]*\
类型：void \*\*

指向内存块的指针，该内存块接收命令分配器的 [ID3D12CommandAllocator](/reference/graphics/d3d12_x/interfaces/ID3D12CommandAllocator/id3d12commandallocator) 接口的指针。

### 返回值

类型：HRESULT

如果没有足够的内存来创建命令分配器，则此方法返回 **E\_OUTOFMEMORY**。
有关其他可能的返回值，请参阅 [Direct3D 12 返回代码](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/d3d12-graphics-reference-returnvalues)。

## 备注

设备从命令分配器创建命令列表。

#### 示例

[D3D12Bundles](https://learn.microsoft.com/en-us/windows/desktop/direct3d12/working-samples) 示例按以下方式使用 **ID3D12Device::CreateCommandAllocator**：

```cpp theme={null}
ThrowIfFailed(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&m_commandAllocator)));
ThrowIfFailed(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_BUNDLE, IID_PPV_ARGS(&m_bundleAllocator)));

```

请参阅 [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](/reference/graphics/d3d12_x/interfaces/id3d12device/id3d12device)


## Related topics

- [CreateCommandList](/zh-CN/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_createcommandlist_public.md)
- [ID3D12CommandAllocator::Reset](/zh-CN/reference/graphics/d3d12/interfaces/id3d12commandallocator/methods/id3d12commandallocator_reset_public.md)
- [XALLOC_ALLOCATOR_IDS](/zh-CN/reference/system/xmem/enums/xalloc_allocator_ids.md)
- [CreateCommandQueue](/zh-CN/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_createcommandqueue_public.md)
- [CreateCommandSignature](/zh-CN/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_createcommandsignature_public.md)
