From 54f3f5271a7550cd782e3955b0fd8ee426dddfa0 Mon Sep 17 00:00:00 2001 From: Terry MacDonald Date: Sat, 10 Oct 2020 15:18:30 +1300 Subject: [PATCH] Fixed NVIDIA IsPossible screen detection Made the IsPossible deviceIdentification work correctly with the NvAPIWrapper logic. Issue was caused by me not really understanding what the NVIDIA documentation meant. This has been rectified. HeliosPlus will now invalidate any profiles that won't work with the currntly attached screens. --- HeliosPlus.Shared/ProfileItem.cs | 2 +- HeliosPlus.Shared/ProfileRepository.cs | 33 ++++++++++++++++---------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/HeliosPlus.Shared/ProfileItem.cs b/HeliosPlus.Shared/ProfileItem.cs index d16312f..1674b13 100644 --- a/HeliosPlus.Shared/ProfileItem.cs +++ b/HeliosPlus.Shared/ProfileItem.cs @@ -139,7 +139,7 @@ namespace HeliosPlus.Shared { // Get the list of connected devices - List connectedDisplayIdentifiers = ProfileRepository.GenerateAllDisplayIdentifiers(); + List connectedDisplayIdentifiers = ProfileRepository.GenerateAllAvailableDisplayIdentifiers(); // Check each display in this profile and make sure it's currently available int validDisplayCount = 0; diff --git a/HeliosPlus.Shared/ProfileRepository.cs b/HeliosPlus.Shared/ProfileRepository.cs index 9bdd9de..452c1ab 100644 --- a/HeliosPlus.Shared/ProfileRepository.cs +++ b/HeliosPlus.Shared/ProfileRepository.cs @@ -27,7 +27,7 @@ using System.Net.NetworkInformation; using NvAPIWrapper.Mosaic; using NvAPIWrapper.Native.Mosaic; using HeliosPlus.Shared.Topology; - +using NvAPIWrapper.Native.GPU; namespace HeliosPlus.Shared { @@ -714,29 +714,37 @@ namespace HeliosPlus.Shared return displayIdentifiers; } - public static List GenerateAllDisplayIdentifiers() + public static List GenerateAllAvailableDisplayIdentifiers() { List displayIdentifiers = new List(); // If the Video Card is an NVidia, then we should generate specific NVidia displayIdentifiers - NvAPIWrapper.GPU.LogicalGPU[] myLogicalGPUs = NvAPIWrapper.GPU.LogicalGPU.GetLogicalGPUs(); - if (myLogicalGPUs.Length > 0) + bool isNvidia = false; + NvAPIWrapper.GPU.PhysicalGPU[] myPhysicalGPUs = null; + try + { + myPhysicalGPUs = NvAPIWrapper.GPU.PhysicalGPU.GetPhysicalGPUs(); + isNvidia = true; + } + catch (Exception ex) + { } + + if (isNvidia && myPhysicalGPUs != null && myPhysicalGPUs.Length > 0) { - foreach (NvAPIWrapper.GPU.LogicalGPU myLogicalGPU in myLogicalGPUs) + foreach (NvAPIWrapper.GPU.PhysicalGPU myPhysicalGPU in myPhysicalGPUs) { - NvAPIWrapper.GPU.PhysicalGPU[] myPhysicalGPUs = myLogicalGPU.CorrespondingPhysicalGPUs; - foreach (NvAPIWrapper.GPU.PhysicalGPU myPhysicalGPU in myPhysicalGPUs) + // get a list of all physical outputs attached to the GPUs + NvAPIWrapper.Display.DisplayDevice[] allDisplayDevices = myPhysicalGPU.GetConnectedDisplayDevices(ConnectedIdsFlag.None); + foreach (NvAPIWrapper.Display.DisplayDevice aDisplayDevice in allDisplayDevices) { - // get a list of all physical outputs attached to the GPUs - NvAPIWrapper.Display.DisplayDevice[] allDisplayDevices = myPhysicalGPU.GetDisplayDevices(); - foreach (NvAPIWrapper.Display.DisplayDevice aDisplayDevice in allDisplayDevices) - { + if (aDisplayDevice.IsAvailable== true) + { // Create an array of all the important display info we need to record string[] displayInfo = { "NVIDIA", - myLogicalGPU.ToString(), + myPhysicalGPU.CorrespondingLogicalGPU.ToString(), myPhysicalGPU.ToString(), myPhysicalGPU.ArchitectInformation.ShortName.ToString(), myPhysicalGPU.ArchitectInformation.Revision.ToString(), @@ -754,7 +762,6 @@ namespace HeliosPlus.Shared // Add it to the list of display identifiers so we can return it displayIdentifiers.Add(displayIdentifier); } - } } }