4

I'm having some code (compiled into a standalone executable) to take a screenshot. It runs pretty fast (around 100ms), however, as soon as I run something graphic intensive (like a game), it takes up to 2 minutes, even though CPU and GPU are not fully exhausted. Specifically, I use IDXGIOutputDuplication to grab the screen, and then some code I have "borrowed" from here https://github.com/microsoft/DirectXTex/blob/main/ScreenGrab/ScreenGrab11.cpp to save the screen as a picture to file. Specifically the "encoding" part, i.e., use of the encoder seems to be problem. Any ideas about (1) where this massive performance impact is coming from and (2) how to improve it?

Full code here: https://github.com/plengauer/DXGIOutputDuplication

Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
loonytune
  • 1,775
  • 11
  • 22
  • 1
    IDXGIOutputDuplication is *not* a screen capture API. It just duplicates the video frames (DXGI) to a buffer when there are new video frames (or changes) available. DXGI_ERROR_WAIT_TIMEOUT is typically expected (no changes available). You must not couple your main loop to AcquireNextFrame. You should study Microsoft's official that uses multiple threads: sample https://github.com/microsoft/Windows-classic-samples/tree/main/Samples/DXGIDesktopDuplication – Simon Mourier Apr 19 '22 at 14:04
  • @SimonMourier I did not say im not expecting DXGI_ERROR_WAIT_TIMEOUT. Since my app is a standalone application, then what would i couple it to if not to the main loop? My question is not about the timeout, its about the encoder taking forever. – loonytune Apr 19 '22 at 14:07
  • 2
    If this is taking up to two minutes, you could just break with debugger and see where things are (and update the question). Also CPU and GPU resources could really be exhausted, it is just not clear how exactly you measure it (you could also attach the details to the question itself). – Roman R. Apr 19 '22 at 17:37

0 Answers0