Experimental GPU overclock

This commit is contained in:
Serge
2023-05-06 14:40:52 +02:00
parent 8e1099545a
commit c61f4d1608
497 changed files with 46937 additions and 232 deletions

View File

@@ -0,0 +1,140 @@
using System;
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.Mosaic;
namespace NvAPIWrapper.Native.Mosaic.Structures
{
/// <summary>
/// Holds a display setting
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 8)]
[StructureVersion(1)]
public struct DisplaySettingsV1 : IDisplaySettings,
IInitializable,
IEquatable<DisplaySettingsV1>,
IEquatable<DisplaySettingsV2>
{
internal StructureVersion _Version;
internal readonly uint _Width;
internal readonly uint _Height;
internal readonly uint _BitsPerPixel;
internal readonly uint _Frequency;
/// <summary>
/// Creates a new DisplaySettingsV1
/// </summary>
/// <param name="width">Per-display width</param>
/// <param name="height">Per-display height</param>
/// <param name="bitsPerPixel">Bits per pixel</param>
/// <param name="frequency">Display frequency</param>
// ReSharper disable once TooManyDependencies
public DisplaySettingsV1(int width, int height, int bitsPerPixel, int frequency)
{
this = typeof(DisplaySettingsV1).Instantiate<DisplaySettingsV1>();
_Width = (uint) width;
_Height = (uint) height;
_BitsPerPixel = (uint) bitsPerPixel;
_Frequency = (uint) frequency;
}
/// <inheritdoc />
public bool Equals(DisplaySettingsV1 other)
{
return _Width == other._Width &&
_Height == other._Height &&
_BitsPerPixel == other._BitsPerPixel &&
_Frequency == other._Frequency;
}
/// <inheritdoc />
public bool Equals(DisplaySettingsV2 other)
{
return _Width == other._Width &&
_Height == other._Height &&
_BitsPerPixel == other._BitsPerPixel &&
_Frequency == other._Frequency;
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
return obj is DisplaySettingsV1 v1 && Equals(v1);
}
/// <inheritdoc />
public override int GetHashCode()
{
unchecked
{
var hashCode = (int) _Width;
hashCode = (hashCode * 397) ^ (int) _Height;
hashCode = (hashCode * 397) ^ (int) _BitsPerPixel;
hashCode = (hashCode * 397) ^ (int) _Frequency;
return hashCode;
}
}
/// <summary>
/// Checks for equality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are equal, otherwise false</returns>
public static bool operator ==(DisplaySettingsV1 left, DisplaySettingsV1 right)
{
return left.Equals(right);
}
/// <summary>
/// Checks for inequality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are not equal, otherwise false</returns>
public static bool operator !=(DisplaySettingsV1 left, DisplaySettingsV1 right)
{
return !left.Equals(right);
}
/// <inheritdoc />
public int Width
{
get => (int) _Width;
}
/// <inheritdoc />
public int Height
{
get => (int) _Height;
}
/// <inheritdoc />
public int BitsPerPixel
{
get => (int) _BitsPerPixel;
}
/// <inheritdoc />
public int Frequency
{
get => (int) _Frequency;
}
/// <inheritdoc />
public uint FrequencyInMillihertz
{
get => _Frequency * 1000;
}
}
}

View File

@@ -0,0 +1,144 @@
using System;
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.Mosaic;
namespace NvAPIWrapper.Native.Mosaic.Structures
{
/// <summary>
/// Holds a display setting
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 8)]
[StructureVersion(2)]
public struct DisplaySettingsV2 : IDisplaySettings,
IInitializable,
IEquatable<DisplaySettingsV2>,
IEquatable<DisplaySettingsV1>
{
internal StructureVersion _Version;
internal readonly uint _Width;
internal readonly uint _Height;
internal readonly uint _BitsPerPixel;
internal readonly uint _Frequency;
internal readonly uint _FrequencyInMillihertz;
/// <summary>
/// Creates a new DisplaySettingsV2
/// </summary>
/// <param name="width">Per-display width</param>
/// <param name="height">Per-display height</param>
/// <param name="bitsPerPixel">Bits per pixel</param>
/// <param name="frequency">Display frequency</param>
/// <param name="frequencyInMillihertz">Display frequency in x1k</param>
// ReSharper disable once TooManyDependencies
public DisplaySettingsV2(int width, int height, int bitsPerPixel, int frequency, uint frequencyInMillihertz)
{
this = typeof(DisplaySettingsV2).Instantiate<DisplaySettingsV2>();
_Width = (uint) width;
_Height = (uint) height;
_BitsPerPixel = (uint) bitsPerPixel;
_Frequency = (uint) frequency;
_FrequencyInMillihertz = frequencyInMillihertz;
}
/// <inheritdoc />
public bool Equals(DisplaySettingsV2 other)
{
return _Width == other._Width &&
_Height == other._Height &&
_BitsPerPixel == other._BitsPerPixel &&
_Frequency == other._Frequency &&
_FrequencyInMillihertz == other._FrequencyInMillihertz;
}
/// <inheritdoc />
public bool Equals(DisplaySettingsV1 other)
{
return _Width == other._Width &&
_Height == other._Height &&
_BitsPerPixel == other._BitsPerPixel &&
_Frequency == other._Frequency;
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
return obj is DisplaySettingsV2 v2 && Equals(v2);
}
/// <inheritdoc />
public override int GetHashCode()
{
unchecked
{
var hashCode = (int) _Width;
hashCode = (hashCode * 397) ^ (int) _Height;
hashCode = (hashCode * 397) ^ (int) _BitsPerPixel;
hashCode = (hashCode * 397) ^ (int) _Frequency;
hashCode = (hashCode * 397) ^ (int) _FrequencyInMillihertz;
return hashCode;
}
}
/// <summary>
/// Checks for equality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are equal, otherwise false</returns>
public static bool operator ==(DisplaySettingsV2 left, DisplaySettingsV2 right)
{
return left.Equals(right);
}
/// <summary>
/// Checks for inequality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are not equal, otherwise false</returns>
public static bool operator !=(DisplaySettingsV2 left, DisplaySettingsV2 right)
{
return !left.Equals(right);
}
/// <inheritdoc />
public int Width
{
get => (int) _Width;
}
/// <inheritdoc />
public int Height
{
get => (int) _Height;
}
/// <inheritdoc />
public int BitsPerPixel
{
get => (int) _BitsPerPixel;
}
/// <inheritdoc />
public int Frequency
{
get => (int) _Frequency;
}
/// <inheritdoc />
public uint FrequencyInMillihertz
{
get => _FrequencyInMillihertz;
}
}
}

