Beispiel #1
0
        /// <summary>
        ///     This function retrieves the available driver memory footprint for the GPU associated with a display.
        /// </summary>
        /// <param name="displayHandle">Handle of the display for which the memory information of its GPU is to be extracted.</param>
        /// <returns>The memory footprint available in the driver.</returns>
        /// <exception cref="NVIDIANotSupportedException">This operation is not supported.</exception>
        /// <exception cref="NVIDIAApiException">Status.NvidiaDeviceNotFound: No NVIDIA GPU driving a display was found.</exception>
        /// <exception cref="Exception">A delegate callback throws an exception.</exception>
        public static IDisplayDriverMemoryInfo GetDisplayDriverMemoryInfo(DisplayHandle displayHandle)
        {
            var getMemoryInfo = DelegateFactory.GetDelegate <Delegates.Display.NvAPI_GetDisplayDriverMemoryInfo>();

            foreach (var acceptType in getMemoryInfo.Accepts())
            {
                var instance = acceptType.Instantiate <IDisplayDriverMemoryInfo>();

                using (var displayDriverMemoryInfo = ValueTypeReference.FromValueType(instance, acceptType))
                {
                    var status = getMemoryInfo(displayHandle, displayDriverMemoryInfo);

                    if (status == Status.IncompatibleStructureVersion)
                    {
                        continue;
                    }

                    if (status != Status.Ok)
                    {
                        throw new NVIDIAApiException(status);
                    }

                    return(displayDriverMemoryInfo.ToValueType <IDisplayDriverMemoryInfo>(acceptType));
                }
            }

            throw new NVIDIANotSupportedException("This operation is not supported.");
        }
Beispiel #2
0
        /// <summary>
        ///     This API lets caller enumerate all the supported NVIDIA display views - nView and Dualview modes.
        /// </summary>
        /// <param name="display">
        ///     NVIDIA Display selection. It can be DisplayHandle.DefaultHandle or a handle enumerated from
        ///     DisplayApi.EnumNVidiaDisplayHandle().
        /// </param>
        /// <returns>Array of supported views.</returns>
        /// <exception cref="NVIDIANotSupportedException">This operation is not supported.</exception>
        /// <exception cref="NVIDIAApiException">Status.Error: Miscellaneous error occurred</exception>
        /// <exception cref="NVIDIAApiException">Status.InvalidArgument: Invalid input parameter.</exception>
        public static TargetViewMode[] GetSupportedViews(DisplayHandle display)
        {
            var  getSupportedViews = DelegateFactory.Get <Delegates.Display.NvAPI_GetSupportedViews>();
            uint allAvailable      = 0;
            var  status            = getSupportedViews(display, ValueTypeArray.Null, ref allAvailable);

            if (status != Status.Ok)
            {
                throw new NVIDIAApiException(status);
            }
            if (allAvailable == 0)
            {
                return(new TargetViewMode[0]);
            }
            if (!getSupportedViews.Accepts().Contains(typeof(TargetViewMode)))
            {
                throw new NVIDIANotSupportedException("This operation is not supported.");
            }
            using (
                var viewModes =
                    ValueTypeArray.FromArray(TargetViewMode.Standard.Repeat((int)allAvailable).Cast <object>(),
                                             typeof(TargetViewMode).GetEnumUnderlyingType()))
            {
                status = getSupportedViews(display, viewModes, ref allAvailable);
                if (status != Status.Ok)
                {
                    throw new NVIDIAApiException(status);
                }
                return(viewModes.ToArray <TargetViewMode>((int)allAvailable,
                                                          typeof(TargetViewMode).GetEnumUnderlyingType()));
            }
        }
Beispiel #3
0
 /// <summary>
 /// This function returns the handle of the NVIDIA display specified by the enum index (thisEnum). The client should keep enumerating until it returns NVAPI_END_ENUMERATION.
 /// Note: Display handles can get invalidated on a modeset, so the calling applications need to renum the handles after every modeset.
 /// </summary>
 /// <param name="thisEnum">The index of the NVIDIA display.</param>
 /// <param name="displayHandle">Pointer to the NVIDIA display handle.</param>
 /// <returns></returns>
 public static Status EnumNvidiaDisplayHandle(int thisEnum, ref DisplayHandle displayHandle)
 {
     Status status;
     if (EnumNvidiaDisplayHandleInternal != null) { status = EnumNvidiaDisplayHandleInternal(thisEnum, ref displayHandle); }
     else { status = Status.NVAPI_FUNCTION_NOT_FOUND; }
     return status;
 }
