Files
XCEngine/docs/api/rhi/command-queue/command-queue.md
2026-03-20 02:35:45 +08:00

75 lines
2.4 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.
# RHICommandQueue
**命名空间**: `XCEngine::RHI`
**类型**: `class` (抽象基类)
**头文件**: `XCEngine/RHI/RHICommandQueue.h`
**描述**: GPU 命令队列抽象接口,负责提交和执行命令列表,以及 GPU/CPU 同步。
## 概述
`RHICommandQueue` 是 RHIRender Hardware Interface系统中的核心抽象接口之一封装了底层图形 APID3D12/Vulkan/Metal 等)的命令队列功能。
主要职责:
- **命令提交**:将准备好的命令列表提交到 GPU 执行
- **GPU/CPU 同步**通过栅栏Fence机制协调 CPU 和 GPU 的执行顺序
- **队列类型管理**:区分直接队列、计算队列和复制队列
使用场景:
- 渲染循环中提交绘制命令
- 资源在 GPU 和 CPU 之间传输时的同步
- 多线程渲染时的命令生成和提交
## 公共方法
| 方法 | 描述 |
|------|------|
| [`Shutdown`](shutdown.md) | 关闭并释放资源 |
| [`ExecuteCommandLists`](execute-command-lists.md) | 执行命令列表 |
| [`Signal`](signal.md) | 向栅栏发送信号 |
| [`Wait`](wait.md) | 等待栅栏达到指定值 |
| [`GetCompletedValue`](get-completed-value.md) | 获取栅栏已完成的值 |
| [`WaitForIdle`](wait-for-idle.md) | 等待队列所有操作完成 |
| [`GetType`](get-type.md) | 获取队列类型 |
| [`GetTimestampFrequency`](get-timestamp-frequency.md) | 获取时间戳频率 |
| [`GetNativeHandle`](get-native-handle.md) | 获取原生句柄 |
## 使用示例
```cpp
#include "RHICommandQueue.h"
#include "RHIDevice.h"
#include "RHIFence.h"
#include "RHICommandList.h"
void RenderLoop(RHIDevice* device, RHICommandQueue* cmdQueue) {
CommandQueueDesc queueDesc;
queueDesc.queueType = (uint32_t)CommandQueueType::Direct;
RHICommandQueue* commandQueue = device->CreateCommandQueue(queueDesc);
FenceDesc fenceDesc;
RHIFence* fence = device->CreateFence(fenceDesc);
RHICommandList* commandList = device->CreateCommandList();
commandList->Begin();
commandList->DrawInstanced(vertices, vertexCount, 0);
commandList->End();
void* lists[1] = { commandList };
commandQueue->ExecuteCommandLists(1, lists);
commandQueue->Signal(fence, 1);
fence->Wait(1);
commandQueue->WaitForIdle();
commandQueue->Shutdown();
}
```
## 相关文档
- [RHI 模块](../rhi.md) - RHI 模块总览
- [RHICommandList](../command-list/command-list.md) - 命令列表
- [RHIFence](../fence/fence.md) - 同步栅栏