using System; using NvAPIWrapper.Native; using NvAPIWrapper.Native.GPU; using NvAPIWrapper.Native.Interfaces.GPU; namespace NvAPIWrapper.GPU { /// /// Contains information regarding the available and total memory as well as the type of memory and other information /// regarding the GPU RAM and frame buffer /// public class GPUMemoryInformation : IDisplayDriverMemoryInfo { internal GPUMemoryInformation(PhysicalGPU physicalGPU) { PhysicalGPU = physicalGPU; } /// /// Gets the frame buffer bandwidth /// public int FrameBufferBandwidth { get { GPUApi.GetFrameBufferWidthAndLocation(PhysicalGPU.Handle, out var width, out _); return (int) width; } } /// /// Gets the frame buffer location index /// public int FrameBufferLocation { get { GPUApi.GetFrameBufferWidthAndLocation(PhysicalGPU.Handle, out _, out var location); return (int) location; } } /// /// Gets the internal clock to bus clock factor based on the type of RAM /// public int InternalClockToBusClockFactor { get => GetMemoryBusClockFactor(RAMType); } /// /// Gets the internal clock to transfer rate factor based on the type of RAM /// public int InternalClockToTransferRateFactor { get => GetMemoryTransferRateFactor(RAMType); } /// /// Gets GPU physical frame buffer size in KB. This does NOT include any system RAM that may be dedicated for use by /// the GPU. /// public int PhysicalFrameBufferSizeInkB { get => GPUApi.GetPhysicalFrameBufferSize(PhysicalGPU.Handle); } /// /// Gets the physical GPU that this instance describes /// public PhysicalGPU PhysicalGPU { get; } /// /// Gets the number of memory banks /// public uint RAMBanks { get => GPUApi.GetRAMBankCount(PhysicalGPU.Handle); } /// /// Gets the memory bus width /// public uint RAMBusWidth { get => GPUApi.GetRAMBusWidth(PhysicalGPU.Handle); } /// /// Gets the memory maker (brand) /// public GPUMemoryMaker RAMMaker { get => GPUApi.GetRAMMaker(PhysicalGPU.Handle); } /// /// Gets the memory type /// public GPUMemoryType RAMType { get => GPUApi.GetRAMType(PhysicalGPU.Handle); } /// /// Gets virtual size of frame-buffer in KB for this GPU. This includes the physical RAM plus any system RAM that has /// been dedicated for use by the GPU. /// public int VirtualFrameBufferSizeInkB { get => GPUApi.GetVirtualFrameBufferSize(PhysicalGPU.Handle); } /// public uint AvailableDedicatedVideoMemoryInkB { get => GPUApi.GetMemoryInfo(PhysicalGPU.Handle).AvailableDedicatedVideoMemoryInkB; } /// public uint CurrentAvailableDedicatedVideoMemoryInkB { get => GPUApi.GetMemoryInfo(PhysicalGPU.Handle).CurrentAvailableDedicatedVideoMemoryInkB; } /// public uint DedicatedVideoMemoryInkB { get => GPUApi.GetMemoryInfo(PhysicalGPU.Handle).DedicatedVideoMemoryInkB; } /// public uint SharedSystemMemoryInkB { get => GPUApi.GetMemoryInfo(PhysicalGPU.Handle).SharedSystemMemoryInkB; } /// public uint SystemVideoMemoryInkB { get => GPUApi.GetMemoryInfo(PhysicalGPU.Handle).SystemVideoMemoryInkB; } /// /// Gets the memory bus clock to internal memory clock factor /// /// /// The value of X in X(InternalMemoryClock)=(BusMemoryClock) public static int GetMemoryBusClockFactor(GPUMemoryType memoryType) { switch (memoryType) { case GPUMemoryType.SDRAM: // Bus Clocks Per Internal Clock = 1 return 1; case GPUMemoryType.DDR1: case GPUMemoryType.DDR2: case GPUMemoryType.DDR3: case GPUMemoryType.GDDR2: case GPUMemoryType.GDDR3: case GPUMemoryType.GDDR4: case GPUMemoryType.LPDDR2: case GPUMemoryType.GDDR5: case GPUMemoryType.GDDR5X: // Bus Clocks Per Internal Clock = 2 return 2; default: throw new ArgumentOutOfRangeException(nameof(memoryType)); } } /// /// Gets the number of transfers per internal memory clock factor /// /// /// The value of X in X(InternalMemoryClock)=(OperationsPerSecond) public static int GetMemoryTransferRateFactor(GPUMemoryType memoryType) { switch (memoryType) { case GPUMemoryType.SDRAM: // Transfers Per Internal Clock = 1 return 1; case GPUMemoryType.DDR1: case GPUMemoryType.DDR2: case GPUMemoryType.DDR3: case GPUMemoryType.GDDR2: case GPUMemoryType.GDDR3: case GPUMemoryType.GDDR4: case GPUMemoryType.LPDDR2: // Transfers Per Internal Clock = 1 return 2; case GPUMemoryType.GDDR5: // Transfers Per Internal Clock = 2 return 4; case GPUMemoryType.GDDR5X: // Transfers Per Internal Clock = 4 return 8; default: throw new ArgumentOutOfRangeException(nameof(memoryType)); } } /// public override string ToString() { return $"[{RAMMaker} {RAMType}] Total: {AvailableDedicatedVideoMemoryInkB:N0} kB - Available: {CurrentAvailableDedicatedVideoMemoryInkB:N0} kB"; } } }