Updated DM will latest video libraries

Brought over all the latest working code from NVIDIAInfo, AMDInfo and CCDInfo. This includes the new split between the NVIDIA and AMD specific layout, and the NVIDIA and AMD specific color application, so that the video application logic goes like this:
1. Apply NVIDIA Surround or AMD Eyefinity and any 'pre' windows settings
2. Apply the Windows Display Layout
3. Apply the NVIDIA or AMD 'post' windows settings e.g. driver specific color overrides

This new process works.
This commit is contained in:
Terry MacDonald 2021-10-07 21:08:10 +13:00
parent 2c3f3de23d
commit a824f06b33
5 changed files with 352 additions and 56 deletions

View File

@ -160,6 +160,7 @@ namespace DisplayMagicianShared.AMD
private static WinLibrary _winLibrary = new WinLibrary(); private static WinLibrary _winLibrary = new WinLibrary();
private bool _initialised = false; private bool _initialised = false;
private bool _haveActiveDisplayConfig = false;
// To detect redundant calls // To detect redundant calls
private bool _disposed = false; private bool _disposed = false;
@ -167,6 +168,7 @@ namespace DisplayMagicianShared.AMD
// Instantiate a SafeHandle instance. // Instantiate a SafeHandle instance.
private SafeHandle _safeHandle = new SafeFileHandle(IntPtr.Zero, true); private SafeHandle _safeHandle = new SafeFileHandle(IntPtr.Zero, true);
private IntPtr _adlContextHandle = IntPtr.Zero; private IntPtr _adlContextHandle = IntPtr.Zero;
private AMD_DISPLAY_CONFIG _activeDisplayConfig;
static AMDLibrary() { } static AMDLibrary() { }
public AMDLibrary() public AMDLibrary()
@ -209,13 +211,9 @@ namespace DisplayMagicianShared.AMD
catch (DllNotFoundException ex) catch (DllNotFoundException ex)
{ {
// If we get here then the AMD ADL DLL wasn't found. We can't continue to use it, so we log the error and exit // If we get here then the AMD ADL DLL wasn't found. We can't continue to use it, so we log the error and exit
SharedLogger.logger.Info(ex, $"AMDLibrary/AMDLibrary: DLL Not Found Exception trying to load the AMD ADL DLL {ADLImport.ATI_ADL_DLL}. This generally means you don't have the AMD ADL driver installed (which it won't be if you don't have an AMD card)"); SharedLogger.logger.Info(ex, $"AMDLibrary/AMDLibrary: Exception trying to load the AMD ADL DLL {ADLImport.ATI_ADL_DLL}. This generally means you don't have the AMD ADL driver installed.");
}
catch (Exception ex)
{
// If we get here then something else happened
SharedLogger.logger.Info(ex, $"AMDLibrary/AMDLibrary: General Exception trying to load the AMD ADL DLL {ADLImport.ATI_ADL_DLL}. This generally means you don't have the AMD ADL driver installed (which it won't be if you don't have an AMD card)");
} }
} }
~AMDLibrary() ~AMDLibrary()
@ -278,6 +276,23 @@ namespace DisplayMagicianShared.AMD
} }
} }
public AMD_DISPLAY_CONFIG ActiveDisplayConfig
{
get
{
if (!_haveActiveDisplayConfig)
{
_activeDisplayConfig = GetActiveConfig();
_haveActiveDisplayConfig = true;
}
return _activeDisplayConfig;
}
set
{
_activeDisplayConfig = value;
}
}
public static AMDLibrary GetLibrary() public static AMDLibrary GetLibrary()
{ {
return _instance; return _instance;
@ -1298,9 +1313,6 @@ namespace DisplayMagicianShared.AMD
// Set the initial state of the ADL_STATUS // Set the initial state of the ADL_STATUS
ADL_STATUS ADLRet = 0; ADL_STATUS ADLRet = 0;
// We want to get the current config
AMD_DISPLAY_CONFIG currentDisplayConfig = GetAMDDisplayConfig();
// set the display locations // set the display locations
if (displayConfig.SlsConfig.IsSlsEnabled) if (displayConfig.SlsConfig.IsSlsEnabled)
{ {
@ -1371,12 +1383,12 @@ namespace DisplayMagicianShared.AMD
// We need to change to a plain, non-Eyefinity (SLS) profile, so we need to disable any SLS Topologies if they are being used // We need to change to a plain, non-Eyefinity (SLS) profile, so we need to disable any SLS Topologies if they are being used
SharedLogger.logger.Trace($"AMDLibrary/SetActiveConfig: SLS is not used in the new display configuration, so we need to set it to disabled if it's configured currently"); SharedLogger.logger.Trace($"AMDLibrary/SetActiveConfig: SLS is not used in the new display configuration, so we need to set it to disabled if it's configured currently");
if (currentDisplayConfig.SlsConfig.IsSlsEnabled) if (ActiveDisplayConfig.SlsConfig.IsSlsEnabled)
{ {
// We need to disable the current Eyefinity (SLS) profile to turn it off // We need to disable the current Eyefinity (SLS) profile to turn it off
SharedLogger.logger.Trace($"AMDLibrary/SetActiveConfig: SLS is enabled in the current display configuration, so we need to turn it off"); SharedLogger.logger.Trace($"AMDLibrary/SetActiveConfig: SLS is enabled in the current display configuration, so we need to turn it off");
foreach (AMD_SLSMAP_CONFIG slsMapConfig in currentDisplayConfig.SlsConfig.SLSMapConfigs) foreach (AMD_SLSMAP_CONFIG slsMapConfig in ActiveDisplayConfig.SlsConfig.SLSMapConfigs)
{ {
// Turn off 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); ADLRet = ADLImport.ADL2_Display_SLSMapConfig_SetState(_adlContextHandle, slsMapConfig.SLSMap.AdapterIndex, slsMapConfig.SLSMap.SLSMapIndex, ADLImport.ADL_FALSE);
@ -1395,6 +1407,24 @@ namespace DisplayMagicianShared.AMD
} }
}
else
{
SharedLogger.logger.Error($"AMDLibrary/SetActiveConfig: ERROR - Tried to run SetActiveConfig but the AMD ADL library isn't initialised!");
throw new AMDLibraryException($"Tried to run SetActiveConfig but the AMD ADL library isn't initialised!");
}
return true;
}
public bool SetActiveConfigOverride(AMD_DISPLAY_CONFIG displayConfig)
{
if (_initialised)
{
// Set the initial state of the ADL_STATUS
ADL_STATUS ADLRet = 0;
// We want to set the AMD HDR settings now // We want to set the AMD HDR settings now
// We got through each of the attached displays and set the HDR // We got through each of the attached displays and set the HDR
@ -1402,7 +1432,7 @@ namespace DisplayMagicianShared.AMD
foreach (var hdrConfig in displayConfig.HdrConfigs) foreach (var hdrConfig in displayConfig.HdrConfigs)
{ {
// Try and find the HDR config displays in the list of currently connected displays // Try and find the HDR config displays in the list of currently connected displays
foreach (var displayInfoItem in currentDisplayConfig.DisplayTargets) foreach (var displayInfoItem in ActiveDisplayConfig.DisplayTargets)
{ {
// If we find the HDR config display in the list of currently connected displays then try to set the HDR setting we recorded earlier // If we find the HDR config display in the list of currently connected displays then try to set the HDR setting we recorded earlier
if (hdrConfig.Key == displayInfoItem.DisplayID.DisplayLogicalIndex) if (hdrConfig.Key == displayInfoItem.DisplayID.DisplayLogicalIndex)
@ -1436,17 +1466,17 @@ namespace DisplayMagicianShared.AMD
} }
} }
} }
else else
{ {
SharedLogger.logger.Error($"AMDLibrary/SetActiveConfig: ERROR - Tried to run SetActiveConfig but the AMD ADL library isn't initialised!"); SharedLogger.logger.Error($"AMDLibrary/SetActiveConfig: ERROR - Tried to run SetActiveConfigOverride but the AMD ADL library isn't initialised!");
throw new AMDLibraryException($"Tried to run SetActiveConfig but the AMD ADL library isn't initialised!"); throw new AMDLibraryException($"Tried to run SetActiveConfigOverride but the AMD ADL library isn't initialised!");
} }
return true; return true;
} }
public bool IsActiveConfig(AMD_DISPLAY_CONFIG displayConfig) public bool IsActiveConfig(AMD_DISPLAY_CONFIG displayConfig)
{ {
// Get the current windows display configs to compare to the one we loaded // Get the current windows display configs to compare to the one we loaded

View File

@ -472,12 +472,12 @@ namespace DisplayMagicianShared.NVIDIA
{ {
VALID = 0x00000000, //!< The topology is valid VALID = 0x00000000, //!< The topology is valid
MISSING_GPU = 0x00000001, //!< Not enough SLI GPUs were found to fill the entire MISSING_GPU = 0x00000001, //!< Not enough SLI GPUs were found to fill the entire
//! topology. hPhysicalGPU will be 0 for these. //! topology. hPhysicalGPU will be 0 for these.
MISSING_DISPLAY = 0x00000002, //!< Not enough displays were found to fill the entire MISSING_DISPLAY = 0x00000002, //!< Not enough displays were found to fill the entire
//! topology. displayOutputId will be 0 for these. //! topology. displayOutputId will be 0 for these.
MIXED_DISPLAY_TYPES = 0x00000004, //!< The topoogy is only possible with displays of the same MIXED_DISPLAY_TYPES = 0x00000004, //!< The topoogy is only possible with displays of the same
//! NV_GPU_OUTPUT_TYPE. Check displayOutputIds to make //! NV_GPU_OUTPUT_TYPE. Check displayOutputIds to make
//! sure they are all CRTs, or all DFPs. //! sure they are all CRTs, or all DFPs.
} }
public enum NV_GPU_BUS_TYPE : UInt32 public enum NV_GPU_BUS_TYPE : UInt32
@ -525,7 +525,7 @@ namespace DisplayMagicianShared.NVIDIA
} }
public enum NV_COLOR_FORMAT : UInt32 public enum NV_COLOR_FORMAT : byte
{ {
RGB = 0, RGB = 0,
YUV422, YUV422,
@ -536,8 +536,36 @@ namespace DisplayMagicianShared.NVIDIA
AUTO = 0xFF AUTO = 0xFF
} }
public enum NV_DYNAMIC_RANGE : byte
{
VESA = 0x0,
CEA = 0x1,
public enum NV_DYNAMIC_RANGE : UInt32 AUTO = 0xFF
}
public enum NV_BPC : byte
{
BPC_DEFAULT = 0,
BPC_6 = 1,
BPC_8 = 2,
BPC_10 = 3,
BPC_12 = 4,
BPC_16 = 5,
}
public enum NV_HDR_COLOR_FORMAT : UInt32
{
RGB = 0,
YUV422,
YUV444,
YUV420,
DEFAULT = 0xFE,
AUTO = 0xFF
}
public enum NV_HDR_DYNAMIC_RANGE : UInt32
{ {
VESA = 0x0, VESA = 0x0,
CEA = 0x1, CEA = 0x1,
@ -546,14 +574,49 @@ namespace DisplayMagicianShared.NVIDIA
} }
public enum NV_BPC : UInt32 public enum NV_COLOR_CMD : byte
{ {
BPC_DEFAULT = 0, NV_COLOR_CMD_GET = 1,
BPC_6 = 1, NV_COLOR_CMD_SET,
BPC_8 = 2, NV_COLOR_CMD_IS_SUPPORTED_COLOR,
BPC_10 = 3, NV_COLOR_CMD_GET_DEFAULT
BPC_12 = 4, }
BPC_16 = 5,
public enum NV_COLOR_COLORIMETRY : UInt32
{
NV_COLOR_COLORIMETRY_RGB = 0,
NV_COLOR_COLORIMETRY_YCC601,
NV_COLOR_COLORIMETRY_YCC709,
NV_COLOR_COLORIMETRY_XVYCC601,
NV_COLOR_COLORIMETRY_XVYCC709,
NV_COLOR_COLORIMETRY_SYCC601,
NV_COLOR_COLORIMETRY_ADOBEYCC601,
NV_COLOR_COLORIMETRY_ADOBERGB,
NV_COLOR_COLORIMETRY_BT2020RGB,
NV_COLOR_COLORIMETRY_BT2020YCC,
NV_COLOR_COLORIMETRY_BT2020cYCC,
NV_COLOR_COLORIMETRY_DEFAULT = 0xFE,
NV_COLOR_COLORIMETRY_AUTO = 0xFF
}
public enum NV_COLOR_SELECTION_POLICY : UInt32
{
NV_COLOR_SELECTION_POLICY_USER = 0, //!< app/nvcpl make decision to select the desire color format
NV_COLOR_SELECTION_POLICY_BEST_QUALITY = 1, //!< driver/ OS make decision to select the best color format
NV_COLOR_SELECTION_POLICY_DEFAULT = NV_COLOR_SELECTION_POLICY_BEST_QUALITY,
NV_COLOR_SELECTION_POLICY_UNKNOWN = 0xFF,
}
public enum NV_DESKTOP_COLOR_DEPTH
{
NV_DESKTOP_COLOR_DEPTH_DEFAULT = 0x0, // set if the current setting should be kept
NV_DESKTOP_COLOR_DEPTH_8BPC = 0x1, //8 bit int per color component (8 bit int alpha)
NV_DESKTOP_COLOR_DEPTH_10BPC = 0x2, //10 bit int per color component (2 bit int alpha)
NV_DESKTOP_COLOR_DEPTH_16BPC_FLOAT = 0x3, //16 bit float per color component (16 bit float alpha)
NV_DESKTOP_COLOR_DEPTH_16BPC_FLOAT_WCG = 0x4, //16 bit float per color component (16 bit float alpha) wide color gamut
NV_DESKTOP_COLOR_DEPTH_16BPC_FLOAT_HDR = 0x5, //16 bit float per color component (16 bit float alpha) HDR
NV_DESKTOP_COLOR_DEPTH_MAX_VALUE = NV_DESKTOP_COLOR_DEPTH_16BPC_FLOAT_HDR, // must be set to highest enum value
} }
[Flags] [Flags]
@ -1298,12 +1361,12 @@ namespace DisplayMagicianShared.NVIDIA
public bool TopologyValid => ValidityMask == 0; //!< The topology is valid public bool TopologyValid => ValidityMask == 0; //!< The topology is valid
public bool TopologyMissingGPU => ValidityMask.HasFlag(NV_MOSAIC_TOPO_VALIDITY.MISSING_GPU); //!< Not enough SLI GPUs were found to fill the entire public bool TopologyMissingGPU => ValidityMask.HasFlag(NV_MOSAIC_TOPO_VALIDITY.MISSING_GPU); //!< Not enough SLI GPUs were found to fill the entire
//! topology. hPhysicalGPU will be 0 for these. //! topology. hPhysicalGPU will be 0 for these.
public bool TopologyMissingDisplay => ValidityMask.HasFlag(NV_MOSAIC_TOPO_VALIDITY.MISSING_DISPLAY);//!< Not enough displays were found to fill the entire public bool TopologyMissingDisplay => ValidityMask.HasFlag(NV_MOSAIC_TOPO_VALIDITY.MISSING_DISPLAY);//!< Not enough displays were found to fill the entire
//! topology. displayOutputId will be 0 for these. //! topology. displayOutputId will be 0 for these.
public bool TopologyMixedDisplayTypes => ValidityMask.HasFlag(NV_MOSAIC_TOPO_VALIDITY.MIXED_DISPLAY_TYPES);//!< The topoogy is only possible with displays of the same public bool TopologyMixedDisplayTypes => ValidityMask.HasFlag(NV_MOSAIC_TOPO_VALIDITY.MIXED_DISPLAY_TYPES);//!< The topoogy is only possible with displays of the same
//! NV_GPU_OUTPUT_TYPE. Check displayOutputIds to make //! NV_GPU_OUTPUT_TYPE. Check displayOutputIds to make
//! sure they are all CRTs, or all DFPs. //! sure they are all CRTs, or all DFPs.
public override Int32 GetHashCode() public override Int32 GetHashCode()
{ {
@ -1799,8 +1862,8 @@ namespace DisplayMagicianShared.NVIDIA
public NV_HDR_MODE HdrMode; //!< HDR mode public NV_HDR_MODE HdrMode; //!< HDR mode
public NV_STATIC_METADATA_DESCRIPTOR_ID StaticMetadataDescriptorId; //!< Static Metadata Descriptor Id (0 for static metadata type 1) public NV_STATIC_METADATA_DESCRIPTOR_ID StaticMetadataDescriptorId; //!< Static Metadata Descriptor Id (0 for static metadata type 1)
public NV_HDR_COLOR_DISPLAY_DATA MasteringDisplayData; //!< Static Metadata Descriptor Type 1, CEA-861.3, SMPTE ST2086 public NV_HDR_COLOR_DISPLAY_DATA MasteringDisplayData; //!< Static Metadata Descriptor Type 1, CEA-861.3, SMPTE ST2086
public NV_COLOR_FORMAT HdrColorFormat; //!< Optional, One of NV_COLOR_FORMAT enum values, if set it will apply requested color format for HDR session public NV_HDR_COLOR_FORMAT HdrColorFormat; //!< Optional, One of NV_COLOR_FORMAT enum values, if set it will apply requested color format for HDR session
public NV_DYNAMIC_RANGE HdrDynamicRange; //!< Optional, One of NV_DYNAMIC_RANGE enum values, if set it will apply requested dynamic range for HDR session public NV_HDR_DYNAMIC_RANGE HdrDynamicRange; //!< Optional, One of NV_DYNAMIC_RANGE enum values, if set it will apply requested dynamic range for HDR session
public NV_BPC HdrBpc; //!< Optional, One of NV_BPC enum values, if set it will apply requested color depth public NV_BPC HdrBpc; //!< Optional, One of NV_BPC enum values, if set it will apply requested color depth
//!< Dolby Vision mode: DV supports specific combinations of colorformat, dynamic range and bpc. Please refer Dolby Vision specification. //!< Dolby Vision mode: DV supports specific combinations of colorformat, dynamic range and bpc. Please refer Dolby Vision specification.
//!< If invalid or no combination is passed driver will force default combination of RGB format + full range + 8bpc. //!< If invalid or no combination is passed driver will force default combination of RGB format + full range + 8bpc.
@ -1867,6 +1930,40 @@ namespace DisplayMagicianShared.NVIDIA
public static bool operator !=(NV_HDR_COLOR_DISPLAY_DATA lhs, NV_HDR_COLOR_DISPLAY_DATA rhs) => !(lhs == rhs); public static bool operator !=(NV_HDR_COLOR_DISPLAY_DATA lhs, NV_HDR_COLOR_DISPLAY_DATA rhs) => !(lhs == rhs);
} }
[StructLayout(LayoutKind.Sequential, Pack = 8)]
public struct NV_COLOR_DATA_V5 : IEquatable<NV_COLOR_DATA_V5>
{
public UInt32 Version; //!< Version of this structure
public UInt16 Size; //!< Size of this structure
public NV_COLOR_CMD Cmd;
public NV_COLOR_FORMAT ColorFormat; //!< One of NV_COLOR_FORMAT enum values.
public NV_COLOR_COLORIMETRY Colorimetry; //!< One of NV_COLOR_COLORIMETRY enum values.
public NV_DYNAMIC_RANGE DynamicRange; //!< One of NV_DYNAMIC_RANGE enum values.
public NV_BPC Bpc; //!< One of NV_BPC enum values.
public NV_COLOR_SELECTION_POLICY ColorSelectionPolicy; //!< One of the color selection policy
public NV_DESKTOP_COLOR_DEPTH Depth; //!< One of NV_DESKTOP_COLOR_DEPTH enum values.
public override bool Equals(object obj) => obj is NV_COLOR_DATA_V5 other && this.Equals(other);
public bool Equals(NV_COLOR_DATA_V5 other)
=> Version == other.Version &&
Size == other.Size &&
Cmd == other.Cmd &&
ColorFormat == other.ColorFormat &&
Colorimetry == other.Colorimetry &&
DynamicRange == other.DynamicRange &&
Bpc == other.Bpc &&
ColorSelectionPolicy == other.ColorSelectionPolicy &&
Depth == other.Depth;
public override Int32 GetHashCode()
{
return (Version, Size, Cmd, ColorFormat, Colorimetry, DynamicRange, Bpc, ColorSelectionPolicy, Depth).GetHashCode();
}
public static bool operator ==(NV_COLOR_DATA_V5 lhs, NV_COLOR_DATA_V5 rhs) => lhs.Equals(rhs);
public static bool operator !=(NV_COLOR_DATA_V5 lhs, NV_COLOR_DATA_V5 rhs) => !(lhs == rhs);
}
// ================================== // ==================================
// NVImport Class // NVImport Class
// ================================== // ==================================
@ -1938,6 +2035,7 @@ namespace DisplayMagicianShared.NVIDIA
public static UInt32 NV_MOSAIC_SUPPORTED_TOPO_INFO_V1_VER = MAKE_NVAPI_VERSION<NV_MOSAIC_SUPPORTED_TOPO_INFO_V1>(1); public static UInt32 NV_MOSAIC_SUPPORTED_TOPO_INFO_V1_VER = MAKE_NVAPI_VERSION<NV_MOSAIC_SUPPORTED_TOPO_INFO_V1>(1);
public static UInt32 NV_MOSAIC_SUPPORTED_TOPO_INFO_V2_VER = MAKE_NVAPI_VERSION<NV_MOSAIC_SUPPORTED_TOPO_INFO_V2>(2); public static UInt32 NV_MOSAIC_SUPPORTED_TOPO_INFO_V2_VER = MAKE_NVAPI_VERSION<NV_MOSAIC_SUPPORTED_TOPO_INFO_V2>(2);
public static UInt32 NV_HDR_COLOR_DATA_V2_VER = MAKE_NVAPI_VERSION<NV_HDR_COLOR_DATA_V2>(2); public static UInt32 NV_HDR_COLOR_DATA_V2_VER = MAKE_NVAPI_VERSION<NV_HDR_COLOR_DATA_V2>(2);
public static UInt32 NV_COLOR_DATA_V5_VER = MAKE_NVAPI_VERSION<NV_COLOR_DATA_V5>(5);
public static UInt32 NV_HDR_CAPABILITIES_V2_VER = MAKE_NVAPI_VERSION<NV_HDR_CAPABILITIES_V2>(2); public static UInt32 NV_HDR_CAPABILITIES_V2_VER = MAKE_NVAPI_VERSION<NV_HDR_CAPABILITIES_V2>(2);
public static UInt32 NV_MOSAIC_DISPLAY_TOPO_STATUS_V1_VER = MAKE_NVAPI_VERSION<NV_MOSAIC_DISPLAY_TOPO_STATUS_V1>(1); public static UInt32 NV_MOSAIC_DISPLAY_TOPO_STATUS_V1_VER = MAKE_NVAPI_VERSION<NV_MOSAIC_DISPLAY_TOPO_STATUS_V1>(1);
public static UInt32 NV_GPU_DISPLAYIDS_V2_VER = MAKE_NVAPI_VERSION<NV_GPU_DISPLAYIDS_V2>(3); // NOTE: There is a bug in R470 that sets the NV_GPU_DISPLAYIDS_V2 version to 3! public static UInt32 NV_GPU_DISPLAYIDS_V2_VER = MAKE_NVAPI_VERSION<NV_GPU_DISPLAYIDS_V2>(3); // NOTE: There is a bug in R470 that sets the NV_GPU_DISPLAYIDS_V2 version to 3!
@ -2078,6 +2176,7 @@ namespace DisplayMagicianShared.NVIDIA
GetDelegate(NvId_DISP_GetGDIPrimaryDisplayId, out DISP_GetGDIPrimaryDisplayIdInternal); GetDelegate(NvId_DISP_GetGDIPrimaryDisplayId, out DISP_GetGDIPrimaryDisplayIdInternal);
GetDelegate(NvId_Disp_GetHdrCapabilities, out Disp_GetHdrCapabilitiesInternal); GetDelegate(NvId_Disp_GetHdrCapabilities, out Disp_GetHdrCapabilitiesInternal);
GetDelegate(NvId_Disp_HdrColorControl, out Disp_HdrColorControlInternal); GetDelegate(NvId_Disp_HdrColorControl, out Disp_HdrColorControlInternal);
GetDelegate(NvId_Disp_ColorControl, out Disp_ColorControlInternal);
/*GetDelegate(NvId_DISP_GetDisplayConfig, out DISP_GetDisplayConfigInternal); /*GetDelegate(NvId_DISP_GetDisplayConfig, out DISP_GetDisplayConfigInternal);
GetDelegate(NvId_DISP_GetDisplayConfig, out DISP_GetDisplayConfigInternalNull); // null version of the submission*/ GetDelegate(NvId_DISP_GetDisplayConfig, out DISP_GetDisplayConfigInternalNull); // null version of the submission*/
GetDelegate(NvId_DISP_GetDisplayIdByDisplayName, out DISP_GetDisplayIdByDisplayNameInternal); GetDelegate(NvId_DISP_GetDisplayIdByDisplayName, out DISP_GetDisplayIdByDisplayNameInternal);
@ -4017,6 +4116,26 @@ namespace DisplayMagicianShared.NVIDIA
return status; return status;
} }
//NVAPI_INTERFACE NvAPI_Disp_ColorControl(__in NvU32 displayId, __inout NV_HDR_COLOR_DATA *pHdrColorData);
private delegate NVAPI_STATUS Disp_ColorControlDelegate(
[In] UInt32 displayId,
[In][Out] ref NV_COLOR_DATA_V5 colorData);
private static readonly Disp_ColorControlDelegate Disp_ColorControlInternal;
/// <summary>
//! This API gets and sets the color capabilities of the display.
/// <param name="displayId"></param>
/// <param name="colorData"></param>
/// <returns></returns>
public static NVAPI_STATUS NvAPI_Disp_ColorControl(UInt32 displayId, ref NV_COLOR_DATA_V5 colorData)
{
NVAPI_STATUS status;
colorData.Version = NVImport.NV_COLOR_DATA_V5_VER;
if (Disp_ColorControlInternal != null) { status = Disp_ColorControlInternal(displayId, ref colorData); }
else { status = NVAPI_STATUS.NVAPI_FUNCTION_NOT_FOUND; }
return status;
}
//NVAPI_INTERFACE NvAPI_GPU_GetFullName(NvPhysicalGpuHandle hPhysicalGpu, NvAPI_ShortString szName); //NVAPI_INTERFACE NvAPI_GPU_GetFullName(NvPhysicalGpuHandle hPhysicalGpu, NvAPI_ShortString szName);
private delegate NVAPI_STATUS GPU_GetFullNameDelegate( private delegate NVAPI_STATUS GPU_GetFullNameDelegate(
[In] PhysicalGpuHandle gpuHandle, [In] PhysicalGpuHandle gpuHandle,

View File

@ -70,6 +70,24 @@ namespace DisplayMagicianShared.NVIDIA
public static bool operator !=(NVIDIA_HDR_CONFIG lhs, NVIDIA_HDR_CONFIG rhs) => !(lhs == rhs); public static bool operator !=(NVIDIA_HDR_CONFIG lhs, NVIDIA_HDR_CONFIG rhs) => !(lhs == rhs);
} }
[StructLayout(LayoutKind.Sequential)]
public struct NVIDIA_COLOR_CONFIG : IEquatable<NVIDIA_COLOR_CONFIG>
{
public Dictionary<UInt32, NV_COLOR_DATA_V5> ColorData;
public override bool Equals(object obj) => obj is NVIDIA_COLOR_CONFIG other && this.Equals(other);
public bool Equals(NVIDIA_COLOR_CONFIG other)
=> ColorData.SequenceEqual(other.ColorData);
public override int GetHashCode()
{
return (ColorData).GetHashCode();
}
public static bool operator ==(NVIDIA_COLOR_CONFIG lhs, NVIDIA_COLOR_CONFIG rhs) => lhs.Equals(rhs);
public static bool operator !=(NVIDIA_COLOR_CONFIG lhs, NVIDIA_COLOR_CONFIG rhs) => !(lhs == rhs);
}
/*[StructLayout(LayoutKind.Sequential)] /*[StructLayout(LayoutKind.Sequential)]
public struct NVIDIA_WINDOWS_DISPLAY_CONFIG : IEquatable<NVIDIA_WINDOWS_DISPLAY_CONFIG> public struct NVIDIA_WINDOWS_DISPLAY_CONFIG : IEquatable<NVIDIA_WINDOWS_DISPLAY_CONFIG>
{ {
@ -94,6 +112,7 @@ namespace DisplayMagicianShared.NVIDIA
{ {
public NVIDIA_MOSAIC_CONFIG MosaicConfig; public NVIDIA_MOSAIC_CONFIG MosaicConfig;
public NVIDIA_HDR_CONFIG HdrConfig; public NVIDIA_HDR_CONFIG HdrConfig;
public NVIDIA_COLOR_CONFIG ColorConfig;
// Note: We purposely have left out the DisplayNames from the Equals as it's order keeps changing after each reboot and after each profile swap // Note: We purposely have left out the DisplayNames from the Equals as it's order keeps changing after each reboot and after each profile swap
// and it is informational only and doesn't contribute to the configuration (it's used for generating the Screens structure, and therefore for // and it is informational only and doesn't contribute to the configuration (it's used for generating the Screens structure, and therefore for
// generating the profile icon. // generating the profile icon.
@ -105,6 +124,7 @@ namespace DisplayMagicianShared.NVIDIA
public bool Equals(NVIDIA_DISPLAY_CONFIG other) public bool Equals(NVIDIA_DISPLAY_CONFIG other)
=> MosaicConfig.Equals(other.MosaicConfig) && => MosaicConfig.Equals(other.MosaicConfig) &&
HdrConfig.Equals(other.HdrConfig) && HdrConfig.Equals(other.HdrConfig) &&
ColorConfig.Equals(other.ColorConfig) &&
DisplayIdentifiers.SequenceEqual(other.DisplayIdentifiers); DisplayIdentifiers.SequenceEqual(other.DisplayIdentifiers);
public override int GetHashCode() public override int GetHashCode()
@ -128,6 +148,7 @@ namespace DisplayMagicianShared.NVIDIA
private bool _initialised = false; private bool _initialised = false;
private bool _haveSessionHandle = false; private bool _haveSessionHandle = false;
private bool _haveActiveDisplayConfig = false;
// To detect redundant calls // To detect redundant calls
private bool _disposed = false; private bool _disposed = false;
@ -135,6 +156,7 @@ namespace DisplayMagicianShared.NVIDIA
// Instantiate a SafeHandle instance. // Instantiate a SafeHandle instance.
private SafeHandle _safeHandle = new SafeFileHandle(IntPtr.Zero, true); private SafeHandle _safeHandle = new SafeFileHandle(IntPtr.Zero, true);
private IntPtr _nvapiSessionHandle = IntPtr.Zero; private IntPtr _nvapiSessionHandle = IntPtr.Zero;
private NVIDIA_DISPLAY_CONFIG _activeDisplayConfig;
static NVIDIALibrary() { } static NVIDIALibrary() { }
public NVIDIALibrary() public NVIDIALibrary()
@ -193,12 +215,7 @@ namespace DisplayMagicianShared.NVIDIA
catch (DllNotFoundException ex) catch (DllNotFoundException ex)
{ {
// If this fires, then the DLL isn't available, so we need don't try to do anything else // If this fires, then the DLL isn't available, so we need don't try to do anything else
SharedLogger.logger.Info(ex, $"NVIDIALibrary/NVIDIALibrary: Exception trying to load the NVIDIA NVAPI DLL. This generally means you don't have the NVIDIA driver installed (which it won't be if you don't have an NVIDIA card)."); SharedLogger.logger.Info(ex, $"NVIDIALibrary/NVIDIALibrary: Exception trying to load the NVIDIA NVAPI DLL. This generally means you don't have the NVIDIA driver installed.");
}
catch (Exception ex)
{
// If we get here then another problem happened
SharedLogger.logger.Info(ex, $"NVIDIALibrary/NVIDIALibrary: General Exception trying to load the NVAPI DLL. This generally means you don't have the NVIDIA NVAPI driver installed (which it won't be if you don't have an NVIDIA card)");
} }
} }
@ -285,6 +302,23 @@ namespace DisplayMagicianShared.NVIDIA
} }
} }
public NVIDIA_DISPLAY_CONFIG ActiveDisplayConfig
{
get
{
if (!_haveActiveDisplayConfig)
{
_activeDisplayConfig = GetActiveConfig();
_haveActiveDisplayConfig = true;
}
return _activeDisplayConfig;
}
set
{
_activeDisplayConfig = value;
}
}
public static NVIDIALibrary GetLibrary() public static NVIDIALibrary GetLibrary()
{ {
@ -302,6 +336,7 @@ namespace DisplayMagicianShared.NVIDIA
myDefaultConfig.MosaicConfig.MosaicViewports = new List<NV_RECT[]>(); myDefaultConfig.MosaicConfig.MosaicViewports = new List<NV_RECT[]>();
myDefaultConfig.HdrConfig.HdrCapabilities = new Dictionary<uint, NV_HDR_CAPABILITIES_V2>(); myDefaultConfig.HdrConfig.HdrCapabilities = new Dictionary<uint, NV_HDR_CAPABILITIES_V2>();
myDefaultConfig.HdrConfig.HdrColorData = new Dictionary<uint, NV_HDR_COLOR_DATA_V2>(); myDefaultConfig.HdrConfig.HdrColorData = new Dictionary<uint, NV_HDR_COLOR_DATA_V2>();
myDefaultConfig.ColorConfig.ColorData = new Dictionary<uint, NV_COLOR_DATA_V5>();
myDefaultConfig.DisplayNames = new Dictionary<uint, string>(); myDefaultConfig.DisplayNames = new Dictionary<uint, string>();
myDefaultConfig.DisplayIdentifiers = new List<string>(); myDefaultConfig.DisplayIdentifiers = new List<string>();
@ -658,10 +693,11 @@ namespace DisplayMagicianShared.NVIDIA
} }
// Time to get the HDR capabilities and settings for each display // Time to get the color settings, HDR capabilities and settings for each display
bool isNvHdrEnabled = false; bool isNvHdrEnabled = false;
Dictionary<UInt32, NV_HDR_CAPABILITIES_V2> allHdrCapabilities = new Dictionary<UInt32, NV_HDR_CAPABILITIES_V2>(); Dictionary<UInt32, NV_HDR_CAPABILITIES_V2> allHdrCapabilities = new Dictionary<UInt32, NV_HDR_CAPABILITIES_V2>();
Dictionary<UInt32, NV_HDR_COLOR_DATA_V2> allHdrColorData = new Dictionary<UInt32, NV_HDR_COLOR_DATA_V2>(); Dictionary<UInt32, NV_HDR_COLOR_DATA_V2> allHdrColorData = new Dictionary<UInt32, NV_HDR_COLOR_DATA_V2>();
Dictionary<UInt32, NV_COLOR_DATA_V5> allColorData = new Dictionary<UInt32, NV_COLOR_DATA_V5>();
for (int displayIndex = 0; displayIndex < displayCount; displayIndex++) for (int displayIndex = 0; displayIndex < displayCount; displayIndex++)
{ {
if (allDisplays) if (allDisplays)
@ -681,7 +717,50 @@ namespace DisplayMagicianShared.NVIDIA
} }
} }
// If we've already got the details from the display, then skip it now
if (allColorData.ContainsKey(displayIds[displayIndex].DisplayId))
{
continue;
}
// We get the Color Capabilities of the display
NV_COLOR_DATA_V5 colorData = new NV_COLOR_DATA_V5();
// Set the command as a 'GET'
colorData.Cmd = NV_COLOR_CMD.NV_COLOR_CMD_GET;
NVStatus = NVImport.NvAPI_Disp_ColorControl(displayIds[displayIndex].DisplayId, ref colorData);
if (NVStatus == NVAPI_STATUS.NVAPI_OK)
{
SharedLogger.logger.Warn($"NVIDIALibrary/SetActiveConfig: Your monitor {displayIds[displayIndex].DisplayId} has the following color settings set. BPC = {colorData.Bpc.ToString("G")}. Color Format = {colorData.ColorFormat.ToString("G")}. Colorimetry = {colorData.Colorimetry.ToString("G")}. Color Selection Policy = {colorData.ColorSelectionPolicy.ToString("G")}. Color Depth = {colorData.Depth.ToString("G")}. Dynamic Range = {colorData.DynamicRange.ToString("G")}. NvAPI_Disp_ColorControl() returned error code {NVStatus}");
allColorData.Add(displayIds[displayIndex].DisplayId, colorData);
}
else if (NVStatus == NVAPI_STATUS.NVAPI_INSUFFICIENT_BUFFER)
{
SharedLogger.logger.Warn($"NVIDIALibrary/GetNVIDIADisplayConfig: The input buffer is not large enough to hold it's contents. NvAPI_Disp_ColorControl() returned error code {NVStatus}");
}
else if (NVStatus == NVAPI_STATUS.NVAPI_INVALID_DISPLAY_ID)
{
SharedLogger.logger.Warn($"NVIDIALibrary/GetNVIDIADisplayConfig: The input monitor is either not connected or is not a DP or HDMI panel. NvAPI_Disp_ColorControl() returned error code {NVStatus}");
}
else if (NVStatus == NVAPI_STATUS.NVAPI_API_NOT_INITIALIZED)
{
SharedLogger.logger.Warn($"NVIDIALibrary/GetNVIDIADisplayConfig: The NvAPI API needs to be initialized first. NvAPI_Disp_ColorControl() returned error code {NVStatus}");
}
else if (NVStatus == NVAPI_STATUS.NVAPI_NO_IMPLEMENTATION)
{
SharedLogger.logger.Warn($"NVIDIALibrary/GetNVIDIADisplayConfig: This entry point not available in this NVIDIA Driver. NvAPI_Disp_ColorControl() returned error code {NVStatus}");
}
else if (NVStatus == NVAPI_STATUS.NVAPI_NOT_SUPPORTED)
{
SharedLogger.logger.Warn($"NVIDIALibrary/GetNVIDIADisplayConfig: This entry point not available in this NVIDIA Driver. NvAPI_Disp_ColorControl() returned error code {NVStatus}");
}
else if (NVStatus == NVAPI_STATUS.NVAPI_ERROR)
{
SharedLogger.logger.Warn($"NVIDIALibrary/GetNVIDIADisplayConfig: A miscellaneous error occurred. NvAPI_Disp_ColorControl() returned error code {NVStatus}.");
}
else
{
SharedLogger.logger.Trace($"NVIDIALibrary/GetNVIDIADisplayConfig: Some non standard error occurred while getting HDR color settings! NvAPI_Disp_ColorControl() returned error code {NVStatus}. It's most likely that your monitor {displayIds[displayIndex].DisplayId} doesn't support HDR.");
}
// Now we get the HDR capabilities of the display // Now we get the HDR capabilities of the display
NV_HDR_CAPABILITIES_V2 hdrCapabilities = new NV_HDR_CAPABILITIES_V2(); NV_HDR_CAPABILITIES_V2 hdrCapabilities = new NV_HDR_CAPABILITIES_V2();
@ -768,10 +847,11 @@ namespace DisplayMagicianShared.NVIDIA
// Now we get the HDR colour settings of the display // Now we get the HDR colour settings of the display
NV_HDR_COLOR_DATA_V2 hdrColorData = new NV_HDR_COLOR_DATA_V2(); NV_HDR_COLOR_DATA_V2 hdrColorData = new NV_HDR_COLOR_DATA_V2();
hdrColorData.Cmd = NV_HDR_CMD.CMD_GET;
NVStatus = NVImport.NvAPI_Disp_HdrColorControl(displayIds[displayIndex].DisplayId, ref hdrColorData); NVStatus = NVImport.NvAPI_Disp_HdrColorControl(displayIds[displayIndex].DisplayId, ref hdrColorData);
if (NVStatus == NVAPI_STATUS.NVAPI_OK) if (NVStatus == NVAPI_STATUS.NVAPI_OK)
{ {
SharedLogger.logger.Trace($"NVIDIALibrary/GetNVIDIADisplayConfig: NvAPI_Disp_HdrColorControl returned OK. HDR mode is currently {hdrColorData.HdrMode.ToString("G")}."); SharedLogger.logger.Trace($"NVIDIALibrary/GetNVIDIADisplayConfig: NvAPI_Disp_HdrColorControl returned OK. HDR mode is set to {hdrColorData.HdrMode.ToString("G")}.");
if (hdrColorData.HdrMode != NV_HDR_MODE.OFF) if (hdrColorData.HdrMode != NV_HDR_MODE.OFF)
{ {
isNvHdrEnabled = true; isNvHdrEnabled = true;
@ -808,6 +888,7 @@ namespace DisplayMagicianShared.NVIDIA
myDisplayConfig.HdrConfig.IsNvHdrEnabled = isNvHdrEnabled; myDisplayConfig.HdrConfig.IsNvHdrEnabled = isNvHdrEnabled;
myDisplayConfig.HdrConfig.HdrCapabilities = allHdrCapabilities; myDisplayConfig.HdrConfig.HdrCapabilities = allHdrCapabilities;
myDisplayConfig.HdrConfig.HdrColorData = allHdrColorData; myDisplayConfig.HdrConfig.HdrColorData = allHdrColorData;
myDisplayConfig.ColorConfig.ColorData = allColorData;
} }
@ -1065,6 +1146,19 @@ namespace DisplayMagicianShared.NVIDIA
} }
// Start printing out things // Start printing out things
stringToReturn += $"\n****** NVIDIA COLOR CONFIG *******\n";
foreach (KeyValuePair<uint, NV_COLOR_DATA_V5> colorData in displayConfig.ColorConfig.ColorData)
{
string displayId = colorData.Key.ToString();
stringToReturn += $"Display {displayId} BPC is {colorData.Value.Bpc.ToString("G")}.\n";
stringToReturn += $"Display {displayId} ColorFormat is {colorData.Value.ColorFormat.ToString("G")}.\n";
stringToReturn += $"Display {displayId} Colorimetry is {colorData.Value.Colorimetry.ToString("G")}.\n";
stringToReturn += $"Display {displayId} ColorSelectionPolicy is {colorData.Value.ColorSelectionPolicy.ToString("G")}.\n";
stringToReturn += $"Display {displayId} Depth is {colorData.Value.Depth.ToString("G")}.\n";
stringToReturn += $"Display {displayId} DynamicRange is {colorData.Value.DynamicRange.ToString("G")}.\n";
}
// Start printing out HDR things
stringToReturn += $"\n****** NVIDIA HDR CONFIG *******\n"; stringToReturn += $"\n****** NVIDIA HDR CONFIG *******\n";
if (displayConfig.HdrConfig.IsNvHdrEnabled) if (displayConfig.HdrConfig.IsNvHdrEnabled)
{ {
@ -1146,8 +1240,6 @@ namespace DisplayMagicianShared.NVIDIA
{ {
NVAPI_STATUS NVStatus = NVAPI_STATUS.NVAPI_ERROR; NVAPI_STATUS NVStatus = NVAPI_STATUS.NVAPI_ERROR;
// We want to get the current config
NVIDIA_DISPLAY_CONFIG currentDisplayConfig = GetNVIDIADisplayConfig();
// We want to check the NVIDIA Surround (Mosaic) config is valid // We want to check the NVIDIA Surround (Mosaic) config is valid
SharedLogger.logger.Trace($"NVIDIALibrary/SetActiveConfig: Testing whether the display configuration is valid"); SharedLogger.logger.Trace($"NVIDIALibrary/SetActiveConfig: Testing whether the display configuration is valid");
@ -1206,7 +1298,7 @@ namespace DisplayMagicianShared.NVIDIA
} }
} }
else if (!displayConfig.MosaicConfig.IsMosaicEnabled && currentDisplayConfig.MosaicConfig.IsMosaicEnabled) else if (!displayConfig.MosaicConfig.IsMosaicEnabled && ActiveDisplayConfig.MosaicConfig.IsMosaicEnabled)
{ {
// We are on a Mosaic profile now, and we need to change to a non-Mosaic profile // We are on a Mosaic profile now, and we need to change to a non-Mosaic profile
// We need to disable the Mosaic Topology // We need to disable the Mosaic Topology
@ -1257,21 +1349,31 @@ namespace DisplayMagicianShared.NVIDIA
SharedLogger.logger.Trace($"NVIDIALibrary/SetActiveConfig: Some non standard error occurred while getting Mosaic Topology! NvAPI_Mosaic_EnableCurrentTopo() returned error code {NVStatus}"); SharedLogger.logger.Trace($"NVIDIALibrary/SetActiveConfig: Some non standard error occurred while getting Mosaic Topology! NvAPI_Mosaic_EnableCurrentTopo() returned error code {NVStatus}");
} }
} }
else if (!displayConfig.MosaicConfig.IsMosaicEnabled && !currentDisplayConfig.MosaicConfig.IsMosaicEnabled) else if (!displayConfig.MosaicConfig.IsMosaicEnabled && !ActiveDisplayConfig.MosaicConfig.IsMosaicEnabled)
{ {
// We are on a non-Mosaic profile now, and we are changing to a non-Mosaic profile // We are on a non-Mosaic profile now, and we are changing to a non-Mosaic profile
// so there is nothing to do as far as NVIDIA is concerned! // so there is nothing to do as far as NVIDIA is concerned!
SharedLogger.logger.Trace($"NVIDIALibrary/SetActiveConfig: We are on a non-Mosaic profile now, and we are changing to a non-Mosaic profile so there is nothing to do as far as NVIDIA is concerned!"); SharedLogger.logger.Trace($"NVIDIALibrary/SetActiveConfig: We are on a non-Mosaic profile now, and we are changing to a non-Mosaic profile so there is nothing to do as far as NVIDIA is concerned!");
} }
SharedLogger.logger.Trace($"NVIDIALibrary/SetActiveConfig: Waiting 0.5 seconds to let the display change take place before adjusting the NVIDIA HDR settings"); }
System.Threading.Thread.Sleep(500); return true;
}
public bool SetActiveConfigOverride(NVIDIA_DISPLAY_CONFIG displayConfig)
{
if (_initialised)
{
NVAPI_STATUS NVStatus = NVAPI_STATUS.NVAPI_ERROR;
// Now, we have the current HDR settings, and the existing HDR settings, so we go through and we attempt to set each display color settings // Now, we have the current HDR settings, and the existing HDR settings, so we go through and we attempt to set each display color settings
foreach (var wantedHdrColorData in displayConfig.HdrConfig.HdrColorData) foreach (var wantedHdrColorData in displayConfig.HdrConfig.HdrColorData)
{ {
// Now we set the HDR colour settings of the display // Now we set the HDR colour settings of the display
NV_HDR_COLOR_DATA_V2 hdrColorData = wantedHdrColorData.Value; NV_HDR_COLOR_DATA_V2 hdrColorData = wantedHdrColorData.Value;
hdrColorData.Cmd = NV_HDR_CMD.CMD_SET;
NVStatus = NVImport.NvAPI_Disp_HdrColorControl(wantedHdrColorData.Key, ref hdrColorData); NVStatus = NVImport.NvAPI_Disp_HdrColorControl(wantedHdrColorData.Key, ref hdrColorData);
if (NVStatus == NVAPI_STATUS.NVAPI_OK) if (NVStatus == NVAPI_STATUS.NVAPI_OK)
{ {
@ -1303,6 +1405,51 @@ namespace DisplayMagicianShared.NVIDIA
} }
} }
//SharedLogger.logger.Trace($"NVIDIALibrary/SetActiveConfig: Waiting 0.5 seconds to let the display change take place before adjusting the NVIDIA HDR settings");
//System.Threading.Thread.Sleep(500);
// Now, we have the current color settings to set, so we go through and we attempt to set each display color settings
foreach (var wantedColorData in displayConfig.ColorConfig.ColorData)
{
// Now we set the colour settings of the display (non-HDR settings)
NV_COLOR_DATA_V5 colorData = wantedColorData.Value;
// Set the command as a 'SET'
colorData.Cmd = NV_COLOR_CMD.NV_COLOR_CMD_SET;
NVStatus = NVImport.NvAPI_Disp_ColorControl(wantedColorData.Key, ref colorData);
if (NVStatus == NVAPI_STATUS.NVAPI_OK)
{
SharedLogger.logger.Trace($"NVIDIALibrary/GetNVIDIADisplayConfig: NvAPI_Disp_ColorControl returned OK. BPC is set to {colorData.Bpc.ToString("G")}. Color Format is set to {colorData.ColorFormat.ToString("G")}. Colorimetry is set to {colorData.Colorimetry.ToString("G")}. Color Selection Policy is set to {colorData.ColorSelectionPolicy.ToString("G")}. Color Depth is set to {colorData.Depth.ToString("G")}. Dynamic Range is set to {colorData.DynamicRange.ToString("G")}");
}
else if (NVStatus == NVAPI_STATUS.NVAPI_NOT_SUPPORTED)
{
SharedLogger.logger.Warn($"NVIDIALibrary/SetActiveConfig: Your monitor {wantedColorData.Key} doesn't support the requested color settings. BPC = {colorData.Bpc.ToString("G")}. Color Format = {colorData.ColorFormat.ToString("G")}. Colorimetry = {colorData.Colorimetry.ToString("G")}. Color Selection Policy = {colorData.ColorSelectionPolicy.ToString("G")}. Color Depth = {colorData.Depth.ToString("G")}. Dynamic Range = {colorData.DynamicRange.ToString("G")}. NvAPI_Disp_ColorControl() returned error code {NVStatus}");
}
else if (NVStatus == NVAPI_STATUS.NVAPI_INSUFFICIENT_BUFFER)
{
SharedLogger.logger.Warn($"NVIDIALibrary/SetActiveConfig: The input buffer is not large enough to hold it's contents. NvAPI_Disp_ColorControl() returned error code {NVStatus}");
}
else if (NVStatus == NVAPI_STATUS.NVAPI_INVALID_DISPLAY_ID)
{
SharedLogger.logger.Warn($"NVIDIALibrary/SetActiveConfig: The input monitor is either not connected or is not a DP or HDMI panel. NvAPI_Disp_ColorControl() returned error code {NVStatus}");
}
else if (NVStatus == NVAPI_STATUS.NVAPI_API_NOT_INITIALIZED)
{
SharedLogger.logger.Warn($"NVIDIALibrary/SetActiveConfig: The NvAPI API needs to be initialized first. NvAPI_Disp_ColorControl() returned error code {NVStatus}");
}
else if (NVStatus == NVAPI_STATUS.NVAPI_NO_IMPLEMENTATION)
{
SharedLogger.logger.Warn($"NVIDIALibrary/SetActiveConfig: This entry point not available in this NVIDIA Driver. NvAPI_Disp_ColorControl() returned error code {NVStatus}");
}
else if (NVStatus == NVAPI_STATUS.NVAPI_ERROR)
{
SharedLogger.logger.Warn($"NVIDIALibrary/SetActiveConfig: A miscellaneous error occurred. NvAPI_Disp_ColorControl() returned error code {NVStatus}");
}
else
{
SharedLogger.logger.Trace($"NVIDIALibrary/SetActiveConfig: Some non standard error occurred while seting the color settings! NvAPI_Disp_ColorControl() returned error code {NVStatus}. It's most likely that your monitor {wantedColorData.Key} doesn't support this color mode.");
}
}
} }
else else
{ {
@ -1319,11 +1466,11 @@ namespace DisplayMagicianShared.NVIDIA
{ {
// Get the current windows display configs to compare to the one we loaded // Get the current windows display configs to compare to the one we loaded
bool allDisplays = false; bool allDisplays = false;
NVIDIA_DISPLAY_CONFIG currentDisplayConfig = GetNVIDIADisplayConfig(allDisplays); _activeDisplayConfig = GetNVIDIADisplayConfig(allDisplays);
// Check whether the display config is in use now // Check whether the display config is in use now
SharedLogger.logger.Trace($"NVIDIALibrary/IsActiveConfig: Checking whether the display configuration is already being used."); SharedLogger.logger.Trace($"NVIDIALibrary/IsActiveConfig: Checking whether the display configuration is already being used.");
if (displayConfig.Equals(currentDisplayConfig)) if (displayConfig.Equals(_activeDisplayConfig))
{ {
SharedLogger.logger.Trace($"NVIDIALibrary/IsActiveConfig: The display configuration is already being used (supplied displayConfig Equals currentDisplayConfig"); SharedLogger.logger.Trace($"NVIDIALibrary/IsActiveConfig: The display configuration is already being used (supplied displayConfig Equals currentDisplayConfig");
return true; return true;

View File

@ -519,7 +519,7 @@ namespace DisplayMagicianShared.Windows
public override bool Equals(object obj) => obj is DISPLAYCONFIG_PATH_SOURCE_INFO other && this.Equals(other); public override bool Equals(object obj) => obj is DISPLAYCONFIG_PATH_SOURCE_INFO other && this.Equals(other);
public bool Equals(DISPLAYCONFIG_PATH_SOURCE_INFO other) public bool Equals(DISPLAYCONFIG_PATH_SOURCE_INFO other)
=> // AdapterId.Equals(other.AdapterId) && // Removed the AdapterId from the Equals, as it changes after a reboot. => // AdapterId.Equals(other.AdapterId) && // Removed the AdapterId from the Equals, as it changes after a reboot.
//Id == other.Id && // Removed the ID from the list as the Display ID it maps to will change after a switch from surround to non-surround profile //Id == other.Id && // Removed the ID from the list as the Display ID it maps to will change after a switch from surround to non-surround profile
ModeInfoIdx == other.ModeInfoIdx && ModeInfoIdx == other.ModeInfoIdx &&
StatusFlags.Equals(other.StatusFlags); StatusFlags.Equals(other.StatusFlags);

View File

@ -736,7 +736,7 @@ namespace DisplayMagicianShared.Windows
{ {
SharedLogger.logger.Trace($"WinLibrary/GetWindowsDisplayConfig: Found SDR White Level: {whiteLevelInfo.SDRWhiteLevel} for target {path.TargetInfo.Id}."); SharedLogger.logger.Trace($"WinLibrary/GetWindowsDisplayConfig: Found SDR White Level: {whiteLevelInfo.SDRWhiteLevel} for target {path.TargetInfo.Id}.");
stringToReturn += $"****** Interrogating SDR Whilte Level for Display {path.TargetInfo.Id} *******\n"; stringToReturn += $"****** Interrogating SDR White Level for Display {path.TargetInfo.Id} *******\n";
stringToReturn += $" SDR White Level: {whiteLevelInfo.SDRWhiteLevel}\n"; stringToReturn += $" SDR White Level: {whiteLevelInfo.SDRWhiteLevel}\n";
stringToReturn += $"\n"; stringToReturn += $"\n";
} }