GLWpfControl icon indicating copy to clipboard operation
GLWpfControl copied to clipboard

Support for multi-adapter D3D + fix closing lid issue

Open marcotod1410 opened this issue 4 years ago • 7 comments

Addresses issue #22 . Freely inspired from an official guide from WPF that addresses the issue.

TODO:

  • check if the general approach works
  • if it works:
    • the selection of the correct device should not be in the render phase. It should be safe to do it periodically (in the link posted, it uses a timer that fires every 500 ms or so)
    • the adapter count is evaluated when instantiating the d3d context for the first time. Should we check periodically for adapter count changed (well, is it even possible)?
    • devices should be regularly checked for validity and cleaned up if they are not valid anymore (d3d device lost). In this case, everything (D3D context and all devices) must be recreated again. Methods for cleaning devices were added. (However this is more of general rather than tackling this specific issue and could be addressed in some other PR)

marcotod1410 avatar Dec 05 '20 11:12 marcotod1410

@marcotod1410 - Let's try to get this in. What's our next step? does it work?

varon avatar Jan 06 '21 13:01 varon

It works in single GPU scenario. It would be great to have someone with multiple GPU to test this PR and see if it works!

Remaining TODOs:

  • should we check regularly if there are new adapters?
  • Fix of closing lid issue. This PR has some infrastructure for handling this case, I'm finding a way to detect this situation so to make the control react accordingly.

marcotod1410 avatar Jan 09 '21 10:01 marcotod1410

Unfortunately this PR has conflicts and I can't merge it like it is. I don't know this codebase well enough atm to feel like I want to fix this, if you have time to fix the conflicts that would be nice. Otherwise I'll do it sometime in the future. Moving this to the 4.3.0 milestone.

NogginBops avatar Jun 18 '22 09:06 NogginBops

Have tested the code from marcotod1410:d3d-multiple-devices on a notebook with multipe graphics cards and an external screen (set as primary one). Tested it with the example project and still found few issues:

  • Unplugging the external screen leads to an AccessViolationException in the D3DDevice.Dispose() method on calling Wgl.DXCloseDeviceNV.
  • Dragging the window from the external screen to the notebook internal one leads to an AccessViolationException in the DxGLFrameBuffer constructor on calling Wgl.DXRegisterObjectNV.
  • Starting on the notebook without the external screen and plugging in the external one leads to a black content. Dragging the window back to the notebook screen shows the correct output.

Have tried to solve them with some code adjusting:

  • Removing the Dispose method from D3DDevice
  • Checking the GLDeviceHandle != IntPtr.Zero in the DXGLContext.SetDeviceFromMonitor method before assigning it.

So I could solve the first two issues in my special system setup, but the last one with the black content is still open. Due to my missing background knowledge of the GlWpfControl code I have stopped here and are now calling for help.

And I'am also interested in a solution for the GLWpfControl version 3 for .net framework. Tried the same approach but without any success.

Michael-5430 avatar Dec 08 '22 14:12 Michael-5430