Files
XCEngine/docs/api/d3d12/d3d12-command-list.md
ssdfasd 7c3f304688 refactor(docs): D3D12模块文档重构 - 修复链接错误并新增Buffer/Texture/SwapChain方法文档
- 新增32个方法文档(D3D12Buffer 13个,D3D12Texture 12个,D3D12SwapChain 6个)
- 修复11处跨模块引用错误(rhi-device.md, rhi-texture.md等路径错误)
- 清理d3d12-overview.md移除不存在的类引用
- 修复D3D12Device/D3D12CommandList/D3D12CommandQueue方法列表
- D3D12模块现无broken links
2026-03-26 01:49:24 +08:00

86 lines
2.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 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 <XCEngine/RHI/D3D12/D3D12CommandList.h>
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) - 命令队列