feat: implement Fence synchronization for CPU-GPU frame sync
D3D12 Core: - Add ID3D12Fence1 and fence_value to d3d12_command - Add fence_event for CPU waiting - Implement wait() in command_frame for frame sync - Implement flush() to wait all frames complete - Add fence_value tracking per frame - Signal fence at end_frame with incremented value TestRenderer: - Call graphics::render() in run() Documentation: - Add changelog for Fence sync implementation - Update D3D12 Wiki with Fence sync section
This commit is contained in:
@@ -211,6 +211,33 @@ _frame_index = (_frame_index + 1) % frame_buffer_count;
|
||||
|
||||
环形缓冲区管理帧资源,确保 CPU 不会超前 GPU 超过 3 帧。
|
||||
|
||||
### 6.4 Fence 同步机制
|
||||
|
||||
项目实现了 Fence(围栏)同步,确保 CPU-GPU 帧同步:
|
||||
|
||||
```cpp
|
||||
struct command_frame
|
||||
{
|
||||
ID3D12CommandAllocator* cmd_allocator{ nullptr };
|
||||
u64 fence_value{ 0 }; // 该帧的围栏值
|
||||
|
||||
void wait(HANDLE fence_event, ID3D12Fence1* fence);
|
||||
};
|
||||
```
|
||||
|
||||
**同步流程**:
|
||||
1. `begin_frame()` - 检查 GPU 是否完成当前帧,未完成则等待
|
||||
2. `end_frame()` - 递增围栏值,向 GPU 发送信号
|
||||
|
||||
```cpp
|
||||
// 帧结束信号
|
||||
++_fence_value;
|
||||
_cmd_frames[_frame_index].fence_value = _fence_value;
|
||||
_cmd_queue->Signal(_fence, _fence_value);
|
||||
```
|
||||
|
||||
**围栏值溢出**:64位无符号整数,每秒1000帧需要5.8亿年才回绕,无需担心。
|
||||
|
||||
## 7. 渲染表面与窗口
|
||||
|
||||
### 7.1 render_surface 结构
|
||||
|
||||
Reference in New Issue
Block a user