hecomi / uDesktopDuplication

Desktop Duplication API implementation for Unity (only for Windows 8/10)
http://tips.hecomi.com/entry/2016/12/04/125641
MIT License
563 stars 97 forks source link

ReleaseFrame should be called as late as possibe #18

Closed gnif closed 6 years ago

gnif commented 6 years ago

I don't use this project but was looking for examples and noticed this.

According to the Microsoft documentation you should be calling ReleaseFrame just before AcquireFrame to prevent GPU resources being wasted.

See: https://msdn.microsoft.com/en-us/library/windows/desktop/hh404623(v=vs.85).aspx

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.

https://github.com/hecomi/uDesktopDuplication/blob/8434d803bb1422a7e75855383f5c3ee3d3512c6e/Plugins/uDesktopDuplication/uDesktopDuplication/Duplicator.cpp#L284

hecomi commented 6 years ago

Sorry for my late reply and thank you very much for providing the information. I've moved the ReleaseFrame() timing just before AcquireNextFrame().