From cbdc810606d13f723135f1093145332ea5e59756 Mon Sep 17 00:00:00 2001 From: Terry MacDonald Date: Mon, 20 Sep 2021 18:41:25 +1200 Subject: [PATCH] Updated AMDLibrary from AMDInfo Made some improvements to SetActiveConfig from AMDInfo testing, so ported them back into DisplayMagician. --- DisplayMagicianShared/AMD/ADL.cs | 2 +- DisplayMagicianShared/AMD/AMDLibrary.cs | 44 +++++++++++++++++++++---- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/DisplayMagicianShared/AMD/ADL.cs b/DisplayMagicianShared/AMD/ADL.cs index a42b7e6..0a2c942 100644 --- a/DisplayMagicianShared/AMD/ADL.cs +++ b/DisplayMagicianShared/AMD/ADL.cs @@ -2072,7 +2072,7 @@ namespace DisplayMagicianShared.AMD //typedef int (* ADL2_DISPLAY_SLSMAPCONFIG_CREATE) (ADL_CONTEXT_HANDLE context, int iAdapterIndex, ADLSLSMap SLSMap, int iNumTarget, ADLSLSTarget* lpSLSTarget, int iBezelModePercent, int* lpSLSMapIndex, int iOption); // This function creates an SLS configuration with a given grid, targets, and bezel mode percent. It will output an SLS map index if the SLS map is successfully created. [DllImport(ATI_ADL_DLL, CallingConvention = CallingConvention.Cdecl)] - public static extern ADL_STATUS ADL2_Display_SLSMapConfig_Create(IntPtr ADLContextHandle, int adapterIndex, ADL_SLS_MAP[] SLSMap, int numDisplayTarget, ref ADL_DISPLAY_TARGET[] displayTarget, int bezelModePercent, out int SLSMapIndex, int option); + public static extern ADL_STATUS ADL2_Display_SLSMapConfig_Create(IntPtr ADLContextHandle, int adapterIndex, ADL_SLS_MAP SLSMap, int numDisplayTarget, ADL_DISPLAY_TARGET[] displayTarget, int bezelModePercent, out int SLSMapIndex, int option); //typedef int (* ADL2_DISPLAY_SLSMAPCONFIG_REARRANGE) (ADL_CONTEXT_HANDLE, int, int, int, ADLSLSTarget*, ADLSLSMap, int); [DllImport(ATI_ADL_DLL, CallingConvention = CallingConvention.Cdecl)] diff --git a/DisplayMagicianShared/AMD/AMDLibrary.cs b/DisplayMagicianShared/AMD/AMDLibrary.cs index 0c83117..54a8af9 100644 --- a/DisplayMagicianShared/AMD/AMDLibrary.cs +++ b/DisplayMagicianShared/AMD/AMDLibrary.cs @@ -50,6 +50,7 @@ namespace DisplayMagicianShared.AMD public List BezelModes; public List TransientModes; public List SLSOffsets; + public int BezelModePercent; public override bool Equals(object obj) => obj is AMD_SLS_CONFIG other && this.Equals(other); @@ -60,11 +61,12 @@ namespace DisplayMagicianShared.AMD NativeModeOffsets.SequenceEqual(other.NativeModeOffsets) && BezelModes.SequenceEqual(other.BezelModes) && TransientModes.SequenceEqual(other.TransientModes) && - SLSOffsets.SequenceEqual(other.SLSOffsets); + SLSOffsets.SequenceEqual(other.SLSOffsets) && + BezelModePercent == other.BezelModePercent; public override int GetHashCode() { - return (SLSMap, SLSTargets, NativeModes, NativeModeOffsets, BezelModes, TransientModes, SLSOffsets).GetHashCode(); + return (SLSMap, SLSTargets, NativeModes, NativeModeOffsets, BezelModes, TransientModes, SLSOffsets, BezelModePercent).GetHashCode(); } public static bool operator ==(AMD_SLSMAP_CONFIG lhs, AMD_SLSMAP_CONFIG rhs) => lhs.Equals(rhs); @@ -889,7 +891,7 @@ namespace DisplayMagicianShared.AMD } } - + } // Add the AMD Display Identifiers @@ -1301,7 +1303,7 @@ namespace DisplayMagicianShared.AMD foreach (AMD_SLSMAP_CONFIG slsMapConfig in displayConfig.SlsConfig.SLSMapConfigs) { - // Turn on this SLS Map Config + // Attempt to turn on this SLS Map Config if it exists in the AMD Radeon driver config database ADLRet = ADLImport.ADL2_Display_SLSMapConfig_SetState(_adlContextHandle, slsMapConfig.SLSMap.AdapterIndex, slsMapConfig.SLSMap.SLSMapIndex, ADLImport.ADL_TRUE); if (ADLRet == ADL_STATUS.ADL_OK) { @@ -1310,7 +1312,36 @@ namespace DisplayMagicianShared.AMD else { SharedLogger.logger.Error($"AMDLibrary/SetActiveConfig: ERROR - ADL2_Display_SLSMapConfig_SetState returned ADL_STATUS {ADLRet} when trying to set the SLSMAP with index {slsMapConfig.SLSMap.SLSMapIndex} to TRUE for adapter { slsMapConfig.SLSMap.AdapterIndex}."); - return false; + + // If we get an error with just tturning it on, then we need to actually try to created a new Eyefinity map and then enable it + // If we reach this stage, then the user has discarded the AMD Eyefinity mode in AMD due to a bad UI design, and we need to work around that slight issue. + // (BTW that's FAR to easy to do in the AMD Radeon GUI) + + // Attempt to create am SLS Map Config in the AMD Radeon driver config database + int newSlsMapIndex; + ADL_SLS_TARGET[] slsTargetArray = slsMapConfig.SLSTargets.ToArray(); + ADLRet = ADLImport.ADL2_Display_SLSMapConfig_Create(_adlContextHandle, slsMapConfig.SLSMap.AdapterIndex, slsMapConfig.SLSMap, displayConfig.DisplayTargets.Count, displayConfig.DisplayTargets.ToArray(), slsMapConfig.BezelModePercent, out newSlsMapIndex, ADLImport.ADL_DISPLAY_SLSMAPCONFIG_GET_OPTION_RELATIVETO_CURRENTANGLE); + if (ADLRet == ADL_STATUS.ADL_OK) + { + SharedLogger.logger.Trace($"AMDLibrary/SetActiveConfig: ADL2_Display_SLSMapConfig_Create successfully created a new SLSMAP with index {newSlsMapIndex} for adapter { slsMapConfig.SLSMap.AdapterIndex}."); + } + else + { + SharedLogger.logger.Error($"AMDLibrary/SetActiveConfig: ERROR - ADL2_Display_SLSMapConfig_Create returned ADL_STATUS {ADLRet} when trying to create a new SLSMAP for adapter { slsMapConfig.SLSMap.AdapterIndex}."); + continue; + } + + // If we get here, then we've successfully created the new SLSMAP, so now we need to turn it on. + ADLRet = ADLImport.ADL2_Display_SLSMapConfig_SetState(_adlContextHandle, slsMapConfig.SLSMap.AdapterIndex, newSlsMapIndex, ADLImport.ADL_TRUE); + if (ADLRet == ADL_STATUS.ADL_OK) + { + SharedLogger.logger.Trace($"AMDLibrary/SetActiveConfig: ADL2_Display_SLSMapConfig_SetState successfully enabled the new SLSMAP we just created with index {slsMapConfig.SLSMap.SLSMapIndex} to TRUE for adapter { slsMapConfig.SLSMap.AdapterIndex}."); + } + else + { + SharedLogger.logger.Error($"AMDLibrary/SetActiveConfig: ERROR - ADL2_Display_SLSMapConfig_Create returned ADL_STATUS {ADLRet} when trying to enable the new SLSMAP we just created for adapter { slsMapConfig.SLSMap.AdapterIndex}."); + continue; + } } } @@ -1328,7 +1359,7 @@ namespace DisplayMagicianShared.AMD foreach (AMD_SLSMAP_CONFIG slsMapConfig in currentDisplayConfig.SlsConfig.SLSMapConfigs) { - // Turn on this SLS Map Config + // Turn off this SLS Map Config ADLRet = ADLImport.ADL2_Display_SLSMapConfig_SetState(_adlContextHandle, slsMapConfig.SLSMap.AdapterIndex, slsMapConfig.SLSMap.SLSMapIndex, ADLImport.ADL_FALSE); if (ADLRet == ADL_STATUS.ADL_OK) { @@ -1339,6 +1370,7 @@ namespace DisplayMagicianShared.AMD SharedLogger.logger.Error($"AMDLibrary/SetActiveConfig: ERROR - ADL2_Display_SLSMapConfig_SetState returned ADL_STATUS {ADLRet} when trying to set the SLSMAP with index {slsMapConfig.SLSMap.SLSMapIndex} to FALSE for adapter { slsMapConfig.SLSMap.AdapterIndex}."); return false; } + } }