public static Result TryCreate( IDXGIAdapter adapter, DriverType driverType, DeviceCreationFlags flags, FeatureLevel[] featureLevels, out ID3D11Device device, out ID3D11DeviceContext immediateContext) { var result = D3D11.CreateDevice( adapter, driverType, IntPtr.Zero, (int)flags, featureLevels, (featureLevels != null) ? featureLevels.Length : 0, D3D11.SdkVersion, out device, out FeatureLevel featureLevel, out immediateContext); if (result.Failure) { return(result); } if (immediateContext != null) { device.AddRef(); device.ImmediateContext__ = immediateContext; immediateContext.Device__ = device; } return(result); }
public D3D11GraphicsDevice(D3D11DeviceOptions options, SwapchainDescription?swapchainDesc) { var flags = (DeviceCreationFlags)options.DeviceCreationFlags; #if DEBUG flags |= DeviceCreationFlags.Debug; #endif // If debug flag set but SDK layers aren't available we can't enable debug. if (0 != (flags & DeviceCreationFlags.Debug) && !Vortice.Direct3D11.D3D11.SdkLayersAvailable()) { flags &= ~DeviceCreationFlags.Debug; } try { if (options.AdapterPtr != IntPtr.Zero) { VorticeD3D11.D3D11CreateDevice(options.AdapterPtr, Vortice.Direct3D.DriverType.Hardware, flags, new[] { Vortice.Direct3D.FeatureLevel.Level_11_1, Vortice.Direct3D.FeatureLevel.Level_11_0, }, out _device).CheckError(); } else { VorticeD3D11.D3D11CreateDevice(IntPtr.Zero, Vortice.Direct3D.DriverType.Hardware, flags, new[] { Vortice.Direct3D.FeatureLevel.Level_11_1, Vortice.Direct3D.FeatureLevel.Level_11_0, }, out _device).CheckError(); } } catch { VorticeD3D11.D3D11CreateDevice(IntPtr.Zero, Vortice.Direct3D.DriverType.Hardware, flags, null, out _device).CheckError(); } using (IDXGIDevice dxgiDevice = _device.QueryInterface <IDXGIDevice>()) { // Store a pointer to the DXGI adapter. // This is for the case of no preferred DXGI adapter, or fallback to WARP. dxgiDevice.GetAdapter(out _dxgiAdapter).CheckError(); _deviceName = _dxgiAdapter.Description.Description; } if (swapchainDesc != null) { SwapchainDescription desc = swapchainDesc.Value; _mainSwapchain = new D3D11Swapchain(this, ref desc); } _immediateContext = _device.ImmediateContext; _device.CheckThreadingSupport(out _supportsConcurrentResources, out _supportsCommandLists); Features = new GraphicsDeviceFeatures( computeShader: true, geometryShader: true, tessellationShaders: true, multipleViewports: true, samplerLodBias: true, drawBaseVertex: true, drawBaseInstance: true, drawIndirect: true, drawIndirectBaseInstance: true, fillModeWireframe: true, samplerAnisotropy: true, depthClipDisable: true, texture1D: true, independentBlend: true, structuredBuffer: true, subsetTextureView: true, commandListDebugMarkers: _device.FeatureLevel >= Vortice.Direct3D.FeatureLevel.Level_11_1, bufferRangeBinding: _device.FeatureLevel >= Vortice.Direct3D.FeatureLevel.Level_11_1, shaderFloat64: _device.CheckFeatureSupport <FeatureDataDoubles>(Vortice.Direct3D11.Feature.Doubles).DoublePrecisionFloatShaderOps); _d3d11ResourceFactory = new D3D11ResourceFactory(this); _d3d11Info = new BackendInfoD3D11(this); PostDeviceCreated(); }