View File

@@ -0,0 +1,100 @@
using System.Linq;
using System.Runtime.InteropServices;
using NvAPIWrapper.Native.Attributes;
using NvAPIWrapper.Native.General.Structures;
using NvAPIWrapper.Native.GPU.Structures;
using NvAPIWrapper.Native.Helpers;
using NvAPIWrapper.Native.Interfaces;
namespace NvAPIWrapper.Native.Mosaic.Structures
{
/// <summary>
/// Holds information about a topology validity status
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 8)]
[StructureVersion(1)]
public struct DisplayTopologyStatus : IInitializable
{
/// <summary>
/// Maximum number of displays for this structure
/// </summary>
public const int MaxDisplays =
PhysicalGPUHandle.PhysicalGPUs * Constants.Display.AdvancedDisplayHeads;
internal StructureVersion _Version;
internal readonly DisplayCapacityProblem _Errors;
internal readonly DisplayTopologyWarning _Warnings;
internal readonly uint _DisplayCounts;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MaxDisplays)]
internal Display[] _Displays;
/// <summary>
/// Gets all error flags for this topology
/// </summary>
public DisplayCapacityProblem Errors
{
get => _Errors;
}
/// <summary>
/// Gets all warning flags for this topology
/// </summary>
public DisplayTopologyWarning Warnings
{
get => _Warnings;
}
/// <summary>
/// Gets per display statuses
/// </summary>
public Display[] Displays
{
get => _Displays.Take((int) _DisplayCounts).ToArray();
}
/// <summary>
/// Holds information about a display validity status in a topology
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 8)]
public struct Display
{
internal uint _DisplayId;
internal DisplayCapacityProblem _Errors;
internal DisplayTopologyWarning _Warnings;
internal uint _RawReserved;
/// <summary>
/// Gets the Display identification of this display.
/// </summary>
public uint DisplayId
{
get => _DisplayId;
}
/// <summary>
/// Gets all error flags for this display
/// </summary>
public DisplayCapacityProblem Errors
{
get => _Errors;
}
/// <summary>
/// Gets all warning flags for this display
/// </summary>
public DisplayTopologyWarning Warnings
{
get => _Warnings;
}
/// <summary>
/// Indicates if this display can be rotated
/// </summary>
public bool SupportsRotation
{
get => _RawReserved.GetBit(0);
}
}
}
}

View File

@@ -0,0 +1,133 @@
using System;
using System.Runtime.InteropServices;
using NvAPIWrapper.Native.Display;
using NvAPIWrapper.Native.Interfaces.Mosaic;
namespace NvAPIWrapper.Native.Mosaic.Structures
{
/// <summary>
/// Holds information about a display in a grid topology
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 8)]
public struct GridTopologyDisplayV1 : IGridTopologyDisplay, IEquatable<GridTopologyDisplayV1>
{
internal readonly uint _DisplayId;
internal readonly int _OverlapX;
internal readonly int _OverlapY;
internal readonly Rotate _Rotation;
internal readonly uint _CloneGroup;
/// <summary>
/// Creates a new GridTopologyDisplayV1
/// </summary>
/// <param name="displayId">Display identification</param>
/// <param name="overlapX">Horizontal overlap (+overlap, -gap)</param>
/// <param name="overlapY">Vertical overlap (+overlap, -gap)</param>
/// <param name="rotation">Rotation of display</param>
/// <param name="cloneGroup">Clone group identification; Reserved, must be 0</param>
// ReSharper disable once TooManyDependencies
public GridTopologyDisplayV1(uint displayId, int overlapX, int overlapY, Rotate rotation, uint cloneGroup = 0)
: this()
{
_DisplayId = displayId;
_OverlapX = overlapX;
_OverlapY = overlapY;
_Rotation = rotation;
_CloneGroup = cloneGroup;
}
/// <inheritdoc />
public bool Equals(GridTopologyDisplayV1 other)
{
return _DisplayId == other._DisplayId &&
_OverlapX == other._OverlapX &&
_OverlapY == other._OverlapY &&
_Rotation == other._Rotation &&
_CloneGroup == other._CloneGroup;
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
return obj is GridTopologyDisplayV1 v1 && Equals(v1);
}
/// <inheritdoc />
public override int GetHashCode()
{
unchecked
{
var hashCode = (int) _DisplayId;
hashCode = (hashCode * 397) ^ _OverlapX;
hashCode = (hashCode * 397) ^ _OverlapY;
hashCode = (hashCode * 397) ^ (int) _Rotation;
hashCode = (hashCode * 397) ^ (int) _CloneGroup;
return hashCode;
}
}
/// <summary>
/// Checks for equality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are equal, otherwise false</returns>
public static bool operator ==(GridTopologyDisplayV1 left, GridTopologyDisplayV1 right)
{
return left.Equals(right);
}
/// <summary>
/// Checks for inequality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are not equal, otherwise false</returns>
public static bool operator !=(GridTopologyDisplayV1 left, GridTopologyDisplayV1 right)
{
return !left.Equals(right);
}
/// <inheritdoc />
public uint DisplayId
{
get => _DisplayId;
}
/// <inheritdoc />
public int OverlapX
{
get => _OverlapX;
}
/// <inheritdoc />
public int OverlapY
{
get => _OverlapY;
}
/// <inheritdoc />
public Rotate Rotation
{
get => _Rotation;
}
/// <inheritdoc />
public uint CloneGroup
{
get => _CloneGroup;
}
/// <inheritdoc />
public PixelShiftType PixelShiftType
{
get => PixelShiftType.NoPixelShift;
}
}
}

