/// <summary> /// This function returns the EDID data for the specified GPU handle and connection bit mask. /// outputId should have exactly 1 bit set to indicate a single display. /// </summary> /// <param name="gpuHandle">Physical GPU handle to check outputs</param> /// <param name="outputId">Output identification</param> /// <param name="offset">EDID offset</param> /// <param name="readIdentification">EDID read identification for multi part read, or zero for first run</param> /// <returns>Whole or a part of the EDID data</returns> /// <exception cref="NVIDIANotSupportedException">This operation is not supported.</exception> /// <exception cref="NVIDIAApiException"> /// Status.InvalidArgument: gpuHandle or edid is invalid, outputId has 0 or > 1 bits /// set /// </exception> /// <exception cref="NVIDIAApiException">Status.NvidiaDeviceNotFound: No NVIDIA GPU driving a display was found.</exception> /// <exception cref="NVIDIAApiException">Status.ExpectedPhysicalGPUHandle: gpuHandle was not a physical GPU handle.</exception> /// <exception cref="NVIDIAApiException">Status.DataNotFound: The requested display does not contain an EDID.</exception> /// <exception cref="Exception">A delegate callback throws an exception.</exception> // ReSharper disable once TooManyArguments public static EDIDV3 GetEDID( PhysicalGPUHandle gpuHandle, OutputId outputId, int offset, int readIdentification = 0) { var gpuGetEDID = DelegateFactory.GetDelegate <Delegates.GPU.NvAPI_GPU_GetEDID>(); if (!gpuGetEDID.Accepts().Contains(typeof(EDIDV3))) { throw new NVIDIANotSupportedException("This operation is not supported."); } var instance = EDIDV3.CreateWithOffset((uint)readIdentification, (uint)offset); using (var edidReference = ValueTypeReference.FromValueType(instance)) { var status = gpuGetEDID(gpuHandle, outputId, edidReference); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return(edidReference.ToValueType <EDIDV3>().GetValueOrDefault()); } }
private void WriteEDIDData(uint displayOutputId, byte[] edidData) { try { for (var offset = 0; offset < edidData.Length; offset += EDIDV3.MaxDataSize) { var array = new byte[Math.Min(EDIDV3.MaxDataSize, edidData.Length - offset)]; Array.Copy(edidData, offset, array, 0, array.Length); var instance = EDIDV3.CreateWithData(0, (uint)offset, array, edidData.Length); GPUApi.SetEDID(Handle, displayOutputId, instance); } return; } catch (NVIDIAApiException ex) { if (ex.Status != Status.IncompatibleStructureVersion) { throw; } } catch (NVIDIANotSupportedException) { // ignore } try { for (var offset = 0; offset < edidData.Length; offset += EDIDV2.MaxDataSize) { var array = new byte[Math.Min(EDIDV2.MaxDataSize, edidData.Length - offset)]; Array.Copy(edidData, offset, array, 0, array.Length); GPUApi.SetEDID(Handle, displayOutputId, EDIDV2.CreateWithData(array, edidData.Length)); } return; } catch (NVIDIAApiException ex) { if (ex.Status != Status.IncompatibleStructureVersion) { throw; } } catch (NVIDIANotSupportedException) { // ignore } GPUApi.SetEDID(Handle, displayOutputId, EDIDV1.CreateWithData(edidData)); }