private static unsafe void InitDeviceFactory() { GraphicsProcessingUnit *outGPUArrPtr; int outGPUArrLen; InteropUtils.CallNative(NativeMethods.DeviceFactory_Init, (IntPtr)(&outGPUArrPtr), (IntPtr)(&outGPUArrLen)).ThrowOnFailure(); InstalledGPUs = new GraphicsProcessingUnit[outGPUArrLen]; for (int i = 0; i < outGPUArrLen; ++i) { installedGPUs[i] = outGPUArrPtr[i]; Logger.Log("Installed GPU: " + outGPUArrPtr[i]); } }
public static void GetRecommendedHardwareIndices(out int gpuIndex, out int outputGPUIndex, out int outputIndex) { if (installedGPUs == null) { throw new InvalidOperationException("Can not view hardware before module has been added."); } GraphicsProcessingUnit recommendedGPU = installedGPUs .OrderByDescending(gpu => gpu.DedicatedVideoMemory).First(); OutputDisplay recommendedOutputDisplay; if (!recommendedGPU.Outputs.Any()) { var allOutputs = installedGPUs.SelectMany(gpu => gpu.Outputs); if (allOutputs.Any(output => output.IsPrimaryOutput)) { recommendedOutputDisplay = allOutputs.First(output => output.IsPrimaryOutput); } else if (!allOutputs.Any()) { throw new ApplicationException("No output detected."); } else { recommendedOutputDisplay = allOutputs .OrderByDescending(output => output.HighestResolution.ResolutionWidth * output.HighestResolution.ResolutionHeight).First(); } } else if (recommendedGPU.Outputs.Any(output => output.IsPrimaryOutput)) { recommendedOutputDisplay = recommendedGPU.Outputs.First(output => output.IsPrimaryOutput); outputGPUIndex = recommendedGPU.Index; } else { recommendedOutputDisplay = recommendedGPU.Outputs .OrderByDescending(output => output.NativeResolutions .Select(res => res.ResolutionWidth * res.ResolutionHeight) .OrderByDescending(res => res).First() ) .First(); outputGPUIndex = recommendedGPU.Index; } gpuIndex = recommendedGPU.Index; outputGPUIndex = installedGPUs.First(gpu => gpu.Outputs.Contains(recommendedOutputDisplay)).Index; outputIndex = recommendedOutputDisplay.Index; }
/// <summary> /// Calls <see cref="SetHardware(Ophidian.Losgap.Rendering.GraphicsProcessingUnit,Ophidian.Losgap.Rendering.OutputDisplay)"/> with /// the <see cref="GraphicsProcessingUnit.Index"/> of the supplied <paramref name="gpu"/> and the /// <see cref="OutputDisplay.Index"/> of the supplied <paramref name="outputDisplay"/>. /// </summary> /// <param name="gpu">The gpu whose index slot you wish you set.</param> /// <param name="outputDisplay">The output whose index slot you wish to set.</param> /// <seealso cref="SetHardware(int,int)"/> public static void SetHardware(GraphicsProcessingUnit gpu, OutputDisplay outputDisplay) { SetHardware(gpu.Index, installedGPUs.First(g => g.Outputs.Contains(outputDisplay)).Index, outputDisplay.Index); }