[WIP] Additional dispId generation tweaks

This commit is contained in:
Terry MacDonald 2021-06-19 13:36:57 +12:00
parent 16c143cffe
commit 48703759bf
2 changed files with 371 additions and 268 deletions

View File

@ -124,7 +124,7 @@ namespace DisplayMagicianShared.AMD
public bool IsInstalled
{
get { return _initialised; }
get { return _initialised || _initialisedADL2; }
}
public static ADLWrapper GetLibrary()
@ -142,85 +142,6 @@ namespace DisplayMagicianShared.AMD
List<string> displayIdentifiers = new List<string>();
// Get the DisplayMap info (Desktops) for all adapters on the machine in one go
// Keep a list of things we want to track
/*List<ADLDisplayMap> allDisplayMaps = new List<ADLDisplayMap>();
List<ADLDisplayTarget> allDisplayTargets = new List<ADLDisplayTarget>();
if (ADL.ADL_Display_DisplayMapConfig_Get != null)
{
IntPtr DisplayMapBuffer = IntPtr.Zero;
IntPtr DisplayTargetBuffer = IntPtr.Zero;
int numDisplayMaps = 0;
int numDisplayTargets = 0;
// Get the DisplayMap info (Desktops) for all adapters on the machine in one go
ADLRet = ADL.ADL_Display_DisplayMapConfig_Get(-1, out numDisplayMaps, out DisplayMapBuffer, out numDisplayTargets, out DisplayTargetBuffer, 0);
if (ADLRet == ADL.ADL_SUCCESS)
{
SharedLogger.logger.Trace($"ADLWrapper/GenerateProfileDisplayIdentifiers: Number Of DisplayMaps (Desktops): {numDisplayMaps.ToString()} ");
// Marshal the Display Maps
ADLDisplayMap oneDisplayMap = new ADLDisplayMap();
for (int displayMapNum = 0; displayMapNum < numDisplayMaps; displayMapNum++)
{
// NOTE: the ToInt64 work on 64 bit, need to change to ToInt32 for 32 bit OS
oneDisplayMap = (ADLDisplayMap)Marshal.PtrToStructure(new IntPtr(DisplayMapBuffer.ToInt64() + (displayMapNum * Marshal.SizeOf(oneDisplayMap))), oneDisplayMap.GetType());
allDisplayMaps.Add(oneDisplayMap);
}
//Marshall the DisplayTargets
ADLDisplayTarget oneDisplayTarget = new ADLDisplayTarget();
for (int displayTargetNum = 0; displayTargetNum < numDisplayTargets; displayTargetNum++)
{
// NOTE: the ToInt64 work on 64 bit, need to change to ToInt32 for 32 bit OS
oneDisplayTarget = (ADLDisplayTarget)Marshal.PtrToStructure(new IntPtr(DisplayMapBuffer.ToInt64() + (displayTargetNum * Marshal.SizeOf(oneDisplayTarget))), oneDisplayTarget.GetType());
allDisplayTargets.Add(oneDisplayTarget);
}
}
}
if (ADL.ADL_Display_DisplayMapConfig_PossibleAddAndRemove != null)
{
int numDisplayMap = 1;
int numDisplayTarget = 1;
IntPtr PossibleAddTargetBuffer = IntPtr.Zero;
IntPtr PossibleRemoveTargetBuffer = IntPtr.Zero;
int numPossibleAddTargets = 0;
int numPossibleRemoveTargets = 0;
List<ADLDisplayTarget> allPossibleAddDisplayTargets = new List<ADLDisplayTarget>();
List<ADLDisplayTarget> allPossibleRemoveDisplayTargets = new List<ADLDisplayTarget>();
// Force the display detection and get the Display Info. Use 0 as last parameter to NOT force detection
ADLRet = ADL.ADL_Display_DisplayMapConfig_PossibleAddAndRemove(0, numDisplayMap, allDisplayMaps[0], numDisplayTarget, allDisplayTargets[0], out numPossibleAddTargets, out PossibleAddTargetBuffer, out numPossibleRemoveTargets, out PossibleRemoveTargetBuffer);
if (ADLRet == ADL.ADL_SUCCESS)
{
// Marshal the Possible Add Targets
ADLDisplayTarget oneDisplayTarget = new ADLDisplayTarget();
for (int displayTargetNum = 0; displayTargetNum < numPossibleAddTargets; displayTargetNum++)
{
// NOTE: the ToInt64 work on 64 bit, need to change to ToInt32 for 32 bit OS
oneDisplayTarget = (ADLDisplayTarget)Marshal.PtrToStructure(new IntPtr(PossibleAddTargetBuffer.ToInt64() + (displayTargetNum * Marshal.SizeOf(oneDisplayTarget))), oneDisplayTarget.GetType());
allPossibleAddDisplayTargets.Add(oneDisplayTarget);
}
// Marshal the Possible Remove Targets too
for (int displayTargetNum = 0; displayTargetNum < numPossibleRemoveTargets; displayTargetNum++)
{
// NOTE: the ToInt64 work on 64 bit, need to change to ToInt32 for 32 bit OS
oneDisplayTarget = (ADLDisplayTarget)Marshal.PtrToStructure(new IntPtr(PossibleRemoveTargetBuffer.ToInt64() + (displayTargetNum * Marshal.SizeOf(oneDisplayTarget))), oneDisplayTarget.GetType());
allPossibleAddDisplayTargets.Add(oneDisplayTarget);
}
}
}*/
if (null != ADL.ADL2_Adapter_NumberOfAdapters_Get)
{
ADL.ADL2_Adapter_NumberOfAdapters_Get(_adlContextHandle, ref NumberOfAdapters);
@ -441,7 +362,7 @@ namespace DisplayMagicianShared.AMD
ConvertedDDCInfoFlag DDCInfoFlag = ADL.ConvertDDCInfoFlag(displayDDCInfo2.DDCInfoFlag);
// Convert the DDCInfoFlag to something usable using a library function I made
ConvertedSupportedHDR supportedHDR= ADL.ConvertSupportedHDR(displayDDCInfo2.SupportedHDR);
ConvertedSupportedHDR supportedHDR = ADL.ConvertSupportedHDR(displayDDCInfo2.SupportedHDR);
Console.WriteLine($"### Display DDCInfo2 for Display #{oneDisplayInfo.DisplayID.DisplayLogicalIndex} on Adapter #{oneAdapter.AdapterIndex} ###");
Console.WriteLine($"Display AvgLuminanceData = {displayDDCInfo2.AvgLuminanceData}");
@ -491,7 +412,8 @@ namespace DisplayMagicianShared.AMD
Console.WriteLine($"Display SupportedHDR Supports CEA861_3 = {supportedHDR.CEA861_3}");
Console.WriteLine($"Display SupportedHDR Supports DOLBYVISION = {supportedHDR.DOLBYVISION}");
Console.WriteLine($"Display SupportedHDR Supports FREESYNC_HDR = {supportedHDR.FREESYNC_HDR}");
} else
}
else
{
Console.WriteLine($"Error running ADL_vDisplay_EdidData_Get on Display #{oneDisplayInfo.DisplayID.DisplayLogicalIndex} on Adapter #{oneAdapter.AdapterIndex}: {ADL.ConvertADLReturnValueIntoWords(ADLRet)}");
}
@ -535,16 +457,6 @@ namespace DisplayMagicianShared.AMD
displayInfoIdentifierSection.Add("#");
}
try
{
displayInfoIdentifierSection.Add(oneAdapter.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(oneAdapter.VendorID.ToString());
@ -617,6 +529,16 @@ namespace DisplayMagicianShared.AMD
// Create a display identifier out of it
string displayIdentifier = String.Join("|", displayInfoIdentifierSection);
// Check first to see if there is already an existing display identifier the same!
// This appears to be a bug with the AMD driver, or with the install on my test machine
// Either way, it is potentially going to happen in the wild, so I will filter it out if it does
if (displayIdentifiers.Contains(displayIdentifier))
{
SharedLogger.logger.Trace($"ADLWrapper/GenerateProfileDisplayIdentifiers: Your AMD driver reported the following Display Identifier multiple times, so ignoring it as we already have it: {displayIdentifier}");
continue;
}
// Add it to the list of display identifiers so we can return it
displayIdentifiers.Add(displayIdentifier);
@ -676,135 +598,308 @@ namespace DisplayMagicianShared.AMD
List<string> displayIdentifiers = new List<string>();
return displayIdentifiers;
if (null != ADL.ADL_Adapter_NumberOfAdapters_Get)
if (null != ADL.ADL2_Adapter_NumberOfAdapters_Get)
{
ADL.ADL_Adapter_NumberOfAdapters_Get(ref NumberOfAdapters);
ADL.ADL2_Adapter_NumberOfAdapters_Get(_adlContextHandle, ref NumberOfAdapters);
SharedLogger.logger.Trace($"ADLWrapper/GenerateProfileDisplayIdentifiers: Number Of Adapters: {NumberOfAdapters.ToString()} ");
}
if (NumberOfAdapters > 0)
{
// Get OS adpater info from ADL
ADLAdapterInfoArray OSAdapterInfoData;
OSAdapterInfoData = new ADLAdapterInfoArray();
ADLAdapterInfoX2Array OSAdapterInfoData;
OSAdapterInfoData = new ADLAdapterInfoX2Array();
IntPtr AdapterBuffer = IntPtr.Zero;
if (ADL.ADL2_Adapter_AdapterInfoX4_Get != null)
{
SharedLogger.logger.Trace($"ADLWrapper/GenerateProfileDisplayIdentifiers: ADL_Adapter_AdapterInfo_Get DLL function exists.");
SharedLogger.logger.Trace($"ADLWrapper/GenerateProfileDisplayIdentifiers: ADL2_Adapter_AdapterInfoX4_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);
// 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(out AdapterBuffer, size);
SharedLogger.logger.Trace($"ADLWrapper/GenerateProfileDisplayIdentifiers: Running ADL2_Adapter_AdapterInfoX4_Get to find all known AMD adapters.");
//ADLRet = ADL.ADL2_Adapter_AdapterInfoX4_Get(_adlContextHandle, AdapterBuffer, size);
int numAdapters = 0;
ADLRet = ADL.ADL2_Adapter_AdapterInfoX4_Get(_adlContextHandle, ADL.ADL_ADAPTER_INDEX_ALL, out numAdapters, out AdapterBuffer);
if (ADLRet == ADL.ADL_OK)
{
// Use the AdapterBuffer pointer to marshal the OS Adapter Info into a structure
OSAdapterInfoData = (ADLAdapterInfoArray)Marshal.PtrToStructure(AdapterBuffer, OSAdapterInfoData.GetType());
OSAdapterInfoData = (ADLAdapterInfoX2Array)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.");
SharedLogger.logger.Trace($"ADLWrapper/GenerateProfileDisplayIdentifiers: Successfully run ADL2_Adapter_AdapterInfoX4_Get to find information about all known AMD adapters.");
// Go through each adapter
for (int i = 0; i < NumberOfAdapters; i++)
foreach (ADLAdapterInfoX2 oneAdapter in OSAdapterInfoData.ADLAdapterInfoX2)
{
if (oneAdapter.Exist != 1)
{
SharedLogger.logger.Trace($"ADLWrapper/GenerateProfileDisplayIdentifiers: AMD Adapter #{oneAdapter.AdapterIndex.ToString()} doesn't exist at present so skipping detection for this adapter.");
Console.WriteLine($"ADLWrapper/GenerateProfileDisplayIdentifiers: AMD Adapter #{oneAdapter.AdapterIndex.ToString()} doesn't exist at present so skipping detection for this adapter.");
continue;
}
if (oneAdapter.Present != 1)
{
SharedLogger.logger.Trace($"ADLWrapper/GenerateProfileDisplayIdentifiers: AMD Adapter #{oneAdapter.AdapterIndex.ToString()} isn't enabled at present so skipping detection for this adapter.");
Console.WriteLine($"ADLWrapper/GenerateProfileDisplayIdentifiers: AMD Adapter #{oneAdapter.AdapterIndex.ToString()} isn't enabled at present so skipping detection for this adapter.");
continue;
}
// 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);
if (ADL.ADL2_Adapter_Active_Get != null)
ADLRet = ADL.ADL2_Adapter_Active_Get(_adlContextHandle, oneAdapter.AdapterIndex, ref IsActive);
if (ADLRet == ADL.ADL_OK)
{
// Only continue if the adapter is enabled
if (IsActive != ADL.ADL_TRUE)
{
SharedLogger.logger.Trace($"ADLWrapper/GenerateProfileDisplayIdentifiers: AMD Adapter #{i} isn't active ({OSAdapterInfoData.ADLAdapterInfo[i].AdapterName}).");
SharedLogger.logger.Trace($"ADLWrapper/GenerateProfileDisplayIdentifiers: AMD Adapter #{oneAdapter.AdapterIndex.ToString()} isn't active ({oneAdapter.AdapterName}).");
continue;
}
SharedLogger.logger.Trace($"ADLWrapper/GenerateProfileDisplayIdentifiers: AMD Adapter #{i} is active! ({OSAdapterInfoData.ADLAdapterInfo[i].AdapterName}).");
// Get the unique identifier from the Adapter
int AdapterID = 0;
if (ADL.ADL_Adapter_ID_Get != null)
// Only continue if the adapter index is > 0
if (oneAdapter.AdapterIndex < 0)
{
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()}");
SharedLogger.logger.Trace($"ADLWrapper/GenerateProfileDisplayIdentifiers: AMD Adapter has an adapter index of {oneAdapter.AdapterIndex.ToString()} which indicates it is not a real adapter.");
continue;
}
SharedLogger.logger.Trace($"ADLWrapper/GenerateProfileDisplayIdentifiers: AMD Adapter #{oneAdapter.AdapterIndex.ToString()} is active! ({oneAdapter.AdapterName}).");
Console.WriteLine($"### Adapter Info for Adapter #{oneAdapter.AdapterIndex} ###");
Console.WriteLine($"Adapter AdapterIndex = {oneAdapter.AdapterIndex}");
Console.WriteLine($"Adapter AdapterName = {oneAdapter.AdapterName}");
Console.WriteLine($"Adapter BusNumber = {oneAdapter.BusNumber}");
Console.WriteLine($"Adapter DeviceNumber = {oneAdapter.DeviceNumber}");
Console.WriteLine($"Adapter DisplayName = {oneAdapter.DisplayName}");
Console.WriteLine($"Adapter DriverPath = {oneAdapter.DriverPath}");
Console.WriteLine($"Adapter DriverPathExt = {oneAdapter.DriverPathExt}");
Console.WriteLine($"Adapter Exist = {oneAdapter.Exist}");
Console.WriteLine($"Adapter FunctionNumber = {oneAdapter.FunctionNumber}");
Console.WriteLine($"Adapter InfoMask = {oneAdapter.InfoMask}");
Console.WriteLine($"Adapter InfoValue = {oneAdapter.InfoValue}");
Console.WriteLine($"Adapter OSDisplayIndex = {oneAdapter.OSDisplayIndex}");
Console.WriteLine($"Adapter PNPString = {oneAdapter.PNPString}");
Console.WriteLine($"Adapter Present = {oneAdapter.Present}");
Console.WriteLine($"Adapter Size = {oneAdapter.Size}");
Console.WriteLine($"Adapter UDID = {oneAdapter.UDID}");
Console.WriteLine($"Adapter VendorID = {oneAdapter.VendorID}");
// Get the Adapter Capabilities
ADLAdapterCapsX2 AdapterCapabilities = new ADLAdapterCapsX2();
if (ADL.ADL_AdapterX2_Caps != null)
if (ADL.ADL2_AdapterX2_Caps != null)
{
ADLRet = ADL.ADL_AdapterX2_Caps(OSAdapterInfoData.ADLAdapterInfo[i].AdapterIndex, out AdapterCapabilities);
ADLRet = ADL.ADL2_AdapterX2_Caps(_adlContextHandle, oneAdapter.AdapterIndex, out AdapterCapabilities);
}
//ADLAdapterCapsX2 AdapterCapabilities = (ADLAdapterCapsX2)Marshal.PtrToStructure(AdapterCapabilitiesBuffer, typeof(ADLAdapterCapsX2));
Console.Write(AdapterCapabilities.AdapterID);
Console.WriteLine($"### Adapter Capabilities for Adapter #{oneAdapter.AdapterIndex} ###");
Console.WriteLine($"Adapter ID = {AdapterCapabilities.AdapterID}");
Console.WriteLine($"Adapter Capabilities Mask = {AdapterCapabilities.CapsMask}");
Console.WriteLine($"Adapter Capabilities Value = {AdapterCapabilities.CapsValue}");
Console.WriteLine($"Adapter Num of Connectors = {AdapterCapabilities.NumConnectors}");
Console.WriteLine($"Adapter Num of Controllers = {AdapterCapabilities.NumControllers}");
Console.WriteLine($"Adapter Num of Displays = {AdapterCapabilities.NumDisplays}");
Console.WriteLine($"Adapter Num of GL Sync Connectors = {AdapterCapabilities.NumOfGLSyncConnectors}");
Console.WriteLine($"Adapter Num of Overlays = {AdapterCapabilities.NumOverlays}");
// Obtain information about displays
ADLDisplayInfo oneDisplayInfo = new ADLDisplayInfo();
ADLDisplayInfoArray displayInfoArray = new ADLDisplayInfoArray();
if (ADL.ADL_Display_DisplayInfo_Get != null)
if (ADL.ADL2_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);
ADLRet = ADL.ADL2_Display_DisplayInfo_Get(_adlContextHandle, oneAdapter.AdapterIndex, ref NumberOfDisplays, out DisplayBuffer, 0);
if (ADLRet == ADL.ADL_OK)
{
List<ADLDisplayInfo> DisplayInfoData = new List<ADLDisplayInfo>();
try
{
displayInfoArray = (ADLDisplayInfoArray)Marshal.PtrToStructure(DisplayBuffer, displayInfoArray.GetType());
for (j = 0; j < NumberOfDisplays; j++)
foreach (ADLDisplayInfo oneDisplayInfo in displayInfoArray.ADLDisplayInfo)
{
// 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++)
if (oneDisplayInfo.DisplayID.DisplayLogicalAdapterIndex == -1)
{
// Skip non connected displays - we want only connected displays that could potentially be used now (thats both mapped and non-mapped 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");
SharedLogger.logger.Trace($"ADLWrapper/GenerateProfileDisplayIdentifiers: AMD Adapter #{oneAdapter.AdapterIndex.ToString()} ({oneAdapter.AdapterName}) AdapterID display ID#{oneDisplayInfo.DisplayID.DisplayLogicalIndex} is not a real display as its DisplayID.DisplayLogicalAdapterIndex is -1");
continue;
}
ADLDisplayConfig DisplayConfig = new ADLDisplayConfig();
if (ADL.ADL_Display_DeviceConfig_Get != null)
// Convert the displayInfoValue to something usable using a library function I made
ConvertedDisplayInfoValue displayInfoValue = ADL.ConvertDisplayInfoValue(oneDisplayInfo.DisplayInfoValue);
// Skip the non-connected displays, but still show the non-mapped displays (as they are still able to be used with a display config change)
if (!displayInfoValue.DISPLAYCONNECTED)
{
// Get the device config
ADLRet = ADL.ADL_Display_DeviceConfig_Get(OSAdapterInfoData.ADLAdapterInfo[i].AdapterIndex, DisplayInfoData[j].DisplayID.DisplayLogicalIndex, out DisplayConfig);
SharedLogger.logger.Trace($"ADLWrapper/GenerateProfileDisplayIdentifiers: AMD Adapter #{oneAdapter.AdapterIndex.ToString()} ({oneAdapter.AdapterName}) AdapterID display ID#{oneDisplayInfo.DisplayID.DisplayLogicalIndex} is not connected");
continue;
}
ADL.ADLDisplayConnectionType displayConnector = (ADL.ADLDisplayConnectionType)oneDisplayInfo.DisplayConnector;
Console.WriteLine($"### Display Info for Display #{oneDisplayInfo.DisplayID.DisplayLogicalIndex} on Adapter #{oneAdapter.AdapterIndex} ###");
Console.WriteLine($"Display Connector = {displayConnector.ToString("G")}");
Console.WriteLine($"Display Controller Index = {oneDisplayInfo.DisplayControllerIndex}");
Console.WriteLine($"Display Logical Adapter Index = {oneDisplayInfo.DisplayID.DisplayLogicalAdapterIndex}");
Console.WriteLine($"Display Logical Index = {oneDisplayInfo.DisplayID.DisplayLogicalIndex}");
Console.WriteLine($"Display Physical Adapter Index = {oneDisplayInfo.DisplayID.DisplayPhysicalAdapterIndex}");
Console.WriteLine($"Display Physical Index = {oneDisplayInfo.DisplayID.DisplayPhysicalIndex}");
Console.WriteLine($"Display Info Mask = {oneDisplayInfo.DisplayInfoMask}");
Console.WriteLine($"Display Info Value = {oneDisplayInfo.DisplayInfoValue}");
Console.WriteLine($"Display Manufacturer Name = {oneDisplayInfo.DisplayManufacturerName}");
Console.WriteLine($"Display Name = {oneDisplayInfo.DisplayName}");
Console.WriteLine($"Display Output Type = {oneDisplayInfo.DisplayOutputType}");
Console.WriteLine($"Display Type = {oneDisplayInfo.DisplayType}");
Console.WriteLine($"Display Info Value DISPLAYCONNECTED = {displayInfoValue.DISPLAYCONNECTED}");
Console.WriteLine($"Display Info Value DISPLAYMAPPED = {displayInfoValue.DISPLAYMAPPED}");
Console.WriteLine($"Display Info Value FORCIBLESUPPORTED = {displayInfoValue.FORCIBLESUPPORTED}");
Console.WriteLine($"Display Info Value GENLOCKSUPPORTED = {displayInfoValue.GENLOCKSUPPORTED}");
Console.WriteLine($"Display Info Value LDA_DISPLAY = {displayInfoValue.LDA_DISPLAY}");
Console.WriteLine($"Display Info Value MANNER_SUPPORTED_2HSTRETCH = {displayInfoValue.MANNER_SUPPORTED_2HSTRETCH}");
Console.WriteLine($"Display Info Value MANNER_SUPPORTED_2VSTRETCH = {displayInfoValue.MANNER_SUPPORTED_2VSTRETCH}");
Console.WriteLine($"Display Info Value MANNER_SUPPORTED_CLONE = {displayInfoValue.MANNER_SUPPORTED_CLONE}");
Console.WriteLine($"Display Info Value MANNER_SUPPORTED_EXTENDED = {displayInfoValue.MANNER_SUPPORTED_EXTENDED}");
Console.WriteLine($"Display Info Value MANNER_SUPPORTED_NSTRETCH1GPU = {displayInfoValue.MANNER_SUPPORTED_NSTRETCH1GPU}");
Console.WriteLine($"Display Info Value MANNER_SUPPORTED_NSTRETCHNGPU = {displayInfoValue.MANNER_SUPPORTED_NSTRETCHNGPU}");
Console.WriteLine($"Display Info Value MANNER_SUPPORTED_SINGLE = {displayInfoValue.MANNER_SUPPORTED_SINGLE}");
Console.WriteLine($"Display Info Value MODETIMING_OVERRIDESSUPPORTED = {displayInfoValue.MODETIMING_OVERRIDESSUPPORTED}");
Console.WriteLine($"Display Info Value MULTIVPU_SUPPORTED = {displayInfoValue.MULTIVPU_SUPPORTED}");
Console.WriteLine($"Display Info Value NONLOCAL = {displayInfoValue.NONLOCAL}");
Console.WriteLine($"Display Info Value SHOWTYPE_PROJECTOR = {displayInfoValue.SHOWTYPE_PROJECTOR}");
ADL.ADLDisplayConnectionType displayConnectionType = ADL.ADLDisplayConnectionType.Unknown;
ADLDisplayConfig displayConfig = new ADLDisplayConfig();
displayConfig.Size = Marshal.SizeOf(displayConfig);
if (ADL.ADL2_Display_DeviceConfig_Get != null)
{
// Get the DisplayConfig from the Display
ADLRet = ADL.ADL2_Display_DeviceConfig_Get(_adlContextHandle, oneAdapter.AdapterIndex, oneDisplayInfo.DisplayID.DisplayPhysicalIndex, out displayConfig);
if (ADLRet == ADL.ADL_OK)
{
displayConnectionType = (ADL.ADLDisplayConnectionType)displayConfig.ConnectorType;
Console.WriteLine($"### Display Device Config for Display #{oneDisplayInfo.DisplayID.DisplayLogicalIndex} on Adapter #{oneAdapter.AdapterIndex} ###");
Console.WriteLine($"Display Connector Type = {displayConnectionType.ToString("G")}");
Console.WriteLine($"Display Device Data = {displayConfig.DeviceData}");
Console.WriteLine($"Display Overridded Device Data = {displayConfig.OverriddedDeviceData}");
Console.WriteLine($"Display Reserved Data = {displayConfig.Reserved}");
Console.WriteLine($"Display Size = {displayConfig.Size}");
}
}
ADLDDCInfo2 displayDDCInfo2 = new ADLDDCInfo2();
displayDDCInfo2.Size = Marshal.SizeOf(displayDDCInfo2);
// Create a stringbuilder buffer that EDID can be loaded into
//displayEDIDData.EDIDData = new StringBuilder(256);
if (ADL.ADL2_Display_DDCInfo2_Get != null)
{
// Get the EDID Data from the Display
ADLRet = ADL.ADL2_Display_DDCInfo2_Get(_adlContextHandle, oneAdapter.AdapterIndex, oneDisplayInfo.DisplayID.DisplayPhysicalIndex, out displayDDCInfo2);
if (ADLRet == ADL.ADL_OK)
{
// Convert the DDCInfoFlag to something usable using a library function I made
ConvertedDDCInfoFlag DDCInfoFlag = ADL.ConvertDDCInfoFlag(displayDDCInfo2.DDCInfoFlag);
// Convert the DDCInfoFlag to something usable using a library function I made
ConvertedSupportedHDR supportedHDR = ADL.ConvertSupportedHDR(displayDDCInfo2.SupportedHDR);
Console.WriteLine($"### Display DDCInfo2 for Display #{oneDisplayInfo.DisplayID.DisplayLogicalIndex} on Adapter #{oneAdapter.AdapterIndex} ###");
Console.WriteLine($"Display AvgLuminanceData = {displayDDCInfo2.AvgLuminanceData}");
Console.WriteLine($"Display DDCInfoFlag = {displayDDCInfo2.DDCInfoFlag}");
Console.WriteLine($"Display DiffuseScreenReflectance = {displayDDCInfo2.DiffuseScreenReflectance}");
Console.WriteLine($"Display DisplayName = {displayDDCInfo2.DisplayName}");
Console.WriteLine($"Display FreesyncFlags = {displayDDCInfo2.FreesyncFlags}");
Console.WriteLine($"Display ManufacturerID = {displayDDCInfo2.ManufacturerID}");
Console.WriteLine($"Display MaxBacklightMaxLuminanceData = {displayDDCInfo2.MaxBacklightMaxLuminanceData}");
Console.WriteLine($"Display MaxBacklightMinLuminanceData = {displayDDCInfo2.MaxBacklightMinLuminanceData}");
Console.WriteLine($"Display MaxHResolution = {displayDDCInfo2.MaxHResolution}");
Console.WriteLine($"Display MaxLuminanceData = {displayDDCInfo2.MaxLuminanceData}");
Console.WriteLine($"Display MaxRefresh = {displayDDCInfo2.MaxRefresh}");
Console.WriteLine($"Display MaxVResolution = {displayDDCInfo2.MaxVResolution}");
Console.WriteLine($"Display MinBacklightMaxLuminanceData = {displayDDCInfo2.MinBacklightMaxLuminanceData}");
Console.WriteLine($"Display MinBacklightMinLuminanceData = {displayDDCInfo2.MinBacklightMinLuminanceData}");
Console.WriteLine($"Display MinLuminanceData = {displayDDCInfo2.MinLuminanceData}");
Console.WriteLine($"Display MinLuminanceNoDimmingData = {displayDDCInfo2.MinLuminanceNoDimmingData}");
Console.WriteLine($"Display NativeDisplayChromaticityBlueX = {displayDDCInfo2.NativeDisplayChromaticityBlueX}");
Console.WriteLine($"Display NativeDisplayChromaticityBlueY = {displayDDCInfo2.NativeDisplayChromaticityBlueY}");
Console.WriteLine($"Display NativeDisplayChromaticityGreenX = {displayDDCInfo2.NativeDisplayChromaticityGreenX}");
Console.WriteLine($"Display NativeDisplayChromaticityGreenY = {displayDDCInfo2.NativeDisplayChromaticityGreenY}");
Console.WriteLine($"Display NativeDisplayChromaticityRedX = {displayDDCInfo2.NativeDisplayChromaticityRedX}");
Console.WriteLine($"Display NativeDisplayChromaticityRedY = {displayDDCInfo2.NativeDisplayChromaticityRedY}");
Console.WriteLine($"Display NativeDisplayChromaticityWhiteX = {displayDDCInfo2.NativeDisplayChromaticityWhiteX}");
Console.WriteLine($"Display NativeDisplayChromaticityWhiteY = {displayDDCInfo2.NativeDisplayChromaticityWhiteY}");
Console.WriteLine($"Display PackedPixelSupported = {displayDDCInfo2.PackedPixelSupported}");
Console.WriteLine($"Display PanelPixelFormat = {displayDDCInfo2.PanelPixelFormat}");
Console.WriteLine($"Display ProductID = {displayDDCInfo2.ProductID}");
Console.WriteLine($"Display PTMCx = {displayDDCInfo2.PTMCx}");
Console.WriteLine($"Display PTMCy = {displayDDCInfo2.PTMCy}");
Console.WriteLine($"Display PTMRefreshRate = {displayDDCInfo2.PTMRefreshRate}");
Console.WriteLine($"Display SerialID = {displayDDCInfo2.SerialID}");
Console.WriteLine($"Display Size = {displayDDCInfo2.Size}");
Console.WriteLine($"Display SpecularScreenReflectance = {displayDDCInfo2.SpecularScreenReflectance}");
Console.WriteLine($"Display SupportedColorSpace = {displayDDCInfo2.SupportedColorSpace}");
Console.WriteLine($"Display SupportedHDR = {displayDDCInfo2.SupportedHDR}");
Console.WriteLine($"Display SupportedTransferFunction = {displayDDCInfo2.SupportedTransferFunction}");
Console.WriteLine($"Display SupportsDDC = {displayDDCInfo2.SupportsDDC}");
Console.WriteLine($"Display DDCInfoFlag Digital Device = {DDCInfoFlag.DIGITALDEVICE}");
Console.WriteLine($"Display DDCInfoFlag EDID Extension = {DDCInfoFlag.EDIDEXTENSION}");
Console.WriteLine($"Display DDCInfoFlag HDMI Audio Device = {DDCInfoFlag.HDMIAUDIODEVICE}");
Console.WriteLine($"Display DDCInfoFlag Projector Device = {DDCInfoFlag.PROJECTORDEVICE}");
Console.WriteLine($"Display DDCInfoFlag Supports AI = {DDCInfoFlag.SUPPORTS_AI}");
Console.WriteLine($"Display DDCInfoFlag Supports xvYCC601 = {DDCInfoFlag.SUPPORT_xvYCC601}");
Console.WriteLine($"Display DDCInfoFlag Supports xvYCC709 = {DDCInfoFlag.SUPPORT_xvYCC709}");
Console.WriteLine($"Display SupportedHDR Supports CEA861_3 = {supportedHDR.CEA861_3}");
Console.WriteLine($"Display SupportedHDR Supports DOLBYVISION = {supportedHDR.DOLBYVISION}");
Console.WriteLine($"Display SupportedHDR Supports FREESYNC_HDR = {supportedHDR.FREESYNC_HDR}");
}
else
{
Console.WriteLine($"Error running ADL_vDisplay_EdidData_Get on Display #{oneDisplayInfo.DisplayID.DisplayLogicalIndex} on Adapter #{oneAdapter.AdapterIndex}: {ADL.ConvertADLReturnValueIntoWords(ADLRet)}");
}
}
int HDRSupported = 0;
int HDREnabled = 0;
if (ADL.ADL2_Display_HDRState_Get != null)
{
// Get the HDR State from the Display
ADLRet = ADL.ADL2_Display_HDRState_Get(_adlContextHandle, oneAdapter.AdapterIndex, oneDisplayInfo.DisplayID, out HDRSupported, out HDREnabled);
if (ADLRet == ADL.ADL_OK)
{
Console.WriteLine($"### Display HDR State for Display #{oneDisplayInfo.DisplayID.DisplayLogicalIndex} on Adapter #{oneAdapter.AdapterIndex} ###");
Console.WriteLine($"Display HDR Supported = {HDRSupported}");
Console.WriteLine($"Display HDR Enabled = {HDREnabled}");
}
}
// Create an array of all the important display info we need to record
List<string> displayInfoIdentifierSection = new List<string>();
displayInfoIdentifierSection.Add("AMD");
try
{
displayInfoIdentifierSection.Add(OSAdapterInfoData.ADLAdapterInfo[i].AdapterName);
displayInfoIdentifierSection.Add(oneAdapter.VendorID.ToString());
}
catch (Exception ex)
{
SharedLogger.logger.Warn(ex, $"ADLWrapper/GenerateProfileDisplayIdentifiers: Exception getting AMD Vendor ID from video card. Substituting with a # instead");
displayInfoIdentifierSection.Add("#");
}
try
{
displayInfoIdentifierSection.Add(oneAdapter.AdapterName);
}
catch (Exception ex)
{
@ -814,17 +909,7 @@ namespace DisplayMagicianShared.AMD
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());
displayInfoIdentifierSection.Add(oneAdapter.VendorID.ToString());
}
catch (Exception ex)
{
@ -834,7 +919,7 @@ namespace DisplayMagicianShared.AMD
try
{
displayInfoIdentifierSection.Add(AdapterID.ToString());
displayInfoIdentifierSection.Add(AdapterCapabilities.AdapterID.ToString());
}
catch (Exception ex)
{
@ -844,8 +929,7 @@ namespace DisplayMagicianShared.AMD
try
{
ADL.ADLConnectionType connector = (ADL.ADLConnectionType)DisplayInfoData[j].DisplayOutputType;
displayInfoIdentifierSection.Add(connector.ToString());
displayInfoIdentifierSection.Add(displayConnector.ToString("G"));
}
catch (Exception ex)
{
@ -855,31 +939,67 @@ namespace DisplayMagicianShared.AMD
try
{
displayInfoIdentifierSection.Add(DisplayInfoData[j].DisplayManufacturerName);
displayInfoIdentifierSection.Add(oneDisplayInfo.DisplayName);
}
catch (Exception ex)
{
SharedLogger.logger.Warn(ex, $"ADLWrapper/GenerateProfileDisplayIdentifiers: Exception getting Display manufacturer from AMD video card. Substituting with a # instead");
SharedLogger.logger.Warn(ex, $"ADLWrapper/GenerateProfileDisplayIdentifiers: Exception getting Display Name from display connected to AMD video card. Substituting with a # instead");
displayInfoIdentifierSection.Add("#");
}
try
{
displayInfoIdentifierSection.Add(DisplayInfoData[j].DisplayName);
displayInfoIdentifierSection.Add(displayDDCInfo2.ManufacturerID.ToString());
}
catch (Exception ex)
{
SharedLogger.logger.Warn(ex, $"ADLWrapper/GenerateProfileDisplayIdentifiers: Exception getting Display Name from AMD video card. Substituting with a # instead");
SharedLogger.logger.Warn(ex, $"ADLWrapper/GenerateProfileDisplayIdentifiers: Exception getting Manufacturer ID from display connected to AMD video card. Substituting with a # instead");
displayInfoIdentifierSection.Add("#");
}
try
{
displayInfoIdentifierSection.Add(displayDDCInfo2.ProductID.ToString());
}
catch (Exception ex)
{
SharedLogger.logger.Warn(ex, $"ADLWrapper/GenerateProfileDisplayIdentifiers: Exception getting Product ID from display connected to AMD video card. Substituting with a # instead");
displayInfoIdentifierSection.Add("#");
}
try
{
displayInfoIdentifierSection.Add(displayDDCInfo2.SerialID.ToString());
}
catch (Exception ex)
{
SharedLogger.logger.Warn(ex, $"ADLWrapper/GenerateProfileDisplayIdentifiers: Exception getting Serial ID from display connected to AMD video card. Substituting with a # instead");
displayInfoIdentifierSection.Add("#");
}
// Create a display identifier out of it
string displayIdentifier = String.Join("|", displayInfoIdentifierSection);
// Check first to see if there is already an existing display identifier the same!
// This appears to be a bug with the AMD driver, or with the install on my test machine
// Either way, it is potentially going to happen in the wild, so I will filter it out if it does
if (displayIdentifiers.Contains(displayIdentifier))
{
SharedLogger.logger.Trace($"ADLWrapper/GenerateProfileDisplayIdentifiers: Your AMD driver reported the following Display Identifier multiple times, so ignoring it as we already have it: {displayIdentifier}");
continue;
}
// Add it to the list of display identifiers so we can return it
displayIdentifiers.Add(displayIdentifier);
Console.WriteLine($"ProfileRepository/GenerateProfileDisplayIdentifiers: DisplayIdentifier: {displayIdentifier}");
SharedLogger.logger.Debug($"ProfileRepository/GenerateProfileDisplayIdentifiers: DisplayIdentifier: {displayIdentifier}");
}
}
catch (Exception ex)
{
Console.WriteLine("Exception caused trying to access attached displays");
continue;
}
}
else
@ -919,4 +1039,3 @@ namespace DisplayMagicianShared.AMD
}
}
}

View File

@ -798,9 +798,11 @@ namespace DisplayMagicianShared
SharedLogger.logger.Debug($"ProfileRepository/GenerateProfileDisplayIdentifiers: Generating the unique Display Identifiers for the currently active profile");
List<string> displayIdentifiers = new List<string>();
bool isNvidia = false;
bool isAMD = false;
// If the Video Card is an NVidia, then we should generate specific NVidia displayIdentifiers
bool isNvidia = false;
NvAPIWrapper.GPU.PhysicalGPU[] myPhysicalGPUs = null;
try
{
@ -812,29 +814,6 @@ namespace DisplayMagicianShared
{
SharedLogger.logger.Debug(ex, "ProfileRepository/GenerateProfileDisplayIdentifiers: Attemped to get GetPhysicalCPUs through NvAPIWrapper library but got exception. This means the video card isn't compatible with the NvAPIWrapper library we use. It is unlikely to be an NVIDIA video card.");
}
// If the Video Card is an AMD, then we should generate specific AMD displayIdentifiers
bool isAMD = false;
if (AMDLibrary.IsInstalled)
{
isAMD = true;
SharedLogger.logger.Debug($"ProfileRepository/GenerateProfileDisplayIdentifiers: The video card is an AMD video card.");
// Needs a lot of work here! We need to check if the AMD returned the right stuff, and then use Windows if there is an error.
return AMDLibrary.GenerateProfileDisplayIdentifiers();
}
try
{
myPhysicalGPUs = NvAPIWrapper.GPU.PhysicalGPU.GetPhysicalGPUs();
isNvidia = true;
SharedLogger.logger.Debug($"ProfileRepository/GenerateProfileDisplayIdentifiers: The video card is a NVIDIA video card.");
}
catch (Exception ex)
{
SharedLogger.logger.Debug(ex, "ProfileRepository/GenerateProfileDisplayIdentifiers: Attemped to get GetPhysicalCPUs through NvAPIWrapper library but got exception. This means the video card isn't compatible with the NvAPIWrapper library we use. It is unlikely to be an NVIDIA video card.");
}
if (isNvidia && myPhysicalGPUs != null && myPhysicalGPUs.Length > 0)
//if (false)
{
@ -936,10 +915,15 @@ namespace DisplayMagicianShared
}
}
// else videocard is not NVIdia so we just use the WindowsAPI access method
// Note: This won't support any special AMD EyeFinity profiles unfortunately.....
// TODO: Add the detection and generation of the device ids using an AMD library
// so that we can match valid AMD Eyefinity profiles with valid AMD standard profiles.
// else if there is an AMD video card then we use that mode
else if (AMDLibrary.IsInstalled)
{
isAMD = true;
SharedLogger.logger.Debug($"ProfileRepository/GenerateProfileDisplayIdentifiers: The video card is an AMD video card.");
// Needs a lot of work here! We need to check if the AMD returned the right stuff, and then use Windows if there is an error.
return AMDLibrary.GenerateProfileDisplayIdentifiers();
}
// else video card is not NVIDIA or AMD so we just use the standard WindowsAPI access method
else
{
// Then go through the adapters we have running using the WindowsDisplayAPI