Question

I'm trying several methods to capture screen with DirectX and I've come up with 3 methods so far:

  • GetFrontBufferData() - Average execution times:
    • GetFrontBufferData(): 0.83598 s
    • D3DXSaveSurfaceToFile(): 0.0036 s
    • Total: 0.83958 s
  • GetBackBuffer() - Average execution times:
    • GetBackBuffer(): 0 s <-- INTERESTING - WHY?
    • D3DXSaveSurfaceToFile(): 0.2918 s
    • Total: 0.2918 s
  • GetRenderTargetData() - Average execution times:
    • GetRenderTargetData(): 0.00928 s
    • D3DXSaveSurfaceToFile(): 0.00354 s
    • Total: 0.01282 s

Average times have been computed by taking 50 screenshots and by measuring time with clock().

All the methods above work, however, as you can see, execution times vary a lot from one method to another for the same results (apparently).

So I have a few questions:

  • Why the execution time differs so much from one method to another?
  • Why is GetBackBuffer() very fast but then D3DXSaveSurfaceToFile() is very slow?

I have an hypothesis about my first question, correct me if I'm wrong:

  • GetFrontBufferData() is very slow because the front buffer is in the VRAM and it's locked/protected because that's what's currently displayed to the screen.
  • GetBackBuffer() (and D3DXSaveSurfaceToFile()) is faster because the back buffer is in the VRAM but it's not currently displayed to the screen, so it's easier to retrieve.
  • Finally, GetRenderTargetData() is fast because the render target is in the system ram (not in the VRAM) so we can retrieve it very fast.

Thank you.

EDIT: I'm still looking for an answer.

Was it helpful?

Solution

The process you are referring to is called 'readback' which involves copying the data back from the GPU video RAM. With the exception of a few specific unified memory architectures (such as Xbox 360), readback is a slow process.

Depending on your OS and other settings, it's likely that the front buffer and the back buffer are both just 'offscreen' textures in VRAM. There are also various locks and GPU pipeline stalls involved when you halt rendering to capture a screen shot.

You may find this (now rather old) article useful.

Note that Direct3D 10/11 offer many features to overcome the inherent slowness of 'readback' from the GPU mostly by allowing algorithms to keep the data on the GPU.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top