View File

@@ -0,0 +1,150 @@
using System;
using System.Runtime.InteropServices;
using NvAPIWrapper.Native.Attributes;
using NvAPIWrapper.Native.Display;
using NvAPIWrapper.Native.General.Structures;
using NvAPIWrapper.Native.Helpers;
using NvAPIWrapper.Native.Interfaces;
using NvAPIWrapper.Native.Interfaces.Mosaic;
namespace NvAPIWrapper.Native.Mosaic.Structures
{
/// <summary>
/// Holds information about a display in a grid topology
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 8)]
[StructureVersion]
public struct GridTopologyDisplayV2 : IGridTopologyDisplay, IInitializable, IEquatable<GridTopologyDisplayV2>
{
internal StructureVersion _Version;
internal readonly uint _DisplayId;
internal readonly int _OverlapX;
internal readonly int _OverlapY;
internal readonly Rotate _Rotation;
internal readonly uint _CloneGroup;
internal readonly PixelShiftType _PixelShiftType;
/// <summary>
/// Creates a new GridTopologyDisplayV2
/// </summary>
/// <param name="displayId">Display identification</param>
/// <param name="overlapX">Horizontal overlap (+overlap, -gap)</param>
/// <param name="overlapY">Vertical overlap (+overlap, -gap)</param>
/// <param name="rotation">Rotation of display</param>
/// <param name="cloneGroup">Clone group identification; Reserved, must be 0</param>
/// <param name="pixelShiftType">Type of the pixel shift enabled display</param>
// ReSharper disable once TooManyDependencies
public GridTopologyDisplayV2(
uint displayId,
int overlapX,
int overlapY,
Rotate rotation,
uint cloneGroup = 0,
PixelShiftType pixelShiftType = PixelShiftType.NoPixelShift) : this()
{
this = typeof(GridTopologyDisplayV2).Instantiate<GridTopologyDisplayV2>();
_DisplayId = displayId;
_OverlapX = overlapX;
_OverlapY = overlapY;
_Rotation = rotation;
_CloneGroup = cloneGroup;
_PixelShiftType = pixelShiftType;
}
/// <inheritdoc />
public bool Equals(GridTopologyDisplayV2 other)
{
return _DisplayId == other._DisplayId &&
_OverlapX == other._OverlapX &&
_OverlapY == other._OverlapY &&
_Rotation == other._Rotation &&
_CloneGroup == other._CloneGroup &&
_PixelShiftType == other._PixelShiftType;
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
return obj is GridTopologyDisplayV2 v2 && Equals(v2);
}
/// <inheritdoc />
public override int GetHashCode()
{
unchecked
{
var hashCode = (int) _DisplayId;
hashCode = (hashCode * 397) ^ _OverlapX;
hashCode = (hashCode * 397) ^ _OverlapY;
hashCode = (hashCode * 397) ^ (int) _Rotation;
hashCode = (hashCode * 397) ^ (int) _CloneGroup;
hashCode = (hashCode * 397) ^ (int) _PixelShiftType;
return hashCode;
}
}
/// <summary>
/// Checks for equality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are equal, otherwise false</returns>
public static bool operator ==(GridTopologyDisplayV2 left, GridTopologyDisplayV2 right)
{
return left.Equals(right);
}
/// <summary>
/// Checks for inequality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are not equal, otherwise false</returns>
public static bool operator !=(GridTopologyDisplayV2 left, GridTopologyDisplayV2 right)
{
return !left.Equals(right);
}
/// <inheritdoc />
public uint DisplayId
{
get => _DisplayId;
}
/// <inheritdoc />
public int OverlapX
{
get => _OverlapX;
}
/// <inheritdoc />
public int OverlapY
{
get => _OverlapY;
}
/// <inheritdoc />
public Rotate Rotation
{
get => _Rotation;
}
/// <inheritdoc />
public uint CloneGroup
{
get => _CloneGroup;
}
/// <inheritdoc />
public PixelShiftType PixelShiftType
{
get => _PixelShiftType;
}
}
}

View File

