/// <summary> /// Initializes the specified device. /// </summary> /// <param name="graphicsProfiles">The graphics profiles.</param> /// <param name="deviceCreationFlags">The device creation flags.</param> /// <param name="windowHandle">The window handle.</param> private void InitializePlatformDevice(GraphicsProfile[] graphicsProfiles, DeviceCreationFlags deviceCreationFlags, object windowHandle) { if (nativeDevice != null) { // Destroy previous device ReleaseDevice(); } // Profiling is supported through pix markers IsProfilingSupported = true; // Map GraphicsProfile to D3D11 FeatureLevel SharpDX.Direct3D.FeatureLevel[] levels = graphicsProfiles.ToFeatureLevel(); creationFlags = (SharpDX.Direct3D11.DeviceCreationFlags)deviceCreationFlags; // Create Device D3D11 with feature Level based on profile nativeDevice = new SharpDX.Direct3D11.Device(Adapter.NativeAdapter, creationFlags, levels); nativeDeviceContext = nativeDevice.ImmediateContext; if (IsDebugMode) { GraphicsResourceBase.SetDebugName(this, nativeDeviceContext, "ImmediateContext"); } InitializeStages(); // Create the input layout manager if (InputLayoutManager == null) { InputLayoutManager = new InputLayoutManager(this).DisposeBy(this); } }
/// <summary> /// Initializes a new instance of the <see cref="GraphicsDevice" /> class using the default GraphicsAdapter /// and the Level10 <see cref="GraphicsProfile" />. /// </summary> /// <param name="device">The device.</param> private GraphicsDevice(GraphicsDevice device) { RootDevice = device; Adapter = device.Adapter; creationFlags = device.creationFlags; Features = device.Features; sharedDataPerDevice = device.sharedDataPerDevice; InputLayoutManager = device.InputLayoutManager; nativeDevice = device.NativeDevice; nativeDeviceContext = new SharpDX.Direct3D11.DeviceContext(NativeDevice).DisposeBy(this); nativeDeviceProfiler = SharpDX.ComObject.QueryInterfaceOrNull <UserDefinedAnnotation>(nativeDeviceContext.NativePointer); isDeferred = true; IsDebugMode = device.IsDebugMode; if (IsDebugMode) { GraphicsResourceBase.SetDebugName(device, nativeDeviceContext, "DeferredContext"); } NeedWorkAroundForUpdateSubResource = !Features.HasDriverCommandLists; primitiveQuad = new PrimitiveQuad(this).DisposeBy(this); InitializeStages(); }
/// <summary> /// Initializes the specified device. /// </summary> /// <param name="graphicsProfiles">The graphics profiles.</param> /// <param name="deviceCreationFlags">The device creation flags.</param> /// <param name="windowHandle">The window handle.</param> private void InitializePlatformDevice(GraphicsProfile[] graphicsProfiles, DeviceCreationFlags deviceCreationFlags, object windowHandle) { if (nativeDevice != null) { // Destroy previous device ReleaseDevice(); } rendererName = Adapter.NativeAdapter.Description.Description; // Profiling is supported through pix markers IsProfilingSupported = true; // Map GraphicsProfile to D3D11 FeatureLevel creationFlags = (SharpDX.Direct3D11.DeviceCreationFlags)deviceCreationFlags; // Default fallback if (graphicsProfiles.Length == 0) { graphicsProfiles = new[] { GraphicsProfile.Level_11_0, GraphicsProfile.Level_10_1, GraphicsProfile.Level_10_0, GraphicsProfile.Level_9_3, GraphicsProfile.Level_9_2, GraphicsProfile.Level_9_1 } } ; // Create Device D3D11 with feature Level based on profile for (int index = 0; index < graphicsProfiles.Length; index++) { var graphicsProfile = graphicsProfiles[index]; try { // D3D12 supports only feature level 11+ var level = graphicsProfile.ToFeatureLevel(); // INTEL workaround: it seems Intel driver doesn't support properly feature level 9.x. Fallback to 10. if (Adapter.VendorId == 0x8086) { if (level < SharpDX.Direct3D.FeatureLevel.Level_10_0) { level = SharpDX.Direct3D.FeatureLevel.Level_10_0; } } nativeDevice = new SharpDX.Direct3D11.Device(Adapter.NativeAdapter, creationFlags, level); // INTEL workaround: force ShaderProfile to be 10+ as well if (Adapter.VendorId == 0x8086) { if (graphicsProfile < GraphicsProfile.Level_10_0 && (!ShaderProfile.HasValue || ShaderProfile.Value < GraphicsProfile.Level_10_0)) { ShaderProfile = GraphicsProfile.Level_10_0; } } RequestedProfile = graphicsProfile; break; } catch (Exception) { if (index == graphicsProfiles.Length - 1) { throw; } } } nativeDeviceContext = nativeDevice.ImmediateContext; if (IsDebugMode) { GraphicsResourceBase.SetDebugName(this, nativeDeviceContext, "ImmediateContext"); } }