# D3D12CommandList **命名空间**: `XCEngine::RHI` **类型**: `class` **头文件**: `XCEngine/RHI/D3D12/D3D12CommandList.h` **描述**: DirectX 12 命令列表封装类,负责录制图形和计算命令 ## 概述 D3D12CommandList 是 DirectX 12 命令列表的封装类,继承自 RHICommandList 接口。它负责录制所有图形渲染命令,包括状态设置、绘制调用、资源状态转换、复制操作等。D3D12CommandList 支持命令列表重置和关闭以实现命令重用,内部维护资源状态跟踪以优化状态转换屏障。 该类是渲染管线的核心,负责将所有渲染操作命令化并提交到 GPU 执行。 ## 公共方法 | 方法 | 描述 | |------|------| | `D3D12CommandList()` | 默认构造函数 | | `~D3D12CommandList()` | 虚析构函数 | | [Initialize](d3d12-command-list-initialize.md) | 初始化命令列表 | | [Shutdown](d3d12-command-list-shutdown.md) | 关闭命令列表 | | [Reset](d3d12-command-list-reset.md) | 重置命令列表 | | [Close](d3d12-command-list-close.md) | 关闭命令列表 | | [TransitionBarrier](d3d12-command-list-transition-barrier.md) | 设置资源转换屏障 | | [SetRenderTargets](d3d12-command-list-set-render-targets.md) | 设置渲染目标 | | [Draw](d3d12-command-list-draw.md) | 绘制调用 | | [DrawIndexed](d3d12-command-list-draw-indexed.md) | 绘制索引图元 | | [ClearRenderTarget](d3d12-command-list-clear-render-target.md) | 清除渲染目标 | | [ClearDepthStencil](d3d12-command-list-clear-depth-stencil.md) | 清除深度模板 | | [CopyResource](d3d12-command-list-copy-resource.md) | 复制资源 | | [Dispatch](d3d12-command-list-dispatch.md) | 分发计算任务 | ## 使用示例 ```cpp #include using namespace XCEngine::RHI; // 创建命令列表 D3D12CommandList commandList; commandList.Initialize(device, CommandQueueType::Direct); // 开始录制命令 commandList.Reset(); // 设置渲染目标 commandList.SetRenderTargets(1, &renderTargetView, nullptr); float clearColor[] = { 0.0f, 0.0f, 0.0f, 1.0f }; commandList.ClearRenderTarget(renderTargetView, clearColor); // 设置视口 Viewport viewport = { 0.0f, 0.0f, 1280.0f, 720.0f, 0.0f, 1.0f }; commandList.SetViewport(viewport); // 设置图元拓扑 commandList.SetPrimitiveTopology(PrimitiveTopology::TriangleList); // 绑定顶点缓冲区 commandList.SetVertexBuffer(0, vertexBuffer, 0, sizeof(Vertex)); // 绑定索引缓冲区 commandList.SetIndexBuffer(indexBuffer, 0, Format::R32_UInt); // 绑定管道状态 commandList.SetPipelineState(pipelineState); // 绘制 commandList.DrawIndexed(indexCount, 1, 0, 0, 0); // 关闭命令列表 commandList.Close(); // 提交到命令队列 commandQueue->ExecuteCommandListsInternal(1, &cmdList); ``` ## 相关文档 - [D3D12 模块概览](d3d12.md) - D3D12 模块总览 - [RHICommandList](../rhi/command-list/command-list.md) - RHI 命令列表基类 - [D3D12CommandQueue](d3d12-command-queue.md) - 命令队列