docs: update RHI API docs

This commit is contained in:
2026-03-20 02:35:45 +08:00
parent ea756c0177
commit 070b444f8f
501 changed files with 13493 additions and 2022 deletions

View File

@@ -2,36 +2,79 @@
**命名空间**: `XCEngine::RHI`
**类型**: `class` (继承自 `RHIBuffer`)
**描述**: DirectX 12 缓冲区的 D3D12 实现,继承自 `RHIBuffer`
## 概述
`D3D12Buffer` 是 RHI 缓冲区接口的 DirectX 12 后端实现。该类封装了 `ID3D12Resource` 对象,提供缓冲区的创建、初始化、数据更新和状态管理功能。支持顶点缓冲区、索引缓冲区、常量缓冲区等多种缓冲区类型。
## 公共方法
### D3D12 特有方法
| 方法 | 描述 |
|------|------|
| [`Initialize`](initialize.md) | 初始化缓冲区 |
| [`InitializeFromExisting`](initialize-from-existing.md) | 从现有资源初始化 |
| [`InitializeWithData`](initialize-with-data.md) | 初始化并写入数据 |
| [`Shutdown`](shutdown.md) | 关闭缓冲区 |
| [`UpdateData`](update-data.md) | 更新数据 |
| [`Map`](map.md) | 映射缓冲区 |
| [`Unmap`](unmap.md) | 取消映射 |
| [`SetData`](set-data.md) | 设置数据 |
| [`GetResource`](get-resource.md) | 获取 D3D12 资源 |
| [`GetDesc`](get-desc.md) | 获取描述符 |
| [`GetGPUVirtualAddress`](get-gpu-virtual-address.md) | 获取 GPU 虚拟地址 |
| [`GetGPUAddress`](get-gpu-address.md) | 获取 GPU 地址 |
| [`GetSize`](get-size.md) | 获取缓冲区大小 |
| [`GetState`](get-state.md) | 获取资源状态 |
### 继承自 RHIBuffer 的方法
| 方法 | 描述 |
|------|------|
| [`Shutdown`](../../buffer/shutdown.md) | 关闭缓冲区 |
| [`Map`](../../buffer/map.md) | 映射缓冲区 |
| [`Unmap`](../../buffer/unmap.md) | 取消映射 |
| [`SetData`](../../buffer/set-data.md) | 设置数据 |
| [`GetSize`](../../buffer/get-size.md) | 获取缓冲区大小 |
| [`GetState`](../../buffer/get-state.md) | 获取资源状态 |
| [`SetState`](../../buffer/set-state.md) | 设置资源状态 |
| [`GetName`](get-name.md) | 获取资源名称 |
| [`GetName`](../../buffer/get-name.md) | 获取资源名称 |
| [`SetName`](../../buffer/set-name.md) | 设置资源名称 |
| [`GetStride`](get-stride.md) | 获取步长 |
| [`GetStride`](../../buffer/get-stride.md) | 获取步长 |
| [`SetStride`](../../buffer/set-stride.md) | 设置步长 |
| [`GetBufferType`](get-buffer-type.md) | 获取缓冲区类型 |
| [`GetBufferType`](../../buffer/get-buffer-type.md) | 获取缓冲区类型 |
| [`SetBufferType`](../../buffer/set-buffer-type.md) | 设置缓冲区类型 |
| [`GetNativeHandle`](get-native-handle.md) | 获取原生句柄 |
| [`GetNativeHandle`](../../buffer/get-native-handle.md) | 获取原生句柄 |
## 使用示例
```cpp
// 创建顶点缓冲区
D3D12Buffer vertexBuffer;
vertexBuffer.Initialize(
device,
sizeof(Vertex) * vertexCount,
D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER,
D3D12_HEAP_TYPE_DEFAULT);
vertexBuffer.SetName(L"VertexBuffer");
vertexBuffer.SetBufferType(BufferType::Vertex);
vertexBuffer.SetStride(sizeof(Vertex));
// 创建索引缓冲区(带初始数据)
D3D12Buffer indexBuffer;
uint16_t indices[] = { 0, 1, 2, 1, 3, 2 };
indexBuffer.InitializeWithData(
device,
commandList,
indices,
sizeof(indices),
D3D12_RESOURCE_STATE_INDEX_BUFFER);
// 使用 UPLOAD 堆更新数据
D3D12Buffer uploadBuffer;
uploadBuffer.Initialize(device, uploadSize, D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_HEAP_TYPE_UPLOAD);
uploadBuffer.UpdateData(newData, dataSize);
```
## 相关文档
- [D3D12 后端总览](../../opengl/overview.md)
- [D3D12 后端总览](../../d3d12/d3d12.md)
- [RHIBuffer](../../buffer/buffer.md) - 抽象缓冲区接口

