perf: 降低低帧率下 WGC 的延迟

This commit is contained in:
Xu 2025-11-14 18:57:39 +08:00
commit 730d73ecea
2 changed files with 10 additions and 5 deletions

View file

@ -90,6 +90,15 @@ FrameSourceState GraphicsCaptureFrameSource::_Update() noexcept {
return FrameSourceState::Waiting;
}
// 取最新帧,帧率较低时可以有效降低延迟
while (true) {
if (winrt::Direct3D11CaptureFrame nextFrame = _captureFramePool.TryGetNextFrame()) {
frame = std::move(nextFrame);
} else {
break;
}
}
// 从帧获取 IDXGISurface
winrt::IDirect3DSurface d3dSurface = frame.Surface();
@ -314,7 +323,7 @@ bool GraphicsCaptureFrameSource::_StartCapture() noexcept {
_captureFramePool = winrt::Direct3D11CaptureFramePool::Create(
_wrappedD3DDevice,
winrt::DirectXPixelFormat::B8G8R8A8UIntNormalized,
1, // 帧的缓存数量
4, // 帧的缓存数量,更大的值有利于在低帧率下降低延迟
{ (int)_frameBox.right, (int)_frameBox.bottom } // 帧的尺寸为包含源窗口的最小尺寸
);

View file

@ -9,8 +9,6 @@
<ItemGroup>
<ClInclude Include="PackageFiles.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="Utils.h" />
<ClInclude Include="Version.h" />
<ClInclude Include="resource.h">
<Filter>Resources</Filter>
</ClInclude>
@ -18,8 +16,6 @@
<ItemGroup>
<ClCompile Include="main.cpp" />
<ClCompile Include="pch.cpp" />
<ClCompile Include="Utils.cpp" />
<ClCompile Include="Version.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Updater.rc">