Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for multi-adapter D3D + fix closing lid issue #30

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

marcotod1410
Copy link
Contributor

@marcotod1410 marcotod1410 commented Dec 5, 2020

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)

- separated device properties from dxglcontext
- added check for device associated with monitor during render phase
- framebuffer associated with device rather than context
@varon
Copy link
Member

varon commented Jan 6, 2021

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

@marcotod1410
Copy link
Contributor Author

marcotod1410 commented Jan 9, 2021

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.

- renderer retains the handle of the current monitor and is updated periodically
- in case it is not found before rendering, clear the context and wait for another valid monitor handle before rendering again
@marcotod1410 marcotod1410 changed the title WIP support for multi-adapter d3d Support for multi-adapter D3D + fix closing lid issue Mar 23, 2021
@NogginBops NogginBops added this to the 4.2.0 milestone Mar 20, 2022
@NogginBops NogginBops linked an issue Mar 21, 2022 that may be closed by this pull request
@NogginBops NogginBops added the 4.0 label Mar 21, 2022
@NogginBops
Copy link
Member

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 NogginBops modified the milestones: 4.2.0, 4.3.0 Jun 18, 2022
@Michael-5430
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Control does not display on device with 2 GPUs (sometimes)
4 participants