refactor: reorganize docs into plan/ and add skills/
This commit is contained in:
82
docs/api/rhi/d3d12/d3d12-query-heap.md
Normal file
82
docs/api/rhi/d3d12/d3d12-query-heap.md
Normal file
@@ -0,0 +1,82 @@
|
||||
# D3D12QueryHeap
|
||||
|
||||
DirectX 12 查询堆的 D3D12 实现,封装了 `ID3D12QueryHeap`。
|
||||
|
||||
## 头文件
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/RHI/D3D12/D3D12QueryHeap.h>
|
||||
```
|
||||
|
||||
## 公共成员函数
|
||||
|
||||
### 构造函数与析构函数
|
||||
|
||||
#### `D3D12QueryHeap()`
|
||||
默认构造函数。
|
||||
|
||||
#### `~D3D12QueryHeap()`
|
||||
析构函数,确保调用 `Shutdown()`。
|
||||
|
||||
### 初始化
|
||||
|
||||
#### `bool Initialize(ID3D12Device* device, QueryType type, uint32_t count)`
|
||||
初始化查询堆。
|
||||
- `device`: D3D12 设备
|
||||
- `type`: 查询类型
|
||||
- `count`: 查询数量
|
||||
- 返回: 初始化是否成功
|
||||
|
||||
#### `void Shutdown()`
|
||||
释放查询堆。
|
||||
|
||||
### 属性
|
||||
|
||||
#### `ID3D12QueryHeap* GetQueryHeap() const`
|
||||
获取底层 `ID3D12QueryHeap` 指针。
|
||||
|
||||
#### `void* GetNativeHandle() const`
|
||||
返回原生句柄。
|
||||
|
||||
#### `QueryType GetType() const`
|
||||
获取查询类型。
|
||||
|
||||
#### `uint32_t GetCount() const`
|
||||
获取查询数量。
|
||||
|
||||
## 内部成员
|
||||
|
||||
| 成员 | 类型 | 描述 |
|
||||
|------|------|------|
|
||||
| `m_queryHeap` | `ComPtr<ID3D12QueryHeap>` | D3D12 查询堆 |
|
||||
| `m_type` | `QueryType` | 查询类型 |
|
||||
| `m_count` | `uint32_t` | 查询数量 |
|
||||
|
||||
## 使用示例
|
||||
|
||||
```cpp
|
||||
// Create query heap for occlusion
|
||||
D3D12QueryHeap queryHeap;
|
||||
queryHeap.Initialize(device->GetDevice(), QueryType::Occlusion, 2);
|
||||
|
||||
// Create readback buffer for results
|
||||
D3D12Buffer readbackBuffer;
|
||||
readbackBuffer.Initialize(device->GetDevice(), sizeof(uint64_t) * 2,
|
||||
D3D12_RESOURCE_STATE_COPY_DEST, D3D12_HEAP_TYPE_READBACK);
|
||||
|
||||
// In render pass
|
||||
cmdList->BeginQuery(queryHeap.GetQueryHeap(), QueryType::Occlusion, 0);
|
||||
// Draw bounding box
|
||||
cmdList->Draw(8);
|
||||
cmdList->EndQuery(queryHeap.GetQueryHeap(), QueryType::Occlusion, 0);
|
||||
|
||||
// Resolve to readback buffer
|
||||
cmdList->ResolveQueryData(queryHeap.GetQueryHeap(), QueryType::Occlusion, 0, 1,
|
||||
readbackBuffer.GetResource(), 0);
|
||||
```
|
||||
|
||||
## 备注
|
||||
|
||||
- 三种查询类型: Occlusion(遮挡)、Timestamp(时间戳)、PipelineStatistics(管线统计)
|
||||
- 查询数据需要通过 resolve 操作复制到可读缓冲区
|
||||
- 时间戳查询需要命令队列支持时间戳功能
|
||||
Reference in New Issue
Block a user