0

My final goal is to get screenshots of a cropped area on the screen as fast as possible.

I'm using the the desktop duplication api with sharpdx to retrieve the full screenshot from windows according to the official sample :

https://github.com/sharpdx/SharpDX-Samples/blob/master/Desktop/Direct3D11.1/ScreenCapture/Program.cs.

I'm currently cropping at CPU level with a pinned memory bitmap and Buffer.BlockCopy on the raw bytes which, IMO, cannot be considerably anymore faster.

Is it possible to apply a simple crop operation at GPU level?

Perfect28
  • 11,089
  • 3
  • 25
  • 45
  • Many remarks can be done to this sample: mapping GPU bitmap to CPU is inefficient, using GDI+ in this context is inefficient, copying the bitmap line per line is inefficient. First things first: what do you want to do with the captured areas? – Simon Mourier May 27 '21 at 10:05
  • Hello agilitypack father. I'm looking for a specific pattern on the captured areas. From my benchmarks, this pixel level search takes approximatively less than one ms (O(n) operation) . My main issue is that the captured zone is already 15ms+ old when the search start. – Perfect28 May 27 '21 at 10:28
  • I'm using GDI library as described in this answer https://stackoverflow.com/questions/24701703/c-sharp-faster-alternatives-to-setpixel-and-getpixel-for-bitmaps-for-windows-f which I allocate once and i just "memcopy" the captured zone to the pined buffer. I apply the crop operation immediatly on the buffer without using any GDI API. Actually, i'm only using the GDI API to save some png on debug mode. – Perfect28 May 27 '21 at 10:28
  • the overall goal is to build some automated test on a directx application where i should a click on a moving object. the click is always late when the object move faster due to this lag. – Perfect28 May 27 '21 at 10:34
  • 1
    Ideally, everything that can happen in GPU should happen in GPU and GPU <-> CPU should be reduced at maximum, so ideally, you should code your pattern search in a GPU shader and only get synthetic information. Ok, this can be complex, so, right now you can use ID3D11DeviceContext::CopySubresourceRegion (I have no idea how you do that with SharpDX which is painful because it redefines all terms and ways of doing things). You can also use Direct2D, and use its built-in shaders, for ex. Atlas: https://learn.microsoft.com/en-us/windows/win32/direct2d/atlas – Simon Mourier May 27 '21 at 12:24
  • thanks for you reply. I will explore these ways. – Perfect28 May 27 '21 at 12:50
  • @SimonMourier in SharpDX, function is deviceContext.CopySubresourceRegion as well, the only difference is indeed the source DataBox is a ResourceRegion struct (members are the same tho, parameter order is slightly different too) – mrvux Jul 19 '21 at 10:08

0 Answers0