@@ -0,0 +1,202 @@
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.Mosaic;
namespace NvAPIWrapper.Native.Mosaic.Structures
{
/// <summary>
/// Holds information about a grid topology
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 8)]
[StructureVersion(1)]
public struct GridTopologyV1 : IGridTopology, IInitializable, IEquatable<GridTopologyV1>
{
/// <summary>
/// Maximum number of displays in a topology
/// </summary>
public const int MaxDisplays = 64;
internal StructureVersion _Version;
internal readonly uint _Rows;
internal readonly uint _Columns;
internal readonly uint _DisplayCount;
internal uint _RawReserved;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MaxDisplays)]
internal readonly GridTopologyDisplayV1[] _Displays;
internal readonly DisplaySettingsV1 _DisplaySettings;
/// <summary>
/// Creates a new GridTopologyV1
/// </summary>
/// <param name="rows">Number of rows</param>
/// <param name="columns">Number of columns</param>
/// <param name="displays">Topology displays; Displays are done as [(row * columns) + column]</param>
/// <param name="displaySettings">Display settings</param>
/// <param name="applyWithBezelCorrectedResolution">
/// When enabling and doing the modeset, do we switch to the
/// bezel-corrected resolution
/// </param>
/// <param name="immersiveGaming">Enable as immersive gaming instead of Mosaic SLI (for Quadro-boards only)</param>
/// <param name="baseMosaicPanoramic">
/// Enable as Base Mosaic (Panoramic) instead of Mosaic SLI (for NVS and Quadro-boards
/// only)
/// </param>
/// <param name="driverReloadAllowed">
/// If necessary, reloading the driver is permitted (for Vista and above only). Will not
/// be persisted.
/// </param>
/// <param name="acceleratePrimaryDisplay">
/// Enable SLI acceleration on the primary display while in single-wide mode (For
/// Immersive Gaming only). Will not be persisted.
/// </param>
/// <exception cref="ArgumentOutOfRangeException">Total number of topology displays is below or equal to zero</exception>
/// <exception cref="ArgumentException">Number of displays doesn't match the arrangement</exception>
// ReSharper disable once TooManyDependencies
public GridTopologyV1(
int rows,
int columns,
GridTopologyDisplayV1[] displays,
DisplaySettingsV1 displaySettings,
bool applyWithBezelCorrectedResolution,
bool immersiveGaming,
bool baseMosaicPanoramic,
bool driverReloadAllowed,
bool acceleratePrimaryDisplay)
{
if (rows * columns <= 0)
{
throw new ArgumentOutOfRangeException($"{nameof(rows)}, {nameof(columns)}",
"Invalid display arrangement.");
}
if (displays.Length > MaxDisplays)
{
throw new ArgumentException("Too many displays.");
}
if (displays.Length != rows * columns)
{
throw new ArgumentException("Number of displays should match the arrangement.", nameof(displays));
}
this = typeof(GridTopologyV1).Instantiate<GridTopologyV1>();
_Rows = (uint) rows;
_Columns = (uint) columns;
_DisplayCount = (uint) displays.Length;
_Displays = displays;
_DisplaySettings = displaySettings;
ApplyWithBezelCorrectedResolution = applyWithBezelCorrectedResolution;
ImmersiveGaming = immersiveGaming;
BaseMosaicPanoramic = baseMosaicPanoramic;
DriverReloadAllowed = driverReloadAllowed;
AcceleratePrimaryDisplay = acceleratePrimaryDisplay;
Array.Resize(ref _Displays, MaxDisplays);
}
/// <inheritdoc />
public bool Equals(GridTopologyV1 other)
{
return _Rows == other._Rows &&
_Columns == other._Columns &&
_DisplayCount == other._DisplayCount &&
_RawReserved == other._RawReserved &&
_Displays.SequenceEqual(other._Displays) &&
_DisplaySettings.Equals(other._DisplaySettings);
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
return obj is GridTopologyV1 v1 && Equals(v1);
}
/// <inheritdoc />
public override int GetHashCode()
{
unchecked
{
var hashCode = (int) _Rows;
hashCode = (hashCode * 397) ^ (int) _Columns;
hashCode = (hashCode * 397) ^ (int) _DisplayCount;
// ReSharper disable once NonReadonlyMemberInGetHashCode
hashCode = (hashCode * 397) ^ (int) _RawReserved;
hashCode = (hashCode * 397) ^ (_Displays?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ _DisplaySettings.GetHashCode();
return hashCode;
}
}
/// <inheritdoc />
public int Rows
{
get => (int) _Rows;
}
/// <inheritdoc />
public int Columns
{
get => (int) _Columns;
}
/// <inheritdoc />
public IEnumerable<IGridTopologyDisplay> Displays
{
get => _Displays.Take((int) _DisplayCount).Cast<IGridTopologyDisplay>();
}
/// <inheritdoc />
public DisplaySettingsV1 DisplaySettings
{
get => _DisplaySettings;
}
/// <inheritdoc />
public bool ApplyWithBezelCorrectedResolution
{
get => _RawReserved.GetBit(0);
private set => _RawReserved = _RawReserved.SetBit(0, value);
}
/// <inheritdoc />
public bool ImmersiveGaming
{
get => _RawReserved.GetBit(1);
private set => _RawReserved = _RawReserved.SetBit(1, value);
}
/// <inheritdoc />
public bool BaseMosaicPanoramic
{
get => _RawReserved.GetBit(2);
private set => _RawReserved = _RawReserved.SetBit(2, value);
}
/// <inheritdoc />
public bool DriverReloadAllowed
{
get => _RawReserved.GetBit(3);
private set => _RawReserved = _RawReserved.SetBit(3, value);
}
/// <inheritdoc />
public bool AcceleratePrimaryDisplay
{
get => _RawReserved.GetBit(4);
private set => _RawReserved = _RawReserved.SetBit(4, value);
}
}
}

