DXGI 桌面复制屏幕捕获速度

DXGI Desktop Duplication Screen Capture Speed

我正在使用 AcquireNextFrame from the Desktop Duplication API 来捕获屏幕。屏幕的刷新率为120Hz。 运行 120FPS的游戏时,截屏可以120FPS抓帧。但当将游戏帧率提高到 240FPS 时,屏幕捕获实际上下降到 70FPS 左右。我的猜测是额外的帧正在累积,这会增加开销,但我不确定。有没有办法避免这种性能下降?

Desktop Duplication API 通过设计累积监视器("output" 在 DXGI 术语中)更新,直到您通过 AcquireNextFrame 请求它们。 API 并非旨在首先捕获每个更新。此外,您没有指定您是在 AcquireNextFrame 循环中做任何其他事情,还是只是测量性能(尽管问题的语言暗示后者)。

也就是说,对于真正密集的前端应用程序,输出重复 API 错过更新是完全可以预料的。那里也没有太多的灵活性。也许最重要的提示可用 MSDN 在 ReleaseFrame 备注部分提到:

For performance reasons, we recommend that you release the frame just before you call the IDXGIOutputDuplication::AcquireNextFrame method to acquire the next frame. When the client does not own the frame, the operating system copies all desktop updates to the surface. This can result in wasted GPU cycles if the operating system updates the same region for each frame that occurs. When the client acquires the frame, the client is aware of only the final update to this region; therefore, any overlapping updates during previous frames are wasted. When the client acquires a frame, the client owns the surface; therefore, the operating system can track only the updated regions and cannot copy desktop updates to the surface. Because of this behavior, we recommend that you minimize the time between the call to release the current frame and the call to acquire the next frame.

也就是说,提前或推迟调用 ReleaseFrame 会影响 API 的内部行为。它要么在一般情况下累积更新,要么也不断将实际有效负载数据复制到重复的帧资源中。