/// <summary> /// Check if a feature level is supported by a particular adapter. /// </summary> /// <param name="adapter">The adapter.</param> /// <param name="featureLevel">The feature level.</param> /// <returns><c>true</c> if the specified adapter is supporting this feature level; otherwise, <c>false</c>.</returns> public static bool IsSupportedFeatureLevel(Adapter adapter, FeatureLevel featureLevel) { var device = new Device(IntPtr.Zero); DeviceContext context = null; try { FeatureLevel outputLevel; var result = D3D11.CreateDevice(adapter, DriverType.Unknown, IntPtr.Zero, DeviceCreationFlags.None, new[] { featureLevel }, 1, D3D11.SdkVersion, device, out outputLevel, out context); return(result.Success && outputLevel == featureLevel); } finally { if (context != null) { context.Dispose(); } if (device.NativePointer != IntPtr.Zero) { device.Dispose(); } } }
/// <summary> /// Gets the highest supported hardware feature level of the primary adapter. /// </summary> /// <param name="adapter">The adapter.</param> /// <returns> /// The highest supported hardware feature level. /// </returns> public static FeatureLevel GetSupportedFeatureLevel(Adapter adapter) { FeatureLevel outputLevel; var device = new Device(IntPtr.Zero); DeviceContext context; D3D11.CreateDevice(adapter, DriverType.Unknown, IntPtr.Zero, DeviceCreationFlags.None, null, 0, D3D11.SdkVersion, device, out outputLevel, out context).CheckError(); context.Dispose(); device.Dispose(); return(outputLevel); }
/// <summary> /// Internal CreateDevice /// </summary> /// <param name = "adapter"></param> /// <param name = "driverType"></param> /// <param name = "flags"></param> /// <param name = "featureLevels"></param> private void CreateDevice(Adapter adapter, DriverType driverType, DeviceCreationFlags flags, FeatureLevel[] featureLevels) { FeatureLevel selectedLevel; D3D11.CreateDevice(adapter, driverType, IntPtr.Zero, flags, featureLevels, featureLevels == null ? 0 : featureLevels.Length, D3D11.SdkVersion, this, out selectedLevel, out ImmediateContext__).CheckError(); if (ImmediateContext__ != null) { // Add a reference when setting the device on the context ((IUnknown)this).AddReference(); ImmediateContext__.Device__ = this; } }