smasherprog / screen_capture_lite

cross platform screen/window capturing library
MIT License
616 stars 156 forks source link

Issue with DirectX12 on Windows #72

Closed TrentWeiss closed 3 years ago

TrentWeiss commented 5 years ago

I have noticed that capturing applications running DirectX12 on Windows 10 produces nothing but black images (regardless of what is happening in the application). Any idea what would cause this behavior?

smasherprog commented 5 years ago

Ill take a look at it. I think its due to the difference in the framesize/pixel format.

smasherprog commented 5 years ago

I could not reproduce black images. I tried full screen star craft and was able to capture normally. Can you do a little debugging and see where the problem is? It shouldnt be that bad, this file is where all of the work is done https://github.com/smasherprog/screen_capture_lite/blob/master/src/windows/DXFrameProcessor.cpp

smasherprog commented 5 years ago

Theres an example file in this repo where you can capture and write the images to disk. Id start there as this is an easy way to test.

I guess star craft isnt DX12. So, i am installing WOW to test out DX12

TrentWeiss commented 5 years ago

I have been testing on F1 2019 http://www.formula1game.com/.

it has the option to run as either DirectX12 or DirectX11.

On DirectX11, everything works as expected.

On DirectX12, images are just black (except for the title bar, interestingly enough.).

TrentWeiss commented 5 years ago

Looks like DXFrameProcessor explicitly uses the DirectX11 SDK. Could that be the underlying issue?

https://github.com/smasherprog/screen_capture_lite/blob/781732b6e605fe24eb9888dfd5b1bf15484c9edf/src/windows/DXFrameProcessor.cpp#L317

smasherprog commented 5 years ago

Yeah its very likely thats the case. I was going to look into this yesterday but got sidetracked. Ill for sure look at it now though.

TrentWeiss commented 5 years ago

Awesome. I am not a skilled WIN32 programmer and I am certainly not a DirectX programmer, but it looks like Microsoft has a mechanism to ease the interchangeability of the two APIs. https://docs.microsoft.com/en-us/windows/win32/direct3d12/direct3d-11-on-12

smasherprog commented 5 years ago

I cant reproduce what you are experiencing. I am running WOW using DX12. Attached is a screenshot taken using the example code here https://github.com/smasherprog/screen_capture_lite/blob/master/Example/Screen_Capture_Example.cpp 82MONITORNEW_

smasherprog commented 5 years ago

I was also able to capture windows as well without issue. Try using the example code to capture and save the images to disk to see if it works.

smasherprog commented 5 years ago

It could be that application you listed above is doing something it shouldn't be? Can you try a print screen and see if you are able to see the game using that method? If that doesnt work then there is something really strange going on with that app.

TrentWeiss commented 5 years ago

Confirmed, exact same result when using the example code: Results with DirectX11 10WINNEW_DirectX11

Exact same test procedure with DirectX12 10WINNEW_DirectX12

Note the difference in the title bar (which is captured correctly in both cases)

TrentWeiss commented 5 years ago

A manual PrtScr is able to capture the game just fine, even on DirectX12.

printscreen_directx12

smasherprog commented 5 years ago

Strange.. I dont know whats going on. Im going to try some other dx 12 examples/games and see if I can reproduce this. Thanks for your efforts on this.

TrentWeiss commented 5 years ago

No problem. You're the real MVP for making this library. It saved me a TON of effort on my project. I'll keep playing around with the game's settings to see if I can get it to work. In the meantime, the DirectX11 version works wells enough.

TrentWeiss commented 5 years ago

stumbled across these when googling around for solutions: https://github.com/microsoft/DirectXTK https://github.com/Microsoft/DirectXTK12

It looks like Microsoft is finally acknowledging how terrible the interface for the DirectX APIs is and is making (slightly) convenient wrappers.

smasherprog commented 4 years ago

I've been trying dx 12 apps and even created a new dx12 project to try and create a bare-bones app to produce this and I cannot. Ill leave this issue open as I don't know why this specific application isn't capture-able in dx 12 mode.

TrentWeiss commented 4 years ago

I have a feeling the issue is one of the following:

  1. A color space other than BGRA for the rendered images (perhaps HSV or something of the sort)
  2. 16-bit images in DirectX12 mode.

Since the core implementation of screen_capture_lite assumes 8-bit BGRA images, supporting either of those things will require a fairly major overhaul. If DirectX12 compatibility becomes an absolute necessity, I may take it upon myself to propose a new architecture for such a change. But, for now anyways, I'll just keep the game running in DirectX11.

Thanks so much for looking into this!!!

smasherprog commented 3 years ago

https://github.com/smasherprog/screen_capture_lite/pull/89 should have fixed this now