View File

@@ -0,0 +1,214 @@
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.Mosaic;
namespace NvAPIWrapper.Native.Mosaic.Structures
{
/// <summary>
/// Holds information about a grid topology
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 8)]
[StructureVersion(2)]
public struct GridTopologyV2 : IGridTopology, IInitializable, IEquatable<GridTopologyV2>
{
/// <summary>
/// Maximum number of displays in a topology
/// </summary>
public const int MaxDisplays = GridTopologyV1.MaxDisplays;
internal StructureVersion _Version;
internal readonly uint _Rows;
internal readonly uint _Columns;
internal readonly uint _DisplayCount;
internal uint _RawReserved;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MaxDisplays)]
internal readonly GridTopologyDisplayV2[] _Displays;
internal readonly DisplaySettingsV1 _DisplaySettings;
/// <summary>
/// Creates a new GridTopologyV2
/// </summary>
/// <param name="rows">Number of rows</param>
/// <param name="columns">Number of columns</param>
/// <param name="displays">Topology displays; Displays are done as [(row * columns) + column]</param>
/// <param name="displaySettings">Display settings</param>
/// <param name="applyWithBezelCorrectedResolution">
/// When enabling and doing the mode-set, do we switch to the
/// bezel-corrected resolution
/// </param>
/// <param name="immersiveGaming">Enable as immersive gaming instead of Mosaic SLI (for Quadro-boards only)</param>
/// <param name="baseMosaicPanoramic">
/// Enable as Base Mosaic (Panoramic) instead of Mosaic SLI (for NVS and Quadro-boards
/// only)
/// </param>
/// <param name="driverReloadAllowed">
/// If necessary, reloading the driver is permitted (for Vista and above only). Will not
/// be persisted.
/// </param>
/// <param name="acceleratePrimaryDisplay">
/// Enable SLI acceleration on the primary display while in single-wide mode (For
/// Immersive Gaming only). Will not be persisted.
/// </param>
/// <param name="pixelShift">Enable Pixel shift</param>
/// <exception cref="ArgumentOutOfRangeException">Total number of topology displays is below or equal to zero</exception>
/// <exception cref="ArgumentException">Number of displays doesn't match the arrangement</exception>
// ReSharper disable once TooManyDependencies
public GridTopologyV2(
int rows,
int columns,
GridTopologyDisplayV2[] displays,
DisplaySettingsV1 displaySettings,
bool applyWithBezelCorrectedResolution,
bool immersiveGaming,
bool baseMosaicPanoramic,
bool driverReloadAllowed,
bool acceleratePrimaryDisplay,
bool pixelShift)
{
if (rows * columns <= 0)
{
throw new ArgumentOutOfRangeException($"{nameof(rows)}, {nameof(columns)}",
"Invalid display arrangement.");
}
if (displays.Length > MaxDisplays)
{
throw new ArgumentException("Too many displays.");
}
if (displays.Length != rows * columns)
{
throw new ArgumentException("Number of displays should match the arrangement.", nameof(displays));
}
this = typeof(GridTopologyV2).Instantiate<GridTopologyV2>();
_Rows = (uint) rows;
_Columns = (uint) columns;
_DisplayCount = (uint) displays.Length;
_Displays = displays;
_DisplaySettings = displaySettings;
ApplyWithBezelCorrectedResolution = applyWithBezelCorrectedResolution;
ImmersiveGaming = immersiveGaming;
BaseMosaicPanoramic = baseMosaicPanoramic;
DriverReloadAllowed = driverReloadAllowed;
AcceleratePrimaryDisplay = acceleratePrimaryDisplay;
PixelShift = pixelShift;
Array.Resize(ref _Displays, MaxDisplays);
}
/// <inheritdoc />
public bool Equals(GridTopologyV2 other)
{
return _Rows == other._Rows &&
_Columns == other._Columns &&
_DisplayCount == other._DisplayCount &&
_RawReserved == other._RawReserved &&
_Displays.SequenceEqual(other._Displays) &&
_DisplaySettings.Equals(other._DisplaySettings);
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
return obj is GridTopologyV2 v2 && Equals(v2);
}
/// <inheritdoc />
public override int GetHashCode()
{
unchecked
{
var hashCode = (int) _Rows;
hashCode = (hashCode * 397) ^ (int) _Columns;
hashCode = (hashCode * 397) ^ (int) _DisplayCount;
// ReSharper disable once NonReadonlyMemberInGetHashCode
hashCode = (hashCode * 397) ^ (int) _RawReserved;
hashCode = (hashCode * 397) ^ (_Displays?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ _DisplaySettings.GetHashCode();
return hashCode;
}
}
/// <inheritdoc />
public int Rows
{
get => (int) _Rows;
}
/// <inheritdoc />
public int Columns
{
get => (int) _Columns;
}
/// <inheritdoc />
public IEnumerable<IGridTopologyDisplay> Displays
{
get => _Displays.Take((int) _DisplayCount).Cast<IGridTopologyDisplay>();
}
/// <inheritdoc />
public DisplaySettingsV1 DisplaySettings
{
get => _DisplaySettings;
}
/// <inheritdoc />
public bool ApplyWithBezelCorrectedResolution
{
get => _RawReserved.GetBit(0);
private set => _RawReserved = _RawReserved.SetBit(0, value);
}
/// <inheritdoc />
public bool ImmersiveGaming
{
get => _RawReserved.GetBit(1);
private set => _RawReserved = _RawReserved.SetBit(1, value);
}
/// <inheritdoc />
public bool BaseMosaicPanoramic
{
get => _RawReserved.GetBit(2);
private set => _RawReserved = _RawReserved.SetBit(2, value);
}
/// <inheritdoc />
public bool DriverReloadAllowed
{
get => _RawReserved.GetBit(3);
private set => _RawReserved = _RawReserved.SetBit(3, value);
}
/// <inheritdoc />
public bool AcceleratePrimaryDisplay
{
get => _RawReserved.GetBit(4);
private set => _RawReserved = _RawReserved.SetBit(4, value);
}
/// <summary>
/// Enable Pixel shift
/// </summary>
public bool PixelShift
{
get => _RawReserved.GetBit(5);
private set => _RawReserved = _RawReserved.SetBit(5, value);
}
}
}

