using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using NvAPIWrapper.Native.Attributes; using NvAPIWrapper.Native.General.Structures; using NvAPIWrapper.Native.Helpers; using NvAPIWrapper.Native.Interfaces; using NvAPIWrapper.Native.Interfaces.GPU; namespace NvAPIWrapper.Native.GPU.Structures { /// /// Holds clock frequencies associated with a physical GPU and an specified clock type /// [StructLayout(LayoutKind.Sequential, Pack = 8)] [StructureVersion(2)] public struct ClockFrequenciesV2 : IInitializable, IClockFrequencies { internal const int MaxClocksPerGpu = 32; internal StructureVersion _Version; internal readonly uint _ClockTypeAndReserve; [MarshalAs(UnmanagedType.ByValArray, SizeConst = MaxClocksPerGpu)] internal ClockDomainInfo[] _Clocks; /// /// Creates a new ClockFrequenciesV2 /// /// The type of the clock frequency being requested public ClockFrequenciesV2(ClockType clockType = ClockType.CurrentClock) { this = typeof(ClockFrequenciesV2).Instantiate(); _ClockTypeAndReserve = 0u.SetBits(0, 2, (uint) clockType); } /// public IReadOnlyDictionary Clocks { get => _Clocks .Select((value, index) => new {index, value}) .Where(arg => Enum.IsDefined(typeof(PublicClockDomain), arg.index)) .ToDictionary(arg => (PublicClockDomain) arg.index, arg => arg.value); } /// public ClockType ClockType { get => (ClockType) _ClockTypeAndReserve.GetBits(0, 2); } /// public ClockDomainInfo GraphicsClock { get => _Clocks[(int) PublicClockDomain.Graphics]; } /// public ClockDomainInfo MemoryClock { get => _Clocks[(int) PublicClockDomain.Memory]; } /// public ClockDomainInfo VideoDecodingClock { get => _Clocks[(int) PublicClockDomain.Video]; } /// public ClockDomainInfo ProcessorClock { get => _Clocks[(int) PublicClockDomain.Processor]; } /// public override string ToString() { return $"[{ClockType}] 3D Graphics = {GraphicsClock} - Memory = {MemoryClock} - Video Decoding = {VideoDecodingClock} - Processor = {ProcessorClock}"; } } }