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 power policies status
///
[StructLayout(LayoutKind.Sequential, Pack = 8)]
[StructureVersion(1)]
public struct PrivatePowerPoliciesStatusV1 : IInitializable
{
internal const int MaxNumberOfPowerPoliciesStatusEntries = 4;
internal StructureVersion _Version;
internal readonly uint _PowerPoliciesStatusEntriesCount;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MaxNumberOfPowerPoliciesStatusEntries,
ArraySubType = UnmanagedType.Struct)]
internal readonly PowerPolicyStatusEntry[] _PowerPoliciesStatusEntries;
///
/// Gets a list of power policy status entries
///
public PowerPolicyStatusEntry[] PowerPolicyStatusEntries
{
get => _PowerPoliciesStatusEntries.Take((int) _PowerPoliciesStatusEntriesCount).ToArray();
}
///
/// Creates a new instance of
///
/// The list of power policy status entries.
public PrivatePowerPoliciesStatusV1(PowerPolicyStatusEntry[] powerPoliciesStatusEntries)
{
if (powerPoliciesStatusEntries?.Length > MaxNumberOfPowerPoliciesStatusEntries)
{
throw new ArgumentException(
$"Maximum of {MaxNumberOfPowerPoliciesStatusEntries} power policies entries are configurable.",
nameof(powerPoliciesStatusEntries)
);
}
if (powerPoliciesStatusEntries == null || powerPoliciesStatusEntries.Length == 0)
{
throw new ArgumentException("Array is null or empty.", nameof(powerPoliciesStatusEntries));
}
this = typeof(PrivatePowerPoliciesStatusV1).Instantiate();
_PowerPoliciesStatusEntriesCount = (uint) powerPoliciesStatusEntries.Length;
Array.Copy(
powerPoliciesStatusEntries,
0,
_PowerPoliciesStatusEntries,
0,
powerPoliciesStatusEntries.Length
);
}
///
/// Contains information regarding a power policies status entry
///
[StructLayout(LayoutKind.Sequential, Pack = 8)]
public struct PowerPolicyStatusEntry
{
internal PerformanceStateId _PerformanceStateId;
internal uint _Unknown1;
internal uint _PowerTargetInPCM;
internal uint _Unknown2;
///
/// Gets the performance state identification number
///
public PerformanceStateId PerformanceStateId
{
get => _PerformanceStateId;
}
///
/// Creates a new instance of PowerPolicyStatusEntry.
///
/// The power limit target in per cent mille.
public PowerPolicyStatusEntry(uint powerTargetInPCM) : this()
{
_PowerTargetInPCM = powerTargetInPCM;
}
///
/// Gets the power limit target in per cent mille
///
public uint PowerTargetInPCM
{
get => _PowerTargetInPCM;
}
}
}
}