Beispiel #4
0
        /// <summary>
        ///     This function returns the logical GPU handle associated with the specified display.
        ///     At least one GPU must be present in the system and running an NVIDIA display driver.
        ///     display can be DisplayHandle.DefaultHandle or a handle enumerated from EnumNVidiaDisplayHandle().
        /// </summary>
        /// <param name="display">Display handle to get information about</param>
        /// <returns>Logical GPU handle associated with the specified display</returns>
        /// <exception cref="NVIDIAApiException">Status.InvalidArgument: display is not valid</exception>
        /// <exception cref="NVIDIAApiException">Status.NvidiaDeviceNotFound: No NVIDIA GPU driving a display was found</exception>
        public static LogicalGPUHandle GetLogicalGPUFromDisplay(DisplayHandle display)
        {
            var status =
                DelegateFactory.GetDelegate <Delegates.GPU.NvAPI_GetLogicalGPUFromDisplay>()(display, out var gpu);

            if (status != Status.Ok)
            {
                throw new NVIDIAApiException(status);
            }

            return(gpu);
        }
Beispiel #5
0
        /// <summary>
        /// This function returns the handle of the NVIDIA display that is associated with the given display "name" (such as "\\.\DISPLAY1").
        /// </summary>
        /// <param name="szDisplayName"></param>
        /// <param name="pNvDispHandle"></param>
        /// <returns></returns>
        public static Status GetAssociatedNvidiaDisplayHandle(string szDisplayName, ref DisplayHandle pNvDispHandle)
        {
            StringBuilder builder = new StringBuilder((int)NvShortStringMax);
            builder.Append(szDisplayName);

            Status status;
            if (GetAssociatedNvidiaDisplayHandleInternal != null) { status = GetAssociatedNvidiaDisplayHandleInternal(builder, ref pNvDispHandle); }
            else { status = Status.NVAPI_FUNCTION_NOT_FOUND; }
            szDisplayName = builder.ToString();

            return status;
        }
Beispiel #6
0
        /// <summary>
        ///     For a given NVIDIA display handle, this function returns a string (such as "\\.\DISPLAY1") to identify the display.
        /// </summary>
        /// <param name="display">Handle of the associated display</param>
        /// <returns>Name of the display</returns>
        /// <exception cref="NVIDIAApiException">Status.InvalidArgument: Display handle is null.</exception>
        /// <exception cref="NVIDIAApiException">Status.NvidiaDeviceNotFound: No NVIDIA device maps to that display name.</exception>
        public static string GetAssociatedNvidiaDisplayName(DisplayHandle display)
        {
            var getAssociatedNvidiaDisplayName =
                DelegateFactory.Get <Delegates.Display.NvAPI_GetAssociatedNvidiaDisplayName>();
            ShortString displayName;
            var         status = getAssociatedNvidiaDisplayName(display, out displayName);

            if (status != Status.Ok)
            {
                throw new NVIDIAApiException(status);
            }
            return(displayName.Value);
        }
Beispiel #7
0
        /// <summary>
        ///     This function gets the active outputId associated with the display handle.
        /// </summary>
        /// <param name="display">
        ///     NVIDIA Display selection. It can be DisplayHandle.DefaultHandle or a handle enumerated from
        ///     DisplayApi.EnumNVidiaDisplayHandle().
        /// </param>
        /// <returns>
        ///     The active display output ID associated with the selected display handle hNvDisplay. The outputid will have
        ///     only one bit set. In the case of Clone or Span mode, this will indicate the display outputId of the primary display
        ///     that the GPU is driving.
        /// </returns>
        /// <exception cref="NVIDIAApiException">Status.NvidiaDeviceNotFound: No NVIDIA GPU driving a display was found.</exception>
        /// <exception cref="NVIDIAApiException">Status.ExpectedDisplayHandle: display is not a valid display handle.</exception>
        public static OutputId GetAssociatedDisplayOutputId(DisplayHandle display)
        {
            var getAssociatedDisplayOutputId =
                DelegateFactory.Get <Delegates.Display.NvAPI_GetAssociatedDisplayOutputId>();
            OutputId outputId;
            var      status = getAssociatedDisplayOutputId(display, out outputId);

            if (status != Status.Ok)
            {
                throw new NVIDIAApiException(status);
            }
            return(outputId);
        }
