using System; using System.Linq; using System.Runtime.InteropServices; using NvAPIWrapper.Native.Attributes; using NvAPIWrapper.Native.General.Structures; using NvAPIWrapper.Native.Helpers; using NvAPIWrapper.Native.Interfaces; namespace NvAPIWrapper.Native.GPU.Structures { /// /// Contains information regarding GPU thermal policies status /// [StructLayout(LayoutKind.Sequential, Pack = 8)] [StructureVersion(2)] public struct PrivateThermalPoliciesStatusV2 : IInitializable { internal const int MaxNumberOfThermalPoliciesStatusEntries = 4; internal StructureVersion _Version; internal readonly uint _ThermalPoliciesStatusEntriesCount; [MarshalAs(UnmanagedType.ByValArray, SizeConst = MaxNumberOfThermalPoliciesStatusEntries)] internal readonly ThermalPoliciesStatusEntry[] _ThermalPoliciesStatusEntries; /// /// Gets a list of thermal policy status entries /// public ThermalPoliciesStatusEntry[] ThermalPoliciesStatusEntries { get => _ThermalPoliciesStatusEntries.Take((int) _ThermalPoliciesStatusEntriesCount).ToArray(); } /// /// Creates a new instance of /// /// The list of thermal policy status entries public PrivateThermalPoliciesStatusV2(ThermalPoliciesStatusEntry[] policiesStatusEntries) { if (policiesStatusEntries?.Length > MaxNumberOfThermalPoliciesStatusEntries) { throw new ArgumentException( $"Maximum of {MaxNumberOfThermalPoliciesStatusEntries} thermal policies entries are configurable.", nameof(policiesStatusEntries) ); } if (policiesStatusEntries == null || policiesStatusEntries.Length == 0) { throw new ArgumentException("Array is null or empty.", nameof(policiesStatusEntries)); } this = typeof(PrivateThermalPoliciesStatusV2).Instantiate(); _ThermalPoliciesStatusEntriesCount = (uint) policiesStatusEntries.Length; Array.Copy( policiesStatusEntries, 0, _ThermalPoliciesStatusEntries, 0, policiesStatusEntries.Length ); } /// /// Contains information regarding a thermal policies status entry /// [StructLayout(LayoutKind.Sequential, Pack = 8)] public struct ThermalPoliciesStatusEntry { internal ThermalController _Controller; internal int _TargetTemperature; internal PerformanceStateId _PerformanceStateId; /// /// Creates a new instance of /// /// The thermal controller /// The target temperature. public ThermalPoliciesStatusEntry(ThermalController controller, int targetTemperature) : this() { _Controller = controller; _TargetTemperature = targetTemperature * 256; } /// /// Creates a new instance of /// /// The performance state identification number /// The thermal controller /// The target temperature. public ThermalPoliciesStatusEntry( PerformanceStateId performanceStateId, ThermalController controller, int targetTemperature) : this(controller, targetTemperature) { _PerformanceStateId = performanceStateId; } /// /// Gets the thermal controller /// public ThermalController Controller { get => _Controller; } /// /// Gets the performance state identification number /// public PerformanceStateId PerformanceStateId { get => _PerformanceStateId; } /// /// Gets the target temperature /// public int TargetTemperature { get => _TargetTemperature >> 8; } } } }