mirror of
https://github.com/terrymacdonald/DisplayMagician.git
synced 2024-08-30 18:32:20 +00:00
[WIP] Learning about PInvoke
This is a lot of learning about Pinvoke and the way to marshal c structures into c# managed structures when passed as out. This is all a lot more indepth than I was hoping it was going to be!
This commit is contained in:
parent
ee7c5fe1da
commit
583fffb612
@ -66,10 +66,24 @@ namespace ATI.ADL
|
|||||||
/// <summary> Function to determine if the adapter is active or not.</summary>
|
/// <summary> Function to determine if the adapter is active or not.</summary>
|
||||||
/// <remarks>The function is used to check if the adapter associated with iAdapterIndex is active</remarks>
|
/// <remarks>The function is used to check if the adapter associated with iAdapterIndex is active</remarks>
|
||||||
/// <param name="adapterIndex"> Adapter Index.</param>
|
/// <param name="adapterIndex"> Adapter Index.</param>
|
||||||
/// <param name="status"> Status of the adapter. True: Active; False: Dsiabled</param>
|
/// <param name="status"> Status of the adapter. True: Active; False: Disabled</param>
|
||||||
/// <returns>Non zero is successfull</returns>
|
/// <returns>Non zero is successful</returns>
|
||||||
internal delegate int ADL_Adapter_Active_Get(int adapterIndex, ref int status);
|
internal delegate int ADL_Adapter_Active_Get(int adapterIndex, ref int status);
|
||||||
|
|
||||||
|
/// <summary> Function to get the unique identifier of an adapter.</summary>
|
||||||
|
/// <remarks>This function retrieves the unique identifier of a specified adapter. The adapter ID is a unique value and will be used to determine what other controllers share the same adapter. The desktop will use this to find which HDCs are associated with an adapter.</remarks>
|
||||||
|
/// <param name="adapterIndex"> Adapter Index.</param>
|
||||||
|
/// <param name="adapterId"> The pointer to the adapter identifier. Zero means: The adapter is not AMD.</param>
|
||||||
|
/// <returns>return ADL Error Code</returns>
|
||||||
|
internal delegate int ADL_Adapter_ID_Get(int adapterIndex, ref int adapterId);
|
||||||
|
|
||||||
|
/// <summary>Function to retrieve adapter capability information.</summary>
|
||||||
|
/// <remarks>This function implements a DI call to retrieve adapter capability information .</remarks>
|
||||||
|
/// <param name="adapterIndex"> Adapter Index.</param>
|
||||||
|
/// <param name="adapterCapabilities"> The pointer to the ADLAdapterCaps structure storing the retrieved adapter capability information.</param>
|
||||||
|
/// <returns>return ADL Error Code</returns>
|
||||||
|
internal delegate int ADL_Adapter_Caps(int adapterIndex, out IntPtr adapterCapabilities);
|
||||||
|
|
||||||
/// <summary>Get display information based on adapter index</summary>
|
/// <summary>Get display information based on adapter index</summary>
|
||||||
/// <param name="adapterIndex">Adapter Index</param>
|
/// <param name="adapterIndex">Adapter Index</param>
|
||||||
/// <param name="numDisplays">return the total number of supported displays</param>
|
/// <param name="numDisplays">return the total number of supported displays</param>
|
||||||
@ -253,6 +267,27 @@ namespace ATI.ADL
|
|||||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = (int)ADL.ADL_MAX_DISPLAYS)]
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = (int)ADL.ADL_MAX_DISPLAYS)]
|
||||||
internal ADLDisplayInfo[] ADLDisplayInfo;
|
internal ADLDisplayInfo[] ADLDisplayInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> ADLAdapterCaps Structure</summary>
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
internal struct ADLAdapterCaps
|
||||||
|
{
|
||||||
|
/// <summary> AdapterID for this adapter </summary>
|
||||||
|
internal int AdapterID;
|
||||||
|
/// <summary> The bit mask identifies the adapter caps. </summary>
|
||||||
|
internal int CapsMask;
|
||||||
|
/// <summary> The bit identifies the adapter caps define_adapter_caps. </summary>
|
||||||
|
internal int CapsValue;
|
||||||
|
/// <summary> Number of controllers for this adapter. </summary>
|
||||||
|
internal int NumControllers;
|
||||||
|
/// <summary> Number of displays for this adapter.</summary>
|
||||||
|
internal int NumDisplays;
|
||||||
|
/// <summary> Number of GLSyncConnectors. </summary>
|
||||||
|
internal int NumOfGLSyncConnectors;
|
||||||
|
/// <summary> Number of overlays for this adapter.</summary>
|
||||||
|
internal int NumOverlays;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion ADLDisplayInfo
|
#endregion ADLDisplayInfo
|
||||||
|
|
||||||
#region ADLSLS
|
#region ADLSLS
|
||||||
@ -437,7 +472,11 @@ namespace ATI.ADL
|
|||||||
/// <summary> Maximum number of GL-Sync ports on the GL-Sync module </summary>
|
/// <summary> Maximum number of GL-Sync ports on the GL-Sync module </summary>
|
||||||
internal const int ADL_MAX_GLSYNC_PORT_LEDS = 8;
|
internal const int ADL_MAX_GLSYNC_PORT_LEDS = 8;
|
||||||
/// <summary> Maximum number of ADLModes for the adapter </summary>
|
/// <summary> Maximum number of ADLModes for the adapter </summary>
|
||||||
internal const int ADL_MAX_NUM_DISPLAYMODES = 1024;
|
internal const int ADL_MAX_NUM_DISPLAYMODES = 1024;
|
||||||
|
/// <summary> Define true </summary>
|
||||||
|
internal const int ADL_TRUE = 1;
|
||||||
|
/// <summary> Maximum number of ADLModes for the adapter </summary>
|
||||||
|
internal const int ADL_FALSE = 0;
|
||||||
|
|
||||||
#endregion Internal Constant
|
#endregion Internal Constant
|
||||||
|
|
||||||
@ -477,6 +516,13 @@ namespace ATI.ADL
|
|||||||
[DllImport(Atiadlxx_FileName)]
|
[DllImport(Atiadlxx_FileName)]
|
||||||
internal static extern int ADL_Adapter_Active_Get(int adapterIndex, ref int status);
|
internal static extern int ADL_Adapter_Active_Get(int adapterIndex, ref int status);
|
||||||
|
|
||||||
|
[DllImport(Atiadlxx_FileName)]
|
||||||
|
internal static extern int ADL_Adapter_ID_Get(int adapterIndex, ref int adapterId);
|
||||||
|
|
||||||
|
[DllImport(Atiadlxx_FileName)]
|
||||||
|
internal static extern int ADL_Adapter_Caps(int adapterIndex, out IntPtr adapterCapabilities);
|
||||||
|
|
||||||
|
|
||||||
[DllImport(Atiadlxx_FileName)]
|
[DllImport(Atiadlxx_FileName)]
|
||||||
internal static extern int ADL_Display_DisplayInfo_Get(int adapterIndex, ref int numDisplays, out IntPtr displayInfoArray, int forceDetect);
|
internal static extern int ADL_Display_DisplayInfo_Get(int adapterIndex, ref int numDisplays, out IntPtr displayInfoArray, int forceDetect);
|
||||||
|
|
||||||
@ -701,6 +747,53 @@ namespace ATI.ADL
|
|||||||
private static bool ADL_Adapter_AdapterInfo_Get_Check = false;
|
private static bool ADL_Adapter_AdapterInfo_Get_Check = false;
|
||||||
#endregion ADL_Adapter_AdapterInfo_Get
|
#endregion ADL_Adapter_AdapterInfo_Get
|
||||||
|
|
||||||
|
#region ADL_Adapter_ID_Get
|
||||||
|
#endregion ADL_Adapter_ID_Get
|
||||||
|
|
||||||
|
/// <summary> ADL_Adapter_Active_Get Delegates</summary>
|
||||||
|
internal static ADL_Adapter_ID_Get ADL_Adapter_ID_Get
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (!ADL_Adapter_ID_Get_Check && null == ADL_Adapter_ID_Get_)
|
||||||
|
{
|
||||||
|
ADL_Adapter_ID_Get_Check = true;
|
||||||
|
if (ADLCheckLibrary.IsFunctionValid("ADL_Adapter_ID_Get"))
|
||||||
|
{
|
||||||
|
ADL_Adapter_ID_Get_ = ADLImport.ADL_Adapter_ID_Get;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ADL_Adapter_ID_Get_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary> Private Delegate</summary>
|
||||||
|
private static ADL_Adapter_ID_Get ADL_Adapter_ID_Get_ = null;
|
||||||
|
/// <summary> check flag to indicate the delegate has been checked</summary>
|
||||||
|
private static bool ADL_Adapter_ID_Get_Check = false;
|
||||||
|
|
||||||
|
#region ADL_Adapter_Caps
|
||||||
|
/// <summary> ADL_Adapter_Active_Get Delegates</summary>
|
||||||
|
internal static ADL_Adapter_Caps ADL_Adapter_Caps
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (!ADL_Adapter_Caps_Check && null == ADL_Adapter_Caps_)
|
||||||
|
{
|
||||||
|
ADL_Adapter_Caps_Check = true;
|
||||||
|
if (ADLCheckLibrary.IsFunctionValid("ADL_Adapter_Caps"))
|
||||||
|
{
|
||||||
|
ADL_Adapter_Caps_ = ADLImport.ADL_Adapter_Caps;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ADL_Adapter_Caps_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary> Private Delegate</summary>
|
||||||
|
private static ADL_Adapter_Caps ADL_Adapter_Caps_ = null;
|
||||||
|
/// <summary> check flag to indicate the delegate has been checked</summary>
|
||||||
|
private static bool ADL_Adapter_Caps_Check = false;
|
||||||
|
#endregion ADL_Adapter_Caps
|
||||||
|
|
||||||
#region ADL_Adapter_Active_Get
|
#region ADL_Adapter_Active_Get
|
||||||
/// <summary> ADL_Adapter_Active_Get Delegates</summary>
|
/// <summary> ADL_Adapter_Active_Get Delegates</summary>
|
||||||
internal static ADL_Adapter_Active_Get ADL_Adapter_Active_Get
|
internal static ADL_Adapter_Active_Get ADL_Adapter_Active_Get
|
||||||
|
@ -102,7 +102,357 @@ namespace DisplayMagicianShared.AMD
|
|||||||
return _instance;
|
return _instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<string> GenerateDisplayProfilesIdentifiers()
|
public List<string> GenerateProfileDisplayIdentifiers()
|
||||||
|
{
|
||||||
|
SharedLogger.logger.Trace($"ADLWrapper/GenerateProfileDisplayIdentifiers: Getting AMD active adapter count");
|
||||||
|
|
||||||
|
int ADLRet = ADL.ADL_FAIL;
|
||||||
|
int NumberOfAdapters = 0;
|
||||||
|
int NumberOfDisplays = 0;
|
||||||
|
|
||||||
|
if (null != ADL.ADL_Adapter_NumberOfAdapters_Get)
|
||||||
|
{
|
||||||
|
ADL.ADL_Adapter_NumberOfAdapters_Get(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();
|
||||||
|
|
||||||
|
IntPtr AdapterBuffer = IntPtr.Zero;
|
||||||
|
if (ADL.ADL_Adapter_AdapterInfo_Get != null)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
{
|
||||||
|
// 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++)
|
||||||
|
{
|
||||||
|
// 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 (ADLRet == ADL.ADL_SUCCESS)
|
||||||
|
{
|
||||||
|
// 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}).");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
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
|
||||||
|
//
|
||||||
|
IntPtr AdapterCapabilitiesBuffer = IntPtr.Zero;
|
||||||
|
//ADLAdapterCaps AdapterCapabilities;
|
||||||
|
//ADLAdapterCaps AdapterCapabilities = new ADLAdapterCaps();
|
||||||
|
//AdapterCapabilitiesBuffer = Marshal.AllocCoTaskMem(Marshal.SizeOf(AdapterCapabilities));
|
||||||
|
|
||||||
|
//Marshal.StructureToPtr(OSAdapterInfoData, AdapterBuffer, false);
|
||||||
|
//IntPtr vtablePtr = Marshal.ReadIntPtr(instancePtr, 0);
|
||||||
|
//IntPtr AdapterCapabilitiesBuffer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ADLAdapterCaps)));
|
||||||
|
if (ADL.ADL_Adapter_Caps != null)
|
||||||
|
{
|
||||||
|
ADLRet = ADL.ADL_Adapter_Caps(OSAdapterInfoData.ADLAdapterInfo[i].AdapterIndex, out AdapterCapabilitiesBuffer);
|
||||||
|
}
|
||||||
|
//Marshal.PtrToStructure(AdapterCapabilitiesBuffer, AdapterCapabilities);
|
||||||
|
//ADLAdapterCaps AdapterCapabilities = (ADLAdapterCaps)Marshal.PtrToStructure(AdapterCapabilitiesBuffer, typeof(ADLAdapterCaps));
|
||||||
|
IntPtr AdapterCapabilitiesPtr = Marshal.ReadIntPtr(AdapterCapabilitiesBuffer, 0);
|
||||||
|
ADLAdapterCaps AdapterCapabilities = Marshal.PtrToStructure<ADLAdapterCaps>(AdapterCapabilitiesPtr);
|
||||||
|
|
||||||
|
|
||||||
|
//AdapterCapabilities = (ADLAdapterCaps)Marshal.PtrToStructure(AdapterCapabilitiesBuffer, AdapterCapabilities.GetType());
|
||||||
|
//AdapterCapabilities = (ADLAdapterCaps)Marshal.PtrToStructure(new IntPtr(AdapterCapabilitiesBuffer.ToInt64() + Marshal.SizeOf(AdapterCapabilities)), AdapterCapabilities.GetType());
|
||||||
|
//AdapterCapabilities = (ADLAdapterCaps)Marshal.PtrToStructure(AdapterCapabilitiesBuffer, AdapterCapabilities.GetType());
|
||||||
|
//Marshal.PtrToStructure<ADLAdapterCaps>(AdapterCapabilitiesBuffer, AdapterCapabilities);
|
||||||
|
//Marshal.PtrToStructure(AdapterCapabilitiesBuffer, AdapterCapabilities.GetType());
|
||||||
|
//Marshal.FreeCoTaskMem(AdapterCapabilitiesBuffer);
|
||||||
|
Console.Write(AdapterCapabilities.AdapterID);
|
||||||
|
|
||||||
|
//AdapterCapabilitiesBuffer = Marshal.AllocCoTaskMem(Marshal.SizeOf(AdapterCapabilities)) ;
|
||||||
|
//AdapterCapabilities = (ADLAdapterCaps)Marshal.PtrToStructure(Marshal.SizeOf(AdapterCapabilities), AdapterCapabilities.GetType());
|
||||||
|
|
||||||
|
// Get OS adpater info from ADL
|
||||||
|
//AdapterCapabilitiesData.dw size = Marshal.SizeOf(AdapterCapabilitiesData);
|
||||||
|
//AdapterCapabilities = Marshal.AllocCoTaskMem((int)size);
|
||||||
|
//Marshal.StructureToPtr(AdapterCapabilitiesData, AdapterCapabilities, false);
|
||||||
|
|
||||||
|
//AdapterCapabilitiesData = (ADLAdapterCaps)Marshal.PtrToStructure(AdapterCapabilities, AdapterCapabilitiesData.GetType());
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
{
|
||||||
|
|
||||||
|
List<ADLDisplayInfo> DisplayInfoData = new List<ADLDisplayInfo>();
|
||||||
|
|
||||||
|
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++)
|
||||||
|
{
|
||||||
|
// Skip non connected displays
|
||||||
|
//if ()
|
||||||
|
|
||||||
|
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());
|
||||||
|
|
||||||
|
// Create an array of all the important display info we need to record
|
||||||
|
List<string> displayInfoIdentifier = new List<string>();
|
||||||
|
displayInfoIdentifier.Add("AMD");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
displayInfoIdentifier.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("#");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
displayInfoIdentifier.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("#");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
displayInfoIdentifier.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");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
displayInfoIdentifier.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("#");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Console.WriteLine();
|
||||||
|
}
|
||||||
|
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_Active_Get() returned error code " + ADLRet.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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<string> displayInfo = new List<string>();
|
||||||
|
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<string> GenerateAllAvailableDisplayIdentifiers()
|
||||||
{
|
{
|
||||||
SharedLogger.logger.Trace($"ADLWrapper/GenerateProfileDisplayIdentifiers: Getting AMD active adapter count");
|
SharedLogger.logger.Trace($"ADLWrapper/GenerateProfileDisplayIdentifiers: Getting AMD active adapter count");
|
||||||
|
|
||||||
@ -339,5 +689,6 @@ namespace DisplayMagicianShared.AMD
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -820,7 +820,7 @@ namespace DisplayMagicianShared
|
|||||||
isAMD = true;
|
isAMD = true;
|
||||||
SharedLogger.logger.Debug($"ProfileRepository/GenerateProfileDisplayIdentifiers: The video card is an AMD video card.");
|
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.
|
// 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.GenerateDisplayProfilesIdentifiers();
|
return AMDLibrary.GenerateProfileDisplayIdentifiers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user