View File

@@ -0,0 +1,85 @@
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.Interfaces;
using NvAPIWrapper.Native.Interfaces.Mosaic;
namespace NvAPIWrapper.Native.Mosaic.Structures
{
/// <summary>
/// Holds information about supported topologies
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 8)]
[StructureVersion(1)]
public struct SupportedTopologiesInfoV1 : ISupportedTopologiesInfo,
IInitializable,
IEquatable<SupportedTopologiesInfoV1>
{
/// <summary>
/// Maximum number of display settings possible to retrieve
/// </summary>
public const int MaxSettings = 40;
internal StructureVersion _Version;
internal readonly uint _TopologyBriefsCount;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = (int) Topology.Max)]
internal readonly TopologyBrief[]
_TopologyBriefs;
internal readonly uint _DisplaySettingsCount;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MaxSettings)]
internal readonly DisplaySettingsV1[]
_DisplaySettings;
/// <inheritdoc />
public bool Equals(SupportedTopologiesInfoV1 other)
{
return _TopologyBriefsCount == other._TopologyBriefsCount &&
_TopologyBriefs.SequenceEqual(other._TopologyBriefs) &&
_DisplaySettingsCount == other._DisplaySettingsCount &&
_DisplaySettings.SequenceEqual(other._DisplaySettings);
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
return obj is SupportedTopologiesInfoV1 v1 && Equals(v1);
}
/// <inheritdoc />
public override int GetHashCode()
{
unchecked
{
var hashCode = (int) _TopologyBriefsCount;
hashCode = (hashCode * 397) ^ (_TopologyBriefs?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (int) _DisplaySettingsCount;
hashCode = (hashCode * 397) ^ (_DisplaySettings?.GetHashCode() ?? 0);
return hashCode;
}
}
/// <inheritdoc />
public IEnumerable<TopologyBrief> TopologyBriefs
{
get => _TopologyBriefs.Take((int) _TopologyBriefsCount);
}
/// <inheritdoc />
public IEnumerable<IDisplaySettings> DisplaySettings
{
get => _DisplaySettings.Take((int) _DisplaySettingsCount).Cast<IDisplaySettings>();
}
}
}

View File

@@ -0,0 +1,85 @@
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.Interfaces;
using NvAPIWrapper.Native.Interfaces.Mosaic;
namespace NvAPIWrapper.Native.Mosaic.Structures
{
/// <summary>
/// Holds information about supported topologies
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 8)]
[StructureVersion(2)]
public struct SupportedTopologiesInfoV2 : ISupportedTopologiesInfo,
IInitializable,
IEquatable<SupportedTopologiesInfoV2>
{
/// <summary>
/// Maximum number of display settings possible to retrieve
/// </summary>
public const int MaxSettings = SupportedTopologiesInfoV1.MaxSettings;
internal StructureVersion _Version;
internal readonly uint _TopologyBriefsCount;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = (int) Topology.Max)]
internal readonly TopologyBrief[]
_TopologyBriefs;
internal readonly uint _DisplaySettingsCount;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MaxSettings)]
internal readonly DisplaySettingsV2[]
_DisplaySettings;
/// <inheritdoc />
public bool Equals(SupportedTopologiesInfoV2 other)
{
return _TopologyBriefsCount == other._TopologyBriefsCount &&
_TopologyBriefs.SequenceEqual(other._TopologyBriefs) &&
_DisplaySettingsCount == other._DisplaySettingsCount &&
_DisplaySettings.SequenceEqual(other._DisplaySettings);
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
return obj is SupportedTopologiesInfoV2 v2 && Equals(v2);
}
/// <inheritdoc />
public override int GetHashCode()
{
unchecked
{
var hashCode = (int) _TopologyBriefsCount;
hashCode = (hashCode * 397) ^ (_TopologyBriefs?.GetHashCode() ?? 0);
hashCode = (hashCode * 397) ^ (int) _DisplaySettingsCount;
hashCode = (hashCode * 397) ^ (_DisplaySettings?.GetHashCode() ?? 0);
return hashCode;
}
}
/// <inheritdoc />
public IEnumerable<TopologyBrief> TopologyBriefs
{
get => _TopologyBriefs.Take((int) _TopologyBriefsCount);
}
/// <inheritdoc />
public IEnumerable<IDisplaySettings> DisplaySettings
{
get => _DisplaySettings.Take((int) _DisplaySettingsCount).Cast<IDisplaySettings>();
}
}
}

