refactor(RHI): remove void* from CommandList interfaces and fix OpenGL MRT bug

- Remove void* parameters from RHICommandList abstract interface
- TransitionBarrier, SetVertexBuffer, SetIndexBuffer, SetRenderTargets,
  ClearRenderTarget, ClearDepthStencil, CopyResource now use RHIResourceView*
- SetPipelineState now uses RHIPipelineState* instead of void*
- Simplified SetVertexBuffer to 3 params, SetIndexBuffer to 2 params
- Add internal D3D12 APIs for native type support (low-level escape hatch)
- Fix OpenGL SetRenderTargets to call glDrawBuffers for MRT support
- Update tests to match new interface signatures

All 289 RHI tests pass (158 unit + 64 OpenGL backend + 58 D3D12 backend + 8 integration + 1 disabled)
This commit is contained in:
2026-03-24 17:20:51 +08:00
parent ac5c98584a
commit 0dde7234b7
10 changed files with 132 additions and 173 deletions

View File

@@ -0,0 +1,50 @@
# RHI 渲染模块设计文档
## 1. 项目背景
本项目旨在参考 Unity 渲染架构,为已有的 **OpenGL** 、**Direct3D 12** 和 **Vulkan** 图形 API 后端设计统一的**渲染硬件抽象层RHI**,屏蔽 API 差异,实现引擎上层逻辑与底层图形 API 的解耦。需要注意的是,该模块的抽象层主要面向**Direct3D 12** 和 **Vulkan**这些高级图形API的显示设计。
## 2. 核心设计理念
**求同存异,分层抽象,特性降级,底层逃逸**
- **求同存异**:优先提取 API 共性作为核心抽象,差异部分通过模拟/降级处理
- **分层抽象**:通过清晰的层级结构隔离 API 差异
- **特性降级**:对高级特性提供能力检测和替代方案
- **底层逃逸**:允许直接访问原生 API 以满足极端需求
## 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 工厂类