View File

@@ -1,16 +0,0 @@
# D3D12Buffer::GetBufferType / SetBufferType
## 函数签名
```cpp
BufferType GetBufferType() const override
void SetBufferType(BufferType type) override
```
## 中文描述
获取和设置缓冲区类型Vertex / Index / Constant 等)。
## 复杂度
O(1)

View File

@@ -1,16 +0,0 @@
# D3D12Buffer::GetName / SetName
## 函数签名
```cpp
const std::string& GetName() const override
void SetName(const std::string& name) override
```
## 中文描述
获取和设置对象名称(用于调试)。
## 复杂度
O(1)

View File

@@ -1,19 +0,0 @@
# D3D12Buffer::GetNativeHandle
## 函数签名
```cpp
void* GetNativeHandle() override
```
## 中文描述
返回原生句柄,即 `ID3D12Resource*`
## 返回值
`void*` - 原生句柄
## 复杂度
O(1)

View File

@@ -1,19 +0,0 @@
# D3D12Buffer::GetSize
## 函数签名
```cpp
uint64_t GetSize() const override
```
## 中文描述
获取缓冲区大小(字节)。
## 返回值
`uint64_t` - 缓冲区大小
## 复杂度
O(1)

View File

@@ -1,16 +0,0 @@
# D3D12Buffer::GetState / SetState
## 函数签名
```cpp
ResourceStates GetState() const
void SetState(ResourceStates state)
```
## 中文描述
获取和设置当前资源状态。用于状态跟踪和屏障生成。
## 复杂度
O(1)

View File

@@ -1,16 +0,0 @@
# D3D12Buffer::GetStride / SetStride
## 函数签名
```cpp
uint32_t GetStride() const override
void SetStride(uint32_t stride) override
```
## 中文描述
获取和设置顶点缓冲区步长(字节)。
## 复杂度
O(1)

View File

@@ -33,9 +33,9 @@ O(n) - 取决于数据大小,内部创建临时上传堆
```cpp
uint16_t indices[] = { 0, 1, 2, 1, 3, 2 };
D3D12Buffer indexBuffer;
D3D12Buffer::InitializeWithData(
device->GetDevice(),
cmdList->GetCommandList(),
indexBuffer.InitializeWithData(
device,
commandList,
indices,
sizeof(indices),
D3D12_RESOURCE_STATE_INDEX_BUFFER);

View File

@@ -1,27 +0,0 @@
# D3D12Buffer::Map
## 函数签名
```cpp
void* Map() override
```
## 中文描述
将缓冲区内存映射到 CPU 可访问地址。仅对 UPLOAD 或 READBACK 堆有效。
## 返回值
`void*` - 映射的内存指针
## 复杂度
O(1)
## 示例
```cpp
void* mapped = uploadBuffer.Map();
memcpy(mapped, vertexData, sizeof(vertexData));
buffer.Unmap();
```

View File

@@ -1,23 +0,0 @@
# D3D12Buffer::SetData
## 函数签名
```cpp
void SetData(const void* data, size_t size, size_t offset = 0) override
```
## 中文描述
设置缓冲区数据。通过 Map/Unmap 实现。
## 参数
| 参数 | 类型 | 描述 |
|------|------|------|
| `data` | `const void*` | 数据指针 |
| `size` | `size_t` | 数据大小 |
| `offset` | `size_t` | 缓冲区内的偏移量 |
## 复杂度
O(n)

View File

@@ -1,15 +0,0 @@
# D3D12Buffer::Shutdown
## 函数签名
```cpp
void Shutdown() override
```
## 中文描述
释放 D3D12 缓冲区资源,将成员变量置为空。
## 复杂度
O(1)

View File

@@ -1,15 +0,0 @@
# D3D12Buffer::Unmap
## 函数签名
```cpp
void Unmap() override
```
## 中文描述
解除缓冲区内存映射。
## 复杂度
O(1)

View File

@@ -17,6 +17,10 @@ void UpdateData(const void* data, uint64_t size)
| `data` | `const void*` | 新数据指针 |
| `size` | `uint64_t` | 数据大小 |
## 返回值
## 复杂度
O(n)