From b1b0ae26f5123bcb208153d7abf2579376b025a0 Mon Sep 17 00:00:00 2001 From: Terry MacDonald Date: Thu, 17 Jun 2021 18:51:48 +1200 Subject: [PATCH] Partially working displayids It needs to be fixed as it isn't getting the underlying displays when eyefinity is turned on. Need to find a way around that --- DisplayMagicianShared/AMD/ADL.cs | 21 + DisplayMagicianShared/AMD/ADLWrapper.cs | 572 ++++++++++-------------- 2 files changed, 263 insertions(+), 330 deletions(-) diff --git a/DisplayMagicianShared/AMD/ADL.cs b/DisplayMagicianShared/AMD/ADL.cs index 35889e0..bf4fae2 100644 --- a/DisplayMagicianShared/AMD/ADL.cs +++ b/DisplayMagicianShared/AMD/ADL.cs @@ -563,6 +563,27 @@ namespace ATI.ADL #endregion Internal Constant + #region Internal Enums + + internal enum ADLConnectionType + { + Unknown = 1, + DVI = 1, + DVI_SL = 2, + HDMI = 4, + DisplayPort = 4, + ActiveDongleDPToDVI_SL = 5, + ActiveDongleDPToDVI_DL = 6, + ActiveDongleDPToHDMI = 7, + ActiveDongleDPToVGA = 8, + PassiveDongleDPToHDMI = 9, + PassiveDongleDPToDVI = 10, + MST = 11, + ActiveDongle = 12, + Virtual = 13 + } + #endregion Internal Enums + #region Class ADLImport /// ADLImport class private static class ADLImport diff --git a/DisplayMagicianShared/AMD/ADLWrapper.cs b/DisplayMagicianShared/AMD/ADLWrapper.cs index bb48af0..bdd44ec 100644 --- a/DisplayMagicianShared/AMD/ADLWrapper.cs +++ b/DisplayMagicianShared/AMD/ADLWrapper.cs @@ -110,6 +110,8 @@ namespace DisplayMagicianShared.AMD int NumberOfAdapters = 0; int NumberOfDisplays = 0; + List displayIdentifiers = new List(); + if (null != ADL.ADL_Adapter_NumberOfAdapters_Get) { ADL.ADL_Adapter_NumberOfAdapters_Get(ref NumberOfAdapters); @@ -160,21 +162,6 @@ namespace DisplayMagicianShared.AMD SharedLogger.logger.Trace($"ADLWrapper/GenerateProfileDisplayIdentifiers: AMD Adapter #{i} is active! ({OSAdapterInfoData.ADLAdapterInfo[i].AdapterName})."); - /*Console.WriteLine("Adapter is : " + (0 == IsActive ? "DISABLED" : "ENABLED")); - Console.WriteLine("Adapter Index: " + OSAdapterInfoData.ADLAdapterInfo[i].AdapterIndex.ToString()); - Console.WriteLine("Adapter UDID : " + OSAdapterInfoData.ADLAdapterInfo[i].UDID); - Console.WriteLine("Bus No : " + OSAdapterInfoData.ADLAdapterInfo[i].BusNumber.ToString()); - Console.WriteLine("Driver No : " + OSAdapterInfoData.ADLAdapterInfo[i].DriverNumber.ToString()); - Console.WriteLine("Function No : " + OSAdapterInfoData.ADLAdapterInfo[i].FunctionNumber.ToString()); - Console.WriteLine("Vendor ID : " + OSAdapterInfoData.ADLAdapterInfo[i].VendorID.ToString()); - Console.WriteLine("Adapter Name : " + OSAdapterInfoData.ADLAdapterInfo[i].AdapterName); - Console.WriteLine("Display Name : " + OSAdapterInfoData.ADLAdapterInfo[i].DisplayName); - Console.WriteLine("Present : " + (0 == OSAdapterInfoData.ADLAdapterInfo[i].Present ? "No" : "Yes")); - Console.WriteLine("Exist : " + (0 == OSAdapterInfoData.ADLAdapterInfo[i].Exist ? "No" : "Yes")); - Console.WriteLine("Driver Path : " + OSAdapterInfoData.ADLAdapterInfo[i].DriverPath); - Console.WriteLine("Driver Path X: " + OSAdapterInfoData.ADLAdapterInfo[i].DriverPathExt); - Console.WriteLine("PNP String : " + OSAdapterInfoData.ADLAdapterInfo[i].PNPString);*/ - // Get the unique identifier from the Adapter int AdapterID = 0; if (ADL.ADL_Adapter_ID_Get != null) @@ -242,23 +229,7 @@ namespace DisplayMagicianShared.AMD continue; } - //int InfoValue = DisplayInfoData[j].DisplayInfoValue; - //string StrConnected = (1 == (InfoValue & 1)) ? "Yes" : "No "; - //string StrMapped = (2 == (InfoValue & 2)) ? "Yes" : "No "; - //int AdpID = DisplayInfoData[j].DisplayID.DisplayLogicalAdapterIndex; - //string StrAdpID = (AdpID < 0) ? "--" : AdpID.ToString("d2"); - - /*Console.WriteLine(DisplayInfoData[j].DisplayID.DisplayLogicalIndex.ToString() + " " + - StrAdpID + " " + - DisplayInfoData[j].DisplayType.ToString() + " " + - DisplayInfoData[j].DisplayOutputType.ToString() + " " + - DisplayInfoData[j].DisplayConnector.ToString() + " " + - StrConnected + " " + - StrMapped + " " + - InfoValue.ToString("x4") + " " + - DisplayInfoData[j].DisplayName.ToString());*/ - - ADLDisplayConfig DisplayConfig = new ADLDisplayConfig(); + /*ADLDisplayConfig DisplayConfig = new ADLDisplayConfig(); if (ADL.ADL_Display_DeviceConfig_Get != null) { // Force the display detection and get the Display Info. Use 0 as last parameter to NOT force detection @@ -267,64 +238,90 @@ namespace DisplayMagicianShared.AMD { } - } - - + }*/ // Create an array of all the important display info we need to record - List displayInfoIdentifier = new List(); - displayInfoIdentifier.Add("AMD"); + List displayInfoIdentifierSection = new List(); + displayInfoIdentifierSection.Add("AMD"); try { - displayInfoIdentifier.Add(OSAdapterInfoData.ADLAdapterInfo[i].AdapterName); + displayInfoIdentifierSection.Add(OSAdapterInfoData.ADLAdapterInfo[i].AdapterName); } catch (Exception ex) { SharedLogger.logger.Warn(ex, $"ADLWrapper/GenerateProfileDisplayIdentifiers: Exception getting AMD Adapter Name from video card. Substituting with a # instead"); - displayInfoIdentifier.Add("#"); + displayInfoIdentifierSection.Add("#"); } try { - displayInfoIdentifier.Add(OSAdapterInfoData.ADLAdapterInfo[i].AdapterIndex.ToString()); + displayInfoIdentifierSection.Add(OSAdapterInfoData.ADLAdapterInfo[i].AdapterIndex.ToString()); } catch (Exception ex) { SharedLogger.logger.Warn(ex, $"ADLWrapper/GenerateProfileDisplayIdentifiers: Exception getting AMD Adapter Index from video card. Substituting with a # instead"); - displayInfoIdentifier.Add("#"); + displayInfoIdentifierSection.Add("#"); } try { - displayInfoIdentifier.Add(OSAdapterInfoData.ADLAdapterInfo[i].VendorID.ToString()); + displayInfoIdentifierSection.Add(OSAdapterInfoData.ADLAdapterInfo[i].VendorID.ToString()); } catch (Exception ex) { SharedLogger.logger.Warn(ex, $"ADLWrapper/GenerateProfileDisplayIdentifiers: Exception getting AMD VendorID from video card. Substituting with a # instead"); - displayInfoIdentifier.Add("1002"); + displayInfoIdentifierSection.Add("1002"); } try { - displayInfoIdentifier.Add(AdapterID.ToString()); + displayInfoIdentifierSection.Add(AdapterID.ToString()); } catch (Exception ex) { SharedLogger.logger.Warn(ex, $"ADLWrapper/GenerateProfileDisplayIdentifiers: Exception getting AMD AdapterID from video card. Substituting with a # instead"); - displayInfoIdentifier.Add("#"); + displayInfoIdentifierSection.Add("#"); } try { - displayInfoIdentifier.Add(AdapterID.ToString()); + ADL.ADLConnectionType connector = (ADL.ADLConnectionType)DisplayInfoData[j].DisplayConnector; + displayInfoIdentifierSection.Add(connector.ToString("G")); } catch (Exception ex) { - SharedLogger.logger.Warn(ex, $"ADLWrapper/GenerateProfileDisplayIdentifiers: Exception getting AMD AdapterID from video card. Substituting with a # instead"); - displayInfoIdentifier.Add("#"); + SharedLogger.logger.Warn(ex, $"ADLWrapper/GenerateProfileDisplayIdentifiers: Exception getting AMD Display Connector from video card to display. Substituting with a # instead"); + displayInfoIdentifierSection.Add("#"); } + + try + { + displayInfoIdentifierSection.Add(DisplayInfoData[j].DisplayManufacturerName); + } + catch (Exception ex) + { + SharedLogger.logger.Warn(ex, $"ADLWrapper/GenerateProfileDisplayIdentifiers: Exception getting Display manufacturer from AMD video card. Substituting with a # instead"); + displayInfoIdentifierSection.Add("#"); + } + + try + { + displayInfoIdentifierSection.Add(DisplayInfoData[j].DisplayName); + } + catch (Exception ex) + { + SharedLogger.logger.Warn(ex, $"ADLWrapper/GenerateProfileDisplayIdentifiers: Exception getting Display Name from AMD video card. Substituting with a # instead"); + displayInfoIdentifierSection.Add("#"); + } + + // Create a display identifier out of it + string displayIdentifier = String.Join("|", displayInfoIdentifierSection); + // Add it to the list of display identifiers so we can return it + displayIdentifiers.Add(displayIdentifier); + + SharedLogger.logger.Debug($"ProfileRepository/GenerateProfileDisplayIdentifiers: DisplayIdentifier: {displayIdentifier}"); + } - Console.WriteLine(); } else { @@ -351,111 +348,15 @@ namespace DisplayMagicianShared.AMD { Marshal.FreeCoTaskMem(AdapterBuffer); } + + // Return all the identifiers we've found + return displayIdentifiers; } else { SharedLogger.logger.Error($"ADLWrapper/GenerateProfileDisplayIdentifiers: There were no AMD adapters found by AMD ADL."); return null; } - - - /*foreach (NvAPIWrapper.GPU.PhysicalGPU myPhysicalGPU in myPhysicalGPUs) - { - // get a list of all physical outputs attached to the GPUs - NvAPIWrapper.GPU.GPUOutput[] myGPUOutputs = myPhysicalGPU.ActiveOutputs; - foreach (NvAPIWrapper.GPU.GPUOutput aGPUOutput in myGPUOutputs) - { - SharedLogger.logger.Debug($"ProfileRepository/GenerateProfileDisplayIdentifiers: We were able to detect {myGPUOutputs.Length} outputs"); - // Figure out the displaydevice attached to the output - NvAPIWrapper.Display.DisplayDevice aConnectedDisplayDevice = myPhysicalGPU.GetDisplayDeviceByOutput(aGPUOutput); - - // Create an array of all the important display info we need to record - List displayInfo = new List(); - displayInfo.Add("NVIDIA"); - try - { - displayInfo.Add(myPhysicalGPU.ArchitectInformation.ShortName.ToString()); - } - catch (Exception ex) - { - SharedLogger.logger.Warn(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers: Exception getting NVIDIA Architecture ShortName from video card. Substituting with a # instead"); - displayInfo.Add("#"); - } - try - { - displayInfo.Add(myPhysicalGPU.ArchitectInformation.Revision.ToString()); - } - catch (Exception ex) - { - SharedLogger.logger.Warn(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers: Exception getting NVIDIA Architecture Revision from video card. Substituting with a # instead"); - displayInfo.Add("#"); - } - try - { - displayInfo.Add(myPhysicalGPU.Board.ToString()); - } - catch (Exception ex) - { - SharedLogger.logger.Warn(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers: Exception getting NVIDIA Board details from video card. Substituting with a # instead"); - displayInfo.Add("#"); - } - try - { - displayInfo.Add(myPhysicalGPU.Foundry.ToString()); - } - catch (Exception ex) - { - SharedLogger.logger.Warn(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers: Exception getting NVIDIA Foundry from video card. Substituting with a # instead"); - displayInfo.Add("#"); - } - try - { - displayInfo.Add(myPhysicalGPU.GPUId.ToString()); - } - catch (Exception ex) - { - SharedLogger.logger.Warn(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers: Exception getting NVIDIA GPUId from video card. Substituting with a # instead"); - displayInfo.Add("#"); - } - try - { - displayInfo.Add(myPhysicalGPU.GPUType.ToString()); - } - catch (Exception ex) - { - SharedLogger.logger.Warn(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers: Exception getting NVIDIA GPUType from video card. Substituting with a # instead"); - displayInfo.Add("#"); - } - try - { - displayInfo.Add(aConnectedDisplayDevice.ConnectionType.ToString()); - } - catch (Exception ex) - { - SharedLogger.logger.Warn(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers: Exception getting NVIDIA Connection from video card. Substituting with a # instead"); - displayInfo.Add("#"); - } - try - { - displayInfo.Add(aConnectedDisplayDevice.DisplayId.ToString()); - } - catch (Exception ex) - { - SharedLogger.logger.Warn(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers: Exception getting NVIDIA DisplayID from video card. Substituting with a # instead"); - displayInfo.Add("#"); - } - - // Create a display identifier out of it - string displayIdentifier = String.Join("|", displayInfo); - // Add it to the list of display identifiers so we can return it - displayIdentifiers.Add(displayIdentifier); - - SharedLogger.logger.Debug($"ProfileRepository/GenerateProfileDisplayIdentifiers: DisplayIdentifier: {displayIdentifier}"); - } - - }*/ - - return null; } public List GenerateAllAvailableDisplayIdentifiers() @@ -466,6 +367,8 @@ namespace DisplayMagicianShared.AMD int NumberOfAdapters = 0; int NumberOfDisplays = 0; + List displayIdentifiers = new List(); + if (null != ADL.ADL_Adapter_NumberOfAdapters_Get) { ADL.ADL_Adapter_NumberOfAdapters_Get(ref NumberOfAdapters); @@ -478,223 +381,232 @@ namespace DisplayMagicianShared.AMD ADLAdapterInfoArray OSAdapterInfoData; OSAdapterInfoData = new ADLAdapterInfoArray(); + IntPtr AdapterBuffer = IntPtr.Zero; if (ADL.ADL_Adapter_AdapterInfo_Get != null) { - IntPtr AdapterBuffer = IntPtr.Zero; + SharedLogger.logger.Trace($"ADLWrapper/GenerateProfileDisplayIdentifiers: ADL_Adapter_AdapterInfo_Get DLL function exists."); + // Figure out the size of the AdapterBuffer we need to build int size = Marshal.SizeOf(OSAdapterInfoData); AdapterBuffer = Marshal.AllocCoTaskMem((int)size); Marshal.StructureToPtr(OSAdapterInfoData, AdapterBuffer, false); - if (null != ADL.ADL_Adapter_AdapterInfo_Get) + // Get the Adapter info and put it in the AdapterBuffer + SharedLogger.logger.Trace($"ADLWrapper/GenerateProfileDisplayIdentifiers: Running ADL_Adapter_AdapterInfo_Get to find all known AMD adapters."); + ADLRet = ADL.ADL_Adapter_AdapterInfo_Get(AdapterBuffer, size); + if (ADLRet == ADL.ADL_SUCCESS) { - ADLRet = ADL.ADL_Adapter_AdapterInfo_Get(AdapterBuffer, size); - if (ADLRet == ADL.ADL_SUCCESS) + // Use the AdapterBuffer pointer to marshal the OS Adapter Info into a structure + OSAdapterInfoData = (ADLAdapterInfoArray)Marshal.PtrToStructure(AdapterBuffer, OSAdapterInfoData.GetType()); + int IsActive = ADL.ADL_TRUE; // We only want to search for active adapters + + SharedLogger.logger.Trace($"ADLWrapper/GenerateProfileDisplayIdentifiers: Successfully run ADL_Adapter_AdapterInfo_Get to find information about all known AMD adapters."); + + // Go through each adapter + for (int i = 0; i < NumberOfAdapters; i++) { - OSAdapterInfoData = (ADLAdapterInfoArray)Marshal.PtrToStructure(AdapterBuffer, OSAdapterInfoData.GetType()); - int IsActive = 1; // We only want to search for active adapters + // Check if the adapter is active + if (ADL.ADL_Adapter_Active_Get != null) + ADLRet = ADL.ADL_Adapter_Active_Get(OSAdapterInfoData.ADLAdapterInfo[i].AdapterIndex, ref IsActive); - for (int i = 0; i < NumberOfAdapters; i++) + if (ADLRet == ADL.ADL_SUCCESS) { - // Check if the adapter is active - if (null != ADL.ADL_Adapter_Active_Get) - ADLRet = ADL.ADL_Adapter_Active_Get(OSAdapterInfoData.ADLAdapterInfo[i].AdapterIndex, ref IsActive); - - if (ADL.ADL_SUCCESS == ADLRet) + // Only continue if the adapter is enabled + if (IsActive != ADL.ADL_TRUE) { - Console.WriteLine("Adapter is : " + (0 == IsActive ? "DISABLED" : "ENABLED")); - Console.WriteLine("Adapter Index: " + OSAdapterInfoData.ADLAdapterInfo[i].AdapterIndex.ToString()); - Console.WriteLine("Adapter UDID : " + OSAdapterInfoData.ADLAdapterInfo[i].UDID); - Console.WriteLine("Bus No : " + OSAdapterInfoData.ADLAdapterInfo[i].BusNumber.ToString()); - Console.WriteLine("Driver No : " + OSAdapterInfoData.ADLAdapterInfo[i].DriverNumber.ToString()); - Console.WriteLine("Function No : " + OSAdapterInfoData.ADLAdapterInfo[i].FunctionNumber.ToString()); - Console.WriteLine("Vendor ID : " + OSAdapterInfoData.ADLAdapterInfo[i].VendorID.ToString()); - Console.WriteLine("Adapter Name : " + OSAdapterInfoData.ADLAdapterInfo[i].AdapterName); - Console.WriteLine("Display Name : " + OSAdapterInfoData.ADLAdapterInfo[i].DisplayName); - Console.WriteLine("Present : " + (0 == OSAdapterInfoData.ADLAdapterInfo[i].Present ? "No" : "Yes")); - Console.WriteLine("Exist : " + (0 == OSAdapterInfoData.ADLAdapterInfo[i].Exist ? "No" : "Yes")); - Console.WriteLine("Driver Path : " + OSAdapterInfoData.ADLAdapterInfo[i].DriverPath); - Console.WriteLine("Driver Path X: " + OSAdapterInfoData.ADLAdapterInfo[i].DriverPathExt); - Console.WriteLine("PNP String : " + OSAdapterInfoData.ADLAdapterInfo[i].PNPString); + SharedLogger.logger.Trace($"ADLWrapper/GenerateProfileDisplayIdentifiers: AMD Adapter #{i} isn't active ({OSAdapterInfoData.ADLAdapterInfo[i].AdapterName})."); + continue; + } - // Obtain information about displays - ADLDisplayInfo oneDisplayInfo = new ADLDisplayInfo(); + SharedLogger.logger.Trace($"ADLWrapper/GenerateProfileDisplayIdentifiers: AMD Adapter #{i} is active! ({OSAdapterInfoData.ADLAdapterInfo[i].AdapterName})."); - if (null != ADL.ADL_Display_DisplayInfo_Get) + // Get the unique identifier from the Adapter + int AdapterID = 0; + if (ADL.ADL_Adapter_ID_Get != null) + { + ADLRet = ADL.ADL_Adapter_ID_Get(OSAdapterInfoData.ADLAdapterInfo[i].AdapterIndex, ref AdapterID); + SharedLogger.logger.Trace($"ADLWrapper/GenerateProfileDisplayIdentifiers: AMD Adapter #{i} ({OSAdapterInfoData.ADLAdapterInfo[i].AdapterName}) AdapterID is {AdapterID.ToString()}"); + } + + // Get the Adapter Capabilities + ADLAdapterCapsX2 AdapterCapabilities = new ADLAdapterCapsX2(); + if (ADL.ADL_AdapterX2_Caps != null) + { + ADLRet = ADL.ADL_AdapterX2_Caps(OSAdapterInfoData.ADLAdapterInfo[i].AdapterIndex, out AdapterCapabilities); + } + + //ADLAdapterCapsX2 AdapterCapabilities = (ADLAdapterCapsX2)Marshal.PtrToStructure(AdapterCapabilitiesBuffer, typeof(ADLAdapterCapsX2)); + Console.Write(AdapterCapabilities.AdapterID); + + // Obtain information about displays + ADLDisplayInfo oneDisplayInfo = new ADLDisplayInfo(); + + if (ADL.ADL_Display_DisplayInfo_Get != null) + { + IntPtr DisplayBuffer = IntPtr.Zero; + int j = 0; + + // Force the display detection and get the Display Info. Use 0 as last parameter to NOT force detection + ADLRet = ADL.ADL_Display_DisplayInfo_Get(OSAdapterInfoData.ADLAdapterInfo[i].AdapterIndex, ref NumberOfDisplays, out DisplayBuffer, 0); + if (ADLRet == ADL.ADL_SUCCESS) { - IntPtr DisplayBuffer = IntPtr.Zero; - int j = 0; - // Force the display detection and get the Display Info. Use 0 as last parameter to NOT force detection - ADLRet = ADL.ADL_Display_DisplayInfo_Get(OSAdapterInfoData.ADLAdapterInfo[i].AdapterIndex, ref NumberOfDisplays, out DisplayBuffer, 0); - if (ADL.ADL_SUCCESS == ADLRet) + List DisplayInfoData = new List(); + + try { - List DisplayInfoData = new List(); - - try - { - - for (j = 0; j < NumberOfDisplays; j++) - { - // NOTE: the ToInt64 work on 64 bit, need to change to ToInt32 for 32 bit OS - oneDisplayInfo = (ADLDisplayInfo)Marshal.PtrToStructure(new IntPtr(DisplayBuffer.ToInt64() + (j * Marshal.SizeOf(oneDisplayInfo))), oneDisplayInfo.GetType()); - DisplayInfoData.Add(oneDisplayInfo); - } - } - catch (Exception ex) - { - Console.WriteLine("Exception caused trying to access attached displays"); - continue; - } - Console.WriteLine("\nTotal Number of Displays supported: " + NumberOfDisplays.ToString()); - Console.WriteLine("\nDispID AdpID Type OutType CnctType Connected Mapped InfoValue DisplayName "); - for (j = 0; j < NumberOfDisplays; j++) { - int InfoValue = DisplayInfoData[j].DisplayInfoValue; - string StrConnected = (1 == (InfoValue & 1)) ? "Yes" : "No "; - string StrMapped = (2 == (InfoValue & 2)) ? "Yes" : "No "; - int AdpID = DisplayInfoData[j].DisplayID.DisplayLogicalAdapterIndex; - string StrAdpID = (AdpID < 0) ? "--" : AdpID.ToString("d2"); - - Console.WriteLine(DisplayInfoData[j].DisplayID.DisplayLogicalIndex.ToString() + " " + - StrAdpID + " " + - DisplayInfoData[j].DisplayType.ToString() + " " + - DisplayInfoData[j].DisplayOutputType.ToString() + " " + - DisplayInfoData[j].DisplayConnector.ToString() + " " + - StrConnected + " " + - StrMapped + " " + - InfoValue.ToString("x4") + " " + - DisplayInfoData[j].DisplayName.ToString()); + // NOTE: the ToInt64 work on 64 bit, need to change to ToInt32 for 32 bit OS + oneDisplayInfo = (ADLDisplayInfo)Marshal.PtrToStructure(new IntPtr(DisplayBuffer.ToInt64() + (j * Marshal.SizeOf(oneDisplayInfo))), oneDisplayInfo.GetType()); + DisplayInfoData.Add(oneDisplayInfo); } - Console.WriteLine(); } - else + catch (Exception ex) { - Console.WriteLine("ADL_Display_DisplayInfo_Get() returned error code " + ADLRet.ToString()); + Console.WriteLine("Exception caused trying to access attached displays"); + continue; + } + Console.WriteLine("\nTotal Number of Displays supported: " + NumberOfDisplays.ToString()); + Console.WriteLine("\nDispID AdpID Type OutType CnctType Connected Mapped InfoValue DisplayName "); + + for (j = 0; j < NumberOfDisplays; j++) + { + // Skip non connected displays + if ((DisplayInfoData[j].DisplayInfoValue & 1) != 1) + { + SharedLogger.logger.Trace($"ADLWrapper/GenerateProfileDisplayIdentifiers: AMD Adapter #{i} ({OSAdapterInfoData.ADLAdapterInfo[i].AdapterName}) AdapterID display ID#{j} is not connected"); + continue; + } + + ADLDisplayConfig DisplayConfig = new ADLDisplayConfig(); + if (ADL.ADL_Display_DeviceConfig_Get != null) + { + // Force the display detection and get the Display Info. Use 0 as last parameter to NOT force detection + ADLRet = ADL.ADL_Display_DeviceConfig_Get(OSAdapterInfoData.ADLAdapterInfo[i].AdapterIndex, DisplayInfoData[j].DisplayID.DisplayLogicalIndex, out DisplayConfig); + if (ADLRet == ADL.ADL_SUCCESS) + { + + } + } + + // Create an array of all the important display info we need to record + List displayInfoIdentifierSection = new List(); + displayInfoIdentifierSection.Add("AMD"); + try + { + displayInfoIdentifierSection.Add(OSAdapterInfoData.ADLAdapterInfo[i].AdapterName); + } + catch (Exception ex) + { + SharedLogger.logger.Warn(ex, $"ADLWrapper/GenerateProfileDisplayIdentifiers: Exception getting AMD Adapter Name from video card. Substituting with a # instead"); + displayInfoIdentifierSection.Add("#"); + } + + try + { + displayInfoIdentifierSection.Add(OSAdapterInfoData.ADLAdapterInfo[i].AdapterIndex.ToString()); + } + catch (Exception ex) + { + SharedLogger.logger.Warn(ex, $"ADLWrapper/GenerateProfileDisplayIdentifiers: Exception getting AMD Adapter Index from video card. Substituting with a # instead"); + displayInfoIdentifierSection.Add("#"); + } + + try + { + displayInfoIdentifierSection.Add(OSAdapterInfoData.ADLAdapterInfo[i].VendorID.ToString()); + } + catch (Exception ex) + { + SharedLogger.logger.Warn(ex, $"ADLWrapper/GenerateProfileDisplayIdentifiers: Exception getting AMD VendorID from video card. Substituting with a # instead"); + displayInfoIdentifierSection.Add("1002"); + } + + try + { + displayInfoIdentifierSection.Add(AdapterID.ToString()); + } + catch (Exception ex) + { + SharedLogger.logger.Warn(ex, $"ADLWrapper/GenerateProfileDisplayIdentifiers: Exception getting AMD AdapterID from video card. Substituting with a # instead"); + displayInfoIdentifierSection.Add("#"); + } + + try + { + ADL.ADLConnectionType connector = (ADL.ADLConnectionType)DisplayInfoData[j].DisplayConnector; + displayInfoIdentifierSection.Add(connector.ToString()); + } + catch (Exception ex) + { + SharedLogger.logger.Warn(ex, $"ADLWrapper/GenerateProfileDisplayIdentifiers: Exception getting AMD Display Connector from video card to display. Substituting with a # instead"); + displayInfoIdentifierSection.Add("#"); + } + + try + { + displayInfoIdentifierSection.Add(DisplayInfoData[j].DisplayManufacturerName); + } + catch (Exception ex) + { + SharedLogger.logger.Warn(ex, $"ADLWrapper/GenerateProfileDisplayIdentifiers: Exception getting Display manufacturer from AMD video card. Substituting with a # instead"); + displayInfoIdentifierSection.Add("#"); + } + + try + { + displayInfoIdentifierSection.Add(DisplayInfoData[j].DisplayName); + } + catch (Exception ex) + { + SharedLogger.logger.Warn(ex, $"ADLWrapper/GenerateProfileDisplayIdentifiers: Exception getting Display Name from AMD video card. Substituting with a # instead"); + displayInfoIdentifierSection.Add("#"); + } + + // Create a display identifier out of it + string displayIdentifier = String.Join("|", displayInfoIdentifierSection); + // Add it to the list of display identifiers so we can return it + displayIdentifiers.Add(displayIdentifier); + + SharedLogger.logger.Debug($"ProfileRepository/GenerateProfileDisplayIdentifiers: DisplayIdentifier: {displayIdentifier}"); + } - // Release the memory for the DisplayInfo structure - if (IntPtr.Zero != DisplayBuffer) - Marshal.FreeCoTaskMem(DisplayBuffer); } + else + { + Console.WriteLine("ADL_Display_DisplayInfo_Get() returned error code " + ADLRet.ToString()); + } + // Release the memory for the DisplayInfo structure + if (IntPtr.Zero != DisplayBuffer) + Marshal.FreeCoTaskMem(DisplayBuffer); } } - } - else - { - Console.WriteLine("ADL_Adapter_AdapterInfo_Get() returned error code " + ADLRet.ToString()); + else + { + Console.WriteLine("ADL_Adapter_Active_Get() returned error code " + ADLRet.ToString()); + } } } - // Release the memory for the AdapterInfo structure - if (IntPtr.Zero != AdapterBuffer) - Marshal.FreeCoTaskMem(AdapterBuffer); + else + { + Console.WriteLine("ADL_Adapter_AdapterInfo_Get() returned error code " + ADLRet.ToString()); + } } + // Release the memory for the AdapterInfo structure + if (IntPtr.Zero != AdapterBuffer) + { + Marshal.FreeCoTaskMem(AdapterBuffer); + } + + // Return all the identifiers we've found + return displayIdentifiers; } else { SharedLogger.logger.Error($"ADLWrapper/GenerateProfileDisplayIdentifiers: There were no AMD adapters found by AMD ADL."); return null; } - - - /*foreach (NvAPIWrapper.GPU.PhysicalGPU myPhysicalGPU in myPhysicalGPUs) - { - // get a list of all physical outputs attached to the GPUs - NvAPIWrapper.GPU.GPUOutput[] myGPUOutputs = myPhysicalGPU.ActiveOutputs; - foreach (NvAPIWrapper.GPU.GPUOutput aGPUOutput in myGPUOutputs) - { - SharedLogger.logger.Debug($"ProfileRepository/GenerateProfileDisplayIdentifiers: We were able to detect {myGPUOutputs.Length} outputs"); - // Figure out the displaydevice attached to the output - NvAPIWrapper.Display.DisplayDevice aConnectedDisplayDevice = myPhysicalGPU.GetDisplayDeviceByOutput(aGPUOutput); - - // Create an array of all the important display info we need to record - List displayInfo = new List(); - displayInfo.Add("NVIDIA"); - try - { - displayInfo.Add(myPhysicalGPU.ArchitectInformation.ShortName.ToString()); - } - catch (Exception ex) - { - SharedLogger.logger.Warn(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers: Exception getting NVIDIA Architecture ShortName from video card. Substituting with a # instead"); - displayInfo.Add("#"); - } - try - { - displayInfo.Add(myPhysicalGPU.ArchitectInformation.Revision.ToString()); - } - catch (Exception ex) - { - SharedLogger.logger.Warn(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers: Exception getting NVIDIA Architecture Revision from video card. Substituting with a # instead"); - displayInfo.Add("#"); - } - try - { - displayInfo.Add(myPhysicalGPU.Board.ToString()); - } - catch (Exception ex) - { - SharedLogger.logger.Warn(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers: Exception getting NVIDIA Board details from video card. Substituting with a # instead"); - displayInfo.Add("#"); - } - try - { - displayInfo.Add(myPhysicalGPU.Foundry.ToString()); - } - catch (Exception ex) - { - SharedLogger.logger.Warn(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers: Exception getting NVIDIA Foundry from video card. Substituting with a # instead"); - displayInfo.Add("#"); - } - try - { - displayInfo.Add(myPhysicalGPU.GPUId.ToString()); - } - catch (Exception ex) - { - SharedLogger.logger.Warn(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers: Exception getting NVIDIA GPUId from video card. Substituting with a # instead"); - displayInfo.Add("#"); - } - try - { - displayInfo.Add(myPhysicalGPU.GPUType.ToString()); - } - catch (Exception ex) - { - SharedLogger.logger.Warn(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers: Exception getting NVIDIA GPUType from video card. Substituting with a # instead"); - displayInfo.Add("#"); - } - try - { - displayInfo.Add(aConnectedDisplayDevice.ConnectionType.ToString()); - } - catch (Exception ex) - { - SharedLogger.logger.Warn(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers: Exception getting NVIDIA Connection from video card. Substituting with a # instead"); - displayInfo.Add("#"); - } - try - { - displayInfo.Add(aConnectedDisplayDevice.DisplayId.ToString()); - } - catch (Exception ex) - { - SharedLogger.logger.Warn(ex, $"ProfileRepository/GenerateProfileDisplayIdentifiers: Exception getting NVIDIA DisplayID from video card. Substituting with a # instead"); - displayInfo.Add("#"); - } - - // Create a display identifier out of it - string displayIdentifier = String.Join("|", displayInfo); - // Add it to the list of display identifiers so we can return it - displayIdentifiers.Add(displayIdentifier); - - SharedLogger.logger.Debug($"ProfileRepository/GenerateProfileDisplayIdentifiers: DisplayIdentifier: {displayIdentifier}"); - } - - }*/ - - return null; } - } }