feat: 帧率控制——手动限帧 + VSync 开关

- Application 帧率控制 API:SetLimitFps/SetTargetFps/SetVSync。
  限帧目标最低 24fps(防止过低刷新导致交互卡死),无上限;
  vsync 开启时 present 自带节奏,手动限帧不生效
- 限帧策略:sleep 到剩 ~2ms 后自旋,精度高且不烧 CPU
- Swapchain 加 VSync 开关:ChoosePresentMode 按开关选
  Mailbox(低延迟垂直同步)/ Immediate(不限速可撕裂),
  FIFO 兜底;切换经 SetVSync → 重建 swapchain(复用 HandleResize)
- Scene Debug 面板新增 Frame 区块(vsync/limit/目标滑条)
- Run 循环新增 CPU 归属遥测(update/ui/render/total,每 120 帧)
This commit is contained in:
2026-09-22 20:33:10 +08:00
parent cef32ea1ba
commit d8274e8bdc
7 changed files with 102 additions and 11 deletions
+15
View File
@@ -54,6 +54,16 @@ namespace Engine {
// 主渲染(ImGui pass 把 draw data 叠加到场景上)。
void EnableImGui();
// ---- 帧率控制 ----
// vsync 开启时 present 自带节奏,手动限帧不生效;
// 限帧目标最低 24fps(防止过低刷新导致交互卡死),无上限
void SetVSync(bool vsync);
bool GetVSync() const { return m_VSync; }
void SetLimitFps(bool on) { m_LimitFps = on; }
bool GetLimitFps() const { return m_LimitFps; }
void SetTargetFps(f32 fps) { m_TargetFps = std::max(24.0f, fps); }
f32 GetTargetFps() const { return m_TargetFps; }
// ---- 供派生类访问的模块 ----
Window& GetWindow() const { return *m_Window; }
Renderer& GetRenderer() const { return *m_Renderer; }
@@ -108,6 +118,11 @@ namespace Engine {
f32 m_DeltaTime = 0.0f;
u64 m_FrameCount = 0;
// 帧率控制
bool m_VSync = true; // 垂直同步(present 自带节奏)
bool m_LimitFps = false; // 手动限帧开关(vsync 开启时不生效)
f32 m_TargetFps = 60.0f; // 限帧目标(≥24)
std::chrono::steady_clock::time_point m_LastFrameTime;
};