public static extern void D3D11CreateDevice( [In, MarshalAs(UnmanagedType.IUnknown)] object adapter, [In] D3D11DriverType driverType, [In] IntPtr software, [In] D3D11CreateDeviceOptions options, [In, MarshalAs(UnmanagedType.LPArray)] D3D11FeatureLevel[] featureLevels, [In] uint numFeatureLevels, [In] uint sdkVersion, [Out] out ID3D11Device device, [Out] out D3D11FeatureLevel featureLevel, [Out] out ID3D11DeviceContext immediateContext);
private void CreateDeviceResources() { D3D11FeatureLevel[] featureLevels; if (this.useHighestFeatureLevel) { if (this.d3dFeatureLevel == D3D11FeatureLevel.FeatureLevel91) { featureLevels = new D3D11FeatureLevel[] { D3D11FeatureLevel.FeatureLevel111, D3D11FeatureLevel.FeatureLevel110, D3D11FeatureLevel.FeatureLevel101, D3D11FeatureLevel.FeatureLevel100, D3D11FeatureLevel.FeatureLevel93, D3D11FeatureLevel.FeatureLevel92, D3D11FeatureLevel.FeatureLevel91 }; } else { featureLevels = Enum.GetValues(typeof(D3D11FeatureLevel)) .Cast <D3D11FeatureLevel>() .Where(t => t >= this.d3dFeatureLevel) .OrderByDescending(t => t) .ToArray(); } } else { featureLevels = new D3D11FeatureLevel[] { this.d3dFeatureLevel }; } D3D11CreateDeviceOptions options = D3D11CreateDeviceOptions.BgraSupport; try { this.d3dDriverType = D3D11DriverType.Hardware; D3D11Device.CreateDevice( null, this.d3dDriverType, options, featureLevels, out this.d3dDevice, out this.d3dFeatureLevel, out this.d3dContext); } catch (Exception ex) { if (ex.HResult == DxgiError.Unsupported) { this.d3dDriverType = D3D11DriverType.Warp; D3D11Device.CreateDevice( null, this.d3dDriverType, options, featureLevels, out this.d3dDevice, out this.d3dFeatureLevel, out this.d3dContext); } else { throw; } } if (this.preferMultisampling) { this.d3dSampleDesc = this.CheckMultisamplingSupport(); } else { this.d3dSampleDesc = new DxgiSampleDesc(1, 0); } }