Files
XCEngine/docs/plan/end/RHI模块设计与实现/总览.md
ssdfasd 08c01dd143 RHI: Refactor Fence module to pure timeline semantics
- Remove IsSignaled() from RHIFence interface (semantic inconsistency)
- Remove Reset() from OpenGL implementation (no D3D12 counterpart)
- OpenGL Fence now uses single GLsync + CPU counters for timeline simulation
- OpenGL Fence Initialize() now accepts uint64_t initialValue (was bool)
- Add comprehensive timeline semantics tests for all backends:
  - Signal increment/decrement scenarios
  - Multiple signals
  - Wait smaller than completed value
  - GetCompletedValue stages verification
- Update documentation to reflect actual implementation
2026-03-24 01:53:00 +08:00

64 lines
3.3 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.
# RHI 渲染模块设计文档
## 1. 项目背景
本项目旨在参考 Unity 渲染架构,为已有的 **OpenGL** 、**Direct3D 12** 和 **Vulkan** 图形 API 后端设计统一的**渲染硬件抽象层RHI**,屏蔽 API 差异,实现引擎上层逻辑与底层图形 API 的解耦。
## 2. 核心设计理念
### 2.1 总体原则
**求同存异,分层抽象,特性降级,底层逃逸**
- **求同存异**:优先提取 API 共性作为核心抽象,差异部分通过模拟/降级处理
- **分层抽象**:通过清晰的层级结构隔离 API 差异
- **特性降级**:对高级特性提供能力检测和替代方案
- **底层逃逸**:允许直接访问原生 API 以满足极端需求
### 2.2 差异分类与处理策略
| 差异类型 | 典型示例 | 处理方案 |
|----------|----------|----------|
| 概念命名不同但本质相似 | D3D12 `CommandList` ≈ OpenGL 状态机绘制 | 直接统一抽象 |
| 显式控制 vs 隐式管理 | D3D12 `DescriptorHeap` vs OpenGL 纹理单元 | 提供"自动模式"+"显式模式" |
| API 独有高级特性 | D3D12 光线追踪、网格着色器 | 特性检测 + 降级方案 + 底层逃逸 |
## 3. RHI 分层架构
### 3.1 通用分层模型
```
┌─────────────────────────────────┐
│ 引擎功能层(场景/材质/光照) │
├─────────────────────────────────┤
│ 渲染管线层SRP/Render Graph
├─────────────────────────────────┤
│ RHI 抽象层(统一接口) │ ← 核心设计重点
├─────────────────────────────────┤
│ API 后端层D3D12/OpenGL
├─────────────────────────────────┤
│ 驱动/硬件层 │
└─────────────────────────────────┘
```
### 3.2 层级职责说明
1. **引擎功能层**:提供场景管理、材质系统、光照等高级功能接口
2. **渲染管线层**:定义渲染流程(前向/延迟渲染)
3. **RHI 抽象层**:统一图形 API 接口,屏蔽差异
4. **API 后端层**:针对具体 API 的实现
5. **驱动/硬件层**:最终执行渲染指令
## 4. RHI 抽象基类设计
include/XCEngine/RHI/
├── RHIEnums.h # 通用枚举
├── RHITypes.h # 通用结构体
├── RHICapabilities.h # 硬件能力检测
├── RHIDevice.h # 设备抽象(核心入口)
├── RHICommandQueue.h # 命令队列抽象
├── RHICommandList.h # 命令列表抽象
├── RHIBuffer.h # 缓冲区抽象
├── RHITexture.h # 纹理抽象
├── RHIShader.h # 着色器抽象
├── RHIPipelineLayout.h # 管线布局抽象(替代 RootSignature
├── RHIPipelineState.h # 管线状态抽象
├── RHISwapChain.h # 交换链抽象
├── RHIFence.h # 同步栅栏抽象
├── RHIDescriptorPool.h # 描述符池抽象
└── RHIFactory.h # RHI 工厂类