View File

@@ -0,0 +1,101 @@
using System;
using System.Runtime.InteropServices;
using NvAPIWrapper.Native.Attributes;
using NvAPIWrapper.Native.General.Structures;
using NvAPIWrapper.Native.Helpers;
using NvAPIWrapper.Native.Interfaces;
namespace NvAPIWrapper.Native.Mosaic.Structures
{
/// <summary>
/// Holds brief information about a topology
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 8)]
[StructureVersion(1)]
public struct TopologyBrief : IInitializable, IEquatable<TopologyBrief>
{
internal StructureVersion _Version;
internal readonly Topology _Topology;
internal readonly uint _IsEnable;
internal readonly uint _IsPossible;
/// <summary>
/// Creates a new TopologyBrief
/// </summary>
/// <param name="topology">The topology</param>
public TopologyBrief(Topology topology)
{
this = typeof(TopologyBrief).Instantiate<TopologyBrief>();
_Topology = topology;
}
/// <inheritdoc />
public bool Equals(TopologyBrief other)
{
return _Topology == other._Topology;
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
return obj is TopologyBrief brief && Equals(brief);
}
/// <inheritdoc />
public override int GetHashCode()
{
return (int) _Topology;
}
/// <summary>
/// Checks for equality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are equal, otherwise false</returns>
public static bool operator ==(TopologyBrief left, TopologyBrief right)
{
return left.Equals(right);
}
/// <summary>
/// Checks for inequality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are not equal, otherwise false</returns>
public static bool operator !=(TopologyBrief left, TopologyBrief right)
{
return !left.Equals(right);
}
/// <summary>
/// The topology
/// </summary>
public Topology Topology
{
get => _Topology;
}
/// <summary>
/// Indicates if the topology is enable
/// </summary>
public bool IsEnable
{
get => _IsEnable > 0;
}
/// <summary>
/// Indicates if the topology is possible
/// </summary>
public bool IsPossible
{
get => _IsPossible > 0;
}
}
}

View File

@@ -0,0 +1,269 @@
using System;
using System.Linq;
using System.Runtime.InteropServices;
using NvAPIWrapper.Native.Attributes;
using NvAPIWrapper.Native.General.Structures;
using NvAPIWrapper.Native.GPU;
using NvAPIWrapper.Native.GPU.Structures;
using NvAPIWrapper.Native.Interfaces;
namespace NvAPIWrapper.Native.Mosaic.Structures
{
/// <summary>
/// Holds extra details about a topology
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 8)]
[StructureVersion(1)]
public struct TopologyDetails : IInitializable, IEquatable<TopologyDetails>
{
/// <summary>
/// Maximum number of rows in a topology detail
/// </summary>
public const int MaxLayoutRows = 8;
/// <summary>
/// Maximum number of columns in a topology detail
/// </summary>
public const int MaxLayoutColumns = 8;
internal StructureVersion _Version;
internal readonly LogicalGPUHandle _LogicalGPUHandle;
internal readonly TopologyValidity _ValidityFlags;
internal readonly uint _Rows;
internal readonly uint _Columns;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MaxLayoutRows)]
internal readonly LayoutRow[] _LayoutRows;
/// <inheritdoc />
public bool Equals(TopologyDetails other)
{
return _LogicalGPUHandle.Equals(other._LogicalGPUHandle) &&
_ValidityFlags == other._ValidityFlags &&
_Rows == other._Rows &&
_Columns == other._Columns &&
_LayoutRows.SequenceEqual(other._LayoutRows);
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
return obj is TopologyDetails details && Equals(details);
}
/// <inheritdoc />
public override int GetHashCode()
{
unchecked
{
var hashCode = _LogicalGPUHandle.GetHashCode();
hashCode = (hashCode * 397) ^ (int) _ValidityFlags;
hashCode = (hashCode * 397) ^ (int) _Rows;
hashCode = (hashCode * 397) ^ (int) _Columns;
hashCode = (hashCode * 397) ^ (_LayoutRows?.GetHashCode() ?? 0);
return hashCode;
}
}
/// <summary>
/// Checks for equality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are equal, otherwise false</returns>
public static bool operator ==(TopologyDetails left, TopologyDetails right)
{
return left.Equals(right);
}
/// <summary>
/// Checks for inequality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are not equal, otherwise false</returns>
public static bool operator !=(TopologyDetails left, TopologyDetails right)
{
return !left.Equals(right);
}
/// <summary>
/// Logical GPU for this topology
/// </summary>
public LogicalGPUHandle LogicalGPUHandle
{
get => _LogicalGPUHandle;
}
/// <summary>
/// Indicates topology validity. TopologyValidity.Valid means topology is valid with the current hardware.
/// </summary>
public TopologyValidity ValidityFlags
{
get => _ValidityFlags;
}
/// <summary>
/// Number of displays in a row
/// </summary>
public int Rows
{
get => (int) _Rows;
}
/// <summary>
/// Number of displays in a column
/// </summary>
public int Columns
{
get => (int) _Columns;
}
/// <summary>
/// Gets a 2D array of layout cells containing information about the display layout of the topology
/// </summary>
public LayoutCell[][] Layout
{
get
{
var columns = (int) _Columns;
return _LayoutRows.Take((int) _Rows).Select(row => row.LayoutCells.Take(columns).ToArray()).ToArray();
}
}
[StructLayout(LayoutKind.Sequential)]
internal struct LayoutRow : IInitializable, IEquatable<LayoutRow>
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MaxLayoutColumns)]
internal readonly LayoutCell[]
LayoutCells;
public bool Equals(LayoutRow other)
{
return LayoutCells.SequenceEqual(other.LayoutCells);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
return obj is LayoutRow row && Equals(row);
}
public override int GetHashCode()
{
return LayoutCells?.GetHashCode() ?? 0;
}
}
/// <summary>
/// Holds information about a topology display
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct LayoutCell : IEquatable<LayoutCell>
{
internal readonly PhysicalGPUHandle _PhysicalGPUHandle;
internal readonly OutputId _DisplayOutputId;
internal readonly int _OverlapX;
internal readonly int _OverlapY;
/// <inheritdoc />
public bool Equals(LayoutCell other)
{
return _PhysicalGPUHandle.Equals(other._PhysicalGPUHandle) &&
_DisplayOutputId == other._DisplayOutputId &&
_OverlapX == other._OverlapX &&
_OverlapY == other._OverlapY;
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
return obj is LayoutCell cell && Equals(cell);
}
/// <inheritdoc />
public override int GetHashCode()
{
unchecked
{
var hashCode = _PhysicalGPUHandle.GetHashCode();
hashCode = (hashCode * 397) ^ (int) _DisplayOutputId;
hashCode = (hashCode * 397) ^ _OverlapX;
hashCode = (hashCode * 397) ^ _OverlapY;
return hashCode;
}
}
/// <summary>
/// Checks for equality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are equal, otherwise false</returns>
public static bool operator ==(LayoutCell left, LayoutCell right)
{
return left.Equals(right);
}
/// <summary>
/// Checks for inequality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are not equal, otherwise false</returns>
public static bool operator !=(LayoutCell left, LayoutCell right)
{
return !left.Equals(right);
}
/// <summary>
/// Physical GPU to be used in the topology (0 if GPU missing)
/// </summary>
public PhysicalGPUHandle PhysicalGPUHandle
{
get => _PhysicalGPUHandle;
}
/// <summary>
/// Connected display target (0 if no display connected)
/// </summary>
public OutputId DisplayOutputId
{
get => _DisplayOutputId;
}
/// <summary>
/// Pixels of overlap on left of target: (+overlap, -gap)
/// </summary>
public int OverlapX
{
get => _OverlapX;
}
/// <summary>
/// Pixels of overlap on top of target: (+overlap, -gap)
/// </summary>
public int OverlapY
{
get => _OverlapY;
}
}
}
}