Beispiel #8
0
        /// <summary>
        ///     Gets the build title of the Driver Settings Database for a display
        /// </summary>
        /// <param name="displayHandle">The display handle to get DRS build title.</param>
        /// <returns>The DRS build title.</returns>
        public static string GetDisplayDriverBuildTitle(DisplayHandle displayHandle)
        {
            var status =
                DelegateFactory.GetDelegate <Delegates.Display.NvAPI_GetDisplayDriverBuildTitle>()(displayHandle,
                                                                                                   out var name);

            if (status != Status.Ok)
            {
                throw new NVIDIAApiException(status);
            }

            return(name.Value);
        }
Beispiel #9
0
        /// <summary>
        /// This function returns the handle of the NVIDIA display specified by the enum index (thisEnum). The client should keep enumerating until it returns NVAPI_END_ENUMERATION.
        /// Note: Display handles can get invalidated on a modeset, so the calling applications need to renum the handles after every modeset.
        /// </summary>
        /// <param name="thisEnum">The index of the NVIDIA display.</param>
        /// <param name="displayHandle">Pointer to the NVIDIA display handle.</param>
        /// <returns></returns>
        public static Status EnumNvidiaDisplayHandle(int thisEnum, ref DisplayHandle displayHandle)
        {
            Status status;

            if (EnumNvidiaDisplayHandleInternal != null)
            {
                status = EnumNvidiaDisplayHandleInternal(thisEnum, ref displayHandle);
            }
            else
            {
                status = Status.NVAPI_FUNCTION_NOT_FOUND;
            }
            return(status);
        }
Beispiel #10
0
        /// <summary>
        ///     This function returns an array of physical GPU handles associated with the specified display.
        ///     At least one GPU must be present in the system and running an NVIDIA display driver.
        ///     If the display corresponds to more than one physical GPU, the first GPU returned is the one with the attached
        ///     active output.
        /// </summary>
        /// <param name="display">Display handle to get information about</param>
        /// <returns>An array of physical GPU handles</returns>
        /// <exception cref="NVIDIAApiException">Status.InvalidArgument: display is not valid</exception>
        /// <exception cref="NVIDIAApiException">Status.NvidiaDeviceNotFound: No NVIDIA GPU driving a display was found</exception>
        public static PhysicalGPUHandle[] GetPhysicalGPUsFromDisplay(DisplayHandle display)
        {
            var gpuList =
                typeof(PhysicalGPUHandle).Instantiate <PhysicalGPUHandle>().Repeat(PhysicalGPUHandle.MaxPhysicalGPUs);
            var status = DelegateFactory.GetDelegate <Delegates.GPU.NvAPI_GetPhysicalGPUsFromDisplay>()(display, gpuList,
                                                                                                        out var count);

            if (status != Status.Ok)
            {
                throw new NVIDIAApiException(status);
            }

            return(gpuList.Take((int)count).ToArray());
        }
Beispiel #11
0
        /// <summary>
        /// This function returns the handle of the NVIDIA display that is associated with the given display "name" (such as "\\.\DISPLAY1").
        /// </summary>
        /// <param name="szDisplayName"></param>
        /// <param name="pNvDispHandle"></param>
        /// <returns></returns>
        public static Status GetAssociatedNvidiaDisplayHandle(string szDisplayName, ref DisplayHandle pNvDispHandle)
        {
            StringBuilder builder = new StringBuilder((int)NvShortStringMax);

            builder.Append(szDisplayName);

            Status status;

            if (GetAssociatedNvidiaDisplayHandleInternal != null)
            {
                status = GetAssociatedNvidiaDisplayHandleInternal(builder, ref pNvDispHandle);
            }
            else
            {
                status = Status.NVAPI_FUNCTION_NOT_FOUND;
            }
            szDisplayName = builder.ToString();

            return(status);
        }
Beispiel #12
0
 /// <summary>
 ///     Creates a new Display
 /// </summary>
 /// <param name="handle">Handle of the display device</param>
 public Display(DisplayHandle handle)
 {
     Handle = handle;
 }
Beispiel #13
0
 /// <summary>
 ///     Creates a new instance of the class using a DisplayHandle
 /// </summary>
 /// <param name="displayHandle">The handle of the display.</param>
 public DVCInformation(DisplayHandle displayHandle)
 {
     _displayHandle = displayHandle;
 }