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

# ExecuteBundle

> 执行捆绑包。

执行捆绑包。

## 语法

```cpp theme={null}
void ExecuteBundle(
    ID3D12GraphicsCommandList  pCommandList
)
```

### 参数

*pCommandList \[in]*\
类型：ID3D12GraphicsCommandList \*

指定确定要执行的捆绑包的 [ID3D12GraphicsCommandList](/reference/graphics/d3d12_xs/interfaces/ID3D12GraphicsCommandList/id3d12graphicscommandlist_xs)。

### 返回值

类型：void

无。

## 备注

捆绑包从其上调用 **ExecuteBundle** 的父命令列表继承所有状态，除了管道状态对象和图元拓扑。捆绑包中设置的所有状态都将影响父命令列表的状态。请注意，**ExecuteBundle** 不是谓词操作。

<h3><a id="Runtime_validation" /><a id="runtime_validation" /><a id="RUNTIME_VALIDATION" />运行时验证</h3>
运行时将验证"被调用者"是捆绑包，"调用者"是直接命令列表。运行时还将验证捆绑包已关闭。如果违反了约定，运行时将默默丢弃该调用。
验证失败将导致 [Close](/reference/graphics/d3d12/interfaces/id3d12graphicscommandlist/methods/id3d12graphicscommandlist_close_public) 返回 E\_INVALIDARG。

<h3><a id="Debug_layer" /><a id="debug_layer" /><a id="DEBUG_LAYER" />调试层</h3>
在与运行时失败相同的情况下，调试层将发出警告。
如果在调用 [ExecuteCommandList](/reference/graphics/d3d12_x/interfaces/id3d12commandqueue/methods/id3d12commandqueue_executecommandlists) 时设置了谓词，调试层将发出警告。
此外，如果调试层检测到命令列表引用的任何资源已被销毁，则会发出错误。

调试层还将验证与捆绑包关联的命令分配器自从对命令列表调用 [Close](/reference/graphics/d3d12/interfaces/id3d12graphicscommandlist/methods/id3d12graphicscommandlist_close_public) 以来尚未重置。此验证发生在 **ExecuteBundle** 时以及在命令队列上执行父命令列表时。

#### 示例

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

```cpp theme={null}
void D3D12Bundles::PopulateCommandList(FrameResource* pFrameResource)
{
// Command list allocators can only be reset when the associated
// command lists have finished execution on the GPU; apps should use
// fences to determine GPU execution progress.
ThrowIfFailed(m_pCurrentFrameResource->m_commandAllocator->Reset());

// However, when ExecuteCommandList() is called on a particular command
// list, that command list can then be reset at any time and must be before
// re-recording.
ThrowIfFailed(m_commandList->Reset(m_pCurrentFrameResource->m_commandAllocator.Get(), m_pipelineState1.Get()));

// Set necessary state.
m_commandList->SetGraphicsRootSignature(m_rootSignature.Get());

ID3D12DescriptorHeap* ppHeaps[] = { m_cbvSrvHeap.Get(), m_samplerHeap.Get() };
m_commandList->SetDescriptorHeaps(_countof(ppHeaps), ppHeaps);

m_commandList->RSSetViewports(1, &m_viewport);
m_commandList->RSSetScissorRects(1, &m_scissorRect);

// Indicate that the back buffer will be used as a render target.
m_commandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_renderTargets[m_frameIndex].Get(), D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET));

CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(m_rtvHeap->GetCPUDescriptorHandleForHeapStart(), m_frameIndex, m_rtvDescriptorSize);
CD3DX12_CPU_DESCRIPTOR_HANDLE dsvHandle(m_dsvHeap->GetCPUDescriptorHandleForHeapStart());
m_commandList->OMSetRenderTargets(1, &rtvHandle, FALSE, &dsvHandle);

// Record commands.
const float clearColor[] = { 0.0f, 0.2f, 0.4f, 1.0f };
m_commandList->ClearRenderTargetView(rtvHandle, clearColor, 0, nullptr);
m_commandList->ClearDepthStencilView(m_dsvHeap->GetCPUDescriptorHandleForHeapStart(), D3D12_CLEAR_FLAG_DEPTH, 1.0f, 0, 0, nullptr);

if (UseBundles)
{
// Execute the prebuilt bundle.
m_commandList->ExecuteBundle(pFrameResource->m_bundle.Get());
}
else
{
// Populate a new command list.
pFrameResource->PopulateCommandList(m_commandList.Get(), m_pipelineState1.Get(), m_pipelineState2.Get(), m_currentFrameResourceIndex, m_numIndices, &m_indexBufferView,
&m_vertexBufferView, m_cbvSrvHeap.Get(), m_cbvSrvDescriptorSize, m_samplerHeap.Get(), m_rootSignature.Get());
}

// Indicate that the back buffer will now be used to present.
m_commandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_renderTargets[m_frameIndex].Get(), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT));

ThrowIfFailed(m_commandList->Close());
}

```

请参阅 [Direct3D 12 参考中的示例代码](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 系列

## 另请参阅

[ID3D12GraphicsCommandList](/reference/graphics/d3d12_xs/interfaces/ID3D12GraphicsCommandList/id3d12graphicscommandlist_xs)


## Related topics

- [捆绑包（Bundles）](/zh-CN/publishing/game-publishing/concepts/bundle.md)
- [ExecuteFunctionResult](/zh-CN/services/playfab/api-references/events/data-types/executefunctionresult.md)
- [XGameStreamingGetTouchBundleVersion](/zh-CN/reference/system/xgamestreaming/functions/xgamestreaminggettouchbundleversion.md)
- [ExecuteCloudScriptResult](/zh-CN/services/playfab/api-references/events/data-types/executecloudscriptresult.md)
- [XGameStreamingGetTouchBundleVersionNameSize](/zh-CN/reference/system/xgamestreaming/functions/xgamestreaminggettouchbundleversionnamesize.md)
