/// <summary> /// Initializes the device for the specified profile. /// </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; // Create Direct3D 11 Device with feature Level based on profile for (int index = 0; index < graphicsProfiles.Length; index++) { var graphicsProfile = graphicsProfiles[index]; try { // Direct3D 12 supports only feature level 11+ var level = graphicsProfile.ToFeatureLevel(); nativeDevice = new Device(Adapter.NativeAdapter, creationFlags, level); RequestedProfile = graphicsProfile; break; } catch { if (index == graphicsProfiles.Length - 1) { throw; } } } nativeDeviceContext = nativeDevice.ImmediateContext; // We keep one reference so that it doesn't disappear with InternalMainCommandList ((IUnknown)nativeDeviceContext).AddReference(); if (IsDebugMode) { GraphicsResourceBase.SetDebugName(this, nativeDeviceContext, "ImmediateContext"); } }
/// <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; // 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; } } if (Core.Platform.Type == PlatformType.Windows && GetModuleHandle("renderdoc.dll") != IntPtr.Zero) { if (level < SharpDX.Direct3D.FeatureLevel.Level_11_0) { level = SharpDX.Direct3D.FeatureLevel.Level_11_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; // We keep one reference so that it doesn't disappear with InternalMainCommandList ((IUnknown)nativeDeviceContext).AddReference(); if (IsDebugMode) { GraphicsResourceBase.SetDebugName(this, nativeDeviceContext, "ImmediateContext"); } }