> ## 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](/zh-TW/reference/graphics/d3d12_x/enums/d3d12_command_list_type) 類型的值，指定要建立的命令配置器類型。
命令配置器的類型可以是記錄直接命令清單或套件組合的類型。

*riid*\
類型：const IID &

命令配置器介面 ([ID3D12CommandAllocator](/zh-TW/reference/graphics/d3d12_x/interfaces/ID3D12CommandAllocator/id3d12commandallocator)) 的全域唯一識別碼 (**GUID**)。
命令配置器介面的 **REFIID** (或 **GUID**) 可以使用 \_\_uuidof() 巨集取得。
例如，\_\_uuidof(ID3D12CommandAllocator) 會取得命令配置器介面的 **GUID**。

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

指向記憶體區塊的指標，該區塊會接收指向命令配置器之 [ID3D12CommandAllocator](/zh-TW/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](/zh-TW/reference/graphics/d3d12_x/interfaces/id3d12device/id3d12device)


## Related topics

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