View File

@@ -0,0 +1,109 @@
using System;
using System.Linq;
using System.Runtime.InteropServices;
using NvAPIWrapper.Native.Attributes;
using NvAPIWrapper.Native.General.Structures;
using NvAPIWrapper.Native.Interfaces;
namespace NvAPIWrapper.Native.Mosaic.Structures
{
/// <summary>
/// This structure defines a group of topologies that work together to create one overall layout. All of the supported
/// topologies are represented with this structure.
/// For example, a 'Passive Stereo' topology would be represented with this structure, and would have separate topology
/// details for the left and right eyes. The count would be 2. A 'Basic' topology is also represented by this
/// structure, with a count of 1.
/// The structure is primarily used internally, but is exposed to applications in a read-only fashion because there are
/// some details in it that might be useful (like the number of rows/cols, or connected display information). A user
/// can get the filled-in structure by calling NvAPI_Mosaic_GetTopoGroup().
/// You can then look at the detailed values within the structure. There are no entry points which take this structure
/// as input (effectively making it read-only).
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 8)]
[StructureVersion(1)]
public struct TopologyGroup : IInitializable, IEquatable<TopologyGroup>
{
/// <summary>
/// Maximum number of topologies per each group
/// </summary>
public const int MaxTopologyPerGroup = 2;
internal StructureVersion _Version;
internal readonly TopologyBrief _Brief;
internal readonly uint _TopologiesCount;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MaxTopologyPerGroup)]
internal readonly TopologyDetails[]
_TopologyDetails;
/// <summary>
/// The brief details of this topology
/// </summary>
public TopologyBrief Brief
{
get => _Brief;
}
/// <summary>
/// Information about the topologies within this group
/// </summary>
public TopologyDetails[] TopologyDetails
{
get => _TopologyDetails.Take((int) _TopologiesCount).ToArray();
}
/// <inheritdoc />
public bool Equals(TopologyGroup other)
{
return _Brief.Equals(other._Brief) &&
_TopologiesCount == other._TopologiesCount &&
_TopologyDetails.SequenceEqual(other._TopologyDetails);
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
return obj is TopologyGroup group && Equals(group);
}
/// <summary>
/// Checks for equality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are equal, otherwise false</returns>
public static bool operator ==(TopologyGroup left, TopologyGroup right)
{
return left.Equals(right);
}
/// <summary>
/// Checks for inequality between two objects of same type
/// </summary>
/// <param name="left">The first object</param>
/// <param name="right">The second object</param>
/// <returns>true, if both objects are not equal, otherwise false</returns>
public static bool operator !=(TopologyGroup left, TopologyGroup right)
{
return !left.Equals(right);
}
/// <inheritdoc />
public override int GetHashCode()
{
unchecked
{
var hashCode = _Brief.GetHashCode();
hashCode = (hashCode * 397) ^ (int) _TopologiesCount;
hashCode = (hashCode * 397) ^ (_TopologyDetails?.GetHashCode() ?? 0);
return hashCode;
}
}
}
}